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-xr.cjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var Ve=Object.defineProperty,It=Object.getOwnPropertyDescriptor,_t=Object.getOwnPropertyNames,kt=Object.prototype.hasOwnProperty,Ut=(e,t)=>{for(var i in t)Ve(e,i,{get:t[i],enumerable:!0})},Nt=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of _t(t))!kt.call(e,a)&&a!==i&&Ve(e,a,{get:()=>t[a],enumerable:!(r=It(t,a))||r.enumerable});return e},Bt=e=>Nt(Ve({},"__esModule",{value:!0}),e),mn={};Ut(mn,{WebXRSessionManager:()=>Be,activateAR:()=>ln,buildUSDZZip:()=>Ze,calculateCRC32:()=>Ye,createSceneViewerIntent:()=>Ct,createUSDZBlob:()=>et,generateUSDA:()=>Dt,generateUSDZ:()=>Je,getARCapabilities:()=>st,getAvailableARModes:()=>on,getBestARMode:()=>an,glbToUSDZ:()=>Qe,isQuickLookSupported:()=>nt,isSceneViewerSupported:()=>rt,isWebXRSupported:()=>it,launchQuickLook:()=>tt,launchSceneViewer:()=>Ft}),module.exports=Bt(mn);function le(){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 c=1/(r-a);return e[10]=(a+r)*c,e[14]=2*a*r*c,e}function Le(e,t,i,r){let[a,s,c]=t,[l,g,d]=r,[v,M,I]=i,D=a-v,u=s-M,x=c-I,C=Math.hypot(D,u,x);C<=1e-5?(D=0,u=0,x=1):(D/=C,u/=C,x/=C);let R=g*x-d*u,T=d*D-l*x,m=l*u-g*D;C=Math.hypot(R,T,m),C<=1e-5?(R=0,T=0,m=0):(R/=C,T/=C,m/=C);let h=u*m-x*T,w=x*R-D*m,y=D*T-u*R;return C=Math.hypot(h,w,y),C<=1e-5?(h=0,w=0,y=0):(h/=C,w/=C,y/=C),e[0]=R,e[1]=h,e[2]=D,e[3]=0,e[4]=T,e[5]=w,e[6]=u,e[7]=0,e[8]=m,e[9]=y,e[10]=x,e[11]=0,e[12]=-(R*a+T*s+m*c),e[13]=-(h*a+w*s+y*c),e[14]=-(D*a+u*s+x*c),e[15]=1,e}function fe(e,t,i){let r=t[0],a=t[1],s=t[2],c=t[3],l=t[4],g=t[5],d=t[6],v=t[7],M=t[8],I=t[9],D=t[10],u=t[11],x=t[12],C=t[13],R=t[14],T=t[15],m=i[0],h=i[1],w=i[2],y=i[3];return e[0]=m*r+h*l+w*M+y*x,e[1]=m*a+h*g+w*I+y*C,e[2]=m*s+h*d+w*D+y*R,e[3]=m*c+h*v+w*u+y*T,m=i[4],h=i[5],w=i[6],y=i[7],e[4]=m*r+h*l+w*M+y*x,e[5]=m*a+h*g+w*I+y*C,e[6]=m*s+h*d+w*D+y*R,e[7]=m*c+h*v+w*u+y*T,m=i[8],h=i[9],w=i[10],y=i[11],e[8]=m*r+h*l+w*M+y*x,e[9]=m*a+h*g+w*I+y*C,e[10]=m*s+h*d+w*D+y*R,e[11]=m*c+h*v+w*u+y*T,m=i[12],h=i[13],w=i[14],y=i[15],e[12]=m*r+h*l+w*M+y*x,e[13]=m*a+h*g+w*I+y*C,e[14]=m*s+h*d+w*D+y*R,e[15]=m*c+h*v+w*u+y*T,e}function Ge(e,t,i,r){let a=t[0],s=t[1],c=t[2],l=t[3],g=a+a,d=s+s,v=c+c,M=a*g,I=a*d,D=a*v,u=s*d,x=s*v,C=c*v,R=l*g,T=l*d,m=l*v,h=r[0],w=r[1],y=r[2];return e[0]=(1-(u+C))*h,e[1]=(I+m)*h,e[2]=(D-T)*h,e[3]=0,e[4]=(I-m)*w,e[5]=(1-(M+C))*w,e[6]=(x+R)*w,e[7]=0,e[8]=(D+T)*y,e[9]=(x-R)*y,e[10]=(1-(M+u))*y,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function ve(e,t,i=0){let r=t[0],a=t[1],s=t[2],c=t[4],l=t[5],g=t[6],d=t[8],v=t[9],M=t[10],I=M*l-g*v,D=-M*c+g*d,u=v*c-l*d,x=r*I+a*D+s*u;return!x||i>0&&(!Number.isFinite(x)||Math.abs(x)<=i)||(x=1/x,e[0]=I*x,e[1]=D*x,e[2]=u*x,e[3]=(-M*a+s*v)*x,e[4]=(M*r-s*d)*x,e[5]=(-v*r+a*d)*x,e[6]=(g*a-s*l)*x,e[7]=(-g*r+s*c)*x,e[8]=(l*r-a*c)*x),e}function ot(e,t){let i=t[0],r=t[1],a=t[2],s=t[3],c=t[4],l=t[5],g=t[6],d=t[7],v=t[8],M=t[9],I=t[10],D=t[11],u=t[12],x=t[13],C=t[14],R=t[15],T=i*l-r*c,m=i*g-a*c,h=i*d-s*c,w=r*g-a*l,y=r*d-s*l,F=a*d-s*g,U=v*x-M*u,_=v*C-I*u,k=v*R-D*u,P=M*C-I*x,N=M*R-D*x,S=I*R-D*C,o=T*S-m*N+h*P+w*k-y*_+F*U;return o?(o=1/o,e[0]=(l*S-g*N+d*P)*o,e[1]=(a*N-r*S-s*P)*o,e[2]=(x*F-C*y+R*w)*o,e[3]=(I*y-M*F-D*w)*o,e[4]=(g*k-c*S-d*_)*o,e[5]=(i*S-a*k+s*_)*o,e[6]=(C*h-u*F-R*m)*o,e[7]=(v*F-I*h+D*m)*o,e[8]=(c*N-l*k+d*U)*o,e[9]=(r*k-i*N-s*U)*o,e[10]=(u*y-x*h+R*T)*o,e[11]=(M*h-v*y-D*T)*o,e[12]=(l*_-c*P-g*U)*o,e[13]=(i*P-r*_+a*U)*o,e[14]=(x*m-u*w-C*T)*o,e[15]=(v*w-M*m+I*T)*o,e):null}function $e(e,t,i,r,a){let s=a[0]*t+a[4]*i+a[8]*r+a[12],c=a[1]*t+a[5]*i+a[9]*r+a[13],l=a[2]*t+a[6]*i+a[10]*r+a[14],g=a[3]*t+a[7]*i+a[11]*r+a[15],d=g!==0?1/g:1;e[0]=s*d,e[1]=c*d,e[2]=l*d}function at(e,t,i,r,a,s,c,l,g,d,v,M,I,D,u,x,C=0){let R=d-c,T=v-l,m=M-g,h=I-c,w=D-l,y=u-g,F=a*y-s*w,U=s*h-r*y,_=r*w-a*h,k=R*F+T*U+m*_;if(k>-1e-7&&k<1e-7)return!1;let P=1/k,N=e-c,S=t-l,o=i-g,V=P*(N*F+S*U+o*_);if(V<-C||V>1+C)return!1;let K=S*m-o*T,f=o*R-N*m,b=N*T-S*R,n=P*(r*K+a*f+s*b);if(n<-C||V+n>1+C)return!1;let p=P*(h*K+w*f+y*b);if(p>1e-4&&p<x.distance){x.distance=p,x.point=[e+r*p,t+a*p,i+s*p];let B=T*y-m*w,z=m*h-R*y,j=R*w-T*h,ee=Math.hypot(B,z,j)||1;return x.normal=[B/ee,z/ee,j/ee],!0}return!1}function ut(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let v=0;v<i;v++)r.push(le());if(i===0)return r;let a=new Set;for(let v of e.nodes)if(Array.isArray(v.children))for(let M of v.children)a.add(M);let s=new Set,c=128,l=(v,M,I=0)=>{if(I>c||v<0||v>=i||s.has(v))return;s.add(v);let D=e.nodes[v];if(!D)return;let u=le();if(t&&t[v])u.set(t[v]);else if(D.matrix&&D.matrix.length===16)u.set(D.matrix);else{let C=D.translation||[0,0,0],R=D.rotation||[0,0,0,1],T=D.scale||[1,1,1];Ge(u,R,C,T)}let x=r[v];if(M?fe(x,M,u):x.set(u),Array.isArray(D.children))for(let C of D.children)typeof C=="number"&&l(C,x,I+1)},g=[],d=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(d&&Array.isArray(d.nodes))g.push(...d.nodes);else for(let v=0;v<i;v++)a.has(v)||g.push(v);for(let v of g)l(v,null);for(let v=0;v<i;v++)!a.has(v)&&!g.includes(v)&&l(v,null);return r}var De="__THREE_LIVE_REGISTRY__";function be(){let e=typeof globalThis<"u"?globalThis:{};if(!e[De]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,De,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[De]=t}}return e[De]}var ce=be().plugins;function ct(e){let t=be().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function lt(){return be().plugins}function mt(e,t,i){let r=[],a=new Map,s=[],c=[],l=[],g=new Map,d=m=>{let h=a.get(m);return h===void 0&&(h=r.length,r.push({op:m}),a.set(m,h)),h},v=m=>{let h=g.get(m);return h===void 0&&(h=l.length,l.push({id:m}),g.set(m,h)),h},M=(m,h={})=>s.push({declaration:d(m),...h})-1,I=(m,h,w)=>c.push({id:m,type:h,value:w})-1,D=m=>({node:m,socket:"value"}),u=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(u&&typeof u=="object"){let m=Array.isArray(u.graphs)?u.graphs[u.graph??0]:u;if(m&&Array.isArray(m.nodes)){let h=Array.isArray(m.declarations)?m.declarations:[];for(let w of h)w?.op&&d(w.op);Array.isArray(m.variables)&&c.push(...m.variables);for(let w of m.events||[])w?.id&&v(w.id);for(let w of m.nodes){if(!w||typeof w!="object")continue;let y=w.op||(typeof w.declaration=="number"?h[w.declaration]?.op:"");s.push(y?{...w,declaration:d(y)}:{...w})}}}let x=(m,h,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,h)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,h)}/${w}`:w==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${w}`,C=new Map;e.forEach((m,h)=>{typeof m?.name=="string"&&!C.has(m.name)&&C.set(m.name,h)});let R=(m,h)=>typeof m.target=="string"&&C.has(m.target)?C.get(m.target):typeof m.targetNode=="number"?m.targetNode:h,T=m=>{let h=e[m];return(typeof h?.mesh=="number"?t[h.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<e.length;m++){let h=e[m],w=h?.extras?.interactivity;if(!w||typeof w!="object")continue;let y=(typeof h.mesh=="number"?t[h.mesh]?.primitives?.[0]?.material:0)??0,F=_=>{let k=Array.isArray(_)?_:[_],P=[];for(let S=0;S<k.length;S++){let o=k[S];if(!o||typeof o!="object")continue;let V=o.action||"interpolate",K=typeof o.duration=="number"?o.duration:.35;if(V==="toggleTransform"){let f=o.property==="rotation"||o.property==="scale"?o.property:"translation",b=f==="rotation"?h.rotation||[0,0,0,1]:f==="scale"?h.scale||[1,1,1]:h.translation||[0,0,0],n=`/nodes/${m}/${f}`,p=I(`__toggle_${m}_${S}`,"bool",!1),B=M("variable/get",{configuration:{variable:p}}),z=M("math/not",{values:{a:D(B)}}),j=M("variable/set",{configuration:{variable:p},values:{value:D(z)}}),ee=M("pointer/interpolate",{configuration:{pointer:n},values:{value:{value:Array.isArray(o.to)?o.to:b},duration:{value:K}}}),L=M("pointer/interpolate",{configuration:{pointer:n},values:{value:{value:Array.isArray(o.from)?o.from:b},duration:{value:K}}});s[j].flows={out:{node:M("flow/branch",{values:{condition:D(B)},flows:{true:{node:ee},false:{node:L}}})}},P.push(j)}else if(V==="interpolate"){let f=o.to??o.value;if(f===void 0)continue;let b={value:{value:f},duration:{value:K}};o.from!==void 0&&(b.from={value:o.from}),P.push(M("pointer/interpolate",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(R(o,m),T(R(o,m)),o.property)},values:b}))}else if(V==="setProperty"){if(o.value===void 0)continue;P.push(M("pointer/set",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(R(o,m),T(R(o,m)),o.property)},values:{value:{value:o.value}}}))}else if(V==="toggleVisibility"){let f=R(o,m),b=I(`__vis_${f}_${S}`,"bool",!0),n=M("variable/get",{configuration:{variable:b}}),p=M("math/not",{values:{a:D(n)}}),B=M("variable/set",{configuration:{variable:b},values:{value:D(p)}});s[B].flows={out:{node:M("pointer/set",{configuration:{pointer:`/nodes/${f}/extensions/KHR_node_visibility/visible`},values:{value:D(n)}})}},P.push(B)}else if(V==="cycleMaterialColor"&&Array.isArray(o.colors)&&o.colors.length>0){let f=typeof o.duration=="number"?o.duration:.25,b=`/materials/${Math.max(0,y)}/pbrMetallicRoughness/baseColorFactor`,n=I(`__color_idx_${m}_${S}`,"int",0),p=M("variable/get",{configuration:{variable:n}}),B=M("math/add",{values:{a:D(p),b:{value:1}}}),z=M("math/rem",{values:{a:D(B),b:{value:o.colors.length}}}),j=M("variable/set",{configuration:{variable:n},values:{value:D(z)}}),ee={};for(let L=0;L<o.colors.length;L++){let X=o.colors[L],J=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];ee[String(L)]={node:f>0?M("pointer/interpolate",{configuration:{pointer:b},values:{value:{value:J},duration:{value:f}}}):M("pointer/set",{configuration:{pointer:b},values:{value:{value:J}}})}}s[j].flows={out:{node:M("flow/switch",{values:{selection:D(p)},flows:ee})}},P.push(j)}else if(V==="playAnimation")P.push(M("animation/start",{configuration:{animation:o.animation??o.clip??0}}));else if(V==="stopAnimation")P.push(M("animation/stop"));else if(V==="sendEvent"){let f={};for(let[b,n]of Object.entries(o.values||{}))f[b]={value:n};P.push(M("event/send",{configuration:{event:v(String(o.event??o.id??"custom"))},values:f}))}}if(!P.length)return null;if(P.length===1)return P[0];let N={};return P.forEach((S,o)=>{N[String(o)]={node:S}}),M("flow/sequence",{flows:N})},U=(_,k,P)=>{let N=F(k);N!==null&&M(_,{...P?{configuration:P}:{},flows:{out:{node:N}}})};if(w.onSelect&&U("pointer/onSelect",w.onSelect,{nodeIndex:m}),w.onHoverIn&&U("pointer/onHoverIn",w.onHoverIn,{nodeIndex:m}),w.onHoverOut&&U("pointer/onHoverOut",w.onHoverOut,{nodeIndex:m}),w.onStart&&U("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[_,k]of Object.entries(w.onReceive))U("event/receive",k,{event:v(_)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:l}],graph:0}:null}var Ot={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function He(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 c=i.componentType??5126,l=Ot[c];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${c}`);let g=l*r,d=a.byteStride&&a.byteStride>0?a.byteStride:g,v=(a.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(v)||v<0||d<g||v+(s-1)*d+g>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(c===5126&&d===g&&v%4===0)return new Float32Array(t,v,s*r);let M=new DataView(t),I=i.normalized===!0,D=new Float32Array(s*r);for(let u=0;u<s;u++){let x=v+u*d;for(let C=0;C<r;C++){let R=x+C*l,T;switch(c){case 5126:T=M.getFloat32(R,!0);break;case 5120:T=M.getInt8(R),I&&(T=Math.max(T/127,-1));break;case 5121:T=M.getUint8(R),I&&(T/=255);break;case 5122:T=M.getInt16(R,!0),I&&(T=Math.max(T/32767,-1));break;case 5123:T=M.getUint16(R,!0),I&&(T/=65535);break;default:T=M.getUint32(R,!0),I&&(T/=4294967295)}D[u*r+C]=T}}return D}function ht(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),c=Number(t.rotation??0)||0,l=Math.cos(c),g=Math.sin(c),d=(Number.isFinite(a)?a:1)*l,v=(Number.isFinite(a)?a:1)*g,M=-(Number.isFinite(s)?s:1)*g,I=(Number.isFinite(s)?s:1)*l;for(let D=0;D+1<e.length;D+=2){let u=e[D],x=e[D+1];e[D]=d*u+v*x+i,e[D+1]=M*u+I*x+r}}function Pe(e,t,i,r=!0){let a=[],s=null;try{for(let[c,l]of[[35633,t],[35632,i]]){let g=e.createShader(c);if(!g){if(r)throw new Error("Shader allocation failed");return null}if(a.push(g),e.shaderSource(g,l),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 c of a)e.attachShader(s,c);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let c=r?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${c}`);return null}return s}finally{for(let c of a)s&&e.detachShader?.(s,c),e.deleteShader?.(c)}}var pt=["neutral","reinhard","none","aces","agx"];function Xe(e){let t=String(e??"").trim().toLowerCase();return pt.includes(t)?t:"neutral"}function Vt(e){return pt.indexOf(Xe(e))}function Gt(e){return new TextDecoder().decode(e)}var bt=be().decoders;function $t(e,t){bt.set(e.toLowerCase(),t)}function we(e){return bt.get(e.toLowerCase())}function gt(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 a=i.getUint32(4,!0);if(a!==2)throw new Error(`Unsupported GLB version: ${a}`);let s=i.getUint32(8,!0),c=12,l=null,g=null;for(;c+8<=s&&c+8<=t.byteLength;){let I=i.getUint32(c,!0),D=i.getUint32(c+4,!0),u=c+8;if(u+I>t.byteLength)throw new Error(`Truncated GLB chunk: required ${u+I} bytes, buffer has ${t.byteLength}`);if(D===1313821514){let x=new Uint8Array(t,u,I),C=Gt(x);l=JSON.parse(C,(R,T)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:T)}else D===5130562&&(g=t.slice(u,u+I));c=u+I}if(!l)throw new Error("Missing JSON chunk in GLB");let d=l.extensionsRequired||[];if(d.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 I of["EXT_meshopt_compression","KHR_meshopt_compression"])if(d.includes(I)&&!we("meshopt"))throw new Error(`Model requires ${I}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(d.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),M={gltf:l,bin:v,animations:[]};for(let I of ce)I.onParseGLB?.(M);return M}function Ht(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 Se(e){if(Ht(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return gt(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var yt=`#version 300 es
|
|
16
|
+
*/var Ye=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,jt=Object.getOwnPropertyNames,Xt=Object.prototype.hasOwnProperty,qt=(e,t)=>{for(var i in t)Ye(e,i,{get:t[i],enumerable:!0})},Kt=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of jt(t))!Xt.call(e,n)&&n!==i&&Ye(e,n,{get:()=>t[n],enumerable:!(r=Wt(t,n))||r.enumerable});return e},Yt=e=>Kt(Ye({},"__esModule",{value:!0}),e),Sn={};qt(Sn,{WebXRSessionManager:()=>je,activateAR:()=>Tn,buildUSDZZip:()=>ft,calculateCRC32:()=>ht,createSceneViewerIntent:()=>zt,createUSDZBlob:()=>bt,generateUSDA:()=>Vt,generateUSDZ:()=>pt,getARCapabilities:()=>Mt,getAvailableARModes:()=>vn,getBestARMode:()=>Mn,glbToUSDZ:()=>dt,isQuickLookSupported:()=>yt,isSceneViewerSupported:()=>xt,isWebXRSupported:()=>vt,launchQuickLook:()=>gt,launchSceneViewer:()=>Ht}),module.exports=Yt(Sn);function ye(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ze(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 Qe(e,t,i,r){let[n,a,l]=t,[o,c,S]=r,[p,x,E]=i,I=n-p,T=a-x,F=l-E,u=Math.hypot(I,T,F);u<=1e-5?(I=0,T=0,F=1):(I/=u,T/=u,F/=u);let m=c*F-S*T,g=S*I-o*F,d=o*T-c*I;u=Math.hypot(m,g,d),u<=1e-5?(m=0,g=0,d=0):(m/=u,g/=u,d/=u);let b=T*d-F*g,w=F*m-I*d,f=I*g-T*m;return u=Math.hypot(b,w,f),u<=1e-5?(b=0,w=0,f=0):(b/=u,w/=u,f/=u),e[0]=m,e[1]=b,e[2]=I,e[3]=0,e[4]=g,e[5]=w,e[6]=T,e[7]=0,e[8]=d,e[9]=f,e[10]=F,e[11]=0,e[12]=-(m*n+g*a+d*l),e[13]=-(b*n+w*a+f*l),e[14]=-(I*n+T*a+F*l),e[15]=1,e}function xe(e,t,i){let r=t[0],n=t[1],a=t[2],l=t[3],o=t[4],c=t[5],S=t[6],p=t[7],x=t[8],E=t[9],I=t[10],T=t[11],F=t[12],u=t[13],m=t[14],g=t[15],d=i[0],b=i[1],w=i[2],f=i[3];return e[0]=d*r+b*o+w*x+f*F,e[1]=d*n+b*c+w*E+f*u,e[2]=d*a+b*S+w*I+f*m,e[3]=d*l+b*p+w*T+f*g,d=i[4],b=i[5],w=i[6],f=i[7],e[4]=d*r+b*o+w*x+f*F,e[5]=d*n+b*c+w*E+f*u,e[6]=d*a+b*S+w*I+f*m,e[7]=d*l+b*p+w*T+f*g,d=i[8],b=i[9],w=i[10],f=i[11],e[8]=d*r+b*o+w*x+f*F,e[9]=d*n+b*c+w*E+f*u,e[10]=d*a+b*S+w*I+f*m,e[11]=d*l+b*p+w*T+f*g,d=i[12],b=i[13],w=i[14],f=i[15],e[12]=d*r+b*o+w*x+f*F,e[13]=d*n+b*c+w*E+f*u,e[14]=d*a+b*S+w*I+f*m,e[15]=d*l+b*p+w*T+f*g,e}function Je(e,t,i,r){let n=t[0],a=t[1],l=t[2],o=t[3],c=n+n,S=a+a,p=l+l,x=n*c,E=n*S,I=n*p,T=a*S,F=a*p,u=l*p,m=o*c,g=o*S,d=o*p,b=r[0],w=r[1],f=r[2];return e[0]=(1-(T+u))*b,e[1]=(E+d)*b,e[2]=(I-g)*b,e[3]=0,e[4]=(E-d)*w,e[5]=(1-(x+u))*w,e[6]=(F+m)*w,e[7]=0,e[8]=(I+g)*f,e[9]=(F-m)*f,e[10]=(1-(x+T))*f,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Le(e,t,i=0){let r=t[0],n=t[1],a=t[2],l=t[4],o=t[5],c=t[6],S=t[8],p=t[9],x=t[10],E=x*o-c*p,I=-x*l+c*S,T=p*l-o*S,F=r*E+n*I+a*T;return!F||i>0&&(!Number.isFinite(F)||Math.abs(F)<=i)||(F=1/F,e[0]=E*F,e[1]=I*F,e[2]=T*F,e[3]=(-x*n+a*p)*F,e[4]=(x*r-a*S)*F,e[5]=(-p*r+n*S)*F,e[6]=(c*n-a*o)*F,e[7]=(-c*r+a*l)*F,e[8]=(o*r-n*l)*F),e}function At(e,t){let i=t[0],r=t[1],n=t[2],a=t[3],l=t[4],o=t[5],c=t[6],S=t[7],p=t[8],x=t[9],E=t[10],I=t[11],T=t[12],F=t[13],u=t[14],m=t[15],g=i*o-r*l,d=i*c-n*l,b=i*S-a*l,w=r*c-n*o,f=r*S-a*o,z=n*S-a*c,_=p*F-x*T,L=p*u-E*T,R=p*m-I*T,C=x*u-E*F,$=x*m-I*F,B=E*m-I*u,y=g*B-d*$+b*C+w*R-f*L+z*_;return y?(y=1/y,e[0]=(o*B-c*$+S*C)*y,e[1]=(n*$-r*B-a*C)*y,e[2]=(F*z-u*f+m*w)*y,e[3]=(E*f-x*z-I*w)*y,e[4]=(c*R-l*B-S*L)*y,e[5]=(i*B-n*R+a*L)*y,e[6]=(u*b-T*z-m*d)*y,e[7]=(p*z-E*b+I*d)*y,e[8]=(l*$-o*R+S*_)*y,e[9]=(r*R-i*$-a*_)*y,e[10]=(T*f-F*b+m*g)*y,e[11]=(x*b-p*f-I*g)*y,e[12]=(o*L-l*C-c*_)*y,e[13]=(i*C-r*L+n*_)*y,e[14]=(F*d-T*w-u*g)*y,e[15]=(p*w-x*d+E*g)*y,e):null}function et(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],o=n[2]*t+n[6]*i+n[10]*r+n[14],c=n[3]*t+n[7]*i+n[11]*r+n[15],S=c!==0?1/c:1;e[0]=a*S,e[1]=l*S,e[2]=o*S}function wt(e,t,i,r,n,a,l,o,c,S,p,x,E,I,T,F,u=0){let m=S-l,g=p-o,d=x-c,b=E-l,w=I-o,f=T-c,z=n*f-a*w,_=a*b-r*f,L=r*w-n*b,R=m*z+g*_+d*L;if(R>-1e-7&&R<1e-7)return!1;let C=1/R,$=e-l,B=t-o,y=i-c,P=C*($*z+B*_+y*L);if(P<-u||P>1+u)return!1;let V=B*d-y*g,j=y*m-$*d,v=$*g-B*m,O=C*(r*V+n*j+a*v);if(O<-u||P+O>1+u)return!1;let s=C*(b*V+w*j+f*v);if(s>1e-4&&s<F.distance){F.distance=s,F.point=[e+r*s,t+n*s,i+a*s];let M=g*f-d*w,h=d*b-m*f,A=m*w-g*b,q=Math.hypot(M,h,A)||1;return F.normal=[M/q,h/q,A/q],!0}return!1}function tt(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let p=0;p<i;p++)r.push(ye());if(i===0)return r;let n=new Set;for(let p of e.nodes)if(Array.isArray(p.children))for(let x of p.children)n.add(x);let a=new Set,l=128,o=(p,x,E=0)=>{if(E>l||p<0||p>=i||a.has(p))return;a.add(p);let I=e.nodes[p];if(!I)return;let T=ye();if(t&&t[p])T.set(t[p]);else if(I.matrix&&I.matrix.length===16)T.set(I.matrix);else{let u=I.translation||[0,0,0],m=I.rotation||[0,0,0,1],g=I.scale||[1,1,1];Je(T,m,u,g)}let F=r[p];if(x?xe(F,x,T):F.set(T),Array.isArray(I.children))for(let u of I.children)typeof u=="number"&&o(u,F,E+1)},c=[],S=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(S&&Array.isArray(S.nodes))c.push(...S.nodes);else for(let p=0;p<i;p++)n.has(p)||c.push(p);for(let p of c)o(p,null);for(let p=0;p<i;p++)!n.has(p)&&!c.includes(p)&&o(p,null);return r}var Be="__THREE_LIVE_REGISTRY__";function Ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Be]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Be,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Be]=t}}return e[Be]}var pe=Ae().plugins;function Tt(e){let t=Ae().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function St(){return Ae().plugins}function Rt(e,t,i){let r=[],n=new Map,a=[],l=[],o=[],c=new Map,S=d=>{let b=n.get(d);return b===void 0&&(b=r.length,r.push({op:d}),n.set(d,b)),b},p=d=>{let b=c.get(d);return b===void 0&&(b=o.length,o.push({id:d}),c.set(d,b)),b},x=(d,b={})=>a.push({declaration:S(d),...b})-1,E=(d,b,w)=>l.push({id:d,type:b,value:w})-1,I=d=>({node:d,socket:"value"}),T=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(T&&typeof T=="object"){let d=Array.isArray(T.graphs)?T.graphs[T.graph??0]:T;if(d&&Array.isArray(d.nodes)){let b=Array.isArray(d.declarations)?d.declarations:[];for(let w of b)w?.op&&S(w.op);Array.isArray(d.variables)&&l.push(...d.variables);for(let w of d.events||[])w?.id&&p(w.id);for(let w of d.nodes){if(!w||typeof w!="object")continue;let f=w.op||(typeof w.declaration=="number"?b[w.declaration]?.op:"");a.push(f?{...w,declaration:S(f)}:{...w})}}}let F=(d,b,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,b)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,b)}/${w}`:w==="visible"?`/nodes/${d}/extensions/KHR_node_visibility/visible`:`/nodes/${d}/${w}`,u=new Map;e.forEach((d,b)=>{typeof d?.name=="string"&&!u.has(d.name)&&u.set(d.name,b)});let m=(d,b)=>typeof d.target=="string"&&u.has(d.target)?u.get(d.target):typeof d.targetNode=="number"?d.targetNode:b,g=d=>{let b=e[d];return(typeof b?.mesh=="number"?t[b.mesh]?.primitives?.[0]?.material:0)??0};for(let d=0;d<e.length;d++){let b=e[d],w=b?.extras?.interactivity;if(!w||typeof w!="object")continue;let f=(typeof b.mesh=="number"?t[b.mesh]?.primitives?.[0]?.material:0)??0,z=L=>{let R=Array.isArray(L)?L:[L],C=[];for(let B=0;B<R.length;B++){let y=R[B];if(!y||typeof y!="object")continue;let P=y.action||"interpolate",V=typeof y.duration=="number"?y.duration:.35;if(P==="toggleTransform"){let j=y.property==="rotation"||y.property==="scale"?y.property:"translation",v=j==="rotation"?b.rotation||[0,0,0,1]:j==="scale"?b.scale||[1,1,1]:b.translation||[0,0,0],O=`/nodes/${d}/${j}`,s=E(`__toggle_${d}_${B}`,"bool",!1),M=x("variable/get",{configuration:{variable:s}}),h=x("math/not",{values:{a:I(M)}}),A=x("variable/set",{configuration:{variable:s},values:{value:I(h)}}),q=x("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(y.to)?y.to:v},duration:{value:V}}}),N=x("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(y.from)?y.from:v},duration:{value:V}}});a[A].flows={out:{node:x("flow/branch",{values:{condition:I(M)},flows:{true:{node:q},false:{node:N}}})}},C.push(A)}else if(P==="interpolate"){let j=y.to??y.value;if(j===void 0)continue;let v={value:{value:j},duration:{value:V}};y.from!==void 0&&(v.from={value:y.from}),C.push(x("pointer/interpolate",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:F(m(y,d),g(m(y,d)),y.property)},values:v}))}else if(P==="setProperty"){if(y.value===void 0)continue;C.push(x("pointer/set",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:F(m(y,d),g(m(y,d)),y.property)},values:{value:{value:y.value}}}))}else if(P==="toggleVisibility"){let j=m(y,d),v=E(`__vis_${j}_${B}`,"bool",!0),O=x("variable/get",{configuration:{variable:v}}),s=x("math/not",{values:{a:I(O)}}),M=x("variable/set",{configuration:{variable:v},values:{value:I(s)}});a[M].flows={out:{node:x("pointer/set",{configuration:{pointer:`/nodes/${j}/extensions/KHR_node_visibility/visible`},values:{value:I(O)}})}},C.push(M)}else if(P==="cycleMaterialColor"&&Array.isArray(y.colors)&&y.colors.length>0){let j=typeof y.duration=="number"?y.duration:.25,v=`/materials/${Math.max(0,f)}/pbrMetallicRoughness/baseColorFactor`,O=E(`__color_idx_${d}_${B}`,"int",0),s=x("variable/get",{configuration:{variable:O}}),M=x("math/add",{values:{a:I(s),b:{value:1}}}),h=x("math/rem",{values:{a:I(M),b:{value:y.colors.length}}}),A=x("variable/set",{configuration:{variable:O},values:{value:I(h)}}),q={};for(let N=0;N<y.colors.length;N++){let X=y.colors[N],K=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];q[String(N)]={node:j>0?x("pointer/interpolate",{configuration:{pointer:v},values:{value:{value:K},duration:{value:j}}}):x("pointer/set",{configuration:{pointer:v},values:{value:{value:K}}})}}a[A].flows={out:{node:x("flow/switch",{values:{selection:I(s)},flows:q})}},C.push(A)}else if(P==="playAnimation")C.push(x("animation/start",{configuration:{animation:y.animation??y.clip??0}}));else if(P==="stopAnimation")C.push(x("animation/stop"));else if(P==="sendEvent"){let j={};for(let[v,O]of Object.entries(y.values||{}))j[v]={value:O};C.push(x("event/send",{configuration:{event:p(String(y.event??y.id??"custom"))},values:j}))}}if(!C.length)return null;if(C.length===1)return C[0];let $={};return C.forEach((B,y)=>{$[String(y)]={node:B}}),x("flow/sequence",{flows:$})},_=(L,R,C)=>{let $=z(R);$!==null&&x(L,{...C?{configuration:C}:{},flows:{out:{node:$}}})};if(w.onSelect&&_("pointer/onSelect",w.onSelect,{nodeIndex:d}),w.onHoverIn&&_("pointer/onHoverIn",w.onHoverIn,{nodeIndex:d}),w.onHoverOut&&_("pointer/onHoverOut",w.onHoverOut,{nodeIndex:d}),w.onStart&&_("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[L,R]of Object.entries(w.onReceive))_("event/receive",R,{event:p(L)})}return a.length?{graphs:[{declarations:r,nodes:a,variables:l,events:o}],graph:0}:null}var Zt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function nt(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,o=Zt[l];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let c=o*r,S=n.byteStride&&n.byteStride>0?n.byteStride:c,p=(n.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(p)||p<0||S<c||p+(a-1)*S+c>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(l===5126&&S===c&&p%4===0)return new Float32Array(t,p,a*r);let x=new DataView(t),E=i.normalized===!0,I=new Float32Array(a*r);for(let T=0;T<a;T++){let F=p+T*S;for(let u=0;u<r;u++){let m=F+u*o,g;switch(l){case 5126:g=x.getFloat32(m,!0);break;case 5120:g=x.getInt8(m),E&&(g=Math.max(g/127,-1));break;case 5121:g=x.getUint8(m),E&&(g/=255);break;case 5122:g=x.getInt16(m,!0),E&&(g=Math.max(g/32767,-1));break;case 5123:g=x.getUint16(m,!0),E&&(g/=65535);break;default:g=x.getUint32(m,!0),E&&(g/=4294967295)}I[T*r+u]=g}}return I}function Lt(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,o=Math.cos(l),c=Math.sin(l),S=(Number.isFinite(n)?n:1)*o,p=(Number.isFinite(n)?n:1)*c,x=-(Number.isFinite(a)?a:1)*c,E=(Number.isFinite(a)?a:1)*o;for(let I=0;I+1<e.length;I+=2){let T=e[I],F=e[I+1];e[I]=S*T+p*F+i,e[I+1]=x*T+E*F+r}}function Ce(e,t,i,r=!0){let n=[],a=null;try{for(let[l,o]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,o),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)}}var Et=["neutral","reinhard","none","aces","agx"];function ot(e){let t=String(e??"").trim().toLowerCase();return Et.includes(t)?t:"neutral"}function Qt(e){return Et.indexOf(ot(e))}function Jt(e){return new TextDecoder().decode(e)}var Dt=Ae().decoders;function en(e,t){Dt.set(e.toLowerCase(),t)}function $e(e){return Dt.get(e.toLowerCase())}function Ct(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 E=i.getUint8(0);throw E===123||E===32||E===10||E===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,o=null,c=null;for(;l+8<=a&&l+8<=t.byteLength;){let E=i.getUint32(l,!0),I=i.getUint32(l+4,!0),T=l+8;if(T+E>t.byteLength)throw new Error(`Truncated GLB chunk: required ${T+E} bytes, buffer has ${t.byteLength}`);if(I===1313821514){let F=new Uint8Array(t,T,E),u=Jt(F);o=JSON.parse(u,(m,g)=>m==="__proto__"||m==="constructor"||m==="prototype"?void 0:g)}else I===5130562&&(c=t.slice(T,T+E));l=T+E}if(!o)throw new Error("Missing JSON chunk in GLB");let S=o.extensionsRequired||[];for(let[E,I]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(S.includes(E)&&!$e(I))throw new Error(`Model requires ${E}. Register a decoder via ThreeLiveElement.registerDecoder('${I}', decoder).`);let p=c||new ArrayBuffer(0),x={gltf:o,bin:p,animations:[],animationsParsed:!1};for(let E of pe)E.onParseGLB?.(x);return x}function ut(e,t=tt(e)){let i=e?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],n=new Set,a=(l,o,c,S)=>{let p=l.type,x=p==="directional"||p==="point"||p==="spot"?p:"ambient",E=o?o[8]:-.5,I=o?o[9]:-1,T=o?o[10]:-.8,F=Math.hypot(E,I,T)||1,u=l.extras?.shadow??c,m=l.name||S,g={type:x,color:l.color||[1,1,1],intensity:l.intensity??1};m&&(g.name=m),o&&(g.position=[o[12],o[13],o[14]]),x==="directional"&&o?g.direction=[E/F,I/F,T/F]:(x==="spot"&&(g.direction=o?[-E/F,-I/F,-T/F]:[0,-1,0],g.innerConeAngle=l.spot?.innerConeAngle??0,g.outerConeAngle=l.spot?.outerConeAngle??Math.PI/4),g.range=l.range),u&&(g.shadow=u),r.push(g)};return(e.nodes||[]).forEach((l,o)=>{let c=l?.extensions?.KHR_lights_punctual?.light;typeof c=="number"&&i[c]&&(n.add(c),a(i[c],t[o],l.extras?.shadow,l.name))}),i.forEach((l,o)=>{n.has(o)||a(l)}),r}function tn(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(tn(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return Ct(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var st=`#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
|
+
}`,nn=`#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,24 +204,24 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
204
|
float outAlpha=base.a;
|
|
240
205
|
/*XRD_O*/
|
|
241
206
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
207
|
+
}`,rn=`#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);}`,on=`#version 300 es
|
|
246
211
|
precision highp float;
|
|
247
212
|
uniform vec4 uColorId;
|
|
248
213
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function je(e,t,i){let r={};for(let a of i)r[a]=e.getUniformLocation(t,a);return r}var ft=["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 xt(){let e=be().xrDepthShader;return{fs:zt.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...ft,...e.uniformNames]:ft}}function jt(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 ze(e,t,i,r,a,s,c,l){if(r===void 0||!t.accessors?.[r])return null;let g=He(t,i,t.accessors[r],s);if(!g)return null;l&&(g=g.slice(),ht(g,l));let d=e.createBuffer();return c.push(d),e.bindBuffer(34962,d),e.bufferData(34962,g,35044),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,s,5126,!1,0,0),g}function We(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function vt(e,t,i){let r=xt(),a=yt,s=r.fs,c=!1;for(let g of ce)if(g.onResolveShader){let d=g.onResolveShader(t,i,a,s);d&&(a=d.vs,s=d.fs,c=!0)}let l=c?Pe(e,a,s):null;return{program:l,uniforms:l?je(e,l,r.uniforms):null}}function qt(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,c=new Float32Array(a*20);for(let g=0;g<a;g++)c.set(r.subarray(g*16,g*16+16),g*20),c[g*20+16]=s?s[g*3]:1,c[g*20+17]=s?s[g*3+1]:1,c[g*20+18]=s?s[g*3+2]:1,c[g*20+19]=1;let l=e.createBuffer();i.push(l),e.bindBuffer(34962,l),e.bufferData(34962,c,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 Kt(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 An=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Mt=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ce(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function At(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,a=e?.extensions?.KHR_materials_clearcoat,s=c=>c!==void 0&&t[c.index]?t[c.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 Tt(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 c of s.primitives){if(c.vao&&e.deleteVertexArray(c.vao),c.buffers)for(let g of c.buffers)e.deleteBuffer(g);a(c.texture),a(c.metallicRoughnessTexture),a(c.normalTexture),a(c.occlusionTexture);let l=new Set;c.customProgram&&l.add(c.customProgram);for(let g of c.programCache?.values()??[])g.program&&l.add(g.program);for(let g of l)e.deleteProgram(g)}if(i)for(let s of i)a(s)}function dt(e,t,i=Mt,r){let a={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Yt(e,t,i,r,a)}catch(s){let c=a.mesh&&!a.meshes.includes(a.mesh)?[...a.meshes,a.mesh]:a.meshes;Tt(e,c,a.gpuTextures),a.vao&&e.deleteVertexArray(a.vao);for(let l of a.buffers)e.deleteBuffer(l);throw s}}function Yt(e,t,i,r,a){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=t,c=we("meshopt");c?.decodeBufferViews&&c.decodeBufferViews(s,t);let l=t.bin,g=[];a.meshes=g;let d=[],v=s.extensions?.KHR_materials_variants;v&&Array.isArray(v.variants)&&v.variants.forEach((S,o)=>{d.push(typeof S?.name=="string"&&S.name?S.name:`Variant_${o}`)});let M=ut(s),I=[];if(Array.isArray(s.nodes))for(let S=0;S<s.nodes.length;S++){let o=s.nodes[S];o.mesh!==void 0&&s.meshes&&s.meshes[o.mesh]&&I.push({node:o,nodeIdx:S,meshIdx:o.mesh})}let D=I.length>0?I:(s.meshes||[]).map((S,o)=>({node:S,nodeIdx:-1,meshIdx:o})),u=[],x=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(x)for(let S of x)u.push({...S,type:S.type||S.light_type||"point",innerConeAngle:S.innerConeAngle??S.inner_cone_angle,outerConeAngle:S.outerConeAngle??S.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let S=s.extensions.KHR_lights_punctual.lights;for(let o of S){let V=o.type==="directional"?"directional":o.type==="point"?"point":o.type==="spot"?"spot":"ambient";u.push({type:V,color:o.color||[1,1,1],intensity:o.intensity!==void 0?o.intensity:1})}}if(u.length===0&&(u.push({type:"ambient",color:[1,1,1],intensity:.35}),u.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),D.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${D.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 S=0;S<s.textures.length;S++){let o=s.textures[S],V=s.images[o.source];if(V){let K=e.createTexture();e.bindTexture(3553,K),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=b=>{e.bindTexture(3553,K),e.texImage2D(3553,0,6408,6408,5121,b),e.generateMipmap(3553),r?.()};if(V.bufferView!==void 0){let b=s.bufferViews[V.bufferView],n=b.byteOffset||0,p=new Blob([l.slice(n,n+b.byteLength)],{type:V.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(p).then(f).catch(()=>{})}else if(V.uri){let b=jt(V.uri);if(b){let n=new Image;n.crossOrigin="anonymous",n.referrerPolicy="no-referrer",n.onload=()=>f(n),n.src=b}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",V.uri)}C.push(K)}else C.push(null)}}let R=[1/0,1/0,1/0],T=[-1/0,-1/0,-1/0],m=0,h=0;for(let S=0;S<D.length;S++){let o=D[S],V=s.meshes[o.meshIdx],K=o.nodeIdx>=0?M[o.nodeIdx]:le(),f=new Float32Array(9);ve(f,K);let b={name:o.node.name||V.name||`Mesh_${o.meshIdx}`,nodeIndex:o.nodeIdx,transform:K,normalMatrix:f,primitives:[],extras:o.node.extras||V.extras,...o.node?.visible===!1||o.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};a.mesh=b;let n=o.node?.extensions?.EXT_mesh_gpu_instancing;if(n&&n.attributes&&typeof n.attributes=="object"){let p=n.attributes,B=p.TRANSLATION!==void 0?s.accessors?.[p.TRANSLATION]:null,z=p.ROTATION!==void 0?s.accessors?.[p.ROTATION]:null,j=p.SCALE!==void 0?s.accessors?.[p.SCALE]:null,ee=p._COLOR_0!==void 0?s.accessors?.[p._COLOR_0]:null,L=Number(B?.count??z?.count??j?.count??0);if(!Number.isFinite(L)||L<0||L>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${L}`);if(L>0){let X=(A,E)=>{if(!A||A.bufferView===void 0||!s.bufferViews?.[A.bufferView])return null;let H=A.componentType??5126,W=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(H!==5120&&H!==5121&&H!==5122&&H!==5123&&H!==5126)return W(`componentType ${H}`);if(!(Number(A.count)>=L))return W(`count ${A.count} < ${L}`);let Z=null;try{Z=He(s,l,{...A,count:L},E)}catch{return W("out of bounds")}return!Z||!Z.every(Number.isFinite)?W("non-finite value"):Z},J=X(B,3),re=X(z,4),$=X(j,3),te=ee?.type==="VEC4"?4:3,O=X(ee,te),G=new Float32Array(L*16),q=le();for(let A=0;A<L;A++){let E=J?[J[A*3],J[A*3+1],J[A*3+2]]:[0,0,0],H=re?[re[A*4],re[A*4+1],re[A*4+2],re[A*4+3]]:[0,0,0,1],W=$?[$[A*3],$[A*3+1],$[A*3+2]]:[1,1,1];Ge(q,H,E,W),G.set(q,A*16)}if(b.instanceMatrices=G,O){let A=new Float32Array(L*3);for(let E=0;E<L;E++)A[E*3]=O[E*te],A[E*3+1]=O[E*te+1],A[E*3+2]=O[E*te+2];b.instanceColors=A}}}for(let p of V.primitives||[]){if(p.extensions?.KHR_draco_mesh_compression){let Z=we("draco");Z&&Z.decodePrimitive(s,p,l)}let B=[],z=e.createVertexArray();a.vao=z,a.buffers=B,e.bindVertexArray(z);let j=qt(e,b,B),ee=s.accessors[p.attributes.POSITION],L=Number(ee?.count??0);if(!Number.isFinite(L)||L<0||m+L>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(m+=L,ee?.min&&ee?.max){let Z=Q=>{for(let Y=0;Y<3;Y++){let ue=Q[12+Y],ie=Q[12+Y];for(let ae=0;ae<3;ae++){let ne=Q[ae*4+Y]*ee.min[ae],oe=Q[ae*4+Y]*ee.max[ae];ue+=ne<oe?ne:oe,ie+=ne>oe?ne:oe}ue<R[Y]&&(R[Y]=ue),ie>T[Y]&&(T[Y]=ie)}};if(b.instanceMatrices&&b.instanceMatrices.length>=16){let Q=b.instanceMatrices.length>>4,Y=le();for(let ue=0;ue<Q;ue++){let ie=b.instanceMatrices.subarray(ue*16,ue*16+16);fe(Y,K,ie),Z(Y)}}else Z(K)}let X=ze(e,s,l,p.attributes.POSITION,0,3,B);ze(e,s,l,p.attributes.NORMAL,1,3,B),ze(e,s,l,p.attributes.TEXCOORD_0,2,2,B,Kt(s,p));let J=0,re=5123,$=null;if(p.indices!==void 0){let Z=s.accessors[p.indices],Q=(s.bufferViews[Z.bufferView].byteOffset||0)+(Z.byteOffset||0);if(J=Number(Z.count??0),!Number.isFinite(J)||J<0||h+J>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);h+=J,re=Z.componentType===5125?5125:5123;let Y=e.createBuffer();B.push(Y),e.bindBuffer(34963,Y),Z.componentType===5125?$=new Uint32Array(l,Q,Z.count):Z.componentType===5121?$=Uint16Array.from(new Uint8Array(l,Q,Z.count)):$=Q%2===0?new Uint16Array(l,Q,Z.count):new Uint16Array(l.slice(Q,Q+Z.count*2)),e.bufferData(34963,$,35044)}else J=ee.count;let te={};for(let Z of ce)if(Z.onBuildPrimitiveVAO){let Q=Z.onBuildPrimitiveVAO(e,z,p,s,l);Q&&(te[Z.name]=Q)}e.bindVertexArray(null);let O=s.materials&&p.material!==void 0?s.materials[p.material]:null,{program:G,uniforms:q}=vt(e,p,O),A=At(O,C),E=!!(O?.extensions?.KHR_materials_transmission||te.materials?.isTransmissive),H=p.extensions?.KHR_materials_variants?.mappings,W=Array.isArray(H)?H.filter(Z=>Z&&typeof Z.material=="number"&&Array.isArray(Z.variants)).map(Z=>({material:Z.material|0,variants:Z.variants.map(Q=>Number(Q)|0)})):void 0;b.primitives.push({vao:z,instanced:j,indexCount:J,indexType:re,...A,positions:X,indices:$,buffers:B,materialIndex:p.material,defaultMaterialIndex:p.material,variantMappings:W,primitiveDef:p,programCache:new Map([[p.material??-1,{program:G,uniforms:q}]]),pluginData:te,customProgram:G,customUniforms:q,isTransmissive:E})}g.push(b)}isFinite(R[0])||(R=[-1,-1,-1]),isFinite(T[0])||(T=[1,1,1]);let w=[(R[0]+T[0])/2,(R[1]+T[1])/2,(R[2]+T[2])/2],y=T[0]-R[0],F=T[1]-R[1],U=T[2]-R[2],_=Math.max(Math.hypot(y,F,U)/2,.5),k=[R[0],R[1],R[2]],P=[T[0],T[1],T[2]],N=t.animations;if(!N){for(let S of ce)if(S.onParseGLB?.(t),t.animations){N=t.animations;break}}return N||(N=[]),{meshes:g,bounds:{center:w,radius:_,min:k,max:P},lights:u,animations:N,worldMatrices:M,gpuTextures:C,availableVariants:d}}function Re(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var Fe=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=le(),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=le(),this.viewMatrix=le(),this.activeViewMatrix=null,this.modelMatrix=le(),this.mvpMatrix=le(),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:le(),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 l=e.querySelector("canvas");l||(l=document.createElement("canvas"),l.style.width="100%",l.style.height="100%",l.style.display="block",l.style.touchAction="none",e.prepend(l)),r=l}this.canvas=r,this.opts=a||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=We(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=Xe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let c=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!c)throw new Error("WebGL2 not supported");this.gl=c,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){$t(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=xt();this.renderProg=Pe(e,yt,t.fs),this.pickProg=Pe(e,Wt,Xt),this.uRender=je(e,this.renderProg,t.uniforms),this.uPick=je(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ce)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:c,gpuTextures:l,availableVariants:g}=dt(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=c||[],this.gpuTextures=l||[],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 M of e.gltf.nodes)this.initialNodeTransforms.push({t:M.translation?[M.translation[0],M.translation[1],M.translation[2]]:[0,0,0],r:M.rotation?[M.rotation[0],M.rotation[1],M.rotation[2],M.rotation[3]]:[0,0,0,1],s:M.scale?[M.scale[0],M.scale[1],M.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let M of ce)M.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 d=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;d!==void 0&&(this.exposure=We(d));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(gt(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of ce)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Se(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Se(e),{meshes:r}=dt(this.gl,i,Mt,()=>this.render());if(t)for(let a of r)a.transform[12]+=t[0],a.transform[13]+=t[1],a.transform[14]+=t[2],ve(a.normalMatrix,a.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),ve(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],a=[],s=[],c=[],l=[],g=[];for(let d of this.lights){let v=d.color||[1,1,1],M=d.intensity!==void 0?d.intensity:1;if(d.type==="ambient")i=[v[0]*M,v[1]*M,v[2]*M];else if(d.type==="directional"&&r.length<6){let I=d.direction||[.5,1,.8];r.push(I[0],I[1],I[2]),a.push(v[0]*M,v[1]*M,v[2]*M)}else if((d.type==="point"||d.type==="spot")&&s.length<6){let I=d.position||[0,0,0];if(s.push(I[0],I[1],I[2]),c.push(v[0]*M,v[1]*M,v[2]*M),d.type==="spot"){let D=d.direction||[0,-1,0],u=Math.max(.01,Math.min(Math.PI/2,d.outerConeAngle??Math.PI/3)),x=Math.max(0,Math.min(u-1e-4,d.innerConeAngle??0));l.push(D[0],D[1],D[2]),g.push(Math.cos(x),Math.cos(u))}else l.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,c),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,l),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,g)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=We(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Xe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ce)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ce)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(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],c=a?a.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,l=a?a.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,g={baseColorFactor:s,metallicFactor:c,roughnessFactor:l,setBaseColorFactor:d=>{let v=[d[0],d[1],d[2],d[3]??1];g.baseColorFactor=v,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=v);for(let M of r)M.baseColor=v;this.render()},setMetallicFactor:d=>{g.metallicFactor=d,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=d);for(let v of r)v.metallic=d;this.render()},setRoughnessFactor:d=>{g.roughnessFactor=d,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=d);for(let v of r)v.roughness=d;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 c=s.defaultMaterialIndex;if(!t&&Array.isArray(s.variantMappings)){for(let g of s.variantMappings)if(Array.isArray(g.variants)&&g.variants.includes(i)){c=g.material;break}}let l=c!==void 0?r[c]:void 0;s.materialIndex=l?c:void 0,Object.assign(s,At(l,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,l??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=vt(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 ce)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=le();fe(i,this.projMatrix,this.viewMatrix);let[r,a,s]=e,c=t?t[0]:0,l=t?t[1]:0,g=t?t[2]:0,d=this.modelRootMatrix;d&&(r=d[0]*e[0]+d[4]*e[1]+d[8]*e[2]+d[12],a=d[1]*e[0]+d[5]*e[1]+d[9]*e[2]+d[13],s=d[2]*e[0]+d[6]*e[1]+d[10]*e[2]+d[14],t&&(c=d[0]*t[0]+d[4]*t[1]+d[8]*t[2],l=d[1]*t[0]+d[5]*t[1]+d[9]*t[2],g=d[2]*t[0]+d[6]*t[1]+d[10]*t[2]));let v=i[0]*r+i[4]*a+i[8]*s+i[12],M=i[1]*r+i[5]*a+i[9]*s+i[13],I=i[2]*r+i[6]*a+i[10]*s+i[14],D=i[3]*r+i[7]*a+i[11]*s+i[15];if(D<=1e-4)return{x:0,y:0,z:1,visible:!1};let u=v/D,x=M/D,C=I/D,R=this.canvas.getBoundingClientRect(),T=R.width||this.canvas.clientWidth||this.canvas.width||300,m=R.height||this.canvas.clientHeight||this.canvas.height||150,h=(u*.5+.5)*T,w=(-x*.5+.5)*m,y=u>=-1.1&&u<=1.1&&x>=-1.1&&x<=1.1&&C>=-1&&C<=1;if(y&&t){let[F,U,_]=Re(this),k=[r-F,a-U,s-_];c*k[0]+l*k[1]+g*k[2]>.05&&(y=!1)}return{x:h,y:w,z:C,visible:y}}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 c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],g=this.customTarget?[...this.customTarget]:[...this.bounds.center],d=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;g[0]+=(-a*c[0]+s*l[0])*d,g[1]+=(-a*c[1]+s*l[1])*d,g[2]+=(-a*c[2]+s*l[2])*d,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,c=r.width>0?Math.floor((e-r.left)*(a/r.width)):Math.floor(e),l=r.height>0?Math.floor((t-r.top)*(s/r.height)):Math.floor(t);return this.performMeshPick(c,l,!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 c=le();fe(c,this.projMatrix,this.viewMatrix);let l=[],g=Math.max(0,Math.min(a-1,e)),d=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 w=0;w<this.meshes.length;w++){let y=this.meshes[w];if(y.visible===!1||y.isPluginMesh)continue;let F=w+1,U=(F&255)/255,_=(F>>8&255)/255,k=(F>>16&255)/255;r.uniform4f(this.uPick.uColorId,U,_,k,1),fe(this.modelMatrix,this.modelRootMatrix,y.transform);let P=y.instanceMatrices;if(P&&P.length>=16){let N=P.length>>4,S=le();for(let o of y.primitives){r.bindVertexArray(o.vao);for(let V=0;V<N;V++)fe(S,this.modelMatrix,P.subarray(V*16,V*16+16)),fe(this.mvpMatrix,c,S),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ce(r,o)}}else{fe(this.mvpMatrix,c,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let N of y.primitives)r.bindVertexArray(N.vao),Ce(r,N)}}let m=new Uint8Array(4);r.readPixels(g,d,1,1,6408,5121,m),r.bindFramebuffer(36160,null);let h=m[0]+(m[1]<<8)+(m[2]<<16);h>0&&h<=this.meshes.length&&(l=[this.meshes[h-1]])}l.length===0&&(l=this.meshes.filter(m=>m.visible!==!1));let v=null,M=1/0,I=[0,0,0],D=[0,1,0],[u,x,C]=Re(this),R=le();for(let m of l){fe(R,this.modelRootMatrix,m.transform);let h=m.instanceMatrices,w=h&&h.length>=16?h.length>>4:1;for(let y=0;y<w;y++){h&&h.length>=16?fe(this.modelMatrix,R,h.subarray(y*16,y*16+16)):this.modelMatrix.set(R),fe(this.mvpMatrix,c,this.modelMatrix);let F=le();if(!ot(F,this.mvpMatrix))continue;let U=(g+.5)/a*2-1,_=(d+.5)/s*2-1,k=[0,0,0],P=[0,0,0];$e(k,U,_,-1,F),$e(P,U,_,1,F);let N=P[0]-k[0],S=P[1]-k[1],o=P[2]-k[2],V=Math.hypot(N,S,o)||1,K=N/V,f=S/V,b=o/V,n={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((p=>{for(let B of m.primitives){if(!B.positions)continue;let z=B.positions,j=B.indices,ee=Math.floor(j?j.length/3:z.length/9);for(let L=0;L<ee;L++){let X=j?j[L*3]:L*3,J=j?j[L*3+1]:L*3+1,re=j?j[L*3+2]:L*3+2;at(k[0],k[1],k[2],K,f,b,z[X*3],z[X*3+1],z[X*3+2],z[J*3],z[J*3+1],z[J*3+2],z[re*3],z[re*3+1],z[re*3+2],n,p)}}})(1e-4),isFinite(n.distance)){let p=n.point[0],B=n.point[1],z=n.point[2],j=this.modelMatrix,ee=j[0]*p+j[4]*B+j[8]*z+j[12],L=j[1]*p+j[5]*B+j[9]*z+j[13],X=j[2]*p+j[6]*B+j[10]*z+j[14],J=ee-u,re=L-x,$=X-C,te=Math.hypot(J,re,$);if(te<M){ve(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,G=n.normal[0],q=n.normal[1],A=n.normal[2],E=O[0]*G+O[3]*q+O[6]*A,H=O[1]*G+O[4]*q+O[7]*A,W=O[2]*G+O[5]*q+O[8]*A,Z=Math.hypot(E,H,W)||1;E/=Z,H/=Z,W/=Z,E*J+H*re+W*$>0&&(E=-E,H=-H,W=-W),v=m,M=Math.round(te*1e3)/1e3,I=[Math.round(ee*1e3)/1e3,Math.round(L*1e3)/1e3,Math.round(X*1e3)/1e3],D=[Math.round(E*1e3)/1e3,Math.round(H*1e3)/1e3,Math.round(W*1e3)/1e3]}}}}if(!v)return null;let T={meshIndex:this.meshes.indexOf(v),meshName:v.name,nodeIndex:v.nodeIndex,distance:M,hitPoint:I,normal:D,screenX:e,screenY:t};if(i){for(let m of ce)m.onMeshSelect?.(this,T);this.opts.onMeshClick&&this.opts.onMeshClick(T),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:T}))}return T}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,c=(a+.5)/s*2-1;return Math.floor((c*.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;Le(this.viewMatrix,Re(this),i,[0,1,0]),fe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ve(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of ce)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 ce)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 ce)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 ce)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 c=e?.transform?.inverse?.matrix||this.viewMatrix,l=e?.projectionMatrix||this.projMatrix,g=e?.transform?.position,d=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:c,projMatrix:l,eyePos:d,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 T=Math.max(2,this.canvas.width||2),m=Math.max(1,this.canvas.height||1),h=Math.max(1,Math.floor(T*.5)),w=Math.max(1,T-h),y=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),F=this.customTarget||this.bounds.center,[U,_,k]=Re(this),P=Math.cos(this.currTheta),N=-Math.sin(this.currTheta),S=.032,o=le(),V=le(),K=[U-P*S,_,k-N*S],f=[F[0]-P*S*.25,F[1],F[2]-N*S*.25];Ee(o,this.fov,h/m,.1,y),Le(V,K,f,[0,1,0]);let b=le(),n=le(),p=[U+P*S,_,k+N*S],B=[F[0]+P*S*.25,F[1],F[2]+N*S*.25];Ee(b,this.fov,w/m,.1,y),Le(n,p,B,[0,1,0]),this.render({viewMatrix:V,projMatrix:o,eyePos:K,viewport:[0,0,h,m],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:n,projMatrix:b,eyePos:p,viewport:[h,0,w,m],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,T,m);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 c=le(),l=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=l,fe(c,e?.projMatrix??this.projMatrix,l);let g=be().xrDepthShader,d=Vt(this.toneMapping),[v,M,I]=e?e.eyePos:Re(this);for(let T of ce)T.onBeforeDrawScene?.(this,t,c,[v,M,I],d);let D=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&D===0)return;let u=e?.eye||"none",x=!1,C=D>0?[...this.backdropMeshes,...this.meshes]:this.meshes,R=T=>{for(let m=0;m<C.length;m++){let h=C[m];if(h.visible===!1)continue;let w=this.selectedMeshName!==""&&h.name===this.selectedMeshName;m<D||h.worldSpace===!0||h.name==="__xr_reticle__"?this.modelMatrix.set(h.transform):fe(this.modelMatrix,this.modelRootMatrix,h.transform),fe(this.mvpMatrix,c,this.modelMatrix),ve(h.normalMatrix,this.modelMatrix);let y=h.extras?.xr?.stereo||h.userData?.xr?.stereo,F=0,U=0,_=1,k=1;y==="sbs"?(_=.5,F=u==="right"?.5:0):y==="ou"&&(k=.5,U=u==="right"?.5:0);for(let P of h.primitives){let N=!!P.isTransmissive;if(!T&&N){x=!0;continue}if(T&&!N)continue;let S=P.customProgram||this.renderProg,o=P.customUniforms||this.uRender;t.useProgram(S),t.vertexAttrib3f(3,0,0,0),o.uInstanced&&t.uniform1i(o.uInstanced,0),t.uniform1i(o.uToneMapping,d),t.uniform1f(o.uEnvIntensity,this.envIntensity),o.uExposure&&t.uniform1f(o.uExposure,this.exposure),t.uniform3f(o.uCameraPos,v,M,I),t.uniform1f(o.uEmissive,w?1:0),t.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(o.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(o.uNormalMatrix,!1,h.normalMatrix),o.uUvTransform&&t.uniform4f(o.uUvTransform,F,U,_,k),o.uViewportSize&&t.uniform2f(o.uViewportSize,Math.max(1,a),Math.max(1,s)),g?.bind(t,o,this.xrDepthState,l,[i,r,Math.max(1,a),Math.max(1,s)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(o.uEnvironmentMap,4),t.uniform1i(o.uHasEnvironmentMap,1)):t.uniform1i(o.uHasEnvironmentMap,0),this.bindLights(o),o.uSectionEnabled&&t.uniform1i(o.uSectionEnabled,0);for(let K of ce)K.onBeforeDrawPrimitive?.(t,S,P,h,this.worldMatrices||[],this.gltf);t.uniform4fv(o.uBaseColor,P.baseColor),t.uniform1f(o.uMetallic,P.metallic),t.uniform1f(o.uRoughness,P.roughness),o.uClearcoat&&t.uniform2f(o.uClearcoat,P.clearcoat??0,P.clearcoatRoughness??.04),P.texture?(t.activeTexture(33984),t.bindTexture(3553,P.texture),t.uniform1i(o.uBaseColorTexture,0),t.uniform1i(o.uHasTexture,1)):t.uniform1i(o.uHasTexture,0),P.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,P.metallicRoughnessTexture),t.uniform1i(o.uMetallicRoughnessTexture,1),t.uniform1i(o.uHasMetallicRoughnessTexture,1)):t.uniform1i(o.uHasMetallicRoughnessTexture,0),P.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,P.normalTexture),t.uniform1i(o.uNormalTexture,2),t.uniform1i(o.uHasNormalTexture,1),t.uniform1f(o.uNormalScale,P.normalScale)):t.uniform1i(o.uHasNormalTexture,0),P.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,P.occlusionTexture),t.uniform1i(o.uOcclusionTexture,3),t.uniform1i(o.uHasOcclusionTexture,1),t.uniform1f(o.uOcclusionStrength,P.occlusionStrength)):t.uniform1i(o.uHasOcclusionTexture,0),t.bindVertexArray(P.vao);let V=h.instanceMatrices;if(P.instanceCount!==void 0)t.drawElementsInstanced(4,P.indexCount,P.indexType,0,P.instanceCount);else if(V&&V.length>=16&&P.instanced&&o.uInstanced&&o.uViewProj){let K=V.length>>4;t.uniform1i(o.uInstanced,1),t.uniformMatrix4fv(o.uViewProj,!1,c),P.indices?t.drawElementsInstanced(4,P.indexCount,P.indexType,0,K):t.drawArraysInstanced(4,0,P.indexCount,K),t.uniform1i(o.uInstanced,0)}else if(V&&V.length>=16){let K=V.length>>4,f=h.instanceColors,b=le(),n=new Float32Array(9),p=[P.baseColor[0],P.baseColor[1],P.baseColor[2],P.baseColor[3]];for(let B=0;B<K;B++)fe(b,this.modelMatrix,V.subarray(B*16,B*16+16)),fe(this.mvpMatrix,c,b),ve(n,b),t.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(o.uModel,!1,b),t.uniformMatrix3fv(o.uNormalMatrix,!1,n),f&&(p[0]=P.baseColor[0]*f[B*3],p[1]=P.baseColor[1]*f[B*3+1],p[2]=P.baseColor[2]*f[B*3+2],p[3]=P.baseColor[3],t.uniform4fv(o.uBaseColor,p)),Ce(t,P)}else Ce(t,P)}}};if(R(!1),x){for(let T of ce)T.onBeforeTransmissivePass?.(t,this);R(!0)}for(let T of ce)T.onAfterRender?.(t,this,c,e?.eye??"none",[i,r,a,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){Tt(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 ce)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Fe.registerPlugin=ct,Fe.getRegisteredPlugins=lt;function Zt(e){return e+3&-4}var se=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function Rt(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function St(e,t=0){let[i,r,a,,s,c,l,,g,d,v,,M,I,D]=Array.from({length:15},(n,p)=>se(e[t+p],p%5===0?1:0)),u=Math.hypot(i,r,a),x=Math.hypot(s,c,l),C=Math.hypot(g,d,v);i*(c*v-d*l)-s*(r*v-d*a)+g*(r*l-c*a)<0&&(u=-u);let R=Math.abs(u)>1e-8?1/u:0,T=Math.abs(x)>1e-8?1/x:0,m=Math.abs(C)>1e-8?1/C:0,h=i*R,w=r*R,y=a*R,F=s*T,U=c*T,_=l*T,k=g*m,P=d*m,N=v*m,S=h+U+N,o=0,V=0,K=0,f=1;if(S>0){let n=.5/Math.sqrt(S+1);f=.25/n,o=(_-P)*n,V=(k-y)*n,K=(w-F)*n}else if(h>U&&h>N){let n=2*Math.sqrt(Math.max(0,1+h-U-N));n>1e-8&&(f=(_-P)/n,o=.25*n,V=(F+w)/n,K=(k+y)/n)}else if(U>N){let n=2*Math.sqrt(Math.max(0,1+U-h-N));n>1e-8&&(f=(k-y)/n,o=(F+w)/n,V=.25*n,K=(_+P)/n)}else{let n=2*Math.sqrt(Math.max(0,1+N-h-U));n>1e-8&&(f=(w-F)/n,o=(k+y)/n,V=(_+P)/n,K=.25*n)}let b=Math.hypot(o,V,K,f);return b>1e-8&&Number.isFinite(b)?(o/=b,V/=b,K/=b,f/=b):(o=0,V=0,K=0,f=1),{t:[M,I,D],r:[o,V,K,f],s:[u,x,C]}}function Qt(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Me=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function Et(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,a=typeof i.preset=="string"?i.preset:void 0;return!r&&!a?null:{ae:i,src:r,preset:a,volume:Me(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Jt(e,t){e.updateMatrixWorld(!0);let i=[],r=0,a=[],s=[],c=[],l=[],g=new Set,d=[],v=[],M=new Map,I=[],D=[],u=[],x=new Map,C=[],R=[];function T(f){let b=M.get(f);if(b!==void 0)return b;b=v.length,M.set(f,b);let n=f,p=n.color?.r??1,B=n.color?.g??1,z=n.color?.b??1,j=n.opacity??1,ee={baseColorFactor:[p,B,z,j],metallicFactor:n.metalness??0,roughnessFactor:n.roughness??.5},L={},X=E=>{if(!E)return;let H=(typeof E=="string"?E:typeof E.source=="string"?E.source:typeof E.image=="string"?E.image:"").trim();if(!H||/[\x00-\x1f\x7f\\]|\.\./.test(H)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(H)||!H.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(H)))return;let W=x.get(H);if(W===void 0){let Z=I.length;I.push({uri:H}),D.length===0&&D.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),W=u.length,u.push({sampler:0,source:Z}),x.set(H,W)}return{index:W}},J=X(n.map);J&&(ee.baseColorTexture=J);let re=X(n.roughnessMap||n.metalnessMap);re&&(ee.metallicRoughnessTexture=re);let $=n.map?.avgColor;Array.isArray($)&&$.length>=3&&(L.avgColor=[$[0],$[1],$[2]]);let te=X(n.normalMap),O=X(n.emissiveMap),G=X(n.aoMap),q={name:n.name||"",pbrMetallicRoughness:ee,doubleSided:n.side===2||!!n.doubleSided,...te?{normalTexture:te}:{},...O?{emissiveTexture:O}:{},...G?{occlusionTexture:G}:{},...Object.keys(L).length>0?{extras:L}:{}};if(n.emissive&&(n.emissive.r>0||n.emissive.g>0||n.emissive.b>0)){let E=n.emissiveIntensity??1;q.emissiveFactor=[n.emissive.r*E,n.emissive.g*E,n.emissive.b*E]}let A={};return n.clearcoat&&n.clearcoat>0&&(A.KHR_materials_clearcoat={clearcoatFactor:n.clearcoat,clearcoatRoughnessFactor:n.clearcoatRoughness||0}),n.sheen&&n.sheen>0&&(A.KHR_materials_sheen={sheenColorFactor:n.sheenColor?[n.sheenColor.r,n.sheenColor.g,n.sheenColor.b]:[1,1,1],sheenRoughnessFactor:n.sheenRoughness||0}),n.transmission&&n.transmission>0&&(A.KHR_materials_transmission={transmissionFactor:n.transmission}),n.thickness&&n.thickness>0&&(A.KHR_materials_volume={thicknessFactor:n.thickness,attenuationDistance:n.attenuationDistance??1/0,attenuationColor:n.attenuationColor?[n.attenuationColor.r,n.attenuationColor.g,n.attenuationColor.b]:[1,1,1]}),n.ior!==void 0&&n.ior!==1.5&&(A.KHR_materials_ior={ior:n.ior}),n.dispersion&&n.dispersion>0&&(A.KHR_materials_dispersion={dispersion:n.dispersion}),n.iridescence&&n.iridescence>0&&(A.KHR_materials_iridescence={iridescenceFactor:n.iridescence,iridescenceIor:n.iridescenceIOR??1.3}),Object.keys(A).length>0&&(q.extensions=A),v.push(q),b}function m(f,b){let n=new Uint8Array(f.buffer,f.byteOffset,f.byteLength),p=Zt(n.byteLength),B=new Uint8Array(p);B.set(n),i.push(B);let z=a.length;return a.push({buffer:0,byteOffset:r,byteLength:n.byteLength,target:b}),r+=p,z}function h(f,b,n,p,B,z,j){let ee=m(f,n),L=s.length,X={bufferView:ee,byteOffset:0,componentType:p,count:B,type:b};return z&&(X.min=z),j&&(X.max=j),s.push(X),L}e.traverse(f=>{if(f.isLight||f.color&&f.intensity!==void 0){let b=f.matrixWorld?.elements,n=se(b?b[12]:f.position?.x,0),p=se(b?b[13]:f.position?.y,0),B=se(b?b[14]:f.position?.z,0),z=f.target,j=z?.parent?z?.matrixWorld?.elements:void 0,ee=se(j?j[12]:z?.position?.x,0),L=se(j?j[13]:z?.position?.y,0),X=se(j?j[14]:z?.position?.z,0),J=ee-n,re=L-p,$=X-B,te=Math.hypot(J,re,$),O=Math.max(.01,Math.min(Math.PI/2,se(f.angle,Math.PI/3))),G=Math.max(0,Math.min(1,se(f.penumbra,0)));R.push({type:f.type,color:[f.color.r,f.color.g,f.color.b],intensity:f.intensity,position:[n,p,B],...f.type==="spot"?{direction:te>1e-6?[J/te,re/te,$/te]:[0,-1,0],outerConeAngle:O,innerConeAngle:Math.max(0,O*(1-G)),range:Math.max(0,se(f.distance,0))}:f.type==="point"?{range:Math.max(0,se(f.distance,0))}:{}})}});let w=[],y=new Set([e]),F=[];if(Array.isArray(e.children))for(let f=e.children.length-1;f>=0;f--)F.push({obj:e.children[f],parentKids:w});for(;F.length>0;){let{obj:f,parentKids:b}=F.pop();if(!f||typeof f!="object"||y.has(f))continue;y.add(f),f._bakeAuthorGeometry?.(),be().materializeDeclarativeGeometry?.(f);let n=!!(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)),p={name:f.name||(n?`Node_${l.length}`:"")},B=se(f.position?.x,0),z=se(f.position?.y,0),j=se(f.position?.z,0),ee=se(f.quaternion?.x,0),L=se(f.quaternion?.y,0),X=se(f.quaternion?.z,0),J=se(f.quaternion?.w,1),re=se(f.scale?.x,1),$=se(f.scale?.y,1),te=se(f.scale?.z,1);if((B||z||j)&&(p.translation=[B,z,j]),(ee||L||X||J!==1)&&(p.rotation=[ee,L,X,J]),(re!==1||$!==1||te!==1)&&(p.scale=[re,$,te]),f.visible===!1&&(p.extensions={...p.extensions||{},KHR_node_visibility:{visible:!1}},g.add("KHR_node_visibility")),f.userData&&Object.keys(f.userData).length>0&&(p.extras=JSON.parse(JSON.stringify(f.userData,(q,A)=>{if(!(q==="__proto__"||q==="prototype"||q==="constructor"))return typeof A=="function"?void 0:A})),f.userData.xr)){let q=Qt(f.userData.xr);p.extensions={...p.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},be().xrTraitSerializer?.gltfNode(p,f.userData.xr),g.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(f.geometry){let q=f.geometry,A=q.attributes.position;if(A&&A.count>0){let E=[1/0,1/0,1/0],H=[-1/0,-1/0,-1/0];for(let ie=0;ie<A.count;ie++){let ae=A.getX(ie),ne=A.getY(ie),oe=A.getZ(ie);ae<E[0]&&(E[0]=ae),ae>H[0]&&(H[0]=ae),ne<E[1]&&(E[1]=ne),ne>H[1]&&(H[1]=ne),oe<E[2]&&(E[2]=oe),oe>H[2]&&(H[2]=oe)}let W={attributes:{POSITION:h(A.array,"VEC3",34962,5126,A.count,E,H)}};if(q.attributes.normal&&(W.attributes.NORMAL=h(q.attributes.normal.array,"VEC3",34962,5126,q.attributes.normal.count)),q.attributes.uv&&(W.attributes.TEXCOORD_0=h(q.attributes.uv.array,"VEC2",34962,5126,q.attributes.uv.count)),q.index){let ie=q.index.array instanceof Uint32Array;W.indices=h(q.index.array,"SCALAR",34963,ie?5125:5123,q.index.count)}let Z=Array.isArray(f.material)?f.material[0]:f.material;Z&&(W.material=T(Z));let Q=f.userData?.variants;if(Q&&typeof Q=="object"){let ie=new Map;for(let ae of Object.keys(Q)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let ne=Q[ae];if(!ne||typeof ne!="object")continue;let oe=C.indexOf(ae);if(oe===-1&&C.length<256&&(oe=C.length,C.push(ae)),oe===-1)continue;let me=T(ne),pe=ie.get(me);pe||(pe=[],ie.set(me,pe)),pe.push(oe)}if(ie.size>0){let ae=[];for(let[ne,oe]of ie.entries())ae.push({material:ne,variants:oe});W.extensions={...W.extensions||{},KHR_materials_variants:{mappings:ae}},g.add("KHR_materials_variants")}}let Y=f;if(Y.isInstancedMesh&&typeof Y.count=="number"&&Y.count>0&&Y.instanceMatrix?.array){let ie=Math.min(1e4,Math.floor(Y.count)),ae=Y.instanceMatrix.array,ne=new Float32Array(ie*3),oe=new Float32Array(ie*4),me=new Float32Array(ie*3);for(let he=0;he<ie;he++){let{t:ge,r:ye,s:Te}=St(ae,he*16);ne[he*3]=ge[0],ne[he*3+1]=ge[1],ne[he*3+2]=ge[2],oe[he*4]=ye[0],oe[he*4+1]=ye[1],oe[he*4+2]=ye[2],oe[he*4+3]=ye[3],me[he*3]=Te[0],me[he*3+1]=Te[1],me[he*3+2]=Te[2]}let pe={TRANSLATION:h(ne,"VEC3",0,5126,ie),ROTATION:h(oe,"VEC4",0,5126,ie),SCALE:h(me,"VEC3",0,5126,ie)};if(Y.instanceColor?.array&&Y.instanceColor.array.length>=ie*3){let he=new Float32Array(Y.instanceColor.array.subarray(0,ie*3));pe._COLOR_0=h(he,"VEC3",0,5126,ie)}p.extensions={...p.extensions||{},EXT_mesh_gpu_instancing:{attributes:pe}},g.add("EXT_mesh_gpu_instancing")}let ue=c.length;c.push({primitives:[W],name:f.name,...p.extras?{extras:p.extras}:{}}),p.mesh=ue}}let O=l.length;l.push(p),d.push(f),b.push(O);let G=f.children;if(Array.isArray(G)&&G.length>0){let q=[];p.children=q;for(let A=G.length-1;A>=0;A--)F.push({obj:G[A],parentKids:q})}}for(let f=0;f<l.length;f++){let b=l[f];b.children&&b.children.length===0?delete b.children:b.children&&b.children.length>0&&(b.extras?.xr?.lod||b.extensions?.ANDROID_xr_scenecore?.lod||d[f]?.isLOD)&&(b.extensions={...b.extensions||{},MSFT_lod:{ids:[...b.children]}},g.add("MSFT_lod"))}let U=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),_=[];if(typeof U=="function"&&d.length>0){let f=t?.duration??4,b=t?.fps??15,n=Math.max(2,Math.round(f*b)+1),p=new Float32Array(n),B=d.map($=>[se($.position?.x,0),se($.position?.y,0),se($.position?.z,0),se($.quaternion?.x,0),se($.quaternion?.y,0),se($.quaternion?.z,0),se($.quaternion?.w,1),se($.scale?.x,1),se($.scale?.y,1),se($.scale?.z,1)]),z=d.map(()=>new Float32Array(n*3)),j=d.map(()=>new Float32Array(n*4)),ee=d.map(()=>new Float32Array(n*3));for(let $=0;$<n;$++){let te=$/(n-1)*f;p[$]=te;try{U(te)}catch{}for(let O=0;O<d.length;O++){let G=d[O];z[O][$*3]=se(G.position?.x,0),z[O][$*3+1]=se(G.position?.y,0),z[O][$*3+2]=se(G.position?.z,0);let q=se(G.quaternion?.x,0),A=se(G.quaternion?.y,0),E=se(G.quaternion?.z,0),H=se(G.quaternion?.w,1),W=Math.hypot(q,A,E,H)||1;if(q/=W,A/=W,E/=W,H/=W,$>0){let Z=($-1)*4,Q=j[O];Q[Z]*q+Q[Z+1]*A+Q[Z+2]*E+Q[Z+3]*H<0&&(q=-q,A=-A,E=-E,H=-H)}j[O][$*4]=q,j[O][$*4+1]=A,j[O][$*4+2]=E,j[O][$*4+3]=H,ee[O][$*3]=se(G.scale?.x,1),ee[O][$*3+1]=se(G.scale?.y,1),ee[O][$*3+2]=se(G.scale?.z,1)}}for(let $=0;$<d.length;$++){let te=d[$],O=B[$];te.position?.set(O[0],O[1],O[2]),te.quaternion?.set(O[3],O[4],O[5],O[6]),te.scale?.set(O[7],O[8],O[9])}e.updateMatrixWorld(!0);let L=null,X=()=>(L===null&&(L=h(p,"SCALAR",0,5126,n,[0],[f])),L),J=[],re=[];for(let $=0;$<d.length;$++){let te=B[$],O=(q,A,E)=>q.some((H,W)=>Math.abs(H-te[E+W%A])>1e-4),G=(q,A,E,H)=>{q&&re.push({sampler:J.push({input:X(),interpolation:"LINEAR",output:h(A,E,0,5126,n)})-1,target:{node:$,path:H}})};G(O(z[$],3,0),z[$],"VEC3","translation"),G(O(j[$],4,3),j[$],"VEC4","rotation"),G(O(ee[$],3,7),ee[$],"VEC3","scale")}re.length>0&&_.push({name:"ProceduralLoop",samplers:J,channels:re})}let k=mt(l,c,e.userData),P=[],N=[],S=[];for(let f=0;f<l.length;f++){let b=l[f],n=Et(b.extras?.xr);if(!n)continue;let{ae:p,src:B,preset:z,volume:j,loop:ee,isGlobal:L}=n,X=b.name||`Node_${f}`,J=N.length;N.push({name:`${X}_source`,gain:j,loop:ee,autoPlay:typeof p.autoplay=="boolean"?p.autoplay:!0,...B!==void 0?{audio:P.push({uri:B})-1}:{},...z?{extras:{preset:z,pitch:Me(p.pitch,.25,4,1)}}:{}});let re=S.length,$=Me(p.refDistance,.05,100,1),te=Me(p.coneInnerAngle,0,360,360),O=Me(p.coneOuterAngle,te,360,360);S.push({name:`${X}_emitter`,type:L?"global":"positional",gain:j,sources:[J],...L?{}:{positional:{distanceModel:p.distanceModel==="linear"||p.distanceModel==="exponential"?p.distanceModel:"inverse",refDistance:$,maxDistance:Me(p.maxDistance,$,500,Math.max($,25)),rolloffFactor:Me(p.rolloffFactor,0,10,1),coneInnerAngle:+(te*Math.PI/180).toFixed(6),coneOuterAngle:+(O*Math.PI/180).toFixed(6),coneOuterGain:Me(p.coneOuterGain,0,1,0)}}}),b.extensions={...b.extensions||{},KHR_audio_emitter:{emitter:re}},g.add("KHR_audio_emitter")}let o={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:w}],scene:0,nodes:l,meshes:c,materials:v,...I.length>0?{images:I}:{},...D.length>0?{samplers:D}:{},...u.length>0?{textures:u}:{},accessors:s,bufferViews:a,buffers:[{byteLength:r}],..._.length>0?{animations:_}:{},...k||g.size>0?{extensionsUsed:[...k?["KHR_interactivity"]:[],...g]}:{},...k||C.length>0||S.length>0?{extensions:{...k?{KHR_interactivity:k}:{},...C.length>0?{KHR_materials_variants:{variants:C.map(f=>({name:f}))}}:{},...S.length>0?{KHR_audio_emitter:{...P.length>0?{audio:P}:{},sources:N,emitters:S}}:{}}}:{}},V=new Uint8Array(r),K=0;for(let f of i)V.set(f,K),K+=f.byteLength;return[{gltf:o,bin:V.buffer,lights:R,environmentIntensity:e.environmentIntensity},d]}function Lt(e){return new TextEncoder().encode(e)}function en(e,t){let[i,r]=Jt(e,t);return Ke(i,r)}function Ke(e,t){let i=[],r=e.gltf,a=be().decoders.get("meshopt");a&&typeof a.decodeBufferViews=="function"&&a.decodeBufferViews(r,e);let s=e.bin,c=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),l=r.accessors||[],g=r.bufferViews||[],d=r.materials||[],v=r.meshes||[],M=r.nodes||[],I=r.textures||[],D=r.images||[],u=r.samplers||[],x=new Set,C=d.map((y,F)=>Rt(x,Ue(y?.name,`Material_${F}`))),R=new Map;function T(y){let F=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(y);if(!F)return null;let U=F[2].replace(/\s+/g,""),_=U.endsWith("==")?2:U.endsWith("=")?1:0,k=new Uint8Array((U.length*3>>2)-_),P=S=>{let o=U.charCodeAt(S);return o>96?o-71:o>64?o-65:o>47?o+4:o===43?62:o===47?63:0},N=0;for(let S=0;S<U.length;S+=4){let o=P(S)<<18|P(S+1)<<12|P(S+2)<<6|P(S+3);k[N++]=o>>16&255,N<k.length&&(k[N++]=o>>8&255),N<k.length&&(k[N++]=o&255)}return k}function m(y,F,U){let _=y?.index;if(typeof _!="number")return;let k=I[_],P=k?.source;if(typeof P!="number"||!D[P])return;let N=R.get(P);if(N===void 0){N=null;let V=D[P],K=null;if(typeof V.bufferView=="number"){let f=g[V.bufferView],b=f?.byteOffset||0,n=f?.byteLength||0;f&&n>0&&b>=0&&b+n<=c.byteLength&&(K=new Uint8Array(c,b,n))}else typeof V.uri=="string"&&(K=T(V.uri));if(K&&K.byteLength>0){let f=K[0]===255&&K[1]===216&&K[2]===255||!(K[0]===137&&K[1]===80)&&/jpe?g/i.test(V.mimeType||V.uri||"");N={file:`texture_${P}.${f?"jpg":"png"}`,data:K}}R.set(P,N)}if(!N)return;let S=typeof k.sampler=="number"?u[k.sampler]:void 0,o=V=>V===33071?"clamp":V===33648?"mirror":"repeat";return{file:N.file,data:N.data,wrapS:o(S?.wrapS),wrapT:o(S?.wrapT),...F?{scale:F}:{},...U?{bias:U}:{}}}function h(y){let F=l[y];if(!F)throw new Error(`Accessor ${y} not found`);let U=g[F.bufferView||0],_=(U.byteOffset||0)+(F.byteOffset||0),k=U.byteLength||0;return{acc:F,buffer:c.slice(_,_+k)}}function w(y,F,U,_){let k=[],P=v[y];if(!P)return k;let N=P.primitives||[];for(let S=0;S<N.length;S++){let o=N[S],V=o.attributes?.POSITION;if(V===void 0)continue;let{acc:K,buffer:f}=h(V),b=new Float32Array(f,0,K.count*3),n,p=o.attributes?.NORMAL;if(p!==void 0){let{acc:A,buffer:E}=h(p),H=new Float32Array(E,0,A.count*3);n=new Float32Array(H.length);for(let W=0;W<A.count;W++){let Z=H[W*3],Q=H[W*3+1],Y=H[W*3+2],ue=Math.hypot(Z,Q,Y)||1;n[W*3]=Z/ue,n[W*3+1]=Q/ue,n[W*3+2]=Y/ue}}let B,z=o.attributes?.TEXCOORD_0;if(z!==void 0){let{acc:A,buffer:E}=h(z);B=new Float32Array(E,0,A.count*2)}let j;if(o.indices!==void 0){let{acc:A,buffer:E}=h(o.indices);j=A.componentType===5125?new Uint32Array(E,0,A.count):new Uint16Array(E,0,A.count);let H=K.count;for(let W of j)if(W>=H)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${H}).`)}else{let A=K.count;j=A>65535?new Uint32Array(A):new Uint16Array(A);for(let E=0;E<A;E++)j[E]=E}let ee="DefaultMaterial",L=[1,1,1],X=.5,J=0,re=0,$=0,te=1.5,O=1,G=[0,0,0],q;if(o.material!==void 0&&d[o.material]){let A=d[o.material];ee=C[o.material]||`Material_${o.material}`;let E=A.pbrMetallicRoughness||{},H=(ge,ye)=>Array.isArray(ge)&&ge.length>=3?[ge[0],ge[1],ge[2]]:ye;L=H(E.baseColorFactor,[1,1,1]);let W=Array.isArray(E.baseColorFactor)&&typeof E.baseColorFactor[3]=="number"?E.baseColorFactor[3]:1,Z=L[0]!==1||L[1]!==1||L[2]!==1||W!==1,Q=m(E.baseColorTexture,Z?[L[0],L[1],L[2],W]:void 0),Y=A.extras?.avgColor;!Q&&Array.isArray(Y)&&Y.length>=3&&(L=[L[0]*Y[0],L[1]*Y[1],L[2]*Y[2]]),typeof E.roughnessFactor=="number"&&(X=E.roughnessFactor),typeof E.metallicFactor=="number"&&(J=E.metallicFactor);let ue=typeof E.roughnessFactor=="number"?E.roughnessFactor:1,ie=typeof E.metallicFactor=="number"?E.metallicFactor:1,ae=m(E.metallicRoughnessTexture,ue!==1||ie!==1?[1,ue,ie,1]:void 0);G=H(A.emissiveFactor,[0,0,0]);let ne=(G[0]>0||G[1]>0||G[2]>0)&&(G[0]!==1||G[1]!==1||G[2]!==1)?[G[0],G[1],G[2],1]:void 0,oe=m(A.emissiveTexture,ne),me=m(A.normalTexture,[2,2,2,1],[-1,-1,-1,0]),pe=m(A.occlusionTexture);(Q||ae||me||oe||pe)&&(q=[Q,ae,me,oe,pe]);let he=A.extensions||{};he.KHR_materials_clearcoat&&(re=he.KHR_materials_clearcoat.clearcoatFactor??0,$=he.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof he.KHR_materials_ior?.ior=="number"&&(te=he.KHR_materials_ior.ior),O=W*(1-(he.KHR_materials_transmission?.transmissionFactor??0))}k.push({name:N.length>1?`${F}_p${S}`:F,positions:b,indices:j,normals:n,uvs:B,materialName:ee,color:L,roughness:X,metallic:J,clearcoat:re,clearcoatRoughness:$,ior:te,opacity:O,emissiveColor:G,...q?{textures:q}:{},xrTraits:U||P.extras?.xr,..._?{invisible:!0}:{}})}return k}if(M.length>0){let y=new Float32Array(0),F=new Uint16Array(0),U=(b,n)=>{if(b===void 0)return null;let{acc:p,buffer:B}=h(b);return new Float32Array(B,0,p.count*n)},_=(b,n)=>Array.isArray(b)&&b.length>=3?[se(b[0],n),se(b[1],n),se(b[2],n)]:[n,n,n],k=(b,n,p)=>b&&b.length>=(n+1)*3?[b[n*3],b[n*3+1],b[n*3+2]]:p,P=(b,n,p)=>b&&b.length>=(n+1)*4?[b[n*4],b[n*4+1],b[n*4+2],b[n*4+3]]:p,N=new Map,S=r.animations?.[0];if(S&&Array.isArray(S.channels)&&Array.isArray(S.samplers))for(let b of S.channels){let n=S.samplers[b?.sampler],p=b?.target?.node,B=b?.target?.path;if(!n||typeof p!="number"||n.input===void 0)continue;let z=N.get(p);z||(z={input:n.input},N.set(p,z)),B==="translation"?z.t=n.output:B==="rotation"?z.r=n.output:B==="scale"&&(z.s=n.output)}let o=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(o)||o.length===0){let b=new Set;for(let n of M)if(Array.isArray(n?.children))for(let p of n.children)b.add(p);o=[];for(let n=0;n<M.length;n++)b.has(n)||o.push(n);o.length===0&&(o=[0])}let V=new Set,K=[],f=(b,n)=>{if(Array.isArray(b))for(let p=b.length-1;p>=0;p--)K.push({idx:b[p],out:n})};for(f(o,i);K.length>0;){let{idx:b,out:n}=K.pop();if(typeof b!="number"||b<0||b>=M.length||V.has(b))continue;V.add(b);let p=M[b];if(!p)continue;let B=[0,0,0],z=[0,0,0,1],j=[1,1,1];if(Array.isArray(p.matrix)&&p.matrix.length===16){let O=St(p.matrix);B=O.t,z=O.r,j=O.s}else B=_(p.translation,0),Array.isArray(p.rotation)&&p.rotation.length>=4&&(z=[se(p.rotation[0],0),se(p.rotation[1],0),se(p.rotation[2],0),se(p.rotation[3],1)]),j=_(p.scale,1);let ee,L=N.get(b);if(L){let O=U(L.input,1);if(O&&O.length>0){let G=U(L.t,3),q=U(L.r,4),A=U(L.s,3),E=Array.from(O),H=[],W=[],Z=[];for(let Q=0;Q<O.length;Q++)H.push(k(G,Q,B)),W.push(P(q,Q,z)),Z.push(k(A,Q,j));ee={times:E,translations:H,rotations:W,scales:Z}}}let X=Array.isArray(p.children)?p.children:[],J=typeof p.mesh=="number"&&p.mesh>=0&&p.mesh<v.length,re=t?.[b]?.userData?.xr??p.extras?.xr;if(!J&&X.length===0&&(p.camera!==void 0||p.extensions?.KHR_lights_punctual||!p.name&&!p.extras&&!re&&!ee))continue;let $=(O,G,q)=>({name:O,positions:y,indices:F,isXform:!0,xrTraits:re,timeSamples:ee,translation:B,rotation:z,scale:j,children:G,...q?{invisible:!0}:{}}),te=p.visible===!1||p.extensions?.KHR_node_visibility?.visible===!1||t?.[b]?.visible===!1;if(J){let O=p.name||v[p.mesh]?.name||`Mesh_${b}`,G=w(p.mesh,O,re,te),q=p.extensions?.EXT_mesh_gpu_instancing?.attributes;if(q&&typeof q=="object"&&G.length>0){let A=U(q.TRANSLATION,3),E=U(q.ROTATION,4),H=U(q.SCALE,3),W=U(q._COLOR_0,3),Z=Math.min(1e3,A?A.length/3:E?E.length/4:H?H.length/3:0);if(Z>0){let Q=[];for(let Y=0;Y<Z;Y++){let ue=k(A,Y,[0,0,0]),ie=P(E,Y,[0,0,0,1]),ae=k(H,Y,[1,1,1]);for(let ne of G){let oe=ne.color||[.8,.8,.8],me=W&&W.length>=(Y+1)*3;Q.push({...ne,name:`${ne.name}_${Y}`,materialName:me?`${ne.materialName}_inst_${Y}`:ne.materialName,color:me?[oe[0]*W[Y*3],oe[1]*W[Y*3+1],oe[2]*W[Y*3+2]]:ne.color,translation:ue,rotation:ie,scale:ae})}}f(X,Q),n.push($(O,Q,te));continue}}if(G.length===1)G[0].translation=B,G[0].rotation=z,G[0].scale=j,G[0].timeSamples=ee,X.length>0&&(G[0].children=[],f(X,G[0].children)),n.push(G[0]);else{let A=[...G];f(X,A),n.push($(O,A,te))}}else{let O=[];f(X,O),n.push($(p.name||`Group_${b}`,O,te))}}}else for(let y=0;y<v.length;y++){let F=v[y].name||`Mesh_${y}`;i.push(...w(y,F,v[y].extras?.xr))}return i}function Ue(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 de(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)=>`(${de(e)}, ${de(t)}, ${de(i)})`,_e=(e,t,i,r)=>`(${de(e)}, ${de(t)}, ${de(i)}, ${de(r)})`;function wt(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 tn(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${de(e[r*2])}, ${de(1-e[r*2+1])})`;return i.join(", ")}function nn(e){return Array.from(e).join(", ")}function qe(e){let t=new Map,i=0,r=null,a=[...e];for(;a.length>0;){let u=a.pop();if(!u.isXform&&u.positions&&u.positions.length>0){let x=Ue(u.materialName,"DefaultMaterial");t.has(x)||t.set(x,{color:u.color||[1,1,1],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0],textures:u.textures})}if(u.timeSamples&&u.timeSamples.times.length>0){let x=u.timeSamples.times[u.timeSamples.times.length-1];x>i&&(i=x)}if(u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal"),u.children)for(let x=u.children.length-1;x>=0;x--)a.push(u.children[x])}let s="";i>0&&(s=`startTimeCode = 0
|
|
250
|
-
endTimeCode = ${
|
|
214
|
+
void main(){fragColor=uColorId;}`;function Ve(e,t,i){let r={};for(let n of i)r[n]=e.getUniformLocation(t,n);return r}var sn="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 at(){let e=Ae(),t=e.xrDepthShader,i=e.shadowMapShader;return{fs:nn.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:[...sn,...t?.uniformNames||[],...i?.uniformNames||[]]}}function an(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 rt(e,t,i,r,n,a,l,o){if(r===void 0||!t.accessors?.[r])return null;let c=nt(t,i,t.accessors[r],a);if(!c)return null;o&&(c=c.slice(),Lt(c,o));let S=e.createBuffer();return l.push(S),e.bindBuffer(34962,S),e.bufferData(34962,c,35044),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,a,5126,!1,0,0),c}function it(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function Ft(e,t,i){let r=at(),n=st,a=r.fs,l=!1;for(let c of pe)if(c.onResolveShader){let S=c.onResolveShader(t,i,n,a);S&&(n=S.vs,a=S.fs,l=!0)}let o=l?Ce(e,n,a):null;return{program:o,uniforms:o?Ve(e,o,r.uniforms):null}}function un(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 o=e.createBuffer();i.push(o),e.bindBuffer(34962,o),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 cn(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 Un=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),_t=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ne(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function It(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,n=e?.emissiveFactor,a=e?.extensions?.KHR_materials_clearcoat,l=o=>o!==void 0&&t[o.index]?t[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat: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 kt(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 o=new Set;l.customProgram&&o.add(l.customProgram);for(let c of l.programCache?.values()??[])c.program&&o.add(c.program);for(let c of o)e.deleteProgram(c)}if(i)for(let a of i)n(a)}function Pt(e,t,i=_t,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ln(e,t,i,r,n)}catch(a){let l=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;kt(e,l,n.gpuTextures),n.vao&&e.deleteVertexArray(n.vao);for(let o of n.buffers)e.deleteBuffer(o);throw a}}function ln(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=$e("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(a,t);let o=t.bin,c=[];n.meshes=c;let S=[],p=a.extensions?.KHR_materials_variants;p&&Array.isArray(p.variants)&&p.variants.forEach((R,C)=>{S.push(typeof R?.name=="string"&&R.name?R.name:`Variant_${C}`)});let x=tt(a),E=[];if(Array.isArray(a.nodes))for(let R=0;R<a.nodes.length;R++){let C=a.nodes[R];C.mesh!==void 0&&a.meshes&&a.meshes[C.mesh]&&E.push({node:C,nodeIdx:R,meshIdx:C.mesh})}let I=E.length>0?E:(a.meshes||[]).map((R,C)=>({node:R,nodeIdx:-1,meshIdx:C})),T=[],F=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(F)for(let R of F)T.push({...R,type:R.type||R.light_type||"point",groundColor:R.groundColor??R.ground_color,innerConeAngle:R.innerConeAngle??R.inner_cone_angle,outerConeAngle:R.outerConeAngle??R.outer_cone_angle});else a.extensions?.KHR_lights_punctual?.lights&&T.push(...ut(a,x));if(T.length===0&&(T.push({type:"ambient",color:[1,1,1],intensity:.35}),T.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),I.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${I.length}`);let u=[];if(n.gpuTextures=u,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 R=0;R<a.textures.length;R++){let C=a.textures[R],$=a.images[C.source];if($){let B=e.createTexture();e.bindTexture(3553,B),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[P,V]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])e.texParameteri(3553,P,V);let y=P=>{B.__gpuImageSource=P,e.bindTexture(3553,B),e.texImage2D(3553,0,6408,6408,5121,P),e.generateMipmap(3553),r?.()};if($.bufferView!==void 0){let P=a.bufferViews[$.bufferView],V=P.byteOffset||0,j=new Blob([o.slice(V,V+P.byteLength)],{type:$.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(j).then(y).catch(()=>{})}else if($.uri){let P=an($.uri);if(P){let V=new Image;V.crossOrigin="anonymous",V.referrerPolicy="no-referrer",V.onload=()=>y(V),V.src=P}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",$.uri)}u.push(B)}else u.push(null)}}let m=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],d=0,b=0;for(let R=0;R<I.length;R++){let C=I[R],$=a.meshes[C.meshIdx],B=C.nodeIdx>=0?x[C.nodeIdx]:ye(),y=new Float32Array(9);Le(y,B);let P=C.node?.extras?.shadow,V={name:C.node.name||$.name||`Mesh_${C.meshIdx}`,nodeIndex:C.nodeIdx,transform:B,normalMatrix:y,primitives:[],extras:C.node.extras||$.extras,...C.node?.visible===!1||C.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=V;let j=C.node?.extensions?.EXT_mesh_gpu_instancing;if(j&&j.attributes&&typeof j.attributes=="object"){let v=j.attributes,O=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,h=v._COLOR_0!==void 0?a.accessors?.[v._COLOR_0]:null,A=Number(O?.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 q=(H,W)=>{if(!H||H.bufferView===void 0||!a.bufferViews?.[H.bufferView])return null;let D=H.componentType??5126,Q=Y=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Y})`),null);if(D!==5120&&D!==5121&&D!==5122&&D!==5123&&D!==5126)return Q(`componentType ${D}`);if(!(Number(H.count)>=A))return Q(`count ${H.count} < ${A}`);let Z=null;try{Z=nt(a,o,{...H,count:A},W)}catch{return Q("out of bounds")}return!Z||!Z.every(Number.isFinite)?Q("non-finite value"):Z},N=q(O,3),X=q(s,4),K=q(M,3),ne=h?.type==="VEC4"?4:3,ae=q(h,ne),oe=new Float32Array(A*16),se=ye();for(let H=0;H<A;H++){let W=H*3,D=H*4;Je(se,X?[X[D],X[D+1],X[D+2],X[D+3]]:[0,0,0,1],N?[N[W],N[W+1],N[W+2]]:[0,0,0],K?[K[W],K[W+1],K[W+2]]:[1,1,1]),oe.set(se,H*16)}if(V.instanceMatrices=oe,ae){let H=new Float32Array(A*3);for(let W=0;W<A;W++)H[W*3]=ae[W*ne],H[W*3+1]=ae[W*ne+1],H[W*3+2]=ae[W*ne+2];V.instanceColors=H}}}for(let v of $.primitives||[]){if(v.extensions?.KHR_draco_mesh_compression){let k=$e("draco");k&&k.decodePrimitive(a,v,o)}let O=[],s=e.createVertexArray();n.vao=s,n.buffers=O,e.bindVertexArray(s);let M=un(e,V,O),h=a.accessors[v.attributes.POSITION],A=Number(h?.count??0);if(!Number.isFinite(A)||A<0||d+A>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(d+=A,h?.min&&h?.max){let k=U=>{for(let G=0;G<3;G++){let J=U[12+G],ee=J;for(let ie=0;ie<3;ie++){let le=U[ie*4+G]*h.min[ie],re=U[ie*4+G]*h.max[ie];J+=le<re?le:re,ee+=le>re?le:re}J<m[G]&&(m[G]=J),ee>g[G]&&(g[G]=ee)}};if(V.instanceMatrices&&V.instanceMatrices.length>=16){let U=V.instanceMatrices.length>>4,G=ye();for(let J=0;J<U;J++)xe(G,B,V.instanceMatrices.subarray(J*16,J*16+16)),k(G)}else k(B)}let q=rt(e,a,o,v.attributes.POSITION,0,3,O),N=rt(e,a,o,v.attributes.NORMAL,1,3,O),X=rt(e,a,o,v.attributes.TEXCOORD_0,2,2,O,cn(a,v)),K=0,ne=5123,ae=null;if(v.indices!==void 0){let k=a.accessors[v.indices],U=(a.bufferViews[k.bufferView].byteOffset||0)+(k.byteOffset||0);if(K=Number(k.count??0),!Number.isFinite(K)||K<0||b+K>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);b+=K,ne=k.componentType===5125?5125:5123;let G=e.createBuffer();O.push(G),e.bindBuffer(34963,G),k.componentType===5125?ae=new Uint32Array(o,U,k.count):k.componentType===5121?ae=Uint16Array.from(new Uint8Array(o,U,k.count)):ae=U%2===0?new Uint16Array(o,U,k.count):new Uint16Array(o.slice(U,U+k.count*2)),e.bufferData(34963,ae,35044)}else K=h.count;let oe={};for(let k of pe)if(k.onBuildPrimitiveVAO){let U=k.onBuildPrimitiveVAO(e,s,v,a,o);U&&(oe[k.name]=U)}e.bindVertexArray(null);let se=a.materials&&v.material!==void 0?a.materials[v.material]:null,{program:H,uniforms:W}=Ft(e,v,se),D=It(se,u),Q=!!(se?.extensions?.KHR_materials_transmission||oe.materials?.isTransmissive),Z=v.extensions?.KHR_materials_variants?.mappings,Y=Array.isArray(Z)?Z.filter(k=>k&&typeof k.material=="number"&&Array.isArray(k.variants)).map(k=>({material:k.material|0,variants:k.variants.map(U=>Number(U)|0)})):void 0;V.primitives.push({vao:s,instanced:M,indexCount:K,indexType:ne,...D,positions:q,normals:N,uvs:X,indices:ae,buffers:O,materialIndex:v.material,defaultMaterialIndex:v.material,variantMappings:Y,primitiveDef:v,programCache:new Map([[v.material??-1,{program:H,uniforms:W}]]),pluginData:oe,customProgram:H,customUniforms:W,isTransmissive:Q})}c.push(V)}isFinite(m[0])||(m=[-1,-1,-1]),isFinite(g[0])||(g=[1,1,1]);let w=[(m[0]+g[0])/2,(m[1]+g[1])/2,(m[2]+g[2])/2],f=Math.max(Math.hypot(g[0]-m[0],g[1]-m[1],g[2]-m[2])/2,.5),z=[...m],_=[...g],L=t.animations;if(t.animationsParsed===!1||!L){for(let R of pe)if(R.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:c,bounds:{center:w,radius:f,min:z,max:_},lights:T,animations:L,worldMatrices:x,gpuTextures:u,availableVariants:S}}function Ge(){return typeof performance<"u"?performance.now():Date.now()}function Fe(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 Oe=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=ye(),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=ye(),this.viewMatrix=ye(),this.activeViewMatrix=null,this.modelMatrix=ye(),this.mvpMatrix=ye(),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:ye(),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=it(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=ot(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 o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),a.environmentImage&&this.setEnvironmentImage(a.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&a.autoStart!==!1&&this.start()}static registerDecoder(e,t){en(e,t)}static getDecoder(e){return $e(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=at();this.renderProg=Ce(e,st,t.fs),this.pickProg=Ce(e,rn,on),this.uRender=Ve(e,this.renderProg,t.uniforms),this.uPick=Ve(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let e=this.gl,t=at();this.renderProg&&e.deleteProgram(this.renderProg),this.renderProg=Ce(e,st,t.fs),this.uRender=Ve(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 pe)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:o,availableVariants:c}=Pt(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=o||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(e.gltf?.nodes||[]).map(x=>({t:[x.translation?.[0]??0,x.translation?.[1]??0,x.translation?.[2]??0],r:[x.rotation?.[0]??0,x.rotation?.[1]??0,x.rotation?.[2]??0,x.rotation?.[3]??1],s:[x.scale?.[0]??1,x.scale?.[1]??1,x.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let x of pe)x.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 S=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;S!==void 0&&(this.exposure=it(S));let p=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;p!==void 0&&(this.envIntensity=Math.max(0,Number(p)||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(Ct(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of pe)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}=Pt(this.gl,i,_t,()=>this.render());if(t)for(let n of r)n.transform[12]+=t[0],n.transform[13]+=t[1],n.transform[14]+=t[2],Le(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),Le(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=[],o=[],c=[],S=[],p=[];for(let x of this.lights){let E=x.color||[1,1,1],I=x.intensity!==void 0?x.intensity:1;if(x.type==="ambient")i=[E[0]*I,E[1]*I,E[2]*I];else if(x.type==="hemisphere"){n=!0;let T=x.groundColor||[.2,.2,.2],F=I*.65;for(let g=0;g<3;g++)r[g]+=E[g]*F,r[g+3]+=T[g]*F;let u=x.position||[0,1,0],m=Math.hypot(u[0],u[1],u[2]);m>1e-5&&(r[6]=u[0]/m,r[7]=u[1]/m,r[8]=u[2]/m)}else if(x.type==="directional"&&a.length<6){let T=x.direction||[.5,1,.8];a.push(T[0],T[1],T[2]),l.push(E[0]*I,E[1]*I,E[2]*I)}else if((x.type==="point"||x.type==="spot")&&o.length<6){let T=x.position||[0,0,0];if(o.push(T[0],T[1],T[2]),c.push(E[0]*I,E[1]*I,E[2]*I),x.type==="spot"){let F=x.direction||[0,-1,0],u=Math.max(.01,Math.min(Math.PI/2,x.outerConeAngle??Math.PI/3)),m=Math.max(0,Math.min(u-1e-4,x.innerConeAngle??0));S.push(F[0],F[1],F[2]),p.push(Math.cos(m),Math.cos(u))}else S.push(0,-1,0),p.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,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,c),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,S),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,p)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=it(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=ot(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){this.environmentSource=e&&typeof e=="object"?e:null;for(let t of pe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e),this.render();return}this.render()}async setSkyboxImage(e){for(let t of pe)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(p=>p.primitives.filter(x=>x.materialIndex===i||e.length===1&&x.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,o=n?n.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c=(p,x,E)=>{S[p]=E,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness[p]=E);for(let I of r)I[x]=E;this.render()},S={baseColorFactor:a,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:p=>c("baseColorFactor","baseColor",[p[0],p[1],p[2],p[3]??1]),setMetallicFactor:p=>c("metallicFactor","metallic",p),setRoughnessFactor:p=>c("roughnessFactor","roughness",p)};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:S}})}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 o=l!==void 0?r[l]:void 0;a.materialIndex=o?l:void 0,Object.assign(a,It(o,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,n=e.programCache.get(r);n||(n=Ft(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 pe)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=ye();xe(i,this.projMatrix,this.viewMatrix);let r=(_,L,R=1)=>[_[0]*L[0]+_[4]*L[1]+_[8]*L[2]+_[12]*R,_[1]*L[0]+_[5]*L[1]+_[9]*L[2]+_[13]*R,_[2]*L[0]+_[6]*L[1]+_[10]*L[2]+_[14]*R,_[3]*L[0]+_[7]*L[1]+_[11]*L[2]+_[15]*R],n=this.modelRootMatrix,[a,l,o]=n?r(n,e):e,[c,S,p]=t?n?r(n,t,0):t:[0,0,0],[x,E,I,T]=r(i,[a,l,o]);if(T<=1e-4)return{x:0,y:0,z:1,visible:!1};let F=x/T,u=E/T,m=I/T,g=this.canvas.getBoundingClientRect(),d=g.width||this.canvas.clientWidth||this.canvas.width||300,b=g.height||this.canvas.clientHeight||this.canvas.height||150,w=(F*.5+.5)*d,f=(-u*.5+.5)*b,z=F>=-1.1&&F<=1.1&&u>=-1.1&&u<=1.1&&m>=-1&&m<=1;if(z&&t){let[_,L,R]=Fe(this),C=[a-_,l-L,o-R];c*C[0]+S*C[1]+p*C[2]>.05&&(z=!1)}return{x:w,y:f,z:m,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=Ge;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]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],S=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-n*l[0]+a*o[0])*S,c[1]+=(-n*l[1]+a*o[1])*S,c[2]+=(-n*l[2]+a*o[2])*S,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),o=r.height>0?Math.floor((t-r.top)*(a/r.height)):Math.floor(t);return this.performMeshPick(l,o,!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=ye();xe(l,this.projMatrix,this.viewMatrix);let o=[],c=Math.max(0,Math.min(n-1,e)),S=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 f=this.meshes[w];if(f.visible===!1||f.isPluginMesh)continue;let z=w+1,_=(z&255)/255,L=(z>>8&255)/255,R=(z>>16&255)/255;r.uniform4f(this.uPick.uColorId,_,L,R,1),xe(this.modelMatrix,this.modelRootMatrix,f.transform);let C=f.instanceMatrices;if(C&&C.length>=16){let $=C.length>>4,B=ye();for(let y of f.primitives){r.bindVertexArray(y.vao);for(let P=0;P<$;P++)xe(B,this.modelMatrix,C.subarray(P*16,P*16+16)),xe(this.mvpMatrix,l,B),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ne(r,y)}}else{xe(this.mvpMatrix,l,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let $ of f.primitives)r.bindVertexArray($.vao),Ne(r,$)}}let d=new Uint8Array(4);r.readPixels(c,S,1,1,6408,5121,d),r.bindFramebuffer(36160,null);let b=d[0]+(d[1]<<8)+(d[2]<<16);b>0&&b<=this.meshes.length&&(o=[this.meshes[b-1]])}o.length===0&&(o=this.meshes.filter(d=>d.visible!==!1));let p=null,x=1/0,E=[0,0,0],I=[0,1,0],[T,F,u]=Fe(this),m=ye();for(let d of o){xe(m,this.modelRootMatrix,d.transform);let b=d.instanceMatrices,w=b&&b.length>=16?b.length>>4:1;for(let f=0;f<w;f++){b&&b.length>=16?xe(this.modelMatrix,m,b.subarray(f*16,f*16+16)):this.modelMatrix.set(m),xe(this.mvpMatrix,l,this.modelMatrix);let z=ye();if(!At(z,this.mvpMatrix))continue;let _=(c+.5)/n*2-1,L=(S+.5)/a*2-1,R=[0,0,0],C=[0,0,0];et(R,_,L,-1,z),et(C,_,L,1,z);let $=C[0]-R[0],B=C[1]-R[1],y=C[2]-R[2],P=Math.hypot($,B,y)||1,V=$/P,j=B/P,v=y/P,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let s of d.primitives){if(!s.positions)continue;let M=s.positions,h=s.indices,A=Math.floor(h?h.length/3:M.length/9);for(let q=0;q<A;q++){let N=(h?h[q*3]:q*3)*3,X=(h?h[q*3+1]:q*3+1)*3,K=(h?h[q*3+2]:q*3+2)*3;wt(R[0],R[1],R[2],V,j,v,M[N],M[N+1],M[N+2],M[X],M[X+1],M[X+2],M[K],M[K+1],M[K+2],O,1e-4)}}if(isFinite(O.distance)){let s=O.point[0],M=O.point[1],h=O.point[2],A=this.modelMatrix,q=A[0]*s+A[4]*M+A[8]*h+A[12],N=A[1]*s+A[5]*M+A[9]*h+A[13],X=A[2]*s+A[6]*M+A[10]*h+A[14],K=q-T,ne=N-F,ae=X-u,oe=Math.hypot(K,ne,ae);if(oe<x){Le(this.normalMatrix,this.modelMatrix);let se=this.normalMatrix,H=O.normal[0],W=O.normal[1],D=O.normal[2],Q=se[0]*H+se[3]*W+se[6]*D,Z=se[1]*H+se[4]*W+se[7]*D,Y=se[2]*H+se[5]*W+se[8]*D,k=Math.hypot(Q,Z,Y)||1;Q/=k,Z/=k,Y/=k,Q*K+Z*ne+Y*ae>0&&(Q=-Q,Z=-Z,Y=-Y);let U=G=>Math.round(G*1e3)/1e3;p=d,x=U(oe),E=[U(q),U(N),U(X)],I=[U(Q),U(Z),U(Y)]}}}}if(!p)return null;let g={meshIndex:this.meshes.indexOf(p),meshName:p.name,nodeIndex:p.nodeIndex,distance:x,hitPoint:E,normal:I,screenX:e,screenY:t};if(i){for(let d of pe)d.onMeshSelect?.(this,g);this.opts.onMeshClick&&this.opts.onMeshClick(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:g}))}return g}mapStereoPickX(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);Ze(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;Qe(this.viewMatrix,Fe(this),i,[0,1,0]),xe(this.mvpMatrix,this.projMatrix,this.viewMatrix),Le(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 pe)i.onXRSessionEnd?.(this);if(this.lastTime=Ge(),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 pe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=Ge();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 pe)a.onUpdate?.(this,e);let t=Ge();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let a of pe)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,o=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,S=c?[c.x,c.y,c.z]:[0,1.6,0];t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:o,eyePos:S,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 f=Math.max(2,this.canvas.width||2),z=Math.max(1,this.canvas.height||1),_=Math.max(1,Math.floor(f*.5)),L=Math.max(1,f-_),R=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),C=this.customTarget||this.bounds.center,[$,B,y]=Fe(this),P=Math.cos(this.currTheta),V=-Math.sin(this.currTheta),j=.032;for(let v of[-1,1]){let O=ye(),s=ye(),M=v<0?_:L,h=[$+v*P*j,B,y+v*V*j];Ze(O,this.fov,M/z,.1,R),Qe(s,h,[C[0]+v*P*j*.25,C[1],C[2]+v*V*j*.25],[0,1,0]),this.render({viewMatrix:s,projMatrix:O,eyePos:h,viewport:[v<0?0:_,0,M,z],eye:v<0?"left":"right",clear:v<0,isAR:!1})}this.gl.viewport(0,0,f,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 f=e?.isAR?[0,0,0,0]:this.clearColor;t.clearColor(f[0],f[1],f[2],f[3]),t.clear(16640)}let l=ye(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o;let c=e?.projMatrix??this.projMatrix;xe(l,c,o);let S=Ae(),p=S.xrDepthShader,x=Qt(this.toneMapping),[E,I,T]=e?e.eyePos:Fe(this);for(let f of pe)f.onBeforeDrawScene?.(this,t,l,[E,I,T],x);let F=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&F===0){S.gpuSceneAccelerator?.hideLayer?.(this);return}let u=e?.eye||"none",m=!e||e.clear!==!1;if(!this.xrSessionActive&&S.gpuSceneAccelerator?.renderScene(this,l,c,o,[E,I,T],x,[i,r,n,a],u,m,!!e?.isAR)){m&&!this.skyboxTexture&&(t.clearColor(0,0,0,0),t.clear(16384));for(let f of pe)f.name.includes("webgpu")&&f.onAfterRender?.(t,this,l,u,[i,r,n,a],c);return}let g=!1,d=F>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=(f,z,_,L)=>{z?(t.activeTexture(33984+f),t.bindTexture(3553,z),t.uniform1i(_,f),t.uniform1i(L,1)):t.uniform1i(L,0)},w=f=>{for(let z=0;z<d.length;z++){let _=d[z];if(_.visible===!1)continue;let L=this.selectedMeshNames.has(_.name);if(z<F||_.worldSpace===!0||_.name==="__xr_reticle__")this.modelMatrix.set(_.transform);else{xe(this.modelMatrix,this.modelRootMatrix,_.transform);let P=!e&&(_.extras?.xr?.billboard??_.userData?.xr?.billboard);if(P){let V=this.modelMatrix,j=Math.hypot(V[0],V[1],V[2])||1,v=Math.hypot(V[4],V[5],V[6])||1,O=Math.hypot(V[8],V[9],V[10])||1,s=P==="y"||P==="cylindrical"||P==="capsule",M=E-V[12],h=T-V[14],A=Math.hypot(M,h),q=A>1e-5?M/A:0,N=A>1e-5?h/A:1;V.set(s?[N*j,0,-q*j,0,0,v,0,0,q*O,0,N*O]:[o[0]*j,o[4]*j,o[8]*j,0,o[1]*v,o[5]*v,o[9]*v,0,o[2]*O,o[6]*O,o[10]*O])}}xe(this.mvpMatrix,l,this.modelMatrix),Le(_.normalMatrix,this.modelMatrix);let R=_.extras?.xr?.stereo||_.userData?.xr?.stereo,C=0,$=0,B=1,y=1;R==="sbs"?(B=.5,C=u==="right"?.5:0):R==="ou"&&(y=.5,$=u==="right"?.5:0);for(let P of _.primitives){let V=!!P.isTransmissive;if(!f&&V){g=!0;continue}if(f&&!V)continue;let j=P.customProgram||this.renderProg,v=P.customUniforms||this.uRender;t.useProgram(j),t.vertexAttrib3f(3,0,0,0),v.uInstanced&&t.uniform1i(v.uInstanced,0),t.uniform1i(v.uToneMapping,x),t.uniform1f(v.uEnvIntensity,this.envIntensity),v.uExposure&&t.uniform1f(v.uExposure,this.exposure),t.uniform3f(v.uCameraPos,E,I,T),t.uniform1f(v.uEmissive,L?1:0),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(v.uNormalMatrix,!1,_.normalMatrix),v.uUvTransform&&t.uniform4f(v.uUvTransform,C,$,B,y),v.uViewportSize&&t.uniform2f(v.uViewportSize,Math.max(1,n),Math.max(1,a)),p?.bind(t,v,this.xrDepthState,o,[i,r,Math.max(1,n),Math.max(1,a)]),S.shadowMapShader?.bind(t,v,this,_),b(4,this.environmentTexture,v.uEnvironmentMap,v.uHasEnvironmentMap),this.bindLights(v),v.uSectionEnabled&&t.uniform1i(v.uSectionEnabled,0);for(let s of pe)s.onBeforeDrawPrimitive?.(t,j,P,_,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),b(0,P.texture,v.uBaseColorTexture,v.uHasTexture),b(1,P.metallicRoughnessTexture,v.uMetallicRoughnessTexture,v.uHasMetallicRoughnessTexture),b(2,P.normalTexture,v.uNormalTexture,v.uHasNormalTexture),P.normalTexture&&t.uniform1f(v.uNormalScale,P.normalScale),b(3,P.occlusionTexture,v.uOcclusionTexture,v.uHasOcclusionTexture),P.occlusionTexture&&t.uniform1f(v.uOcclusionStrength,P.occlusionStrength),t.uniform3fv(v.uEmissiveFactor,P.emissiveFactor),b(8,P.emissiveTexture,v.uEmissiveTexture,v.uHasEmissiveTexture),t.bindVertexArray(P.vao);let O=_.instanceMatrices;if(P.instanceCount!==void 0)t.drawElementsInstanced(4,P.indexCount,P.indexType,0,P.instanceCount);else if(O&&O.length>=16&&P.instanced&&v.uInstanced&&v.uViewProj){let s=O.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(O&&O.length>=16){let s=O.length>>4,M=_.instanceColors,h=ye(),A=new Float32Array(9);for(let q=0;q<s;q++){if(xe(h,this.modelMatrix,O.subarray(q*16,q*16+16)),xe(this.mvpMatrix,l,h),Le(A,h),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,h),t.uniformMatrix3fv(v.uNormalMatrix,!1,A),M){let N=P.baseColor,X=q*3;t.uniform4fv(v.uBaseColor,[N[0]*M[X],N[1]*M[X+1],N[2]*M[X+2],N[3]])}Ne(t,P)}}else Ne(t,P)}}};if(w(!1),g){for(let f of pe)f.onBeforeTransmissivePass?.(t,this);w(!0)}for(let f of pe)f.onAfterRender?.(t,this,l,u,[i,r,n,a],c)}disposeMeshListGpuResources(e,t){kt(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 pe)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()}};Oe.registerPlugin=Tt,Oe.getRegisteredPlugins=St;function mn(e){return e+3&-4}var te=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function ct(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function Bt(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 o=Math.sqrt((1+l)*2);return[a/o,-n/o,0,o*.5]}function Nt(e,t=0){let[i,r,n,,a,l,o,,c,S,p,,x,E,I]=Array.from({length:15},(O,s)=>te(e[t+s],s%5===0?1:0)),T=Math.hypot(i,r,n),F=Math.hypot(a,l,o),u=Math.hypot(c,S,p);i*(l*p-S*o)-a*(r*p-S*n)+c*(r*o-l*n)<0&&(T=-T);let m=Math.abs(T)>1e-8?1/T:0,g=Math.abs(F)>1e-8?1/F:0,d=Math.abs(u)>1e-8?1/u:0,b=i*m,w=r*m,f=n*m,z=a*g,_=l*g,L=o*g,R=c*d,C=S*d,$=p*d,B=b+_+$,y=0,P=0,V=0,j=1;if(B>0){let O=.5/Math.sqrt(B+1);j=.25/O,y=(L-C)*O,P=(R-f)*O,V=(w-z)*O}else if(b>_&&b>$){let O=2*Math.sqrt(Math.max(0,1+b-_-$));O>1e-8&&(j=(L-C)/O,y=.25*O,P=(z+w)/O,V=(R+f)/O)}else if(_>$){let O=2*Math.sqrt(Math.max(0,1+_-b-$));O>1e-8&&(j=(R-f)/O,y=(z+w)/O,P=.25*O,V=(L+C)/O)}else{let O=2*Math.sqrt(Math.max(0,1+$-b-_));O>1e-8&&(j=(w-z)/O,y=(R+f)/O,P=(L+C)/O,V=.25*O)}let v=Math.hypot(y,P,V,j);return v>1e-8&&Number.isFinite(v)?(y/=v,P/=v,V/=v,j/=v):(y=0,P=0,V=0,j=1),{t:[x,E,I],r:[y,P,V,j],s:[T,F,u]}}function hn(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 Gt(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 fn(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 dn(e,t){e.updateMatrixWorld(!0);let i=[],r=0,n=[],a=[],l=[],o=[],c=new Set,S=[],p=[],x=new Map,E=[],I=[],T=[],F=new Map,u=[],m=[],g=[],d=!1;function b(s){let M=x.get(s);if(M!==void 0)return M;M=p.length,x.set(s,M);let h=s,A=h.color?.r??1,q=h.color?.g??1,N=h.color?.b??1,X=h.opacity??1,K={baseColorFactor:[A,q,N,X],metallicFactor:h.metalness??0,roughnessFactor:h.roughness??.5},ne={},ae=re=>{if(!re)return;let de=(typeof re=="string"?re:typeof re.source=="string"?re.source:typeof re.image=="string"?re.image:"").trim();if(!de||/[\x00-\x1f\x7f\\]|\.\./.test(de)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(de)||!de.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(de)))return;let ue=F.get(de);if(ue===void 0){let me=E.length;E.push({uri:de}),I.length===0&&I.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),ue=T.length,T.push({sampler:0,source:me}),F.set(de,ue)}return{index:ue}},oe=h._packPbr?.(),se=ae(h.map);se&&(K.baseColorTexture=se);let H=ae(oe?.mrUri||h.roughnessMap||h.metalnessMap);H&&(K.metallicRoughnessTexture=H);let W=h.map?.avgColor;Array.isArray(W)&&W.length>=3&&(ne.avgColor=[W[0],W[1],W[2]]);let D=ae(oe?.normUri||h.normalMap),Q=h.normalScale,Z=oe?.normUri?oe.normScale??1:typeof Q=="number"?Math.max(0,te(Q,1)):Q?Math.max(0,(te(Q.x,1)+te(Q.y,1))*.5):1;D&&Z!==1&&(D.scale=Z);let Y=ae(h.emissiveMap),k=ae(h.aoMap),U=Math.max(0,Math.min(1,te(h.aoMapIntensity,1)));k&&U!==1&&(k.strength=U);let G={name:h.name||"",pbrMetallicRoughness:K,doubleSided:h.side===2||!!h.doubleSided,...X<1||h.transparent?{alphaMode:"BLEND"}:{},...D?{normalTexture:D}:{},...Y?{emissiveTexture:Y}:{},...k?{occlusionTexture:k}:{},...Object.keys(ne).length>0?{extras:ne}:{}},J=Math.max(0,te(h.emissiveIntensity,1)),ee=h.emissive&&(h.emissive.r>0||h.emissive.g>0||h.emissive.b>0);(ee||Y&&!h._em&&J>0)&&(G.emissiveFactor=ee?[h.emissive.r*J,h.emissive.g*J,h.emissive.b*J]:[J,J,J]);let ie={};h.clearcoat&&h.clearcoat>0&&(ie.KHR_materials_clearcoat={clearcoatFactor:h.clearcoat,clearcoatRoughnessFactor:h.clearcoatRoughness||0}),h.sheen&&h.sheen>0&&(ie.KHR_materials_sheen={sheenColorFactor:h.sheenColor?[h.sheenColor.r,h.sheenColor.g,h.sheenColor.b]:[1,1,1],sheenRoughnessFactor:h.sheenRoughness||0}),h.transmission&&h.transmission>0&&(ie.KHR_materials_transmission={transmissionFactor:h.transmission}),h.thickness&&h.thickness>0&&(ie.KHR_materials_volume={thicknessFactor:h.thickness,attenuationDistance:h.attenuationDistance??1/0,attenuationColor:h.attenuationColor?[h.attenuationColor.r,h.attenuationColor.g,h.attenuationColor.b]:[1,1,1]}),h.ior!==void 0&&h.ior!==1.5&&(ie.KHR_materials_ior={ior:h.ior}),h.dispersion&&h.dispersion>0&&(ie.KHR_materials_dispersion={dispersion:h.dispersion}),h.iridescence&&h.iridescence>0&&(ie.KHR_materials_iridescence={iridescenceFactor:h.iridescence,iridescenceIor:h.iridescenceIOR??1.3});let le=h._serializeTslGraph?.();return le&&(ie.GOOGLE_material_tsl=le,c.add("GOOGLE_material_tsl")),Object.keys(ie).length>0&&(G.extensions=ie),p.push(G),M}function w(s,M){let h=new Uint8Array(s.buffer,s.byteOffset,s.byteLength),A=mn(h.byteLength),q=new Uint8Array(A);q.set(h),i.push(q);let N=n.length;return n.push({buffer:0,byteOffset:r,byteLength:h.byteLength,target:M}),r+=A,N}function f(s,M,h,A,q,N,X){let K=w(s,h),ne=a.length,ae={bufferView:K,byteOffset:0,componentType:A,count:q,type:M};return N&&(ae.min=N),X&&(ae.max=X),a.push(ae),ne}let z=[],_=[],L=new Set([e]),R=[];if(Array.isArray(e.children))for(let s=e.children.length-1;s>=0;s--)R.push({obj:e.children[s],parentKids:_});for(;R.length>0;){let{obj:s,parentKids:M}=R.pop();if(!s||typeof s!="object"||L.has(s))continue;L.add(s),s._bakeAuthorGeometry?.(),Ae().materializeDeclarativeGeometry?.(s);let h=!!(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||(h?`Node_${o.length}`:"")},q=te(s.position?.x,0),N=te(s.position?.y,0),X=te(s.position?.z,0),K=te(s.quaternion?.x,0),ne=te(s.quaternion?.y,0),ae=te(s.quaternion?.z,0),oe=te(s.quaternion?.w,1),se=te(s.scale?.x,1),H=te(s.scale?.y,1),W=te(s.scale?.z,1);if((q||N||X)&&(A.translation=[q,N,X]),(K||ne||ae||oe!==1)&&(A.rotation=[K,ne,ae,oe]),(se!==1||H!==1||W!==1)&&(A.scale=[se,H,W]),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,(k,U)=>{if(!(k==="__proto__"||k==="prototype"||k==="constructor"))return typeof U=="function"?void 0:U})),s.userData.xr)){let k=hn(s.userData.xr);A.extensions={...A.extensions||{},MOZ_hubs_components:k,ANDROID_xr_scenecore:k},Ae().xrTraitSerializer?.gltfNode(A,s.userData.xr);let U=fn(s),G=A.extras?.xr?.material;U&&G&&typeof G=="object"&&!Array.isArray(G)&&(G.textureKey=U),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let D=s,Q=D.isLight||D.color&&D.intensity!==void 0;if(!Q&&(D._castShdSet||D._recvShdSet||s.castShadow||s.receiveShadow)&&(A.extras={...A.extras||{},shadow:{cast:!!s.castShadow,receive:D._recvShdSet?!!s.receiveShadow:!!(s.receiveShadow||s.castShadow)}}),Q){let k=D.matrixWorld?.elements,U=te(k?k[12]:s.position?.x,0),G=te(k?k[13]:s.position?.y,0),J=te(k?k[14]:s.position?.z,0),ee=D.target,ie=ee?.parent?ee?.matrixWorld?.elements:void 0,le=te(ie?ie[12]:ee?.position?.x,0),re=te(ie?ie[13]:ee?.position?.y,0),de=te(ie?ie[14]:ee?.position?.z,0),ue=le-U,me=re-G,he=de-J,ce=Math.hypot(ue,me,he),ge=Math.max(.01,Math.min(Math.PI/2,te(D.angle,Math.PI/3))),ve=Math.max(0,Math.min(1,te(D.penumbra,0))),fe=Math.max(0,ge*(1-ve)),Me=Math.max(0,te(D.distance,0)),Se=s.type==="directional"||s.type==="spot"||s.type==="point",Pe;if(s.castShadow&&Se){let Re=D.shadow,Ke=Math.max(256,Math.min(2048,Math.round(te(Re?.mapSize?.x??Re?.mapSize?.width,1024))));Pe={cast:!0,mapSize:Ke<=384?256:Ke<=768?512:Ke<=1536?1024:2048,bias:we(Re?.bias,-.05,.05,-5e-4),normalBias:we(Re?.normalBias,0,.2,.015),radius:we(Re?.radius,0,8,1.5)},d=!0}let Ue=U-le,qe=G-re,Xe=J-de,De=Math.hypot(Ue,qe,Xe);m.push({type:s.type,color:[s.color.r,s.color.g,s.color.b],intensity:s.intensity,position:s.type==="directional"?[Ue,qe,Xe]:[U,G,J],...s.type==="directional"?{direction:De>1e-6?[Ue/De,qe/De,Xe/De]:[0,1,0]}:s.type==="spot"?{direction:ce>1e-6?[ue/ce,me/ce,he/ce]:[0,-1,0],outerConeAngle:ge,innerConeAngle:fe,range:Me}:s.type==="point"?{range:Me}:s.type==="hemisphere"&&D.groundColor?{groundColor:[D.groundColor.r,D.groundColor.g,D.groundColor.b]}:{},...Pe?{shadow:Pe}:{}}),Se&&z.push({node:A,obj:s,px:U,py:G,pz:J,tx:le,ty:re,tz:de,dx:ue,dy:me,dz:he,dLen:ce,outerAngle:ge,innerAngle:fe,range:Me,shadowSpec:Pe})}if(s.geometry){let k=s.geometry,U=k.attributes.position;if(U&&U.count>0){let G=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0];for(let ue=0;ue<U.count;ue++){let me=U.getX(ue),he=U.getY(ue),ce=U.getZ(ue);me<G[0]&&(G[0]=me),me>J[0]&&(J[0]=me),he<G[1]&&(G[1]=he),he>J[1]&&(J[1]=he),ce<G[2]&&(G[2]=ce),ce>J[2]&&(J[2]=ce)}let ee={attributes:{POSITION:f(U.array,"VEC3",34962,5126,U.count,G,J)}};if(k.attributes.normal&&(ee.attributes.NORMAL=f(k.attributes.normal.array,"VEC3",34962,5126,k.attributes.normal.count)),k.attributes.uv&&(ee.attributes.TEXCOORD_0=f(k.attributes.uv.array,"VEC2",34962,5126,k.attributes.uv.count)),k.index){let ue=k.index.array instanceof Uint32Array;ee.indices=f(k.index.array,"SCALAR",34963,ue?5125:5123,k.index.count)}let ie=Array.isArray(s.material)?s.material[0]:s.material;ie&&(ee.material=b(ie));let le=s.userData?.variants;if(le&&typeof le=="object"){let ue=new Map;for(let me of Object.keys(le)){if(!me||me==="__proto__"||me==="constructor"||me==="prototype")continue;let he=le[me];if(!he||typeof he!="object")continue;let ce=u.indexOf(me);if(ce===-1&&u.length<256&&(ce=u.length,u.push(me)),ce===-1)continue;let ge=b(he),ve=ue.get(ge);ve||(ve=[],ue.set(ge,ve)),ve.push(ce)}if(ue.size>0){let me=[];for(let[he,ce]of ue.entries())me.push({material:he,variants:ce});ee.extensions={...ee.extensions||{},KHR_materials_variants:{mappings:me}},c.add("KHR_materials_variants")}}let re=s;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let ue=Math.min(1e4,Math.floor(re.count)),me=re.instanceMatrix.array,he=new Float32Array(ue*3),ce=new Float32Array(ue*4),ge=new Float32Array(ue*3);for(let fe=0;fe<ue;fe++){let{t:Me,r:Se,s:Pe}=Nt(me,fe*16);he[fe*3]=Me[0],he[fe*3+1]=Me[1],he[fe*3+2]=Me[2],ce[fe*4]=Se[0],ce[fe*4+1]=Se[1],ce[fe*4+2]=Se[2],ce[fe*4+3]=Se[3],ge[fe*3]=Pe[0],ge[fe*3+1]=Pe[1],ge[fe*3+2]=Pe[2]}let ve={TRANSLATION:f(he,"VEC3",0,5126,ue),ROTATION:f(ce,"VEC4",0,5126,ue),SCALE:f(ge,"VEC3",0,5126,ue)};if(re.instanceColor?.array&&re.instanceColor.array.length>=ue*3){let fe=new Float32Array(re.instanceColor.array.subarray(0,ue*3));ve._COLOR_0=f(fe,"VEC3",0,5126,ue)}A.extensions={...A.extensions||{},EXT_mesh_gpu_instancing:{attributes:ve}},c.add("EXT_mesh_gpu_instancing")}let de=l.length;l.push({primitives:[ee],name:s.name,...A.extras?{extras:A.extras}:{}}),A.mesh=de}}let Z=o.length;o.push(A),S.push(s),M.push(Z);let Y=s.children;if(Array.isArray(Y)&&Y.length>0){let k=[];A.children=k;for(let U=Y.length-1;U>=0;U--)R.push({obj:Y[U],parentKids:k})}}if(d)for(let s of z){let M=g.length;if(g.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 h=s.dLen>1e-6?s.dx/s.dLen:0,A=s.dLen>1e-6?s.dy/s.dLen:-1,q=s.dLen>1e-6?s.dz/s.dLen:0;s.node.rotation=Bt(h,A,q),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<o.length;s++){let M=o[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||S[s]?.isLOD)&&(M.extensions={...M.extensions||{},MSFT_lod:{ids:[...M.children]}},c.add("MSFT_lod"))}let C=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),$=[];if(typeof C=="function"&&S.length>0){let s=t?.duration??4,M=t?.fps??15,h=Math.max(2,Math.round(s*M)+1),A=new Float32Array(h),q=S.map(H=>[te(H.position?.x,0),te(H.position?.y,0),te(H.position?.z,0),te(H.quaternion?.x,0),te(H.quaternion?.y,0),te(H.quaternion?.z,0),te(H.quaternion?.w,1),te(H.scale?.x,1),te(H.scale?.y,1),te(H.scale?.z,1)]),N=S.map(()=>new Float32Array(h*3)),X=S.map(()=>new Float32Array(h*4)),K=S.map(()=>new Float32Array(h*3));for(let H=0;H<h;H++){let W=H/(h-1)*s;A[H]=W;try{C(W)}catch{}for(let D=0;D<S.length;D++){let Q=S[D];N[D][H*3]=te(Q.position?.x,0),N[D][H*3+1]=te(Q.position?.y,0),N[D][H*3+2]=te(Q.position?.z,0);let Z=te(Q.quaternion?.x,0),Y=te(Q.quaternion?.y,0),k=te(Q.quaternion?.z,0),U=te(Q.quaternion?.w,1),G=Math.hypot(Z,Y,k,U)||1;if(Z/=G,Y/=G,k/=G,U/=G,H>0){let J=(H-1)*4,ee=X[D];ee[J]*Z+ee[J+1]*Y+ee[J+2]*k+ee[J+3]*U<0&&(Z=-Z,Y=-Y,k=-k,U=-U)}X[D][H*4]=Z,X[D][H*4+1]=Y,X[D][H*4+2]=k,X[D][H*4+3]=U,K[D][H*3]=te(Q.scale?.x,1),K[D][H*3+1]=te(Q.scale?.y,1),K[D][H*3+2]=te(Q.scale?.z,1)}}for(let H=0;H<S.length;H++){let W=S[H],D=q[H];W.position?.set(D[0],D[1],D[2]),W.quaternion?.set(D[3],D[4],D[5],D[6]),W.scale?.set(D[7],D[8],D[9])}e.updateMatrixWorld(!0);let ne=null,ae=()=>(ne===null&&(ne=f(A,"SCALAR",0,5126,h,[0],[s])),ne),oe=[],se=[];for(let H=0;H<S.length;H++){let W=q[H],D=(Z,Y,k)=>Z.some((U,G)=>Math.abs(U-W[k+G%Y])>1e-4),Q=(Z,Y,k,U)=>{Z&&se.push({sampler:oe.push({input:ae(),interpolation:"LINEAR",output:f(Y,k,0,5126,h)})-1,target:{node:H,path:U}})};Q(D(N[H],3,0),N[H],"VEC3","translation"),Q(D(X[H],4,3),X[H],"VEC4","rotation"),Q(D(K[H],3,7),K[H],"VEC3","scale")}se.length>0&&$.push({name:"ProceduralLoop",samplers:oe,channels:se})}let B=Rt(o,l,e.userData),y=[],P=[],V=[];for(let s=0;s<o.length;s++){let M=o[s],h=Gt(M.extras?.xr);if(!h)continue;let{ae:A,src:q,preset:N,volume:X,loop:K,isGlobal:ne}=h,ae=M.name||`Node_${s}`,oe=P.length;P.push({name:`${ae}_source`,gain:X,loop:K,autoPlay:typeof A.autoplay=="boolean"?A.autoplay:!0,...q!==void 0?{audio:y.push({uri:q})-1}:{},...N?{extras:{preset:N,pitch:we(A.pitch,.25,4,1)}}:{}});let se=V.length,H=we(A.refDistance,.05,100,1),W=we(A.coneInnerAngle,0,360,360),D=we(A.coneOuterAngle,W,360,360);V.push({name:`${ae}_emitter`,type:ne?"global":"positional",gain:X,sources:[oe],...ne?{}:{positional:{distanceModel:A.distanceModel==="linear"||A.distanceModel==="exponential"?A.distanceModel:"inverse",refDistance:H,maxDistance:we(A.maxDistance,H,500,Math.max(H,25)),rolloffFactor:we(A.rolloffFactor,0,10,1),coneInnerAngle:+(W*Math.PI/180).toFixed(6),coneOuterAngle:+(D*Math.PI/180).toFixed(6),coneOuterGain:we(A.coneOuterGain,0,1,0)}}}),M.extensions={...M.extensions||{},KHR_audio_emitter:{emitter:se}},c.add("KHR_audio_emitter")}let j={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity,...m.length>0?{lights:m}:{}}},scenes:[{nodes:_}],scene:0,nodes:o,meshes:l,materials:p,...E.length>0?{images:E}:{},...I.length>0?{samplers:I}:{},...T.length>0?{textures:T}:{},accessors:a,bufferViews:n,buffers:[{byteLength:r}],...$.length>0?{animations:$}:{},...B||c.size>0?{extensionsUsed:[...B?["KHR_interactivity"]:[],...c]}:{},...B||u.length>0||V.length>0||g.length>0?{extensions:{...B?{KHR_interactivity:B}:{},...u.length>0?{KHR_materials_variants:{variants:u.map(s=>({name:s}))}}:{},...V.length>0?{KHR_audio_emitter:{...y.length>0?{audio:y}:{},sources:P,emitters:V}}:{},...g.length>0?{KHR_lights_punctual:{lights:g}}:{}}}:{}},v=new Uint8Array(r),O=0;for(let s of i)v.set(s,O),O+=s.byteLength;return[{gltf:j,bin:v.buffer,lights:m,environmentIntensity:e.environmentIntensity},S]}function Ot(e){return new TextEncoder().encode(e)}function pn(e,t){let[i,r]=dn(e,t);return mt(i,r)}function mt(e,t){let i=[],r=e.gltf,n=Ae().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),o=r.accessors||[],c=r.bufferViews||[],S=r.materials||[],p=r.meshes||[],x=r.nodes||[],E=r.textures||[],I=r.images||[],T=r.samplers||[],F=new Set,u=S.map((_,L)=>ct(F,ke(_?.name,`Material_${L}`))),m=new Map;function g(_){let L=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(_);if(!L)return null;let R=L[2].replace(/\s+/g,""),C=R.endsWith("==")?2:R.endsWith("=")?1:0,$=new Uint8Array((R.length*3>>2)-C),B=P=>{let V=R.charCodeAt(P);return V>96?V-71:V>64?V-65:V>47?V+4:V===43?62:V===47?63:0},y=0;for(let P=0;P<R.length;P+=4){let V=B(P)<<18|B(P+1)<<12|B(P+2)<<6|B(P+3);$[y++]=V>>16&255,y<$.length&&($[y++]=V>>8&255),y<$.length&&($[y++]=V&255)}return $}function d(_,L,R){let C=_?.index;if(typeof C!="number")return;let $=E[C],B=$?.source;if(typeof B!="number"||!I[B])return;let y=m.get(B);if(y===void 0){y=null;let j=I[B],v=null;if(typeof j.bufferView=="number"){let O=c[j.bufferView],s=O?.byteOffset||0,M=O?.byteLength||0;O&&M>0&&s>=0&&s+M<=l.byteLength&&(v=new Uint8Array(l,s,M))}else typeof j.uri=="string"&&(v=g(j.uri));if(v&&v.byteLength>0){let O=v[0]===255&&v[1]===216&&v[2]===255||!(v[0]===137&&v[1]===80)&&/jpe?g/i.test(j.mimeType||j.uri||"");y={file:`texture_${B}.${O?"jpg":"png"}`,data:v}}m.set(B,y)}if(!y)return;let P=typeof $.sampler=="number"?T[$.sampler]:void 0,V=j=>j===33071?"clamp":j===33648?"mirror":"repeat";return{file:y.file,data:y.data,wrapS:V(P?.wrapS),wrapT:V(P?.wrapT),...L?{scale:L}:{},...R?{bias:R}:{}}}function b(_){let L=o[_];if(!L)throw new Error(`Accessor ${_} not found`);let R=c[L.bufferView||0],C=(R.byteOffset||0)+(L.byteOffset||0),$=R.byteLength||0;return{acc:L,buffer:l.slice(C,C+$)}}function w(_,L,R,C){let $=[],B=p[_];if(!B)return $;let y=B.primitives||[];for(let P=0;P<y.length;P++){let V=y[P],j=V.attributes?.POSITION;if(j===void 0)continue;let{acc:v,buffer:O}=b(j),s=new Float32Array(O,0,v.count*3),M,h=V.attributes?.NORMAL;if(h!==void 0){let{acc:Y,buffer:k}=b(h),U=new Float32Array(k,0,Y.count*3);M=new Float32Array(U.length);for(let G=0;G<Y.count;G++){let J=U[G*3],ee=U[G*3+1],ie=U[G*3+2],le=Math.hypot(J,ee,ie)||1;M[G*3]=J/le,M[G*3+1]=ee/le,M[G*3+2]=ie/le}}let A,q=V.attributes?.TEXCOORD_0;if(q!==void 0){let{acc:Y,buffer:k}=b(q);A=new Float32Array(k,0,Y.count*2)}let N;if(V.indices!==void 0){let{acc:Y,buffer:k}=b(V.indices);N=Y.componentType===5125?new Uint32Array(k,0,Y.count):new Uint16Array(k,0,Y.count);let U=v.count;for(let G of N)if(G>=U)throw new Error(`SecurityError: Index buffer value (${G}) out of vertex bounds [0, ${U}).`)}else{let Y=v.count;N=Y>65535?new Uint32Array(Y):new Uint16Array(Y);for(let k=0;k<Y;k++)N[k]=k}let X="DefaultMaterial",K=[1,1,1],ne=.5,ae=0,oe=0,se=0,H=1.5,W=1,D=[0,0,0],Q,Z={};if(V.material!==void 0&&S[V.material]){let Y=S[V.material];X=u[V.material]||`Material_${V.material}`;let k=Y.pbrMetallicRoughness||{},U=(fe,Me)=>Array.isArray(fe)&&fe.length>=3?[fe[0],fe[1],fe[2]]:Me;K=U(k.baseColorFactor,[1,1,1]);let G=Array.isArray(k.baseColorFactor)&&typeof k.baseColorFactor[3]=="number"?k.baseColorFactor[3]:1,J=K[0]!==1||K[1]!==1||K[2]!==1||G!==1,ee=d(k.baseColorTexture,J?[K[0],K[1],K[2],G]:void 0),ie=Y.extras?.avgColor;!ee&&Array.isArray(ie)&&ie.length>=3&&(K=[K[0]*ie[0],K[1]*ie[1],K[2]*ie[2]]),typeof k.roughnessFactor=="number"&&(ne=k.roughnessFactor),typeof k.metallicFactor=="number"&&(ae=k.metallicFactor);let le=typeof k.roughnessFactor=="number"?k.roughnessFactor:1,re=typeof k.metallicFactor=="number"?k.metallicFactor:1,de=d(k.metallicRoughnessTexture,le!==1||re!==1?[1,le,re,1]:void 0);D=U(Y.emissiveFactor,[0,0,0]);let ue=(D[0]>0||D[1]>0||D[2]>0)&&(D[0]!==1||D[1]!==1||D[2]!==1)?[D[0],D[1],D[2],1]:void 0,me=d(Y.emissiveTexture,ue),he=typeof Y.normalTexture?.scale=="number"?Y.normalTexture.scale:1,ce=d(Y.normalTexture,[2*he,2*he,2,1],[-he,-he,-1,0]),ge=typeof Y.occlusionTexture?.strength=="number"?Y.occlusionTexture.strength:1,ve=ge!==1?d(Y.occlusionTexture,[ge,ge,ge,1],[1-ge,1-ge,1-ge,0]):d(Y.occlusionTexture);(ee||de||ce||me||ve)&&(Q=[ee,de,ce,me,ve]),Z=Y.extensions||{},Z.KHR_materials_clearcoat&&(oe=Z.KHR_materials_clearcoat.clearcoatFactor??0,se=Z.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof Z.KHR_materials_ior?.ior=="number"&&(H=Z.KHR_materials_ior.ior),W=G*(1-(Z.KHR_materials_transmission?.transmissionFactor??0))}$.push({name:y.length>1?`${L}_p${P}`:L,positions:s,indices:N,normals:M,uvs:A,materialName:X,color:K,roughness:ne,metallic:ae,clearcoat:oe,clearcoatRoughness:se,ior:H,opacity:W,emissiveColor:D,...Q?{textures:Q}:{},...Z.GOOGLE_material_tsl?{tslGraph:Z.GOOGLE_material_tsl}:{},xrTraits:R||B.extras?.xr,...C?{invisible:!0}:{}})}return $}if(x.length>0){let _=new Float32Array(0),L=new Uint16Array(0),R=(s,M)=>{if(s===void 0)return null;let{acc:h,buffer:A}=b(s);return new Float32Array(A,0,h.count*M)},C=(s,M)=>Array.isArray(s)&&s.length>=3?[te(s[0],M),te(s[1],M),te(s[2],M)]:[M,M,M],$=(s,M,h)=>s&&s.length>=(M+1)*3?[s[M*3],s[M*3+1],s[M*3+2]]:h,B=(s,M,h)=>s&&s.length>=(M+1)*4?[s[M*4],s[M*4+1],s[M*4+2],s[M*4+3]]:h,y=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],h=s?.target?.node,A=s?.target?.path;if(!M||typeof h!="number"||M.input===void 0)continue;let q=y.get(h);q||(q={input:M.input},y.set(h,q)),A==="translation"?q.t=M.output:A==="rotation"?q.r=M.output:A==="scale"&&(q.s=M.output)}let V=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(V)||V.length===0){let s=new Set;for(let M of x)if(Array.isArray(M?.children))for(let h of M.children)s.add(h);V=[];for(let M=0;M<x.length;M++)s.has(M)||V.push(M);V.length===0&&(V=[0])}let j=new Set,v=[],O=(s,M)=>{if(Array.isArray(s))for(let h=s.length-1;h>=0;h--)v.push({idx:s[h],out:M})};for(O(V,i);v.length>0;){let{idx:s,out:M}=v.pop();if(typeof s!="number"||s<0||s>=x.length||j.has(s))continue;j.add(s);let h=x[s];if(!h)continue;let A=[0,0,0],q=[0,0,0,1],N=[1,1,1];if(Array.isArray(h.matrix)&&h.matrix.length===16){let W=Nt(h.matrix);A=W.t,q=W.r,N=W.s}else A=C(h.translation,0),Array.isArray(h.rotation)&&h.rotation.length>=4&&(q=[te(h.rotation[0],0),te(h.rotation[1],0),te(h.rotation[2],0),te(h.rotation[3],1)]),N=C(h.scale,1);let X,K=y.get(s);if(K){let W=R(K.input,1);if(W&&W.length>0){let D=R(K.t,3),Q=R(K.r,4),Z=R(K.s,3),Y=Array.from(W),k=[],U=[],G=[];for(let J=0;J<W.length;J++)k.push($(D,J,A)),U.push(B(Q,J,q)),G.push($(Z,J,N));X={times:Y,translations:k,rotations:U,scales:G}}}let ne=Array.isArray(h.children)?h.children:[],ae=typeof h.mesh=="number"&&h.mesh>=0&&h.mesh<p.length,oe=t?.[s]?.userData?.xr??h.extras?.xr;if(!ae&&ne.length===0&&(h.camera!==void 0||h.extensions?.KHR_lights_punctual||!h.name&&!h.extras&&!oe&&!X))continue;let se=(W,D,Q)=>({name:W,positions:_,indices:L,isXform:!0,xrTraits:oe,timeSamples:X,translation:A,rotation:q,scale:N,children:D,...Q?{invisible:!0}:{}}),H=h.visible===!1||h.extensions?.KHR_node_visibility?.visible===!1||t?.[s]?.visible===!1;if(ae){let W=h.name||p[h.mesh]?.name||`Mesh_${s}`,D=w(h.mesh,W,oe,H),Q=t?.[s],Z=!!(Q?._castShdSet||Q?._recvShdSet),Y=typeof h.extras?.shadow?.cast=="boolean"?h.extras.shadow.cast:Z?!!Q?.castShadow:void 0;if(Y!==void 0)for(let U of D)U.castShadow=Y;let k=h.extensions?.EXT_mesh_gpu_instancing?.attributes;if(k&&typeof k=="object"&&D.length>0){let U=R(k.TRANSLATION,3),G=R(k.ROTATION,4),J=R(k.SCALE,3),ee=R(k._COLOR_0,3),ie=Math.min(1e3,U?U.length/3:G?G.length/4:J?J.length/3:0);if(ie>0){let le=[];for(let re=0;re<ie;re++){let de=$(U,re,[0,0,0]),ue=B(G,re,[0,0,0,1]),me=$(J,re,[1,1,1]);for(let he of D){let ce=he.color||[.8,.8,.8],ge=ee&&ee.length>=(re+1)*3;le.push({...he,name:`${he.name}_${re}`,materialName:ge?`${he.materialName}_inst_${re}`:he.materialName,color:ge?[ce[0]*ee[re*3],ce[1]*ee[re*3+1],ce[2]*ee[re*3+2]]:he.color,translation:de,rotation:ue,scale:me})}}O(ne,le),M.push(se(W,le,H));continue}}if(D.length===1)D[0].translation=A,D[0].rotation=q,D[0].scale=N,D[0].timeSamples=X,ne.length>0&&(D[0].children=[],O(ne,D[0].children)),M.push(D[0]);else{let U=[...D];O(ne,U),M.push(se(W,U,H))}}else{let W=[];O(ne,W),M.push(se(h.name||`Group_${s}`,W,H))}}}else for(let _=0;_<p.length;_++){let L=p[_].name||`Mesh_${_}`;i.push(...w(_,L,p[_].extras?.xr))}let f=(Array.isArray(e.lights)&&e.lights.length>0?e.lights:void 0)??ut(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),z=[];for(let _=0;_<f.length;_++){let L=f[_];L?.shadow?.cast&&(L.type==="directional"||L.type==="spot"||L.type==="point")&&z.push({name:`Light_${_}`,type:L.type,color:L.color,intensity:L.intensity,position:L.position,direction:L.direction,range:L.range,innerConeAngle:L.innerConeAngle,outerConeAngle:L.outerConeAngle,shadow:L.shadow})}return z.length>0&&(i.__usdaShadowLights=z),i}function ke(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 ze(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function be(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)=>`(${be(e)}, ${be(t)}, ${be(i)})`,Ie=(e,t,i,r)=>`(${be(e)}, ${be(t)}, ${be(i)}, ${be(r)})`;function Ut(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 bn(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${be(e[r*2])}, ${be(1-e[r*2+1])})`;return i.join(", ")}function gn(e){return Array.from(e).join(", ")}function lt(e,t){let i=(t??e.__usdaShadowLights??[]).filter(u=>u?.shadow?.cast),r=new Map,n=0,a=null,l=[...e];for(;l.length>0;){let u=l.pop();if(!u.isXform&&u.positions&&u.positions.length>0){let m=ke(u.materialName,"DefaultMaterial");r.has(m)||r.set(m,{color:u.color||[1,1,1],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0],textures:u.textures,tslGraph:u.tslGraph})}if(u.timeSamples&&u.timeSamples.times.length>0){let m=u.timeSamples.times[u.timeSamples.times.length-1];m>n&&(n=m)}else u.tslGraph&&n<=0&&JSON.stringify(u.tslGraph).includes('"time"')&&(n=60);if(u.xrTraits?.anchor&&!a&&(a=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal"),u.children)for(let m=u.children.length-1;m>=0;m--)l.push(u.children[m])}let o="";n>0&&(o=`startTimeCode = 0
|
|
215
|
+
endTimeCode = ${be(n)}
|
|
251
216
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let c="";
|
|
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 S=`#usda 1.0
|
|
255
220
|
(
|
|
256
221
|
defaultPrim = "Root"
|
|
257
222
|
metersPerUnit = 1.0
|
|
258
223
|
upAxis = "Y"
|
|
259
|
-
${
|
|
224
|
+
${o})
|
|
260
225
|
|
|
261
226
|
def Xform "Root" (
|
|
262
227
|
kind = "component"
|
|
@@ -264,105 +229,122 @@ kind = "component"
|
|
|
264
229
|
{
|
|
265
230
|
${c}def Scope "Materials"
|
|
266
231
|
{
|
|
267
|
-
`;for(let[u,
|
|
268
|
-
float inputs:roughness${
|
|
269
|
-
float inputs:roughness = ${
|
|
270
|
-
`,
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
273
|
-
`)
|
|
274
|
-
`:(
|
|
275
|
-
`),
|
|
276
|
-
`),
|
|
277
|
-
`);let
|
|
232
|
+
`;for(let[u,m]of r.entries()){let[g,d,b]=m.color,[w,f,z]=m.emissiveColor,_=`/Root/Materials/${u}`,[L,R,C,$,B]=m.textures||[],y=(M,h)=>`.connect = <${_}/${M}.outputs:${h}>`,P=L?`color3f inputs:diffuseColor${y("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Te(g,d,b)}`,V=R?`float inputs:metallic${y("MetallicRoughnessTexture","b")}
|
|
233
|
+
float inputs:roughness${y("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${be(m.metallic)}
|
|
234
|
+
float inputs:roughness = ${be(m.roughness)}`,j="";m.clearcoat>0&&(j+=`float inputs:clearcoat = ${be(m.clearcoat)}
|
|
235
|
+
`,j+=`float inputs:clearcoatRoughness = ${be(m.clearcoatRoughness)}
|
|
236
|
+
`),m.ior!==1.5&&(j+=`float inputs:ior = ${be(m.ior)}
|
|
237
|
+
`),m.opacity<1&&(j+=`float inputs:opacity = ${be(m.opacity)}
|
|
238
|
+
`),$?j+=`color3f inputs:emissiveColor${y("EmissiveTexture","rgb")}
|
|
239
|
+
`:(w>0||f>0||z>0)&&(j+=`color3f inputs:emissiveColor = ${Te(w,f,z)}
|
|
240
|
+
`),C&&(j+=`normal3f inputs:normal${y("NormalTexture","rgb")}
|
|
241
|
+
`),B&&(j+=`float inputs:occlusion${y("OcclusionTexture","r")}
|
|
242
|
+
`);let v="";if(L||R||C||$||B){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=(h,A,q,N)=>{if(!A)return;let X=A.scale?`float4 inputs:scale = ${Ie(A.scale[0],A.scale[1],A.scale[2],A.scale[3])}
|
|
249
|
+
`:"",K=A.bias?`float4 inputs:bias = ${Ie(A.bias[0],A.bias[1],A.bias[2],A.bias[3])}
|
|
250
|
+
`:"";v+=`def Shader "${h}"
|
|
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 = @${ze(A.file)}@
|
|
254
|
+
float2 inputs:st${y("PrimvarReader","result")}
|
|
255
|
+
token inputs:sourceColorSpace = "${q}"
|
|
256
|
+
token inputs:wrapS = "${A.wrapS||"repeat"}"
|
|
257
|
+
token inputs:wrapT = "${A.wrapT||"repeat"}"
|
|
258
|
+
${X}${K}${N}}
|
|
259
|
+
`};M("DiffuseTexture",L,"sRGB",`float3 outputs:rgb
|
|
260
|
+
`),M("MetallicRoughnessTexture",R,"raw",`float outputs:g
|
|
296
261
|
float outputs:b
|
|
297
|
-
`),
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`)}
|
|
262
|
+
`),M("NormalTexture",C,"raw",`float3 outputs:rgb
|
|
263
|
+
`),M("EmissiveTexture",$,"sRGB",`float3 outputs:rgb
|
|
264
|
+
`),M("OcclusionTexture",B,"raw",`float outputs:r
|
|
265
|
+
`)}let O=`${P}
|
|
266
|
+
${V}
|
|
267
|
+
${j}`,s=m.tslGraph&&Ae().tslUsdzSerializer?.(m.tslGraph,u,O);s&&(O=s.surfaceInputsUsda||O,v+=s.nodeGraphUsda),S+=`def Material "${u}"
|
|
301
268
|
{
|
|
302
269
|
def Shader "PBRShader"
|
|
303
270
|
{
|
|
304
271
|
uniform token info:id = "UsdPreviewSurface"
|
|
305
|
-
${
|
|
306
|
-
${o}
|
|
307
|
-
${V}token outputs:surface
|
|
272
|
+
${O}token outputs:surface
|
|
308
273
|
}
|
|
309
|
-
token outputs:surface${
|
|
310
|
-
${
|
|
311
|
-
`}
|
|
274
|
+
token outputs:surface${y("PBRShader","surface")}
|
|
275
|
+
${v}}
|
|
276
|
+
`}S+=`}
|
|
312
277
|
def Scope "Meshes"
|
|
313
278
|
{
|
|
314
|
-
`;let
|
|
279
|
+
`;let p=(u,m,g)=>{let d=[];m&&d.push('"MaterialBindingAPI"');let b=!!(u?.rigidBody&&u.rigidBody!=="none"&&(typeof u.rigidBody!="object"||u.rigidBody.enabled!==!1)),w=!!(u?.physics&&u.physics!=="none"||b);w&&d.push(...b?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let f=[];d.length>0&&f.push(`prepend apiSchemas = [${d.join(", ")}]`);let z=Ae().xrTraitSerializer;if(u){let $=z?.usdLines(u,ze)??[];if(!$.length)for(let B of["grab","billboard","follow","anchor","physics"]){let y=B==="follow"&&typeof u.follow=="object"?u.follow.mode??"head":u[B];y!==void 0&&$.push(`string ${B} = "${ze(y)}"`)}$.length>0&&f.push(`customData = {
|
|
315
280
|
dictionary xr = {
|
|
316
|
-
${
|
|
281
|
+
${$.join(`
|
|
317
282
|
`)}
|
|
318
283
|
}
|
|
319
|
-
}`)}let
|
|
320
|
-
${
|
|
284
|
+
}`)}let _=f.length>0?` (
|
|
285
|
+
${f.join(`
|
|
321
286
|
`)}
|
|
322
|
-
)`:"",
|
|
323
|
-
`:"";if(
|
|
324
|
-
bool physics:kinematicEnabled = ${
|
|
287
|
+
)`:"",L=g?`uniform token visibility = "invisible"
|
|
288
|
+
`:"";if(w){let $=u?.rigidBody??u?.physics,B=$?.body??$?.mode??$;L+=`bool physics:rigidBodyEnabled = true
|
|
289
|
+
bool physics:kinematicEnabled = ${B==="static"||B==="kinematic"}
|
|
325
290
|
bool physics:collisionEnabled = true
|
|
326
|
-
|
|
327
|
-
`)}let
|
|
291
|
+
`,$?.mass>0&&Number.isFinite($.mass)&&(L+=`float physics:mass = ${be($.mass)}
|
|
292
|
+
`)}let R=Gt(u),C=(R?`def SpatialAudio "AudioEmitter"
|
|
328
293
|
{
|
|
329
|
-
${
|
|
330
|
-
`:""}uniform token inputs:auralMode = "${
|
|
331
|
-
uniform token inputs:playbackMode = "${
|
|
332
|
-
double gain = ${
|
|
294
|
+
${R.src?`asset inputs:file = @${ze(R.src)}@
|
|
295
|
+
`:""}uniform token inputs:auralMode = "${R.isGlobal?"nonSpatial":"spatial"}"
|
|
296
|
+
uniform token inputs:playbackMode = "${R.loop?"loopFromStart":"onceFromStart"}"
|
|
297
|
+
double gain = ${be(R.volume)}
|
|
333
298
|
}
|
|
334
|
-
`:"";return{header:
|
|
335
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
336
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
299
|
+
`:"")+(u?z?.usdPrims?.(u)??"":"");return{header:_,body:L,tail:C}},x=u=>{if(u.timeSamples&&u.timeSamples.times.length>0){let f=u.timeSamples,z=(C,$,B)=>f.times.map((y,P)=>`${be(y)}: ${B(C?.[P]||$)}`).join(", "),_=z(f.translations,[0,0,0],C=>Te(C[0],C[1],C[2])),L=z(f.rotations,[0,0,0,1],C=>{let $=Math.hypot(C[0],C[1],C[2],C[3])||1;return Ie(C[3]/$,C[0]/$,C[1]/$,C[2]/$)}),R=z(f.scales,[1,1,1],C=>Te(C[0],C[1],C[2]));return`double3 xformOp:translate.timeSamples = { ${_} }
|
|
300
|
+
quatf xformOp:orient.timeSamples = { ${L} }
|
|
301
|
+
double3 xformOp:scale.timeSamples = { ${R} }
|
|
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 u.normals&&u.normals.length===u.positions.length&&(
|
|
303
|
+
`}let m=[],g="",d=u.translation;d&&(Math.abs(d[0])>1e-7||Math.abs(d[1])>1e-7||Math.abs(d[2])>1e-7)&&(g+=`double3 xformOp:translate = ${Te(d[0],d[1],d[2])}
|
|
304
|
+
`,m.push('"xformOp:translate"'));let b=u.rotation;if(b){let f=Math.hypot(b[0],b[1],b[2],b[3])||1,z=b[0]/f,_=b[1]/f,L=b[2]/f,R=b[3]/f;(1-Math.abs(R)>1e-7||Math.hypot(z,_,L)>1e-7)&&(g+=`quatf xformOp:orient = ${Ie(R,z,_,L)}
|
|
305
|
+
`,m.push('"xformOp:orient"'))}let w=u.scale;return w&&(Math.abs(w[0]-1)>1e-7||Math.abs(w[1]-1)>1e-7||Math.abs(w[2]-1)>1e-7)&&(g+=`float3 xformOp:scale = ${Te(w[0],w[1],w[2])}
|
|
306
|
+
`,m.push('"xformOp:scale"')),m.length>0&&(g+=`uniform token[] xformOpOrder = [${m.join(", ")}]
|
|
307
|
+
`),g},E=u=>{let m=u.positions.length/3,g=1/0,d=1/0,b=1/0,w=-1/0,f=-1/0,z=-1/0;for(let $=0;$<m;$++){let B=u.positions[$*3],y=u.positions[$*3+1],P=u.positions[$*3+2];B<g&&(g=B),B>w&&(w=B),y<d&&(d=y),y>f&&(f=y),P<b&&(b=P),P>z&&(z=P)}isFinite(g)||(g=d=b=-1,w=f=z=1);let _=Math.floor(u.indices.length/3),L=ke(u.materialName,"DefaultMaterial"),R=_>0?_===1?"3":"3, ".repeat(_-1)+"3":"",C=`float3[] extent = [${Te(g,d,b)}, ${Te(w,f,z)}]
|
|
308
|
+
int[] faceVertexCounts = [${R}]
|
|
309
|
+
int[] faceVertexIndices = [${gn(u.indices)}]
|
|
310
|
+
point3f[] points = [${Ut(u.positions)}]
|
|
311
|
+
`;return u.normals&&u.normals.length===u.positions.length&&(C+=`normal3f[] normals = [${Ut(u.normals)}] (
|
|
347
312
|
interpolation = "vertex"
|
|
348
313
|
)
|
|
349
|
-
`),u.uvs&&u.uvs.length===
|
|
314
|
+
`),u.uvs&&u.uvs.length===m*2&&(C+=`texCoord2f[] primvars:st = [${bn(u.uvs,m)}] (
|
|
350
315
|
interpolation = "vertex"
|
|
351
316
|
)
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
|
|
317
|
+
`),C+=`rel material:binding = </Root/Materials/${L}>
|
|
318
|
+
`,u.castShadow===!1&&i.length>0&&(C+=`bool primvars:doNotCastShadows = 1
|
|
319
|
+
`),C},I=new Set,T=[];for(let u=e.length-1;u>=0;u--)T.push({node:e[u],siblings:I});let F=0;for(;T.length>0;){let u=T.pop();if(u.close){S+=`}
|
|
320
|
+
`;continue}let{node:m,siblings:g}=u,d=!!(m.isXform||m.positions.length===0),b=ct(g,ke(m.name,d?`Group_${F}`:`Mesh_${F}`));F++;let w=m.children||[];if(d){let f=p(m.xrTraits,!1,m.invisible);S+=`def Xform "${b}"${f.header}
|
|
355
321
|
{
|
|
356
|
-
${
|
|
322
|
+
${f.body}${x(m)}${f.tail}`,T.push({close:!0});let z=new Set;for(let _=w.length-1;_>=0;_--)T.push({node:w[_],siblings:z})}else if(w.length>0){let f=p(m.xrTraits,!1,m.invisible),z=`${b}_mesh`;S+=`def Xform "${b}"${f.header}
|
|
357
323
|
{
|
|
358
|
-
${
|
|
324
|
+
${f.body}${x(m)}${f.tail}`,S+=`def Mesh "${z}" (
|
|
359
325
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
360
326
|
)
|
|
361
327
|
{
|
|
362
|
-
${
|
|
363
|
-
`,
|
|
328
|
+
${E(m)}}
|
|
329
|
+
`,T.push({close:!0});let _=new Set([z]);for(let L=w.length-1;L>=0;L--)T.push({node:w[L],siblings:_})}else{let f=p(m.xrTraits,!0,m.invisible);S+=`def Mesh "${b}"${f.header}
|
|
364
330
|
{
|
|
365
|
-
${
|
|
366
|
-
`}}
|
|
367
|
-
|
|
368
|
-
`,l}function Dt(e,t){if(e&&typeof e.traverse=="function"){let a=en(e,t);return qe(a)}let i=Se(e),r=Ke(i);return qe(r)}var ke=null;function Ye(e){if(!ke){ke=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let a=0;a<8;a++)r=r&1?3988292384^r>>>1:r>>>1;ke[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=ke[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function Ze(e){let t=[],i=0,r=[];for(let v of e){let M=Lt(v.filename),I=Ye(v.data),D=v.data.length,u=30+M.length,x=(i+u)%64,C=x!==0?64-x:0;C>0&&C<4&&(C+=64);let R=new Uint8Array(u+C),T=new DataView(R.buffer);T.setUint32(0,67324752,!0),T.setUint16(4,20,!0),T.setUint32(14,I,!0),T.setUint32(18,D,!0),T.setUint32(22,D,!0),T.setUint16(26,M.length,!0),T.setUint16(28,C,!0),R.set(M,30),C>=4&&(T.setUint16(u,6534,!0),T.setUint16(u+2,C-4,!0)),t.push({offset:i,size:D,crc:I,filenameBytes:M,entry:v}),r.push(R,v.data),i+=R.length+v.data.length}let a=i;for(let v of t){let M=new Uint8Array(46+v.filenameBytes.length),I=new DataView(M.buffer);I.setUint32(0,33639248,!0),I.setUint16(4,20,!0),I.setUint16(6,20,!0),I.setUint32(16,v.crc,!0),I.setUint32(20,v.size,!0),I.setUint32(24,v.size,!0),I.setUint16(28,v.filenameBytes.length,!0),I.setUint32(42,v.offset,!0),M.set(v.filenameBytes,46),r.push(M),i+=M.length}let s=i-a,c=new Uint8Array(22),l=new DataView(c.buffer);l.setUint32(0,101010256,!0),l.setUint16(8,t.length,!0),l.setUint16(10,t.length,!0),l.setUint32(12,s,!0),l.setUint32(16,a,!0),r.push(c),i+=22;let g=new Uint8Array(i),d=0;for(let v of r)g.set(v,d),d+=v.length;return g}function rn(e){let t=[{filename:"model.usda",data:Lt(qe(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let a=r.pop();for(let s of a.textures||[])s?.file&&s.data?.byteLength&&!i.has(s.file)&&(i.add(s.file),t.push({filename:s.file,data:s.data}));if(a.children)for(let s=a.children.length-1;s>=0;s--)r.push(a.children[s])}return Ze(t)}function Qe(e){return rn(Ke(Se(e)))}function Je(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Qe(e)}function et(e){let t=Je(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function nt(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let t=document.createElement("a");return t.relList!==void 0&&t.relList.supports!==void 0&&t.relList.supports("ar")}function rt(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function it(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function on(){let e=[];return await it()&&e.push("webxr"),nt()&&e.push("quick-look"),rt()&&e.push("scene-viewer"),e}async function an(){return(await st()).bestMode}async function st(){let[e,t,i]=await Promise.all([it(),Promise.resolve(nt()),Promise.resolve(rt())]),r=[];t&&r.push("quick-look"),e&&r.push("webxr"),i&&r.push("scene-viewer");let a=null;return t?a="quick-look":e?a="webxr":i&&(a="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:i,availableModes:r,bestMode:a}}function tt(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let i,r=!1;if(typeof e=="string"){if(i=un(e),!i)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else i=URL.createObjectURL(e),r=!0;let a=[];if(t.allowScale===!1&&a.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let l=Ne(t.canonicalWebPageUrl,!1);l&&a.push(`canonicalWebPageURL=${encodeURIComponent(l)}`)}t.checkoutTitle&&a.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&a.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&a.push(`price=${encodeURIComponent(t.price)}`),a.length>0&&(i+=`#${a.join("&")}`);let s=document.createElement("a");s.setAttribute("rel","ar"),s.setAttribute("href",i);let c=document.createElement("img");c.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),c.style.display="none",s.appendChild(c),document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s),r&&URL.revokeObjectURL(i.split("#")[0])},3e3)}function Ne(e,t=!1){if(typeof e!="string")return"";let i=e.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!i)return"";if(/^[\\/]{2}/.test(i))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${i.slice(0,32)}`);let r=i.toLowerCase();if(r.startsWith("https://")||r.startsWith("http://")||t&&r.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(i))return i;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${i.slice(0,32)}`)}function un(e){try{return Ne(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function Ct(e,t={}){let i=Ne(e,!0),r=t.mode||"ar_preferred",a=new URLSearchParams({file:i,mode:r,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&a.set("title",t.title),t.link&&a.set("link",Ne(t.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${a.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function Ft(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let i=Ct(e,t);window.location.href=i}var Ae=null;function cn(e,t){let i=new Float32Array(144),r=new Float32Array(144),a=new Float32Array(96),s=new Uint16Array(144);for(let v=0;v<24;v++){let M=v/24*Math.PI*2,I=Math.cos(M),D=Math.sin(M),u=v*2,x=u+1,C=(v+1)%24*2;i[u*3]=I*.11,i[u*3+1]=.002,i[u*3+2]=D*.11,i[x*3]=I*.145,i[x*3+1]=.002,i[x*3+2]=D*.145,r[u*3+1]=r[x*3+1]=1,s.set([u,C,x,x,C,C+1],v*6)}let c=e.createVertexArray();e.bindVertexArray(c);let l=(v,M,I)=>{let D=e.createBuffer();return e.bindBuffer(34962,D),e.bufferData(34962,v,35044),e.enableVertexAttribArray(M),e.vertexAttribPointer(M,I,5126,!1,0,0),D},g=[l(i,0,3),l(r,1,3),l(a,2,2)],d=e.createBuffer();return g.push(d),e.bindBuffer(34963,d),e.bufferData(34963,s,35044),e.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:c,indexCount:s.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:i,indices:s,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:g}]}}function Pt(e,t,i,r,a){let s=Math.cos(r),c=Math.sin(r),l=Math.max(.01,a);e.fill(0),e[0]=l*s,e[2]=-l*c,e[5]=l,e[8]=l*c,e[10]=l*s,e[12]=t[0]-l*(s*i[0]+c*i[2]),e[13]=t[1]-l*i[1],e[14]=t[2]-l*(-c*i[0]+s*i[2]),e[15]=1}var Be=class{constructor(e={}){this.s=null,this.placed=!1,this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.cleanFn=null,this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,t){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");Ae&&Ae!==this&&Ae.isSessionActive()&&await Ae.stop().catch(()=>{});let i=navigator.xr,r=this.opts,a=t||e?.container,s=String(a?.tagName||"").toLowerCase()==="xr-live",c=e?.bounds,l=Number(c?.radius)||1,g=Array.isArray(c?.center)?c.center:[0,0,0],d=Array.isArray(c?.min)?c.min:[-.5,-.5,-.5],v=typeof navigator<"u"&&navigator.userAgent||"",M=/Android|iPhone|iPad|iPod/i.test(v)&&!/Quest|Oculus|Pico|Vision/i.test(v),I=s?r.arScale==="fixed"?1:M?.55:1:r.arScale==="fixed"?1:l>.45?.3/l:l<.05?.12/Math.max(l,.001):1,D=s?[0,-.25,0]:[g[0]||0,r.arPlacement==="wall"?g[1]:d[1]??0,g[2]||0],u="immersive-ar";try{await i.isSessionSupported("immersive-ar")||(u="immersive-vr")}catch{u="immersive-vr"}let x=a?.querySelector?.('[slot="ar-overlay"]')||null,C=!1,R=null,T=()=>{C&&x?.parentNode&&x.parentNode.removeChild(x),x=null,R=null,C=!1};if(u==="immersive-ar"){if(x)x.addEventListener?.("beforexrselect",L=>L.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let L=document.createElement("div");L.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let X=document.createElement("button");X.type="button",X.textContent="\u2715 Exit AR",X.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",X.addEventListener("beforexrselect",J=>J.preventDefault()),X.addEventListener("click",J=>{J.stopPropagation(),this.stop().catch(()=>{})}),R=document.createElement("div"),R.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",R.textContent="Move phone to detect a surface \u2022 Tap to place",L.appendChild(X),L.appendChild(R),document.body.appendChild(L),x=L,C=!0}}let m=new Set(r.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),h={requiredFeatures:r.requiredFeatures?[...r.requiredFeatures]:[],optionalFeatures:Array.from(m)};x&&(m.add("dom-overlay"),h.optionalFeatures=Array.from(m),h.domOverlay={root:x});for(let L of ce)L.onConfigureXRSessionInit?.(a,h);Array.isArray(h.optionalFeatures)&&h.optionalFeatures.includes("dom-overlay")&&!h.domOverlay?.root&&(h.optionalFeatures=h.optionalFeatures.filter(L=>L!=="dom-overlay"));let w=L=>{let X=String(L?.name||"");return X==="NotAllowedError"||X==="SecurityError"};try{this.s=await i.requestSession(u,h)}catch(L){if(T(),w(L))throw r.onError?.(L),L;try{this.s=await i.requestSession(u,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(X){if(w(X))throw r.onError?.(X),X;try{this.s=await i.requestSession(u)}catch(J){throw r.onError?.(J),J}}}let y=this.s;Ae=this,this.placed=!1;let F=null,U=null,_=null,k=null,P=null,N=[0,-.25,-1.2],S=[0,-.25,-1.2],o=new Float32Array(16),V=new Float32Array(16),K=!1,f=1,b=0,n=!1,p=null,B=null,z=0,j=null,ee=()=>{Ae===this&&(Ae=null),j?.(),j=null;try{U?.cancel?.()}catch{}if(U=null,_){let L=e?.meshes;if(Array.isArray(L)){let J=L.indexOf(_);J!==-1&&L.splice(J,1)}let X=e.getGLContext?.()||e?.gl;if(X)for(let J of _.primitives||[]){X.deleteVertexArray?.(J.vao);for(let re of J.buffers||[])X.deleteBuffer?.(re)}_=null}e?.setXRSessionActive?.(!1),T(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=ee,y.addEventListener("end",()=>{ee(),r.onExit?.()}),y.addEventListener("select",()=>{if(!this.placed){let L=P||N;S=[L[0],L[1],L[2]],Pt(this.placedMat,S,D,b,I*f),this.placed=!0,_&&(_.visible=!1),R&&(R.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),r.onPlaced?.(this.placedMat)}});try{let L=e.getGLContext?.()||e?.gl;L&&typeof L.makeXRCompatible=="function"&&await L.makeXRCompatible();let X=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;L&&typeof X=="function"&&typeof y.updateRenderState=="function"&&y.updateRenderState({baseLayer:new X(y,L,{alpha:!0})});try{F=await y.requestReferenceSpace("local")}catch{try{F=await y.requestReferenceSpace("local-floor")}catch{F=await y.requestReferenceSpace("viewer")}}let J=await y.requestReferenceSpace("viewer").catch(()=>F);if(typeof y.requestHitTestSource=="function"&&J&&(U=await y.requestHitTestSource({space:J}).catch(()=>null)),u==="immersive-ar"&&L&&typeof L.createVertexArray=="function"&&Array.isArray(e.meshes)&&(_=cn(L,r.reticleColor),e.meshes.push(_)),typeof window<"u"&&typeof window.addEventListener=="function"){let $=A=>Math.hypot(A.touches[1].clientX-A.touches[0].clientX,A.touches[1].clientY-A.touches[0].clientY),te=A=>Math.atan2(A.touches[1].clientY-A.touches[0].clientY,A.touches[1].clientX-A.touches[0].clientX),O=A=>{this.s&&(A.touches.length===1&&this.placed?n=!0:A.touches.length>=2&&(n=!1,p=$(A),B=te(A)))},G=A=>{if(!this.s||A.touches.length<2)return;let E=$(A),H=te(A);if(p&&p>4&&r.arScale!=="fixed"&&(f=Math.max(.15,Math.min(6,f*(E/p)))),B!==null){let W=H-B;W>Math.PI&&(W-=Math.PI*2),W<-Math.PI&&(W+=Math.PI*2),b-=W}p=E,B=H},q=A=>{(!A.touches||A.touches.length===0)&&(n=!1),(!A.touches||A.touches.length<2)&&(p=null,B=null)};window.addEventListener("touchstart",O,{passive:!0}),window.addEventListener("touchmove",G,{passive:!0}),window.addEventListener("touchend",q,{passive:!0}),window.addEventListener("touchcancel",q,{passive:!0}),j=()=>{window.removeEventListener("touchstart",O),window.removeEventListener("touchmove",G),window.removeEventListener("touchend",q),window.removeEventListener("touchcancel",q)}}e.setXRSessionActive?.(!0);let re=($,te)=>{if(this.s!==y)return;y.requestAnimationFrame(re);let O=z>0?Math.min(Math.max(($-z)/1e3,0),.1):1/60;z=$,e?.stepXRUpdate?.(O);let G=te.getViewerPose(F);if(!G)return;let q=G.views?.[0];if(!K&&q?.transform){let Q=q.transform.position,Y=q.transform.matrix,ue=Q?.x??(Y?Y[12]:0),ie=Q?.y??(Y?Y[13]:0),ae=Q?.z??(Y?Y[14]:0),ne=Y?-Y[8]:0,oe=Y?-Y[10]:-1,me=Math.hypot(ne,oe);me>1e-4?(ne/=me,oe/=me):(ne=0,oe=-1),N=[ue+ne*1.2,ie-.25,ae+oe*1.2],b=Math.atan2(-ne,-oe),K=!0}if(U&&typeof te.getHitTestResults=="function"&&(!this.placed||n)){let Q=te.getHitTestResults(U)||[],Y=!1;for(let ue of Q){let ie=ue.getPose(F);if(ie?.transform?.matrix){let ae=ie.transform.matrix,ne=ae[5];if(r.arPlacement==="wall"&&Math.abs(ne)>.35||r.arPlacement==="floor"&&Math.abs(ne)<.65)continue;k||(k=new Float32Array(16)),k.set(ae),P=[ae[12],ae[13],ae[14]],this.placed&&n&&(S=[ae[12],ae[13],ae[14]]),_&&(_.visible=!this.placed||n,_.transform.set(ae)),!this.placed&&R&&(R.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),r.onHit?.(k),Y=!0;break}}!Y&&_&&(_.visible=!1)}Pt(o,this.placed?S:P||N,D,b,I*f),this.placed&&this.placedMat.set(o);let A=e.xrRigMatrix;A instanceof Float32Array&&A.length===16?fe(V,A,o):V.set(o),e.modelRootMatrix&&e.modelRootMatrix.set(V);for(let Q of ce)Q.onXRFrame?.(e,y,te,F);let E=e.getGLContext?.()||e?.gl,H=y.renderState?.baseLayer;E&&H&&H.framebuffer!==void 0&&E.bindFramebuffer(36160,H.framebuffer);let W=u==="immersive-ar",Z=G.views||[];for(let Q=0;Q<Z.length;Q++){let Y=Z[Q];if(typeof e.renderXRView=="function"){let ue;if(H&&typeof H.getViewport=="function"){let ie=H.getViewport(Y);ie&&ie.width>0&&ie.height>0&&(ue=[ie.x,ie.y,ie.width,ie.height])}else H?.framebufferWidth>0&&H?.framebufferHeight>0&&(ue=[0,0,H.framebufferWidth,H.framebufferHeight]);e.renderXRView(Y,V,this.placed,ue,W,Q)}}E&&H&&H.framebuffer&&E.bindFramebuffer(36160,null)};y.requestAnimationFrame(re)}catch(L){throw typeof y.end=="function"&&await y.end().catch(()=>{}),ee(),r.onError?.(L),L}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function ln(e){let t=await st(),i=e.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let l of i)if(t.availableModes.includes(l)){r=l;break}if(r||(r=t.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let a={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},s={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},c={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(r==="quick-look"){let l;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")l=e.model;else{if(typeof e.model=="string")return tt(e.model,a),{mode:"quick-look",success:!0};l=et(e.model)}return tt(l,a),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let l=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!l)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Ft(l,s),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let l=new Be(c);return await l.start(e.view,e.element),{mode:"webxr",success:!0,session:l}}}catch(l){return{mode:r,success:!1,error:l}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}
|
|
331
|
+
${f.body}${x(m)}${E(m)}${f.tail}}
|
|
332
|
+
`}}if(S+=`}
|
|
333
|
+
`,i.length>0){S+=`def Scope "Lights"
|
|
334
|
+
{
|
|
335
|
+
`;let u=new Set;for(let m=0;m<i.length;m++){let g=i[m],d=ct(u,ke(g.name,`Light_${m}`)),b=g.type==="directional"?"DistantLight":g.type==="spot"?"DiskLight":"SphereLight",w=g.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[f,z,_]=g.color||[1,1,1],[L,R,C]=g.position||[0,5,5],$=-L,B=-R,y=-C;g.direction&&g.direction.length>=3&&(g.type==="directional"?($=-g.direction[0],B=-g.direction[1],y=-g.direction[2]):($=g.direction[0],B=g.direction[1],y=g.direction[2]));let[P,V,j,v]=Bt($,B,y),O="",s=[];g.type!=="directional"&&(Math.abs(L)>1e-7||Math.abs(R)>1e-7||Math.abs(C)>1e-7)&&(O+=`double3 xformOp:translate = ${Te(L,R,C)}
|
|
336
|
+
`,s.push('"xformOp:translate"')),g.type!=="point"&&(1-Math.abs(v)>1e-7||Math.hypot(P,V,j)>1e-7)&&(O+=`quatf xformOp:orient = ${Ie(v,P,V,j)}
|
|
337
|
+
`,s.push('"xformOp:orient"')),s.length>0&&(O+=`uniform token[] xformOpOrder = [${s.join(", ")}]
|
|
338
|
+
`);let M="";if(g.type==="spot"){let h=(g.outerConeAngle??Math.PI/3)*180/Math.PI,A=(g.innerConeAngle??h*.8)*180/Math.PI,q=h>1e-4?Math.max(0,Math.min(1,1-A/h)):0;M=`float inputs:shaping:cone:angle = ${be(h)}
|
|
339
|
+
float inputs:shaping:cone:softness = ${be(q)}
|
|
340
|
+
`}S+=`def ${b} "${d}" (
|
|
341
|
+
prepend apiSchemas = ${w}
|
|
342
|
+
)
|
|
343
|
+
{
|
|
344
|
+
color3f inputs:color = ${Te(f,z,_)}
|
|
345
|
+
float inputs:intensity = ${be(g.intensity??1)}
|
|
346
|
+
bool inputs:shadow:enable = 1
|
|
347
|
+
${M}${O}}
|
|
348
|
+
`}S+=`}
|
|
349
|
+
`}return S+=`}
|
|
350
|
+
`,S}function Vt(e,t){if(e&&typeof e.traverse=="function"){let n=pn(e,t);return lt(n)}let i=_e(e),r=mt(i);return lt(r)}var He=null;function ht(e){if(!He){He=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;He[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=He[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function ft(e){let t=[],i=0,r=[];for(let p of e){let x=Ot(p.filename),E=ht(p.data),I=p.data.length,T=30+x.length,F=(i+T)%64,u=F!==0?64-F:0;u>0&&u<4&&(u+=64);let m=new Uint8Array(T+u),g=new DataView(m.buffer);g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint32(14,E,!0),g.setUint32(18,I,!0),g.setUint32(22,I,!0),g.setUint16(26,x.length,!0),g.setUint16(28,u,!0),m.set(x,30),u>=4&&(g.setUint16(T,6534,!0),g.setUint16(T+2,u-4,!0)),t.push({offset:i,size:I,crc:E,filenameBytes:x,entry:p}),r.push(m,p.data),i+=m.length+p.data.length}let n=i;for(let p of t){let x=new Uint8Array(46+p.filenameBytes.length),E=new DataView(x.buffer);E.setUint32(0,33639248,!0),E.setUint16(4,20,!0),E.setUint16(6,20,!0),E.setUint32(16,p.crc,!0),E.setUint32(20,p.size,!0),E.setUint32(24,p.size,!0),E.setUint16(28,p.filenameBytes.length,!0),E.setUint32(42,p.offset,!0),x.set(p.filenameBytes,46),r.push(x),i+=x.length}let a=i-n,l=new Uint8Array(22),o=new DataView(l.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,a,!0),o.setUint32(16,n,!0),r.push(l),i+=22;let c=new Uint8Array(i),S=0;for(let p of r)c.set(p,S),S+=p.length;return c}function yn(e){let t=[{filename:"model.usda",data:Ot(lt(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 ft(t)}function dt(e){return yn(mt(_e(e)))}function pt(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():dt(e)}function bt(e){let t=pt(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function yt(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let t=document.createElement("a");return t.relList!==void 0&&t.relList.supports!==void 0&&t.relList.supports("ar")}function xt(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function vt(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function vn(){let e=[];return await vt()&&e.push("webxr"),yt()&&e.push("quick-look"),xt()&&e.push("scene-viewer"),e}async function Mn(){return(await Mt()).bestMode}async function Mt(){let[e,t,i]=await Promise.all([vt(),Promise.resolve(yt()),Promise.resolve(xt())]),r=[];t&&r.push("quick-look"),e&&r.push("webxr"),i&&r.push("scene-viewer");let n=null;return t?n="quick-look":e?n="webxr":i&&(n="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:i,availableModes:r,bestMode:n}}function gt(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let i,r=!1;if(typeof e=="string"){if(i=An(e),!i)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else i=URL.createObjectURL(e),r=!0;let n=[];if(t.allowScale===!1&&n.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let o=We(t.canonicalWebPageUrl,!1);o&&n.push(`canonicalWebPageURL=${encodeURIComponent(o)}`)}t.checkoutTitle&&n.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&n.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&n.push(`price=${encodeURIComponent(t.price)}`),n.length>0&&(i+=`#${n.join("&")}`);let a=document.createElement("a");a.setAttribute("rel","ar"),a.setAttribute("href",i);let l=document.createElement("img");l.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),l.style.display="none",a.appendChild(l),document.body.appendChild(a),a.click(),setTimeout(()=>{document.body.removeChild(a),r&&URL.revokeObjectURL(i.split("#")[0])},3e3)}function We(e,t=!1){if(typeof e!="string")return"";let i=e.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!i)return"";if(/^[\\/]{2}/.test(i))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${i.slice(0,32)}`);let r=i.toLowerCase();if(r.startsWith("https://")||r.startsWith("http://")||t&&r.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(i))return i;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${i.slice(0,32)}`)}function An(e){try{return We(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function zt(e,t={}){let i=We(e,!0),r=t.mode||"ar_preferred",n=new URLSearchParams({file:i,mode:r,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&n.set("title",t.title),t.link&&n.set("link",We(t.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${n.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function Ht(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let i=zt(e,t);window.location.href=i}var Ee=null;function wn(e,t){let i=new Float32Array(144),r=new Float32Array(144),n=new Float32Array(96),a=new Uint16Array(144);for(let p=0;p<24;p++){let x=p/24*Math.PI*2,E=Math.cos(x),I=Math.sin(x),T=p*2,F=T+1,u=(p+1)%24*2;i[T*3]=E*.11,i[T*3+1]=.002,i[T*3+2]=I*.11,i[F*3]=E*.145,i[F*3+1]=.002,i[F*3+2]=I*.145,r[T*3+1]=r[F*3+1]=1,a.set([T,u,F,F,u,u+1],p*6)}let l=e.createVertexArray();e.bindVertexArray(l);let o=(p,x,E)=>{let I=e.createBuffer();return e.bindBuffer(34962,I),e.bufferData(34962,p,35044),e.enableVertexAttribArray(x),e.vertexAttribPointer(x,E,5126,!1,0,0),I},c=[o(i,0,3),o(r,1,3),o(n,2,2)],S=e.createBuffer();return c.push(S),e.bindBuffer(34963,S),e.bufferData(34963,a,35044),e.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:l,indexCount:a.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:i,indices:a,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:c}]}}function $t(e,t,i,r,n){let a=Math.cos(r),l=Math.sin(r),o=Math.max(.01,n);e.fill(0),e[0]=o*a,e[2]=-o*l,e[5]=o,e[8]=o*l,e[10]=o*a,e[12]=t[0]-o*(a*i[0]+l*i[2]),e[13]=t[1]-o*i[1],e[14]=t[2]-o*(-l*i[0]+a*i[2]),e[15]=1}var je=class{constructor(e={}){this.s=null,this.placed=!1,this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.cleanFn=null,this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,t){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");Ee&&Ee!==this&&Ee.isSessionActive()&&await Ee.stop().catch(()=>{});let i=navigator.xr,r=this.opts,n=t||e?.container,a=String(n?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,o=Number(l?.radius)||1,c=Array.isArray(l?.center)?l.center:[0,0,0],S=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],p=typeof navigator<"u"&&navigator.userAgent||"",x=/Android|iPhone|iPad|iPod/i.test(p)&&!/Quest|Oculus|Pico|Vision/i.test(p),E=a?r.arScale==="fixed"?1:x?.55:1:r.arScale==="fixed"?1:o>.45?.3/o:o<.05?.12/Math.max(o,.001):1,I=a?[0,-.25,0]:[c[0]||0,r.arPlacement==="wall"?c[1]:S[1]??0,c[2]||0],T="immersive-ar";try{await i.isSessionSupported("immersive-ar")||(T="immersive-vr")}catch{T="immersive-vr"}let F=n?.querySelector?.('[slot="ar-overlay"]')||null,u=!1,m=null,g=()=>{u&&F?.parentNode&&F.parentNode.removeChild(F),F=null,m=null,u=!1};if(T==="immersive-ar"){if(F)F.addEventListener?.("beforexrselect",N=>N.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let N=document.createElement("div");N.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let X=document.createElement("button");X.type="button",X.textContent="\u2715 Exit AR",X.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",X.addEventListener("beforexrselect",K=>K.preventDefault()),X.addEventListener("click",K=>{K.stopPropagation(),this.stop().catch(()=>{})}),m=document.createElement("div"),m.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",m.textContent="Move phone to detect a surface \u2022 Tap to place",N.appendChild(X),N.appendChild(m),document.body.appendChild(N),F=N,u=!0}}let d=new Set(r.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),b={requiredFeatures:r.requiredFeatures?[...r.requiredFeatures]:[],optionalFeatures:Array.from(d)};F&&(d.add("dom-overlay"),b.optionalFeatures=Array.from(d),b.domOverlay={root:F});for(let N of pe)N.onConfigureXRSessionInit?.(n,b);Array.isArray(b.optionalFeatures)&&b.optionalFeatures.includes("dom-overlay")&&!b.domOverlay?.root&&(b.optionalFeatures=b.optionalFeatures.filter(N=>N!=="dom-overlay"));let w=N=>{let X=String(N?.name||"");return X==="NotAllowedError"||X==="SecurityError"};try{this.s=await i.requestSession(T,b)}catch(N){if(g(),w(N))throw r.onError?.(N),N;try{this.s=await i.requestSession(T,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(X){if(w(X))throw r.onError?.(X),X;try{this.s=await i.requestSession(T)}catch(K){throw r.onError?.(K),K}}}let f=this.s;Ee=this,this.placed=!1;let z=null,_=null,L=null,R=null,C=null,$=[0,-.25,-1.2],B=[0,-.25,-1.2],y=new Float32Array(16),P=new Float32Array(16),V=!1,j=1,v=0,O=!1,s=null,M=null,h=0,A=null,q=()=>{Ee===this&&(Ee=null),A?.(),A=null;try{_?.cancel?.()}catch{}if(_=null,L){let N=e?.meshes;if(Array.isArray(N)){let K=N.indexOf(L);K!==-1&&N.splice(K,1)}let X=e.getGLContext?.()||e?.gl;if(X)for(let K of L.primitives||[]){X.deleteVertexArray?.(K.vao);for(let ne of K.buffers||[])X.deleteBuffer?.(ne)}L=null}e?.setXRSessionActive?.(!1),g(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=q,f.addEventListener("end",()=>{q(),r.onExit?.()}),f.addEventListener("select",()=>{if(!this.placed){let N=C||$;B=[N[0],N[1],N[2]],$t(this.placedMat,B,I,v,E*j),this.placed=!0,L&&(L.visible=!1),m&&(m.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),r.onPlaced?.(this.placedMat)}});try{let N=e.getGLContext?.()||e?.gl;N&&typeof N.makeXRCompatible=="function"&&await N.makeXRCompatible();let X=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;N&&typeof X=="function"&&typeof f.updateRenderState=="function"&&f.updateRenderState({baseLayer:new X(f,N,{alpha:!0})});try{z=await f.requestReferenceSpace("local")}catch{try{z=await f.requestReferenceSpace("local-floor")}catch{z=await f.requestReferenceSpace("viewer")}}let K=await f.requestReferenceSpace("viewer").catch(()=>z);if(typeof f.requestHitTestSource=="function"&&K&&(_=await f.requestHitTestSource({space:K}).catch(()=>null)),T==="immersive-ar"&&N&&typeof N.createVertexArray=="function"&&Array.isArray(e.meshes)&&(L=wn(N,r.reticleColor),e.meshes.push(L)),typeof window<"u"&&typeof window.addEventListener=="function"){let ae=D=>Math.hypot(D.touches[1].clientX-D.touches[0].clientX,D.touches[1].clientY-D.touches[0].clientY),oe=D=>Math.atan2(D.touches[1].clientY-D.touches[0].clientY,D.touches[1].clientX-D.touches[0].clientX),se=D=>{this.s&&(D.touches.length===1&&this.placed?O=!0:D.touches.length>=2&&(O=!1,s=ae(D),M=oe(D)))},H=D=>{if(!this.s||D.touches.length<2)return;let Q=ae(D),Z=oe(D);if(s&&s>4&&r.arScale!=="fixed"&&(j=Math.max(.15,Math.min(6,j*(Q/s)))),M!==null){let Y=Z-M;Y>Math.PI&&(Y-=Math.PI*2),Y<-Math.PI&&(Y+=Math.PI*2),v-=Y}s=Q,M=Z},W=D=>{(!D.touches||D.touches.length===0)&&(O=!1),(!D.touches||D.touches.length<2)&&(s=null,M=null)};window.addEventListener("touchstart",se,{passive:!0}),window.addEventListener("touchmove",H,{passive:!0}),window.addEventListener("touchend",W,{passive:!0}),window.addEventListener("touchcancel",W,{passive:!0}),A=()=>{window.removeEventListener("touchstart",se),window.removeEventListener("touchmove",H),window.removeEventListener("touchend",W),window.removeEventListener("touchcancel",W)}}e.setXRSessionActive?.(!0);let ne=(ae,oe)=>{if(this.s!==f)return;f.requestAnimationFrame(ne);let se=h>0?Math.min(Math.max((ae-h)/1e3,0),.1):1/60;h=ae,e?.stepXRUpdate?.(se);let H=oe.getViewerPose(z);if(!H)return;let W=H.views?.[0];if(!V&&W?.transform){let U=W.transform.position,G=W.transform.matrix,J=U?.x??(G?G[12]:0),ee=U?.y??(G?G[13]:0),ie=U?.z??(G?G[14]:0),le=G?-G[8]:0,re=G?-G[10]:-1,de=Math.hypot(le,re);de>1e-4?(le/=de,re/=de):(le=0,re=-1),$=[J+le*1.2,ee-.25,ie+re*1.2],v=Math.atan2(-le,-re),V=!0}if(_&&typeof oe.getHitTestResults=="function"&&(!this.placed||O)){let U=oe.getHitTestResults(_)||[],G=!1;for(let J of U){let ee=J.getPose(z);if(ee?.transform?.matrix){let ie=ee.transform.matrix,le=ie[5];if(r.arPlacement==="wall"&&Math.abs(le)>.35||r.arPlacement==="floor"&&Math.abs(le)<.65)continue;R||(R=new Float32Array(16)),R.set(ie),C=[ie[12],ie[13],ie[14]],this.placed&&O&&(B=[ie[12],ie[13],ie[14]]),L&&(L.visible=!this.placed||O,L.transform.set(ie)),!this.placed&&m&&(m.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),r.onHit?.(R),G=!0;break}}!G&&L&&(L.visible=!1)}$t(y,this.placed?B:C||$,I,v,E*j),this.placed&&this.placedMat.set(y);let D=e.xrRigMatrix;D instanceof Float32Array&&D.length===16?xe(P,D,y):P.set(y),e.modelRootMatrix&&e.modelRootMatrix.set(P);for(let U of pe)U.onXRFrame?.(e,f,oe,z);let Q=e.getGLContext?.()||e?.gl,Z=f.renderState?.baseLayer;Q&&Z&&Z.framebuffer!==void 0&&Q.bindFramebuffer(36160,Z.framebuffer);let Y=T==="immersive-ar",k=H.views||[];for(let U=0;U<k.length;U++){let G=k[U];if(typeof e.renderXRView=="function"){let J;if(Z&&typeof Z.getViewport=="function"){let ee=Z.getViewport(G);ee&&ee.width>0&&ee.height>0&&(J=[ee.x,ee.y,ee.width,ee.height])}else Z?.framebufferWidth>0&&Z?.framebufferHeight>0&&(J=[0,0,Z.framebufferWidth,Z.framebufferHeight]);e.renderXRView(G,P,this.placed,J,Y,U)}}Q&&Z&&Z.framebuffer&&Q.bindFramebuffer(36160,null)};f.requestAnimationFrame(ne)}catch(N){throw typeof f.end=="function"&&await f.end().catch(()=>{}),q(),r.onError?.(N),N}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function Tn(e){let t=await Mt(),i=e.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let o of i)if(t.availableModes.includes(o)){r=o;break}if(r||(r=t.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let n={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},a={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},l={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(r==="quick-look"){let o;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")o=e.model;else{if(typeof e.model=="string")return gt(e.model,n),{mode:"quick-look",success:!0};o=bt(e.model)}return gt(o,n),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let o=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!o)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Ht(o,a),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let o=new je(l);return await o.start(e.view,e.element),{mode:"webxr",success:!0,session:o}}}catch(o){return{mode:r,success:!1,error:o}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}
|