three-live 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.ts +190 -0
- package/dist/three-author-engine.js +171 -163
- package/dist/three-author.cjs +145 -163
- package/dist/three-author.d.ts +190 -0
- package/dist/three-author.js +145 -163
- package/dist/three-convert.cjs +142 -160
- package/dist/three-convert.d.ts +190 -0
- package/dist/three-convert.js +142 -160
- package/dist/three-live-ai.cjs +41 -0
- package/dist/three-live-ai.d.ts +759 -0
- package/dist/three-live-ai.js +41 -0
- package/dist/three-live-ai.min.js +41 -0
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +190 -0
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +190 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +50 -85
- package/dist/three-live-element.d.ts +190 -0
- package/dist/three-live-element.js +50 -85
- package/dist/three-live-full.cjs +907 -189
- package/dist/three-live-full.js +907 -189
- package/dist/three-live-full.min.js +907 -189
- package/dist/three-live-procedural.cjs +16 -0
- package/dist/three-live-procedural.d.ts +759 -0
- package/dist/three-live-procedural.js +16 -0
- package/dist/three-live-procedural.min.js +16 -0
- package/dist/three-live-sandbox.html +11 -1
- package/dist/three-live-studio.cjs +72 -17
- package/dist/three-live-studio.d.ts +190 -0
- package/dist/three-live-studio.js +72 -17
- package/dist/three-live-studio.min.js +73 -18
- package/dist/three-live-tsl.cjs +103 -0
- package/dist/three-live-tsl.d.ts +759 -0
- package/dist/three-live-tsl.js +103 -0
- package/dist/three-live-tsl.min.js +103 -0
- package/dist/three-live-viewer.cjs +50 -85
- package/dist/three-live-viewer.d.ts +190 -0
- package/dist/three-live-viewer.js +50 -85
- package/dist/three-live-viewer.min.js +50 -85
- package/dist/three-live-webgpu.cjs +585 -0
- package/dist/three-live-webgpu.d.ts +759 -0
- package/dist/three-live-webgpu.js +585 -0
- package/dist/three-live-webgpu.min.js +585 -0
- package/dist/three-live.cjs +147 -165
- package/dist/three-live.js +147 -165
- package/dist/three-live.min.js +147 -165
- package/dist/three-view.cjs +49 -84
- package/dist/three-view.d.ts +190 -0
- package/dist/three-view.js +50 -85
- package/dist/three-xr.cjs +141 -159
- package/dist/three-xr.d.ts +190 -0
- package/dist/three-xr.js +140 -158
- package/package.json +21 -1
package/dist/three-convert.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/function je(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})},O=(F,_,T)=>{let L=$(_);L!==null&&y(F,{...T?{configuration:T}:{},flows:{out:{node:L}}})};if(M.onSelect&&O("pointer/onSelect",M.onSelect,{nodeIndex:u}),M.onHoverIn&&O("pointer/onHoverIn",M.onHoverIn,{nodeIndex:u}),M.onHoverOut&&O("pointer/onHoverOut",M.onHoverOut,{nodeIndex:u}),M.onStart&&O("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[F,_]of Object.entries(M.onReceive))O("event/receive",_,{event:v(F)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:m,events:p}],graph:0}:null}var Re="__THREE_LIVE_REGISTRY__";function ge(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Re]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Re,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Re]=t}}return e[Re]}var ue=ge().plugins;function gt(e){let t=ge().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function vt(){return ge().plugins}var xt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function ze(e,t,i,r){if(!i||i.bufferView===void 0)return null;let 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=xt[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 bt(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 $e(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 he(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ee(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 ke(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 Ge(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 ye(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 yt(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,O=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+$*O;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*O)*n,e[9]=(r*_-i*L-s*O)*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*O)*n,e[13]=(i*T-r*F+a*O)*n,e[14]=(b*u-h*M-C*w)*n,e[15]=(v*M-y*u+D*w)*n,e):null}function Ke(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 Mt(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,O=s*l-r*P,F=r*M-a*l,_=A*$+w*O+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*O+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 wt(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let v=0;v<i;v++)r.push(he());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=he();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];Ge(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 We=["neutral","reinhard","none","aces","agx"];function Ve(e){let t=String(e??"").trim().toLowerCase();return We.includes(t)?t:"neutral"}function Tt(e){return We.indexOf(Ve(e))}function Pt(e){return new TextDecoder().decode(e)}var Xe=ge().decoders;function At(e,t){Xe.set(e.toLowerCase(),t)}function we(e){return Xe.get(e.toLowerCase())}function qe(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let 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=Pt(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")&&!we("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)&&!we("meshopt"))throw new Error(`Model requires ${D}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!we("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 ue)D.onParseGLB?.(y);return y}function Rt(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 Ce(e){if(Rt(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return qe(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ye=`#version 300 es
|
|
16
|
+
*/function rt(e,t,i){let r=[],n=new Map,a=[],l=[],h=[],c=new Map,T=m=>{let y=n.get(m);return y===void 0&&(y=r.length,r.push({op:m}),n.set(m,y)),y},d=m=>{let y=c.get(m);return y===void 0&&(y=h.length,h.push({id:m}),c.set(m,y)),y},g=(m,y={})=>a.push({declaration:T(m),...y})-1,I=(m,y,w)=>l.push({id:m,type:y,value:w})-1,L=m=>({node:m,socket:"value"}),D=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(D&&typeof D=="object"){let m=Array.isArray(D.graphs)?D.graphs[D.graph??0]:D;if(m&&Array.isArray(m.nodes)){let y=Array.isArray(m.declarations)?m.declarations:[];for(let w of y)w?.op&&T(w.op);Array.isArray(m.variables)&&l.push(...m.variables);for(let w of m.events||[])w?.id&&d(w.id);for(let w of m.nodes){if(!w||typeof w!="object")continue;let x=w.op||(typeof w.declaration=="number"?y[w.declaration]?.op:"");a.push(x?{...w,declaration:T(x)}:{...w})}}}let O=(m,y,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,y)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,y)}/${w}`:w==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${w}`,o=new Map;e.forEach((m,y)=>{typeof m?.name=="string"&&!o.has(m.name)&&o.set(m.name,y)});let f=(m,y)=>typeof m.target=="string"&&o.has(m.target)?o.get(m.target):typeof m.targetNode=="number"?m.targetNode:y,p=m=>{let y=e[m];return(typeof y?.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<e.length;m++){let y=e[m],w=y?.extras?.interactivity;if(!w||typeof w!="object")continue;let x=(typeof y.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0,z=_=>{let C=Array.isArray(_)?_:[_],S=[];for(let V=0;V<C.length;V++){let b=C[V];if(!b||typeof b!="object")continue;let P=b.action||"interpolate",E=typeof b.duration=="number"?b.duration:.35;if(P==="toggleTransform"){let H=b.property==="rotation"||b.property==="scale"?b.property:"translation",v=H==="rotation"?y.rotation||[0,0,0,1]:H==="scale"?y.scale||[1,1,1]:y.translation||[0,0,0],$=`/nodes/${m}/${H}`,s=I(`__toggle_${m}_${V}`,"bool",!1),M=g("variable/get",{configuration:{variable:s}}),u=g("math/not",{values:{a:L(M)}}),A=g("variable/set",{configuration:{variable:s},values:{value:L(u)}}),j=g("pointer/interpolate",{configuration:{pointer:$},values:{value:{value:Array.isArray(b.to)?b.to:v},duration:{value:E}}}),q=g("pointer/interpolate",{configuration:{pointer:$},values:{value:{value:Array.isArray(b.from)?b.from:v},duration:{value:E}}});a[A].flows={out:{node:g("flow/branch",{values:{condition:L(M)},flows:{true:{node:j},false:{node:q}}})}},S.push(A)}else if(P==="interpolate"){let H=b.to??b.value;if(H===void 0)continue;let v={value:{value:H},duration:{value:E}};b.from!==void 0&&(v.from={value:b.from}),S.push(g("pointer/interpolate",{configuration:{pointer:typeof b.pointer=="string"?b.pointer:O(f(b,m),p(f(b,m)),b.property)},values:v}))}else if(P==="setProperty"){if(b.value===void 0)continue;S.push(g("pointer/set",{configuration:{pointer:typeof b.pointer=="string"?b.pointer:O(f(b,m),p(f(b,m)),b.property)},values:{value:{value:b.value}}}))}else if(P==="toggleVisibility"){let H=f(b,m),v=I(`__vis_${H}_${V}`,"bool",!0),$=g("variable/get",{configuration:{variable:v}}),s=g("math/not",{values:{a:L($)}}),M=g("variable/set",{configuration:{variable:v},values:{value:L(s)}});a[M].flows={out:{node:g("pointer/set",{configuration:{pointer:`/nodes/${H}/extensions/KHR_node_visibility/visible`},values:{value:L($)}})}},S.push(M)}else if(P==="cycleMaterialColor"&&Array.isArray(b.colors)&&b.colors.length>0){let H=typeof b.duration=="number"?b.duration:.25,v=`/materials/${Math.max(0,x)}/pbrMetallicRoughness/baseColorFactor`,$=I(`__color_idx_${m}_${V}`,"int",0),s=g("variable/get",{configuration:{variable:$}}),M=g("math/add",{values:{a:L(s),b:{value:1}}}),u=g("math/rem",{values:{a:L(M),b:{value:b.colors.length}}}),A=g("variable/set",{configuration:{variable:$},values:{value:L(u)}}),j={};for(let q=0;q<b.colors.length;q++){let Z=b.colors[q],W=Array.isArray(Z)&&Z.length>=3?[Z[0],Z[1],Z[2],Z[3]??1]:[1,1,1,1];j[String(q)]={node:H>0?g("pointer/interpolate",{configuration:{pointer:v},values:{value:{value:W},duration:{value:H}}}):g("pointer/set",{configuration:{pointer:v},values:{value:{value:W}}})}}a[A].flows={out:{node:g("flow/switch",{values:{selection:L(s)},flows:j})}},S.push(A)}else if(P==="playAnimation")S.push(g("animation/start",{configuration:{animation:b.animation??b.clip??0}}));else if(P==="stopAnimation")S.push(g("animation/stop"));else if(P==="sendEvent"){let H={};for(let[v,$]of Object.entries(b.values||{}))H[v]={value:$};S.push(g("event/send",{configuration:{event:d(String(b.event??b.id??"custom"))},values:H}))}}if(!S.length)return null;if(S.length===1)return S[0];let N={};return S.forEach((V,b)=>{N[String(b)]={node:V}}),g("flow/sequence",{flows:N})},R=(_,C,S)=>{let N=z(C);N!==null&&g(_,{...S?{configuration:S}:{},flows:{out:{node:N}}})};if(w.onSelect&&R("pointer/onSelect",w.onSelect,{nodeIndex:m}),w.onHoverIn&&R("pointer/onHoverIn",w.onHoverIn,{nodeIndex:m}),w.onHoverOut&&R("pointer/onHoverOut",w.onHoverOut,{nodeIndex:m}),w.onStart&&R("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[_,C]of Object.entries(w.onReceive))R("event/receive",C,{event:d(_)})}return a.length?{graphs:[{declarations:r,nodes:a,variables:l,events:h}],graph:0}:null}var Ne="__THREE_LIVE_REGISTRY__";function Me(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Ne]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Ne,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Ne]=t}}return e[Ne]}var ge=Me().plugins;function It(e){let t=Me().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function Lt(){return Me().plugins}var Ft={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function at(e,t,i,r){if(!i||i.bufferView===void 0)return null;let n=e.bufferViews?.[i.bufferView];if(!n)return null;let a=Number(i.count??0);if(!Number.isInteger(a)||a<=0)return null;let l=i.componentType??5126,h=Ft[l];if(!h)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let c=h*r,T=n.byteStride&&n.byteStride>0?n.byteStride:c,d=(n.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(d)||d<0||T<c||d+(a-1)*T+c>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(l===5126&&T===c&&d%4===0)return new Float32Array(t,d,a*r);let g=new DataView(t),I=i.normalized===!0,L=new Float32Array(a*r);for(let D=0;D<a;D++){let O=d+D*T;for(let o=0;o<r;o++){let f=O+o*h,p;switch(l){case 5126:p=g.getFloat32(f,!0);break;case 5120:p=g.getInt8(f),I&&(p=Math.max(p/127,-1));break;case 5121:p=g.getUint8(f),I&&(p/=255);break;case 5122:p=g.getInt16(f,!0),I&&(p=Math.max(p/32767,-1));break;case 5123:p=g.getUint16(f,!0),I&&(p/=65535);break;default:p=g.getUint32(f,!0),I&&(p/=4294967295)}L[D*r+o]=p}}return L}function Nt(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,n=Number(t.scale?.[0]??1),a=Number(t.scale?.[1]??1),l=Number(t.rotation??0)||0,h=Math.cos(l),c=Math.sin(l),T=(Number.isFinite(n)?n:1)*h,d=(Number.isFinite(n)?n:1)*c,g=-(Number.isFinite(a)?a:1)*c,I=(Number.isFinite(a)?a:1)*h;for(let L=0;L+1<e.length;L+=2){let D=e[L],O=e[L+1];e[L]=T*D+d*O+i,e[L+1]=g*D+I*O+r}}function Ee(e,t,i,r=!0){let n=[],a=null;try{for(let[l,h]of[[35633,t],[35632,i]]){let c=e.createShader(l);if(!c){if(r)throw new Error("Shader allocation failed");return null}if(n.push(c),e.shaderSource(c,h),e.compileShader(c),e.getShaderParameter&&!e.getShaderParameter(c,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(c)}`);return null}}if(a=e.createProgram(),!a){if(r)throw new Error("Program allocation failed");return null}for(let l of n)e.attachShader(a,l);if(e.linkProgram(a),e.getProgramParameter&&!e.getProgramParameter(a,35714)){let l=r?e.getProgramInfoLog(a):null;if(e.deleteProgram?.(a),a=null,r)throw new Error(`Program link error: ${l}`);return null}return a}finally{for(let l of n)a&&e.detachShader?.(a,l),e.deleteShader?.(l)}}function ve(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function st(e,t,i,r,n){let a=1/Math.tan(t/2);e.fill(0),e[0]=a/i,e[5]=a,e[11]=-1;let l=1/(r-n);return e[10]=(n+r)*l,e[14]=2*n*r*l,e}function nt(e,t,i,r){let[n,a,l]=t,[h,c,T]=r,[d,g,I]=i,L=n-d,D=a-g,O=l-I,o=Math.hypot(L,D,O);o<=1e-5?(L=0,D=0,O=1):(L/=o,D/=o,O/=o);let f=c*O-T*D,p=T*L-h*O,m=h*D-c*L;o=Math.hypot(f,p,m),o<=1e-5?(f=0,p=0,m=0):(f/=o,p/=o,m/=o);let y=D*m-O*p,w=O*f-L*m,x=L*p-D*f;return o=Math.hypot(y,w,x),o<=1e-5?(y=0,w=0,x=0):(y/=o,w/=o,x/=o),e[0]=f,e[1]=y,e[2]=L,e[3]=0,e[4]=p,e[5]=w,e[6]=D,e[7]=0,e[8]=m,e[9]=x,e[10]=O,e[11]=0,e[12]=-(f*n+p*a+m*l),e[13]=-(y*n+w*a+x*l),e[14]=-(L*n+D*a+O*l),e[15]=1,e}function be(e,t,i){let r=t[0],n=t[1],a=t[2],l=t[3],h=t[4],c=t[5],T=t[6],d=t[7],g=t[8],I=t[9],L=t[10],D=t[11],O=t[12],o=t[13],f=t[14],p=t[15],m=i[0],y=i[1],w=i[2],x=i[3];return e[0]=m*r+y*h+w*g+x*O,e[1]=m*n+y*c+w*I+x*o,e[2]=m*a+y*T+w*L+x*f,e[3]=m*l+y*d+w*D+x*p,m=i[4],y=i[5],w=i[6],x=i[7],e[4]=m*r+y*h+w*g+x*O,e[5]=m*n+y*c+w*I+x*o,e[6]=m*a+y*T+w*L+x*f,e[7]=m*l+y*d+w*D+x*p,m=i[8],y=i[9],w=i[10],x=i[11],e[8]=m*r+y*h+w*g+x*O,e[9]=m*n+y*c+w*I+x*o,e[10]=m*a+y*T+w*L+x*f,e[11]=m*l+y*d+w*D+x*p,m=i[12],y=i[13],w=i[14],x=i[15],e[12]=m*r+y*h+w*g+x*O,e[13]=m*n+y*c+w*I+x*o,e[14]=m*a+y*T+w*L+x*f,e[15]=m*l+y*d+w*D+x*p,e}function ot(e,t,i,r){let n=t[0],a=t[1],l=t[2],h=t[3],c=n+n,T=a+a,d=l+l,g=n*c,I=n*T,L=n*d,D=a*T,O=a*d,o=l*d,f=h*c,p=h*T,m=h*d,y=r[0],w=r[1],x=r[2];return e[0]=(1-(D+o))*y,e[1]=(I+m)*y,e[2]=(L-p)*y,e[3]=0,e[4]=(I-m)*w,e[5]=(1-(g+o))*w,e[6]=(O+f)*w,e[7]=0,e[8]=(L+p)*x,e[9]=(O-f)*x,e[10]=(1-(g+D))*x,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Ce(e,t,i=0){let r=t[0],n=t[1],a=t[2],l=t[4],h=t[5],c=t[6],T=t[8],d=t[9],g=t[10],I=g*h-c*d,L=-g*l+c*T,D=d*l-h*T,O=r*I+n*L+a*D;return!O||i>0&&(!Number.isFinite(O)||Math.abs(O)<=i)||(O=1/O,e[0]=I*O,e[1]=L*O,e[2]=D*O,e[3]=(-g*n+a*d)*O,e[4]=(g*r-a*T)*O,e[5]=(-d*r+n*T)*O,e[6]=(c*n-a*h)*O,e[7]=(-c*r+a*l)*O,e[8]=(h*r-n*l)*O),e}function Et(e,t){let i=t[0],r=t[1],n=t[2],a=t[3],l=t[4],h=t[5],c=t[6],T=t[7],d=t[8],g=t[9],I=t[10],L=t[11],D=t[12],O=t[13],o=t[14],f=t[15],p=i*h-r*l,m=i*c-n*l,y=i*T-a*l,w=r*c-n*h,x=r*T-a*h,z=n*T-a*c,R=d*O-g*D,_=d*o-I*D,C=d*f-L*D,S=g*o-I*O,N=g*f-L*O,V=I*f-L*o,b=p*V-m*N+y*S+w*C-x*_+z*R;return b?(b=1/b,e[0]=(h*V-c*N+T*S)*b,e[1]=(n*N-r*V-a*S)*b,e[2]=(O*z-o*x+f*w)*b,e[3]=(I*x-g*z-L*w)*b,e[4]=(c*C-l*V-T*_)*b,e[5]=(i*V-n*C+a*_)*b,e[6]=(o*y-D*z-f*m)*b,e[7]=(d*z-I*y+L*m)*b,e[8]=(l*N-h*C+T*R)*b,e[9]=(r*C-i*N-a*R)*b,e[10]=(D*x-O*y+f*p)*b,e[11]=(g*y-d*x-L*p)*b,e[12]=(h*_-l*S-c*R)*b,e[13]=(i*S-r*_+n*R)*b,e[14]=(O*m-D*w-o*p)*b,e[15]=(d*w-g*m+I*p)*b,e):null}function lt(e,t,i,r,n){let a=n[0]*t+n[4]*i+n[8]*r+n[12],l=n[1]*t+n[5]*i+n[9]*r+n[13],h=n[2]*t+n[6]*i+n[10]*r+n[14],c=n[3]*t+n[7]*i+n[11]*r+n[15],T=c!==0?1/c:1;e[0]=a*T,e[1]=l*T,e[2]=h*T}function Ot(e,t,i,r,n,a,l,h,c,T,d,g,I,L,D,O,o=0){let f=T-l,p=d-h,m=g-c,y=I-l,w=L-h,x=D-c,z=n*x-a*w,R=a*y-r*x,_=r*w-n*y,C=f*z+p*R+m*_;if(C>-1e-7&&C<1e-7)return!1;let S=1/C,N=e-l,V=t-h,b=i-c,P=S*(N*z+V*R+b*_);if(P<-o||P>1+o)return!1;let E=V*m-b*p,H=b*f-N*m,v=N*p-V*f,$=S*(r*E+n*H+a*v);if($<-o||P+$>1+o)return!1;let s=S*(y*E+w*H+x*v);if(s>1e-4&&s<O.distance){O.distance=s,O.point=[e+r*s,t+n*s,i+a*s];let M=p*x-m*w,u=m*y-f*x,A=f*w-p*y,j=Math.hypot(M,u,A)||1;return O.normal=[M/j,u/j,A/j],!0}return!1}function ut(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let d=0;d<i;d++)r.push(ve());if(i===0)return r;let n=new Set;for(let d of e.nodes)if(Array.isArray(d.children))for(let g of d.children)n.add(g);let a=new Set,l=128,h=(d,g,I=0)=>{if(I>l||d<0||d>=i||a.has(d))return;a.add(d);let L=e.nodes[d];if(!L)return;let D=ve();if(t&&t[d])D.set(t[d]);else if(L.matrix&&L.matrix.length===16)D.set(L.matrix);else{let o=L.translation||[0,0,0],f=L.rotation||[0,0,0,1],p=L.scale||[1,1,1];ot(D,f,o,p)}let O=r[d];if(g?be(O,g,D):O.set(D),Array.isArray(L.children))for(let o of L.children)typeof o=="number"&&h(o,O,I+1)},c=[],T=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(T&&Array.isArray(T.nodes))c.push(...T.nodes);else for(let d=0;d<i;d++)n.has(d)||c.push(d);for(let d of c)h(d,null);for(let d=0;d<i;d++)!n.has(d)&&!c.includes(d)&&h(d,null);return r}var ht=["neutral","reinhard","none","aces","agx"];function We(e){let t=String(e??"").trim().toLowerCase();return ht.includes(t)?t:"neutral"}function $t(e){return ht.indexOf(We(e))}function kt(e){return new TextDecoder().decode(e)}var ct=Me().decoders;function Vt(e,t){ct.set(e.toLowerCase(),t)}function Oe(e){return ct.get(e.toLowerCase())}function mt(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 I=i.getUint8(0);throw I===123||I===32||I===10||I===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let n=i.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let a=i.getUint32(8,!0),l=12,h=null,c=null;for(;l+8<=a&&l+8<=t.byteLength;){let I=i.getUint32(l,!0),L=i.getUint32(l+4,!0),D=l+8;if(D+I>t.byteLength)throw new Error(`Truncated GLB chunk: required ${D+I} bytes, buffer has ${t.byteLength}`);if(L===1313821514){let O=new Uint8Array(t,D,I),o=kt(O);h=JSON.parse(o,(f,p)=>f==="__proto__"||f==="constructor"||f==="prototype"?void 0:p)}else L===5130562&&(c=t.slice(D,D+I));l=D+I}if(!h)throw new Error("Missing JSON chunk in GLB");let T=h.extensionsRequired||[];for(let[I,L]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(T.includes(I)&&!Oe(L))throw new Error(`Model requires ${I}. Register a decoder via ThreeLiveElement.registerDecoder('${L}', decoder).`);let d=c||new ArrayBuffer(0),g={gltf:h,bin:d,animations:[],animationsParsed:!1};for(let I of ge)I.onParseGLB?.(g);return g}function ft(e,t=ut(e)){let i=e?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],n=new Set,a=(l,h,c,T)=>{let d=l.type,g=d==="directional"||d==="point"||d==="spot"?d:"ambient",I=h?h[8]:-.5,L=h?h[9]:-1,D=h?h[10]:-.8,O=Math.hypot(I,L,D)||1,o=l.extras?.shadow??c,f=l.name||T,p={type:g,color:l.color||[1,1,1],intensity:l.intensity??1};f&&(p.name=f),h&&(p.position=[h[12],h[13],h[14]]),g==="directional"&&h?p.direction=[I/O,L/O,D/O]:(g==="spot"&&(p.direction=h?[-I/O,-L/O,-D/O]:[0,-1,0],p.innerConeAngle=l.spot?.innerConeAngle??0,p.outerConeAngle=l.spot?.outerConeAngle??Math.PI/4),p.range=l.range),o&&(p.shadow=o),r.push(p)};return(e.nodes||[]).forEach((l,h)=>{let c=l?.extensions?.KHR_lights_punctual?.light;typeof c=="number"&&i[c]&&(n.add(c),a(i[c],t[h],l.extras?.shadow,l.name))}),i.forEach((l,h)=>{n.has(h)||a(l)}),r}function Ut(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 $e(e){if(Ut(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return mt(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ze=`#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
|
+
}`,Bt=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -57,117 +57,81 @@ in vec4 vInstTint;
|
|
|
57
57
|
#define uBaseColor (uBaseColor*vInstTint)
|
|
58
58
|
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
59
59
|
uniform vec2 uClearcoat;
|
|
60
|
-
uniform vec3 uCameraPos,uAmbientColor;
|
|
61
|
-
uniform
|
|
62
|
-
uniform
|
|
60
|
+
uniform vec3 uCameraPos,uAmbientColor,uEmissiveFactor;
|
|
61
|
+
uniform mat3 uHemi;
|
|
62
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uEmissiveTexture;
|
|
63
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uHasEmissiveTexture;
|
|
63
64
|
uniform float uNormalScale,uOcclusionStrength;
|
|
64
|
-
/*XRD_U*/
|
|
65
|
+
/*XRD_U*//*SHD_U*/
|
|
65
66
|
uniform vec2 uViewportSize;
|
|
66
67
|
uniform vec4 uSectionPlane;
|
|
67
68
|
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
68
69
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
|
|
69
70
|
uniform vec2 uPointLightSpotCone[2];
|
|
70
71
|
out vec4 fragColor;
|
|
71
|
-
|
|
72
72
|
vec2 envBRDF(float r,float n){
|
|
73
|
-
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
74
|
-
vec4 rv=r*c0+c1;
|
|
73
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04),rv=r*c0+c1;
|
|
75
74
|
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
76
75
|
return vec2(-1.04,1.04)*a+rv.zw;
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
80
78
|
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
vec3 getStudioRadiance(vec3 R,float r){
|
|
84
|
-
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
81
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35)),fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
85
82
|
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
86
|
-
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
87
83
|
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
88
84
|
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
89
|
-
|
|
90
|
-
return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
85
|
+
return mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5)+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
91
86
|
}
|
|
92
|
-
|
|
93
|
-
vec3
|
|
94
|
-
vec3
|
|
95
|
-
|
|
96
|
-
vec3
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
vec2 duv2=dFdy(uv);
|
|
100
|
-
vec3 dp2perp=cross(dp2,N);
|
|
101
|
-
vec3 dp1perp=cross(N,dp1);
|
|
102
|
-
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
103
|
-
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
104
|
-
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
105
|
-
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
87
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D m,float s){
|
|
88
|
+
vec3 q=texture(m,uv).xyz*2.0-1.0;q.xy*=s;
|
|
89
|
+
vec3 p1=dFdx(vWorldPos),p2=dFdy(vWorldPos),c2=cross(p2,N),c1=cross(N,p1);
|
|
90
|
+
vec2 u1=dFdx(uv),u2=dFdy(uv);
|
|
91
|
+
vec3 T=c2*u1.x+c1*u2.x,B=c2*u1.y+c1*u2.y;
|
|
92
|
+
float k=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
93
|
+
return normalize(mat3(T*k,B*k,N)*normalize(q));
|
|
106
94
|
}
|
|
107
|
-
|
|
108
95
|
vec2 equirectangularUV(vec3 dir){
|
|
109
96
|
vec3 d=normalize(dir);
|
|
110
|
-
|
|
111
|
-
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
112
|
-
return vec2(u,1.0-v);
|
|
97
|
+
return vec2(atan(d.z,d.x)*0.15915494309+0.5,0.5-asin(clamp(d.y,-1.0,1.0))*0.31830988618);
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
float
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if(peak<startCompression)return color;
|
|
123
|
-
const float d=1.0-startCompression;
|
|
124
|
-
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
125
|
-
color*=newPeak/peak;
|
|
126
|
-
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
127
|
-
return mix(color,newPeak*vec3(1.0),g);
|
|
99
|
+
vec3 neutralToneMapping(vec3 c){
|
|
100
|
+
float x=min(c.r,min(c.g,c.b));
|
|
101
|
+
c-=x<0.08?x-6.25*x*x:0.04;
|
|
102
|
+
float p=max(c.r,max(c.g,c.b));
|
|
103
|
+
if(p<0.76)return c;
|
|
104
|
+
float n=1.0-0.0576/(p-0.52);
|
|
105
|
+
c*=n/p;
|
|
106
|
+
return mix(c,vec3(n),1.0-1.0/(0.15*(p-n)+1.0));
|
|
128
107
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
color*=0.6;
|
|
132
|
-
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
108
|
+
vec3 acesToneMapping(vec3 c){
|
|
109
|
+
c*=0.6;return clamp((c*(2.51*c+0.03))/(c*(2.43*c+0.59)+0.14),0.0,1.0);
|
|
133
110
|
}
|
|
134
|
-
|
|
135
|
-
vec3
|
|
136
|
-
|
|
137
|
-
vec3
|
|
138
|
-
|
|
139
|
-
0.
|
|
140
|
-
0.
|
|
141
|
-
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
142
|
-
vec3 x2=ev*ev;
|
|
143
|
-
vec3 x4=x2*x2;
|
|
144
|
-
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
145
|
-
vec3 outset=vec3(
|
|
146
|
-
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
147
|
-
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
148
|
-
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
149
|
-
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
111
|
+
vec3 agxToneMapping(vec3 c){
|
|
112
|
+
c=max(c,vec3(0.0));
|
|
113
|
+
vec3 i=mat3(0.84247906,0.04232824,0.04237565,0.0784336,0.87846864,0.0784336,0.07922375,0.07916613,0.87914297)*c;
|
|
114
|
+
vec3 e=clamp((log2(max(i,vec3(1e-6)))+12.47393)/16.5,0.0,1.0),x2=e*e,x4=x2*x2;
|
|
115
|
+
vec3 s=15.5*x4*x2-40.14*x4*e+31.96*x4-6.868*x2*e+0.4298*x2+0.1191*e-0.00232;
|
|
116
|
+
vec3 o=mat3(1.196879,-0.05289685,-0.05297164,-0.09802088,1.15190313,-0.09804345,-0.09902974,-0.09896118,1.15107367)*s;
|
|
117
|
+
return clamp(pow(max(o,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
150
118
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if(mode==0)return neutralToneMapping(color);
|
|
154
|
-
if(mode==1)return color/(color+vec3(1.0));
|
|
155
|
-
if(mode==3)return acesToneMapping(color);
|
|
156
|
-
if(mode==4)return agxToneMapping(color);
|
|
157
|
-
return color;
|
|
119
|
+
vec3 applyToneMapping(vec3 c,int m){
|
|
120
|
+
return m==0?neutralToneMapping(c):m==1?c/(c+vec3(1.0)):m==3?acesToneMapping(c):m==4?agxToneMapping(c):c;
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
122
|
+
vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 b,float e,float w){
|
|
123
|
+
float h=max(dot(N,normalize(L+V)),0.0);
|
|
124
|
+
return b*max(dot(N,L),0.0)*0.75+vec3(pow(h,e)*w+uClearcoat.x*pow(h,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
163
125
|
}
|
|
164
126
|
|
|
165
127
|
void main(){
|
|
166
128
|
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
167
129
|
vec4 base=uBaseColor;
|
|
168
130
|
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
131
|
+
if(base.a<0.004)discard;
|
|
132
|
+
vec3 em=uHasEmissiveTexture==1?uEmissiveFactor*texture(uEmissiveTexture,vUV).rgb:uEmissiveFactor;
|
|
169
133
|
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
170
|
-
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
134
|
+
vec3 unlit=base.rgb+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
171
135
|
fragColor=vec4(unlit,base.a);
|
|
172
136
|
return;
|
|
173
137
|
}
|
|
@@ -199,7 +163,7 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
|
199
163
|
vec3 directLight=vec3(0.0);
|
|
200
164
|
for(int i=0;i<2;i++){
|
|
201
165
|
if(i>=uNumDirLights)break;
|
|
202
|
-
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]
|
|
166
|
+
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]/*SHD_D*/;
|
|
203
167
|
}
|
|
204
168
|
for(int i=0;i<2;i++){
|
|
205
169
|
if(i>=uNumPointLights)break;
|
|
@@ -208,7 +172,7 @@ float dist=length(toLight);
|
|
|
208
172
|
vec3 L=toLight/max(dist,0.0001);
|
|
209
173
|
float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
|
|
210
174
|
spotAtt*=spotAtt;
|
|
211
|
-
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)
|
|
175
|
+
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)/*SHD_P*/;
|
|
212
176
|
}
|
|
213
177
|
|
|
214
178
|
vec3 R=reflect(-V,N);
|
|
@@ -228,8 +192,9 @@ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
|
228
192
|
}
|
|
229
193
|
|
|
230
194
|
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
195
|
+
directLight+=kD*base.rgb*mix(uHemi[1],uHemi[0],dot(N,uHemi[2])*0.5+0.5)*occ;
|
|
231
196
|
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
232
|
-
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
197
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
233
198
|
if(uClearcoat.x>0.0){
|
|
234
199
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
235
200
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
@@ -239,130 +204,147 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
204
|
float outAlpha=base.a;
|
|
240
205
|
/*XRD_O*/
|
|
241
206
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
207
|
+
}`,Ht=`#version 300 es
|
|
243
208
|
layout(location=0) in vec3 aPosition;
|
|
244
209
|
uniform mat4 uMVP;
|
|
245
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
210
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,jt=`#version 300 es
|
|
246
211
|
precision highp float;
|
|
247
212
|
uniform vec4 uColorId;
|
|
248
213
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function Oe(e,t,i){let r={};for(let a of i)r[a]=e.getUniformLocation(t,a);return r}var Ze=["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 Je(){let e=ge().xrDepthShader;return{fs:Ct.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...Ze,...e.uniformNames]:Ze}}function It(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 Ue(e,t,i,r,a,s,m,p){if(r===void 0||!t.accessors?.[r])return null;let g=ze(t,i,t.accessors[r],s);if(!g)return null;p&&(g=g.slice(),bt(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 Be(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function Qe(e,t,i){let r=Je(),a=Ye,s=r.fs,m=!1;for(let g of ue)if(g.onResolveShader){let c=g.onResolveShader(t,i,a,s);c&&(a=c.vs,s=c.fs,m=!0)}let p=m?$e(e,a,s):null;return{program:p,uniforms:p?Oe(e,p,r.uniforms):null}}function _t(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 Ft(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 Ht=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),et=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function De(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function tt(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 it(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=et,r){let a={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Lt(e,t,i,r,a)}catch(s){let m=a.mesh&&!a.meshes.includes(a.mesh)?[...a.meshes,a.mesh]:a.meshes;it(e,m,a.gpuTextures),a.vao&&e.deleteVertexArray(a.vao);for(let p of a.buffers)e.deleteBuffer(p);throw s}}function Lt(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=we("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=wt(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=It(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]:he(),f=new Float32Array(9);ye(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=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),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=ze(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,V=Z(Y,ie),K=new Float32Array(H*16),W=he();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];Ge(W,z,N,X),K.set(W,I*16)}if(x.instanceMatrices=K,V){let I=new Float32Array(H*3);for(let N=0;N<H;N++)I[N*3]=V[N*ie],I[N*3+1]=V[N*ie+1],I[N*3+2]=V[N*ie+2];x.instanceColors=I}}}for(let d of E.primitives||[]){if(d.extensions?.KHR_draco_mesh_compression){let q=we("draco");q&&q.decodePrimitive(s,d,p)}let U=[],j=e.createVertexArray();a.vao=j,a.buffers=U,e.bindVertexArray(j);let B=_t(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=Q=>{for(let ee=0;ee<3;ee++){let ce=Q[12+ee],ae=Q[12+ee];for(let se=0;se<3;se++){let oe=Q[se*4+ee]*Y.min[se],ne=Q[se*4+ee]*Y.max[se];ce+=oe<ne?oe:ne,ae+=oe>ne?oe:ne}ce<A[ee]&&(A[ee]=ce),ae>w[ee]&&(w[ee]=ae)}};if(x.instanceMatrices&&x.instanceMatrices.length>=16){let Q=x.instanceMatrices.length>>4,ee=he();for(let ce=0;ce<Q;ce++){let ae=x.instanceMatrices.subarray(ce*16,ce*16+16);fe(ee,G,ae),q(ee)}}else q(G)}let Z=Ue(e,s,p,d.attributes.POSITION,0,3,U);Ue(e,s,p,d.attributes.NORMAL,1,3,U),Ue(e,s,p,d.attributes.TEXCOORD_0,2,2,U,Ft(s,d));let te=0,re=5123,k=null;if(d.indices!==void 0){let q=s.accessors[d.indices],Q=(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 ee=e.createBuffer();U.push(ee),e.bindBuffer(34963,ee),q.componentType===5125?k=new Uint32Array(p,Q,q.count):q.componentType===5121?k=Uint16Array.from(new Uint8Array(p,Q,q.count)):k=Q%2===0?new Uint16Array(p,Q,q.count):new Uint16Array(p.slice(Q,Q+q.count*2)),e.bufferData(34963,k,35044)}else te=Y.count;let ie={};for(let q of ue)if(q.onBuildPrimitiveVAO){let Q=q.onBuildPrimitiveVAO(e,j,d,s,p);Q&&(ie[q.name]=Q)}e.bindVertexArray(null);let V=s.materials&&d.material!==void 0?s.materials[d.material]:null,{program:K,uniforms:W}=Qe(e,d,V),I=tt(V,C),N=!!(V?.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(Q=>Number(Q)|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],O=w[2]-A[2],F=Math.max(Math.hypot(P,$,O)/2,.5),_=[A[0],A[1],A[2]],T=[w[0],w[1],w[2]],L=t.animations;if(!L){for(let R of ue)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 Te(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 at=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=he(),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=he(),this.viewMatrix=he(),this.activeViewMatrix=null,this.modelMatrix=he(),this.mvpMatrix=he(),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:he(),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=Be(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=Ve(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){At(e,t)}static getDecoder(e){return we(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=Je();this.renderProg=$e(e,Ye,t.fs),this.pickProg=$e(e,Dt,St),this.uRender=Oe(e,this.renderProg,t.uniforms),this.uPick=Oe(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ue)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 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 c=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;c!==void 0&&(this.exposure=Be(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(qe(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of ue)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Ce(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Ce(e),{meshes:r}=rt(this.gl,i,et,()=>this.render());if(t)for(let a of r)a.transform[12]+=t[0],a.transform[13]+=t[1],a.transform[14]+=t[2],ye(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),ye(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=Be(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=Ve(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ue)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ue)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,tt(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=Qe(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 ue)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=he();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[$,O,F]=Te(this),_=[r-$,a-O,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=he();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,O=($&255)/255,F=($>>8&255)/255,_=($>>16&255)/255;r.uniform4f(this.uPick.uColorId,O,F,_,1),fe(this.modelMatrix,this.modelRootMatrix,P.transform);let T=P.instanceMatrices;if(T&&T.length>=16){let L=T.length>>4,R=he();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),De(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),De(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]=Te(this),A=he();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 $=he();if(!yt($,this.mvpMatrix))continue;let O=(g+.5)/a*2-1,F=(c+.5)/s*2-1,_=[0,0,0],T=[0,0,0];Ke(_,O,F,-1,$),Ke(T,O,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;Mt(_[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){ye(this.normalMatrix,this.modelMatrix);let V=this.normalMatrix,K=o.normal[0],W=o.normal[1],I=o.normal[2],N=V[0]*K+V[3]*W+V[6]*I,z=V[1]*K+V[4]*W+V[7]*I,X=V[2]*K+V[5]*W+V[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 ue)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);Ee(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;ke(this.viewMatrix,Te(this),i,[0,1,0]),fe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ye(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 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(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of ue)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 ue)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 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(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,[O,F,_]=Te(this),T=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),R=.032,n=he(),E=he(),G=[O-T*R,F,_-L*R],f=[$[0]-T*R*.25,$[1],$[2]-L*R*.25];Ee(n,this.fov,l/u,.1,P),ke(E,G,f,[0,1,0]);let x=he(),o=he(),d=[O+T*R,F,_+L*R],U=[$[0]+T*R*.25,$[1],$[2]+L*R*.25];Ee(x,this.fov,M/u,.1,P),ke(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=he(),p=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=p,fe(m,e?.projMatrix??this.projMatrix,p);let g=ge().xrDepthShader,c=Tt(this.toneMapping),[v,y,D]=e?e.eyePos:Te(this);for(let w of ue)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),ye(l.normalMatrix,this.modelMatrix);let P=l.extras?.xr?.stereo||l.userData?.xr?.stereo,$=0,O=0,F=1,_=1;P==="sbs"?(F=.5,$=h==="right"?.5:0):P==="ou"&&(_=.5,O=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,$,O,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 ue)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=he(),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),ye(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)),De(t,T)}else De(t,T)}}};if(A(!1),b){for(let w of ue)w.onBeforeTransmissivePass?.(t,this);A(!0)}for(let w of ue)w.onAfterRender?.(t,this,m,e?.eye??"none",[i,r,a,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){it(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 ue)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()}};at.registerPlugin=gt,at.getRegisteredPlugins=vt;function Nt(e){return e+3&-4}var J=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function st(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ot(e,t=0){let[i,r,a,,s,m,p,,g,c,v,,y,D,S]=Array.from({length:15},(o,d)=>J(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,O=m*w,F=p*w,_=g*u,T=c*u,L=v*u,R=l+O+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>O&&l>L){let o=2*Math.sqrt(Math.max(0,1+l-O-L));o>1e-8&&(f=(F-T)/o,n=.25*o,E=($+M)/o,G=(_+P)/o)}else if(O>L){let o=2*Math.sqrt(Math.max(0,1+O-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-O));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 $t(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 be=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function nt(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:be(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function lt(e,t){return ht(e,t)[0]}function ht(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),V=Z(o.emissiveMap),K=Z(o.aoMap),W={name:o.name||"",pbrMetallicRoughness:Y,doubleSided:o.side===2||!!o.doubleSided,...ie?{normalTexture:ie}:{},...V?{emissiveTexture:V}:{},...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=Nt(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=J(x?x[12]:f.position?.x,0),d=J(x?x[13]:f.position?.y,0),U=J(x?x[14]:f.position?.z,0),j=f.target,B=j?.parent?j?.matrixWorld?.elements:void 0,Y=J(B?B[12]:j?.position?.x,0),H=J(B?B[13]:j?.position?.y,0),Z=J(B?B[14]:j?.position?.z,0),te=Y-o,re=H-d,k=Z-U,ie=Math.hypot(te,re,k),V=Math.max(.01,Math.min(Math.PI/2,J(f.angle,Math.PI/3))),K=Math.max(0,Math.min(1,J(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:V,innerConeAngle:Math.max(0,V*(1-K)),range:Math.max(0,J(f.distance,0))}:f.type==="point"?{range:Math.max(0,J(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?.(),ge().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=J(f.position?.x,0),j=J(f.position?.y,0),B=J(f.position?.z,0),Y=J(f.quaternion?.x,0),H=J(f.quaternion?.y,0),Z=J(f.quaternion?.z,0),te=J(f.quaternion?.w,1),re=J(f.scale?.x,1),k=J(f.scale?.y,1),ie=J(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=$t(f.userData.xr);d.extensions={...d.extensions||{},MOZ_hubs_components:W,ANDROID_xr_scenecore:W},ge().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 Q=f.userData?.variants;if(Q&&typeof Q=="object"){let ae=new Map;for(let se of Object.keys(Q)){if(!se||se==="__proto__"||se==="constructor"||se==="prototype")continue;let oe=Q[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 pe=w(oe),de=ae.get(pe);de||(de=[],ae.set(pe,de)),de.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 ee=f;if(ee.isInstancedMesh&&typeof ee.count=="number"&&ee.count>0&&ee.instanceMatrix?.array){let ae=Math.min(1e4,Math.floor(ee.count)),se=ee.instanceMatrix.array,oe=new Float32Array(ae*3),ne=new Float32Array(ae*4),pe=new Float32Array(ae*3);for(let le=0;le<ae;le++){let{t:ve,r:Me,s:Ne}=ot(se,le*16);oe[le*3]=ve[0],oe[le*3+1]=ve[1],oe[le*3+2]=ve[2],ne[le*4]=Me[0],ne[le*4+1]=Me[1],ne[le*4+2]=Me[2],ne[le*4+3]=Me[3],pe[le*3]=Ne[0],pe[le*3+1]=Ne[1],pe[le*3+2]=Ne[2]}let de={TRANSLATION:l(oe,"VEC3",0,5126,ae),ROTATION:l(ne,"VEC4",0,5126,ae),SCALE:l(pe,"VEC3",0,5126,ae)};if(ee.instanceColor?.array&&ee.instanceColor.array.length>=ae*3){let le=new Float32Array(ee.instanceColor.array.subarray(0,ae*3));de._COLOR_0=l(le,"VEC3",0,5126,ae)}d.extensions={...d.extensions||{},EXT_mesh_gpu_instancing:{attributes:de}},g.add("EXT_mesh_gpu_instancing")}let ce=m.length;m.push({primitives:[X],name:f.name,...d.extras?{extras:d.extras}:{}}),d.mesh=ce}}let V=p.length;p.push(d),c.push(f),x.push(V);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 O=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 O=="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=>[J(k.position?.x,0),J(k.position?.y,0),J(k.position?.z,0),J(k.quaternion?.x,0),J(k.quaternion?.y,0),J(k.quaternion?.z,0),J(k.quaternion?.w,1),J(k.scale?.x,1),J(k.scale?.y,1),J(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{O(ie)}catch{}for(let V=0;V<c.length;V++){let K=c[V];j[V][k*3]=J(K.position?.x,0),j[V][k*3+1]=J(K.position?.y,0),j[V][k*3+2]=J(K.position?.z,0);let W=J(K.quaternion?.x,0),I=J(K.quaternion?.y,0),N=J(K.quaternion?.z,0),z=J(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,Q=B[V];Q[q]*W+Q[q+1]*I+Q[q+2]*N+Q[q+3]*z<0&&(W=-W,I=-I,N=-N,z=-z)}B[V][k*4]=W,B[V][k*4+1]=I,B[V][k*4+2]=N,B[V][k*4+3]=z,Y[V][k*3]=J(K.scale?.x,1),Y[V][k*3+1]=J(K.scale?.y,1),Y[V][k*3+2]=J(K.scale?.z,1)}}for(let k=0;k<c.length;k++){let ie=c[k],V=U[k];ie.position?.set(V[0],V[1],V[2]),ie.quaternion?.set(V[3],V[4],V[5],V[6]),ie.scale?.set(V[7],V[8],V[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],V=(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(V(j[k],3,0),j[k],"VEC3","translation"),K(V(B[k],4,3),B[k],"VEC4","rotation"),K(V(Y[k],3,7),Y[k],"VEC3","scale")}re.length>0&&F.push({name:"ProceduralLoop",samplers:te,channels:re})}let _=je(p,m,e.userData),T=[],L=[],R=[];for(let f=0;f<p.length;f++){let x=p[f],o=nt(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:be(d.pitch,.25,4,1)}}:{}});let re=R.length,k=be(d.refDistance,.05,100,1),ie=be(d.coneInnerAngle,0,360,360),V=be(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:be(d.maxDistance,k,500,Math.max(k,25)),rolloffFactor:be(d.rolloffFactor,0,10,1),coneInnerAngle:+(ie*Math.PI/180).toFixed(6),coneOuterAngle:+(V*Math.PI/180).toFixed(6),coneOuterGain:be(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 Se(e){return new TextEncoder().encode(e)}function Et(e,t){let{gltf:i,bin:r}=lt(e,t),a=JSON.stringify(i),s=Se(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 He(e,t){let[i,r]=ht(e,t);return Ie(i,r)}function Ie(e,t){let i=[],r=e.gltf,a=ge().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,$)=>st(b,Pe(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 O=$[2].replace(/\s+/g,""),F=O.endsWith("==")?2:O.endsWith("=")?1:0,_=new Uint8Array((O.length*3>>2)-F),T=R=>{let n=O.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<O.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,$,O){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:$}:{},...O?{bias:O}:{}}}function l(P){let $=p[P];if(!$)throw new Error(`Accessor ${P} not found`);let O=g[$.bufferView||0],F=(O.byteOffset||0)+($.byteOffset||0),_=O.byteLength||0;return{acc:$,buffer:m.slice(F,F+_)}}function M(P,$,O,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],Q=z[X*3+1],ee=z[X*3+2],ce=Math.hypot(q,Q,ee)||1;o[X*3]=q/ce,o[X*3+1]=Q/ce,o[X*3+2]=ee/ce}}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,V=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=(ve,Me)=>Array.isArray(ve)&&ve.length>=3?[ve[0],ve[1],ve[2]]:Me;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,Q=u(N.baseColorTexture,q?[H[0],H[1],H[2],X]:void 0),ee=I.extras?.avgColor;!Q&&Array.isArray(ee)&&ee.length>=3&&(H=[H[0]*ee[0],H[1]*ee[1],H[2]*ee[2]]),typeof N.roughnessFactor=="number"&&(Z=N.roughnessFactor),typeof N.metallicFactor=="number"&&(te=N.metallicFactor);let ce=typeof N.roughnessFactor=="number"?N.roughnessFactor:1,ae=typeof N.metallicFactor=="number"?N.metallicFactor:1,se=u(N.metallicRoughnessTexture,ce!==1||ae!==1?[1,ce,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),pe=u(I.normalTexture,[2,2,2,1],[-1,-1,-1,0]),de=u(I.occlusionTexture);(Q||se||pe||ne||de)&&(W=[Q,se,pe,ne,de]);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),V=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:V,emissiveColor:K,...W?{textures:W}:{},xrTraits:O||T.extras?.xr,...F?{invisible:!0}:{}})}return _}if(y.length>0){let P=new Float32Array(0),$=new Uint16Array(0),O=(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?[J(x[0],o),J(x[1],o),J(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 V=ot(d.matrix);U=V.t,j=V.r,B=V.s}else U=F(d.translation,0),Array.isArray(d.rotation)&&d.rotation.length>=4&&(j=[J(d.rotation[0],0),J(d.rotation[1],0),J(d.rotation[2],0),J(d.rotation[3],1)]),B=F(d.scale,1);let Y,H=L.get(x);if(H){let V=O(H.input,1);if(V&&V.length>0){let K=O(H.t,3),W=O(H.r,4),I=O(H.s,3),N=Array.from(V),z=[],X=[],q=[];for(let Q=0;Q<V.length;Q++)z.push(_(K,Q,U)),X.push(T(W,Q,j)),q.push(_(I,Q,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=(V,K,W)=>({name:V,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 V=d.name||v[d.mesh]?.name||`Mesh_${x}`,K=M(d.mesh,V,re,ie),W=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(W&&typeof W=="object"&&K.length>0){let I=O(W.TRANSLATION,3),N=O(W.ROTATION,4),z=O(W.SCALE,3),X=O(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 Q=[];for(let ee=0;ee<q;ee++){let ce=_(I,ee,[0,0,0]),ae=T(N,ee,[0,0,0,1]),se=_(z,ee,[1,1,1]);for(let oe of K){let ne=oe.color||[.8,.8,.8],pe=X&&X.length>=(ee+1)*3;Q.push({...oe,name:`${oe.name}_${ee}`,materialName:pe?`${oe.materialName}_inst_${ee}`:oe.materialName,color:pe?[ne[0]*X[ee*3],ne[1]*X[ee*3+1],ne[2]*X[ee*3+2]]:oe.color,translation:ce,rotation:ae,scale:se})}}f(Z,Q),o.push(k(V,Q,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(V,I,ie))}}else{let V=[];f(Z,V),o.push(k(d.name||`Group_${x}`,V,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 Pe(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 Ae(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function me(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)=>`(${me(e)}, ${me(t)}, ${me(i)})`,_e=(e,t,i,r)=>`(${me(e)}, ${me(t)}, ${me(i)}, ${me(r)})`;function ut(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 kt(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${me(e[r*2])}, ${me(1-e[r*2+1])})`;return i.join(", ")}function Vt(e){return Array.from(e).join(", ")}function Fe(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=Pe(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 = ${
|
|
214
|
+
void main(){fragColor=uColorId;}`;function ke(e,t,i){let r={};for(let n of i)r[n]=e.getUniformLocation(t,n);return r}var zt="uMVP uModel uInstanced uViewProj uNormalMatrix uUvTransform uBaseColor uMetallic uRoughness uClearcoat uEmissive uCameraPos uBaseColorTexture uHasTexture uMetallicRoughnessTexture uHasMetallicRoughnessTexture uNormalTexture uHasNormalTexture uNormalScale uOcclusionTexture uHasOcclusionTexture uOcclusionStrength uEmissiveFactor uEmissiveTexture uHasEmissiveTexture uToneMapping uEnvironmentMap uHasEnvironmentMap uAmbientColor uHemi uNumDirLights uDirLightDir uDirLightColor uNumPointLights uPointLightPos uPointLightColor uPointLightSpotDir uPointLightSpotCone uEnvIntensity uExposure uViewportSize uSectionPlane uSectionEnabled".split(" ");function Ye(){let e=Me(),t=e.xrDepthShader,i=e.shadowMapShader;return{fs:Bt.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||"").replace("/*SHD_U*/",i?.uniformsGLSL||"").replace("/*SHD_D*/",i?.dirGLSL||"").replace("/*SHD_P*/",i?.ptGLSL||""),uniforms:[...zt,...t?.uniformNames||[],...i?.uniformNames||[]]}}function Gt(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 Qe(e,t,i,r,n,a,l,h){if(r===void 0||!t.accessors?.[r])return null;let c=at(t,i,t.accessors[r],a);if(!c)return null;h&&(c=c.slice(),Nt(c,h));let T=e.createBuffer();return l.push(T),e.bindBuffer(34962,T),e.bufferData(34962,c,35044),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,a,5126,!1,0,0),c}function Je(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function dt(e,t,i){let r=Ye(),n=Ze,a=r.fs,l=!1;for(let c of ge)if(c.onResolveShader){let T=c.onResolveShader(t,i,n,a);T&&(n=T.vs,a=T.fs,l=!0)}let h=l?Ee(e,n,a):null;return{program:h,uniforms:h?ke(e,h,r.uniforms):null}}function Kt(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let n=r.length>>4,a=t.instanceColors,l=new Float32Array(n*20);for(let c=0;c<n;c++)l.set(r.subarray(c*16,c*16+16),c*20),l[c*20+16]=a?a[c*3]:1,l[c*20+17]=a?a[c*3+1]:1,l[c*20+18]=a?a[c*3+2]:1,l[c*20+19]=1;let h=e.createBuffer();i.push(h),e.bindBuffer(34962,h),e.bufferData(34962,l,35044);for(let c=0;c<5;c++)e.enableVertexAttribArray(8+c),e.vertexAttribPointer(8+c,4,5126,!1,80,c*16),e.vertexAttribDivisor(8+c,1);return!0}function Xt(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 n of r){let a=n?.extensions?.KHR_texture_transform;if(a&&typeof a=="object")return a}return null}var ai=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),pt=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ve(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function gt(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,n=e?.emissiveFactor,a=e?.extensions?.KHR_materials_clearcoat,l=h=>h!==void 0&&t[h.index]?t[h.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:l(i?.baseColorTexture),metallicRoughnessTexture:l(i?.metallicRoughnessTexture),normalTexture:l(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:l(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,emissiveTexture:l(e?.emissiveTexture),emissiveFactor:Array.isArray(n)&&n.length>=3?[n[0],n[1],n[2]]:[0,0,0],isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function vt(e,t,i){let r=new Set,n=a=>{a&&!r.has(a)&&(r.add(a),e.deleteTexture(a))};for(let a of t)for(let l of a.primitives){if(l.vao&&e.deleteVertexArray(l.vao),l.buffers)for(let c of l.buffers)e.deleteBuffer(c);for(let c of[l.texture,l.metallicRoughnessTexture,l.normalTexture,l.occlusionTexture,l.emissiveTexture])n(c);let h=new Set;l.customProgram&&h.add(l.customProgram);for(let c of l.programCache?.values()??[])c.program&&h.add(c.program);for(let c of h)e.deleteProgram(c)}if(i)for(let a of i)n(a)}function xt(e,t,i=pt,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return qt(e,t,i,r,n)}catch(a){let l=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;vt(e,l,n.gpuTextures),n.vao&&e.deleteVertexArray(n.vao);for(let h of n.buffers)e.deleteBuffer(h);throw a}}function qt(e,t,i,r,n){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:a}=t,l=Oe("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(a,t);let h=t.bin,c=[];n.meshes=c;let T=[],d=a.extensions?.KHR_materials_variants;d&&Array.isArray(d.variants)&&d.variants.forEach((C,S)=>{T.push(typeof C?.name=="string"&&C.name?C.name:`Variant_${S}`)});let g=ut(a),I=[];if(Array.isArray(a.nodes))for(let C=0;C<a.nodes.length;C++){let S=a.nodes[C];S.mesh!==void 0&&a.meshes&&a.meshes[S.mesh]&&I.push({node:S,nodeIdx:C,meshIdx:S.mesh})}let L=I.length>0?I:(a.meshes||[]).map((C,S)=>({node:C,nodeIdx:-1,meshIdx:S})),D=[],O=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(a.asset?.extras?.lights)&&a.asset.extras.lights.length>0?a.asset.extras.lights:null;if(O)for(let C of O)D.push({...C,type:C.type||C.light_type||"point",groundColor:C.groundColor??C.ground_color,innerConeAngle:C.innerConeAngle??C.inner_cone_angle,outerConeAngle:C.outerConeAngle??C.outer_cone_angle});else a.extensions?.KHR_lights_punctual?.lights&&D.push(...ft(a,g));if(D.length===0&&(D.push({type:"ambient",color:[1,1,1],intensity:.35}),D.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),L.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${L.length}`);let o=[];if(n.gpuTextures=o,a.textures&&a.images){if(a.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${a.textures.length}`);for(let C=0;C<a.textures.length;C++){let S=a.textures[C],N=a.images[S.source];if(N){let V=e.createTexture();e.bindTexture(3553,V),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[P,E]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])e.texParameteri(3553,P,E);let b=P=>{V.__gpuImageSource=P,e.bindTexture(3553,V),e.texImage2D(3553,0,6408,6408,5121,P),e.generateMipmap(3553),r?.()};if(N.bufferView!==void 0){let P=a.bufferViews[N.bufferView],E=P.byteOffset||0,H=new Blob([h.slice(E,E+P.byteLength)],{type:N.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(H).then(b).catch(()=>{})}else if(N.uri){let P=Gt(N.uri);if(P){let E=new Image;E.crossOrigin="anonymous",E.referrerPolicy="no-referrer",E.onload=()=>b(E),E.src=P}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",N.uri)}o.push(V)}else o.push(null)}}let f=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0],m=0,y=0;for(let C=0;C<L.length;C++){let S=L[C],N=a.meshes[S.meshIdx],V=S.nodeIdx>=0?g[S.nodeIdx]:ve(),b=new Float32Array(9);Ce(b,V);let P=S.node?.extras?.shadow,E={name:S.node.name||N.name||`Mesh_${S.meshIdx}`,nodeIndex:S.nodeIdx,transform:V,normalMatrix:b,primitives:[],extras:S.node.extras||N.extras,...S.node?.visible===!1||S.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{},...typeof P?.cast=="boolean"?{castShadow:P.cast}:{},...typeof P?.receive=="boolean"?{receiveShadow:P.receive}:{}};n.mesh=E;let H=S.node?.extensions?.EXT_mesh_gpu_instancing;if(H&&H.attributes&&typeof H.attributes=="object"){let v=H.attributes,$=v.TRANSLATION!==void 0?a.accessors?.[v.TRANSLATION]:null,s=v.ROTATION!==void 0?a.accessors?.[v.ROTATION]:null,M=v.SCALE!==void 0?a.accessors?.[v.SCALE]:null,u=v._COLOR_0!==void 0?a.accessors?.[v._COLOR_0]:null,A=Number($?.count??s?.count??M?.count??0);if(!Number.isFinite(A)||A<0||A>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${A}`);if(A>0){let j=(U,K)=>{if(!U||U.bufferView===void 0||!a.bufferViews?.[U.bufferView])return null;let k=U.componentType??5126,J=X=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${X})`),null);if(k!==5120&&k!==5121&&k!==5122&&k!==5123&&k!==5126)return J(`componentType ${k}`);if(!(Number(U.count)>=A))return J(`count ${U.count} < ${A}`);let ee=null;try{ee=at(a,h,{...U,count:A},K)}catch{return J("out of bounds")}return!ee||!ee.every(Number.isFinite)?J("non-finite value"):ee},q=j($,3),Z=j(s,4),W=j(M,3),se=u?.type==="VEC4"?4:3,ae=j(u,se),he=new Float32Array(A*16),oe=ve();for(let U=0;U<A;U++){let K=U*3,k=U*4;ot(oe,Z?[Z[k],Z[k+1],Z[k+2],Z[k+3]]:[0,0,0,1],q?[q[K],q[K+1],q[K+2]]:[0,0,0],W?[W[K],W[K+1],W[K+2]]:[1,1,1]),he.set(oe,U*16)}if(E.instanceMatrices=he,ae){let U=new Float32Array(A*3);for(let K=0;K<A;K++)U[K*3]=ae[K*se],U[K*3+1]=ae[K*se+1],U[K*3+2]=ae[K*se+2];E.instanceColors=U}}}for(let v of N.primitives||[]){if(v.extensions?.KHR_draco_mesh_compression){let F=Oe("draco");F&&F.decodePrimitive(a,v,h)}let $=[],s=e.createVertexArray();n.vao=s,n.buffers=$,e.bindVertexArray(s);let M=Kt(e,E,$),u=a.accessors[v.attributes.POSITION],A=Number(u?.count??0);if(!Number.isFinite(A)||A<0||m+A>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(m+=A,u?.min&&u?.max){let F=B=>{for(let G=0;G<3;G++){let Q=B[12+G],re=Q;for(let ie=0;ie<3;ie++){let me=B[ie*4+G]*u.min[ie],te=B[ie*4+G]*u.max[ie];Q+=me<te?me:te,re+=me>te?me:te}Q<f[G]&&(f[G]=Q),re>p[G]&&(p[G]=re)}};if(E.instanceMatrices&&E.instanceMatrices.length>=16){let B=E.instanceMatrices.length>>4,G=ve();for(let Q=0;Q<B;Q++)be(G,V,E.instanceMatrices.subarray(Q*16,Q*16+16)),F(G)}else F(V)}let j=Qe(e,a,h,v.attributes.POSITION,0,3,$),q=Qe(e,a,h,v.attributes.NORMAL,1,3,$),Z=Qe(e,a,h,v.attributes.TEXCOORD_0,2,2,$,Xt(a,v)),W=0,se=5123,ae=null;if(v.indices!==void 0){let F=a.accessors[v.indices],B=(a.bufferViews[F.bufferView].byteOffset||0)+(F.byteOffset||0);if(W=Number(F.count??0),!Number.isFinite(W)||W<0||y+W>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);y+=W,se=F.componentType===5125?5125:5123;let G=e.createBuffer();$.push(G),e.bindBuffer(34963,G),F.componentType===5125?ae=new Uint32Array(h,B,F.count):F.componentType===5121?ae=Uint16Array.from(new Uint8Array(h,B,F.count)):ae=B%2===0?new Uint16Array(h,B,F.count):new Uint16Array(h.slice(B,B+F.count*2)),e.bufferData(34963,ae,35044)}else W=u.count;let he={};for(let F of ge)if(F.onBuildPrimitiveVAO){let B=F.onBuildPrimitiveVAO(e,s,v,a,h);B&&(he[F.name]=B)}e.bindVertexArray(null);let oe=a.materials&&v.material!==void 0?a.materials[v.material]:null,{program:U,uniforms:K}=dt(e,v,oe),k=gt(oe,o),J=!!(oe?.extensions?.KHR_materials_transmission||he.materials?.isTransmissive),ee=v.extensions?.KHR_materials_variants?.mappings,X=Array.isArray(ee)?ee.filter(F=>F&&typeof F.material=="number"&&Array.isArray(F.variants)).map(F=>({material:F.material|0,variants:F.variants.map(B=>Number(B)|0)})):void 0;E.primitives.push({vao:s,instanced:M,indexCount:W,indexType:se,...k,positions:j,normals:q,uvs:Z,indices:ae,buffers:$,materialIndex:v.material,defaultMaterialIndex:v.material,variantMappings:X,primitiveDef:v,programCache:new Map([[v.material??-1,{program:U,uniforms:K}]]),pluginData:he,customProgram:U,customUniforms:K,isTransmissive:J})}c.push(E)}isFinite(f[0])||(f=[-1,-1,-1]),isFinite(p[0])||(p=[1,1,1]);let w=[(f[0]+p[0])/2,(f[1]+p[1])/2,(f[2]+p[2])/2],x=Math.max(Math.hypot(p[0]-f[0],p[1]-f[1],p[2]-f[2])/2,.5),z=[...f],R=[...p],_=t.animations;if(t.animationsParsed===!1||!_){for(let C of ge)if(C.onParseGLB?.(t),t.animations){_=t.animations;break}}return _||(_=[]),{meshes:c,bounds:{center:w,radius:x,min:z,max:R},lights:D,animations:_,worldMatrices:g,gpuTextures:o,availableVariants:T}}function Ue(){return typeof performance<"u"?performance.now():Date.now()}function _e(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 bt=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=ve(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.environmentSource=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ve(),this.viewMatrix=ve(),this.activeViewMatrix=null,this.modelMatrix=ve(),this.mvpMatrix=ve(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshNames=new Set,this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ve(),rawValueToMeters:.001,format:0},this.container=e;let r,n;if(t&&typeof t.getContext=="function"?(r=t,n=i):(n=t,r=n?.canvas),!r){let c=e.querySelector("canvas");c||(c=document.createElement("canvas"),c.style.cssText="width:100%;height:100%;display:block;touch-action:none",e.prepend(c)),r=c}this.canvas=r;let a=this.opts=n||{};a.clearColor&&(this.clearColor=a.clearColor);let l=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;a.autoRotate!==void 0?this.autoRotate=a.autoRotate&&!l:l&&(this.autoRotate=!1),a.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=a.autoRotateSpeed),a.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(a.autoRotateDelay)||0)),a.exposure!==void 0&&(this.exposure=Je(a.exposure)),a.camera&&this.setInitialCamera(a.camera.theta,a.camera.phi,a.camera.distance,a.camera.zoom),(a.shadowIntensity!==void 0||a.shadowSoftness!==void 0)&&this.setShadow(a.shadowIntensity??0,a.shadowSoftness),a.shadowMaps!==void 0&&(this.shadowMaps=a.shadowMaps),a.toneMapping!==void 0&&(this.toneMapping=We(a.toneMapping)),a.autoplay!==void 0&&(this.autoplay=a.autoplay),a.animationName!==void 0&&(this.animationName=a.animationName),a.variantName!==void 0&&(this.activeVariantName=a.variantName||null),a.fieldOfView!==void 0&&(this.fov=a.fieldOfView*Math.PI/180),a.distanceMode!==void 0&&(this.distanceMode=a.distanceMode),a.cameraTarget!==void 0&&(this.setTarget(a.cameraTarget[0],a.cameraTarget[1],a.cameraTarget[2]),this.initialCustomTarget=[...a.cameraTarget]),(a.minCameraOrbit||a.maxCameraOrbit)&&this.setOrbitLimits({minTheta:a.minCameraOrbit?.theta,maxTheta:a.maxCameraOrbit?.theta,minPhi:a.minCameraOrbit?.phi,maxPhi:a.maxCameraOrbit?.phi,minDistance:a.minCameraOrbit?.distance,maxDistance:a.maxCameraOrbit?.distance});let h=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),a.environmentImage&&this.setEnvironmentImage(a.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&a.autoStart!==!1&&this.start()}static registerDecoder(e,t){Vt(e,t)}static getDecoder(e){return Oe(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=Ye();this.renderProg=Ee(e,Ze,t.fs),this.pickProg=Ee(e,Ht,jt),this.uRender=ke(e,this.renderProg,t.uniforms),this.uPick=ke(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let e=this.gl,t=Ye();this.renderProg&&e.deleteProgram(this.renderProg),this.renderProg=Ee(e,Ze,t.fs),this.uRender=ke(e,this.renderProg,t.uniforms);for(let i of this.meshes)for(let r of i.primitives)r.customProgram&&(e.deleteProgram(r.customProgram),r.programCache?.clear(),this.applyPrimitiveProgram(r,r.materialIndex,this.gltf?.materials?.[r.materialIndex??-1]??null))}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ge)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;typeof e.createFramebuffer=="function"&&(this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer(),this.resizePickingFbo(this.canvas.width,this.canvas.height),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),n=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=n,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,n,0,6408,5121,null),i.texParameteri(3553,10241,9728),i.texParameteri(3553,10240,9728),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,n)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:n,animations:a,worldMatrices:l,gpuTextures:h,availableVariants:c}=xt(this.gl,e,t,()=>this.render());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=n,this.animations=a||[],this.worldMatrices=l||[],this.gpuTextures=h||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(e.gltf?.nodes||[]).map(g=>({t:[g.translation?.[0]??0,g.translation?.[1]??0,g.translation?.[2]??0],r:[g.rotation?.[0]??0,g.rotation?.[1]??0,g.rotation?.[2]??0,g.rotation?.[3]??1],s:[g.scale?.[0]??1,g.scale?.[1]??1,g.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let g of ge)g.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 T=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;T!==void 0&&(this.exposure=Je(T));let d=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;d!==void 0&&(this.envIntensity=Math.max(0,Number(d)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(mt(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of ge)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData($e(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=$e(e),{meshes:r}=xt(this.gl,i,pt,()=>this.render());if(t)for(let n of r)n.transform[12]+=t[0],n.transform[13]+=t[1],n.transform[14]+=t[2],Ce(n.normalMatrix,n.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?e.get(i.name)??e.get(t):Array.isArray(e)?e[t]:e&&typeof e=="object"?Object.prototype.hasOwnProperty.call(e,i.name)?e[i.name]:Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0:void 0;r&&r.length===16&&(i.transform.set(r),Ce(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[0,0,0,0,0,0,0,1,0],n=!1,a=[],l=[],h=[],c=[],T=[],d=[];for(let g of this.lights){let I=g.color||[1,1,1],L=g.intensity!==void 0?g.intensity:1;if(g.type==="ambient")i=[I[0]*L,I[1]*L,I[2]*L];else if(g.type==="hemisphere"){n=!0;let D=g.groundColor||[.2,.2,.2],O=L*.65;for(let p=0;p<3;p++)r[p]+=I[p]*O,r[p+3]+=D[p]*O;let o=g.position||[0,1,0],f=Math.hypot(o[0],o[1],o[2]);f>1e-5&&(r[6]=o[0]/f,r[7]=o[1]/f,r[8]=o[2]/f)}else if(g.type==="directional"&&a.length<6){let D=g.direction||[.5,1,.8];a.push(D[0],D[1],D[2]),l.push(I[0]*L,I[1]*L,I[2]*L)}else if((g.type==="point"||g.type==="spot")&&h.length<6){let D=g.position||[0,0,0];if(h.push(D[0],D[1],D[2]),c.push(I[0]*L,I[1]*L,I[2]*L),g.type==="spot"){let O=g.direction||[0,-1,0],o=Math.max(.01,Math.min(Math.PI/2,g.outerConeAngle??Math.PI/3)),f=Math.max(0,Math.min(o-1e-4,g.innerConeAngle??0));T.push(O[0],O[1],O[2]),d.push(Math.cos(f),Math.cos(o))}else T.push(0,-1,0),d.push(-2,-3)}}a.length===0&&!n&&(a.push(.5,1,.8),l.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),e.uHemi&&t.uniformMatrix3fv(e.uHemi,!1,r),t.uniform1i(e.uNumDirLights,a.length/3),a.length>0&&(t.uniform3fv(e.uDirLightDir,a),t.uniform3fv(e.uDirLightColor,l)),t.uniform1i(e.uNumPointLights,h.length/3),h.length>0&&(t.uniform3fv(e.uPointLightPos,h),t.uniform3fv(e.uPointLightColor,c),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,T),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,d)),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=We(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){this.environmentSource=e&&typeof e=="object"?e:null;for(let t of ge)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e),this.render();return}this.render()}async setSkyboxImage(e){for(let t of ge)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(d=>d.primitives.filter(g=>g.materialIndex===i||e.length===1&&g.materialIndex===void 0)),n=r[0],a=n?[...n.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=n?n.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,h=n?n.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c=(d,g,I)=>{T[d]=I,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness[d]=I);for(let L of r)L[g]=I;this.render()},T={baseColorFactor:a,metallicFactor:l,roughnessFactor:h,setBaseColorFactor:d=>c("baseColorFactor","baseColor",[d[0],d[1],d[2],d[3]??1]),setMetallicFactor:d=>c("metallicFactor","metallic",d),setRoughnessFactor:d=>c("roughnessFactor","roughness",d)};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:T}})}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 n of this.meshes)for(let a of n.primitives){let l=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(i)){l=c.material;break}}let h=l!==void 0?r[l]:void 0;a.materialIndex=h?l:void 0,Object.assign(a,gt(h,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,h??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,n=e.programCache.get(r);n||(n=dt(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,n)),e.customProgram=n.program,e.customUniforms=n.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 ge)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){let t=Math.PI/180,i=Math.PI*.48;e.minTheta!==void 0&&(this.minTheta=e.minTheta*t),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*t),e.minPhi!==void 0&&(this.minPhi=Math.max(-i,e.minPhi*t)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(i,e.maxPhi*t)),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(){let e=180/Math.PI;return{minTheta:isFinite(this.minTheta)?this.minTheta*e:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*e:void 0,minPhi:this.minPhi*e,maxPhi:this.maxPhi*e,minDistance:this.minDistanceLimit??void 0,maxDistance: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.bounds?.radius;return Math.max(this.minDistanceLimit??(t?t*.5:.1),Math.min(this.maxDistanceLimit??(t?t*8:100),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){e!==void 0&&(this.initialTheta=this.targetTheta=this.currTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.initialPhi=this.targetPhi=this.currPhi=this.clampPhi(t*Math.PI/180));let n=i!==void 0&&i>0?i:r!==void 0&&r>0?this.bounds.radius*2.5/r:null;this.customDistance=n!==null,this.initialDistance=this.targetDistance=this.currDistance=this.clampDistance(n??(this.distanceMode==="absolute"?3:this.bounds.radius*2.5)),this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.targetDistance=this.clampDistance(this.initialDistance??this.bounds.radius*2.5),this.customTarget=this.initialCustomTarget?[...this.initialCustomTarget]:null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=ve();be(i,this.projMatrix,this.viewMatrix);let r=(R,_,C=1)=>[R[0]*_[0]+R[4]*_[1]+R[8]*_[2]+R[12]*C,R[1]*_[0]+R[5]*_[1]+R[9]*_[2]+R[13]*C,R[2]*_[0]+R[6]*_[1]+R[10]*_[2]+R[14]*C,R[3]*_[0]+R[7]*_[1]+R[11]*_[2]+R[15]*C],n=this.modelRootMatrix,[a,l,h]=n?r(n,e):e,[c,T,d]=t?n?r(n,t,0):t:[0,0,0],[g,I,L,D]=r(i,[a,l,h]);if(D<=1e-4)return{x:0,y:0,z:1,visible:!1};let O=g/D,o=I/D,f=L/D,p=this.canvas.getBoundingClientRect(),m=p.width||this.canvas.clientWidth||this.canvas.width||300,y=p.height||this.canvas.clientHeight||this.canvas.height||150,w=(O*.5+.5)*m,x=(-o*.5+.5)*y,z=O>=-1.1&&O<=1.1&&o>=-1.1&&o<=1.1&&f>=-1&&f<=1;if(z&&t){let[R,_,C]=_e(this),S=[a-R,l-_,h-C];c*S[0]+T*S[1]+d*S[2]>.05&&(z=!1)}return{x:w,y:x,z:f,visible:z}}setSelectedMesh(e){this.setSelectedMeshes([e])}setSelectedMeshes(e){this.selectedMeshNames=new Set(e.filter(Boolean))}getSelectedMesh(){return[...this.selectedMeshNames][0]||""}setupEvents(){let e=this.canvas,t=Ue;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},n=i.clientX-r.x,a=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(n,a),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],T=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-n*l[0]+a*h[0])*T,c[1]+=(-n*l[1]+a*h[1])*T,c[2]+=(-n*l[2]+a*h[2])*T,this.customTarget=c}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+a*.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(),n=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),a=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(n,a,!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,n)=>{this[n]&&(i.removeEventListener(r,this[n]),this[n]=null)},t=this.canvas;for(let[i,r]of[["webglcontextlost","boundContextLost"],["webglcontextrestored","boundContextRestored"],["contextmenu","boundContextMenu"],["pointerdown","boundPointerDown"],["pointermove","boundPointerMove"],["pointerup","boundPointerUp"],["wheel","boundWheel"],["keydown","boundKeyDown"]])e(t,i,r);e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),n=i.width||300,a=i.height||300,l=r.width>0?Math.floor((e-r.left)*(n/r.width)):Math.floor(e),h=r.height>0?Math.floor((t-r.top)*(a/r.height)):Math.floor(t);return this.performMeshPick(l,h,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,n=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,n);let l=ve();be(l,this.projMatrix,this.viewMatrix);let h=[],c=Math.max(0,Math.min(n-1,e)),T=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==a)&&this.resizePickingFbo(n,a),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,n,a),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let w=0;w<this.meshes.length;w++){let x=this.meshes[w];if(x.visible===!1||x.isPluginMesh)continue;let z=w+1,R=(z&255)/255,_=(z>>8&255)/255,C=(z>>16&255)/255;r.uniform4f(this.uPick.uColorId,R,_,C,1),be(this.modelMatrix,this.modelRootMatrix,x.transform);let S=x.instanceMatrices;if(S&&S.length>=16){let N=S.length>>4,V=ve();for(let b of x.primitives){r.bindVertexArray(b.vao);for(let P=0;P<N;P++)be(V,this.modelMatrix,S.subarray(P*16,P*16+16)),be(this.mvpMatrix,l,V),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ve(r,b)}}else{be(this.mvpMatrix,l,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let N of x.primitives)r.bindVertexArray(N.vao),Ve(r,N)}}let m=new Uint8Array(4);r.readPixels(c,T,1,1,6408,5121,m),r.bindFramebuffer(36160,null);let y=m[0]+(m[1]<<8)+(m[2]<<16);y>0&&y<=this.meshes.length&&(h=[this.meshes[y-1]])}h.length===0&&(h=this.meshes.filter(m=>m.visible!==!1));let d=null,g=1/0,I=[0,0,0],L=[0,1,0],[D,O,o]=_e(this),f=ve();for(let m of h){be(f,this.modelRootMatrix,m.transform);let y=m.instanceMatrices,w=y&&y.length>=16?y.length>>4:1;for(let x=0;x<w;x++){y&&y.length>=16?be(this.modelMatrix,f,y.subarray(x*16,x*16+16)):this.modelMatrix.set(f),be(this.mvpMatrix,l,this.modelMatrix);let z=ve();if(!Et(z,this.mvpMatrix))continue;let R=(c+.5)/n*2-1,_=(T+.5)/a*2-1,C=[0,0,0],S=[0,0,0];lt(C,R,_,-1,z),lt(S,R,_,1,z);let N=S[0]-C[0],V=S[1]-C[1],b=S[2]-C[2],P=Math.hypot(N,V,b)||1,E=N/P,H=V/P,v=b/P,$={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let s of m.primitives){if(!s.positions)continue;let M=s.positions,u=s.indices,A=Math.floor(u?u.length/3:M.length/9);for(let j=0;j<A;j++){let q=(u?u[j*3]:j*3)*3,Z=(u?u[j*3+1]:j*3+1)*3,W=(u?u[j*3+2]:j*3+2)*3;Ot(C[0],C[1],C[2],E,H,v,M[q],M[q+1],M[q+2],M[Z],M[Z+1],M[Z+2],M[W],M[W+1],M[W+2],$,1e-4)}}if(isFinite($.distance)){let s=$.point[0],M=$.point[1],u=$.point[2],A=this.modelMatrix,j=A[0]*s+A[4]*M+A[8]*u+A[12],q=A[1]*s+A[5]*M+A[9]*u+A[13],Z=A[2]*s+A[6]*M+A[10]*u+A[14],W=j-D,se=q-O,ae=Z-o,he=Math.hypot(W,se,ae);if(he<g){Ce(this.normalMatrix,this.modelMatrix);let oe=this.normalMatrix,U=$.normal[0],K=$.normal[1],k=$.normal[2],J=oe[0]*U+oe[3]*K+oe[6]*k,ee=oe[1]*U+oe[4]*K+oe[7]*k,X=oe[2]*U+oe[5]*K+oe[8]*k,F=Math.hypot(J,ee,X)||1;J/=F,ee/=F,X/=F,J*W+ee*se+X*ae>0&&(J=-J,ee=-ee,X=-X);let B=G=>Math.round(G*1e3)/1e3;d=m,g=B(he),I=[B(j),B(q),B(Z)],L=[B(J),B(ee),B(X)]}}}}if(!d)return null;let p={meshIndex:this.meshes.indexOf(d),meshName:d.name,nodeIndex:d.nodeIndex,distance:g,hitPoint:I,normal:L,screenX:e,screenY:t};if(i){for(let m of ge)m.onMeshSelect?.(this,p);this.opts.onMeshClick&&this.opts.onMeshClick(p),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:p}))}return p}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,n=r?e-i:e,a=r?Math.max(1,t-i):i,l=(n+.5)/a*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);st(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;nt(this.viewMatrix,_e(this),i,[0,1,0]),be(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ce(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 ge)i.onXRSessionEnd?.(this);if(this.lastTime=Ue(),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 ge)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=Ue();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,,r]=this.bounds.center;this.modelRootMatrix.set([e,0,-t,0,0,1,0,0,t,0,e,0,i-(e*i+t*r),0,r-(-t*i+e*r),1])}setVisible(e){this.isVisible=e}update(e){for(let a of ge)a.onUpdate?.(this,e);let t=Ue();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let a of ge)a.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=n;let a={theta:i,phi:r,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,t,i,r,n=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,h=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,T=c?[c.x,c.y,c.z]:[0,1.6,0];t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:h,eyePos:T,viewport:r,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:n})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let x=Math.max(2,this.canvas.width||2),z=Math.max(1,this.canvas.height||1),R=Math.max(1,Math.floor(x*.5)),_=Math.max(1,x-R),C=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),S=this.customTarget||this.bounds.center,[N,V,b]=_e(this),P=Math.cos(this.currTheta),E=-Math.sin(this.currTheta),H=.032;for(let v of[-1,1]){let $=ve(),s=ve(),M=v<0?R:_,u=[N+v*P*H,V,b+v*E*H];st($,this.fov,M/z,.1,C),nt(s,u,[S[0]+v*P*H*.25,S[1],S[2]+v*E*H*.25],[0,1,0]),this.render({viewMatrix:s,projMatrix:$,eyePos:u,viewport:[v<0?0:R,0,M,z],eye:v<0?"left":"right",clear:v<0,isAR:!1})}this.gl.viewport(0,0,x,z);return}let t=this.gl,[i,r,n,a]=e?.viewport||[0,0,this.canvas.width,this.canvas.height];if(t.viewport(i,r,n,a),t.enable(2929),!e||e.clear!==!1){let x=e?.isAR?[0,0,0,0]:this.clearColor;t.clearColor(x[0],x[1],x[2],x[3]),t.clear(16640)}let l=ve(),h=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=h;let c=e?.projMatrix??this.projMatrix;be(l,c,h);let T=Me(),d=T.xrDepthShader,g=$t(this.toneMapping),[I,L,D]=e?e.eyePos:_e(this);for(let x of ge)x.onBeforeDrawScene?.(this,t,l,[I,L,D],g);let O=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&O===0){T.gpuSceneAccelerator?.hideLayer?.(this);return}let o=e?.eye||"none",f=!e||e.clear!==!1;if(!this.xrSessionActive&&T.gpuSceneAccelerator?.renderScene(this,l,c,h,[I,L,D],g,[i,r,n,a],o,f,!!e?.isAR)){f&&!this.skyboxTexture&&(t.clearColor(0,0,0,0),t.clear(16384));for(let x of ge)x.name.includes("webgpu")&&x.onAfterRender?.(t,this,l,o,[i,r,n,a],c);return}let p=!1,m=O>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=(x,z,R,_)=>{z?(t.activeTexture(33984+x),t.bindTexture(3553,z),t.uniform1i(R,x),t.uniform1i(_,1)):t.uniform1i(_,0)},w=x=>{for(let z=0;z<m.length;z++){let R=m[z];if(R.visible===!1)continue;let _=this.selectedMeshNames.has(R.name);if(z<O||R.worldSpace===!0||R.name==="__xr_reticle__")this.modelMatrix.set(R.transform);else{be(this.modelMatrix,this.modelRootMatrix,R.transform);let P=!e&&(R.extras?.xr?.billboard??R.userData?.xr?.billboard);if(P){let E=this.modelMatrix,H=Math.hypot(E[0],E[1],E[2])||1,v=Math.hypot(E[4],E[5],E[6])||1,$=Math.hypot(E[8],E[9],E[10])||1,s=P==="y"||P==="cylindrical"||P==="capsule",M=I-E[12],u=D-E[14],A=Math.hypot(M,u),j=A>1e-5?M/A:0,q=A>1e-5?u/A:1;E.set(s?[q*H,0,-j*H,0,0,v,0,0,j*$,0,q*$]:[h[0]*H,h[4]*H,h[8]*H,0,h[1]*v,h[5]*v,h[9]*v,0,h[2]*$,h[6]*$,h[10]*$])}}be(this.mvpMatrix,l,this.modelMatrix),Ce(R.normalMatrix,this.modelMatrix);let C=R.extras?.xr?.stereo||R.userData?.xr?.stereo,S=0,N=0,V=1,b=1;C==="sbs"?(V=.5,S=o==="right"?.5:0):C==="ou"&&(b=.5,N=o==="right"?.5:0);for(let P of R.primitives){let E=!!P.isTransmissive;if(!x&&E){p=!0;continue}if(x&&!E)continue;let H=P.customProgram||this.renderProg,v=P.customUniforms||this.uRender;t.useProgram(H),t.vertexAttrib3f(3,0,0,0),v.uInstanced&&t.uniform1i(v.uInstanced,0),t.uniform1i(v.uToneMapping,g),t.uniform1f(v.uEnvIntensity,this.envIntensity),v.uExposure&&t.uniform1f(v.uExposure,this.exposure),t.uniform3f(v.uCameraPos,I,L,D),t.uniform1f(v.uEmissive,_?1:0),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(v.uNormalMatrix,!1,R.normalMatrix),v.uUvTransform&&t.uniform4f(v.uUvTransform,S,N,V,b),v.uViewportSize&&t.uniform2f(v.uViewportSize,Math.max(1,n),Math.max(1,a)),d?.bind(t,v,this.xrDepthState,h,[i,r,Math.max(1,n),Math.max(1,a)]),T.shadowMapShader?.bind(t,v,this,R),y(4,this.environmentTexture,v.uEnvironmentMap,v.uHasEnvironmentMap),this.bindLights(v),v.uSectionEnabled&&t.uniform1i(v.uSectionEnabled,0);for(let s of ge)s.onBeforeDrawPrimitive?.(t,H,P,R,this.worldMatrices||[],this.gltf);t.uniform4fv(v.uBaseColor,P.baseColor),t.uniform1f(v.uMetallic,P.metallic),t.uniform1f(v.uRoughness,P.roughness),v.uClearcoat&&t.uniform2f(v.uClearcoat,P.clearcoat??0,P.clearcoatRoughness??.04),y(0,P.texture,v.uBaseColorTexture,v.uHasTexture),y(1,P.metallicRoughnessTexture,v.uMetallicRoughnessTexture,v.uHasMetallicRoughnessTexture),y(2,P.normalTexture,v.uNormalTexture,v.uHasNormalTexture),P.normalTexture&&t.uniform1f(v.uNormalScale,P.normalScale),y(3,P.occlusionTexture,v.uOcclusionTexture,v.uHasOcclusionTexture),P.occlusionTexture&&t.uniform1f(v.uOcclusionStrength,P.occlusionStrength),t.uniform3fv(v.uEmissiveFactor,P.emissiveFactor),y(8,P.emissiveTexture,v.uEmissiveTexture,v.uHasEmissiveTexture),t.bindVertexArray(P.vao);let $=R.instanceMatrices;if(P.instanceCount!==void 0)t.drawElementsInstanced(4,P.indexCount,P.indexType,0,P.instanceCount);else if($&&$.length>=16&&P.instanced&&v.uInstanced&&v.uViewProj){let s=$.length>>4;t.uniform1i(v.uInstanced,1),t.uniformMatrix4fv(v.uViewProj,!1,l),P.indices?t.drawElementsInstanced(4,P.indexCount,P.indexType,0,s):t.drawArraysInstanced(4,0,P.indexCount,s),t.uniform1i(v.uInstanced,0)}else if($&&$.length>=16){let s=$.length>>4,M=R.instanceColors,u=ve(),A=new Float32Array(9);for(let j=0;j<s;j++){if(be(u,this.modelMatrix,$.subarray(j*16,j*16+16)),be(this.mvpMatrix,l,u),Ce(A,u),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,u),t.uniformMatrix3fv(v.uNormalMatrix,!1,A),M){let q=P.baseColor,Z=j*3;t.uniform4fv(v.uBaseColor,[q[0]*M[Z],q[1]*M[Z+1],q[2]*M[Z+2],q[3]])}Ve(t,P)}}else Ve(t,P)}}};if(w(!1),p){for(let x of ge)x.onBeforeTransmissivePass?.(t,this);w(!0)}for(let x of ge)x.onAfterRender?.(t,this,l,o,[i,r,n,a],c)}disposeMeshListGpuResources(e,t){vt(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 ge)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()}};bt.registerPlugin=It,bt.getRegisteredPlugins=Lt;function Wt(e){return e+3&-4}var Y=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function et(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function yt(e,t,i){let r=Math.hypot(e,t,i)||1,n=e/r,a=t/r,l=-(i/r);if(l<-.999999)return[0,1,0,0];let h=Math.sqrt((1+l)*2);return[a/h,-n/h,0,h*.5]}function Mt(e,t=0){let[i,r,n,,a,l,h,,c,T,d,,g,I,L]=Array.from({length:15},($,s)=>Y(e[t+s],s%5===0?1:0)),D=Math.hypot(i,r,n),O=Math.hypot(a,l,h),o=Math.hypot(c,T,d);i*(l*d-T*h)-a*(r*d-T*n)+c*(r*h-l*n)<0&&(D=-D);let f=Math.abs(D)>1e-8?1/D:0,p=Math.abs(O)>1e-8?1/O:0,m=Math.abs(o)>1e-8?1/o:0,y=i*f,w=r*f,x=n*f,z=a*p,R=l*p,_=h*p,C=c*m,S=T*m,N=d*m,V=y+R+N,b=0,P=0,E=0,H=1;if(V>0){let $=.5/Math.sqrt(V+1);H=.25/$,b=(_-S)*$,P=(C-x)*$,E=(w-z)*$}else if(y>R&&y>N){let $=2*Math.sqrt(Math.max(0,1+y-R-N));$>1e-8&&(H=(_-S)/$,b=.25*$,P=(z+w)/$,E=(C+x)/$)}else if(R>N){let $=2*Math.sqrt(Math.max(0,1+R-y-N));$>1e-8&&(H=(C-x)/$,b=(z+w)/$,P=.25*$,E=(_+S)/$)}else{let $=2*Math.sqrt(Math.max(0,1+N-y-R));$>1e-8&&(H=(w-z)/$,b=(C+x)/$,P=(_+S)/$,E=.25*$)}let v=Math.hypot(b,P,E,H);return v>1e-8&&Number.isFinite(v)?(b/=v,P/=v,E/=v,H/=v):(b=0,P=0,E=0,H=1),{t:[g,I,L],r:[b,P,E,H],s:[D,O,o]}}function Zt(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 we=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function wt(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,n=typeof i.preset=="string"?i.preset:void 0;return!r&&!n?null:{ae:i,src:r,preset:n,volume:we(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function tt(e){let t=e?.material,i=t?._presetMaps?.map;if(!i||i!==t.map)return null;let r=/^ai_([0-9a-f]{16})_albedo$/.exec(String(i.name??""));return r?r[1]:null}function Yt(e,t){let i=tt(t),r=e?.material;return!i||!r||typeof r!="object"||Array.isArray(r)?e:{...e,material:{...r,textureKey:i}}}function Tt(e,t){return At(e,t)[0]}function At(e,t){e.updateMatrixWorld(!0);let i=[],r=0,n=[],a=[],l=[],h=[],c=new Set,T=[],d=[],g=new Map,I=[],L=[],D=[],O=new Map,o=[],f=[],p=[],m=!1;function y(s){let M=g.get(s);if(M!==void 0)return M;M=d.length,g.set(s,M);let u=s,A=u.color?.r??1,j=u.color?.g??1,q=u.color?.b??1,Z=u.opacity??1,W={baseColorFactor:[A,j,q,Z],metallicFactor:u.metalness??0,roughnessFactor:u.roughness??.5},se={},ae=te=>{if(!te)return;let xe=(typeof te=="string"?te:typeof te.source=="string"?te.source:typeof te.image=="string"?te.image:"").trim();if(!xe||/[\x00-\x1f\x7f\\]|\.\./.test(xe)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(xe)||!xe.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(xe)))return;let ne=O.get(xe);if(ne===void 0){let ce=I.length;I.push({uri:xe}),L.length===0&&L.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),ne=D.length,D.push({sampler:0,source:ce}),O.set(xe,ne)}return{index:ne}},he=u._packPbr?.(),oe=ae(u.map);oe&&(W.baseColorTexture=oe);let U=ae(he?.mrUri||u.roughnessMap||u.metalnessMap);U&&(W.metallicRoughnessTexture=U);let K=u.map?.avgColor;Array.isArray(K)&&K.length>=3&&(se.avgColor=[K[0],K[1],K[2]]);let k=ae(he?.normUri||u.normalMap),J=u.normalScale,ee=he?.normUri?he.normScale??1:typeof J=="number"?Math.max(0,Y(J,1)):J?Math.max(0,(Y(J.x,1)+Y(J.y,1))*.5):1;k&&ee!==1&&(k.scale=ee);let X=ae(u.emissiveMap),F=ae(u.aoMap),B=Math.max(0,Math.min(1,Y(u.aoMapIntensity,1)));F&&B!==1&&(F.strength=B);let G={name:u.name||"",pbrMetallicRoughness:W,doubleSided:u.side===2||!!u.doubleSided,...Z<1||u.transparent?{alphaMode:"BLEND"}:{},...k?{normalTexture:k}:{},...X?{emissiveTexture:X}:{},...F?{occlusionTexture:F}:{},...Object.keys(se).length>0?{extras:se}:{}},Q=Math.max(0,Y(u.emissiveIntensity,1)),re=u.emissive&&(u.emissive.r>0||u.emissive.g>0||u.emissive.b>0);(re||X&&!u._em&&Q>0)&&(G.emissiveFactor=re?[u.emissive.r*Q,u.emissive.g*Q,u.emissive.b*Q]:[Q,Q,Q]);let ie={};u.clearcoat&&u.clearcoat>0&&(ie.KHR_materials_clearcoat={clearcoatFactor:u.clearcoat,clearcoatRoughnessFactor:u.clearcoatRoughness||0}),u.sheen&&u.sheen>0&&(ie.KHR_materials_sheen={sheenColorFactor:u.sheenColor?[u.sheenColor.r,u.sheenColor.g,u.sheenColor.b]:[1,1,1],sheenRoughnessFactor:u.sheenRoughness||0}),u.transmission&&u.transmission>0&&(ie.KHR_materials_transmission={transmissionFactor:u.transmission}),u.thickness&&u.thickness>0&&(ie.KHR_materials_volume={thicknessFactor:u.thickness,attenuationDistance:u.attenuationDistance??1/0,attenuationColor:u.attenuationColor?[u.attenuationColor.r,u.attenuationColor.g,u.attenuationColor.b]:[1,1,1]}),u.ior!==void 0&&u.ior!==1.5&&(ie.KHR_materials_ior={ior:u.ior}),u.dispersion&&u.dispersion>0&&(ie.KHR_materials_dispersion={dispersion:u.dispersion}),u.iridescence&&u.iridescence>0&&(ie.KHR_materials_iridescence={iridescenceFactor:u.iridescence,iridescenceIor:u.iridescenceIOR??1.3});let me=u._serializeTslGraph?.();return me&&(ie.GOOGLE_material_tsl=me,c.add("GOOGLE_material_tsl")),Object.keys(ie).length>0&&(G.extensions=ie),d.push(G),M}function w(s,M){let u=new Uint8Array(s.buffer,s.byteOffset,s.byteLength),A=Wt(u.byteLength),j=new Uint8Array(A);j.set(u),i.push(j);let q=n.length;return n.push({buffer:0,byteOffset:r,byteLength:u.byteLength,target:M}),r+=A,q}function x(s,M,u,A,j,q,Z){let W=w(s,u),se=a.length,ae={bufferView:W,byteOffset:0,componentType:A,count:j,type:M};return q&&(ae.min=q),Z&&(ae.max=Z),a.push(ae),se}let z=[],R=[],_=new Set([e]),C=[];if(Array.isArray(e.children))for(let s=e.children.length-1;s>=0;s--)C.push({obj:e.children[s],parentKids:R});for(;C.length>0;){let{obj:s,parentKids:M}=C.pop();if(!s||typeof s!="object"||_.has(s))continue;_.add(s),s._bakeAuthorGeometry?.(),Me().materializeDeclarativeGeometry?.(s);let u=!!(s.userData&&(s.userData.xr&&typeof s.userData.xr=="object"&&Object.keys(s.userData.xr).length>0||s.userData.interactivity&&typeof s.userData.interactivity=="object"&&Object.keys(s.userData.interactivity).length>0)),A={name:s.name||(u?`Node_${h.length}`:"")},j=Y(s.position?.x,0),q=Y(s.position?.y,0),Z=Y(s.position?.z,0),W=Y(s.quaternion?.x,0),se=Y(s.quaternion?.y,0),ae=Y(s.quaternion?.z,0),he=Y(s.quaternion?.w,1),oe=Y(s.scale?.x,1),U=Y(s.scale?.y,1),K=Y(s.scale?.z,1);if((j||q||Z)&&(A.translation=[j,q,Z]),(W||se||ae||he!==1)&&(A.rotation=[W,se,ae,he]),(oe!==1||U!==1||K!==1)&&(A.scale=[oe,U,K]),s.visible===!1&&(A.extensions={...A.extensions||{},KHR_node_visibility:{visible:!1}},c.add("KHR_node_visibility")),s.userData&&Object.keys(s.userData).length>0&&(A.extras=JSON.parse(JSON.stringify(s.userData,(F,B)=>{if(!(F==="__proto__"||F==="prototype"||F==="constructor"))return typeof B=="function"?void 0:B})),s.userData.xr)){let F=Zt(s.userData.xr);A.extensions={...A.extensions||{},MOZ_hubs_components:F,ANDROID_xr_scenecore:F},Me().xrTraitSerializer?.gltfNode(A,s.userData.xr);let B=tt(s),G=A.extras?.xr?.material;B&&G&&typeof G=="object"&&!Array.isArray(G)&&(G.textureKey=B),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let k=s,J=k.isLight||k.color&&k.intensity!==void 0;if(!J&&(k._castShdSet||k._recvShdSet||s.castShadow||s.receiveShadow)&&(A.extras={...A.extras||{},shadow:{cast:!!s.castShadow,receive:k._recvShdSet?!!s.receiveShadow:!!(s.receiveShadow||s.castShadow)}}),J){let F=k.matrixWorld?.elements,B=Y(F?F[12]:s.position?.x,0),G=Y(F?F[13]:s.position?.y,0),Q=Y(F?F[14]:s.position?.z,0),re=k.target,ie=re?.parent?re?.matrixWorld?.elements:void 0,me=Y(ie?ie[12]:re?.position?.x,0),te=Y(ie?ie[13]:re?.position?.y,0),xe=Y(ie?ie[14]:re?.position?.z,0),ne=me-B,ce=te-G,le=xe-Q,ue=Math.hypot(ne,ce,le),de=Math.max(.01,Math.min(Math.PI/2,Y(k.angle,Math.PI/3))),ye=Math.max(0,Math.min(1,Y(k.penumbra,0))),fe=Math.max(0,de*(1-ye)),Ae=Math.max(0,Y(k.distance,0)),Se=s.type==="directional"||s.type==="spot"||s.type==="point",Pe;if(s.castShadow&&Se){let De=k.shadow,qe=Math.max(256,Math.min(2048,Math.round(Y(De?.mapSize?.x??De?.mapSize?.width,1024))));Pe={cast:!0,mapSize:qe<=384?256:qe<=768?512:qe<=1536?1024:2048,bias:we(De?.bias,-.05,.05,-5e-4),normalBias:we(De?.normalBias,0,.2,.015),radius:we(De?.radius,0,8,1.5)},m=!0}let Ge=B-me,Ke=G-te,Xe=Q-xe,Fe=Math.hypot(Ge,Ke,Xe);f.push({type:s.type,color:[s.color.r,s.color.g,s.color.b],intensity:s.intensity,position:s.type==="directional"?[Ge,Ke,Xe]:[B,G,Q],...s.type==="directional"?{direction:Fe>1e-6?[Ge/Fe,Ke/Fe,Xe/Fe]:[0,1,0]}:s.type==="spot"?{direction:ue>1e-6?[ne/ue,ce/ue,le/ue]:[0,-1,0],outerConeAngle:de,innerConeAngle:fe,range:Ae}:s.type==="point"?{range:Ae}:s.type==="hemisphere"&&k.groundColor?{groundColor:[k.groundColor.r,k.groundColor.g,k.groundColor.b]}:{},...Pe?{shadow:Pe}:{}}),Se&&z.push({node:A,obj:s,px:B,py:G,pz:Q,tx:me,ty:te,tz:xe,dx:ne,dy:ce,dz:le,dLen:ue,outerAngle:de,innerAngle:fe,range:Ae,shadowSpec:Pe})}if(s.geometry){let F=s.geometry,B=F.attributes.position;if(B&&B.count>0){let G=[1/0,1/0,1/0],Q=[-1/0,-1/0,-1/0];for(let ne=0;ne<B.count;ne++){let ce=B.getX(ne),le=B.getY(ne),ue=B.getZ(ne);ce<G[0]&&(G[0]=ce),ce>Q[0]&&(Q[0]=ce),le<G[1]&&(G[1]=le),le>Q[1]&&(Q[1]=le),ue<G[2]&&(G[2]=ue),ue>Q[2]&&(Q[2]=ue)}let re={attributes:{POSITION:x(B.array,"VEC3",34962,5126,B.count,G,Q)}};if(F.attributes.normal&&(re.attributes.NORMAL=x(F.attributes.normal.array,"VEC3",34962,5126,F.attributes.normal.count)),F.attributes.uv&&(re.attributes.TEXCOORD_0=x(F.attributes.uv.array,"VEC2",34962,5126,F.attributes.uv.count)),F.index){let ne=F.index.array instanceof Uint32Array;re.indices=x(F.index.array,"SCALAR",34963,ne?5125:5123,F.index.count)}let ie=Array.isArray(s.material)?s.material[0]:s.material;ie&&(re.material=y(ie));let me=s.userData?.variants;if(me&&typeof me=="object"){let ne=new Map;for(let ce of Object.keys(me)){if(!ce||ce==="__proto__"||ce==="constructor"||ce==="prototype")continue;let le=me[ce];if(!le||typeof le!="object")continue;let ue=o.indexOf(ce);if(ue===-1&&o.length<256&&(ue=o.length,o.push(ce)),ue===-1)continue;let de=y(le),ye=ne.get(de);ye||(ye=[],ne.set(de,ye)),ye.push(ue)}if(ne.size>0){let ce=[];for(let[le,ue]of ne.entries())ce.push({material:le,variants:ue});re.extensions={...re.extensions||{},KHR_materials_variants:{mappings:ce}},c.add("KHR_materials_variants")}}let te=s;if(te.isInstancedMesh&&typeof te.count=="number"&&te.count>0&&te.instanceMatrix?.array){let ne=Math.min(1e4,Math.floor(te.count)),ce=te.instanceMatrix.array,le=new Float32Array(ne*3),ue=new Float32Array(ne*4),de=new Float32Array(ne*3);for(let fe=0;fe<ne;fe++){let{t:Ae,r:Se,s:Pe}=Mt(ce,fe*16);le[fe*3]=Ae[0],le[fe*3+1]=Ae[1],le[fe*3+2]=Ae[2],ue[fe*4]=Se[0],ue[fe*4+1]=Se[1],ue[fe*4+2]=Se[2],ue[fe*4+3]=Se[3],de[fe*3]=Pe[0],de[fe*3+1]=Pe[1],de[fe*3+2]=Pe[2]}let ye={TRANSLATION:x(le,"VEC3",0,5126,ne),ROTATION:x(ue,"VEC4",0,5126,ne),SCALE:x(de,"VEC3",0,5126,ne)};if(te.instanceColor?.array&&te.instanceColor.array.length>=ne*3){let fe=new Float32Array(te.instanceColor.array.subarray(0,ne*3));ye._COLOR_0=x(fe,"VEC3",0,5126,ne)}A.extensions={...A.extensions||{},EXT_mesh_gpu_instancing:{attributes:ye}},c.add("EXT_mesh_gpu_instancing")}let xe=l.length;l.push({primitives:[re],name:s.name,...A.extras?{extras:A.extras}:{}}),A.mesh=xe}}let ee=h.length;h.push(A),T.push(s),M.push(ee);let X=s.children;if(Array.isArray(X)&&X.length>0){let F=[];A.children=F;for(let B=X.length-1;B>=0;B--)C.push({obj:X[B],parentKids:F})}}if(m)for(let s of z){let M=p.length;if(p.push({name:s.obj.name||`Light_${M}`,type:s.obj.type,color:[s.obj.color.r,s.obj.color.g,s.obj.color.b],intensity:s.obj.intensity,...s.range>0&&(s.obj.type==="point"||s.obj.type==="spot")?{range:s.range}:{},...s.obj.type==="spot"?{spot:{innerConeAngle:s.innerAngle,outerConeAngle:s.outerAngle}}:{},...s.shadowSpec?{extras:{shadow:s.shadowSpec}}:{}}),s.node.extensions={...s.node.extensions||{},KHR_lights_punctual:{light:M}},c.add("KHR_lights_punctual"),s.obj.type==="directional"||s.obj.type==="spot"){let u=s.dLen>1e-6?s.dx/s.dLen:0,A=s.dLen>1e-6?s.dy/s.dLen:-1,j=s.dLen>1e-6?s.dz/s.dLen:0;s.node.rotation=yt(u,A,j),s.obj.type==="directional"&&(s.tx||s.ty||s.tz)&&(s.node.translation=[s.px-s.tx,s.py-s.ty,s.pz-s.tz])}}for(let s=0;s<h.length;s++){let M=h[s];M.children&&M.children.length===0?delete M.children:M.children&&M.children.length>0&&(M.extras?.xr?.lod||M.extensions?.ANDROID_xr_scenecore?.lod||T[s]?.isLOD)&&(M.extensions={...M.extensions||{},MSFT_lod:{ids:[...M.children]}},c.add("MSFT_lod"))}let S=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),N=[];if(typeof S=="function"&&T.length>0){let s=t?.duration??4,M=t?.fps??15,u=Math.max(2,Math.round(s*M)+1),A=new Float32Array(u),j=T.map(U=>[Y(U.position?.x,0),Y(U.position?.y,0),Y(U.position?.z,0),Y(U.quaternion?.x,0),Y(U.quaternion?.y,0),Y(U.quaternion?.z,0),Y(U.quaternion?.w,1),Y(U.scale?.x,1),Y(U.scale?.y,1),Y(U.scale?.z,1)]),q=T.map(()=>new Float32Array(u*3)),Z=T.map(()=>new Float32Array(u*4)),W=T.map(()=>new Float32Array(u*3));for(let U=0;U<u;U++){let K=U/(u-1)*s;A[U]=K;try{S(K)}catch{}for(let k=0;k<T.length;k++){let J=T[k];q[k][U*3]=Y(J.position?.x,0),q[k][U*3+1]=Y(J.position?.y,0),q[k][U*3+2]=Y(J.position?.z,0);let ee=Y(J.quaternion?.x,0),X=Y(J.quaternion?.y,0),F=Y(J.quaternion?.z,0),B=Y(J.quaternion?.w,1),G=Math.hypot(ee,X,F,B)||1;if(ee/=G,X/=G,F/=G,B/=G,U>0){let Q=(U-1)*4,re=Z[k];re[Q]*ee+re[Q+1]*X+re[Q+2]*F+re[Q+3]*B<0&&(ee=-ee,X=-X,F=-F,B=-B)}Z[k][U*4]=ee,Z[k][U*4+1]=X,Z[k][U*4+2]=F,Z[k][U*4+3]=B,W[k][U*3]=Y(J.scale?.x,1),W[k][U*3+1]=Y(J.scale?.y,1),W[k][U*3+2]=Y(J.scale?.z,1)}}for(let U=0;U<T.length;U++){let K=T[U],k=j[U];K.position?.set(k[0],k[1],k[2]),K.quaternion?.set(k[3],k[4],k[5],k[6]),K.scale?.set(k[7],k[8],k[9])}e.updateMatrixWorld(!0);let se=null,ae=()=>(se===null&&(se=x(A,"SCALAR",0,5126,u,[0],[s])),se),he=[],oe=[];for(let U=0;U<T.length;U++){let K=j[U],k=(ee,X,F)=>ee.some((B,G)=>Math.abs(B-K[F+G%X])>1e-4),J=(ee,X,F,B)=>{ee&&oe.push({sampler:he.push({input:ae(),interpolation:"LINEAR",output:x(X,F,0,5126,u)})-1,target:{node:U,path:B}})};J(k(q[U],3,0),q[U],"VEC3","translation"),J(k(Z[U],4,3),Z[U],"VEC4","rotation"),J(k(W[U],3,7),W[U],"VEC3","scale")}oe.length>0&&N.push({name:"ProceduralLoop",samplers:he,channels:oe})}let V=rt(h,l,e.userData),b=[],P=[],E=[];for(let s=0;s<h.length;s++){let M=h[s],u=wt(M.extras?.xr);if(!u)continue;let{ae:A,src:j,preset:q,volume:Z,loop:W,isGlobal:se}=u,ae=M.name||`Node_${s}`,he=P.length;P.push({name:`${ae}_source`,gain:Z,loop:W,autoPlay:typeof A.autoplay=="boolean"?A.autoplay:!0,...j!==void 0?{audio:b.push({uri:j})-1}:{},...q?{extras:{preset:q,pitch:we(A.pitch,.25,4,1)}}:{}});let oe=E.length,U=we(A.refDistance,.05,100,1),K=we(A.coneInnerAngle,0,360,360),k=we(A.coneOuterAngle,K,360,360);E.push({name:`${ae}_emitter`,type:se?"global":"positional",gain:Z,sources:[he],...se?{}:{positional:{distanceModel:A.distanceModel==="linear"||A.distanceModel==="exponential"?A.distanceModel:"inverse",refDistance:U,maxDistance:we(A.maxDistance,U,500,Math.max(U,25)),rolloffFactor:we(A.rolloffFactor,0,10,1),coneInnerAngle:+(K*Math.PI/180).toFixed(6),coneOuterAngle:+(k*Math.PI/180).toFixed(6),coneOuterGain:we(A.coneOuterGain,0,1,0)}}}),M.extensions={...M.extensions||{},KHR_audio_emitter:{emitter:oe}},c.add("KHR_audio_emitter")}let H={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity,...f.length>0?{lights:f}:{}}},scenes:[{nodes:R}],scene:0,nodes:h,meshes:l,materials:d,...I.length>0?{images:I}:{},...L.length>0?{samplers:L}:{},...D.length>0?{textures:D}:{},accessors:a,bufferViews:n,buffers:[{byteLength:r}],...N.length>0?{animations:N}:{},...V||c.size>0?{extensionsUsed:[...V?["KHR_interactivity"]:[],...c]}:{},...V||o.length>0||E.length>0||p.length>0?{extensions:{...V?{KHR_interactivity:V}:{},...o.length>0?{KHR_materials_variants:{variants:o.map(s=>({name:s}))}}:{},...E.length>0?{KHR_audio_emitter:{...b.length>0?{audio:b}:{},sources:P,emitters:E}}:{},...p.length>0?{KHR_lights_punctual:{lights:p}}:{}}}:{}},v=new Uint8Array(r),$=0;for(let s of i)v.set(s,$),$+=s.byteLength;return[{gltf:H,bin:v.buffer,lights:f,environmentIntensity:e.environmentIntensity},T]}function Be(e){return new TextEncoder().encode(e)}function Qt(e,t){let{gltf:i,bin:r}=Tt(e,t),n=JSON.stringify(i),a=Be(n),l=(4-a.byteLength%4)%4,h=a.byteLength+l,c=20+h+8+r.byteLength,T=new Uint8Array(c),d=new DataView(T.buffer);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,c,!0),d.setUint32(12,h,!0),d.setUint32(16,1313821514,!0),T.set(a,20);for(let I=0;I<l;I++)T[20+a.byteLength+I]=32;let g=20+h;return d.setUint32(g,r.byteLength,!0),d.setUint32(g+4,5130562,!0),T.set(new Uint8Array(r),g+8),T}function it(e,t){let[i,r]=At(e,t);return He(i,r)}function He(e,t){let i=[],r=e.gltf,n=Me().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(r,e);let a=e.bin,l=a instanceof ArrayBuffer?a:a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),h=r.accessors||[],c=r.bufferViews||[],T=r.materials||[],d=r.meshes||[],g=r.nodes||[],I=r.textures||[],L=r.images||[],D=r.samplers||[],O=new Set,o=T.map((R,_)=>et(O,Re(R?.name,`Material_${_}`))),f=new Map;function p(R){let _=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(R);if(!_)return null;let C=_[2].replace(/\s+/g,""),S=C.endsWith("==")?2:C.endsWith("=")?1:0,N=new Uint8Array((C.length*3>>2)-S),V=P=>{let E=C.charCodeAt(P);return E>96?E-71:E>64?E-65:E>47?E+4:E===43?62:E===47?63:0},b=0;for(let P=0;P<C.length;P+=4){let E=V(P)<<18|V(P+1)<<12|V(P+2)<<6|V(P+3);N[b++]=E>>16&255,b<N.length&&(N[b++]=E>>8&255),b<N.length&&(N[b++]=E&255)}return N}function m(R,_,C){let S=R?.index;if(typeof S!="number")return;let N=I[S],V=N?.source;if(typeof V!="number"||!L[V])return;let b=f.get(V);if(b===void 0){b=null;let H=L[V],v=null;if(typeof H.bufferView=="number"){let $=c[H.bufferView],s=$?.byteOffset||0,M=$?.byteLength||0;$&&M>0&&s>=0&&s+M<=l.byteLength&&(v=new Uint8Array(l,s,M))}else typeof H.uri=="string"&&(v=p(H.uri));if(v&&v.byteLength>0){let $=v[0]===255&&v[1]===216&&v[2]===255||!(v[0]===137&&v[1]===80)&&/jpe?g/i.test(H.mimeType||H.uri||"");b={file:`texture_${V}.${$?"jpg":"png"}`,data:v}}f.set(V,b)}if(!b)return;let P=typeof N.sampler=="number"?D[N.sampler]:void 0,E=H=>H===33071?"clamp":H===33648?"mirror":"repeat";return{file:b.file,data:b.data,wrapS:E(P?.wrapS),wrapT:E(P?.wrapT),..._?{scale:_}:{},...C?{bias:C}:{}}}function y(R){let _=h[R];if(!_)throw new Error(`Accessor ${R} not found`);let C=c[_.bufferView||0],S=(C.byteOffset||0)+(_.byteOffset||0),N=C.byteLength||0;return{acc:_,buffer:l.slice(S,S+N)}}function w(R,_,C,S){let N=[],V=d[R];if(!V)return N;let b=V.primitives||[];for(let P=0;P<b.length;P++){let E=b[P],H=E.attributes?.POSITION;if(H===void 0)continue;let{acc:v,buffer:$}=y(H),s=new Float32Array($,0,v.count*3),M,u=E.attributes?.NORMAL;if(u!==void 0){let{acc:X,buffer:F}=y(u),B=new Float32Array(F,0,X.count*3);M=new Float32Array(B.length);for(let G=0;G<X.count;G++){let Q=B[G*3],re=B[G*3+1],ie=B[G*3+2],me=Math.hypot(Q,re,ie)||1;M[G*3]=Q/me,M[G*3+1]=re/me,M[G*3+2]=ie/me}}let A,j=E.attributes?.TEXCOORD_0;if(j!==void 0){let{acc:X,buffer:F}=y(j);A=new Float32Array(F,0,X.count*2)}let q;if(E.indices!==void 0){let{acc:X,buffer:F}=y(E.indices);q=X.componentType===5125?new Uint32Array(F,0,X.count):new Uint16Array(F,0,X.count);let B=v.count;for(let G of q)if(G>=B)throw new Error(`SecurityError: Index buffer value (${G}) out of vertex bounds [0, ${B}).`)}else{let X=v.count;q=X>65535?new Uint32Array(X):new Uint16Array(X);for(let F=0;F<X;F++)q[F]=F}let Z="DefaultMaterial",W=[1,1,1],se=.5,ae=0,he=0,oe=0,U=1.5,K=1,k=[0,0,0],J,ee={};if(E.material!==void 0&&T[E.material]){let X=T[E.material];Z=o[E.material]||`Material_${E.material}`;let F=X.pbrMetallicRoughness||{},B=(fe,Ae)=>Array.isArray(fe)&&fe.length>=3?[fe[0],fe[1],fe[2]]:Ae;W=B(F.baseColorFactor,[1,1,1]);let G=Array.isArray(F.baseColorFactor)&&typeof F.baseColorFactor[3]=="number"?F.baseColorFactor[3]:1,Q=W[0]!==1||W[1]!==1||W[2]!==1||G!==1,re=m(F.baseColorTexture,Q?[W[0],W[1],W[2],G]:void 0),ie=X.extras?.avgColor;!re&&Array.isArray(ie)&&ie.length>=3&&(W=[W[0]*ie[0],W[1]*ie[1],W[2]*ie[2]]),typeof F.roughnessFactor=="number"&&(se=F.roughnessFactor),typeof F.metallicFactor=="number"&&(ae=F.metallicFactor);let me=typeof F.roughnessFactor=="number"?F.roughnessFactor:1,te=typeof F.metallicFactor=="number"?F.metallicFactor:1,xe=m(F.metallicRoughnessTexture,me!==1||te!==1?[1,me,te,1]:void 0);k=B(X.emissiveFactor,[0,0,0]);let ne=(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,ce=m(X.emissiveTexture,ne),le=typeof X.normalTexture?.scale=="number"?X.normalTexture.scale:1,ue=m(X.normalTexture,[2*le,2*le,2,1],[-le,-le,-1,0]),de=typeof X.occlusionTexture?.strength=="number"?X.occlusionTexture.strength:1,ye=de!==1?m(X.occlusionTexture,[de,de,de,1],[1-de,1-de,1-de,0]):m(X.occlusionTexture);(re||xe||ue||ce||ye)&&(J=[re,xe,ue,ce,ye]),ee=X.extensions||{},ee.KHR_materials_clearcoat&&(he=ee.KHR_materials_clearcoat.clearcoatFactor??0,oe=ee.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof ee.KHR_materials_ior?.ior=="number"&&(U=ee.KHR_materials_ior.ior),K=G*(1-(ee.KHR_materials_transmission?.transmissionFactor??0))}N.push({name:b.length>1?`${_}_p${P}`:_,positions:s,indices:q,normals:M,uvs:A,materialName:Z,color:W,roughness:se,metallic:ae,clearcoat:he,clearcoatRoughness:oe,ior:U,opacity:K,emissiveColor:k,...J?{textures:J}:{},...ee.GOOGLE_material_tsl?{tslGraph:ee.GOOGLE_material_tsl}:{},xrTraits:C||V.extras?.xr,...S?{invisible:!0}:{}})}return N}if(g.length>0){let R=new Float32Array(0),_=new Uint16Array(0),C=(s,M)=>{if(s===void 0)return null;let{acc:u,buffer:A}=y(s);return new Float32Array(A,0,u.count*M)},S=(s,M)=>Array.isArray(s)&&s.length>=3?[Y(s[0],M),Y(s[1],M),Y(s[2],M)]:[M,M,M],N=(s,M,u)=>s&&s.length>=(M+1)*3?[s[M*3],s[M*3+1],s[M*3+2]]:u,V=(s,M,u)=>s&&s.length>=(M+1)*4?[s[M*4],s[M*4+1],s[M*4+2],s[M*4+3]]:u,b=new Map,P=r.animations?.[0];if(P&&Array.isArray(P.channels)&&Array.isArray(P.samplers))for(let s of P.channels){let M=P.samplers[s?.sampler],u=s?.target?.node,A=s?.target?.path;if(!M||typeof u!="number"||M.input===void 0)continue;let j=b.get(u);j||(j={input:M.input},b.set(u,j)),A==="translation"?j.t=M.output:A==="rotation"?j.r=M.output:A==="scale"&&(j.s=M.output)}let E=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(E)||E.length===0){let s=new Set;for(let M of g)if(Array.isArray(M?.children))for(let u of M.children)s.add(u);E=[];for(let M=0;M<g.length;M++)s.has(M)||E.push(M);E.length===0&&(E=[0])}let H=new Set,v=[],$=(s,M)=>{if(Array.isArray(s))for(let u=s.length-1;u>=0;u--)v.push({idx:s[u],out:M})};for($(E,i);v.length>0;){let{idx:s,out:M}=v.pop();if(typeof s!="number"||s<0||s>=g.length||H.has(s))continue;H.add(s);let u=g[s];if(!u)continue;let A=[0,0,0],j=[0,0,0,1],q=[1,1,1];if(Array.isArray(u.matrix)&&u.matrix.length===16){let K=Mt(u.matrix);A=K.t,j=K.r,q=K.s}else A=S(u.translation,0),Array.isArray(u.rotation)&&u.rotation.length>=4&&(j=[Y(u.rotation[0],0),Y(u.rotation[1],0),Y(u.rotation[2],0),Y(u.rotation[3],1)]),q=S(u.scale,1);let Z,W=b.get(s);if(W){let K=C(W.input,1);if(K&&K.length>0){let k=C(W.t,3),J=C(W.r,4),ee=C(W.s,3),X=Array.from(K),F=[],B=[],G=[];for(let Q=0;Q<K.length;Q++)F.push(N(k,Q,A)),B.push(V(J,Q,j)),G.push(N(ee,Q,q));Z={times:X,translations:F,rotations:B,scales:G}}}let se=Array.isArray(u.children)?u.children:[],ae=typeof u.mesh=="number"&&u.mesh>=0&&u.mesh<d.length,he=t?.[s]?.userData?.xr??u.extras?.xr;if(!ae&&se.length===0&&(u.camera!==void 0||u.extensions?.KHR_lights_punctual||!u.name&&!u.extras&&!he&&!Z))continue;let oe=(K,k,J)=>({name:K,positions:R,indices:_,isXform:!0,xrTraits:he,timeSamples:Z,translation:A,rotation:j,scale:q,children:k,...J?{invisible:!0}:{}}),U=u.visible===!1||u.extensions?.KHR_node_visibility?.visible===!1||t?.[s]?.visible===!1;if(ae){let K=u.name||d[u.mesh]?.name||`Mesh_${s}`,k=w(u.mesh,K,he,U),J=t?.[s],ee=!!(J?._castShdSet||J?._recvShdSet),X=typeof u.extras?.shadow?.cast=="boolean"?u.extras.shadow.cast:ee?!!J?.castShadow:void 0;if(X!==void 0)for(let B of k)B.castShadow=X;let F=u.extensions?.EXT_mesh_gpu_instancing?.attributes;if(F&&typeof F=="object"&&k.length>0){let B=C(F.TRANSLATION,3),G=C(F.ROTATION,4),Q=C(F.SCALE,3),re=C(F._COLOR_0,3),ie=Math.min(1e3,B?B.length/3:G?G.length/4:Q?Q.length/3:0);if(ie>0){let me=[];for(let te=0;te<ie;te++){let xe=N(B,te,[0,0,0]),ne=V(G,te,[0,0,0,1]),ce=N(Q,te,[1,1,1]);for(let le of k){let ue=le.color||[.8,.8,.8],de=re&&re.length>=(te+1)*3;me.push({...le,name:`${le.name}_${te}`,materialName:de?`${le.materialName}_inst_${te}`:le.materialName,color:de?[ue[0]*re[te*3],ue[1]*re[te*3+1],ue[2]*re[te*3+2]]:le.color,translation:xe,rotation:ne,scale:ce})}}$(se,me),M.push(oe(K,me,U));continue}}if(k.length===1)k[0].translation=A,k[0].rotation=j,k[0].scale=q,k[0].timeSamples=Z,se.length>0&&(k[0].children=[],$(se,k[0].children)),M.push(k[0]);else{let B=[...k];$(se,B),M.push(oe(K,B,U))}}else{let K=[];$(se,K),M.push(oe(u.name||`Group_${s}`,K,U))}}}else for(let R=0;R<d.length;R++){let _=d[R].name||`Mesh_${R}`;i.push(...w(R,_,d[R].extras?.xr))}let x=(Array.isArray(e.lights)&&e.lights.length>0?e.lights:void 0)??ft(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),z=[];for(let R=0;R<x.length;R++){let _=x[R];_?.shadow?.cast&&(_.type==="directional"||_.type==="spot"||_.type==="point")&&z.push({name:`Light_${R}`,type:_.type,color:_.color,intensity:_.intensity,position:_.position,direction:_.direction,range:_.range,innerConeAngle:_.innerConeAngle,outerConeAngle:_.outerConeAngle,shadow:_.shadow})}return z.length>0&&(i.__usdaShadowLights=z),i}function Re(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function Ie(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function pe(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 Te=(e,t,i)=>`(${pe(e)}, ${pe(t)}, ${pe(i)})`,Le=(e,t,i,r)=>`(${pe(e)}, ${pe(t)}, ${pe(i)}, ${pe(r)})`;function Pt(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Te(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function Jt(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${pe(e[r*2])}, ${pe(1-e[r*2+1])})`;return i.join(", ")}function ei(e){return Array.from(e).join(", ")}function je(e,t){let i=(t??e.__usdaShadowLights??[]).filter(o=>o?.shadow?.cast),r=new Map,n=0,a=null,l=[...e];for(;l.length>0;){let o=l.pop();if(!o.isXform&&o.positions&&o.positions.length>0){let f=Re(o.materialName,"DefaultMaterial");r.has(f)||r.set(f,{color:o.color||[1,1,1],roughness:o.roughness??.5,metallic:o.metallic??0,clearcoat:o.clearcoat??0,clearcoatRoughness:o.clearcoatRoughness??0,ior:o.ior??1.5,opacity:o.opacity??1,emissiveColor:o.emissiveColor||[0,0,0],textures:o.textures,tslGraph:o.tslGraph})}if(o.timeSamples&&o.timeSamples.times.length>0){let f=o.timeSamples.times[o.timeSamples.times.length-1];f>n&&(n=f)}else o.tslGraph&&n<=0&&JSON.stringify(o.tslGraph).includes('"time"')&&(n=60);if(o.xrTraits?.anchor&&!a&&(a=o.xrTraits.anchor==="vertical"||o.xrTraits.anchor==="wall"?"vertical":"horizontal"),o.children)for(let f=o.children.length-1;f>=0;f--)l.push(o.children[f])}let h="";n>0&&(h=`startTimeCode = 0
|
|
215
|
+
endTimeCode = ${pe(n)}
|
|
251
216
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let
|
|
253
|
-
uniform token preliminary:planeAnchoring:alignment = "${
|
|
254
|
-
`);let
|
|
217
|
+
`);let c="";a&&(c=`uniform token preliminary:anchoring:type = "plane"
|
|
218
|
+
uniform token preliminary:planeAnchoring:alignment = "${a}"
|
|
219
|
+
`);let T=`#usda 1.0
|
|
255
220
|
(
|
|
256
221
|
defaultPrim = "Root"
|
|
257
222
|
metersPerUnit = 1.0
|
|
258
223
|
upAxis = "Y"
|
|
259
|
-
${
|
|
224
|
+
${h})
|
|
260
225
|
|
|
261
226
|
def Xform "Root" (
|
|
262
227
|
kind = "component"
|
|
263
228
|
)
|
|
264
229
|
{
|
|
265
|
-
${
|
|
230
|
+
${c}def Scope "Materials"
|
|
266
231
|
{
|
|
267
|
-
`;for(let[
|
|
268
|
-
float inputs:roughness${
|
|
269
|
-
float inputs:roughness = ${
|
|
270
|
-
`,
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
274
|
-
`:(
|
|
275
|
-
`),
|
|
276
|
-
`),
|
|
277
|
-
`);let
|
|
232
|
+
`;for(let[o,f]of r.entries()){let[p,m,y]=f.color,[w,x,z]=f.emissiveColor,R=`/Root/Materials/${o}`,[_,C,S,N,V]=f.textures||[],b=(M,u)=>`.connect = <${R}/${M}.outputs:${u}>`,P=_?`color3f inputs:diffuseColor${b("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Te(p,m,y)}`,E=C?`float inputs:metallic${b("MetallicRoughnessTexture","b")}
|
|
233
|
+
float inputs:roughness${b("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${pe(f.metallic)}
|
|
234
|
+
float inputs:roughness = ${pe(f.roughness)}`,H="";f.clearcoat>0&&(H+=`float inputs:clearcoat = ${pe(f.clearcoat)}
|
|
235
|
+
`,H+=`float inputs:clearcoatRoughness = ${pe(f.clearcoatRoughness)}
|
|
236
|
+
`),f.ior!==1.5&&(H+=`float inputs:ior = ${pe(f.ior)}
|
|
237
|
+
`),f.opacity<1&&(H+=`float inputs:opacity = ${pe(f.opacity)}
|
|
238
|
+
`),N?H+=`color3f inputs:emissiveColor${b("EmissiveTexture","rgb")}
|
|
239
|
+
`:(w>0||x>0||z>0)&&(H+=`color3f inputs:emissiveColor = ${Te(w,x,z)}
|
|
240
|
+
`),S&&(H+=`normal3f inputs:normal${b("NormalTexture","rgb")}
|
|
241
|
+
`),V&&(H+=`float inputs:occlusion${b("OcclusionTexture","r")}
|
|
242
|
+
`);let v="";if(_||C||S||N||V){v+=`def Shader "PrimvarReader"
|
|
278
243
|
{
|
|
279
244
|
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
245
|
string inputs:varname = "st"
|
|
281
246
|
float2 outputs:result
|
|
282
247
|
}
|
|
283
|
-
`;let
|
|
284
|
-
`:"",
|
|
285
|
-
`:"";
|
|
248
|
+
`;let M=(u,A,j,q)=>{if(!A)return;let Z=A.scale?`float4 inputs:scale = ${Le(A.scale[0],A.scale[1],A.scale[2],A.scale[3])}
|
|
249
|
+
`:"",W=A.bias?`float4 inputs:bias = ${Le(A.bias[0],A.bias[1],A.bias[2],A.bias[3])}
|
|
250
|
+
`:"";v+=`def Shader "${u}"
|
|
286
251
|
{
|
|
287
252
|
uniform token info:id = "UsdUVTexture"
|
|
288
|
-
asset inputs:file = @${
|
|
289
|
-
float2 inputs:st${
|
|
290
|
-
token inputs:sourceColorSpace = "${
|
|
291
|
-
token inputs:wrapS = "${
|
|
292
|
-
token inputs:wrapT = "${
|
|
293
|
-
${
|
|
294
|
-
`};
|
|
295
|
-
`),
|
|
253
|
+
asset inputs:file = @${Ie(A.file)}@
|
|
254
|
+
float2 inputs:st${b("PrimvarReader","result")}
|
|
255
|
+
token inputs:sourceColorSpace = "${j}"
|
|
256
|
+
token inputs:wrapS = "${A.wrapS||"repeat"}"
|
|
257
|
+
token inputs:wrapT = "${A.wrapT||"repeat"}"
|
|
258
|
+
${Z}${W}${q}}
|
|
259
|
+
`};M("DiffuseTexture",_,"sRGB",`float3 outputs:rgb
|
|
260
|
+
`),M("MetallicRoughnessTexture",C,"raw",`float outputs:g
|
|
296
261
|
float outputs:b
|
|
297
|
-
`),
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`)}
|
|
262
|
+
`),M("NormalTexture",S,"raw",`float3 outputs:rgb
|
|
263
|
+
`),M("EmissiveTexture",N,"sRGB",`float3 outputs:rgb
|
|
264
|
+
`),M("OcclusionTexture",V,"raw",`float outputs:r
|
|
265
|
+
`)}let $=`${P}
|
|
266
|
+
${E}
|
|
267
|
+
${H}`,s=f.tslGraph&&Me().tslUsdzSerializer?.(f.tslGraph,o,$);s&&($=s.surfaceInputsUsda||$,v+=s.nodeGraphUsda),T+=`def Material "${o}"
|
|
301
268
|
{
|
|
302
269
|
def Shader "PBRShader"
|
|
303
270
|
{
|
|
304
271
|
uniform token info:id = "UsdPreviewSurface"
|
|
305
|
-
${
|
|
306
|
-
${n}
|
|
307
|
-
${E}token outputs:surface
|
|
272
|
+
${$}token outputs:surface
|
|
308
273
|
}
|
|
309
|
-
token outputs:surface${
|
|
310
|
-
${
|
|
311
|
-
`}
|
|
274
|
+
token outputs:surface${b("PBRShader","surface")}
|
|
275
|
+
${v}}
|
|
276
|
+
`}T+=`}
|
|
312
277
|
def Scope "Meshes"
|
|
313
278
|
{
|
|
314
|
-
`;let
|
|
279
|
+
`;let d=(o,f,p)=>{let m=[];f&&m.push('"MaterialBindingAPI"');let y=!!(o?.rigidBody&&o.rigidBody!=="none"&&(typeof o.rigidBody!="object"||o.rigidBody.enabled!==!1)),w=!!(o?.physics&&o.physics!=="none"||y);w&&m.push(...y?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let x=[];m.length>0&&x.push(`prepend apiSchemas = [${m.join(", ")}]`);let z=Me().xrTraitSerializer;if(o){let N=z?.usdLines(o,Ie)??[];if(!N.length)for(let V of["grab","billboard","follow","anchor","physics"]){let b=V==="follow"&&typeof o.follow=="object"?o.follow.mode??"head":o[V];b!==void 0&&N.push(`string ${V} = "${Ie(b)}"`)}N.length>0&&x.push(`customData = {
|
|
315
280
|
dictionary xr = {
|
|
316
|
-
${
|
|
281
|
+
${N.join(`
|
|
317
282
|
`)}
|
|
318
283
|
}
|
|
319
|
-
}`)}let
|
|
320
|
-
${
|
|
284
|
+
}`)}let R=x.length>0?` (
|
|
285
|
+
${x.join(`
|
|
321
286
|
`)}
|
|
322
|
-
)`:"",
|
|
323
|
-
`:"";if(
|
|
324
|
-
bool physics:kinematicEnabled = ${
|
|
287
|
+
)`:"",_=p?`uniform token visibility = "invisible"
|
|
288
|
+
`:"";if(w){let N=o?.rigidBody??o?.physics,V=N?.body??N?.mode??N;_+=`bool physics:rigidBodyEnabled = true
|
|
289
|
+
bool physics:kinematicEnabled = ${V==="static"||V==="kinematic"}
|
|
325
290
|
bool physics:collisionEnabled = true
|
|
326
|
-
`,
|
|
327
|
-
`)}let
|
|
291
|
+
`,N?.mass>0&&Number.isFinite(N.mass)&&(_+=`float physics:mass = ${pe(N.mass)}
|
|
292
|
+
`)}let C=wt(o),S=(C?`def SpatialAudio "AudioEmitter"
|
|
328
293
|
{
|
|
329
|
-
${
|
|
330
|
-
`:""}uniform token inputs:auralMode = "${
|
|
331
|
-
uniform token inputs:playbackMode = "${
|
|
332
|
-
double gain = ${
|
|
294
|
+
${C.src?`asset inputs:file = @${Ie(C.src)}@
|
|
295
|
+
`:""}uniform token inputs:auralMode = "${C.isGlobal?"nonSpatial":"spatial"}"
|
|
296
|
+
uniform token inputs:playbackMode = "${C.loop?"loopFromStart":"onceFromStart"}"
|
|
297
|
+
double gain = ${pe(C.volume)}
|
|
333
298
|
}
|
|
334
|
-
`:"";return{header:
|
|
335
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
336
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
299
|
+
`:"")+(o?z?.usdPrims?.(o)??"":"");return{header:R,body:_,tail:S}},g=o=>{if(o.timeSamples&&o.timeSamples.times.length>0){let x=o.timeSamples,z=(S,N,V)=>x.times.map((b,P)=>`${pe(b)}: ${V(S?.[P]||N)}`).join(", "),R=z(x.translations,[0,0,0],S=>Te(S[0],S[1],S[2])),_=z(x.rotations,[0,0,0,1],S=>{let N=Math.hypot(S[0],S[1],S[2],S[3])||1;return Le(S[3]/N,S[0]/N,S[1]/N,S[2]/N)}),C=z(x.scales,[1,1,1],S=>Te(S[0],S[1],S[2]));return`double3 xformOp:translate.timeSamples = { ${R} }
|
|
300
|
+
quatf xformOp:orient.timeSamples = { ${_} }
|
|
301
|
+
double3 xformOp:scale.timeSamples = { ${C} }
|
|
337
302
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
338
|
-
`}let
|
|
339
|
-
`,
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
`),
|
|
343
|
-
int[] faceVertexCounts = [${
|
|
344
|
-
int[] faceVertexIndices = [${
|
|
345
|
-
point3f[] points = [${
|
|
346
|
-
`;return
|
|
303
|
+
`}let f=[],p="",m=o.translation;m&&(Math.abs(m[0])>1e-7||Math.abs(m[1])>1e-7||Math.abs(m[2])>1e-7)&&(p+=`double3 xformOp:translate = ${Te(m[0],m[1],m[2])}
|
|
304
|
+
`,f.push('"xformOp:translate"'));let y=o.rotation;if(y){let x=Math.hypot(y[0],y[1],y[2],y[3])||1,z=y[0]/x,R=y[1]/x,_=y[2]/x,C=y[3]/x;(1-Math.abs(C)>1e-7||Math.hypot(z,R,_)>1e-7)&&(p+=`quatf xformOp:orient = ${Le(C,z,R,_)}
|
|
305
|
+
`,f.push('"xformOp:orient"'))}let w=o.scale;return w&&(Math.abs(w[0]-1)>1e-7||Math.abs(w[1]-1)>1e-7||Math.abs(w[2]-1)>1e-7)&&(p+=`float3 xformOp:scale = ${Te(w[0],w[1],w[2])}
|
|
306
|
+
`,f.push('"xformOp:scale"')),f.length>0&&(p+=`uniform token[] xformOpOrder = [${f.join(", ")}]
|
|
307
|
+
`),p},I=o=>{let f=o.positions.length/3,p=1/0,m=1/0,y=1/0,w=-1/0,x=-1/0,z=-1/0;for(let N=0;N<f;N++){let V=o.positions[N*3],b=o.positions[N*3+1],P=o.positions[N*3+2];V<p&&(p=V),V>w&&(w=V),b<m&&(m=b),b>x&&(x=b),P<y&&(y=P),P>z&&(z=P)}isFinite(p)||(p=m=y=-1,w=x=z=1);let R=Math.floor(o.indices.length/3),_=Re(o.materialName,"DefaultMaterial"),C=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",S=`float3[] extent = [${Te(p,m,y)}, ${Te(w,x,z)}]
|
|
308
|
+
int[] faceVertexCounts = [${C}]
|
|
309
|
+
int[] faceVertexIndices = [${ei(o.indices)}]
|
|
310
|
+
point3f[] points = [${Pt(o.positions)}]
|
|
311
|
+
`;return o.normals&&o.normals.length===o.positions.length&&(S+=`normal3f[] normals = [${Pt(o.normals)}] (
|
|
347
312
|
interpolation = "vertex"
|
|
348
313
|
)
|
|
349
|
-
`),
|
|
314
|
+
`),o.uvs&&o.uvs.length===f*2&&(S+=`texCoord2f[] primvars:st = [${Jt(o.uvs,f)}] (
|
|
350
315
|
interpolation = "vertex"
|
|
351
316
|
)
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
|
|
317
|
+
`),S+=`rel material:binding = </Root/Materials/${_}>
|
|
318
|
+
`,o.castShadow===!1&&i.length>0&&(S+=`bool primvars:doNotCastShadows = 1
|
|
319
|
+
`),S},L=new Set,D=[];for(let o=e.length-1;o>=0;o--)D.push({node:e[o],siblings:L});let O=0;for(;D.length>0;){let o=D.pop();if(o.close){T+=`}
|
|
320
|
+
`;continue}let{node:f,siblings:p}=o,m=!!(f.isXform||f.positions.length===0),y=et(p,Re(f.name,m?`Group_${O}`:`Mesh_${O}`));O++;let w=f.children||[];if(m){let x=d(f.xrTraits,!1,f.invisible);T+=`def Xform "${y}"${x.header}
|
|
355
321
|
{
|
|
356
|
-
${
|
|
322
|
+
${x.body}${g(f)}${x.tail}`,D.push({close:!0});let z=new Set;for(let R=w.length-1;R>=0;R--)D.push({node:w[R],siblings:z})}else if(w.length>0){let x=d(f.xrTraits,!1,f.invisible),z=`${y}_mesh`;T+=`def Xform "${y}"${x.header}
|
|
357
323
|
{
|
|
358
|
-
${
|
|
324
|
+
${x.body}${g(f)}${x.tail}`,T+=`def Mesh "${z}" (
|
|
359
325
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
360
326
|
)
|
|
361
327
|
{
|
|
362
|
-
${
|
|
363
|
-
`,D.push({close:!0});let
|
|
328
|
+
${I(f)}}
|
|
329
|
+
`,D.push({close:!0});let R=new Set([z]);for(let _=w.length-1;_>=0;_--)D.push({node:w[_],siblings:R})}else{let x=d(f.xrTraits,!0,f.invisible);T+=`def Mesh "${y}"${x.header}
|
|
364
330
|
{
|
|
365
|
-
${
|
|
366
|
-
`}}
|
|
367
|
-
|
|
368
|
-
|
|
331
|
+
${x.body}${g(f)}${I(f)}${x.tail}}
|
|
332
|
+
`}}if(T+=`}
|
|
333
|
+
`,i.length>0){T+=`def Scope "Lights"
|
|
334
|
+
{
|
|
335
|
+
`;let o=new Set;for(let f=0;f<i.length;f++){let p=i[f],m=et(o,Re(p.name,`Light_${f}`)),y=p.type==="directional"?"DistantLight":p.type==="spot"?"DiskLight":"SphereLight",w=p.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[x,z,R]=p.color||[1,1,1],[_,C,S]=p.position||[0,5,5],N=-_,V=-C,b=-S;p.direction&&p.direction.length>=3&&(p.type==="directional"?(N=-p.direction[0],V=-p.direction[1],b=-p.direction[2]):(N=p.direction[0],V=p.direction[1],b=p.direction[2]));let[P,E,H,v]=yt(N,V,b),$="",s=[];p.type!=="directional"&&(Math.abs(_)>1e-7||Math.abs(C)>1e-7||Math.abs(S)>1e-7)&&($+=`double3 xformOp:translate = ${Te(_,C,S)}
|
|
336
|
+
`,s.push('"xformOp:translate"')),p.type!=="point"&&(1-Math.abs(v)>1e-7||Math.hypot(P,E,H)>1e-7)&&($+=`quatf xformOp:orient = ${Le(v,P,E,H)}
|
|
337
|
+
`,s.push('"xformOp:orient"')),s.length>0&&($+=`uniform token[] xformOpOrder = [${s.join(", ")}]
|
|
338
|
+
`);let M="";if(p.type==="spot"){let u=(p.outerConeAngle??Math.PI/3)*180/Math.PI,A=(p.innerConeAngle??u*.8)*180/Math.PI,j=u>1e-4?Math.max(0,Math.min(1,1-A/u)):0;M=`float inputs:shaping:cone:angle = ${pe(u)}
|
|
339
|
+
float inputs:shaping:cone:softness = ${pe(j)}
|
|
340
|
+
`}T+=`def ${y} "${m}" (
|
|
341
|
+
prepend apiSchemas = ${w}
|
|
342
|
+
)
|
|
343
|
+
{
|
|
344
|
+
color3f inputs:color = ${Te(x,z,R)}
|
|
345
|
+
float inputs:intensity = ${pe(p.intensity??1)}
|
|
346
|
+
bool inputs:shadow:enable = 1
|
|
347
|
+
${M}${$}}
|
|
348
|
+
`}T+=`}
|
|
349
|
+
`}return T+=`}
|
|
350
|
+
`,T}function ti(e,t){if(e&&typeof e.traverse=="function"){let n=it(e,t);return je(n)}let i=$e(e),r=He(i);return je(r)}var ze=null;function St(e){if(!ze){ze=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;ze[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=ze[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function Ct(e){let t=[],i=0,r=[];for(let d of e){let g=Be(d.filename),I=St(d.data),L=d.data.length,D=30+g.length,O=(i+D)%64,o=O!==0?64-O:0;o>0&&o<4&&(o+=64);let f=new Uint8Array(D+o),p=new DataView(f.buffer);p.setUint32(0,67324752,!0),p.setUint16(4,20,!0),p.setUint32(14,I,!0),p.setUint32(18,L,!0),p.setUint32(22,L,!0),p.setUint16(26,g.length,!0),p.setUint16(28,o,!0),f.set(g,30),o>=4&&(p.setUint16(D,6534,!0),p.setUint16(D+2,o-4,!0)),t.push({offset:i,size:L,crc:I,filenameBytes:g,entry:d}),r.push(f,d.data),i+=f.length+d.data.length}let n=i;for(let d of t){let g=new Uint8Array(46+d.filenameBytes.length),I=new DataView(g.buffer);I.setUint32(0,33639248,!0),I.setUint16(4,20,!0),I.setUint16(6,20,!0),I.setUint32(16,d.crc,!0),I.setUint32(20,d.size,!0),I.setUint32(24,d.size,!0),I.setUint16(28,d.filenameBytes.length,!0),I.setUint32(42,d.offset,!0),g.set(d.filenameBytes,46),r.push(g),i+=g.length}let a=i-n,l=new Uint8Array(22),h=new DataView(l.buffer);h.setUint32(0,101010256,!0),h.setUint16(8,t.length,!0),h.setUint16(10,t.length,!0),h.setUint32(12,a,!0),h.setUint32(16,n,!0),r.push(l),i+=22;let c=new Uint8Array(i),T=0;for(let d of r)c.set(d,T),T+=d.length;return c}function Rt(e){let t=[{filename:"model.usda",data:Be(je(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let n=r.pop();for(let a of n.textures||[])a?.file&&a.data?.byteLength&&!i.has(a.file)&&(i.add(a.file),t.push({filename:a.file,data:a.data}));if(n.children)for(let a=n.children.length-1;a>=0;a--)r.push(n.children[a])}return Ct(t)}function ii(e){return Rt(it(e))}function Dt(e){return Rt(He($e(e)))}function _t(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Dt(e)}function ri(e){let t=_t(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}export{tt as aiTextureKeyOf,Ct as buildUSDZZip,St as calculateCRC32,rt as compileInteractivityGraph,ri as createUSDZBlob,Be as encodeUtf8,He as extractMeshesFromGLB,it as extractMeshesFromScene,ti as generateUSDA,je as generateUSDAFromMeshes,_t as generateUSDZ,Dt as glbToUSDZ,Re as sanitizeUsdIdentifier,Ie as sanitizeUsdStringLiteral,Tt as sceneToCanvas3D,Qt as sceneToGLB,ii as sceneToUSDZ,Yt as withAITextureKey};
|