three-live 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -3
- package/dist/three-author-engine.js +45 -40
- package/dist/three-author.cjs +32 -27
- package/dist/three-author.d.ts +3 -3
- package/dist/three-author.js +32 -27
- package/dist/three-convert.cjs +43 -38
- package/dist/three-convert.d.ts +3 -3
- package/dist/three-convert.js +42 -37
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +3 -3
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +6 -6
- package/dist/three-live-element.cjs +12 -7
- package/dist/three-live-element.d.ts +3 -3
- package/dist/three-live-element.js +12 -7
- package/dist/three-live-extras.cjs +13 -13
- package/dist/three-live-extras.d.ts +3 -3
- package/dist/three-live-extras.js +12 -12
- package/dist/three-live-extras.min.js +13 -13
- package/dist/three-live-full.cjs +69 -64
- package/dist/three-live-full.js +69 -64
- package/dist/three-live-full.min.js +69 -64
- package/dist/three-live-viewer.cjs +12 -7
- package/dist/three-live-viewer.d.ts +3 -3
- package/dist/three-live-viewer.js +12 -7
- package/dist/three-live-viewer.min.js +12 -7
- package/dist/three-live.cjs +49 -44
- package/dist/three-live.js +49 -44
- package/dist/three-live.min.js +49 -44
- package/dist/three-view.cjs +12 -7
- package/dist/three-view.d.ts +3 -3
- package/dist/three-view.js +12 -7
- package/dist/three-xr.cjs +44 -39
- package/dist/three-xr.d.ts +3 -3
- package/dist/three-xr.js +44 -39
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var ThreeLiveBundle=(()=>{var Tn=Object.defineProperty;var hi=Object.getOwnPropertyDescriptor;var di=Object.getOwnPropertyNames;var fi=Object.prototype.hasOwnProperty;var pi=(t,e)=>{for(var n in e)Tn(t,n,{get:e[n],enumerable:!0})},bi=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of di(e))!fi.call(t,r)&&r!==n&&Tn(t,r,{get:()=>e[r],enumerable:!(i=hi(e,r))||i.enumerable});return t};var yi=t=>bi(Tn({},"__esModule",{value:!0}),t);var sr={};pi(sr,{AmbientLight:()=>ct,BoxGeometry:()=>ot,BufferAttribute:()=>te,BufferGeometry:()=>be,Camera:()=>lt,CapsuleGeometry:()=>on,CircleGeometry:()=>an,Clock:()=>Jt,Color:()=>ve,ConeGeometry:()=>Vt,CylinderGeometry:()=>Pe,DirectionalLight:()=>jt,DodecahedronGeometry:()=>nn,Euler:()=>rt,Float32BufferAttribute:()=>Ut,Group:()=>Yt,HemisphereLight:()=>dt,IcosahedronGeometry:()=>en,InteractivityVM:()=>yt,Light:()=>Ue,Material:()=>Re,MathUtils:()=>Ir,Matrix3:()=>kt,Matrix4:()=>Fe,Mesh:()=>Ge,MeshBasicMaterial:()=>Wt,MeshLambertMaterial:()=>Gt,MeshPhongMaterial:()=>$t,MeshPhysicalMaterial:()=>qt,MeshStandardMaterial:()=>ke,Object3D:()=>we,OctahedronGeometry:()=>tn,PerspectiveCamera:()=>Kt,PlaneGeometry:()=>Bt,PointLight:()=>ut,PolyhedronFallbackGeometry:()=>Ne,Quaternion:()=>it,RawShaderMaterial:()=>zr,RectAreaLight:()=>Hr,RingGeometry:()=>sn,Scene:()=>mt,SceneQuotaValidator:()=>Te,ShaderMaterial:()=>ht,SphereGeometry:()=>st,SpotLight:()=>cn,THREE:()=>ft,TetrahedronGeometry:()=>rn,Texture:()=>at,TextureLoader:()=>Xt,ThreeLiveElement:()=>Ee,ThreeView:()=>me,TorusGeometry:()=>zt,TorusKnotGeometry:()=>Ht,Uint16BufferAttribute:()=>Nt,Uint32BufferAttribute:()=>Ot,Vector2:()=>Lt,Vector3:()=>ae,Vector4:()=>Ft,WebGLRenderer:()=>Zt,activateAR:()=>wn,authorScriptRunner:()=>Ye,buildSandboxWorkerSource:()=>kn,clearAuthorWarnings:()=>Vr,contactShadowPlugin:()=>xt,createUSDZBlob:()=>We,crossFadeTo:()=>Bn,environmentMapPlugin:()=>Gn,exportSceneToCanvas3D:()=>Pn,exportSceneToGLB:()=>Ln,exportSceneToUSDZ:()=>Pr,generateUSDZ:()=>It,getARCapabilities:()=>vn,getAllowClientScripts:()=>kr,getAuthorWarnings:()=>Br,getBestARMode:()=>ui,getEnvironmentSH:()=>jr,getInteractivityVM:()=>yn,getSandboxEngineSrc:()=>Fn,getSandboxIframeSrc:()=>Fr,glbToUSDZ:()=>Xe,hotspotPlugin:()=>Yn,interactivityPlugin:()=>Jn,isAllowedSandboxEngineUrl:()=>Le,isQuickLookSupported:()=>rr,isSceneViewerSupported:()=>ir,isWebXRSupported:()=>or,keyframeAnimationPlugin:()=>Vn,materialsPlugin:()=>er,morphPlugin:()=>zn,noopProxy:()=>tt,parseAnimations:()=>On,parseSafeGltfPointer:()=>bt,registerMaterialShader:()=>ri,sampleChannel:()=>je,sceneToCanvas3D:()=>ze,sceneToGLB:()=>Qe,sceneToUSDZ:()=>He,sendInteractivityEvent:()=>Zn,setAllowClientScripts:()=>Ui,setEnvironmentSH:()=>hn,setMorphTargetWeight:()=>Gr,setSandboxEngineSrc:()=>Pi,setSandboxIframeSrc:()=>Fi,skinningPlugin:()=>Xn,threeAuthorPlugin:()=>nt,threeMicroPlugin:()=>Gi,toGLBData:()=>Ce,toTrustedWorkerScriptURL:()=>Lr,validateSandboxWorkerMessage:()=>Un,warnUnsupported:()=>ye,webxrPlugin:()=>tr});function ar(t,e,n){let i=[],r=new Map,o=[],u=[],l=[],a=new Map,c=p=>{let R=r.get(p);return R===void 0&&(R=i.length,i.push({op:p}),r.set(p,R)),R},s=p=>{let R=a.get(p);return R===void 0&&(R=l.length,l.push({id:p}),a.set(p,R)),R},m=(p,R={})=>o.push({declaration:c(p),...R})-1,h=(p,R,x)=>u.push({id:p,type:R,value:x})-1,f=p=>({node:p,socket:"value"}),d=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(d&&typeof d=="object"){let p=Array.isArray(d.graphs)?d.graphs[d.graph??0]:d;if(p&&Array.isArray(p.nodes)){let R=Array.isArray(p.declarations)?p.declarations:[];for(let x of R)x?.op&&c(x.op);Array.isArray(p.variables)&&u.push(...p.variables);for(let x of p.events||[])x?.id&&s(x.id);for(let x of p.nodes){if(!x||typeof x!="object")continue;let F=x.op||(typeof x.declaration=="number"?R[x.declaration]?.op:"");o.push(F?{...x,declaration:c(F)}:{...x})}}}let b=(p,R,x="translation")=>x==="baseColorFactor"||x==="metallicFactor"||x==="roughnessFactor"?`/materials/${Math.max(0,R)}/pbrMetallicRoughness/${x}`:x==="emissiveFactor"||x==="alphaCutoff"?`/materials/${Math.max(0,R)}/${x}`:x==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${x}`,g=new Map;t.forEach((p,R)=>{typeof p?.name=="string"&&!g.has(p.name)&&g.set(p.name,R)});let E=(p,R)=>typeof p.target=="string"&&g.has(p.target)?g.get(p.target):typeof p.targetNode=="number"?p.targetNode:R,A=p=>{let R=t[p];return(typeof R?.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<t.length;p++){let R=t[p],x=R?.extras?.interactivity;if(!x||typeof x!="object")continue;let F=(typeof R.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0,y=T=>{let I=Array.isArray(T)?T:[T],B=[];for(let N=0;N<I.length;N++){let _=I[N];if(!_||typeof _!="object")continue;let q=_.action||"interpolate",J=typeof _.duration=="number"?_.duration:.35;if(q==="toggleTransform"){let Z=_.property==="rotation"||_.property==="scale"?_.property:"translation",j=Z==="rotation"?R.rotation||[0,0,0,1]:Z==="scale"?R.scale||[1,1,1]:R.translation||[0,0,0],V=`/nodes/${p}/${Z}`,X=h(`__toggle_${p}_${N}`,"bool",!1),k=m("variable/get",{configuration:{variable:X}}),W=m("math/not",{values:{a:f(k)}}),G=m("variable/set",{configuration:{variable:X},values:{value:f(W)}}),S=m("pointer/interpolate",{configuration:{pointer:V},values:{value:{value:Array.isArray(_.to)?_.to:j},duration:{value:J}}}),v=m("pointer/interpolate",{configuration:{pointer:V},values:{value:{value:Array.isArray(_.from)?_.from:j},duration:{value:J}}});o[G].flows={out:{node:m("flow/branch",{values:{condition:f(k)},flows:{true:{node:S},false:{node:v}}})}},B.push(G)}else if(q==="interpolate"){let Z=_.to??_.value;if(Z===void 0)continue;let j={value:{value:Z},duration:{value:J}};_.from!==void 0&&(j.from={value:_.from}),B.push(m("pointer/interpolate",{configuration:{pointer:typeof _.pointer=="string"?_.pointer:b(E(_,p),A(E(_,p)),_.property)},values:j}))}else if(q==="setProperty"){if(_.value===void 0)continue;B.push(m("pointer/set",{configuration:{pointer:typeof _.pointer=="string"?_.pointer:b(E(_,p),A(E(_,p)),_.property)},values:{value:{value:_.value}}}))}else if(q==="toggleVisibility"){let Z=E(_,p),j=h(`__vis_${Z}_${N}`,"bool",!0),V=m("variable/get",{configuration:{variable:j}}),X=m("math/not",{values:{a:f(V)}}),k=m("variable/set",{configuration:{variable:j},values:{value:f(X)}});o[k].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${Z}/extensions/KHR_node_visibility/visible`},values:{value:f(V)}})}},B.push(k)}else if(q==="cycleMaterialColor"&&Array.isArray(_.colors)&&_.colors.length>0){let Z=typeof _.duration=="number"?_.duration:.25,j=`/materials/${Math.max(0,F)}/pbrMetallicRoughness/baseColorFactor`,V=h(`__color_idx_${p}_${N}`,"int",0),X=m("variable/get",{configuration:{variable:V}}),k=m("math/add",{values:{a:f(X),b:{value:1}}}),W=m("math/rem",{values:{a:f(k),b:{value:_.colors.length}}}),G=m("variable/set",{configuration:{variable:V},values:{value:f(W)}}),S={};for(let v=0;v<_.colors.length;v++){let L=_.colors[v],U=Array.isArray(L)&&L.length>=3?[L[0],L[1],L[2],L[3]??1]:[1,1,1,1];S[String(v)]={node:Z>0?m("pointer/interpolate",{configuration:{pointer:j},values:{value:{value:U},duration:{value:Z}}}):m("pointer/set",{configuration:{pointer:j},values:{value:{value:U}}})}}o[G].flows={out:{node:m("flow/switch",{values:{selection:f(X)},flows:S})}},B.push(G)}else if(q==="playAnimation")B.push(m("animation/start",{configuration:{animation:_.animation??_.clip??0}}));else if(q==="stopAnimation")B.push(m("animation/stop"));else if(q==="sendEvent"){let Z={};for(let[j,V]of Object.entries(_.values||{}))Z[j]={value:V};B.push(m("event/send",{configuration:{event:s(String(_.event??_.id??"custom"))},values:Z}))}}if(!B.length)return null;if(B.length===1)return B[0];let P={};return B.forEach((N,_)=>{P[String(_)]={node:N}}),m("flow/sequence",{flows:P})},w=(T,I,B)=>{let P=y(I);P!==null&&m(T,{...B?{configuration:B}:{},flows:{out:{node:P}}})};if(x.onSelect&&w("pointer/onSelect",x.onSelect,{nodeIndex:p}),x.onHoverIn&&w("pointer/onHoverIn",x.onHoverIn,{nodeIndex:p}),x.onHoverOut&&w("pointer/onHoverOut",x.onHoverOut,{nodeIndex:p}),x.onStart&&w("event/onStart",x.onStart),x.onReceive&&typeof x.onReceive=="object")for(let[T,I]of Object.entries(x.onReceive))w("event/receive",I,{event:s(T)})}return o.length?{graphs:[{declarations:i,nodes:o,variables:u,events:l}],graph:0}:null}var Tt='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',Rt="Security Error: client-side scripts require allow-client-scripts opt-in.";var Et="__THREE_LIVE_REGISTRY__";function re(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Et]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Et,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Et]=e}}return t[Et]}var ce=re().plugins;function fe(t){let e=re().plugins;e.some(n=>n.name===t.name)||e.push(t)}function St(){return re().plugins}function se(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function cr(t,e,n,i,r){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let u=1/(i-r);return t[10]=(r+i)*u,t[14]=2*r*i*u,t}function Mt(t,e,n,i){let[r,o,u]=e,[l,a,c]=i,[s,m,h]=n,f=r-s,d=o-m,b=u-h,g=Math.hypot(f,d,b);g<=1e-5?(f=0,d=0,b=1):(f/=g,d/=g,b/=g);let E=a*b-c*d,A=c*f-l*b,p=l*d-a*f;g=Math.hypot(E,A,p),g<=1e-5?(E=0,A=0,p=0):(E/=g,A/=g,p/=g);let R=d*p-b*A,x=b*E-f*p,F=f*A-d*E;return g=Math.hypot(R,x,F),g<=1e-5?(R=0,x=0,F=0):(R/=g,x/=g,F/=g),t[0]=E,t[1]=R,t[2]=f,t[3]=0,t[4]=A,t[5]=x,t[6]=d,t[7]=0,t[8]=p,t[9]=F,t[10]=b,t[11]=0,t[12]=-(E*r+A*o+p*u),t[13]=-(R*r+x*o+F*u),t[14]=-(f*r+d*o+b*u),t[15]=1,t}function pe(t,e,n){let i=e[0],r=e[1],o=e[2],u=e[3],l=e[4],a=e[5],c=e[6],s=e[7],m=e[8],h=e[9],f=e[10],d=e[11],b=e[12],g=e[13],E=e[14],A=e[15],p=n[0],R=n[1],x=n[2],F=n[3];return t[0]=p*i+R*l+x*m+F*b,t[1]=p*r+R*a+x*h+F*g,t[2]=p*o+R*c+x*f+F*E,t[3]=p*u+R*s+x*d+F*A,p=n[4],R=n[5],x=n[6],F=n[7],t[4]=p*i+R*l+x*m+F*b,t[5]=p*r+R*a+x*h+F*g,t[6]=p*o+R*c+x*f+F*E,t[7]=p*u+R*s+x*d+F*A,p=n[8],R=n[9],x=n[10],F=n[11],t[8]=p*i+R*l+x*m+F*b,t[9]=p*r+R*a+x*h+F*g,t[10]=p*o+R*c+x*f+F*E,t[11]=p*u+R*s+x*d+F*A,p=n[12],R=n[13],x=n[14],F=n[15],t[12]=p*i+R*l+x*m+F*b,t[13]=p*r+R*a+x*h+F*g,t[14]=p*o+R*c+x*f+F*E,t[15]=p*u+R*s+x*d+F*A,t}function Ve(t,e,n,i){let r=e[0],o=e[1],u=e[2],l=e[3],a=r+r,c=o+o,s=u+u,m=r*a,h=r*c,f=r*s,d=o*c,b=o*s,g=u*s,E=l*a,A=l*c,p=l*s,R=i[0],x=i[1],F=i[2];return t[0]=(1-(d+g))*R,t[1]=(h+p)*R,t[2]=(f-A)*R,t[3]=0,t[4]=(h-p)*x,t[5]=(1-(m+g))*x,t[6]=(b+E)*x,t[7]=0,t[8]=(f+A)*F,t[9]=(b-E)*F,t[10]=(1-(m+d))*F,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ue(t,e){let n=e[0],i=e[1],r=e[2],o=e[4],u=e[5],l=e[6],a=e[8],c=e[9],s=e[10],m=s*u-l*c,h=-s*o+l*a,f=c*o-u*a,d=n*m+i*h+r*f;return d&&(d=1/d,t[0]=m*d,t[1]=(-s*i+r*c)*d,t[2]=(l*i-r*u)*d,t[3]=h*d,t[4]=(s*n-r*a)*d,t[5]=(-l*n+r*o)*d,t[6]=f*d,t[7]=(-c*n+i*a)*d,t[8]=(u*n-i*o)*d),t}function _t(t,e){let n=e[0],i=e[1],r=e[2],o=e[3],u=e[4],l=e[5],a=e[6],c=e[7],s=e[8],m=e[9],h=e[10],f=e[11],d=e[12],b=e[13],g=e[14],E=e[15],A=n*l-i*u,p=n*a-r*u,R=n*c-o*u,x=i*a-r*l,F=i*c-o*l,y=r*c-o*a,w=s*b-m*d,T=s*g-h*d,I=s*E-f*d,B=m*g-h*b,P=m*E-f*b,N=h*E-f*g,_=A*N-p*P+R*B+x*I-F*T+y*w;return _?(_=1/_,t[0]=(l*N-a*P+c*B)*_,t[1]=(r*P-i*N-o*B)*_,t[2]=(b*y-g*F+E*x)*_,t[3]=(h*F-m*y-f*x)*_,t[4]=(a*I-u*N-c*T)*_,t[5]=(n*N-r*I+o*T)*_,t[6]=(g*R-d*y-E*p)*_,t[7]=(s*y-h*R+f*p)*_,t[8]=(u*P-l*I+c*w)*_,t[9]=(i*I-n*P-o*w)*_,t[10]=(d*F-b*R+E*A)*_,t[11]=(m*R-s*F-f*A)*_,t[12]=(l*T-u*B-a*w)*_,t[13]=(n*B-i*T+r*w)*_,t[14]=(b*p-d*x-g*A)*_,t[15]=(s*x-m*p+h*A)*_,t):null}function Rn(t,e,n,i,r){let o=r[0]*e+r[4]*n+r[8]*i+r[12],u=r[1]*e+r[5]*n+r[9]*i+r[13],l=r[2]*e+r[6]*n+r[10]*i+r[14],a=r[3]*e+r[7]*n+r[11]*i+r[15],c=a!==0?1/a:1;t[0]=o*c,t[1]=u*c,t[2]=l*c}function ur(t,e,n,i,r,o,u,l,a,c,s,m,h,f,d,b,g=0){let E=c-u,A=s-l,p=m-a,R=h-u,x=f-l,F=d-a,y=r*F-o*x,w=o*R-i*F,T=i*x-r*R,I=E*y+A*w+p*T;if(I>-1e-7&&I<1e-7)return!1;let B=1/I,P=t-u,N=e-l,_=n-a,q=B*(P*y+N*w+_*T);if(q<-g||q>1+g)return!1;let J=N*p-_*A,Z=_*E-P*p,j=P*A-N*E,V=B*(i*J+r*Z+o*j);if(V<-g||q+V>1+g)return!1;let X=B*(R*J+x*Z+F*j);if(X>1e-4&&X<b.distance){b.distance=X,b.point=[t+i*X,e+r*X,n+o*X];let k=A*F-p*x,W=p*R-E*F,G=E*x-A*R,S=Math.hypot(k,W,G)||1;return b.normal=[k/S,W/S,G/S],!0}return!1}function _e(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,i=[];for(let s=0;s<n;s++)i.push(se());if(n===0)return i;let r=new Set;for(let s of t.nodes)if(Array.isArray(s.children))for(let m of s.children)r.add(m);let o=new Set,u=128,l=(s,m,h=0)=>{if(h>u||s<0||s>=n||o.has(s))return;o.add(s);let f=t.nodes[s];if(!f)return;let d=se();if(e&&e[s])d.set(e[s]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let g=f.translation||[0,0,0],E=f.rotation||[0,0,0,1],A=f.scale||[1,1,1];Ve(d,E,g,A)}let b=i[s];if(m?pe(b,m,d):b.set(d),Array.isArray(f.children))for(let g of f.children)typeof g=="number"&&l(g,b,h+1)},a=[],c=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(c&&Array.isArray(c.nodes))a.push(...c.nodes);else for(let s=0;s<n;s++)r.has(s)||a.push(s);for(let s of a)l(s,null);for(let s=0;s<n;s++)!r.has(s)&&!a.includes(s)&&l(s,null);return i}function gi(t){return new TextDecoder().decode(t)}var hr=re().decoders;function xi(t,e){hr.set(t.toLowerCase(),e)}function Je(t){return hr.get(t.toLowerCase())}function dr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let i=n.getUint32(0,!0);if(i!==1179937895){let h=n.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${i.toString(16)}`)}let r=n.getUint32(4,!0);if(r!==2)throw new Error(`Unsupported GLB version: ${r}`);let o=n.getUint32(8,!0),u=12,l=null,a=null;for(;u+8<=o&&u+8<=e.byteLength;){let h=n.getUint32(u,!0),f=n.getUint32(u+4,!0),d=u+8;if(d+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+h} bytes, buffer has ${e.byteLength}`);if(f===1313821514){let b=new Uint8Array(e,d,h),g=gi(b);l=JSON.parse(g,(E,A)=>E==="__proto__"||E==="constructor"||E==="prototype"?void 0:A)}else f===5130562&&(a=e.slice(d,d+h));u=d+h}if(!l)throw new Error("Missing JSON chunk in GLB");let c=l.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!Je("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(c.includes("EXT_meshopt_compression")&&!Je("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(c.includes("KHR_texture_basisu")&&!Je("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let s=a||new ArrayBuffer(0),m={gltf:l,bin:s,animations:[]};for(let h of ce)h.onParseGLB?.(m);return m}function vi(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function Ce(t){if(vi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return dr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var fr=`#version 300 es
|
|
17
|
+
"use strict";var ThreeLiveBundle=(()=>{var Mn=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var bi=Object.prototype.hasOwnProperty;var yi=(t,e)=>{for(var n in e)Mn(t,n,{get:e[n],enumerable:!0})},gi=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pi(e))!bi.call(t,i)&&i!==n&&Mn(t,i,{get:()=>e[i],enumerable:!(r=fi(e,i))||r.enumerable});return t};var xi=t=>gi(Mn({},"__esModule",{value:!0}),t);var hr={};yi(hr,{AmbientLight:()=>pt,BoxGeometry:()=>ht,BufferAttribute:()=>re,BufferGeometry:()=>ve,Camera:()=>yt,CapsuleGeometry:()=>ln,CircleGeometry:()=>hn,Clock:()=>rn,Color:()=>Te,ConeGeometry:()=>Gt,CylinderGeometry:()=>Ne,DirectionalLight:()=>en,DodecahedronGeometry:()=>cn,Euler:()=>lt,Float32BufferAttribute:()=>zt,Group:()=>Qt,HemisphereLight:()=>vt,IcosahedronGeometry:()=>sn,InteractivityVM:()=>Tt,Light:()=>ze,Material:()=>Ce,MathUtils:()=>Ur,Matrix3:()=>Vt,Matrix4:()=>Be,Mesh:()=>Ze,MeshBasicMaterial:()=>jt,MeshLambertMaterial:()=>Kt,MeshPhongMaterial:()=>Zt,MeshPhysicalMaterial:()=>Jt,MeshStandardMaterial:()=>Ve,Object3D:()=>Se,OctahedronGeometry:()=>an,PerspectiveCamera:()=>tn,PlaneGeometry:()=>Wt,PointLight:()=>bt,PolyhedronFallbackGeometry:()=>He,Quaternion:()=>mt,RawShaderMaterial:()=>$r,RectAreaLight:()=>qr,RingGeometry:()=>mn,Scene:()=>gt,SceneQuotaValidator:()=>_e,ShaderMaterial:()=>xt,SphereGeometry:()=>dt,SpotLight:()=>dn,THREE:()=>wt,TetrahedronGeometry:()=>un,Texture:()=>ft,TextureLoader:()=>Yt,ThreeLiveElement:()=>De,ThreeView:()=>fe,TorusGeometry:()=>$t,TorusKnotGeometry:()=>qt,Uint16BufferAttribute:()=>Ht,Uint32BufferAttribute:()=>Xt,Vector2:()=>Ot,Vector3:()=>le,Vector4:()=>Bt,WebGLRenderer:()=>nn,activateAR:()=>En,authorScriptRunner:()=>et,buildSandboxWorkerSource:()=>Bn,clearAuthorWarnings:()=>Gr,contactShadowPlugin:()=>Et,createUSDZBlob:()=>Ke,crossFadeTo:()=>Xn,environmentMapPlugin:()=>jn,exportSceneToCanvas3D:()=>Un,exportSceneToGLB:()=>Nn,exportSceneToUSDZ:()=>Nr,generateUSDZ:()=>st,getARCapabilities:()=>Sn,getAllowClientScripts:()=>Vr,getAuthorWarnings:()=>Wr,getBestARMode:()=>di,getEnvironmentSH:()=>ei,getInteractivityVM:()=>An,getSandboxEngineSrc:()=>On,getSandboxIframeSrc:()=>Br,glbToUSDZ:()=>ot,hotspotPlugin:()=>Jn,interactivityPlugin:()=>nr,isAllowedSandboxEngineUrl:()=>Oe,isQuickLookSupported:()=>ur,isSceneViewerSupported:()=>lr,isWebXRSupported:()=>mr,keyframeAnimationPlugin:()=>Wn,materialsPlugin:()=>ir,morphPlugin:()=>Gn,noopProxy:()=>ct,parseAnimations:()=>Hn,parseSafeGltfPointer:()=>Rt,registerMaterialShader:()=>ci,sampleChannel:()=>tt,sceneToCanvas3D:()=>Ye,sceneToGLB:()=>it,sceneToUSDZ:()=>je,sendInteractivityEvent:()=>tr,setAllowClientScripts:()=>Oi,setEnvironmentSH:()=>yn,setMorphTargetWeight:()=>Kr,setSandboxEngineSrc:()=>Fi,setSandboxIframeSrc:()=>Ui,skinningPlugin:()=>qn,threeAuthorPlugin:()=>ut,threeMicroPlugin:()=>qi,toGLBData:()=>Fe,toTrustedWorkerScriptURL:()=>Or,validateSandboxWorkerMessage:()=>Vn,warnUnsupported:()=>we,webxrPlugin:()=>ar});function dr(t,e,n){let r=[],i=new Map,o=[],c=[],l=[],a=new Map,s=y=>{let w=i.get(y);return w===void 0&&(w=r.length,r.push({op:y}),i.set(y,w)),w},u=y=>{let w=a.get(y);return w===void 0&&(w=l.length,l.push({id:y}),a.set(y,w)),w},m=(y,w={})=>o.push({declaration:s(y),...w})-1,h=(y,w,g)=>c.push({id:y,type:w,value:g})-1,f=y=>({node:y,socket:"value"}),d=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(d&&typeof d=="object"){let y=Array.isArray(d.graphs)?d.graphs[d.graph??0]:d;if(y&&Array.isArray(y.nodes)){let w=Array.isArray(y.declarations)?y.declarations:[];for(let g of w)g?.op&&s(g.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let g of y.events||[])g?.id&&u(g.id);for(let g of y.nodes){if(!g||typeof g!="object")continue;let C=g.op||(typeof g.declaration=="number"?w[g.declaration]?.op:"");o.push(C?{...g,declaration:s(C)}:{...g})}}}let p=(y,w,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,w)}/${g}`:g==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${g}`,v=new Map;t.forEach((y,w)=>{typeof y?.name=="string"&&!v.has(y.name)&&v.set(y.name,w)});let _=(y,w)=>typeof y.target=="string"&&v.has(y.target)?v.get(y.target):typeof y.targetNode=="number"?y.targetNode:w,S=y=>{let w=t[y];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<t.length;y++){let w=t[y],g=w?.extras?.interactivity;if(!g||typeof g!="object")continue;let C=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,b=R=>{let E=Array.isArray(R)?R:[R],O=[];for(let F=0;F<E.length;F++){let M=E[F];if(!M||typeof M!="object")continue;let G=M.action||"interpolate",B=typeof M.duration=="number"?M.duration:.35;if(G==="toggleTransform"){let Q=M.property==="rotation"||M.property==="scale"?M.property:"translation",j=Q==="rotation"?w.rotation||[0,0,0,1]:Q==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],z=`/nodes/${y}/${Q}`,X=h(`__toggle_${y}_${F}`,"bool",!1),U=m("variable/get",{configuration:{variable:X}}),q=m("math/not",{values:{a:f(U)}}),Y=m("variable/set",{configuration:{variable:X},values:{value:f(q)}}),T=m("pointer/interpolate",{configuration:{pointer:z},values:{value:{value:Array.isArray(M.to)?M.to:j},duration:{value:B}}}),x=m("pointer/interpolate",{configuration:{pointer:z},values:{value:{value:Array.isArray(M.from)?M.from:j},duration:{value:B}}});o[Y].flows={out:{node:m("flow/branch",{values:{condition:f(U)},flows:{true:{node:T},false:{node:x}}})}},O.push(Y)}else if(G==="interpolate"){let Q=M.to??M.value;if(Q===void 0)continue;let j={value:{value:Q},duration:{value:B}};M.from!==void 0&&(j.from={value:M.from}),O.push(m("pointer/interpolate",{configuration:{pointer:typeof M.pointer=="string"?M.pointer:p(_(M,y),S(_(M,y)),M.property)},values:j}))}else if(G==="setProperty"){if(M.value===void 0)continue;O.push(m("pointer/set",{configuration:{pointer:typeof M.pointer=="string"?M.pointer:p(_(M,y),S(_(M,y)),M.property)},values:{value:{value:M.value}}}))}else if(G==="toggleVisibility"){let Q=_(M,y),j=h(`__vis_${Q}_${F}`,"bool",!0),z=m("variable/get",{configuration:{variable:j}}),X=m("math/not",{values:{a:f(z)}}),U=m("variable/set",{configuration:{variable:j},values:{value:f(X)}});o[U].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${Q}/extensions/KHR_node_visibility/visible`},values:{value:f(z)}})}},O.push(U)}else if(G==="cycleMaterialColor"&&Array.isArray(M.colors)&&M.colors.length>0){let Q=typeof M.duration=="number"?M.duration:.25,j=`/materials/${Math.max(0,C)}/pbrMetallicRoughness/baseColorFactor`,z=h(`__color_idx_${y}_${F}`,"int",0),X=m("variable/get",{configuration:{variable:z}}),U=m("math/add",{values:{a:f(X),b:{value:1}}}),q=m("math/rem",{values:{a:f(U),b:{value:M.colors.length}}}),Y=m("variable/set",{configuration:{variable:z},values:{value:f(q)}}),T={};for(let x=0;x<M.colors.length;x++){let D=M.colors[x],k=Array.isArray(D)&&D.length>=3?[D[0],D[1],D[2],D[3]??1]:[1,1,1,1];T[String(x)]={node:Q>0?m("pointer/interpolate",{configuration:{pointer:j},values:{value:{value:k},duration:{value:Q}}}):m("pointer/set",{configuration:{pointer:j},values:{value:{value:k}}})}}o[Y].flows={out:{node:m("flow/switch",{values:{selection:f(X)},flows:T})}},O.push(Y)}else if(G==="playAnimation")O.push(m("animation/start",{configuration:{animation:M.animation??M.clip??0}}));else if(G==="stopAnimation")O.push(m("animation/stop"));else if(G==="sendEvent"){let Q={};for(let[j,z]of Object.entries(M.values||{}))Q[j]={value:z};O.push(m("event/send",{configuration:{event:u(String(M.event??M.id??"custom"))},values:Q}))}}if(!O.length)return null;if(O.length===1)return O[0];let H={};return O.forEach((F,M)=>{H[String(M)]={node:F}}),m("flow/sequence",{flows:H})},A=(R,E,O)=>{let H=b(E);H!==null&&m(R,{...O?{configuration:O}:{},flows:{out:{node:H}}})};if(g.onSelect&&A("pointer/onSelect",g.onSelect,{nodeIndex:y}),g.onHoverIn&&A("pointer/onHoverIn",g.onHoverIn,{nodeIndex:y}),g.onHoverOut&&A("pointer/onHoverOut",g.onHoverOut,{nodeIndex:y}),g.onStart&&A("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[R,E]of Object.entries(g.onReceive))A("event/receive",E,{event:u(R)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:c,events:l}],graph:0}:null}var Ct='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',Dt="Security Error: client-side scripts require allow-client-scripts opt-in.";var It="__THREE_LIVE_REGISTRY__";function oe(){let t=typeof globalThis<"u"?globalThis:{};if(!t[It]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,It,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[It]=e}}return t[It]}var ce=oe().plugins;function ye(t){let e=oe().plugins;e.some(n=>n.name===t.name)||e.push(t)}function Pt(){return oe().plugins}function ae(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Lt(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let c=1/(r-i);return t[10]=(i+r)*c,t[14]=2*i*r*c,t}function $e(t,e,n,r){let[i,o,c]=e,[l,a,s]=r,[u,m,h]=n,f=i-u,d=o-m,p=c-h,v=Math.hypot(f,d,p);v<=1e-5?(f=0,d=0,p=1):(f/=v,d/=v,p/=v);let _=a*p-s*d,S=s*f-l*p,y=l*d-a*f;v=Math.hypot(_,S,y),v<=1e-5?(_=0,S=0,y=0):(_/=v,S/=v,y/=v);let w=d*y-p*S,g=p*_-f*y,C=f*S-d*_;return v=Math.hypot(w,g,C),v<=1e-5?(w=0,g=0,C=0):(w/=v,g/=v,C/=v),t[0]=_,t[1]=w,t[2]=f,t[3]=0,t[4]=S,t[5]=g,t[6]=d,t[7]=0,t[8]=y,t[9]=C,t[10]=p,t[11]=0,t[12]=-(_*i+S*o+y*c),t[13]=-(w*i+g*o+C*c),t[14]=-(f*i+d*o+p*c),t[15]=1,t}function ge(t,e,n){let r=e[0],i=e[1],o=e[2],c=e[3],l=e[4],a=e[5],s=e[6],u=e[7],m=e[8],h=e[9],f=e[10],d=e[11],p=e[12],v=e[13],_=e[14],S=e[15],y=n[0],w=n[1],g=n[2],C=n[3];return t[0]=y*r+w*l+g*m+C*p,t[1]=y*i+w*a+g*h+C*v,t[2]=y*o+w*s+g*f+C*_,t[3]=y*c+w*u+g*d+C*S,y=n[4],w=n[5],g=n[6],C=n[7],t[4]=y*r+w*l+g*m+C*p,t[5]=y*i+w*a+g*h+C*v,t[6]=y*o+w*s+g*f+C*_,t[7]=y*c+w*u+g*d+C*S,y=n[8],w=n[9],g=n[10],C=n[11],t[8]=y*r+w*l+g*m+C*p,t[9]=y*i+w*a+g*h+C*v,t[10]=y*o+w*s+g*f+C*_,t[11]=y*c+w*u+g*d+C*S,y=n[12],w=n[13],g=n[14],C=n[15],t[12]=y*r+w*l+g*m+C*p,t[13]=y*i+w*a+g*h+C*v,t[14]=y*o+w*s+g*f+C*_,t[15]=y*c+w*u+g*d+C*S,t}function qe(t,e,n,r){let i=e[0],o=e[1],c=e[2],l=e[3],a=i+i,s=o+o,u=c+c,m=i*a,h=i*s,f=i*u,d=o*s,p=o*u,v=c*u,_=l*a,S=l*s,y=l*u,w=r[0],g=r[1],C=r[2];return t[0]=(1-(d+v))*w,t[1]=(h+y)*w,t[2]=(f-S)*w,t[3]=0,t[4]=(h-y)*g,t[5]=(1-(m+v))*g,t[6]=(p+_)*g,t[7]=0,t[8]=(f+S)*C,t[9]=(p-_)*C,t[10]=(1-(m+d))*C,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function de(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],c=e[5],l=e[6],a=e[8],s=e[9],u=e[10],m=u*c-l*s,h=-u*o+l*a,f=s*o-c*a,d=n*m+r*h+i*f;return d&&(d=1/d,t[0]=m*d,t[1]=(-u*r+i*s)*d,t[2]=(l*r-i*c)*d,t[3]=h*d,t[4]=(u*n-i*a)*d,t[5]=(-l*n+i*o)*d,t[6]=f*d,t[7]=(-s*n+r*a)*d,t[8]=(c*n-r*o)*d),t}function Ft(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],c=e[4],l=e[5],a=e[6],s=e[7],u=e[8],m=e[9],h=e[10],f=e[11],d=e[12],p=e[13],v=e[14],_=e[15],S=n*l-r*c,y=n*a-i*c,w=n*s-o*c,g=r*a-i*l,C=r*s-o*l,b=i*s-o*a,A=u*p-m*d,R=u*v-h*d,E=u*_-f*d,O=m*v-h*p,H=m*_-f*p,F=h*_-f*v,M=S*F-y*H+w*O+g*E-C*R+b*A;return M?(M=1/M,t[0]=(l*F-a*H+s*O)*M,t[1]=(i*H-r*F-o*O)*M,t[2]=(p*b-v*C+_*g)*M,t[3]=(h*C-m*b-f*g)*M,t[4]=(a*E-c*F-s*R)*M,t[5]=(n*F-i*E+o*R)*M,t[6]=(v*w-d*b-_*y)*M,t[7]=(u*b-h*w+f*y)*M,t[8]=(c*H-l*E+s*A)*M,t[9]=(r*E-n*H-o*A)*M,t[10]=(d*C-p*w+_*S)*M,t[11]=(m*w-u*C-f*S)*M,t[12]=(l*R-c*O-a*A)*M,t[13]=(n*O-r*R+i*A)*M,t[14]=(p*y-d*g-v*S)*M,t[15]=(u*g-m*y+h*S)*M,t):null}function _n(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],c=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],a=i[3]*e+i[7]*n+i[11]*r+i[15],s=a!==0?1/a:1;t[0]=o*s,t[1]=c*s,t[2]=l*s}function fr(t,e,n,r,i,o,c,l,a,s,u,m,h,f,d,p,v=0){let _=s-c,S=u-l,y=m-a,w=h-c,g=f-l,C=d-a,b=i*C-o*g,A=o*w-r*C,R=r*g-i*w,E=_*b+S*A+y*R;if(E>-1e-7&&E<1e-7)return!1;let O=1/E,H=t-c,F=e-l,M=n-a,G=O*(H*b+F*A+M*R);if(G<-v||G>1+v)return!1;let B=F*y-M*S,Q=M*_-H*y,j=H*S-F*_,z=O*(r*B+i*Q+o*j);if(z<-v||G+z>1+v)return!1;let X=O*(w*B+g*Q+C*j);if(X>1e-4&&X<p.distance){p.distance=X,p.point=[t+r*X,e+i*X,n+o*X];let U=S*C-y*g,q=y*w-_*C,Y=_*g-S*w,T=Math.hypot(U,q,Y)||1;return p.normal=[U/T,q/T,Y/T],!0}return!1}function Le(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(ae());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let m of u.children)i.add(m);let o=new Set,c=128,l=(u,m,h=0)=>{if(h>c||u<0||u>=n||o.has(u))return;o.add(u);let f=t.nodes[u];if(!f)return;let d=ae();if(e&&e[u])d.set(e[u]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let v=f.translation||[0,0,0],_=f.rotation||[0,0,0,1],S=f.scale||[1,1,1];qe(d,_,v,S)}let p=r[u];if(m?ge(p,m,d):p.set(d),Array.isArray(f.children))for(let v of f.children)typeof v=="number"&&l(v,p,h+1)},a=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))a.push(...s.nodes);else for(let u=0;u<n;u++)i.has(u)||a.push(u);for(let u of a)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!a.includes(u)&&l(u,null);return r}function vi(t){return new TextDecoder().decode(t)}var yr=oe().decoders;function wi(t,e){yr.set(t.toLowerCase(),e)}function rt(t){return yr.get(t.toLowerCase())}function gr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let h=n.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),c=12,l=null,a=null;for(;c+8<=o&&c+8<=e.byteLength;){let h=n.getUint32(c,!0),f=n.getUint32(c+4,!0),d=c+8;if(d+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+h} bytes, buffer has ${e.byteLength}`);if(f===1313821514){let p=new Uint8Array(e,d,h),v=vi(p);l=JSON.parse(v,(_,S)=>_==="__proto__"||_==="constructor"||_==="prototype"?void 0:S)}else f===5130562&&(a=e.slice(d,d+h));c=d+h}if(!l)throw new Error("Missing JSON chunk in GLB");let s=l.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!rt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!rt("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!rt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),m={gltf:l,bin:u,animations:[]};for(let h of ce)h.onParseGLB?.(m);return m}function Ai(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function Fe(t){if(Ai(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return gr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var xr=`#version 300 es
|
|
18
18
|
layout(location=0) in vec3 aPosition;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
20
20
|
layout(location=2) in vec2 aUV;
|
|
@@ -32,7 +32,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
32
32
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
33
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
34
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
-
}`,
|
|
35
|
+
}`,vr=`#version 300 es
|
|
36
36
|
precision highp float;
|
|
37
37
|
in vec3 vNormal,vWorldPos;
|
|
38
38
|
in vec2 vUV;
|
|
@@ -45,6 +45,8 @@ uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclu
|
|
|
45
45
|
uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
|
|
46
46
|
uniform mat4 uXrDepthUVTransform;
|
|
47
47
|
uniform vec2 uViewportSize;
|
|
48
|
+
uniform vec4 uViewport;
|
|
49
|
+
uniform vec3 uCameraFwd;
|
|
48
50
|
uniform int uToneMapping,uNumDirLights,uNumPointLights;
|
|
49
51
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
|
|
50
52
|
out vec4 fragColor;
|
|
@@ -195,36 +197,39 @@ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
|
195
197
|
color=applyToneMapping(color,uToneMapping);
|
|
196
198
|
float outAlpha=base.a;
|
|
197
199
|
if(uXrDepthEnabled==1){
|
|
198
|
-
vec2 normViewUV=gl_FragCoord.
|
|
200
|
+
vec2 normViewUV=vec2((gl_FragCoord.x-uViewport.x)/max(uViewport.z,1.0),1.0-(gl_FragCoord.y-uViewport.y)/max(uViewport.w,1.0));
|
|
199
201
|
vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
|
|
202
|
+
if(depthUV.x>=0.0&&depthUV.x<=1.0&&depthUV.y>=0.0&&depthUV.y<=1.0){
|
|
200
203
|
vec4 depthSample=texture(uXrDepthTex,depthUV);
|
|
201
|
-
float
|
|
202
|
-
float
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
float rawDepth=uXrDepthFormat==1?depthSample.r:(depthSample.r*255.0+depthSample.a*65280.0);
|
|
205
|
+
float realDepth=rawDepth*uXrRawValueToMeters;
|
|
206
|
+
float virtDepth=dot(uCameraFwd,uCameraFwd)>0.5?dot(vWorldPos-uCameraPos,uCameraFwd):length(uCameraPos-vWorldPos);
|
|
207
|
+
if(rawDepth>0.0&&(uXrDepthFormat==1||rawDepth<65500.0)&&realDepth>0.15&&realDepth<20.0&&virtDepth>realDepth+0.02){
|
|
208
|
+
float occAlpha=1.0-smoothstep(0.0,0.035,virtDepth-realDepth-0.02);
|
|
205
209
|
outAlpha*=occAlpha;
|
|
206
210
|
if(outAlpha<0.01)discard;
|
|
207
211
|
}
|
|
208
212
|
}
|
|
213
|
+
}
|
|
209
214
|
fragColor=vec4(color,outAlpha);
|
|
210
|
-
}`,
|
|
215
|
+
}`,Ri=`#version 300 es
|
|
211
216
|
layout(location=0) in vec3 aPosition;
|
|
212
217
|
uniform mat4 uMVP;
|
|
213
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
218
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Ti=`#version 300 es
|
|
214
219
|
precision highp float;
|
|
215
220
|
uniform vec4 uColorId;
|
|
216
221
|
out vec4 fragColor;
|
|
217
|
-
void main(){fragColor=uColorId;}`;function lr(t,e,n){let i=t.createShader(e);if(t.shaderSource(i,n),t.compileShader(i),!t.getShaderParameter(i,35713)){let r=t.getShaderInfoLog(i);throw t.deleteShader(i),new Error(`Shader compile error: ${r}`)}return i}function Sn(t,e,n){let i=lr(t,35633,e),r=lr(t,35632,n),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,r),t.linkProgram(o),!t.getProgramParameter(o,35714)){let u=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${u}`)}return o}function Mn(t,e,n){let i={};for(let r of n)i[r]=t.getUniformLocation(e,r);return i}var br=["uMVP","uModel","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","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize"];function Ti(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function En(t,e,n,i,r,o,u){if(i===void 0||!e.accessors?.[i])return null;let l=e.accessors[i],a=e.bufferViews[l.bufferView],c=(a.byteOffset||0)+(l.byteOffset||0),s=a.byteStride&&a.byteStride>o*4?a.byteStride>>2:o,m;if(s===o)m=new Float32Array(n,c,l.count*o);else{m=new Float32Array(l.count*o);let f=new Float32Array(n,a.byteOffset||0,Math.floor(a.byteLength/4)),d=(l.byteOffset||0)>>2;for(let b=0;b<l.count;b++){let g=d+b*s;for(let E=0;E<o;E++)m[b*o+E]=f[g+E]}}let h=t.createBuffer();return u.push(h),t.bindBuffer(34962,h),t.bufferData(34962,m,35044),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,o,5126,!1,0,0),m}var yr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),gr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function mr(t,e,n=gr,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r,bin:o}=e,u=[],l=_e(r),a=[];if(Array.isArray(r.nodes))for(let w=0;w<r.nodes.length;w++){let T=r.nodes[w];T.mesh!==void 0&&r.meshes&&r.meshes[T.mesh]&&a.push({node:T,nodeIdx:w,meshIdx:T.mesh})}let c=a.length>0?a:(r.meshes||[]).map((w,T)=>({node:w,nodeIdx:-1,meshIdx:T})),s=[];if(Array.isArray(e.lights)&&e.lights.length>0)s.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let w=r.extensions.KHR_lights_punctual.lights;for(let T of w){let I=T.type==="directional"?"directional":T.type==="point"?"point":"ambient";s.push({type:I,color:T.color||[1,1,1],intensity:T.intensity!==void 0?T.intensity:1})}}if(s.length===0&&(s.push({type:"ambient",color:[1,1,1],intensity:.35}),s.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),c.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${c.length}`);let m=[];if(r.textures&&r.images){if(r.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${r.textures.length}`);for(let w=0;w<r.textures.length;w++){let T=r.textures[w],I=r.images[T.source];if(I){let B=t.createTexture();if(t.bindTexture(3553,B),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),I.bufferView!==void 0){let P=r.bufferViews[I.bufferView],N=o.slice(P.byteOffset||0,(P.byteOffset||0)+P.byteLength),_=new Blob([N],{type:I.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(_).then(q=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,q),t.generateMipmap(3553),i?.()}).catch(()=>{})}else if(I.uri){let P=Ti(I.uri);if(P){let N=new Image;N.crossOrigin="anonymous",N.referrerPolicy="no-referrer",N.onload=()=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,N),t.generateMipmap(3553),i?.()},N.src=P}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",I.uri)}m.push(B)}else m.push(null)}}let h=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],d=0,b=0;for(let w=0;w<c.length;w++){let T=c[w],I=r.meshes[T.meshIdx],B=T.nodeIdx>=0?l[T.nodeIdx]:se(),P=new Float32Array(9);ue(P,B);let N={name:T.node.name||I.name||`Mesh_${T.meshIdx}`,nodeIndex:T.nodeIdx,transform:B,normalMatrix:P,primitives:[],extras:T.node.extras||I.extras};for(let _ of I.primitives||[]){if(_.extensions?.KHR_draco_mesh_compression){let ne=Je("draco");ne&&ne.decodePrimitive(r,_,o)}let q=[],J=t.createVertexArray();t.bindVertexArray(J);let Z=r.accessors[_.attributes.POSITION],j=Number(Z?.count??0);if(!Number.isFinite(j)||j<0||d+j>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(d+=j,Z?.min&&Z?.max)for(let ne=0;ne<3;ne++){let xe=B[12+ne],Be=B[12+ne];for(let Me=0;Me<3;Me++){let wt=B[Me*4+ne]*Z.min[Me],At=B[Me*4+ne]*Z.max[Me];xe+=wt<At?wt:At,Be+=wt>At?wt:At}xe<h[ne]&&(h[ne]=xe),Be>f[ne]&&(f[ne]=Be)}let V=En(t,r,o,_.attributes.POSITION,0,3,q);En(t,r,o,_.attributes.NORMAL,1,3,q),En(t,r,o,_.attributes.TEXCOORD_0,2,2,q);let X=0,k=5123,W=null;if(_.indices!==void 0){let ne=r.accessors[_.indices],Be=(r.bufferViews[ne.bufferView].byteOffset||0)+(ne.byteOffset||0);if(X=Number(ne.count??0),!Number.isFinite(X)||X<0||b+X>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);b+=X,k=ne.componentType===5125?5125||5125:5123||5123;let Me=t.createBuffer();q.push(Me),t.bindBuffer(34963,Me),ne.componentType===5125?(W=new Uint32Array(o,Be,ne.count),t.bufferData(34963,W,35044)):(W=new Uint16Array(o,Be,ne.count),t.bufferData(34963,W,35044))}else X=Z.count;let G={};for(let ne of ce)if(ne.onBuildPrimitiveVAO){let xe=ne.onBuildPrimitiveVAO(t,J,_,r,o);xe&&(G[ne.name]=xe)}t.bindVertexArray(null);let S=r.materials&&_.material!==void 0?r.materials[_.material]:null,v=fr,L=pr,U=!1;for(let ne of ce)if(ne.onResolveShader){let xe=ne.onResolveShader(_,S,v,L);xe&&(v=xe.vs,L=xe.fs,U=!0)}let M=U?Sn(t,v,L):null,D=M?Mn(t,M,br):null,C=S?.pbrMetallicRoughness,O=C?.baseColorFactor||[.8,.8,.8,1],Y=C?.metallicFactor??.1,K=C?.roughnessFactor??.5,Q=S?.extensions?.KHR_materials_clearcoat,z=Q?Q.clearcoatFactor??1:0,$=Math.max(.04,Q?.clearcoatRoughnessFactor??.04),oe=C?.baseColorTexture!==void 0&&m[C.baseColorTexture.index]?m[C.baseColorTexture.index]:null,he=C?.metallicRoughnessTexture!==void 0&&m[C.metallicRoughnessTexture.index]?m[C.metallicRoughnessTexture.index]:null,vt=S?.normalTexture!==void 0&&m[S.normalTexture.index]?m[S.normalTexture.index]:null,An=S?.normalTexture?.scale??1,Ze=S?.occlusionTexture!==void 0&&m[S.occlusionTexture.index]?m[S.occlusionTexture.index]:null,li=S?.occlusionTexture?.strength??1,mi=!!(S?.extensions?.KHR_materials_transmission||G.materials?.isTransmissive);N.primitives.push({vao:J,indexCount:X,indexType:k,baseColor:O,metallic:Y,roughness:K,clearcoat:z,clearcoatRoughness:$,positions:V,indices:W,texture:oe,metallicRoughnessTexture:he,normalTexture:vt,occlusionTexture:Ze,normalScale:An,occlusionStrength:li,buffers:q,materialIndex:_.material,pluginData:G,customProgram:M,customUniforms:D,isTransmissive:mi})}u.push(N)}isFinite(h[0])||(h=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let g=[(h[0]+f[0])/2,(h[1]+f[1])/2,(h[2]+f[2])/2],E=f[0]-h[0],A=f[1]-h[1],p=f[2]-h[2],R=Math.max(Math.hypot(E,A,p)/2,.5),x=[h[0],h[1],h[2]],F=[f[0],f[1],f[2]],y=e.animations;if(!y){for(let w of ce)if(w.onParseGLB?.(e),e.animations){y=e.animations;break}}return y||(y=[]),{meshes:u,bounds:{center:g,radius:R,min:x,max:F},lights:s,animations:y,worldMatrices:l}}var me=class{constructor(e,n,i){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=se();this.clearColor=[0,0,0,0];this.envIntensity=1;this.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.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=se();this.viewMatrix=se();this.modelMatrix=se();this.mvpMatrix=se();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.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.xrDepthState={enabled:!1,texture:null,uvTransform:se(),rawValueToMeters:.001,format:0};this.container=e;let r,o;if(n&&typeof n.getContext=="function"?(r=n,o=i):(o=n,r=o?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let u=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!u:u&&(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.envIntensity=Math.max(0,Number(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=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.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 l=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.renderProg=Sn(l,fr,pr),this.pickProg=Sn(l,wi,Ai),this.uRender=Mn(l,this.renderProg,br),this.uPick=Mn(l,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){xi(e,n)}static getDecoder(e){return Je(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,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,n){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=r,this.pickFboHeight=o,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,o,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,o)}loadGLBData(e,n){let{meshes:i,bounds:r,lights:o,animations:u,worldMatrices:l}=mr(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=u||[],this.worldMatrices=l||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let c of e.gltf.nodes)this.initialNodeTransforms.push({t:c.translation?[c.translation[0],c.translation[1],c.translation[2]]:[0,0,0],r:c.rotation?[c.rotation[0],c.rotation[1],c.rotation[2],c.rotation[3]]:[0,0,0,1],s:c.scale?[c.scale[0],c.scale[1],c.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let c of ce)c.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 a=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;a!==void 0&&(this.envIntensity=Math.max(0,Number(a))),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(dr(e))}loadModel(e){this.loadGLBData(Ce(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Ce(e),{meshes:r}=mr(this.gl,i,gr,()=>this.render());if(n)for(let o of r)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],ue(o.normalMatrix,o.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,n,i,r=1){this.clearColor=[e,n,i,r]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let i=this.meshes[n],r;e instanceof Map?r=e.get(i.name)??e.get(n):Array.isArray(e)?r=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,n)&&(r=e[n])),r&&r.length===16&&(i.transform.set(r),ue(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let n=this.gl,i=[.28,.28,.28],r=[],o=[],u=[],l=[];for(let a of this.lights){let c=a.color||[1,1,1],s=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")i=[c[0]*s,c[1]*s,c[2]*s];else if(a.type==="directional"&&r.length<6){let m=a.direction||[.5,1,.8];r.push(m[0],m[1],m[2]),o.push(c[0]*s,c[1]*s,c[2]*s)}else if(a.type==="point"&&u.length<6){let m=a.position||[0,0,0];u.push(m[0],m[1],m[2]),l.push(c[0]*s,c[1]*s,c[2]*s)}}r.length===0&&(r.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,i),n.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(n.uniform3fv(e.uDirLightDir,r),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,u.length/3),u.length>0&&(n.uniform3fv(e.uPointLightPos,u),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ce)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ce)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,i=this.currDistance;return{theta:e,phi:n,radius:i,toString(){return`${e.toFixed(4)}rad ${n.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((n,i)=>{let r=this.meshes.flatMap(s=>s.primitives.filter(m=>m.materialIndex===i||e.length===1&&m.materialIndex===void 0)),o=r[0],u=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:u,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:s=>{let m=[s[0],s[1],s[2],s[3]??1];c.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let h of r)h.baseColor=m;this.render()},setMetallicFactor:s=>{c.metallicFactor=s,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=s);for(let m of r)m.metallic=s;this.render()},setRoughnessFactor:s=>{c.roughnessFactor=s,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=s);for(let m of r)m.roughness=s;this.render()}};return{name:n.name||`Material_${i}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(i=>i.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}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 n of ce)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,i){this.customTarget=[e,n,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 n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=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(n,Math.min(i,e))}setCamera(e,n,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*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,n,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let o=this.clampDistance(i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(r!==void 0&&r>0){let o=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let i=se();pe(i,this.projMatrix,this.viewMatrix);let[r,o,u]=e,l=n?n[0]:0,a=n?n[1]:0,c=n?n[2]:0,s=this.modelRootMatrix;s&&(r=s[0]*e[0]+s[4]*e[1]+s[8]*e[2]+s[12],o=s[1]*e[0]+s[5]*e[1]+s[9]*e[2]+s[13],u=s[2]*e[0]+s[6]*e[1]+s[10]*e[2]+s[14],n&&(l=s[0]*n[0]+s[4]*n[1]+s[8]*n[2],a=s[1]*n[0]+s[5]*n[1]+s[9]*n[2],c=s[2]*n[0]+s[6]*n[1]+s[10]*n[2]));let m=i[0]*r+i[4]*o+i[8]*u+i[12],h=i[1]*r+i[5]*o+i[9]*u+i[13],f=i[2]*r+i[6]*o+i[10]*u+i[14],d=i[3]*r+i[7]*o+i[11]*u+i[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let b=m/d,g=h/d,E=f/d,A=this.canvas.getBoundingClientRect(),p=A.width||this.canvas.clientWidth||this.canvas.width||300,R=A.height||this.canvas.clientHeight||this.canvas.height||150,x=(b*.5+.5)*p,F=(-g*.5+.5)*R,y=b>=-1.1&&b<=1.1&&g>=-1.1&&g<=1.1&&E>=-1&&E<=1;if(y&&n){let w=this.customTarget||this.bounds.center,T=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),I=w[1]+this.currDistance*Math.sin(this.currPhi),B=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),P=[r-T,o-I,u-B];l*P[0]+a*P[1]+c*P[2]>.05&&(y=!1)}return{x,y:F,z:E,visible:y}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let i=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},r=n.clientX-i.x,o=n.clientY-i.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(r,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let u=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-r*u[0]+o*l[0])*c,a[1]+=(-r*u[1]+o*l[1])*c,a[2]+=(-r*u[2]+o*l[2])*c,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-r*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let i=e.getBoundingClientRect(),r=Math.floor((n.clientX-i.left)*(e.width/Math.max(i.width,1))),o=Math.floor((n.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(r,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let i=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let i=n.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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=n=>{if(!this.interactive)return;let i=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=i,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let i=this.canvas,r=i.getBoundingClientRect(),o=i.width||300,u=i.height||300,l=r.width>0?Math.floor((e-r.left)*(o/r.width)):Math.floor(e),a=r.height>0?Math.floor((n-r.top)*(u/r.height)):Math.floor(n);return this.performMeshPick(l,a,!1)}performMeshPick(e,n,i=!0){if(this.meshes.length===0)return null;let r=this.gl,o=Math.max(1,this.canvas.width||300),u=Math.max(1,this.canvas.height||300),l=se();pe(l,this.projMatrix,this.viewMatrix);let a=[],c=Math.max(0,Math.min(o-1,e)),s=Math.max(0,Math.min(u-1,u-1-n));if(this.pickFbo&&r){(this.pickFboWidth!==o||this.pickFboHeight!==u)&&this.resizePickingFbo(o,u),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,o,u),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16384|256),r.useProgram(this.pickProg);for(let y=0;y<this.meshes.length;y++){let w=this.meshes[y];if(w.visible===!1||w.isPluginMesh)continue;let T=y+1,I=(T&255)/255,B=(T>>8&255)/255,P=(T>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,B,P,1),pe(this.modelMatrix,this.modelRootMatrix,w.transform),pe(this.mvpMatrix,l,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let N of w.primitives)r.bindVertexArray(N.vao),r.drawElements(4,N.indexCount,N.indexType,0)}let x=new Uint8Array(4);r.readPixels(c,s,1,1,6408,5121,x),r.bindFramebuffer(36160,null);let F=x[0]+(x[1]<<8)+(x[2]<<16);F>0&&F<=this.meshes.length&&(a=[this.meshes[F-1]])}a.length===0&&(a=this.meshes.filter(x=>x.visible!==!1));let m=null,h=1/0,f=[0,0,0],d=[0,1,0],b=this.customTarget||this.bounds.center,g=b[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),E=b[1]+this.currDistance*Math.sin(this.currPhi),A=b[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let x of a){pe(this.modelMatrix,this.modelRootMatrix,x.transform),pe(this.mvpMatrix,l,this.modelMatrix);let F=se();if(!_t(F,this.mvpMatrix))continue;let y=(c+.5)/o*2-1,w=(s+.5)/u*2-1,T=[0,0,0],I=[0,0,0];Rn(T,y,w,-1,F),Rn(I,y,w,1,F);let B=I[0]-T[0],P=I[1]-T[1],N=I[2]-T[2],_=Math.hypot(B,P,N)||1,q=B/_,J=P/_,Z=N/_,j={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((X=>{for(let k of x.primitives){if(!k.positions)continue;let W=k.positions,G=k.indices,S=Math.floor(G?G.length/3:W.length/9);for(let v=0;v<S;v++){let L=G?G[v*3]:v*3,U=G?G[v*3+1]:v*3+1,M=G?G[v*3+2]:v*3+2;ur(T[0],T[1],T[2],q,J,Z,W[L*3],W[L*3+1],W[L*3+2],W[U*3],W[U*3+1],W[U*3+2],W[M*3],W[M*3+1],W[M*3+2],j,X)}}})(1e-4),isFinite(j.distance)){let X=j.point[0],k=j.point[1],W=j.point[2],G=this.modelMatrix,S=G[0]*X+G[4]*k+G[8]*W+G[12],v=G[1]*X+G[5]*k+G[9]*W+G[13],L=G[2]*X+G[6]*k+G[10]*W+G[14],U=S-g,M=v-E,D=L-A,C=Math.hypot(U,M,D);if(C<h){ue(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,Y=j.normal[0],K=j.normal[1],Q=j.normal[2],z=O[0]*Y+O[3]*K+O[6]*Q,$=O[1]*Y+O[4]*K+O[7]*Q,oe=O[2]*Y+O[5]*K+O[8]*Q,he=Math.hypot(z,$,oe)||1;z/=he,$/=he,oe/=he,z*U+$*M+oe*D>0&&(z=-z,$=-$,oe=-oe),m=x,h=Math.round(C*1e3)/1e3,f=[Math.round(S*1e3)/1e3,Math.round(v*1e3)/1e3,Math.round(L*1e3)/1e3],d=[Math.round(z*1e3)/1e3,Math.round($*1e3)/1e3,Math.round(oe*1e3)/1e3]}}}if(!m)return null;let R={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:h,hitPoint:f,normal:d,screenX:e,screenY:n};if(i){for(let x of ce)x.onMeshSelect?.(this,R);this.opts.onMeshClick&&this.opts.onMeshClick(R),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:R}))}return R}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(n.width*e)),r=Math.max(1,Math.floor(n.height*e));(this.canvas.width!==i||this.canvas.height!==r)&&(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r))}start(){if(this.animFrameId!==null)return;this.lastTime=performance.now();let e=n=>{let i=Math.min((n-this.lastTime)/1e3,.1);this.lastTime=n,this.isVisible&&(this.resize(),this.update(i),this.render()),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),n=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=i-(e*i+n*r),o[13]=0,o[14]=r-(-n*i+e*r),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let h of ce)h.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let h of ce)h.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;let i=(this.canvas.width||1)/(this.canvas.height||1),r=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):this.bounds.radius*20;cr(this.projMatrix,this.fov,i,.1,r);let o=this.customTarget||this.bounds.center,u=o[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),l=o[1]+this.currDistance*Math.sin(this.currPhi),a=o[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Mt(this.viewMatrix,[u,l,a],o,[0,1,0]),pe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ue(this.normalMatrix,this.modelMatrix);let c=Math.round((this.currTheta*180/Math.PI%360+360)%360),s=Math.round(this.currPhi*180/Math.PI),m=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(c-this.lastReportedTheta)>=1||Math.abs(s-this.lastReportedPhi)>=1||Math.abs(m-this.lastReportedZoom)>=.02){this.lastReportedTheta=c,this.lastReportedPhi=s,this.lastReportedZoom=m;let h={theta:c,phi:s,zoom:m,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(h),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:h}))}}renderXRView(e,n,i,r){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let o=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,a=l?[l.x,l.y,l.z]:[0,1.6,0];i&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:o,projMatrix:u,eyePos:a,viewport:r,eye:e?.eye||"none",clear:e?.eye!=="right"})}render(e){let n=this.gl,i=this.canvas.width,r=this.canvas.height;e?.viewport?(n.viewport(e.viewport[0],e.viewport[1],e.viewport[2],e.viewport[3]),i=e.viewport[2],r=e.viewport[3]):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let o=se();pe(o,e?.projMatrix??this.projMatrix,e?.viewMatrix??this.viewMatrix);let u=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,l=this.customTarget||this.bounds.center,a=e?e.eyePos[0]:l[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),c=e?e.eyePos[1]:l[1]+this.currDistance*Math.sin(this.currPhi),s=e?e.eyePos[2]:l[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let g of ce)g.onBeforeDrawScene?.(this,n,o,[a,c,s],u);if(this.meshes.length===0&&this.backdropMeshes.length===0)return;let m=e?.eye||"none",h=!1,f=this.backdropMeshes.length,d=f>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=g=>{for(let E=0;E<d.length;E++){let A=d[E];if(A.visible===!1)continue;let p=this.selectedMeshName!==""&&A.name===this.selectedMeshName;E<f?this.modelMatrix.set(A.transform):pe(this.modelMatrix,this.modelRootMatrix,A.transform),pe(this.mvpMatrix,o,this.modelMatrix),ue(A.normalMatrix,this.modelMatrix);let R=A.extras?.xr?.stereo||A.userData?.xr?.stereo,x=0,F=0,y=1,w=1;R==="sbs"?(y=.5,x=m==="right"?.5:0):R==="ou"&&(w=.5,F=m==="right"?.5:0);for(let T of A.primitives){let I=!!T.isTransmissive;if(!g&&I){h=!0;continue}if(g&&!I)continue;let B=T.customProgram||this.renderProg,P=T.customUniforms||this.uRender;n.useProgram(B),n.uniform1i(P.uToneMapping,u),n.uniform1f(P.uEnvIntensity,this.envIntensity),n.uniform3f(P.uCameraPos,a,c,s),n.uniform1f(P.uEmissive,p?1:0),n.uniformMatrix4fv(P.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(P.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(P.uNormalMatrix,!1,A.normalMatrix),P.uUvTransform&&n.uniform4f(P.uUvTransform,x,F,y,w),P.uViewportSize&&n.uniform2f(P.uViewportSize,Math.max(1,i),Math.max(1,r)),this.xrDepthState.enabled&&this.xrDepthState.texture?(n.activeTexture(33989),n.bindTexture(3553,this.xrDepthState.texture),P.uXrDepthTex&&n.uniform1i(P.uXrDepthTex,5),P.uXrDepthEnabled&&n.uniform1i(P.uXrDepthEnabled,1),P.uXrDepthFormat&&n.uniform1i(P.uXrDepthFormat,this.xrDepthState.format||0),P.uXrRawValueToMeters&&n.uniform1f(P.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),P.uXrDepthUVTransform&&n.uniformMatrix4fv(P.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):P.uXrDepthEnabled&&n.uniform1i(P.uXrDepthEnabled,0),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(P.uEnvironmentMap,4),n.uniform1i(P.uHasEnvironmentMap,1)):n.uniform1i(P.uHasEnvironmentMap,0),this.bindLights(P);for(let N of ce)N.onBeforeDrawPrimitive?.(n,B,T,A,this.worldMatrices||[],this.gltf);n.uniform4fv(P.uBaseColor,T.baseColor),n.uniform1f(P.uMetallic,T.metallic),n.uniform1f(P.uRoughness,T.roughness),P.uClearcoat&&n.uniform2f(P.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(n.activeTexture(33984),n.bindTexture(3553,T.texture),n.uniform1i(P.uBaseColorTexture,0),n.uniform1i(P.uHasTexture,1)):n.uniform1i(P.uHasTexture,0),T.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,T.metallicRoughnessTexture),n.uniform1i(P.uMetallicRoughnessTexture,1),n.uniform1i(P.uHasMetallicRoughnessTexture,1)):n.uniform1i(P.uHasMetallicRoughnessTexture,0),T.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,T.normalTexture),n.uniform1i(P.uNormalTexture,2),n.uniform1i(P.uHasNormalTexture,1),n.uniform1f(P.uNormalScale,T.normalScale)):n.uniform1i(P.uHasNormalTexture,0),T.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,T.occlusionTexture),n.uniform1i(P.uOcclusionTexture,3),n.uniform1i(P.uHasOcclusionTexture,1),n.uniform1f(P.uOcclusionStrength,T.occlusionStrength)):n.uniform1i(P.uHasOcclusionTexture,0),n.bindVertexArray(T.vao),n.drawElements(4,T.indexCount,T.indexType,0)}}};if(b(!1),h){for(let g of ce)g.onBeforeTransmissivePass?.(n,this);b(!0)}for(let g of ce)g.onAfterRender?.(n,this,o)}disposeMeshListGpuResources(e){let n=this.gl;for(let i of e)for(let r of i.primitives){if(r.vao&&n.deleteVertexArray(r.vao),r.buffers)for(let o of r.buffers)n.deleteBuffer(o);r.texture&&n.deleteTexture(r.texture),r.metallicRoughnessTexture&&n.deleteTexture(r.metallicRoughnessTexture),r.normalTexture&&n.deleteTexture(r.normalTexture),r.occlusionTexture&&n.deleteTexture(r.occlusionTexture),r.customProgram&&n.deleteProgram(r.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ce)n.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()}};me.registerPlugin=fe,me.getRegisteredPlugins=St;function Ri(t){return t+3&-4}function Ei(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function ze(t,e){t.updateMatrixWorld(!0);let n=[],i=0,r=[],o=[],u=[],l=[],a=new Set,c=[],s=[],m=new Map,h=[];function f(y,w){let T=new Uint8Array(y.buffer,y.byteOffset,y.byteLength),I=Ri(T.byteLength),B=new Uint8Array(I);B.set(T),n.push(B);let P=r.length;return r.push({buffer:0,byteOffset:i,byteLength:T.byteLength,target:w}),i+=I,P}function d(y,w,T,I,B,P,N){let _=f(y,T),q=o.length,J={bufferView:_,byteOffset:0,componentType:I,count:B,type:w};return P&&(J.min=P),N&&(J.max=N),o.push(J),q}t.traverse(y=>{(y.isLight||y.color&&y.intensity!==void 0)&&h.push({type:y.type,color:[y.color.r,y.color.g,y.color.b],intensity:y.intensity,position:[y.position.x,y.position.y,y.position.z]})});let b=[];function g(y){let w={name:y.name||""},T=y.position,I=y.quaternion,B=y.scale;if((T.x||T.y||T.z)&&(w.translation=[T.x,T.y,T.z]),(I.x||I.y||I.z||I.w!==1)&&(w.rotation=[I.x,I.y,I.z,I.w]),(B.x!==1||B.y!==1||B.z!==1)&&(w.scale=[B.x,B.y,B.z]),y.userData&&Object.keys(y.userData).length>0&&(w.extras=JSON.parse(JSON.stringify(y.userData,(N,_)=>{if(!(N==="__proto__"||N==="prototype"||N==="constructor"))return typeof _=="function"?void 0:_})),y.userData.xr)){let N=Ei(y.userData.xr);w.extensions={...w.extensions||{},MOZ_hubs_components:N,ANDROID_xr_scenecore:N},re().xrTraitSerializer?.gltfNode(w,y.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(y.geometry){let N=y.geometry,_=N.attributes.position;if(_&&_.count>0){let q=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0];for(let X=0;X<_.count;X++){let k=_.getX(X),W=_.getY(X),G=_.getZ(X);k<q[0]&&(q[0]=k),k>J[0]&&(J[0]=k),W<q[1]&&(q[1]=W),W>J[1]&&(J[1]=W),G<q[2]&&(q[2]=G),G>J[2]&&(J[2]=G)}let j={attributes:{POSITION:d(_.array,"VEC3",34962,5126,_.count,q,J)}};if(N.attributes.normal&&(j.attributes.NORMAL=d(N.attributes.normal.array,"VEC3",34962,5126,N.attributes.normal.count)),N.attributes.uv&&(j.attributes.TEXCOORD_0=d(N.attributes.uv.array,"VEC2",34962,5126,N.attributes.uv.count)),N.index){let X=N.index.array instanceof Uint32Array;j.indices=d(N.index.array,"SCALAR",34963,X?5125:5123,N.index.count)}if(y.material){let X=m.get(y.material);if(X===void 0){X=s.length,m.set(y.material,X);let k=y.material,W={name:k.name||"",pbrMetallicRoughness:{baseColorFactor:[k.color.r,k.color.g,k.color.b,k.opacity],metallicFactor:k.metalness,roughnessFactor:k.roughness},doubleSided:k.side===2||k.doubleSided};if(k.emissive&&(k.emissive.r>0||k.emissive.g>0||k.emissive.b>0)){let S=k.emissiveIntensity??1;W.emissiveFactor=[k.emissive.r*S,k.emissive.g*S,k.emissive.b*S]}let G={};k.clearcoat>0&&(G.KHR_materials_clearcoat={clearcoatFactor:k.clearcoat,clearcoatRoughnessFactor:k.clearcoatRoughness||0}),k.sheen>0&&(G.KHR_materials_sheen={sheenColorFactor:k.sheenColor?[k.sheenColor.r,k.sheenColor.g,k.sheenColor.b]:[1,1,1],sheenRoughnessFactor:k.sheenRoughness||0}),k.transmission>0&&(G.KHR_materials_transmission={transmissionFactor:k.transmission}),k.thickness>0&&(G.KHR_materials_volume={thicknessFactor:k.thickness,attenuationDistance:k.attenuationDistance??1/0,attenuationColor:k.attenuationColor?[k.attenuationColor.r,k.attenuationColor.g,k.attenuationColor.b]:[1,1,1]}),k.ior!==void 0&&k.ior!==1.5&&(G.KHR_materials_ior={ior:k.ior}),k.dispersion>0&&(G.KHR_materials_dispersion={dispersion:k.dispersion}),k.iridescence>0&&(G.KHR_materials_iridescence={iridescenceFactor:k.iridescence,iridescenceIor:k.iridescenceIOR??1.3}),Object.keys(G).length>0&&(W.extensions=G),s.push(W)}j.material=X}let V=u.length;u.push({primitives:[j],name:y.name,...w.extras?{extras:w.extras}:{}}),w.mesh=V}}let P=l.length;if(l.push(w),c.push(y),y.children.length>0){w.children=[];for(let N of y.children)w.children.push(g(N))}return P}for(let y of t.children)b.push(g(y));let E=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),A=[];if(typeof E=="function"&&c.length>0){let y=e?.duration??4,w=e?.fps??15,T=Math.max(2,Math.round(y*w)+1),I=new Float32Array(T),B=c.map(V=>({px:V.position.x,py:V.position.y,pz:V.position.z,qx:V.quaternion.x,qy:V.quaternion.y,qz:V.quaternion.z,qw:V.quaternion.w,sx:V.scale.x,sy:V.scale.y,sz:V.scale.z})),P=c.map(()=>new Float32Array(T*3)),N=c.map(()=>new Float32Array(T*4)),_=c.map(()=>new Float32Array(T*3));for(let V=0;V<T;V++){let X=V/(T-1)*y;I[V]=X;try{E(X)}catch{}for(let k=0;k<c.length;k++){let W=c[k];P[k][V*3]=W.position.x,P[k][V*3+1]=W.position.y,P[k][V*3+2]=W.position.z,N[k][V*4]=W.quaternion.x,N[k][V*4+1]=W.quaternion.y,N[k][V*4+2]=W.quaternion.z,N[k][V*4+3]=W.quaternion.w,_[k][V*3]=W.scale.x,_[k][V*3+1]=W.scale.y,_[k][V*3+2]=W.scale.z}}for(let V=0;V<c.length;V++){let X=c[V],k=B[V];X.position.set(k.px,k.py,k.pz),X.quaternion.set(k.qx,k.qy,k.qz,k.qw),X.scale.set(k.sx,k.sy,k.sz)}t.updateMatrixWorld(!0);let q=null,J=()=>(q===null&&(q=d(I,"SCALAR",0,5126,T,[0],[y])),q),Z=[],j=[];for(let V=0;V<c.length;V++){let X=B[V],k=!1,W=!1,G=!1;for(let S=0;S<T;S++)(Math.abs(P[V][S*3]-X.px)>1e-4||Math.abs(P[V][S*3+1]-X.py)>1e-4||Math.abs(P[V][S*3+2]-X.pz)>1e-4)&&(k=!0),(Math.abs(N[V][S*4]-X.qx)>1e-4||Math.abs(N[V][S*4+1]-X.qy)>1e-4||Math.abs(N[V][S*4+2]-X.qz)>1e-4||Math.abs(N[V][S*4+3]-X.qw)>1e-4)&&(W=!0),(Math.abs(_[V][S*3]-X.sx)>1e-4||Math.abs(_[V][S*3+1]-X.sy)>1e-4||Math.abs(_[V][S*3+2]-X.sz)>1e-4)&&(G=!0);if(k){let S=d(P[V],"VEC3",0,5126,T),v=Z.length;Z.push({input:J(),interpolation:"LINEAR",output:S}),j.push({sampler:v,target:{node:V,path:"translation"}})}if(W){let S=d(N[V],"VEC4",0,5126,T),v=Z.length;Z.push({input:J(),interpolation:"LINEAR",output:S}),j.push({sampler:v,target:{node:V,path:"rotation"}})}if(G){let S=d(_[V],"VEC3",0,5126,T),v=Z.length;Z.push({input:J(),interpolation:"LINEAR",output:S}),j.push({sampler:v,target:{node:V,path:"scale"}})}}j.length>0&&A.push({name:"ProceduralLoop",samplers:Z,channels:j})}let p=ar(l,u,t.userData),R={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:b}],scene:0,nodes:l,meshes:u,materials:s,accessors:o,bufferViews:r,buffers:[{byteLength:i}],...A.length>0?{animations:A}:{},...p||a.size>0?{extensionsUsed:[...p?["KHR_interactivity"]:[],...a]}:{},...p?{extensions:{KHR_interactivity:p}}:{}},x=new Uint8Array(i),F=0;for(let y of n)x.set(y,F),F+=y.byteLength;return{gltf:R,bin:x.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function Dt(t){return new TextEncoder().encode(t)}function Qe(t,e){let{gltf:n,bin:i}=ze(t,e),r=JSON.stringify(n),o=Dt(r),u=(4-o.byteLength%4)%4,l=o.byteLength+u,a=20+l+8+i.byteLength,c=new Uint8Array(a),s=new DataView(c.buffer);s.setUint32(0,1179937895,!0),s.setUint32(4,2,!0),s.setUint32(8,a,!0),s.setUint32(12,l,!0),s.setUint32(16,1313821514,!0),c.set(o,20);for(let h=0;h<u;h++)c[20+o.byteLength+h]=32;let m=20+l;return s.setUint32(m,i.byteLength,!0),s.setUint32(m+4,5130562,!0),c.set(new Uint8Array(i),m+8),c}function Si(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(i=>{if(i.geometry){let r=i.geometry,o=r.attributes.position;if(!o||o.count===0)return;let u=o.count,l=new Float32Array(u*3),a=i.matrixWorld.elements;for(let y=0;y<u;y++){let w=o.getX(y),T=o.getY(y),I=o.getZ(y);l[y*3]=a[0]*w+a[4]*T+a[8]*I+a[12],l[y*3+1]=a[1]*w+a[5]*T+a[9]*I+a[13],l[y*3+2]=a[2]*w+a[6]*T+a[10]*I+a[14]}let c;if(r.attributes.normal){let y=r.attributes.normal;c=new Float32Array(u*3);let w=new Float32Array(9);ue(w,a);for(let T=0;T<u;T++){let I=y.getX(T),B=y.getY(T),P=y.getZ(T),N=w[0]*I+w[3]*B+w[6]*P,_=w[1]*I+w[4]*B+w[7]*P,q=w[2]*I+w[5]*B+w[8]*P,J=Math.hypot(N,_,q)||1;c[T*3]=N/J,c[T*3+1]=_/J,c[T*3+2]=q/J}}let s;if(r.attributes.uv){let y=r.attributes.uv;s=new Float32Array(u*2);for(let w=0;w<u;w++)s[w*2]=y.getX(w),s[w*2+1]=y.getY(w)}let m;if(r.index)m=r.index.array;else{m=u>65535?new Uint32Array(u):new Uint16Array(u);for(let y=0;y<u;y++)m[y]=y}let h="DefaultMaterial",f=[.8,.8,.8],d=.5,b=.1,g=0,E=0,A=1.5,p=1,R=[0,0,0];if(i.material){let y=i.material;h=y.name||`Material_${n.length}`,y.color&&(f=[y.color.r,y.color.g,y.color.b]),typeof y.roughness=="number"&&(d=y.roughness),typeof y.metalness=="number"&&(b=y.metalness),typeof y.clearcoat=="number"&&(g=y.clearcoat),typeof y.clearcoatRoughness=="number"&&(E=y.clearcoatRoughness),typeof y.ior=="number"&&(A=y.ior);let w=typeof y.opacity=="number"?y.opacity:1,T=typeof y.transmission=="number"?y.transmission:0;if(p=w*(1-T),y.emissive&&(y.emissive.r>0||y.emissive.g>0||y.emissive.b>0)){let I=y.emissiveIntensity??1;R=[y.emissive.r*I,y.emissive.g*I,y.emissive.b*I]}}let x,F=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof F=="function"){let y=e?.duration??4,w=e?.fps??4,T=Math.max(2,Math.round(y*w)+1),I=[],B=[],P=[],N=[],_=[i.position.x,i.position.y,i.position.z],q=[i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w],J=[i.scale.x,i.scale.y,i.scale.z],Z=!1;for(let j=0;j<T;j++){let V=j/(T-1)*y;I.push(V);try{F(V)}catch{}B.push([i.position.x,i.position.y,i.position.z]),P.push([i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w]),N.push([i.scale.x,i.scale.y,i.scale.z]),(Math.abs(i.position.x-_[0])>1e-4||Math.abs(i.position.y-_[1])>1e-4||Math.abs(i.position.z-_[2])>1e-4||Math.abs(i.quaternion.x-q[0])>1e-4||Math.abs(i.quaternion.y-q[1])>1e-4||Math.abs(i.quaternion.z-q[2])>1e-4||Math.abs(i.quaternion.w-q[3])>1e-4||Math.abs(i.scale.x-J[0])>1e-4)&&(Z=!0)}i.position.set(_[0],_[1],_[2]),i.quaternion.set(q[0],q[1],q[2],q[3]),i.scale.set(J[0],J[1],J[2]),Z&&(x={times:I,translations:B,rotations:P,scales:N})}n.push({name:i.name||`Mesh_${n.length}`,positions:l,indices:m,normals:c,uvs:s,materialName:h,color:f,roughness:d,metallic:b,clearcoat:g,clearcoatRoughness:E,ior:A,opacity:p,emissiveColor:R,xrTraits:i.userData?.xr,timeSamples:x})}}),n}function wr(t){let e=[],n=t.gltf,i=t.bin,r=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),o=n.accessors||[],u=n.bufferViews||[],l=n.materials||[],a=n.meshes||[],c=n.nodes||[];function s(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let b=u[d.bufferView||0],g=(b.byteOffset||0)+(d.byteOffset||0),E=b.byteLength||0,A=r.slice(g,g+E);return{acc:d,buffer:A}}let m=new Map;if(c.length>0){let f=_e(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function h(f,d,b,g){let E=a[f];if(!E)return;let A=new Float32Array(9);ue(A,d);for(let p=0;p<(E.primitives||[]).length;p++){let R=E.primitives[p],x=R.attributes?.POSITION;if(x===void 0)continue;let{acc:F,buffer:y}=s(x),w=new Float32Array(y,0,F.count*3),T=new Float32Array(w.length);for(let v=0;v<F.count;v++){let L=w[v*3],U=w[v*3+1],M=w[v*3+2];T[v*3]=d[0]*L+d[4]*U+d[8]*M+d[12],T[v*3+1]=d[1]*L+d[5]*U+d[9]*M+d[13],T[v*3+2]=d[2]*L+d[6]*U+d[10]*M+d[14]}let I,B=R.attributes?.NORMAL;if(B!==void 0){let{acc:v,buffer:L}=s(B),U=new Float32Array(L,0,v.count*3);I=new Float32Array(U.length);for(let M=0;M<v.count;M++){let D=U[M*3],C=U[M*3+1],O=U[M*3+2],Y=A[0]*D+A[3]*C+A[6]*O,K=A[1]*D+A[4]*C+A[7]*O,Q=A[2]*D+A[5]*C+A[8]*O,z=Math.hypot(Y,K,Q)||1;I[M*3]=Y/z,I[M*3+1]=K/z,I[M*3+2]=Q/z}}let P,N=R.attributes?.TEXCOORD_0;if(N!==void 0){let{acc:v,buffer:L}=s(N);P=new Float32Array(L,0,v.count*2)}let _;if(R.indices!==void 0){let{acc:v,buffer:L}=s(R.indices);v.componentType===5125?_=new Uint32Array(L,0,v.count):_=new Uint16Array(L,0,v.count);let U=F.count;for(let M of _)if(M>=U)throw new Error(`SecurityError: Index buffer value (${M}) out of vertex bounds [0, ${U}).`)}else{let v=F.count;_=v>65535?new Uint32Array(v):new Uint16Array(v);for(let L=0;L<v;L++)_[L]=L}let q="DefaultMaterial",J=[.8,.8,.8],Z=.5,j=.1,V=0,X=0,k=1.5,W=1,G=[0,0,0];if(R.material!==void 0&&l[R.material]){let v=l[R.material];q=v.name||`Material_${R.material}`;let L=v.pbrMetallicRoughness||{},U=1;Array.isArray(L.baseColorFactor)&&(J=[L.baseColorFactor[0],L.baseColorFactor[1],L.baseColorFactor[2]],typeof L.baseColorFactor[3]=="number"&&(U=L.baseColorFactor[3])),typeof L.roughnessFactor=="number"&&(Z=L.roughnessFactor),typeof L.metallicFactor=="number"&&(j=L.metallicFactor),Array.isArray(v.emissiveFactor)&&v.emissiveFactor.length>=3&&(G=[v.emissiveFactor[0],v.emissiveFactor[1],v.emissiveFactor[2]]);let M=v.extensions||{};M.KHR_materials_clearcoat&&(V=M.KHR_materials_clearcoat.clearcoatFactor??0,X=M.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),M.KHR_materials_ior&&typeof M.KHR_materials_ior.ior=="number"&&(k=M.KHR_materials_ior.ior);let D=M.KHR_materials_transmission?.transmissionFactor??0;W=U*(1-D)}let S=(E.primitives||[]).length>1?`${b}_p${p}`:b;e.push({name:S,positions:T,indices:_,normals:I,uvs:P,materialName:q,color:J,roughness:Z,metallic:j,clearcoat:V,clearcoatRoughness:X,ior:k,opacity:W,emissiveColor:G,xrTraits:g?.xr||E.extras?.xr})}}if(c.length>0)for(let f=0;f<c.length;f++){let d=c[f];if(d.mesh!==void 0&&d.mesh<a.length){let b=m.get(f)||se(),g=d.name||a[d.mesh].name||`Node_${f}`;h(d.mesh,b,g,d.extras)}}else{let f=se();for(let d=0;d<a.length;d++){let b=a[d].name||`Mesh_${d}`;h(d,f,b,a[d].extras)}}return e}function _n(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function xr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ee(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function vr(t){let e=t.length/3,n=new Array(e);for(let i=0;i<e;i++)n[i]=`(${ee(t[i*3])}, ${ee(t[i*3+1])}, ${ee(t[i*3+2])})`;return n.join(", ")}function Mi(t,e){let n=new Array(e);for(let i=0;i<e;i++)n[i]=`(${ee(t[i*2])}, ${ee(1-t[i*2+1])})`;return n.join(", ")}function _i(t){return Array.from(t).join(", ")}function Cn(t){let e=new Map;for(let a of t){let c=_n(a.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,i=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let c=a.timeSamples.times[a.timeSamples.times.length-1];c>n&&(n=c)}a.xrTraits?.anchor&&!i&&(i=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let r="";n>0&&(r=`startTimeCode = 0
|
|
222
|
+
void main(){fragColor=uColorId;}`;function pr(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Dn(t,e,n){let r=pr(t,35633,e),i=pr(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let c=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${c}`)}return o}function In(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var wr=["uMVP","uModel","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","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize","uViewport","uCameraFwd"];function Si(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Cn(t,e,n,r,i,o,c){if(r===void 0||!e.accessors?.[r])return null;let l=e.accessors[r],a=e.bufferViews[l.bufferView],s=(a.byteOffset||0)+(l.byteOffset||0),u=a.byteStride&&a.byteStride>o*4?a.byteStride>>2:o,m;if(u===o)m=new Float32Array(n,s,l.count*o);else{m=new Float32Array(l.count*o);let f=new Float32Array(n,a.byteOffset||0,Math.floor(a.byteLength/4)),d=(l.byteOffset||0)>>2;for(let p=0;p<l.count;p++){let v=d+p*u;for(let _=0;_<o;_++)m[p*o+_]=f[v+_]}}let h=t.createBuffer();return c.push(h),t.bindBuffer(34962,h),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var Ar=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Rr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function br(t,e,n=Rr,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,c=[],l=Le(i),a=[];if(Array.isArray(i.nodes))for(let A=0;A<i.nodes.length;A++){let R=i.nodes[A];R.mesh!==void 0&&i.meshes&&i.meshes[R.mesh]&&a.push({node:R,nodeIdx:A,meshIdx:R.mesh})}let s=a.length>0?a:(i.meshes||[]).map((A,R)=>({node:A,nodeIdx:-1,meshIdx:R})),u=[];if(Array.isArray(e.lights)&&e.lights.length>0)u.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let A=i.extensions.KHR_lights_punctual.lights;for(let R of A){let E=R.type==="directional"?"directional":R.type==="point"?"point":"ambient";u.push({type:E,color:R.color||[1,1,1],intensity:R.intensity!==void 0?R.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]})),s.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${s.length}`);let m=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let A=0;A<i.textures.length;A++){let R=i.textures[A],E=i.images[R.source];if(E){let O=t.createTexture();if(t.bindTexture(3553,O),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),E.bufferView!==void 0){let H=i.bufferViews[E.bufferView],F=o.slice(H.byteOffset||0,(H.byteOffset||0)+H.byteLength),M=new Blob([F],{type:E.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(M).then(G=>{t.bindTexture(3553,O),t.texImage2D(3553,0,6408,6408,5121,G),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(E.uri){let H=Si(E.uri);if(H){let F=new Image;F.crossOrigin="anonymous",F.referrerPolicy="no-referrer",F.onload=()=>{t.bindTexture(3553,O),t.texImage2D(3553,0,6408,6408,5121,F),t.generateMipmap(3553),r?.()},F.src=H}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",E.uri)}m.push(O)}else m.push(null)}}let h=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],d=0,p=0;for(let A=0;A<s.length;A++){let R=s[A],E=i.meshes[R.meshIdx],O=R.nodeIdx>=0?l[R.nodeIdx]:ae(),H=new Float32Array(9);de(H,O);let F={name:R.node.name||E.name||`Mesh_${R.meshIdx}`,nodeIndex:R.nodeIdx,transform:O,normalMatrix:H,primitives:[],extras:R.node.extras||E.extras};for(let M of E.primitives||[]){if(M.extensions?.KHR_draco_mesh_compression){let ne=rt("draco");ne&&ne.decodePrimitive(i,M,o)}let G=[],B=t.createVertexArray();t.bindVertexArray(B);let Q=i.accessors[M.attributes.POSITION],j=Number(Q?.count??0);if(!Number.isFinite(j)||j<0||d+j>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(d+=j,Q?.min&&Q?.max)for(let ne=0;ne<3;ne++){let be=O[12+ne],Ge=O[12+ne];for(let Pe=0;Pe<3;Pe++){let Mt=O[Pe*4+ne]*Q.min[Pe],_t=O[Pe*4+ne]*Q.max[Pe];be+=Mt<_t?Mt:_t,Ge+=Mt>_t?Mt:_t}be<h[ne]&&(h[ne]=be),Ge>f[ne]&&(f[ne]=Ge)}let z=Cn(t,i,o,M.attributes.POSITION,0,3,G);Cn(t,i,o,M.attributes.NORMAL,1,3,G),Cn(t,i,o,M.attributes.TEXCOORD_0,2,2,G);let X=0,U=5123,q=null;if(M.indices!==void 0){let ne=i.accessors[M.indices],Ge=(i.bufferViews[ne.bufferView].byteOffset||0)+(ne.byteOffset||0);if(X=Number(ne.count??0),!Number.isFinite(X)||X<0||p+X>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);p+=X,U=ne.componentType===5125?5125||5125:5123||5123;let Pe=t.createBuffer();G.push(Pe),t.bindBuffer(34963,Pe),ne.componentType===5125?(q=new Uint32Array(o,Ge,ne.count),t.bufferData(34963,q,35044)):(q=new Uint16Array(o,Ge,ne.count),t.bufferData(34963,q,35044))}else X=Q.count;let Y={};for(let ne of ce)if(ne.onBuildPrimitiveVAO){let be=ne.onBuildPrimitiveVAO(t,B,M,i,o);be&&(Y[ne.name]=be)}t.bindVertexArray(null);let T=i.materials&&M.material!==void 0?i.materials[M.material]:null,x=xr,D=vr,k=!1;for(let ne of ce)if(ne.onResolveShader){let be=ne.onResolveShader(M,T,x,D);be&&(x=be.vs,D=be.fs,k=!0)}let I=k?Dn(t,x,D):null,L=I?In(t,I,wr):null,P=T?.pbrMetallicRoughness,N=P?.baseColorFactor||[.8,.8,.8,1],K=P?.metallicFactor??.1,Z=P?.roughnessFactor??.5,$=T?.extensions?.KHR_materials_clearcoat,V=$?$.clearcoatFactor??1:0,J=Math.max(.04,$?.clearcoatRoughnessFactor??.04),te=P?.baseColorTexture!==void 0&&m[P.baseColorTexture.index]?m[P.baseColorTexture.index]:null,ie=P?.metallicRoughnessTexture!==void 0&&m[P.metallicRoughnessTexture.index]?m[P.metallicRoughnessTexture.index]:null,ue=T?.normalTexture!==void 0&&m[T.normalTexture.index]?m[T.normalTexture.index]:null,Re=T?.normalTexture?.scale??1,he=T?.occlusionTexture!==void 0&&m[T.occlusionTexture.index]?m[T.occlusionTexture.index]:null,xe=T?.occlusionTexture?.strength??1,Me=!!(T?.extensions?.KHR_materials_transmission||Y.materials?.isTransmissive);F.primitives.push({vao:B,indexCount:X,indexType:U,baseColor:N,metallic:K,roughness:Z,clearcoat:V,clearcoatRoughness:J,positions:z,indices:q,texture:te,metallicRoughnessTexture:ie,normalTexture:ue,occlusionTexture:he,normalScale:Re,occlusionStrength:xe,buffers:G,materialIndex:M.material,pluginData:Y,customProgram:I,customUniforms:L,isTransmissive:Me})}c.push(F)}isFinite(h[0])||(h=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let v=[(h[0]+f[0])/2,(h[1]+f[1])/2,(h[2]+f[2])/2],_=f[0]-h[0],S=f[1]-h[1],y=f[2]-h[2],w=Math.max(Math.hypot(_,S,y)/2,.5),g=[h[0],h[1],h[2]],C=[f[0],f[1],f[2]],b=e.animations;if(!b){for(let A of ce)if(A.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:c,bounds:{center:v,radius:w,min:g,max:C},lights:u,animations:b,worldMatrices:l}}var fe=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=ae();this.clearColor=[0,0,0,0];this.envIntensity=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.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=ae();this.viewMatrix=ae();this.modelMatrix=ae();this.mvpMatrix=ae();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.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:ae(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(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.envIntensity=Math.max(0,Number(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=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.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 l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.renderProg=Dn(l,xr,vr),this.pickProg=Dn(l,Ri,Ti),this.uRender=In(l,this.renderProg,wr),this.uPick=In(l,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){wi(e,n)}static getDecoder(e){return rt(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),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,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:c,worldMatrices:l}=br(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=c||[],this.worldMatrices=l||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let s of e.gltf.nodes)this.initialNodeTransforms.push({t:s.translation?[s.translation[0],s.translation[1],s.translation[2]]:[0,0,0],r:s.rotation?[s.rotation[0],s.rotation[1],s.rotation[2],s.rotation[3]]:[0,0,0,1],s:s.scale?[s.scale[0],s.scale[1],s.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let s of ce)s.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let a=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;a!==void 0&&(this.envIntensity=Math.max(0,Number(a))),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(gr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Fe(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Fe(e),{meshes:i}=br(this.gl,r,Rr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],de(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),de(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],c=[],l=[];for(let a of this.lights){let s=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[s[0]*u,s[1]*u,s[2]*u];else if(a.type==="directional"&&i.length<6){let m=a.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(s[0]*u,s[1]*u,s[2]*u)}else if(a.type==="point"&&c.length<6){let m=a.position||[0,0,0];c.push(m[0],m[1],m[2]),l.push(s[0]*u,s[1]*u,s[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(n.uniform3fv(e.uPointLightPos,c),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ce)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ce)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.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((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],c=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:c,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:u=>{let m=[u[0],u[1],u[2],u[3]??1];s.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let h of i)h.baseColor=m;this.render()},setMetallicFactor:u=>{s.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let m of i)m.metallic=u;this.render()},setRoughnessFactor:u=>{s.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let m of i)m.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:s}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}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 n of ce)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],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 n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let r=ae();ge(r,this.projMatrix,this.viewMatrix);let[i,o,c]=e,l=n?n[0]:0,a=n?n[1]:0,s=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],c=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(l=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],a=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],s=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*c+r[12],h=r[1]*i+r[5]*o+r[9]*c+r[13],f=r[2]*i+r[6]*o+r[10]*c+r[14],d=r[3]*i+r[7]*o+r[11]*c+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=m/d,v=h/d,_=f/d,S=this.canvas.getBoundingClientRect(),y=S.width||this.canvas.clientWidth||this.canvas.width||300,w=S.height||this.canvas.clientHeight||this.canvas.height||150,g=(p*.5+.5)*y,C=(-v*.5+.5)*w,b=p>=-1.1&&p<=1.1&&v>=-1.1&&v<=1.1&&_>=-1&&_<=1;if(b&&n){let A=this.customTarget||this.bounds.center,R=A[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),E=A[1]+this.currDistance*Math.sin(this.currPhi),O=A[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),H=[i-R,o-E,c-O];l*H[0]+a*H[1]+s*H[2]>.05&&(b=!1)}return{x:g,y:C,z:_,visible:b}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.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]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*c[0]+o*l[0])*s,a[1]+=(-i*c[1]+o*l[1])*s,a[2]+=(-i*c[2]+o*l[2])*s,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.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=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,c=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),a=i.height>0?Math.floor((n-i.top)*(c/i.height)):Math.floor(n);return this.performMeshPick(l,a,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=ae();ge(l,this.projMatrix,this.viewMatrix);let a=[],s=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(c-1,c-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==c)&&this.resizePickingFbo(o,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let b=0;b<this.meshes.length;b++){let A=this.meshes[b];if(A.visible===!1||A.isPluginMesh)continue;let R=b+1,E=(R&255)/255,O=(R>>8&255)/255,H=(R>>16&255)/255;i.uniform4f(this.uPick.uColorId,E,O,H,1),ge(this.modelMatrix,this.modelRootMatrix,A.transform),ge(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let F of A.primitives)i.bindVertexArray(F.vao),i.drawElements(4,F.indexCount,F.indexType,0)}let g=new Uint8Array(4);i.readPixels(s,u,1,1,6408,5121,g),i.bindFramebuffer(36160,null);let C=g[0]+(g[1]<<8)+(g[2]<<16);C>0&&C<=this.meshes.length&&(a=[this.meshes[C-1]])}a.length===0&&(a=this.meshes.filter(g=>g.visible!==!1));let m=null,h=1/0,f=[0,0,0],d=[0,1,0],p=this.customTarget||this.bounds.center,v=p[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=p[1]+this.currDistance*Math.sin(this.currPhi),S=p[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let g of a){ge(this.modelMatrix,this.modelRootMatrix,g.transform),ge(this.mvpMatrix,l,this.modelMatrix);let C=ae();if(!Ft(C,this.mvpMatrix))continue;let b=(s+.5)/o*2-1,A=(u+.5)/c*2-1,R=[0,0,0],E=[0,0,0];_n(R,b,A,-1,C),_n(E,b,A,1,C);let O=E[0]-R[0],H=E[1]-R[1],F=E[2]-R[2],M=Math.hypot(O,H,F)||1,G=O/M,B=H/M,Q=F/M,j={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((X=>{for(let U of g.primitives){if(!U.positions)continue;let q=U.positions,Y=U.indices,T=Math.floor(Y?Y.length/3:q.length/9);for(let x=0;x<T;x++){let D=Y?Y[x*3]:x*3,k=Y?Y[x*3+1]:x*3+1,I=Y?Y[x*3+2]:x*3+2;fr(R[0],R[1],R[2],G,B,Q,q[D*3],q[D*3+1],q[D*3+2],q[k*3],q[k*3+1],q[k*3+2],q[I*3],q[I*3+1],q[I*3+2],j,X)}}})(1e-4),isFinite(j.distance)){let X=j.point[0],U=j.point[1],q=j.point[2],Y=this.modelMatrix,T=Y[0]*X+Y[4]*U+Y[8]*q+Y[12],x=Y[1]*X+Y[5]*U+Y[9]*q+Y[13],D=Y[2]*X+Y[6]*U+Y[10]*q+Y[14],k=T-v,I=x-_,L=D-S,P=Math.hypot(k,I,L);if(P<h){de(this.normalMatrix,this.modelMatrix);let N=this.normalMatrix,K=j.normal[0],Z=j.normal[1],$=j.normal[2],V=N[0]*K+N[3]*Z+N[6]*$,J=N[1]*K+N[4]*Z+N[7]*$,te=N[2]*K+N[5]*Z+N[8]*$,ie=Math.hypot(V,J,te)||1;V/=ie,J/=ie,te/=ie,V*k+J*I+te*L>0&&(V=-V,J=-J,te=-te),m=g,h=Math.round(P*1e3)/1e3,f=[Math.round(T*1e3)/1e3,Math.round(x*1e3)/1e3,Math.round(D*1e3)/1e3],d=[Math.round(V*1e3)/1e3,Math.round(J*1e3)/1e3,Math.round(te*1e3)/1e3]}}}if(!m)return null;let w={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:h,hitPoint:f,normal:d,screenX:e,screenY:n};if(r){for(let g of ce)g.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,c=i?Math.max(1,n-r):r,l=(o+.5)/c*2-1;return Math.floor((l*.5+1)*.5*n)}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),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Lt(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);$e(this.viewMatrix,[i,o,c],r,[0,1,0]),ge(this.mvpMatrix,this.projMatrix,this.viewMatrix),de(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of ce)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of ce)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}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),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of ce)c.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let c of ce)c.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 r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let c={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,n,r,i,o=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,s=e?.transform?.position,u=s?[s.x,s.y,s.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:l,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),g=Math.max(1,this.canvas.height||1),C=Math.max(1,Math.floor(w*.5)),b=Math.max(1,w-C),A=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),R=this.customTarget||this.bounds.center,E=R[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),O=R[1]+this.currDistance*Math.sin(this.currPhi),H=R[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),F=Math.cos(this.currTheta),M=-Math.sin(this.currTheta),G=.032,B=ae(),Q=ae(),j=[E-F*G,O,H-M*G],z=[R[0]-F*G*.25,R[1],R[2]-M*G*.25];Lt(B,this.fov,C/g,.1,A),$e(Q,j,z,[0,1,0]);let X=ae(),U=ae(),q=[E+F*G,O,H+M*G],Y=[R[0]+F*G*.25,R[1],R[2]+M*G*.25];Lt(X,this.fov,b/g,.1,A),$e(U,q,Y,[0,1,0]),this.render({viewMatrix:Q,projMatrix:B,eyePos:j,viewport:[0,0,C,g],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:U,projMatrix:X,eyePos:q,viewport:[C,0,b,g],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,g);return}let n=this.gl,r=0,i=0,o=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],c=e.viewport[3],n.viewport(r,i,o,c)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let l=ae(),a=e?.viewMatrix??this.viewMatrix;ge(l,e?.projMatrix??this.projMatrix,a);let s=[-a[2],-a[6],-a[10]],u=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,h=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),f=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),d=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let w of ce)w.onBeforeDrawScene?.(this,n,l,[h,f,d],u);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let v=e?.eye||"none",_=!1,S=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=w=>{for(let g=0;g<S.length;g++){let C=S[g];if(C.visible===!1)continue;let b=this.selectedMeshName!==""&&C.name===this.selectedMeshName;g<p||C.worldSpace===!0||C.name==="__xr_reticle__"?this.modelMatrix.set(C.transform):ge(this.modelMatrix,this.modelRootMatrix,C.transform),ge(this.mvpMatrix,l,this.modelMatrix),de(C.normalMatrix,this.modelMatrix);let A=C.extras?.xr?.stereo||C.userData?.xr?.stereo,R=0,E=0,O=1,H=1;A==="sbs"?(O=.5,R=v==="right"?.5:0):A==="ou"&&(H=.5,E=v==="right"?.5:0);for(let F of C.primitives){let M=!!F.isTransmissive;if(!w&&M){_=!0;continue}if(w&&!M)continue;let G=F.customProgram||this.renderProg,B=F.customUniforms||this.uRender;n.useProgram(G),n.uniform1i(B.uToneMapping,u),n.uniform1f(B.uEnvIntensity,this.envIntensity),n.uniform3f(B.uCameraPos,h,f,d),B.uCameraFwd&&n.uniform3f(B.uCameraFwd,s[0],s[1],s[2]),n.uniform1f(B.uEmissive,b?1:0),n.uniformMatrix4fv(B.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(B.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(B.uNormalMatrix,!1,C.normalMatrix),B.uUvTransform&&n.uniform4f(B.uUvTransform,R,E,O,H),B.uViewportSize&&n.uniform2f(B.uViewportSize,Math.max(1,o),Math.max(1,c)),B.uViewport&&n.uniform4f(B.uViewport,r,i,Math.max(1,o),Math.max(1,c)),this.xrDepthState.enabled&&this.xrDepthState.texture?(n.activeTexture(33989),n.bindTexture(3553,this.xrDepthState.texture),B.uXrDepthTex&&n.uniform1i(B.uXrDepthTex,5),B.uXrDepthEnabled&&n.uniform1i(B.uXrDepthEnabled,1),B.uXrDepthFormat&&n.uniform1i(B.uXrDepthFormat,this.xrDepthState.format||0),B.uXrRawValueToMeters&&n.uniform1f(B.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),B.uXrDepthUVTransform&&n.uniformMatrix4fv(B.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):B.uXrDepthEnabled&&n.uniform1i(B.uXrDepthEnabled,0),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(B.uEnvironmentMap,4),n.uniform1i(B.uHasEnvironmentMap,1)):n.uniform1i(B.uHasEnvironmentMap,0),this.bindLights(B);for(let Q of ce)Q.onBeforeDrawPrimitive?.(n,G,F,C,this.worldMatrices||[],this.gltf);n.uniform4fv(B.uBaseColor,F.baseColor),n.uniform1f(B.uMetallic,F.metallic),n.uniform1f(B.uRoughness,F.roughness),B.uClearcoat&&n.uniform2f(B.uClearcoat,F.clearcoat??0,F.clearcoatRoughness??.04),F.texture?(n.activeTexture(33984),n.bindTexture(3553,F.texture),n.uniform1i(B.uBaseColorTexture,0),n.uniform1i(B.uHasTexture,1)):n.uniform1i(B.uHasTexture,0),F.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,F.metallicRoughnessTexture),n.uniform1i(B.uMetallicRoughnessTexture,1),n.uniform1i(B.uHasMetallicRoughnessTexture,1)):n.uniform1i(B.uHasMetallicRoughnessTexture,0),F.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,F.normalTexture),n.uniform1i(B.uNormalTexture,2),n.uniform1i(B.uHasNormalTexture,1),n.uniform1f(B.uNormalScale,F.normalScale)):n.uniform1i(B.uHasNormalTexture,0),F.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,F.occlusionTexture),n.uniform1i(B.uOcclusionTexture,3),n.uniform1i(B.uHasOcclusionTexture,1),n.uniform1f(B.uOcclusionStrength,F.occlusionStrength)):n.uniform1i(B.uHasOcclusionTexture,0),n.bindVertexArray(F.vao),n.drawElements(4,F.indexCount,F.indexType,0)}}};if(y(!1),_){for(let w of ce)w.onBeforeTransmissivePass?.(n,this);y(!0)}for(let w of ce)w.onAfterRender?.(n,this,l)}disposeMeshListGpuResources(e){let n=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&n.deleteVertexArray(i.vao),i.buffers)for(let o of i.buffers)n.deleteBuffer(o);i.texture&&n.deleteTexture(i.texture),i.metallicRoughnessTexture&&n.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&n.deleteTexture(i.normalTexture),i.occlusionTexture&&n.deleteTexture(i.occlusionTexture),i.customProgram&&n.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ce)n.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};fe.registerPlugin=ye,fe.getRegisteredPlugins=Pt;function Ei(t){return t+3&-4}function Mi(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function Ye(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],c=[],l=[],a=new Set,s=[],u=[],m=new Map,h=[];function f(b,A){let R=new Uint8Array(b.buffer,b.byteOffset,b.byteLength),E=Ei(R.byteLength),O=new Uint8Array(E);O.set(R),n.push(O);let H=i.length;return i.push({buffer:0,byteOffset:r,byteLength:R.byteLength,target:A}),r+=E,H}function d(b,A,R,E,O,H,F){let M=f(b,R),G=o.length,B={bufferView:M,byteOffset:0,componentType:E,count:O,type:A};return H&&(B.min=H),F&&(B.max=F),o.push(B),G}t.traverse(b=>{(b.isLight||b.color&&b.intensity!==void 0)&&h.push({type:b.type,color:[b.color.r,b.color.g,b.color.b],intensity:b.intensity,position:[b.position.x,b.position.y,b.position.z]})});let p=[];function v(b){let A={name:b.name||""},R=b.position,E=b.quaternion,O=b.scale;if((R.x||R.y||R.z)&&(A.translation=[R.x,R.y,R.z]),(E.x||E.y||E.z||E.w!==1)&&(A.rotation=[E.x,E.y,E.z,E.w]),(O.x!==1||O.y!==1||O.z!==1)&&(A.scale=[O.x,O.y,O.z]),b.userData&&Object.keys(b.userData).length>0&&(A.extras=JSON.parse(JSON.stringify(b.userData,(F,M)=>{if(!(F==="__proto__"||F==="prototype"||F==="constructor"))return typeof M=="function"?void 0:M})),b.userData.xr)){let F=Mi(b.userData.xr);A.extensions={...A.extensions||{},MOZ_hubs_components:F,ANDROID_xr_scenecore:F},oe().xrTraitSerializer?.gltfNode(A,b.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(b.geometry){let F=b.geometry,M=F.attributes.position;if(M&&M.count>0){let G=[1/0,1/0,1/0],B=[-1/0,-1/0,-1/0];for(let X=0;X<M.count;X++){let U=M.getX(X),q=M.getY(X),Y=M.getZ(X);U<G[0]&&(G[0]=U),U>B[0]&&(B[0]=U),q<G[1]&&(G[1]=q),q>B[1]&&(B[1]=q),Y<G[2]&&(G[2]=Y),Y>B[2]&&(B[2]=Y)}let j={attributes:{POSITION:d(M.array,"VEC3",34962,5126,M.count,G,B)}};if(F.attributes.normal&&(j.attributes.NORMAL=d(F.attributes.normal.array,"VEC3",34962,5126,F.attributes.normal.count)),F.attributes.uv&&(j.attributes.TEXCOORD_0=d(F.attributes.uv.array,"VEC2",34962,5126,F.attributes.uv.count)),F.index){let X=F.index.array instanceof Uint32Array;j.indices=d(F.index.array,"SCALAR",34963,X?5125:5123,F.index.count)}if(b.material){let X=m.get(b.material);if(X===void 0){X=u.length,m.set(b.material,X);let U=b.material,q={name:U.name||"",pbrMetallicRoughness:{baseColorFactor:[U.color.r,U.color.g,U.color.b,U.opacity],metallicFactor:U.metalness,roughnessFactor:U.roughness},doubleSided:U.side===2||U.doubleSided};if(U.emissive&&(U.emissive.r>0||U.emissive.g>0||U.emissive.b>0)){let T=U.emissiveIntensity??1;q.emissiveFactor=[U.emissive.r*T,U.emissive.g*T,U.emissive.b*T]}let Y={};U.clearcoat>0&&(Y.KHR_materials_clearcoat={clearcoatFactor:U.clearcoat,clearcoatRoughnessFactor:U.clearcoatRoughness||0}),U.sheen>0&&(Y.KHR_materials_sheen={sheenColorFactor:U.sheenColor?[U.sheenColor.r,U.sheenColor.g,U.sheenColor.b]:[1,1,1],sheenRoughnessFactor:U.sheenRoughness||0}),U.transmission>0&&(Y.KHR_materials_transmission={transmissionFactor:U.transmission}),U.thickness>0&&(Y.KHR_materials_volume={thicknessFactor:U.thickness,attenuationDistance:U.attenuationDistance??1/0,attenuationColor:U.attenuationColor?[U.attenuationColor.r,U.attenuationColor.g,U.attenuationColor.b]:[1,1,1]}),U.ior!==void 0&&U.ior!==1.5&&(Y.KHR_materials_ior={ior:U.ior}),U.dispersion>0&&(Y.KHR_materials_dispersion={dispersion:U.dispersion}),U.iridescence>0&&(Y.KHR_materials_iridescence={iridescenceFactor:U.iridescence,iridescenceIor:U.iridescenceIOR??1.3}),Object.keys(Y).length>0&&(q.extensions=Y),u.push(q)}j.material=X}let z=c.length;c.push({primitives:[j],name:b.name,...A.extras?{extras:A.extras}:{}}),A.mesh=z}}let H=l.length;if(l.push(A),s.push(b),b.children.length>0){A.children=[];for(let F of b.children)A.children.push(v(F))}return H}for(let b of t.children)p.push(v(b));let _=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),S=[];if(typeof _=="function"&&s.length>0){let b=e?.duration??4,A=e?.fps??15,R=Math.max(2,Math.round(b*A)+1),E=new Float32Array(R),O=s.map(z=>({px:z.position.x,py:z.position.y,pz:z.position.z,qx:z.quaternion.x,qy:z.quaternion.y,qz:z.quaternion.z,qw:z.quaternion.w,sx:z.scale.x,sy:z.scale.y,sz:z.scale.z})),H=s.map(()=>new Float32Array(R*3)),F=s.map(()=>new Float32Array(R*4)),M=s.map(()=>new Float32Array(R*3));for(let z=0;z<R;z++){let X=z/(R-1)*b;E[z]=X;try{_(X)}catch{}for(let U=0;U<s.length;U++){let q=s[U];H[U][z*3]=q.position.x,H[U][z*3+1]=q.position.y,H[U][z*3+2]=q.position.z,F[U][z*4]=q.quaternion.x,F[U][z*4+1]=q.quaternion.y,F[U][z*4+2]=q.quaternion.z,F[U][z*4+3]=q.quaternion.w,M[U][z*3]=q.scale.x,M[U][z*3+1]=q.scale.y,M[U][z*3+2]=q.scale.z}}for(let z=0;z<s.length;z++){let X=s[z],U=O[z];X.position.set(U.px,U.py,U.pz),X.quaternion.set(U.qx,U.qy,U.qz,U.qw),X.scale.set(U.sx,U.sy,U.sz)}t.updateMatrixWorld(!0);let G=null,B=()=>(G===null&&(G=d(E,"SCALAR",0,5126,R,[0],[b])),G),Q=[],j=[];for(let z=0;z<s.length;z++){let X=O[z],U=!1,q=!1,Y=!1;for(let T=0;T<R;T++)(Math.abs(H[z][T*3]-X.px)>1e-4||Math.abs(H[z][T*3+1]-X.py)>1e-4||Math.abs(H[z][T*3+2]-X.pz)>1e-4)&&(U=!0),(Math.abs(F[z][T*4]-X.qx)>1e-4||Math.abs(F[z][T*4+1]-X.qy)>1e-4||Math.abs(F[z][T*4+2]-X.qz)>1e-4||Math.abs(F[z][T*4+3]-X.qw)>1e-4)&&(q=!0),(Math.abs(M[z][T*3]-X.sx)>1e-4||Math.abs(M[z][T*3+1]-X.sy)>1e-4||Math.abs(M[z][T*3+2]-X.sz)>1e-4)&&(Y=!0);if(U){let T=d(H[z],"VEC3",0,5126,R),x=Q.length;Q.push({input:B(),interpolation:"LINEAR",output:T}),j.push({sampler:x,target:{node:z,path:"translation"}})}if(q){let T=d(F[z],"VEC4",0,5126,R),x=Q.length;Q.push({input:B(),interpolation:"LINEAR",output:T}),j.push({sampler:x,target:{node:z,path:"rotation"}})}if(Y){let T=d(M[z],"VEC3",0,5126,R),x=Q.length;Q.push({input:B(),interpolation:"LINEAR",output:T}),j.push({sampler:x,target:{node:z,path:"scale"}})}}j.length>0&&S.push({name:"ProceduralLoop",samplers:Q,channels:j})}let y=dr(l,c,t.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:p}],scene:0,nodes:l,meshes:c,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...S.length>0?{animations:S}:{},...y||a.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...a]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},g=new Uint8Array(r),C=0;for(let b of n)g.set(b,C),C+=b.byteLength;return{gltf:w,bin:g.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function Ut(t){return new TextEncoder().encode(t)}function it(t,e){let{gltf:n,bin:r}=Ye(t,e),i=JSON.stringify(n),o=Ut(i),c=(4-o.byteLength%4)%4,l=o.byteLength+c,a=20+l+8+r.byteLength,s=new Uint8Array(a),u=new DataView(s.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,a,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),s.set(o,20);for(let h=0;h<c;h++)s[20+o.byteLength+h]=32;let m=20+l;return u.setUint32(m,r.byteLength,!0),u.setUint32(m+4,5130562,!0),s.set(new Uint8Array(r),m+8),s}function _i(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let c=o.count,l=new Float32Array(c*3),a=r.matrixWorld.elements;for(let b=0;b<c;b++){let A=o.getX(b),R=o.getY(b),E=o.getZ(b);l[b*3]=a[0]*A+a[4]*R+a[8]*E+a[12],l[b*3+1]=a[1]*A+a[5]*R+a[9]*E+a[13],l[b*3+2]=a[2]*A+a[6]*R+a[10]*E+a[14]}let s;if(i.attributes.normal){let b=i.attributes.normal;s=new Float32Array(c*3);let A=new Float32Array(9);de(A,a);for(let R=0;R<c;R++){let E=b.getX(R),O=b.getY(R),H=b.getZ(R),F=A[0]*E+A[3]*O+A[6]*H,M=A[1]*E+A[4]*O+A[7]*H,G=A[2]*E+A[5]*O+A[8]*H,B=Math.hypot(F,M,G)||1;s[R*3]=F/B,s[R*3+1]=M/B,s[R*3+2]=G/B}}let u;if(i.attributes.uv){let b=i.attributes.uv;u=new Float32Array(c*2);for(let A=0;A<c;A++)u[A*2]=b.getX(A),u[A*2+1]=b.getY(A)}let m;if(i.index)m=i.index.array;else{m=c>65535?new Uint32Array(c):new Uint16Array(c);for(let b=0;b<c;b++)m[b]=b}let h="DefaultMaterial",f=[.8,.8,.8],d=.5,p=.1,v=0,_=0,S=1.5,y=1,w=[0,0,0];if(r.material){let b=r.material;h=b.name||`Material_${n.length}`,b.color&&(f=[b.color.r,b.color.g,b.color.b]),typeof b.roughness=="number"&&(d=b.roughness),typeof b.metalness=="number"&&(p=b.metalness),typeof b.clearcoat=="number"&&(v=b.clearcoat),typeof b.clearcoatRoughness=="number"&&(_=b.clearcoatRoughness),typeof b.ior=="number"&&(S=b.ior);let A=typeof b.opacity=="number"?b.opacity:1,R=typeof b.transmission=="number"?b.transmission:0;if(y=A*(1-R),b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let E=b.emissiveIntensity??1;w=[b.emissive.r*E,b.emissive.g*E,b.emissive.b*E]}}let g,C=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof C=="function"){let b=e?.duration??4,A=e?.fps??4,R=Math.max(2,Math.round(b*A)+1),E=[],O=[],H=[],F=[],M=[r.position.x,r.position.y,r.position.z],G=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],B=[r.scale.x,r.scale.y,r.scale.z],Q=!1;for(let j=0;j<R;j++){let z=j/(R-1)*b;E.push(z);try{C(z)}catch{}O.push([r.position.x,r.position.y,r.position.z]),H.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),F.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-M[0])>1e-4||Math.abs(r.position.y-M[1])>1e-4||Math.abs(r.position.z-M[2])>1e-4||Math.abs(r.quaternion.x-G[0])>1e-4||Math.abs(r.quaternion.y-G[1])>1e-4||Math.abs(r.quaternion.z-G[2])>1e-4||Math.abs(r.quaternion.w-G[3])>1e-4||Math.abs(r.scale.x-B[0])>1e-4)&&(Q=!0)}r.position.set(M[0],M[1],M[2]),r.quaternion.set(G[0],G[1],G[2],G[3]),r.scale.set(B[0],B[1],B[2]),Q&&(g={times:E,translations:O,rotations:H,scales:F})}n.push({name:r.name||`Mesh_${n.length}`,positions:l,indices:m,normals:s,uvs:u,materialName:h,color:f,roughness:d,metallic:p,clearcoat:v,clearcoatRoughness:_,ior:S,opacity:y,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:g})}}),n}function Er(t){let e=[],n=t.gltf,r=t.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=n.accessors||[],c=n.bufferViews||[],l=n.materials||[],a=n.meshes||[],s=n.nodes||[];function u(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let p=c[d.bufferView||0],v=(p.byteOffset||0)+(d.byteOffset||0),_=p.byteLength||0,S=i.slice(v,v+_);return{acc:d,buffer:S}}let m=new Map;if(s.length>0){let f=Le(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function h(f,d,p,v){let _=a[f];if(!_)return;let S=new Float32Array(9);de(S,d);for(let y=0;y<(_.primitives||[]).length;y++){let w=_.primitives[y],g=w.attributes?.POSITION;if(g===void 0)continue;let{acc:C,buffer:b}=u(g),A=new Float32Array(b,0,C.count*3),R=new Float32Array(A.length);for(let x=0;x<C.count;x++){let D=A[x*3],k=A[x*3+1],I=A[x*3+2];R[x*3]=d[0]*D+d[4]*k+d[8]*I+d[12],R[x*3+1]=d[1]*D+d[5]*k+d[9]*I+d[13],R[x*3+2]=d[2]*D+d[6]*k+d[10]*I+d[14]}let E,O=w.attributes?.NORMAL;if(O!==void 0){let{acc:x,buffer:D}=u(O),k=new Float32Array(D,0,x.count*3);E=new Float32Array(k.length);for(let I=0;I<x.count;I++){let L=k[I*3],P=k[I*3+1],N=k[I*3+2],K=S[0]*L+S[3]*P+S[6]*N,Z=S[1]*L+S[4]*P+S[7]*N,$=S[2]*L+S[5]*P+S[8]*N,V=Math.hypot(K,Z,$)||1;E[I*3]=K/V,E[I*3+1]=Z/V,E[I*3+2]=$/V}}let H,F=w.attributes?.TEXCOORD_0;if(F!==void 0){let{acc:x,buffer:D}=u(F);H=new Float32Array(D,0,x.count*2)}let M;if(w.indices!==void 0){let{acc:x,buffer:D}=u(w.indices);x.componentType===5125?M=new Uint32Array(D,0,x.count):M=new Uint16Array(D,0,x.count);let k=C.count;for(let I of M)if(I>=k)throw new Error(`SecurityError: Index buffer value (${I}) out of vertex bounds [0, ${k}).`)}else{let x=C.count;M=x>65535?new Uint32Array(x):new Uint16Array(x);for(let D=0;D<x;D++)M[D]=D}let G="DefaultMaterial",B=[.8,.8,.8],Q=.5,j=.1,z=0,X=0,U=1.5,q=1,Y=[0,0,0];if(w.material!==void 0&&l[w.material]){let x=l[w.material];G=x.name||`Material_${w.material}`;let D=x.pbrMetallicRoughness||{},k=1;Array.isArray(D.baseColorFactor)&&(B=[D.baseColorFactor[0],D.baseColorFactor[1],D.baseColorFactor[2]],typeof D.baseColorFactor[3]=="number"&&(k=D.baseColorFactor[3])),typeof D.roughnessFactor=="number"&&(Q=D.roughnessFactor),typeof D.metallicFactor=="number"&&(j=D.metallicFactor),Array.isArray(x.emissiveFactor)&&x.emissiveFactor.length>=3&&(Y=[x.emissiveFactor[0],x.emissiveFactor[1],x.emissiveFactor[2]]);let I=x.extensions||{};I.KHR_materials_clearcoat&&(z=I.KHR_materials_clearcoat.clearcoatFactor??0,X=I.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),I.KHR_materials_ior&&typeof I.KHR_materials_ior.ior=="number"&&(U=I.KHR_materials_ior.ior);let L=I.KHR_materials_transmission?.transmissionFactor??0;q=k*(1-L)}let T=(_.primitives||[]).length>1?`${p}_p${y}`:p;e.push({name:T,positions:R,indices:M,normals:E,uvs:H,materialName:G,color:B,roughness:Q,metallic:j,clearcoat:z,clearcoatRoughness:X,ior:U,opacity:q,emissiveColor:Y,xrTraits:v?.xr||_.extras?.xr})}}if(s.length>0)for(let f=0;f<s.length;f++){let d=s[f];if(d.mesh!==void 0&&d.mesh<a.length){let p=m.get(f)||ae(),v=d.name||a[d.mesh].name||`Node_${f}`;h(d.mesh,p,v,d.extras)}}else{let f=ae();for(let d=0;d<a.length;d++){let p=a[d].name||`Mesh_${d}`;h(d,f,p,a[d].extras)}}return e}function Pn(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function Tr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ee(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function Sr(t){let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ee(t[r*3])}, ${ee(t[r*3+1])}, ${ee(t[r*3+2])})`;return n.join(", ")}function Ci(t,e){let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ee(t[r*2])}, ${ee(1-t[r*2+1])})`;return n.join(", ")}function Di(t){return Array.from(t).join(", ")}function Ln(t){let e=new Map;for(let a of t){let s=Pn(a.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,r=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let s=a.timeSamples.times[a.timeSamples.times.length-1];s>n&&(n=s)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
218
223
|
endTimeCode = ${ee(n)}
|
|
219
224
|
timeCodesPerSecond = 1.0
|
|
220
|
-
`);let o="";
|
|
221
|
-
uniform token preliminary:planeAnchoring:alignment = "${
|
|
222
|
-
`);let
|
|
225
|
+
`);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
|
|
226
|
+
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
227
|
+
`);let c=`#usda 1.0
|
|
223
228
|
(
|
|
224
229
|
defaultPrim = "Root"
|
|
225
230
|
metersPerUnit = 1.0
|
|
226
231
|
upAxis = "Y"
|
|
227
|
-
${
|
|
232
|
+
${i})
|
|
228
233
|
|
|
229
234
|
def Xform "Root" (
|
|
230
235
|
kind = "component"
|
|
@@ -232,89 +237,89 @@ kind = "component"
|
|
|
232
237
|
{
|
|
233
238
|
${o}def Scope "Materials"
|
|
234
239
|
{
|
|
235
|
-
`;for(let[a,
|
|
236
|
-
`,
|
|
237
|
-
`),
|
|
238
|
-
`),
|
|
239
|
-
`),(f>0||d>0||
|
|
240
|
-
`),
|
|
240
|
+
`;for(let[a,s]of e.entries()){let[u,m,h]=s.color,[f,d,p]=s.emissiveColor,v="";s.clearcoat>0&&(v+=`float inputs:clearcoat = ${ee(s.clearcoat)}
|
|
241
|
+
`,v+=`float inputs:clearcoatRoughness = ${ee(s.clearcoatRoughness)}
|
|
242
|
+
`),s.ior!==1.5&&(v+=`float inputs:ior = ${ee(s.ior)}
|
|
243
|
+
`),s.opacity<1&&(v+=`float inputs:opacity = ${ee(s.opacity)}
|
|
244
|
+
`),(f>0||d>0||p>0)&&(v+=`color3f inputs:emissiveColor = (${ee(f)}, ${ee(d)}, ${ee(p)})
|
|
245
|
+
`),c+=`def Material "${a}"
|
|
241
246
|
{
|
|
242
247
|
def Shader "PBRShader"
|
|
243
248
|
{
|
|
244
249
|
uniform token info:id = "UsdPreviewSurface"
|
|
245
|
-
color3f inputs:diffuseColor = (${ee(
|
|
246
|
-
float inputs:metallic = ${ee(
|
|
247
|
-
float inputs:roughness = ${ee(
|
|
248
|
-
${
|
|
250
|
+
color3f inputs:diffuseColor = (${ee(u)}, ${ee(m)}, ${ee(h)})
|
|
251
|
+
float inputs:metallic = ${ee(s.metallic)}
|
|
252
|
+
float inputs:roughness = ${ee(s.roughness)}
|
|
253
|
+
${v}token outputs:surface
|
|
249
254
|
}
|
|
250
255
|
token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
|
|
251
256
|
}
|
|
252
|
-
`}
|
|
257
|
+
`}c+=`}
|
|
253
258
|
def Scope "Meshes"
|
|
254
259
|
{
|
|
255
|
-
`;let l=new Set;for(let a=0;a<t.length;a++){let
|
|
260
|
+
`;let l=new Set;for(let a=0;a<t.length;a++){let s=t[a],u=s.positions.length/3,m=1/0,h=1/0,f=1/0,d=-1/0,p=-1/0,v=-1/0;for(let b=0;b<u;b++){let A=s.positions[b*3],R=s.positions[b*3+1],E=s.positions[b*3+2];A<m&&(m=A),A>d&&(d=A),R<h&&(h=R),R>p&&(p=R),E<f&&(f=E),E>v&&(v=E)}isFinite(m)||(m=h=f=-1,d=p=v=1);let _=Math.floor(s.indices.length/3),S=Pn(s.materialName,"DefaultMaterial"),y=Pn(s.name,`Mesh_${a}`);l.has(y)&&(y=`${y}_${a}`),l.add(y);let w=_>0?_===1?"3":"3, ".repeat(_-1)+"3":"",g=s.xrTraits,C="";if(g){let b=[];g.physics&&g.physics!=="none"&&b.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let A=oe().xrTraitSerializer?.usdLines(g,Tr)??[];if(!A.length)for(let R of["grab","billboard","follow","anchor","physics"]){let E=R==="follow"&&typeof g.follow=="object"?g.follow.mode??"head":g[R];E!==void 0&&A.push(`string ${R} = "${Tr(E)}"`)}A.length>0&&b.push(`customData = {
|
|
256
261
|
dictionary xr = {
|
|
257
|
-
${
|
|
262
|
+
${A.join(`
|
|
258
263
|
`)}
|
|
259
264
|
}
|
|
260
|
-
}`),
|
|
261
|
-
${
|
|
265
|
+
}`),b.length>0&&(C=` (
|
|
266
|
+
${b.join(`
|
|
262
267
|
`)}
|
|
263
|
-
)`)}if(
|
|
268
|
+
)`)}if(c+=`def Mesh "${y}"${C}
|
|
264
269
|
{
|
|
265
|
-
`,
|
|
266
|
-
bool physics:kinematicEnabled = ${
|
|
270
|
+
`,g?.physics&&g.physics!=="none"){let b=g.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
|
|
271
|
+
bool physics:kinematicEnabled = ${b}
|
|
267
272
|
bool physics:collisionEnabled = true
|
|
268
|
-
`}if(
|
|
269
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
270
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
273
|
+
`}if(s.timeSamples&&s.timeSamples.times.length>0){let b=s.timeSamples,A=b.times.map((O,H)=>{let F=b.translations?.[H]||[0,0,0];return`${ee(O)}: (${ee(F[0])}, ${ee(F[1])}, ${ee(F[2])})`}).join(", "),R=b.times.map((O,H)=>{let F=b.rotations?.[H]||[0,0,0,1];return`${ee(O)}: (${ee(F[3])}, ${ee(F[0])}, ${ee(F[1])}, ${ee(F[2])})`}).join(", "),E=b.times.map((O,H)=>{let F=b.scales?.[H]||[1,1,1];return`${ee(O)}: (${ee(F[0])}, ${ee(F[1])}, ${ee(F[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${A} }
|
|
274
|
+
quatf xformOp:orient.timeSamples = { ${R} }
|
|
275
|
+
double3 xformOp:scale.timeSamples = { ${E} }
|
|
271
276
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
272
|
-
`}
|
|
273
|
-
int[] faceVertexCounts = [${
|
|
274
|
-
int[] faceVertexIndices = [${
|
|
275
|
-
point3f[] points = [${
|
|
276
|
-
`,
|
|
277
|
+
`}c+=`float3[] extent = [(${ee(m)}, ${ee(h)}, ${ee(f)}), (${ee(d)}, ${ee(p)}, ${ee(v)})]
|
|
278
|
+
int[] faceVertexCounts = [${w}]
|
|
279
|
+
int[] faceVertexIndices = [${Di(s.indices)}]
|
|
280
|
+
point3f[] points = [${Sr(s.positions)}]
|
|
281
|
+
`,s.normals&&s.normals.length===s.positions.length&&(c+=`normal3f[] normals = [${Sr(s.normals)}] (
|
|
277
282
|
interpolation = "vertex"
|
|
278
283
|
)
|
|
279
|
-
`),
|
|
284
|
+
`),s.uvs&&s.uvs.length===u*2&&(c+=`texCoord2f[] primvars:st = [${Ci(s.uvs,u)}] (
|
|
280
285
|
interpolation = "vertex"
|
|
281
286
|
)
|
|
282
|
-
`),
|
|
287
|
+
`),c+=`rel material:binding = </Root/Materials/${S}>
|
|
283
288
|
}
|
|
284
|
-
`}return
|
|
289
|
+
`}return c+=`}
|
|
285
290
|
}
|
|
286
|
-
`,u}function Ar(t,e){if(t&&typeof t.traverse=="function"){let r=Si(t,e);return Cn(r)}let n=Ce(t),i=wr(n);return Cn(i)}var Ct=null;function Tr(t){if(!Ct){Ct=new Uint32Array(256);for(let n=0;n<256;n++){let i=n;for(let r=0;r<8;r++)i=i&1?3988292384^i>>>1:i>>>1;Ct[n]=i}}let e=4294967295;for(let n=0;n<t.length;n++)e=Ct[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Dn(t){let e=[],n=0,i=[];for(let s of t){let m=Dt(s.filename),h=Tr(s.data),f=s.data.length,d=30+m.length,b=n+d,g=0,E=b%64;E!==0&&(g=64-E);let A=new Uint8Array(d+g),p=new DataView(A.buffer);p.setUint32(0,67324752,!0),p.setUint16(4,20,!0),p.setUint16(6,0,!0),p.setUint16(8,0,!0),p.setUint16(10,0,!0),p.setUint16(12,0,!0),p.setUint32(14,h,!0),p.setUint32(18,f,!0),p.setUint32(22,f,!0),p.setUint16(26,m.length,!0),p.setUint16(28,g,!0),A.set(m,30),g>0&&A.fill(0,30+m.length),e.push({offset:n,size:f,crc:h,filenameBytes:m,entry:s}),i.push(A),i.push(s.data),n+=A.length+s.data.length}let r=n;for(let s of e){let m=new Uint8Array(46+s.filenameBytes.length),h=new DataView(m.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint16(14,0,!0),h.setUint32(16,s.crc,!0),h.setUint32(20,s.size,!0),h.setUint32(24,s.size,!0),h.setUint16(28,s.filenameBytes.length,!0),h.setUint16(30,0,!0),h.setUint16(32,0,!0),h.setUint16(34,0,!0),h.setUint16(36,0,!0),h.setUint32(38,0,!0),h.setUint32(42,s.offset,!0),m.set(s.filenameBytes,46),i.push(m),n+=m.length}let o=n-r,u=new Uint8Array(22),l=new DataView(u.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,r,!0),l.setUint16(20,0,!0),i.push(u),n+=22;let a=new Uint8Array(n),c=0;for(let s of i)a.set(s,c),c+=s.length;return a}function He(t){let e=Ar(t),n=Dt(e);return Dn([{filename:"model.usda",data:n}])}function Xe(t){let e=Ce(t),n=wr(e),i=Cn(n),r=Dt(i);return Dn([{filename:"model.usda",data:r}])}function It(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?He(t):Xe(t)}function We(t){let e=t&&typeof t.toUSDZ=="function"?t.toUSDZ():Xe(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function Pt(t,e,n,i){let r=typeof t=="number"&&Number.isFinite(t)?t:i;return Math.max(e,Math.min(n,r))}function Ci(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Di(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Rr(t){let e=Di(t);if(!e)return null;let n=e.target;return{target:Ci(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Pt(e.radius,.01,50,.5),speed:Pt(e.speed,-20,20,.5),height:Pt(e.height,-10,10,0),phase:Pt(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}var Lt=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},ae=class t{constructor(e=0,n=0,i=0){this.x=Number(e),this.y=Number(n),this.z=Number(i)}set(e,n,i){return this.x=Number(e),this.y=Number(n),this.z=Number(i),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,i=this.z*e.x-this.x*e.z,r=this.x*e.y-this.y*e.x;return this.x=n,this.y=i,this.z=r,this}crossVectors(e,n){let i=e.x,r=e.y,o=e.z,u=n.x,l=n.y,a=n.z;return this.x=r*a-o*l,this.y=o*u-i*a,this.z=i*l-r*u,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,i=this.y,r=this.z,o=e.elements,u=1/(o[3]*n+o[7]*i+o[11]*r+o[15]);return this.x=(o[0]*n+o[4]*i+o[8]*r+o[12])*u,this.y=(o[1]*n+o[5]*i+o[9]*r+o[13])*u,this.z=(o[2]*n+o[6]*i+o[10]*r+o[14])*u,this}},Ft=class{constructor(e=0,n=0,i=0,r=1){this.x=Number(e),this.y=Number(n),this.z=Number(i),this.w=Number(r)}set(e,n,i,r){return this.x=Number(e),this.y=Number(n),this.z=Number(i),this.w=Number(r),this}},rt=class t{constructor(e=0,n=0,i=0,r="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(i),this.order=r}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,i,r=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(i),this.order=r,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},it=class t{constructor(e=0,n=0,i=0,r=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(i),this._w=Number(r)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,i,r){return this._x=Number(e),this._y=Number(n),this._z=Number(i),this._w=Number(r),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let i=e.x,r=e.y,o=e.z,u=Math.cos(i/2),l=Math.cos(r/2),a=Math.cos(o/2),c=Math.sin(i/2),s=Math.sin(r/2),m=Math.sin(o/2);return this._x=c*l*a+u*s*m,this._y=u*s*a-c*l*m,this._z=u*l*m+c*s*a,this._w=u*l*a-c*s*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let i=n/2,r=Math.sin(i);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(i),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let i=e.x,r=e.y,o=e.z,u=e.w,l=n.x,a=n.y,c=n.z,s=n.w;return this._x=i*s+u*l+r*c-o*a,this._y=r*s+u*a+o*l-i*c,this._z=o*s+u*c+i*a-r*l,this._w=u*s-i*l-r*a-o*c,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Fe=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,i){return Ve(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[i.x,i.y,i.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return pe(this.elements,e.elements,n.elements),this}lookAt(e,n,i){return Mt(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[i.x,i.y,i.z]),this}makeRotationFromQuaternion(e){let n=new ae(0,0,0),i=new ae(1,1,1);return this.compose(n,e,i)}makeTranslation(e,n,i){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(i),this}makeScale(e,n,i){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(i),this}},kt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return ue(this.elements,e.elements),this}},ve=class t{constructor(e,n,i){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&i!==void 0?this.setRGB(e,n,i):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,i){return this.r=Number(e),this.g=Number(n),this.b=Number(i),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Ir={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},te=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let i=this.array?this.array.length:0;if(!Number.isFinite(i)||i<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(i)}`);this.count=Math.floor(i/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,i,r){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=i,this.array[o+2]=r,this.needsUpdate=!0,this}},Ut=class extends te{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Nt=class extends te{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Ot=class extends te{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},be=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof te)this.index=e;else if(Array.isArray(e)){let n=0;for(let r=0;r<e.length;r++)e[r]>n&&(n=e[r]);let i=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new te(i,1)}else e&&e.buffer&&(this.index=new te(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,i=new Float32Array(n*3),r=new ae,o=new ae,u=new ae,l=new ae,a=new ae;if(this.index){let c=this.index.array;for(let s=0;s<c.length;s+=3){let m=c[s],h=c[s+1],f=c[s+2];r.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(h),e.getY(h),e.getZ(h)),u.set(e.getX(f),e.getY(f),e.getZ(f)),l.subVectors(u,o),a.subVectors(r,o),l.cross(a).normalize();for(let d of[m,h,f])i[d*3]+=l.x,i[d*3+1]+=l.y,i[d*3+2]+=l.z}}else for(let c=0;c<n;c+=3){r.set(e.getX(c),e.getY(c),e.getZ(c)),o.set(e.getX(c+1),e.getY(c+1),e.getZ(c+1)),u.set(e.getX(c+2),e.getY(c+2),e.getZ(c+2)),l.subVectors(u,o),a.subVectors(r,o),l.cross(a).normalize();for(let s=0;s<3;s++)i[(c+s)*3]=l.x,i[(c+s)*3+1]=l.y,i[(c+s)*3+2]=l.z}for(let c=0;c<n;c++){let s=i[c*3],m=i[c*3+1],h=i[c*3+2],f=Math.hypot(s,m,h)||1;i[c*3]=s/f,i[c*3+1]=m/f,i[c*3+2]=h/f}return this.setAttribute("normal",new te(i,3)),this}setFromBuffers(e,n,i,r){this.setAttribute("position",new te(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new te(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new te(i instanceof Float32Array?i:new Float32Array(i),2)),this.setIndex(r)}dispose(){}},ot=class extends be{constructor(e=1,n=1,i=1){super();let r=e/2,o=n/2,u=i/2,l=[-r,-o,u,r,-o,u,r,o,u,-r,o,u,r,-o,-u,-r,-o,-u,-r,o,-u,r,o,-u,-r,o,u,r,o,u,r,o,-u,-r,o,-u,-r,-o,-u,r,-o,-u,r,-o,u,-r,-o,u,r,-o,u,r,-o,-u,r,o,-u,r,o,u,-r,-o,-u,-r,-o,u,-r,o,u,-r,o,-u],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],c=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],s=[];for(let m=0;m<6;m++){let h=m*4;s.push(h,h+1,h+2,h,h+2,h+3)}this.setAttribute("position",new te(new Float32Array(l),3)),this.setAttribute("normal",new te(new Float32Array(a),3)),this.setAttribute("uv",new te(new Float32Array(c),2)),this.setIndex(s)}},Bt=class extends be{constructor(e=1,n=1){super();let i=e/2,r=n/2,o=[-i,r,0,i,r,0,-i,-r,0,i,-r,0],u=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],a=[0,2,1,2,3,1];this.setAttribute("position",new te(new Float32Array(o),3)),this.setAttribute("normal",new te(new Float32Array(u),3)),this.setAttribute("uv",new te(new Float32Array(l),2)),this.setIndex(a)}},st=class extends be{constructor(e=1,n=16,i=12){super(),n=Math.max(3,Math.floor(n)),i=Math.max(2,Math.floor(i));let r=[],o=[],u=[],l=[],a=[];for(let c=0;c<=i;c++){let s=[],m=c/i;for(let h=0;h<=n;h++){let f=h/n,d=f*Math.PI*2,b=m*Math.PI,g=-e*Math.cos(d)*Math.sin(b),E=e*Math.cos(b),A=e*Math.sin(d)*Math.sin(b);r.push(g,E,A);let p=Math.hypot(g,E,A)||1;o.push(g/p,E/p,A/p),u.push(f,1-m),s.push(r.length/3-1)}a.push(s)}for(let c=0;c<i;c++)for(let s=0;s<n;s++){let m=a[c][s+1],h=a[c][s],f=a[c+1][s],d=a[c+1][s+1];c!==0&&l.push(m,h,d),c!==i-1&&l.push(h,f,d)}this.setAttribute("position",new te(new Float32Array(r),3)),this.setAttribute("normal",new te(new Float32Array(o),3)),this.setAttribute("uv",new te(new Float32Array(u),2)),this.setIndex(l)}},Pe=class extends be{constructor(e=1,n=1,i=1,r=16){super(),r=Math.max(3,Math.floor(r));let o=[],u=[],l=[],a=[],c=i/2;for(let s=0;s<=1;s++){let m=s,h=s===0?e:n,f=s===0?c:-c;for(let d=0;d<=r;d++){let b=d/r,g=b*Math.PI*2,E=Math.sin(g),A=Math.cos(g);o.push(h*E,f,h*A),u.push(E,0,A),l.push(b,1-m)}}for(let s=0;s<r;s++){let m=s,h=s+r+1,f=s+r+2,d=s+1;a.push(m,h,d,h,f,d)}if(e>0){let s=o.length/3;o.push(0,c,0),u.push(0,1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=r;h++){let f=h/r*Math.PI*2,d=Math.sin(f),b=Math.cos(f);o.push(e*d,c,e*b),u.push(0,1,0),l.push(b*.5+.5,d*.5+.5)}for(let h=0;h<r;h++)a.push(s,m+h,m+h+1)}if(n>0){let s=o.length/3;o.push(0,-c,0),u.push(0,-1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=r;h++){let f=h/r*Math.PI*2,d=Math.sin(f),b=Math.cos(f);o.push(n*d,-c,n*b),u.push(0,-1,0),l.push(b*.5+.5,1-(d*.5+.5))}for(let h=0;h<r;h++)a.push(s,m+h+1,m+h)}this.setAttribute("position",new te(new Float32Array(o),3)),this.setAttribute("normal",new te(new Float32Array(u),3)),this.setAttribute("uv",new te(new Float32Array(l),2)),this.setIndex(a)}},Vt=class extends Pe{constructor(e=1,n=1,i=16){super(0,e,n,i)}},zt=class extends be{constructor(e=1,n=.4,i=12,r=32){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let o=[],u=[],l=[],a=[];for(let c=0;c<=i;c++){let s=c/i*Math.PI*2;for(let m=0;m<=r;m++){let h=m/r*Math.PI*2,f=(e+n*Math.cos(s))*Math.cos(h),d=(e+n*Math.cos(s))*Math.sin(h),b=n*Math.sin(s);o.push(f,d,b);let g=e*Math.cos(h),E=e*Math.sin(h),A=f-g,p=d-E,R=b,x=Math.hypot(A,p,R)||1;u.push(A/x,p/x,R/x),l.push(m/r,c/i)}}for(let c=1;c<=i;c++)for(let s=1;s<=r;s++){let m=(r+1)*c+s-1,h=(r+1)*(c-1)+s-1,f=(r+1)*(c-1)+s,d=(r+1)*c+s;a.push(m,h,d,h,f,d)}this.setAttribute("position",new te(new Float32Array(o),3)),this.setAttribute("normal",new te(new Float32Array(u),3)),this.setAttribute("uv",new te(new Float32Array(l),2)),this.setIndex(a)}},Ht=class extends be{constructor(e=1,n=.4,i=64,r=8,o=2,u=3){super(),i=Math.floor(i),r=Math.floor(r);let l=[],a=[],c=[],s=[],m=new ae,h=new ae,f=new ae,d=new ae,b=new ae;function g(p,R){let x=Math.cos(R),F=Math.sin(R),y=u/o*R,w=e*(2+Math.cos(y))*.5;p.set(w*x,w*F,e*Math.sin(y)*.5)}let E=[];for(let p=0;p<=r;++p){let R=p/r*Math.PI*2;E.push(-n*Math.cos(R),n*Math.sin(R),p/r)}for(let p=0;p<=i;++p){let R=p/i,x=R*o*Math.PI*2;g(m,x),g(h,x+.01),f.subVectors(h,m).normalize(),d.addVectors(m,h).normalize(),b.crossVectors(f,d).normalize(),d.crossVectors(b,f).normalize();for(let F=0;F<=r;++F){let y=F*3,w=E[y],T=E[y+1],I=E[y+2],B=w*d.x+T*b.x,P=w*d.y+T*b.y,N=w*d.z+T*b.z;l.push(m.x+B,m.y+P,m.z+N);let _=Math.hypot(B,P,N)||1;a.push(B/_,P/_,N/_),c.push(R,I)}}let A=r+1;for(let p=1;p<=i;p++){let R=A*(p-1),x=R+A;for(let F=1;F<=r;F++){let y=R+(F-1),w=x+(F-1),T=x+F,I=R+F;s.push(y,w,I,w,T,I)}}this.setAttribute("position",new te(new Float32Array(l),3)),this.setAttribute("normal",new te(new Float32Array(a),3)),this.setAttribute("uv",new te(new Float32Array(c),2)),this.setIndex(s)}},at=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Xt=class{load(e,n){let i=new at(e);return n?.(i),i}};function de(t,e){return t!==void 0?Number(t):e}function In(t,e){return t!==void 0?!!t:e}var Re=class{constructor(e={}){this.name=e.name||"",this.color=new ve(e.color!==void 0?e.color:16777215),this.emissive=new ve(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=de(e.emissiveIntensity,1),this.roughness=de(e.roughness,.5),this.metalness=de(e.metalness,.1),this.opacity=de(e.opacity,1),this.transparent=In(e.transparent,!1),this.wireframe=In(e.wireframe,!1),this.side=de(e.side,2),this.doubleSided=In(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=de(e.clearcoat,0),this.clearcoatRoughness=de(e.clearcoatRoughness,0),this.sheen=de(e.sheen,0),this.sheenColor=new ve(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=de(e.sheenRoughness,0),this.transmission=de(e.transmission,0),this.thickness=de(e.thickness,0),this.attenuationColor=new ve(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=de(e.attenuationDistance,1/0),this.ior=de(e.ior,1.5),this.dispersion=de(e.dispersion,0),this.iridescence=de(e.iridescence,0),this.iridescenceIOR=de(e.iridescenceIOR,1.3)}dispose(){}},ke=class extends Re{},Wt=class extends Re{},Gt=class extends Re{},$t=class extends Re{},qt=class extends Re{},we=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new ae,this.rotation=new rt,this.quaternion=new it,this.scale=new ae(1,1,1),this.matrix=new Fe,this.matrixWorld=new Fe,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),i=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),r=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,i,r)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let i=this.children.indexOf(n);i!==-1&&(n.parent=null,this.children.splice(i,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,i){let r=typeof e=="object"?e:new ae(e,n,i);this.updateMatrixWorld(!0);let o=new Fe;o.lookAt(this.position,r,new ae(0,1,0));let u=o.elements,l=u[0],a=u[4],c=u[8],s=u[1],m=u[5],h=u[9],f=u[2],d=u[6],b=u[10],g=l+m+b;if(g>0){let E=.5/Math.sqrt(g+1);this.quaternion.set((d-h)*E,(c-f)*E,(s-a)*E,.25/E)}}},Yt=class extends we{},Ge=class extends we{constructor(n,i){super();this.isMesh=!0;let r=Array.isArray(i)?i[0]:i;this.geometry=n instanceof be?n:n?(ye("unsupported geometry","BoxGeometry"),new ot(.5,.5,.5)):new be,this.material=r instanceof Re?r:r?(ye("unsupported material","MeshStandardMaterial"),new ke({color:13421772})):new ke}},Ue=class extends we{constructor(e=16777215,n=1){super(),this.color=new ve(e),this.intensity=Number(n),this.type="directional"}},ct=class extends Ue{constructor(e,n){super(e,n),this.type="ambient"}},jt=class extends Ue{constructor(n,i){super(n,i);this.target=new we;this.type="directional"}},ut=class extends Ue{constructor(n,i,r=0,o=2){super(n,i);this.distance=0;this.decay=2;this.type="point",this.distance=r,this.decay=o}},lt=class extends we{},Kt=class extends lt{constructor(n=45,i=1,r=.1,o=1e3){super();this.target=new ae(0,0,0);this.fov=Number(n),this.aspect=Number(i),this.near=Number(r),this.far=Number(o)}},mt=class extends we{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return Te.validate(this),ze(this)}toGLB(){return Te.validate(this),Qe(this)}toUSDZ(){return Te.validate(this),He(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,i=0;return this.traverse(r=>{if(r instanceof Ge){let o=new Float32Array(r.matrixWorld.elements);n.set(i,o),r.name&&n.set(r.name,o),i++}}),n}},Pn=ze,Ln=Qe,Pr=He;var Te=class{static validate(e){let n=0,i=0,r=0,o=new Set,u=(a,c,s)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${c}). Found: ${s}`)},l=(a,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(c)}), which cannot be bounds-checked.`);return c};e.traverse(a=>{if(a instanceof Ge){r++,r>1e3&&u("MESHES",1e3,r);let c=a.geometry;if(c){let s=0;if(c.attributes.position&&(s=l("vertex",c.attributes.position.count),n+=s,n>1e5&&u("VERTICES",1e5,n)),c.index){let m=l("index",c.index.count);i+=m,i>3e5&&u("INDICES",3e5,i);let h=c.index.array;if(h&&s>0){let f=Math.min(m,h.length);for(let d=0;d<f;d++){let b=h[d];if(!Number.isFinite(b)||b<0||b>=s)throw new Error(`SecurityError: Index buffer value (${String(b)}) out of vertex bounds [0, ${s}).`)}}}}if(a.material){let s=a.material;s.map&&o.add(s.map),s.normalMap&&o.add(s.normalMap),s.roughnessMap&&o.add(s.roughnessMap)}}}),o.size>16&&u("TEXTURES",16,o.size);for(let a of o){let c=a,s=c.image,m=Number(s?.width??c.width??0)||0,h=Number(s?.height??c.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(h)||m>2048||h>2048)&&u("TEXTURE_DIMENSION",2048,Math.max(m,h))}}},Zt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let i=new ve(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){Te.validate(e);let r=(o,u)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(u&&u.length?self.postMessage(o,u):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),u={};for(let[l,a]of o.entries())u[l]=Array.from(a);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:u})}else{this.hasInitialModelRendered=!0;let o=Pn(e),u=Ln(e),l=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:u.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[u.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function Er(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Jt=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Er(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Er();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Ii(){}var tt=new Proxy(Ii,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:tt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>tt,construct:()=>tt}),Sr=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function qe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Le(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let i=new URL(n,qe());return!(i.protocol!=="https:"&&i.protocol!=="http:"&&i.protocol!=="blob:"||e?.requireSameOrigin&&i.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&i.origin!==location.origin)}catch{return!1}}var Mr,et;function Lr(t){if(!Le(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(et===void 0||Mr!==n){Mr=n;try{et=n.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Le(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{et=null}}return et?et.createScriptURL(t):t}function Pi(t){re().sandboxEngineSrc=t}function Fn(){let t=re().sandboxEngineSrc;if(t)return t;if(Sr)return Sr;try{if(typeof document>"u")return null;let e=qe(),n=Array.from(document.querySelectorAll("script[src]"));for(let i of n){let r=i.src;if(!r)continue;let o=new URL(r,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Le(r,{requireSameOrigin:!0}))return r}}catch{}return null}function Li(){let t=Fn();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Le(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,qe()).href}function Fi(t){re().sandboxIframeSrc=t}function Fr(){let t=re().sandboxIframeSrc;if(t)return t;let e=Fn();if(!e||!Le(e))return null;let n=new URL(e,qe());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function ki(){let t=Fr();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Le(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,qe()).href}function Ui(t){re().allowClientScripts=t}function kr(){return!!re().allowClientScripts}function Ni(t){if(!Le(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,qe()).href}var Oi=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function Bi(t){let e=self,n=t.nonce,i=t.engineSrc,r=t.allowedScriptUrl,o=t.allowClientScripts,u=t.revoked,l=e.postMessage.bind(e);function a(x){l({type:"ERROR",nonce:n,message:String(x)})}let c=typeof e.importScripts=="function"?e.importScripts.bind(e):null,s=r,m=null;try{let x=i;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let F={createScriptURL:function(w){if(w!==i&&(!r||w!==r))throw new TypeError("Disallowed worker importScripts URL");return w}};o&&(F.createScript=function(w){return String(w)});let y=e.trustedTypes.createPolicy("three-live#worker-boot",F);x=y.createScriptURL(i),r&&(s=y.createScriptURL(r)),o&&typeof y.createScript=="function"&&(m=y.createScript.bind(y))}catch{}c(x)}catch(x){a('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(x&&x.message||x));return}let h=e.THREE;if(!h||typeof h.Scene!="function"){a('Sandbox loaded "'+i+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let x=0;x<u.length;x++){let F=u[x],y=e;for(;y&&y!==Object.prototype;){if(y!==e)try{delete y[F]}catch{}try{Object.defineProperty(y,F,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}}let f=Object.freeze({now:function(){return Date.now()}}),d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:f,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],g=!1;function E(x,F){if(x.type==="3D_MODEL_READY"){if(g)return;g=!0}x.nonce=n,F&&F.length?l(x,F):l(x)}let A=function(x,F){if(!x||b.indexOf(x.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");E(x,F)},p=e;for(;p&&p!==Object.prototype;){if(p===e||Object.prototype.hasOwnProperty.call(p,"postMessage"))try{Object.defineProperty(p,"postMessage",{value:A,writable:!1,configurable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}let R=!1;e.onmessage=function(x){let F=x&&x.data;if(!(!F||F.nonce!==n)&&!(F.type!=="EXECUTE"&&F.type!=="EXECUTE_URL")&&!R){R=!0;try{let y=new h.Scene,w=new h.PerspectiveCamera(60,1,.1,1e3),T=new h.WebGLRenderer({isSandboxed:!0});if(F.type==="EXECUTE_URL"){if(!r||F.scriptUrl!==r||typeof c!="function"){a("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=s||r,B=c;if(c=null,s=null,e.THREE=h,e.scene=y,e.camera=w,e.renderer=T,B(I),typeof e.__THREE_LIVE_SCENE__=="function"){let P=e.__THREE_LIVE_SCENE__(h,y,w,T);P&&typeof P.toGLB=="function"&&(y=P)}else e.scene&&typeof e.scene.toGLB=="function"&&(y=e.scene)}else{if(!o){a("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
291
|
+
`,c}function Mr(t,e){if(t&&typeof t.traverse=="function"){let i=_i(t,e);return Ln(i)}let n=Fe(t),r=Er(n);return Ln(r)}var kt=null;function _r(t){if(!kt){kt=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;kt[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=kt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Fn(t){let e=[],n=0,r=[];for(let u of t){let m=Ut(u.filename),h=_r(u.data),f=u.data.length,d=30+m.length,p=n+d,v=0,_=p%64;_!==0&&(v=64-_);let S=new Uint8Array(d+v),y=new DataView(S.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,h,!0),y.setUint32(18,f,!0),y.setUint32(22,f,!0),y.setUint16(26,m.length,!0),y.setUint16(28,v,!0),S.set(m,30),v>0&&S.fill(0,30+m.length),e.push({offset:n,size:f,crc:h,filenameBytes:m,entry:u}),r.push(S),r.push(u.data),n+=S.length+u.data.length}let i=n;for(let u of e){let m=new Uint8Array(46+u.filenameBytes.length),h=new DataView(m.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint16(14,0,!0),h.setUint32(16,u.crc,!0),h.setUint32(20,u.size,!0),h.setUint32(24,u.size,!0),h.setUint16(28,u.filenameBytes.length,!0),h.setUint16(30,0,!0),h.setUint16(32,0,!0),h.setUint16(34,0,!0),h.setUint16(36,0,!0),h.setUint32(38,0,!0),h.setUint32(42,u.offset,!0),m.set(u.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,c=new Uint8Array(22),l=new DataView(c.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(c),n+=22;let a=new Uint8Array(n),s=0;for(let u of r)a.set(u,s),s+=u.length;return a}function je(t){let e=Mr(t),n=Ut(e);return Fn([{filename:"model.usda",data:n}])}function ot(t){let e=Fe(t),n=Er(e),r=Ln(n),i=Ut(r);return Fn([{filename:"model.usda",data:i}])}function st(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?je(t):ot(t)}function Ke(t){let e=st(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function Nt(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ii(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Pi(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Cr(t){let e=Pi(t);if(!e)return null;let n=e.target;return{target:Ii(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Nt(e.radius,.01,50,.5),speed:Nt(e.speed,-20,20,.5),height:Nt(e.height,-10,10,0),phase:Nt(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}var Ot=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},le=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,c=n.x,l=n.y,a=n.z;return this.x=i*a-o*l,this.y=o*c-r*a,this.z=r*l-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,c=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*c,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*c,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*c,this}},Bt=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},lt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},mt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,c=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(o/2),s=Math.sin(r/2),u=Math.sin(i/2),m=Math.sin(o/2);return this._x=s*l*a+c*u*m,this._y=c*u*a-s*l*m,this._z=c*l*m+s*u*a,this._w=c*l*a-s*u*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,c=e.w,l=n.x,a=n.y,s=n.z,u=n.w;return this._x=r*u+c*l+i*s-o*a,this._y=i*u+c*a+o*l-r*s,this._z=o*u+c*s+r*a-i*l,this._w=c*u-r*l-i*a-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Be=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,r){return qe(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return ge(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return $e(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new le(0,0,0),r=new le(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},Vt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return de(this.elements,e.elements),this}},Te=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Ur={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},re=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},zt=class extends re{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Ht=class extends re{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Xt=class extends re{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},ve=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof re)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new re(r,1)}else e&&e.buffer&&(this.index=new re(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new le,o=new le,c=new le,l=new le,a=new le;if(this.index){let s=this.index.array;for(let u=0;u<s.length;u+=3){let m=s[u],h=s[u+1],f=s[u+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(h),e.getY(h),e.getZ(h)),c.set(e.getX(f),e.getY(f),e.getZ(f)),l.subVectors(c,o),a.subVectors(i,o),l.cross(a).normalize();for(let d of[m,h,f])r[d*3]+=l.x,r[d*3+1]+=l.y,r[d*3+2]+=l.z}}else for(let s=0;s<n;s+=3){i.set(e.getX(s),e.getY(s),e.getZ(s)),o.set(e.getX(s+1),e.getY(s+1),e.getZ(s+1)),c.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),l.subVectors(c,o),a.subVectors(i,o),l.cross(a).normalize();for(let u=0;u<3;u++)r[(s+u)*3]=l.x,r[(s+u)*3+1]=l.y,r[(s+u)*3+2]=l.z}for(let s=0;s<n;s++){let u=r[s*3],m=r[s*3+1],h=r[s*3+2],f=Math.hypot(u,m,h)||1;r[s*3]=u/f,r[s*3+1]=m/f,r[s*3+2]=h/f}return this.setAttribute("normal",new re(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new re(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new re(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new re(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},ht=class extends ve{constructor(e=1,n=1,r=1){super();let i=e/2,o=n/2,c=r/2,l=[-i,-o,c,i,-o,c,i,o,c,-i,o,c,i,-o,-c,-i,-o,-c,-i,o,-c,i,o,-c,-i,o,c,i,o,c,i,o,-c,-i,o,-c,-i,-o,-c,i,-o,-c,i,-o,c,-i,-o,c,i,-o,c,i,-o,-c,i,o,-c,i,o,c,-i,-o,-c,-i,-o,c,-i,o,c,-i,o,-c],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],s=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],u=[];for(let m=0;m<6;m++){let h=m*4;u.push(h,h+1,h+2,h,h+2,h+3)}this.setAttribute("position",new re(new Float32Array(l),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},Wt=class extends ve{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],a=[0,2,1,2,3,1];this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(a)}},dt=class extends ve{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));let i=[],o=[],c=[],l=[],a=[];for(let s=0;s<=r;s++){let u=[],m=s/r;for(let h=0;h<=n;h++){let f=h/n,d=f*Math.PI*2,p=m*Math.PI,v=-e*Math.cos(d)*Math.sin(p),_=e*Math.cos(p),S=e*Math.sin(d)*Math.sin(p);i.push(v,_,S);let y=Math.hypot(v,_,S)||1;o.push(v/y,_/y,S/y),c.push(f,1-m),u.push(i.length/3-1)}a.push(u)}for(let s=0;s<r;s++)for(let u=0;u<n;u++){let m=a[s][u+1],h=a[s][u],f=a[s+1][u],d=a[s+1][u+1];s!==0&&l.push(m,h,d),s!==r-1&&l.push(h,f,d)}this.setAttribute("position",new re(new Float32Array(i),3)),this.setAttribute("normal",new re(new Float32Array(o),3)),this.setAttribute("uv",new re(new Float32Array(c),2)),this.setIndex(l)}},Ne=class extends ve{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],c=[],l=[],a=[],s=r/2;for(let u=0;u<=1;u++){let m=u,h=u===0?e:n,f=u===0?s:-s;for(let d=0;d<=i;d++){let p=d/i,v=p*Math.PI*2,_=Math.sin(v),S=Math.cos(v);o.push(h*_,f,h*S),c.push(_,0,S),l.push(p,1-m)}}for(let u=0;u<i;u++){let m=u,h=u+i+1,f=u+i+2,d=u+1;a.push(m,h,d,h,f,d)}if(e>0){let u=o.length/3;o.push(0,s,0),c.push(0,1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=i;h++){let f=h/i*Math.PI*2,d=Math.sin(f),p=Math.cos(f);o.push(e*d,s,e*p),c.push(0,1,0),l.push(p*.5+.5,d*.5+.5)}for(let h=0;h<i;h++)a.push(u,m+h,m+h+1)}if(n>0){let u=o.length/3;o.push(0,-s,0),c.push(0,-1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=i;h++){let f=h/i*Math.PI*2,d=Math.sin(f),p=Math.cos(f);o.push(n*d,-s,n*p),c.push(0,-1,0),l.push(p*.5+.5,1-(d*.5+.5))}for(let h=0;h<i;h++)a.push(u,m+h+1,m+h)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(a)}},Gt=class extends Ne{constructor(e=1,n=1,r=16){super(0,e,n,r)}},$t=class extends ve{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],c=[],l=[],a=[];for(let s=0;s<=r;s++){let u=s/r*Math.PI*2;for(let m=0;m<=i;m++){let h=m/i*Math.PI*2,f=(e+n*Math.cos(u))*Math.cos(h),d=(e+n*Math.cos(u))*Math.sin(h),p=n*Math.sin(u);o.push(f,d,p);let v=e*Math.cos(h),_=e*Math.sin(h),S=f-v,y=d-_,w=p,g=Math.hypot(S,y,w)||1;c.push(S/g,y/g,w/g),l.push(m/i,s/r)}}for(let s=1;s<=r;s++)for(let u=1;u<=i;u++){let m=(i+1)*s+u-1,h=(i+1)*(s-1)+u-1,f=(i+1)*(s-1)+u,d=(i+1)*s+u;a.push(m,h,d,h,f,d)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(a)}},qt=class extends ve{constructor(e=1,n=.4,r=64,i=8,o=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],a=[],s=[],u=[],m=new le,h=new le,f=new le,d=new le,p=new le;function v(y,w){let g=Math.cos(w),C=Math.sin(w),b=c/o*w,A=e*(2+Math.cos(b))*.5;y.set(A*g,A*C,e*Math.sin(b)*.5)}let _=[];for(let y=0;y<=i;++y){let w=y/i*Math.PI*2;_.push(-n*Math.cos(w),n*Math.sin(w),y/i)}for(let y=0;y<=r;++y){let w=y/r,g=w*o*Math.PI*2;v(m,g),v(h,g+.01),f.subVectors(h,m).normalize(),d.addVectors(m,h).normalize(),p.crossVectors(f,d).normalize(),d.crossVectors(p,f).normalize();for(let C=0;C<=i;++C){let b=C*3,A=_[b],R=_[b+1],E=_[b+2],O=A*d.x+R*p.x,H=A*d.y+R*p.y,F=A*d.z+R*p.z;l.push(m.x+O,m.y+H,m.z+F);let M=Math.hypot(O,H,F)||1;a.push(O/M,H/M,F/M),s.push(w,E)}}let S=i+1;for(let y=1;y<=r;y++){let w=S*(y-1),g=w+S;for(let C=1;C<=i;C++){let b=w+(C-1),A=g+(C-1),R=g+C,E=w+C;u.push(b,A,E,A,R,E)}}this.setAttribute("position",new re(new Float32Array(l),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},ft=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Yt=class{load(e,n){let r=new ft(e);return n?.(r),r}};function pe(t,e){return t!==void 0?Number(t):e}function kn(t,e){return t!==void 0?!!t:e}var Ce=class{constructor(e={}){this.name=e.name||"",this.color=new Te(e.color!==void 0?e.color:16777215),this.emissive=new Te(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=pe(e.emissiveIntensity,1),this.roughness=pe(e.roughness,.5),this.metalness=pe(e.metalness,.1),this.opacity=pe(e.opacity,1),this.transparent=kn(e.transparent,!1),this.wireframe=kn(e.wireframe,!1),this.side=pe(e.side,2),this.doubleSided=kn(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=pe(e.clearcoat,0),this.clearcoatRoughness=pe(e.clearcoatRoughness,0),this.sheen=pe(e.sheen,0),this.sheenColor=new Te(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=pe(e.sheenRoughness,0),this.transmission=pe(e.transmission,0),this.thickness=pe(e.thickness,0),this.attenuationColor=new Te(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=pe(e.attenuationDistance,1/0),this.ior=pe(e.ior,1.5),this.dispersion=pe(e.dispersion,0),this.iridescence=pe(e.iridescence,0),this.iridescenceIOR=pe(e.iridescenceIOR,1.3)}dispose(){}},Ve=class extends Ce{},jt=class extends Ce{},Kt=class extends Ce{},Zt=class extends Ce{},Jt=class extends Ce{},Se=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new le,this.rotation=new lt,this.quaternion=new mt,this.scale=new le(1,1,1),this.matrix=new Be,this.matrixWorld=new Be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new le(e,n,r);this.updateMatrixWorld(!0);let o=new Be;o.lookAt(this.position,i,new le(0,1,0));let c=o.elements,l=c[0],a=c[4],s=c[8],u=c[1],m=c[5],h=c[9],f=c[2],d=c[6],p=c[10],v=l+m+p;if(v>0){let _=.5/Math.sqrt(v+1);this.quaternion.set((d-h)*_,(s-f)*_,(u-a)*_,.25/_)}}},Qt=class extends Se{},Ze=class extends Se{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof ve?n:n?(we("unsupported geometry","BoxGeometry"),new ht(.5,.5,.5)):new ve,this.material=i instanceof Ce?i:i?(we("unsupported material","MeshStandardMaterial"),new Ve({color:13421772})):new Ve}},ze=class extends Se{constructor(e=16777215,n=1){super(),this.color=new Te(e),this.intensity=Number(n),this.type="directional"}},pt=class extends ze{constructor(e,n){super(e,n),this.type="ambient"}},en=class extends ze{constructor(n,r){super(n,r);this.target=new Se;this.type="directional"}},bt=class extends ze{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},yt=class extends Se{},tn=class extends yt{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new le(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},gt=class extends Se{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return _e.validate(this),Ye(this)}toGLB(){return _e.validate(this),it(this)}toUSDZ(){return _e.validate(this),je(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Ze){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},Un=Ye,Nn=it,Nr=je;var _e=class{static validate(e){let n=0,r=0,i=0,o=new Set,c=(a,s,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${s}). Found: ${u}`)},l=(a,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(a=>{if(a instanceof Ze){i++,i>1e3&&c("MESHES",1e3,i);let s=a.geometry;if(s){let u=0;if(s.attributes.position&&(u=l("vertex",s.attributes.position.count),n+=u,n>1e5&&c("VERTICES",1e5,n)),s.index){let m=l("index",s.index.count);r+=m,r>3e5&&c("INDICES",3e5,r);let h=s.index.array;if(h&&u>0){let f=Math.min(m,h.length);for(let d=0;d<f;d++){let p=h[d];if(!Number.isFinite(p)||p<0||p>=u)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${u}).`)}}}}if(a.material){let u=a.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&c("TEXTURES",16,o.size);for(let a of o){let s=a,u=s.image,m=Number(u?.width??s.width??0)||0,h=Number(u?.height??s.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(h)||m>2048||h>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(m,h))}}},nn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new Te(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){_e.validate(e);let i=(o,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(o,c):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),c={};for(let[l,a]of o.entries())c[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let o=Un(e),c=Nn(e),l=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Dr(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var rn=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Dr(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Dr();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Li(){}var ct=new Proxy(Li,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:ct},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>ct,construct:()=>ct}),Ir=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function Qe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Oe(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Qe());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Pr,at;function Or(t){if(!Oe(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(at===void 0||Pr!==n){Pr=n;try{at=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Oe(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{at=null}}return at?at.createScriptURL(t):t}function Fi(t){oe().sandboxEngineSrc=t}function On(){let t=oe().sandboxEngineSrc;if(t)return t;if(Ir)return Ir;try{if(typeof document>"u")return null;let e=Qe(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Oe(i,{requireSameOrigin:!0}))return i}}catch{}return null}function ki(){let t=On();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Oe(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Qe()).href}function Ui(t){oe().sandboxIframeSrc=t}function Br(){let t=oe().sandboxIframeSrc;if(t)return t;let e=On();if(!e||!Oe(e))return null;let n=new URL(e,Qe());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Ni(){let t=Br();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Oe(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Qe()).href}function Oi(t){oe().allowClientScripts=t}function Vr(){return!!oe().allowClientScripts}function Bi(t){if(!Oe(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Qe()).href}var Vi=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function zi(t){let e=self,n=t.nonce,r=t.engineSrc,i=t.allowedScriptUrl,o=t.allowClientScripts,c=t.revoked,l=e.postMessage.bind(e);function a(g){l({type:"ERROR",nonce:n,message:String(g)})}let s=typeof e.importScripts=="function"?e.importScripts.bind(e):null,u=i,m=null;try{let g=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let C={createScriptURL:function(A){if(A!==r&&(!i||A!==i))throw new TypeError("Disallowed worker importScripts URL");return A}};o&&(C.createScript=function(A){return String(A)});let b=e.trustedTypes.createPolicy("three-live#worker-boot",C);g=b.createScriptURL(r),i&&(u=b.createScriptURL(i)),o&&typeof b.createScript=="function"&&(m=b.createScript.bind(b))}catch{}s(g)}catch(g){a('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(g&&g.message||g));return}let h=e.THREE;if(!h||typeof h.Scene!="function"){a('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let g=0;g<c.length;g++){let C=c[g],b=e;for(;b&&b!==Object.prototype;){if(b!==e)try{delete b[C]}catch{}try{Object.defineProperty(b,C,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}}let f=Object.freeze({now:function(){return Date.now()}}),d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:f,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],v=!1;function _(g,C){if(g.type==="3D_MODEL_READY"){if(v)return;v=!0}g.nonce=n,C&&C.length?l(g,C):l(g)}let S=function(g,C){if(!g||p.indexOf(g.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");_(g,C)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:S,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let w=!1;e.onmessage=function(g){let C=g&&g.data;if(!(!C||C.nonce!==n)&&!(C.type!=="EXECUTE"&&C.type!=="EXECUTE_URL")&&!w){w=!0;try{let b=new h.Scene,A=new h.PerspectiveCamera(60,1,.1,1e3),R=new h.WebGLRenderer({isSandboxed:!0});if(C.type==="EXECUTE_URL"){if(!i||C.scriptUrl!==i||typeof s!="function"){a("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let E=u||i,O=s;if(s=null,u=null,e.THREE=h,e.scene=b,e.camera=A,e.renderer=R,O(E),typeof e.__THREE_LIVE_SCENE__=="function"){let H=e.__THREE_LIVE_SCENE__(h,b,A,R);H&&typeof H.toGLB=="function"&&(b=H)}else e.scene&&typeof e.scene.toGLB=="function"&&(b=e.scene)}else{if(!o){a("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let E=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
287
292
|
return (function () {
|
|
288
|
-
`+
|
|
293
|
+
`+C.script+`
|
|
289
294
|
})();
|
|
290
295
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
291
|
-
`+
|
|
292
|
-
})();`);m=null;let B=I(h,y,w,T);B&&typeof B.toGLB=="function"&&(y=B)}if(!g){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(y);let I=y.toGLB(),B=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);E({type:"3D_MODEL_READY",glbBuffer:B},[B])}l({type:"DONE",nonce:n})}catch(y){a(y&&y.message||y)}}},l({type:"READY",nonce:n})}function kn(t,e,n){let i=n?.allowedScriptUrl??null,r=n?.allowClientScripts??i===null,o={nonce:e,engineSrc:t,allowedScriptUrl:i,allowClientScripts:r,revoked:Oi};return`'use strict';(${Bi.toString()})(${JSON.stringify(o)});`}function Ur(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var Ie=0;function Nr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Vi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var zi=1024,Hi=256;function _r(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function Un(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zi)};case"3D_UPDATE_TRANSFORMS":{let r=n.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let o of r)if(!_r(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let o=Object.keys(r);if(o.length>1e3)return null;let u=Object.create(null),l=r;for(let a of o){if(a.length>Hi||a==="__proto__"||a==="constructor"||a==="prototype")return null;let c=l[a];if(!_r(c))return null;u[a]=c}return{type:"3D_UPDATE_TRANSFORMS",transforms:u}}return null}case"3D_MODEL_READY":{let r=n.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Xi(t){let e=Vi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Or(t,e,n,i){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(i.modelDispatched)return;i.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Wi(t,e,n,i){let r=Nr(),o=kn(e,r,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),u=document.createElement("iframe");u.setAttribute("sandbox","allow-scripts"),u.setAttribute("aria-hidden","true"),u.tabIndex=-1,u.style.display="none",u.src=n,Ie++;let l=!1,a=!1,c={modelDispatched:!1},s,m=()=>{if(l||a)return;let b=u.contentWindow;!b||typeof b.postMessage!="function"||(a=!0,b.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:r,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:r,workerSource:o,script:t.script},"*"))},h=()=>{},f=b=>{if(l||!u.contentWindow||b.source!==u.contentWindow)return;let g=b.data;if(g&&typeof g=="object"&&g.type==="IFRAME_READY"){m();return}let E=Un(g,r);E&&Or(E,i,h,c)};h=()=>{l||(l=!0,s!==void 0&&clearTimeout(s),Ie=Math.max(0,Ie-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",f),typeof u.remove=="function"?u.remove():u.parentNode&&u.parentNode.removeChild(u))},s=setTimeout(()=>{l||(h(),Ur(i))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),u.onload=()=>{m()},u.onerror=()=>{h(),i.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let d=document.body||document.documentElement;if(!d||typeof d.appendChild!="function"){h();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw i.onError?.(b),b}return d.appendChild(u),{terminate:h}}function Cr(t,e,n,i){if(e==="worker"&&typeof Worker>"u")return i("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return i("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Ie>=32)return i(`SecurityError: ${Ie} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let r;try{r=Li()}catch(h){let f=h instanceof Error?h.message:String(h);return i(f,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=ki()}catch(f){let d=f instanceof Error?f.message:String(f);return i(d,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Wi(t,r,h,n))}catch(f){return Promise.reject(f)}}let o=Nr(),u=kn(r,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([u],{type:"application/javascript"}),f=URL.createObjectURL(h);try{let d=Lr(f);l=new Worker(d)}finally{URL.revokeObjectURL(f)}}catch(h){let f=h instanceof Error?h.message:String(h);return i(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${f}`,"Security Error: Failed to start Worker sandbox.")}Ie++;let a=!1,c={modelDispatched:!1},s,m=()=>{a||(a=!0,s!==void 0&&clearTimeout(s),Ie=Math.max(0,Ie-1),l.terminate())};return s=setTimeout(()=>{a||(m(),Ur(n))},3e3),l.onmessage=h=>{let f=Un(h.data,o);f&&Or(f,n,m,c)},l.onerror=h=>{m(),n.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function Dr(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Ye={execute(t,e,n,i){let r=(l,a)=>{let c=new Error(l);return n.onError?.(c),a&&n.onToast?.(a),Promise.reject(c)},o=Dr(e,r);if(o)return o;try{Xi(t)}catch(l){let a=l instanceof Error?l.message:String(l);return r(a,"Security Error: script exceeds the size limit.")}return i?.allowClientScripts??kr()?Cr({kind:"script",script:t},e,n,r):r(Tt,Rt)},executeUrl(t,e,n){let i=(u,l)=>{let a=new Error(u);return n.onError?.(a),l&&n.onToast?.(l),Promise.reject(a)},r=Dr(e,i);if(r)return r;let o;try{o=Ni(t)}catch(u){let l=u instanceof Error?u.message:String(u);return i(l,"Security Error: disallowed scene script URL.")}return Cr({kind:"url",scriptUrl:o},e,n,i)}},Qt=new Set;function ye(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;Qt.has(n)||(Qt.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Br(){return Array.from(Qt)}function Vr(){Qt.clear()}var ht=class extends ke{constructor(e={}){ye("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},i=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},zr=ht,Ne=class extends st{constructor(e=1,n=0,i="PolyhedronGeometry"){ye(i,"SphereGeometry");let r=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,r,r)}},en=class extends Ne{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},tn=class extends Ne{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},nn=class extends Ne{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},rn=class extends Ne{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},on=class extends Pe{constructor(e=1,n=1,i=4,r=8){ye("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,r)}},sn=class extends Pe{constructor(e=.5,n=1,i=16){ye("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,i))}},an=class extends Pe{constructor(e=1,n=16){ye("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},cn=class extends ut{constructor(n,i,r=0,o=Math.PI/3,u=0,l=2){ye("SpotLight","PointLight");super(n,i,r,l);this.target=new we;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=u}},dt=class extends ct{constructor(e,n,i){ye("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new ve(n??4473924)}},Hr=dt,Xr={Vector2:Lt,Vector3:ae,Vector4:Ft,Euler:rt,Quaternion:it,Matrix4:Fe,Matrix3:kt,Color:ve,MathUtils:Ir,BufferAttribute:te,Float32BufferAttribute:Ut,Uint16BufferAttribute:Nt,Uint32BufferAttribute:Ot,BufferGeometry:be,BoxGeometry:ot,PlaneGeometry:Bt,SphereGeometry:st,CylinderGeometry:Pe,ConeGeometry:Vt,TorusGeometry:zt,TorusKnotGeometry:Ht,IcosahedronGeometry:en,OctahedronGeometry:tn,DodecahedronGeometry:nn,TetrahedronGeometry:rn,CapsuleGeometry:on,RingGeometry:sn,CircleGeometry:an,Texture:at,TextureLoader:Xt,Material:Re,MeshStandardMaterial:ke,MeshBasicMaterial:Wt,MeshLambertMaterial:Gt,MeshPhongMaterial:$t,MeshPhysicalMaterial:qt,ShaderMaterial:ht,RawShaderMaterial:zr,Object3D:we,Group:Yt,Mesh:Ge,Light:Ue,AmbientLight:ct,DirectionalLight:jt,PointLight:ut,SpotLight:cn,HemisphereLight:dt,RectAreaLight:Hr,Camera:lt,PerspectiveCamera:Kt,Scene:mt,WebGLRenderer:Zt,Clock:Jt,SceneQuotaValidator:Te,exportSceneToCanvas3D:Pn,exportSceneToGLB:Ln,exportSceneToUSDZ:Pr,generateUSDZ:It,glbToUSDZ:Xe,sceneToCanvas3D:ze,sceneToGLB:Qe,sceneToUSDZ:He,authorScriptRunner:Ye,getAuthorWarnings:Br,clearAuthorWarnings:Vr};Object.freeze(Te);Object.freeze(Te.prototype);Object.freeze(mt.prototype);Object.freeze(Xr);var ft=new Proxy(Xr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&ye(`THREE.${e}`,"no-op proxy"),tt),set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),nt={name:"three_author",THREE:ft},Gi=nt,$e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof $e.THREE>"u"&&($e.THREE=ft);typeof $e.requestAnimationFrame!="function"&&($e.requestAnimationFrame=()=>(ye("requestAnimationFrame","single-frame static evaluation"),0));typeof $e.cancelAnimationFrame!="function"&&($e.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=ft,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=nt,t.ThreeLivePlugins.three_author=nt,t.ThreeLivePlugins["three-author"]=nt}var $i=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(t,e){super(t,e),this.detail=e?.detail??null}});var le=class le extends $i{constructor(){super(...arguments);this.viewer=null;this.canvas=null;this.posterEl=null;this.arButton=null;this.currentModel=null;this.currentModelLimits=void 0;this.isModelLoaded=!1;this.scriptHandle=null;this.resizeObserver=null;this.mutationObserver=null}static get arProvider(){return re().arProvider}static set arProvider(n){re().arProvider=n}static get scriptRunner(){return re().scriptRunner}static set scriptRunner(n){re().scriptRunner=n}static get sandboxEngineSrc(){return re().sandboxEngineSrc??null}static set sandboxEngineSrc(n){re().sandboxEngineSrc=n}static get sandboxIframeSrc(){return re().sandboxIframeSrc??null}static set sandboxIframeSrc(n){re().sandboxIframeSrc=n}static get allowClientScripts(){return!!re().allowClientScripts}static set allowClientScripts(n){re().allowClientScripts=n}static registerScriptRunner(n){le.scriptRunner=n}static registerDecoder(n,i){me.registerDecoder(n,i)}static getDecoder(n){return me.getDecoder(n)}static registerAR(n){typeof n=="function"?le.arProvider={activateAR:n}:le.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(r=>{r instanceof le&&r.updateARButtonVisibility()})}static isARSupported(){return!!le.arProvider}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let n=this.getAttribute("src"),i=this.getAttribute("script-src");if(n)this.loadModelFromSrc(n).catch(()=>{});else if(i)this.loadScriptFromSrc(i).catch(()=>{});else{let r=this.querySelector('script[type="text/three"], script[type="text/three-live"]');r&&r.textContent&&this.executeScript(r.textContent).catch(()=>{})}for(let r of me.getRegisteredPlugins())r.onElementConnected?.(this)}disconnectedCallback(){for(let n of me.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(n,i,r){if(i!==r){switch(n){case"src":r&&this.loadModelFromSrc(r).catch(()=>{});break;case"camera-target":this.applyCameraTarget(r);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(r);break;case"script-src":r&&this.loadScriptFromSrc(r).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(r);break;case"camera-orbit":this.applyCameraOrbit(r);break;case"selected-mesh":this.viewer&&r!==null&&this.viewer.setSelectedMesh(r);break;case"exposure":if(this.viewer&&r!==null){let o=parseFloat(r);isNaN(o)||this.viewer.setExposure(o)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer&&r&&this.viewer.setToneMapping(r);break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(r).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(r)?.catch?.(()=>{});break;case"camera-controls":{let o=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(o),this.canvas&&(this.canvas.style.touchAction=o?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(r!==null&&r!=="false");break;case"animation-name":this.viewer&&r!==null&&this.viewer.setAnimationName(r);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(r!==null&&r!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(r));break;case"ar":this.updateARButtonVisibility();break}for(let o of me.getRegisteredPlugins())o.onAttributeChanged?.(this,n,i,r)}}getAttr(n){return this.getAttribute(n)}setAttr(n,i){i!==null?this.setAttribute(n,i):this.removeAttribute(n)}getBoolAttr(n){return this.hasAttribute(n)&&this.getAttribute(n)!=="false"}setBoolAttr(n,i){i?this.setAttribute(n,""):this.removeAttribute(n)}getFloatAttr(n,i){let r=this.getAttribute(n);return r!==null?parseFloat(r):i}get src(){return this.getAttr("src")}set src(n){this.setAttr("src",n)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(n){this.setBoolAttr("camera-controls",n)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(n){this.setAttr("camera-orbit",n)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(n){this.setAttr("camera-target",n)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(n){this.setAttr("min-camera-orbit",n)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(n){this.setAttr("max-camera-orbit",n)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(n){this.setAttr("field-of-view",n)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(n){this.setAttr("ios-src",n)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(n){this.setAttr("script-src",n)}get sandbox(){return this.getAttribute("sandbox")||(re().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||le.allowClientScripts}set allowClientScripts(n){this.setBoolAttr("allow-client-scripts",n)}get poster(){return this.getAttr("poster")}set poster(n){this.setAttr("poster",n)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(n){this.setAttr("selected-mesh",n)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(n){this.setAttribute("exposure",String(n))}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(n){this.setBoolAttr("auto-rotate",n)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(n){this.setAttribute("auto-rotate-delay",String(n))}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(n){this.setAttr("rotation-per-second",n)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(n){this.setBoolAttr("ar",n)}get arScale(){return this.getAttribute("ar-scale")||"auto"}set arScale(n){this.setAttribute("ar-scale",n)}get arPlacement(){return this.getAttribute("ar-placement")||"floor"}set arPlacement(n){this.setAttribute("ar-placement",n)}get canActivateAR(){return le.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(n){this.setAttribute("shadow-intensity",String(n))}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(n){this.setAttribute("shadow-softness",String(n))}get toneMapping(){return this.getAttribute("tone-mapping")||"neutral"}set toneMapping(n){this.setAttribute("tone-mapping",n)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(n){this.setAttr("environment-image",n)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(n){this.setAttr("skybox-image",n)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(n){this.setBoolAttr("autoplay",n)}get animationName(){return this.getAttr("animation-name")}set animationName(n){this.setAttr("animation-name",n)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get model(){let n=this.viewer?this.viewer.getModelMaterials():[];return{materials:n,getMaterialByName(i){return n.find(r=>r.name===i)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(n=0){this.viewer?.resetTurntableRotation(n)}setCamera(n,i,r,o){this.viewer&&this.viewer.setCamera(n,i,r,o)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,i){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(n,i):""}toBlob(n){return this.viewer&&this.viewer.render?.(),new Promise((i,r)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){r(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(o=>{o?i(o):r(new Error("Failed to capture canvas blob."))},n?.mimeType,n?.qualityArgument)})}positionAndNormalFromPoint(n,i){if(!this.viewer)return null;let r=this.viewer.raycastFromScreenPoint(n,i);if(!r)return null;let[o,u,l]=r.hitPoint||r.point,[a,c,s]=r.normal;return{position:{x:o,y:u,z:l,toString(){return`${o}m ${u}m ${l}m`}},normal:{x:a,y:c,z:s,toString(){return`${a}m ${c}m ${s}m`}}}}async loadModel(n){return this.loadModelWithLimits(n)}async loadModelWithLimits(n,i){if(!this.viewer){this.currentModel=n,this.currentModelLimits=i;return}try{let r;if(typeof n=="string"){let l=await fetch(n);if(!l.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${l.status}`);r=await l.arrayBuffer()}else r=n;let o=Ce(r);this.viewer.loadGLBData(o,i),this.currentModel=o,this.currentModelLimits=i,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let u=this.getAttribute("selected-mesh");u&&this.viewer.setSelectedMesh(u),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:o}}))}catch(r){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),r}}showToast(n,i=4e3){if(typeof document>"u")return;let r=this.querySelector(".three-live-toast");r||(r=document.createElement("div"),r.className="three-live-toast",r.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 18px;background-color:rgba(15,23,42,0.92);color:#f8fafc;border:1px solid rgba(56,189,248,0.4);border-radius:9999px;font:500 13px system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.4);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:90%;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis",this.appendChild(r)),r.textContent=n,typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{r&&(r.style.opacity="1",r.style.transform="translateX(-50%) translateY(0)")}):(r.style.opacity="1",r.style.transform="translateX(-50%) translateY(0)"),setTimeout(()=>{r&&(r.style.opacity="0",r.style.transform="translateX(-50%) translateY(10px)")},i)}async activateAR(){if(!this.currentModel){let r=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:r}})),this.showToast(r.message),r}if(!le.arProvider){let r=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:r}})),this.showToast(r.message),r}let n=this.getAttribute("ios-src"),i=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let r=await le.arProvider.activateAR({model:n||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,preferredModes:i.length>0?i:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:o=>{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:o}})),this.showToast(`AR error: ${o.message}`)}}});if(r.success)r.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):r.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):r.mode==="webxr"&&this.showToast("WebXR AR session started.");else{if(typeof document<"u"&&this.currentModel&&le.arProvider.createUSDZBlob)try{let o=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:le.arProvider.createUSDZBlob(this.currentModel),u=URL.createObjectURL(o),l=document.createElement("a");l.href=u,l.download="three_live_model.usdz",document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(u),3e3),this.showToast("\u{1F4F1} AR camera requires iOS / Android. Downloaded USDZ for macOS Quick Look!")}catch{this.showToast(r.error?.message||"AR requires an iOS (Quick Look) or Android (Scene Viewer / WebXR) device.")}else this.showToast(r.error?.message||"AR requires an iOS (Quick Look) or Android (Scene Viewer / WebXR) device.");r.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:r.error}}))}return r}catch(r){throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:r}})),this.showToast(`AR error: ${r.message||String(r)}`),r}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction=this.cameraControls?"none":"auto",n.style.outline="none",this.appendChild(n)),this.canvas=n;let i=this.getAttribute("poster");i&&this.updatePoster(i),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let n=this.autoRotate,i=this.exposure,r=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),o=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),u=this.parseCameraTarget(this.getAttribute("camera-target")),l=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new me(this,this.canvas,{autoRotate:n,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttribute("rotation-per-second")),exposure:i,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,fieldOfView:l,cameraTarget:u,minCameraOrbit:r,maxCameraOrbit:o,onMeshClick:c=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:c}))},onCameraChange:c=>{this.updateHotspots();for(let s of me.getRegisteredPlugins())s.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail:c}))}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let a=this.getAttribute("camera-orbit");a&&this.applyCameraOrbit(a),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(n){if(!(typeof document>"u")){if(!n){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.setAttribute("alt","3D Scene Preview"),this.posterEl.style.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("aria-label","View in Augmented Reality"),n.className="three-live-ar-button",n.setAttribute("part","default-ar-button");let i="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let o=document.createElementNS(i,"svg");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.style.marginRight="6px";let u=document.createElementNS(i,"path");u.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let l=document.createElementNS(i,"polyline");l.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let a=document.createElementNS(i,"line");a.setAttribute("x1","12"),a.setAttribute("y1","22.08"),a.setAttribute("x2","12"),a.setAttribute("y2","12"),o.appendChild(u),o.appendChild(l),o.appendChild(a),n.appendChild(o)}let r=document.createElement("span");r.textContent="View in AR",n.appendChild(r),n.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",n.addEventListener("mouseenter",()=>{n.style.backgroundColor="rgba(30, 41, 59, 0.95)",n.style.transform="scale(1.04)"}),n.addEventListener("mouseleave",()=>{n.style.backgroundColor="rgba(15, 23, 42, 0.85)",n.style.transform="scale(1)"}),n.addEventListener("click",o=>{o.stopPropagation(),this.activateAR()}),this.arButton=n,this.appendChild(n)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let n=this.hasAttribute("ar")&&!!le.arProvider,i=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;i?(this.arButton&&(this.arButton.style.display="none"),i.__tlARBound||(i.__tlARBound=!0,i.addEventListener("click",r=>{r.stopPropagation(),this.activateAR()})),i.dataset.tlOrigDisplay===void 0&&(i.dataset.tlOrigDisplay=i.style.display==="none"?"":i.style.display),i.style.display=n?i.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=n?"flex":"none")}applyCameraOrbit(n){if(!(!n||!this.viewer))try{let i=JSON.parse(n);this.viewer.setInitialCamera(i.theta,i.phi,i.distance,i.zoom)}catch{let i=n.trim().split(/\s+/);if(i.length>=2){let r=a=>a.endsWith("rad")?parseFloat(a)*180/Math.PI:parseFloat(a.replace(/deg$/,"")),o=i[0]==="auto"?void 0:r(i[0]),u=i[1]==="auto"?void 0:r(i[1]),l;i.length>=3&&i[2]!=="auto"&&(l=parseFloat(i[2].replace(/m$/,""))),(o!==void 0&&!isNaN(o)||u!==void 0&&!isNaN(u))&&this.viewer.setInitialCamera(o!==void 0&&!isNaN(o)?o:void 0,u!==void 0&&!isNaN(u)?u:void 0,l!==void 0&&!isNaN(l)?l:void 0)}}}parseOrbitLimit(n){if(!n)return{};let i=n.trim().split(/\s+/),r={};if(i.length>0&&i[0]!=="auto"){let o=i[0].endsWith("rad")?parseFloat(i[0])*180/Math.PI:parseFloat(i[0].replace(/deg$/,""));isNaN(o)||(r.theta=o)}if(i.length>1&&i[1]!=="auto"){let o=i[1].endsWith("rad")?parseFloat(i[1])*180/Math.PI:parseFloat(i[1].replace(/deg$/,""));isNaN(o)||(r.phi=o)}if(i.length>2&&i[2]!=="auto"){let o=parseFloat(i[2].replace(/m$/,""));isNaN(o)||(r.distance=o)}return r}applyOrbitLimits(){if(!this.viewer)return;let n=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),i=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:n.theta,maxTheta:i.theta,minPhi:n.phi,maxPhi:i.phi,minDistance:n.distance,maxDistance:i.distance})}parseCameraTarget(n){if(!n)return;let i=n.trim().split(/\s+/).map(r=>parseFloat(r.replace(/m$/,"")));return i.length>=3&&!i.some(isNaN)?[i[0],i[1],i[2]]:void 0}parseFieldOfView(n){if(!n)return;let i=n.endsWith("rad")?parseFloat(n)*180/Math.PI:parseFloat(n.replace(/deg$/,""));return isNaN(i)?void 0:i}parseRotationPerSecond(n){if(!n)return Math.PI/6;let i=n.trim(),r=parseFloat(i);return isNaN(r)?Math.PI/6:i.endsWith("rad")?r:i.endsWith("%")?r/100*Math.PI*2:r*Math.PI/180}applyCameraTarget(n){let i=this.parseCameraTarget(n);this.viewer&&i&&this.viewer.setTarget(i[0],i[1],i[2])}applyFieldOfView(n){let i=this.parseFieldOfView(n);this.viewer&&i!==void 0&&this.viewer.setFieldOfView(i)}updateHotspot(n){let i=this.querySelector(`[slot="${n.name}"]`);i&&(n.position!==void 0&&i.setAttribute("data-position",n.position),n.normal!==void 0&&i.setAttribute("data-normal",n.normal)),this.updateHotspots()}updateHotspots(){for(let n of me.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}async loadModelFromSrc(n){await this.loadModel(n)}runWithScriptRunner(n){let i=le.scriptRunner;if(!i){let r=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(r.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),new Promise((r,o)=>{let u=!1;n(i,{onModelReady:a=>{this.loadModelWithLimits(a,yr).then(()=>{u||(u=!0,r(a))},c=>{let s=c instanceof Error?c.message:String(c);this.showToast(s),u||(u=!0,o(c))})},onUpdateTransforms:a=>this.viewer?.updateMeshTransforms(a),onError:a=>{this.showToast(a.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:a}})),u||(u=!0,o(a))},onToast:a=>this.showToast(a)}).then(a=>{a&&(this.scriptHandle=a)},a=>{a instanceof Error&&a.message&&this.showToast(a.message),u||(u=!0,o(a))})})}loadScriptFromSrc(n){return this.runWithScriptRunner((i,r)=>{if(typeof i.executeUrl!="function"){let o=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return r.onError?.(o),Promise.reject(o)}return i.executeUrl(n,this.sandbox,r)})}executeScript(n){if(!le.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let i=new Error(Tt);return this.showToast(Rt),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.runWithScriptRunner((i,r)=>i.execute(n,this.sandbox,r,{allowClientScripts:!0}))}};le.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","environment-image","skybox-image","autoplay","animation-name","auto-rotate","auto-rotate-delay","rotation-per-second"],le.registerPlugin=me.registerPlugin,le.getRegisteredPlugins=me.getRegisteredPlugins;var Ee=le;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",Ee);function un(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function mn(t,e,n,i){let r=e[0],o=e[1],u=e[2],l=e[3],a=n[0],c=n[1],s=n[2],m=n[3],h=r*a+o*c+u*s+l*m;if(h<0&&(a=-a,c=-c,s=-s,m=-m,h=-h),Math.abs(h)>=1)return t[0]=r,t[1]=o,t[2]=u,t[3]=l,t;let f=Math.acos(h),d=Math.sqrt(1-h*h);if(Math.abs(d)<.001)return t[0]=.5*(r+a),t[1]=.5*(o+c),t[2]=.5*(u+s),t[3]=.5*(l+m),t;let b=Math.sin((1-i)*f)/d,g=Math.sin(i*f)/d;return t[0]=r*b+a*g,t[1]=o*b+c*g,t[2]=u*b+s*g,t[3]=l*b+m*g,t}function Wr(t,e,n,i){return t[0]=e[0]+i*(n[0]-e[0]),t[1]=e[1]+i*(n[1]-e[1]),t[2]=e[2]+i*(n[2]-e[2]),t}function On(t,e){if(!Array.isArray(t?.animations))return[];let n=[];for(let i=0;i<t.animations.length;i++){let r=t.animations[i],o=r.name||`Animation_${i}`,u=[],l=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let a of r.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let c=r.samplers[a.sampler];if(!c)continue;let s=t.accessors?.[c.input],m=t.accessors?.[c.output];if(!s||!m)continue;let h=t.bufferViews?.[s.bufferView],f=t.bufferViews?.[m.bufferView];if(!h||!f)continue;let d=(h.byteOffset||0)+(s.byteOffset||0),b=(f.byteOffset||0)+(m.byteOffset||0),g=un(e,d,s.count);g.length>0&&g[g.length-1]>l&&(l=g[g.length-1]);let E=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,s.count))):3,A=un(e,b,m.count*(a.target.path==="weights"?1:E)),p=c.interpolation==="STEP"?"STEP":"LINEAR";u.push({nodeIndex:a.target.node,path:a.target.path,times:g,values:A,interpolation:p})}u.length>0&&n.push({name:o,duration:l,channels:u})}return n}function je(t,e,n){let{times:i,values:r,path:o,interpolation:u}=t,l=i.length;if(l===0)return;let a=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(r.length/l)):3;if(e<=i[0]){for(let A=0;A<a;A++)n[A]=r[A];return}if(e>=i[l-1]){let A=(l-1)*a;for(let p=0;p<a;p++)n[p]=r[A+p];return}let c=0,s=l-1;for(;c<=s;){let A=c+s>>1;i[A]<=e?c=A+1:s=A-1}let m=Math.max(0,s),h=Math.min(l-1,m+1);if(u==="STEP"||m===h){let A=m*a;for(let p=0;p<a;p++)n[p]=r[A+p];return}let f=i[m],d=i[h],b=(e-f)/Math.max(1e-5,d-f),g=m*a,E=h*a;if(o==="rotation"){let A=[r[g],r[g+1],r[g+2],r[g+3]],p=[r[E],r[E+1],r[E+2],r[E+3]];mn(n,A,p,b)}else for(let A=0;A<a;A++)n[A]=r[g+A]+b*(r[E+A]-r[g+A])}var ln=new WeakMap;function Bn(t,e,n=.3){if(!t?.animations)return;let i=t.animations.find(l=>l.name===e);if(!i)return;let r=ln.get(t);r||(r=[],t.currentClip&&r.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),ln.set(t,r));let o=n>0?1/n:1e3;for(let l of r)l.clip.name!==e&&(l.fadeSpeed=-o);let u=r.find(l=>l.clip.name===e);u?u.fadeSpeed=o:r.push({clip:i,time:0,weight:n>0?0:1,fadeSpeed:o}),t.currentClip=i,t.isPlayingAnimation=!0}function Nn(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=ln.get(t);if(!n||n.length===0){if(!t.currentClip)return;n=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let i=t.gltf.nodes.length,r=[];for(let m=0;m<i;m++){let h=t.initialNodeTransforms[m];h?r.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let o=[0,0,0],u=[0,0,0,1],l=[1,1,1],a=new Float32Array(64);for(let m of n){let h=Math.max(0,Math.min(1,m.weight));if(!(h<=1e-4))for(let f of m.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=i)continue;let d=r[f.nodeIndex];if(f.path==="translation")je(f,m.time,o),Wr(d.t,d.t,o,h);else if(f.path==="rotation")je(f,m.time,u),mn(d.r,d.r,u,h);else if(f.path==="scale")je(f,m.time,l),Wr(d.s,d.s,l,h);else if(f.path==="weights"&&(je(f,m.time,a),t.meshes)){for(let b of t.meshes)if(b.nodeIndex===f.nodeIndex){for(let g of b.primitives)if(g.pluginData?.morph?.weights){let E=g.pluginData.morph.weights,A=g.pluginData.morph.numTargets||E.length;for(let p=0;p<A;p++)E[p]=E[p]*(1-h)+a[p]*h}}}}}let c=[];for(let m=0;m<i;m++){let h=se(),{t:f,r:d,s:b}=r[m];Ve(h,d,f,b),c.push(h)}let s=_e(t.gltf,c);t.worldMatrices=s;for(let m of t.meshes)m.nodeIndex>=0&&m.nodeIndex<s.length&&(m.transform.set(s[m.nodeIndex]),ue(m.normalMatrix,m.transform))}var Vn={name:"keyframes",evaluateAnimation:Nn,crossFadeTo:Bn,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=On(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=ln.get(t);if(n&&n.length>0){for(let i=n.length-1;i>=0;i--){let r=n[i];if(r.time+=e,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*e,r.weight<=0){n.splice(i,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}n.length>0&&(t.animationTime=n[n.length-1].time),Nn(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),Nn(t,t.animationTime))}};var pt=64;function Gr(t,e,n){if(!(!t?.meshes||e<0||e>=pt))for(let i of t.meshes)for(let r of i.primitives){let o=r.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var zn={name:"morph",onResolveShader(t,e,n,i){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let r=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
296
|
+
`+C.script+`
|
|
297
|
+
})();`);m=null;let O=E(h,b,A,R);O&&typeof O.toGLB=="function"&&(b=O)}if(!v){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(b);let E=b.toGLB(),O=E instanceof ArrayBuffer?E:E.buffer.slice(E.byteOffset,E.byteOffset+E.byteLength);_({type:"3D_MODEL_READY",glbBuffer:O},[O])}l({type:"DONE",nonce:n})}catch(b){a(b&&b.message||b)}}},l({type:"READY",nonce:n})}function Bn(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Vi};return`'use strict';(${zi.toString()})(${JSON.stringify(o)});`}function zr(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var Ue=0;function Hr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Hi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Xi=1024,Wi=256;function Lr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function Vn(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Xi)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Lr(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let c=Object.create(null),l=i;for(let a of o){if(a.length>Wi||a==="__proto__"||a==="constructor"||a==="prototype")return null;let s=l[a];if(!Lr(s))return null;c[a]=s}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Gi(t){let e=Hi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Xr(t,e,n,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function $i(t,e,n,r){let i=Hr(),o=Bn(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=n,Ue++;let l=!1,a=!1,s={modelDispatched:!1},u,m=()=>{if(l||a)return;let p=c.contentWindow;!p||typeof p.postMessage!="function"||(a=!0,p.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},h=()=>{},f=p=>{if(l||!c.contentWindow||p.source!==c.contentWindow)return;let v=p.data;if(v&&typeof v=="object"&&v.type==="IFRAME_READY"){m();return}let _=Vn(v,i);_&&Xr(_,r,h,s)};h=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Ue=Math.max(0,Ue-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",f),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},u=setTimeout(()=>{l||(h(),zr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),c.onload=()=>{m()},c.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let d=document.body||document.documentElement;if(!d||typeof d.appendChild!="function"){h();let p=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(p),p}return d.appendChild(c),{terminate:h}}function Fr(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Ue>=32)return r(`SecurityError: ${Ue} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=ki()}catch(h){let f=h instanceof Error?h.message:String(h);return r(f,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Ni()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve($i(t,i,h,n))}catch(f){return Promise.reject(f)}}let o=Hr(),c=Bn(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([c],{type:"application/javascript"}),f=URL.createObjectURL(h);try{let d=Or(f);l=new Worker(d)}finally{URL.revokeObjectURL(f)}}catch(h){let f=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${f}`,"Security Error: Failed to start Worker sandbox.")}Ue++;let a=!1,s={modelDispatched:!1},u,m=()=>{a||(a=!0,u!==void 0&&clearTimeout(u),Ue=Math.max(0,Ue-1),l.terminate())};return u=setTimeout(()=>{a||(m(),zr(n))},3e3),l.onmessage=h=>{let f=Vn(h.data,o);f&&Xr(f,n,m,s)},l.onerror=h=>{m(),n.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function kr(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var et={execute(t,e,n,r){let i=(l,a)=>{let s=new Error(l);return n.onError?.(s),a&&n.onToast?.(a),Promise.reject(s)},o=kr(e,i);if(o)return o;try{Gi(t)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Vr()?Fr({kind:"script",script:t},e,n,i):i(Ct,Dt)},executeUrl(t,e,n){let r=(c,l)=>{let a=new Error(c);return n.onError?.(a),l&&n.onToast?.(l),Promise.reject(a)},i=kr(e,r);if(i)return i;let o;try{o=Bi(t)}catch(c){let l=c instanceof Error?c.message:String(c);return r(l,"Security Error: disallowed scene script URL.")}return Fr({kind:"url",scriptUrl:o},e,n,r)}},on=new Set;function we(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;on.has(n)||(on.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Wr(){return Array.from(on)}function Gr(){on.clear()}var xt=class extends Ve{constructor(e={}){we("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},$r=xt,He=class extends dt{constructor(e=1,n=0,r="PolyhedronGeometry"){we(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},sn=class extends He{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},an=class extends He{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},cn=class extends He{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},un=class extends He{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},ln=class extends Ne{constructor(e=1,n=1,r=4,i=8){we("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},mn=class extends Ne{constructor(e=.5,n=1,r=16){we("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},hn=class extends Ne{constructor(e=1,n=16){we("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},dn=class extends bt{constructor(n,r,i=0,o=Math.PI/3,c=0,l=2){we("SpotLight","PointLight");super(n,r,i,l);this.target=new Se;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=c}},vt=class extends pt{constructor(e,n,r){we("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new Te(n??4473924)}},qr=vt,Yr={Vector2:Ot,Vector3:le,Vector4:Bt,Euler:lt,Quaternion:mt,Matrix4:Be,Matrix3:Vt,Color:Te,MathUtils:Ur,BufferAttribute:re,Float32BufferAttribute:zt,Uint16BufferAttribute:Ht,Uint32BufferAttribute:Xt,BufferGeometry:ve,BoxGeometry:ht,PlaneGeometry:Wt,SphereGeometry:dt,CylinderGeometry:Ne,ConeGeometry:Gt,TorusGeometry:$t,TorusKnotGeometry:qt,IcosahedronGeometry:sn,OctahedronGeometry:an,DodecahedronGeometry:cn,TetrahedronGeometry:un,CapsuleGeometry:ln,RingGeometry:mn,CircleGeometry:hn,Texture:ft,TextureLoader:Yt,Material:Ce,MeshStandardMaterial:Ve,MeshBasicMaterial:jt,MeshLambertMaterial:Kt,MeshPhongMaterial:Zt,MeshPhysicalMaterial:Jt,ShaderMaterial:xt,RawShaderMaterial:$r,Object3D:Se,Group:Qt,Mesh:Ze,Light:ze,AmbientLight:pt,DirectionalLight:en,PointLight:bt,SpotLight:dn,HemisphereLight:vt,RectAreaLight:qr,Camera:yt,PerspectiveCamera:tn,Scene:gt,WebGLRenderer:nn,Clock:rn,SceneQuotaValidator:_e,exportSceneToCanvas3D:Un,exportSceneToGLB:Nn,exportSceneToUSDZ:Nr,generateUSDZ:st,glbToUSDZ:ot,sceneToCanvas3D:Ye,sceneToGLB:it,sceneToUSDZ:je,authorScriptRunner:et,getAuthorWarnings:Wr,clearAuthorWarnings:Gr};Object.freeze(_e);Object.freeze(_e.prototype);Object.freeze(gt.prototype);Object.freeze(Yr);var wt=new Proxy(Yr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&we(`THREE.${e}`,"no-op proxy"),ct),set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),ut={name:"three_author",THREE:wt},qi=ut,Je=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Je.THREE>"u"&&(Je.THREE=wt);typeof Je.requestAnimationFrame!="function"&&(Je.requestAnimationFrame=()=>(we("requestAnimationFrame","single-frame static evaluation"),0));typeof Je.cancelAnimationFrame!="function"&&(Je.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=wt,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=ut,t.ThreeLivePlugins.three_author=ut,t.ThreeLivePlugins["three-author"]=ut}var Yi=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(t,e){super(t,e),this.detail=e?.detail??null}});var me=class me extends Yi{constructor(){super(...arguments);this.viewer=null;this.canvas=null;this.posterEl=null;this.arButton=null;this.currentModel=null;this.activeXRSession=null;this.toastTimer=null;this.currentModelLimits=void 0;this.isModelLoaded=!1;this.scriptHandle=null;this.resizeObserver=null;this.mutationObserver=null}static get arProvider(){return oe().arProvider}static set arProvider(n){oe().arProvider=n}static get scriptRunner(){return oe().scriptRunner}static set scriptRunner(n){oe().scriptRunner=n}static get sandboxEngineSrc(){return oe().sandboxEngineSrc??null}static set sandboxEngineSrc(n){oe().sandboxEngineSrc=n}static get sandboxIframeSrc(){return oe().sandboxIframeSrc??null}static set sandboxIframeSrc(n){oe().sandboxIframeSrc=n}static get allowClientScripts(){return!!oe().allowClientScripts}static set allowClientScripts(n){oe().allowClientScripts=n}static registerScriptRunner(n){me.scriptRunner=n}static registerDecoder(n,r){fe.registerDecoder(n,r)}static getDecoder(n){return fe.getDecoder(n)}static registerAR(n){typeof n=="function"?me.arProvider={activateAR:n}:me.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof me&&i.updateARButtonVisibility()})}static isARSupported(){return!!me.arProvider}getLoadedModel(){return this.currentModel}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let n=this.getAttribute("src"),r=this.getAttribute("script-src");if(n)this.loadModelFromSrc(n).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of fe.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of fe.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.activeXRSession&&(this.activeXRSession.stop?.().catch?.(()=>{}),this.activeXRSession=null),this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(n,r,i){if(r!==i){switch(n){case"src":i&&this.loadModelFromSrc(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let o=parseFloat(i);isNaN(o)||this.viewer.setExposure(o)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer&&i&&this.viewer.setToneMapping(i);break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let o=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(o),this.canvas&&(this.canvas.style.touchAction=o?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let o of fe.getRegisteredPlugins())o.onAttributeChanged?.(this,n,r,i)}}getAttr(n){return this.getAttribute(n)}setAttr(n,r){r!==null?this.setAttribute(n,r):this.removeAttribute(n)}getBoolAttr(n){return this.hasAttribute(n)&&this.getAttribute(n)!=="false"}setBoolAttr(n,r){r?this.setAttribute(n,""):this.removeAttribute(n)}getFloatAttr(n,r){let i=this.getAttribute(n);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(n){this.setAttr("src",n)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(n){this.setBoolAttr("camera-controls",n)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(n){this.setAttr("camera-orbit",n)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(n){this.setAttr("camera-target",n)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(n){this.setAttr("min-camera-orbit",n)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(n){this.setAttr("max-camera-orbit",n)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(n){this.setAttr("field-of-view",n)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(n){this.setAttr("ios-src",n)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(n){this.setAttr("script-src",n)}get sandbox(){return this.getAttribute("sandbox")||(oe().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||me.allowClientScripts}set allowClientScripts(n){this.setBoolAttr("allow-client-scripts",n)}get poster(){return this.getAttr("poster")}set poster(n){this.setAttr("poster",n)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(n){this.setAttr("selected-mesh",n)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(n){this.setAttribute("exposure",String(n))}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(n){this.setBoolAttr("auto-rotate",n)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(n){this.setAttribute("auto-rotate-delay",String(n))}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(n){this.setAttr("rotation-per-second",n)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(n){this.setBoolAttr("ar",n)}get arScale(){return this.getAttribute("ar-scale")||"auto"}set arScale(n){this.setAttribute("ar-scale",n)}get arPlacement(){return this.getAttribute("ar-placement")||"floor"}set arPlacement(n){this.setAttribute("ar-placement",n)}get canActivateAR(){return me.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(n){this.setAttribute("shadow-intensity",String(n))}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(n){this.setAttribute("shadow-softness",String(n))}get toneMapping(){return this.getAttribute("tone-mapping")||"neutral"}set toneMapping(n){this.setAttribute("tone-mapping",n)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(n){this.setAttr("environment-image",n)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(n){this.setAttr("skybox-image",n)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(n){this.setBoolAttr("autoplay",n)}get animationName(){return this.getAttr("animation-name")}set animationName(n){this.setAttr("animation-name",n)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get model(){let n=this.viewer?this.viewer.getModelMaterials():[];return{materials:n,getMaterialByName(r){return n.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(n=0){this.viewer?.resetTurntableRotation(n)}setCamera(n,r,i,o){this.viewer&&this.viewer.setCamera(n,r,i,o)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,r){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(n,r):""}toBlob(n){return this.viewer&&this.viewer.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(o=>{o?r(o):i(new Error("Failed to capture canvas blob."))},n?.mimeType,n?.qualityArgument)})}positionAndNormalFromPoint(n,r){if(!this.viewer)return null;let i=this.viewer.raycastFromScreenPoint(n,r);if(!i)return null;let[o,c,l]=i.hitPoint||i.point,[a,s,u]=i.normal;return{position:{x:o,y:c,z:l,toString(){return`${o}m ${c}m ${l}m`}},normal:{x:a,y:s,z:u,toString(){return`${a}m ${s}m ${u}m`}}}}async loadModel(n){return this.loadModelWithLimits(n)}async loadModelWithLimits(n,r){if(!this.viewer){this.currentModel=n,this.currentModelLimits=r;return}try{let i;if(typeof n=="string"){this.isModelLoaded=!1,this.viewer?.clearScene?.();let l=await fetch(n);if(!l.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${l.status}`);i=await l.arrayBuffer()}else i=n;let o=Fe(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let c=this.getAttribute("selected-mesh");c&&this.viewer.setSelectedMesh(c),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:o}}))}catch(i){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),i}}showToast(n,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=n,this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")}):(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)"),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){if(this.activeXRSession&&typeof this.activeXRSession.isSessionActive=="function"&&this.activeXRSession.isSessionActive()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null),!this.currentModel){let i=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}if(!me.arProvider){let i=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}let n=this.getAttribute("ios-src"),r=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let i=await me.arProvider.activateAR({model:n||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:r.length>0?r:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:o=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:o}})),this.showToast(`AR error: ${o.message}`,6e3)}}});if(i.success)i.session&&(this.activeXRSession=i.session),i.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):i.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):i.mode==="webxr"&&this.showToast("WebXR AR session started.");else{let o=typeof navigator<"u"&&navigator.userAgent||"",c=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),l=/Android|iPhone|iPad|iPod/i.test(o);if(c&&!l&&typeof document<"u"&&this.currentModel&&me.arProvider.createUSDZBlob)try{let a=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:me.arProvider.createUSDZBlob(this.currentModel),s=URL.createObjectURL(a),u=document.createElement("a");u.href=s,u.download="three_live_model.usdz",document.body.appendChild(u),u.click(),document.body.removeChild(u),setTimeout(()=>URL.revokeObjectURL(s),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3)}else this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3);i.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i.error}}))}return i}catch(i){throw this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(`AR error: ${i.message||String(i)}`,6e3),i}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction=this.cameraControls?"none":"auto",n.style.outline="none",this.appendChild(n)),this.canvas=n;let r=this.getAttribute("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let n=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),o=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),c=this.parseCameraTarget(this.getAttribute("camera-target")),l=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new fe(this,this.canvas,{autoRotate:n,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttribute("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,fieldOfView:l,cameraTarget:c,minCameraOrbit:i,maxCameraOrbit:o,onMeshClick:s=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:s}))},onCameraChange:s=>{this.updateHotspots();for(let u of fe.getRegisteredPlugins())u.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail:s}))}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let a=this.getAttribute("camera-orbit");a&&this.applyCameraOrbit(a),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(n){if(!(typeof document>"u")){if(!n){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.setAttribute("alt","3D Scene Preview"),this.posterEl.style.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("aria-label","View in Augmented Reality"),n.className="three-live-ar-button",n.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let o=document.createElementNS(r,"svg");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.style.marginRight="6px";let c=document.createElementNS(r,"path");c.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let l=document.createElementNS(r,"polyline");l.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let a=document.createElementNS(r,"line");a.setAttribute("x1","12"),a.setAttribute("y1","22.08"),a.setAttribute("x2","12"),a.setAttribute("y2","12"),o.appendChild(c),o.appendChild(l),o.appendChild(a),n.appendChild(o)}let i=document.createElement("span");i.textContent="View in AR",n.appendChild(i),n.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",n.addEventListener("mouseenter",()=>{n.style.backgroundColor="rgba(30, 41, 59, 0.95)",n.style.transform="scale(1.04)"}),n.addEventListener("mouseleave",()=>{n.style.backgroundColor="rgba(15, 23, 42, 0.85)",n.style.transform="scale(1)"}),n.addEventListener("click",o=>{o.stopPropagation(),this.activateAR()}),this.arButton=n,this.appendChild(n)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let n=this.hasAttribute("ar")&&!!me.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=n?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=n?"flex":"none")}applyCameraOrbit(n){if(!(!n||!this.viewer))try{let r=JSON.parse(n);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=n.trim().split(/\s+/);if(r.length>=2){let i=a=>a.endsWith("rad")?parseFloat(a)*180/Math.PI:parseFloat(a.replace(/deg$/,"")),o=r[0]==="auto"?void 0:i(r[0]),c=r[1]==="auto"?void 0:i(r[1]),l;r.length>=3&&r[2]!=="auto"&&(l=parseFloat(r[2].replace(/m$/,""))),(o!==void 0&&!isNaN(o)||c!==void 0&&!isNaN(c))&&this.viewer.setInitialCamera(o!==void 0&&!isNaN(o)?o:void 0,c!==void 0&&!isNaN(c)?c:void 0,l!==void 0&&!isNaN(l)?l:void 0)}}}parseOrbitLimit(n){if(!n)return{};let r=n.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let o=r[0].endsWith("rad")?parseFloat(r[0])*180/Math.PI:parseFloat(r[0].replace(/deg$/,""));isNaN(o)||(i.theta=o)}if(r.length>1&&r[1]!=="auto"){let o=r[1].endsWith("rad")?parseFloat(r[1])*180/Math.PI:parseFloat(r[1].replace(/deg$/,""));isNaN(o)||(i.phi=o)}if(r.length>2&&r[2]!=="auto"){let o=parseFloat(r[2].replace(/m$/,""));isNaN(o)||(i.distance=o)}return i}applyOrbitLimits(){if(!this.viewer)return;let n=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:n.theta,maxTheta:r.theta,minPhi:n.phi,maxPhi:r.phi,minDistance:n.distance,maxDistance:r.distance})}parseCameraTarget(n){if(!n)return;let r=n.trim().split(/\s+/).map(i=>parseFloat(i.replace(/m$/,"")));return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(n){if(!n)return;let r=n.endsWith("rad")?parseFloat(n)*180/Math.PI:parseFloat(n.replace(/deg$/,""));return isNaN(r)?void 0:r}parseRotationPerSecond(n){if(!n)return Math.PI/6;let r=n.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(n){let r=this.parseCameraTarget(n);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(n){let r=this.parseFieldOfView(n);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(n){let r=this.querySelector(`[slot="${n.name}"]`);r&&(n.position!==void 0&&r.setAttribute("data-position",n.position),n.normal!==void 0&&r.setAttribute("data-normal",n.normal)),this.updateHotspots()}updateHotspots(){for(let n of fe.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}async loadModelFromSrc(n){await this.loadModel(n)}runWithScriptRunner(n){let r=me.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.isModelLoaded=!1,this.viewer?.clearScene?.(),new Promise((i,o)=>{let c=!1;n(r,{onModelReady:a=>{this.loadModelWithLimits(a,Ar).then(()=>{c||(c=!0,i(a))},s=>{let u=s instanceof Error?s.message:String(s);this.showToast(u),c||(c=!0,o(s))})},onUpdateTransforms:a=>this.viewer?.updateMeshTransforms(a),onError:a=>{this.showToast(a.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:a}})),c||(c=!0,o(a))},onToast:a=>this.showToast(a)}).then(a=>{a&&(this.scriptHandle=a)},a=>{a instanceof Error&&a.message&&this.showToast(a.message),c||(c=!0,o(a))})})}loadScriptFromSrc(n){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let o=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(o),Promise.reject(o)}return r.executeUrl(n,this.sandbox,i)})}executeScript(n){if(!me.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Ct);return this.showToast(Dt),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(n,this.sandbox,i,{allowClientScripts:!0}))}};me.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","environment-image","skybox-image","autoplay","animation-name","auto-rotate","auto-rotate-delay","rotation-per-second"],me.registerPlugin=fe.registerPlugin,me.getRegisteredPlugins=fe.getRegisteredPlugins;var De=me;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",De);function fn(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function bn(t,e,n,r){let i=e[0],o=e[1],c=e[2],l=e[3],a=n[0],s=n[1],u=n[2],m=n[3],h=i*a+o*s+c*u+l*m;if(h<0&&(a=-a,s=-s,u=-u,m=-m,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=o,t[2]=c,t[3]=l,t;let f=Math.acos(h),d=Math.sqrt(1-h*h);if(Math.abs(d)<.001)return t[0]=.5*(i+a),t[1]=.5*(o+s),t[2]=.5*(c+u),t[3]=.5*(l+m),t;let p=Math.sin((1-r)*f)/d,v=Math.sin(r*f)/d;return t[0]=i*p+a*v,t[1]=o*p+s*v,t[2]=c*p+u*v,t[3]=l*p+m*v,t}function jr(t,e,n,r){return t[0]=e[0]+r*(n[0]-e[0]),t[1]=e[1]+r*(n[1]-e[1]),t[2]=e[2]+r*(n[2]-e[2]),t}function Hn(t,e){if(!Array.isArray(t?.animations))return[];let n=[];for(let r=0;r<t.animations.length;r++){let i=t.animations[r],o=i.name||`Animation_${r}`,c=[],l=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let a of i.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let s=i.samplers[a.sampler];if(!s)continue;let u=t.accessors?.[s.input],m=t.accessors?.[s.output];if(!u||!m)continue;let h=t.bufferViews?.[u.bufferView],f=t.bufferViews?.[m.bufferView];if(!h||!f)continue;let d=(h.byteOffset||0)+(u.byteOffset||0),p=(f.byteOffset||0)+(m.byteOffset||0),v=fn(e,d,u.count);v.length>0&&v[v.length-1]>l&&(l=v[v.length-1]);let _=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,u.count))):3,S=fn(e,p,m.count*(a.target.path==="weights"?1:_)),y=s.interpolation==="STEP"?"STEP":"LINEAR";c.push({nodeIndex:a.target.node,path:a.target.path,times:v,values:S,interpolation:y})}c.length>0&&n.push({name:o,duration:l,channels:c})}return n}function tt(t,e,n){let{times:r,values:i,path:o,interpolation:c}=t,l=r.length;if(l===0)return;let a=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/l)):3;if(e<=r[0]){for(let S=0;S<a;S++)n[S]=i[S];return}if(e>=r[l-1]){let S=(l-1)*a;for(let y=0;y<a;y++)n[y]=i[S+y];return}let s=0,u=l-1;for(;s<=u;){let S=s+u>>1;r[S]<=e?s=S+1:u=S-1}let m=Math.max(0,u),h=Math.min(l-1,m+1);if(c==="STEP"||m===h){let S=m*a;for(let y=0;y<a;y++)n[y]=i[S+y];return}let f=r[m],d=r[h],p=(e-f)/Math.max(1e-5,d-f),v=m*a,_=h*a;if(o==="rotation"){let S=[i[v],i[v+1],i[v+2],i[v+3]],y=[i[_],i[_+1],i[_+2],i[_+3]];bn(n,S,y,p)}else for(let S=0;S<a;S++)n[S]=i[v+S]+p*(i[_+S]-i[v+S])}var pn=new WeakMap;function Xn(t,e,n=.3){if(!t?.animations)return;let r=t.animations.find(l=>l.name===e);if(!r)return;let i=pn.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),pn.set(t,i));let o=n>0?1/n:1e3;for(let l of i)l.clip.name!==e&&(l.fadeSpeed=-o);let c=i.find(l=>l.clip.name===e);c?c.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),t.currentClip=r,t.isPlayingAnimation=!0}function zn(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=pn.get(t);if(!n||n.length===0){if(!t.currentClip)return;n=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let r=t.gltf.nodes.length,i=[];for(let m=0;m<r;m++){let h=t.initialNodeTransforms[m];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let o=[0,0,0],c=[0,0,0,1],l=[1,1,1],a=new Float32Array(64);for(let m of n){let h=Math.max(0,Math.min(1,m.weight));if(!(h<=1e-4))for(let f of m.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=r)continue;let d=i[f.nodeIndex];if(f.path==="translation")tt(f,m.time,o),jr(d.t,d.t,o,h);else if(f.path==="rotation")tt(f,m.time,c),bn(d.r,d.r,c,h);else if(f.path==="scale")tt(f,m.time,l),jr(d.s,d.s,l,h);else if(f.path==="weights"&&(tt(f,m.time,a),t.meshes)){for(let p of t.meshes)if(p.nodeIndex===f.nodeIndex){for(let v of p.primitives)if(v.pluginData?.morph?.weights){let _=v.pluginData.morph.weights,S=v.pluginData.morph.numTargets||_.length;for(let y=0;y<S;y++)_[y]=_[y]*(1-h)+a[y]*h}}}}}let s=[];for(let m=0;m<r;m++){let h=ae(),{t:f,r:d,s:p}=i[m];qe(h,d,f,p),s.push(h)}let u=Le(t.gltf,s);t.worldMatrices=u;for(let m of t.meshes)m.nodeIndex>=0&&m.nodeIndex<u.length&&(m.transform.set(u[m.nodeIndex]),de(m.normalMatrix,m.transform))}var Wn={name:"keyframes",evaluateAnimation:zn,crossFadeTo:Xn,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=Hn(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=pn.get(t);if(n&&n.length>0){for(let r=n.length-1;r>=0;r--){let i=n[r];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){n.splice(r,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(t.animationTime=n[n.length-1].time),zn(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),zn(t,t.animationTime))}};var At=64;function Kr(t,e,n){if(!(!t?.meshes||e<0||e>=At))for(let r of t.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var Gn={name:"morph",onResolveShader(t,e,n,r){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
293
298
|
uniform sampler2D uMorphDeltasTex;
|
|
294
|
-
uniform float uMorphWeights[${
|
|
295
|
-
uniform int uNumMorphTargets;`);return
|
|
296
|
-
for (int m = 0; m < ${
|
|
299
|
+
uniform float uMorphWeights[${At}];
|
|
300
|
+
uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
301
|
+
for (int m = 0; m < ${At}; m++) {
|
|
297
302
|
if (m >= uNumMorphTargets) break;
|
|
298
303
|
float w = uMorphWeights[m];
|
|
299
304
|
if (abs(w) > 0.0001) {
|
|
300
305
|
morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
|
-
vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:
|
|
308
|
+
vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.targets;if(!Array.isArray(o)||o.length===0)return null;let c=n.attributes?.POSITION,l=r?.accessors?.[c];if(!l)return null;let a=l.count,s=Math.min(o.length,At),u=new Float32Array(a*s*4);for(let f=0;f<s;f++){let d=o[f].POSITION;if(d===void 0)continue;let p=r.accessors?.[d],v=r.bufferViews?.[p?.bufferView];if(!p||!v)continue;let _=(v.byteOffset||0)+(p.byteOffset||0),S=fn(i,_,a*3),y=f*a*4;for(let w=0;w<a;w++)u[y+w*4]=S[w*3],u[y+w*4+1]=S[w*3+1],u[y+w*4+2]=S[w*3+2],u[y+w*4+3]=0}let m=t.createTexture();t.bindTexture(3553,m),t.texImage2D(3553,0,34836,a,s,0,6408,5126,u),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array(At);return{hasMorph:!0,morphTex:m,numTargets:s,vertexCount:a,weights:h}},onBeforeDrawPrimitive(t,e,n,r,i,o){let c=n.pluginData?.morph;if(!c?.hasMorph||!c.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,c.morphTex);let l=t.getUniformLocation(e,"uMorphDeltasTex");l&&t.uniform1i(l,5);let a=t.getUniformLocation(e,"uNumMorphTargets");a&&t.uniform1i(a,c.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,c.weights)}};var $n=64,qn={name:"skinning",onResolveShader(t,e,n,r){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=n.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
|
|
304
309
|
layout(location=4) in uvec4 aJoints;
|
|
305
310
|
layout(location=5) in vec4 aWeights;
|
|
306
|
-
uniform mat4 uJointMatrix[${
|
|
311
|
+
uniform mat4 uJointMatrix[${$n}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
|
|
307
312
|
aWeights.x * uJointMatrix[int(aJoints.x)] +
|
|
308
313
|
aWeights.y * uJointMatrix[int(aJoints.y)] +
|
|
309
314
|
aWeights.z * uJointMatrix[int(aJoints.z)] +
|
|
310
315
|
aWeights.w * uJointMatrix[int(aJoints.w)];
|
|
311
|
-
vec4 world=uModel*(skinMatrix*vec4(${o},1.0));`).replace(`gl_Position=uMVP*vec4(${o},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${o},1.0));`),{vs:
|
|
316
|
+
vec4 world=uModel*(skinMatrix*vec4(${o},1.0));`).replace(`gl_Position=uMVP*vec4(${o},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${o},1.0));`),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.attributes;if(!o||o.JOINTS_0===void 0||o.WEIGHTS_0===void 0)return null;let c=r.accessors[o.JOINTS_0],l=r.accessors[o.WEIGHTS_0];if(!c||!l)return null;let a=r.bufferViews[c.bufferView],s=r.bufferViews[l.bufferView];if(!a||!s)return null;let u=(a.byteOffset||0)+(c.byteOffset||0),m=(s.byteOffset||0)+(l.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=c.componentType===5121?5121:5123,d=f===5121?new Uint8Array(i,u,c.count*4):new Uint16Array(i,u,c.count*4);t.bufferData(34962,d,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let p=t.createBuffer();t.bindBuffer(34962,p);let v=new Float32Array(i,m,l.count*4);return t.bufferData(34962,v,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,p]}},onBeforeDrawPrimitive(t,e,n,r,i,o){if(!n.pluginData?.skinning?.hasSkin)return;let c=o?.nodes?.[r.nodeIndex]?.skin;if(c===void 0||!o.skins||!o.skins[c])return;let a=o.skins[c].joints||[],s=new Float32Array($n*16);for(let m=0;m<a.length&&m<$n;m++){let h=a[m],f=i[h]||ae();s.subarray(m*16,(m+1)*16).set(f)}let u=t.getUniformLocation(e,"uJointMatrix[0]");u&&t.uniformMatrix4fv(u,!1,s)}};ye(Gn);ye(Wn);ye(qn);var Yn=new WeakMap;function yn(t,e){let n=e instanceof Float32Array?e:new Float32Array(e);Yn.set(t,n)}function ei(t){return Yn.get(t)}async function ji(t,e){if(!e)return null;let n;if(typeof e=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let o=await(await fetch(e)).blob();n=await createImageBitmap(o)}else if(typeof Image<"u")n=await new Promise((i,o)=>{let c=new Image;c.crossOrigin="anonymous",c.onload=()=>i(c),c.onerror=o,c.src=e});else return null;else n=e;let r=t.createTexture();return t.bindTexture(3553,r),t.texImage2D(3553,0,6408,6408,5121,n),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553),r}var Zr=new WeakMap,Jr=new Float32Array(16);async function Qr(t,e,n){let r=n?await ji(t.gl,n):null;t[e]&&t.gl.deleteTexture(t[e]),t[e]=r}var jn={name:"environment-map",setEnvironmentImage(t,e){return Qr(t,"environmentTexture",e)},setSkyboxImage(t,e){return Qr(t,"skyboxTexture",e)},onBeforeDrawScene(t,e,n,r,i){if(!t.skyboxTexture||typeof e.createProgram!="function")return;let o=Zr.get(e);if(!o){let m=(d,p)=>{let v=e.createShader(d);return e.shaderSource(v,p),e.compileShader(v),v},h=e.createProgram();e.attachShader(h,m(35633,`#version 300 es
|
|
312
317
|
out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),e.attachShader(h,m(35632,`#version 300 es
|
|
313
|
-
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),e.linkProgram(h);let f=typeof e.createVertexArray=="function"?e.createVertexArray():null;o={program:h,vao:f}
|
|
318
|
+
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),e.linkProgram(h);let f=typeof e.createVertexArray=="function"?e.createVertexArray():null;o={program:h,vao:f},Zr.set(e,o)}let c=Ft(Jr,n)||Jr;e.depthMask(!1),e.useProgram(o.program),o.vao&&e.bindVertexArray(o.vao),e.activeTexture(33984),e.bindTexture(3553,t.skyboxTexture);let l=e.getUniformLocation(o.program,"uSkyboxMap");l&&e.uniform1i(l,0);let a=e.getUniformLocation(o.program,"uInvVP");a&&e.uniformMatrix4fv(a,!1,c);let s=e.getUniformLocation(o.program,"uCameraPos");s&&e.uniform3f(s,r[0],r[1],r[2]);let u=e.getUniformLocation(o.program,"uExposure");u&&e.uniform1f(u,t.exposure??1),e.drawArrays(4,0,3),e.depthMask(!0)},onResolveShader(t,e,n,r){if(r.includes("evalSHIrradiance"))return null;let i=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
314
319
|
uniform int uHasSH;
|
|
315
320
|
out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
|
|
316
321
|
vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
|
|
317
|
-
void main(){`);return
|
|
322
|
+
void main(){`);return i=i.replace(`if(uHasEnvironmentMap==1){
|
|
318
323
|
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
319
324
|
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
320
325
|
}`,`if(uHasEnvironmentMap==1){
|
|
@@ -323,14 +328,14 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
|
|
|
323
328
|
}else if(uHasSH==1){
|
|
324
329
|
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
325
330
|
envDiffuse=evalSHIrradiance(N);
|
|
326
|
-
}`),{vs:n,fs:r}},onBeforeDrawPrimitive(t,e,n,i,r,o){let u=Wn.get(t),l=t.getUniformLocation(e,"uHasSH");if(u&&u.length>=27){l&&t.uniform1i(l,1);let a=t.getUniformLocation(e,"uSH");a&&t.uniform3fv(a,u)}else l&&t.uniform1i(l,0)},onAttributeChanged(t,e,n,i){e==="environment-image"&&t.viewer?this.setEnvironmentImage?.(t.viewer,i):e==="skybox-image"&&t.viewer&&this.setSkyboxImage?.(t.viewer,i)}};var $n=new WeakMap;function qn(t,e){let n=e||t.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let i=t.mockHotspots||t.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let r=0;r<i.length;r++){let o=i[r],u=o.getAttribute("data-position");if(!u)continue;let l=u.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let a=o.getAttribute("data-normal"),c;if(a){let m=a.trim().split(/\s+/).map(h=>parseFloat(h));m.length>=3&&!m.some(isNaN)&&(c=[m[0],m[1],m[2]])}let s=n.projectPointToScreen([l[0],l[1],l[2]],c);o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.transform=`translate(-50%, -50%) translate3d(${s.x}px, ${s.y}px, 0)`,o.style.zIndex="3",s.visible?(o.style.opacity="1",o.style.pointerEvents="auto",o.removeAttribute("data-occluded")):(o.style.opacity="0",o.style.pointerEvents="none",o.setAttribute("data-occluded",""))}}var Yn={name:"hotspots",updateHotspotsForElement:qn,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{qn(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),$n.set(t,e)},onCameraChange(t,e){e&&qn(e,t)},onElementDisconnected(t){let e=$n.get(t);e&&(e.disconnect(),$n.delete(t))}};var Kr=1024,jn=256,dn=2048,Yi=128,ji=64,Ki=16,Zi=1e4,Ji=8,De=new Set(["__proto__","constructor","prototype"]),Zr={neg:t=>-t,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:t=>t-Math.floor(t),sqrt:t=>Math.sqrt(Math.max(0,t)),cbrt:Math.cbrt,exp:Math.exp,log:t=>t>0?Math.log(t):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:t=>Math.asin(Math.max(-1,Math.min(1,t))),acos:t=>Math.acos(Math.max(-1,Math.min(1,t))),atan:Math.atan,rad:t=>t*Math.PI/180,deg:t=>t*180/Math.PI,saturate:t=>Math.max(0,Math.min(1,t))},Jr={add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>Math.abs(e)<1e-12?0:t/e,rem:(t,e)=>Math.abs(e)<1e-12?0:t%e,mod:(t,e)=>Math.abs(e)<1e-12?0:t%e,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},fn={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},pn=(t,e)=>t!==null&&typeof t=="object"&&!De.has(e)&&Object.prototype.hasOwnProperty.call(t,e),ge=t=>Array.isArray(t)?[...t]:t,ni=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&pn(t,"value")?t.value:t,ie=(t,e)=>pn(t.configuration,e)?ni(t.configuration[e]):void 0,H=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Oe=t=>Math.max(0,Math.min(1,t)),Ae=t=>typeof t=="boolean"?t:typeof t=="number"?t!==0&&!Number.isNaN(t):typeof t=="string"?t.length>0&&t!=="false":!!t;function bt(t){if(typeof t!="string"||!t.startsWith("/"))return null;let e=[];for(let n of t.slice(1).split("/")){let i=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||De.has(i)||De.has(n))return null;e.push(i)}return{segments:e}}var Ke=(t,e)=>{if(t===void 0||!/^\d+$/.test(t))return-1;let n=Number(t);return Number.isSafeInteger(n)&&n>=0&&n<e?n:-1},Qr=t=>{let e=H(t[0]),n=H(t[1]),i=H(t[2]),r=H(t[3],1),o=Math.hypot(e,n,i,r);return o>1e-8?[e/o,n/o,i/o,r/o]:[0,0,0,1]},ei=(t,e,n,i)=>{if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(Array.isArray(t)&&Array.isArray(e)){if(i&&t.length===4&&e.length===4){let r=[0,0,0,1];return mn(r,Qr(t),Qr(e),n),r}return t.slice(0,e.length).map((r,o)=>r+(e[o]-r)*n)}return n>=.5?e:t},Kn=(t,e,n)=>Array.isArray(t)&&Array.isArray(e)?t.slice(0,e.length).map((i,r)=>n(H(i),H(e[r]))):Array.isArray(t)?t.map(i=>n(H(i),H(e))):Array.isArray(e)?e.map(i=>n(H(t),H(i))):n(H(t),H(e)),Qi=(t,e)=>Array.isArray(t)?t.map(n=>e(H(n))):e(H(t)),ti=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((n,i)=>Math.abs(n-e[i])<=1e-6):t===e,yt=class{constructor(e,n,i){let r=Array.isArray(i.nodes)?i.nodes:[];if(r.length>Kr)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Kr})`);let o=Array.isArray(i.variables)?i.variables:[];if(o.length>jn)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${jn})`);let u=Array.isArray(i.declarations)?i.declarations:[],l=Array.isArray(i.events)?i.events:[],a=new Map,c=new Map,s=new Map,m=new Map,h=new Map,f=new Map,d=[],b=[],g=new Map,E=1,A=0,p=0,R=0,x=0,F=!1,y=!1,w=!1;o.forEach((S,v)=>{if(!S||typeof S!="object")return;let L=ge(ni(S.value));a.set(v,L);let U=S.id??S.name;typeof U=="string"&&U&&!De.has(U)&&a.set(U,L)}),(n?.nodes||[]).forEach((S,v)=>{for(let L of S?.children||[])typeof L=="number"&&g.set(L,v)});let T=S=>S.op||typeof S.declaration=="number"&&u[S.declaration]?.op||"",I=(S,v,L)=>{if(De.has(v))return;let U=c.get(S);U||c.set(S,U=Object.create(null)),U[v]=L},B=(S,v)=>{if(typeof S!="number"&&typeof S!="string"||typeof S=="string"&&De.has(S)||!a.has(S)&&a.size>=jn*2)return;let L=ge(v);if(a.set(S,L),typeof S=="number"){let U=o[S]?.id??o[S]?.name;typeof U=="string"&&!De.has(U)&&a.set(U,L)}},P=S=>typeof S=="number"?l[S]?.id??String(S):typeof S=="string"?/^\d+$/.test(S)&&l[Number(S)]?.id?l[Number(S)].id:S:"",N=(S,v)=>{for(let L=S,U=0;L!==void 0&&L>=0&&U<128;L=g.get(L),U++)if(L===v)return!0;return!1},_=S=>{for(let v=d.length-1;v>=0;v--)d[v].key===S&&d.splice(v,1)},q=S=>{_(S.key),d.length>=Yi&&d.shift(),d.push(S)},J=S=>{let v=bt(S)?.segments;if(v){if(v[0]==="nodes"&&Array.isArray(n?.nodes)){let L=n.nodes[Ke(v[1],n.nodes.length)];if(!L)return;let U=v[2];if(U in fn){let M=fn[U],D=L[U]||M;return M.map((C,O)=>H(D[O],C))}if(U==="weights"){let M=Array.isArray(L.weights)?L.weights:[0],D=v.length===4?Ke(v[3],64):-2;return D===-2?M.map(C=>H(C)):D>=0?H(M[D]):void 0}if(U==="visible"||U==="extensions"&&v[3]==="KHR_node_visibility"&&v[4]==="visible")return L.extensions?.KHR_node_visibility?.visible??L.visible??!0}else if(v[0]==="materials"&&Array.isArray(n?.materials)){let L=n.materials[Ke(v[1],n.materials.length)];if(!L)return;let U=L.pbrMetallicRoughness||{};if(v[2]==="pbrMetallicRoughness"){if(v[3]==="baseColorFactor"){let M=U.baseColorFactor||[1,1,1,1];return[H(M[0],1),H(M[1],1),H(M[2],1),H(M[3],1)]}if(v[3]==="metallicFactor"||v[3]==="roughnessFactor")return H(U[v[3]],1)}if(v[2]==="emissiveFactor"){let M=L.emissiveFactor||[0,0,0];return[H(M[0]),H(M[1]),H(M[2])]}if(v[2]==="alphaCutoff")return H(L.alphaCutoff,.5)}}},Z=(S,v)=>{let L=bt(S)?.segments;if(!L)return!1;if(L[0]==="nodes"&&Array.isArray(n?.nodes)){let U=Ke(L[1],n.nodes.length),M=n.nodes[U];if(!M)return!1;let D=L[2];if(D in fn&&Array.isArray(v)){let C=fn[D];if(v.length<C.length)return!1;let O=C.map((K,Q)=>H(v[Q],K));if(D==="rotation"){let K=Math.hypot(...O);O=K>1e-8?O.map(Q=>Q/K):[0,0,0,1]}M[D]=O,delete M.matrix;let Y=e?.initialNodeTransforms?.[U];return Y&&(Y[D[0]]=[...O]),F=!0,!0}if(D==="weights"){Array.isArray(M.weights)||(M.weights=[]);let C=(O,Y)=>{for(let K of e?.meshes||[])if(K.nodeIndex===U)for(let Q of K.primitives||[])Q.pluginData?.morph?.weights&&(Q.pluginData.morph.weights[O]=Y)};if(L.length===4){let O=Ke(L[3],64);if(O<0)return!1;C(O,M.weights[O]=H(v))}else if(Array.isArray(v))M.weights=v.slice(0,64).map(O=>H(O)),M.weights.forEach((O,Y)=>C(Y,O));else return!1;return w=!0,!0}if(D==="visible"||D==="extensions"&&L[3]==="KHR_node_visibility"&&L[4]==="visible"){let C=Ae(v);return M.visible=C,(!M.extensions||typeof M.extensions!="object")&&(M.extensions={}),M.extensions.KHR_node_visibility={visible:C},y=!0,!0}}else if(L[0]==="materials"&&Array.isArray(n?.materials)){let U=Ke(L[1],n.materials.length),M=n.materials[U];if(!M)return!1;let D=M.pbrMetallicRoughness||(M.pbrMetallicRoughness={}),C=O=>{for(let Y of e?.meshes||[])for(let K of Y.primitives||[])(K.materialIndex??0)===U&&O(K)};if(L[2]==="pbrMetallicRoughness"){if(L[3]==="baseColorFactor"&&Array.isArray(v)&&v.length>=3){let O=[Oe(H(v[0],1)),Oe(H(v[1],1)),Oe(H(v[2],1)),v[3]!==void 0?Oe(H(v[3],1)):D.baseColorFactor?.[3]??1];return D.baseColorFactor=O,C(Y=>Y.baseColor=[...O]),w=!0}if(L[3]==="metallicFactor"||L[3]==="roughnessFactor"){let O=L[3]==="metallicFactor",Y=Oe(H(v,O?0:.5));return D[L[3]]=Y,C(K=>K[O?"metallic":"roughness"]=Y),w=!0}}if(L[2]==="emissiveFactor"&&Array.isArray(v)&&v.length>=3)return M.emissiveFactor=[0,1,2].map(O=>Math.max(0,H(v[O]))),w=!0;if(L[2]==="alphaCutoff")return M.alphaCutoff=Oe(H(v,.5)),w=!0}return!1},j=(S,v,L=new Set)=>{let U=ie(v,"pointer");if(typeof U!="string"||!U.startsWith("/"))return null;let M=U.replace(/\{([a-zA-Z0-9_]+)\}/g,(D,C)=>{let O=Math.trunc(Number(V(S,C,void 0,L)??ie(v,C)));return Number.isSafeInteger(O)&&O>=0?String(O):"-1"});return bt(M)?M:null},V=(S,v,L,U)=>{let M=r[S]?.values;if(!pn(M,v))return L;let D=M[v];if(D==null)return L;if(typeof D!="object"||Array.isArray(D))return ge(D);let C=D;return typeof C.node=="number"?X(C.node,C.socket||"value",U):pn(C,"value")?ge(C.value):L},X=(S,v,L)=>{if(S<0||S>=r.length||L.has(S)||L.size>128||++R>Zi)return;let U=r[S],M=T(U);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(M))return ge(c.get(S)?.[v]);L.add(S);try{let D=(C,O=0)=>V(S,C,O,L);if(M==="variable/get"){let C=ie(U,"variable")??ie(U,"id");return typeof C=="number"||typeof C=="string"?ge(a.get(C)):void 0}if(M==="pointer/get"){let C=j(S,U,L);return C?J(C):void 0}if(M.startsWith("math/")){let C=M.slice(5);if(C in Zr)return Qi(D("a"),Zr[C]);if(C in Jr){let O=/^(mul|div|rem|mod|pow)$/.test(C)?1:0;return Kn(D("a",C==="mul"?1:0),D("b",O),Jr[C])}if(C==="pi")return Math.PI;if(C==="e")return Math.E;if(C==="random")return Math.random();if(C==="clamp")return Kn(Kn(D("a"),D("b",D("min",0)),Math.max),D("c",D("max",1)),Math.min);if(C==="mix"||C==="quatSlerp")return ei(D("a",0),D("b",1),H(D("c",D("t",.5)),.5),C==="quatSlerp");if(C==="dot"){let O=D("a"),Y=D("b");return Array.isArray(O)&&Array.isArray(Y)?O.reduce((K,Q,z)=>K+(Q||0)*(Y[z]||0),0):H(O)*H(Y)}if(C==="cross"){let O=D("a",[0,0,0]),Y=D("b",[0,0,0]);return Array.isArray(O)&&Array.isArray(Y)?[(O[1]||0)*(Y[2]||0)-(O[2]||0)*(Y[1]||0),(O[2]||0)*(Y[0]||0)-(O[0]||0)*(Y[2]||0),(O[0]||0)*(Y[1]||0)-(O[1]||0)*(Y[0]||0)]:[0,0,0]}if(C==="length"){let O=D("a");return Array.isArray(O)?Math.hypot(...O):Math.abs(H(O))}if(C==="distance"){let O=D("a"),Y=D("b");return Array.isArray(O)&&Array.isArray(Y)?Math.hypot(...O.map((K,Q)=>(K||0)-(Y[Q]||0))):Math.abs(H(O)-H(Y))}if(C==="normalize"){let O=D("a");if(!Array.isArray(O))return H(O)>=0?1:-1;let Y=Math.hypot(...O);return Y>1e-8?O.map(K=>K/Y):O.map(()=>0)}if(C.startsWith("combine"))return["a","b","c","d"].slice(0,Number(C[7])||2).map(O=>H(D(O)));if(C.startsWith("extract")){let O=D("a");return Array.isArray(O)?O[v==="0"||v==="x"?0:v==="1"||v==="y"?1:v==="2"||v==="z"?2:3]??0:0}if(C==="eq")return ti(D("a"),D("b"));if(C==="ne")return!ti(D("a"),D("b"));if(C==="lt")return H(D("a"))<H(D("b"));if(C==="le")return H(D("a"))<=H(D("b"));if(C==="gt")return H(D("a"))>H(D("b"));if(C==="ge")return H(D("a"))>=H(D("b"));if(C==="isNaN")return Number.isNaN(Number(D("a")));if(C==="isInf"){let O=Number(D("a"));return!Number.isFinite(O)&&!Number.isNaN(O)}return C==="and"?Ae(D("a",!1))&&Ae(D("b",!1)):C==="or"?Ae(D("a",!1))||Ae(D("b",!1)):C==="xor"?Ae(D("a",!1))!==Ae(D("b",!1)):C==="not"?!Ae(D("a",!1)):C==="select"?ge(Ae(D("condition",!1))?D("a"):D("b")):void 0}return M==="type/boolToInt"||M==="type/boolToFloat"?Ae(D("a",!1))?1:0:M==="type/intToBool"||M==="type/floatToBool"?H(D("a",0))!==0:M==="type/intToFloat"?H(D("a",0)):M==="type/floatToInt"?Math.trunc(H(D("a",0))):void 0}finally{L.delete(S)}},k=()=>{if(F){F=!1,w=!0;let S=_e(n);if(e){e.worldMatrices=S;for(let v of e.meshes||[])v.nodeIndex>=0&&v.nodeIndex<S.length&&(v.transform.set(S[v.nodeIndex]),ue(v.normalMatrix,v.transform))}}if(y){y=!1,w=!0;let S=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(S))for(let v of e.meshes){let L=!0;for(let U=v.nodeIndex,M=0;U!==void 0&&U>=0&&M<128;U=g.get(U),M++){let D=S[U];if(D?.visible===!1||D?.extensions?.KHR_node_visibility?.visible===!1){L=!1;break}}v.visible=L}}w&&(w=!1,e?.render?.())},W=(S,v={steps:0})=>{if(!S||typeof S.node!="number")return;v.steps===0&&(R=0);let L=[S],U=M=>{L.length+v.steps<dn&&L.push(M)};for(;L.length>0&&v.steps<dn;){v.steps++;let M=L.shift();if(!M||M.node<0||M.node>=r.length)continue;let D=M.node,C=r[D];if(!C)continue;let O=M.socket||"in",Y=T(C),K=(z,$=void 0)=>V(D,z,$,new Set),Q=(z="out")=>{let $=C.flows?.[z];$&&U($)};switch(Y){case"flow/branch":Q(Ae(K("condition",!1))?"true":"false");break;case"flow/sequence":for(let z of Object.keys(C.flows||{}).sort(($,oe)=>Number($)-Number(oe)||$.localeCompare(oe)))Q(z);break;case"flow/switch":{let z=C.flows?.[String(K("selection",K("value",0)))]??C.flows?.default;z&&U(z);break}case"flow/for":{let z=Math.trunc(H(K("startIndex",0))),$=Math.trunc(H(K("endIndex",0))),oe=Math.max(1,Math.trunc(H(K("step",1),1))),he=C.flows?.body;if(he&&$>z&&x<Ji){let An=Math.min(Math.ceil(($-z)/oe),dn);x++;try{for(let Ze=0;Ze<An&&v.steps<dn;Ze++)I(D,"index",z+Ze*oe),W(he,v)}finally{x--}}let vt=C.flows?.completed??C.flows?.out;vt&&U(vt);break}case"flow/doN":{let z=O==="reset"?0:(s.get(D)||0)+1;if(s.set(D,z),I(D,"currentCount",z),I(D,"count",z),O!=="reset"){let $=Math.trunc(H(K("n",ie(C,"stopIterations")??ie(C,"n")??1),1));z<=$&&Q()}break}case"flow/multiGate":{if(O==="reset"){f.set(D,0);break}let z=Object.keys(C.flows||{}).sort();if(!z.length)break;let $=ie(C,"isRandom")?Math.floor(Math.random()*z.length):f.get(D)||0;$<z.length&&(Q(z[$]),f.set(D,ie(C,"isLoop")!==!1?($+1)%z.length:$+1));break}case"flow/waitAll":{if(O==="reset"){m.delete(D);break}let z=m.get(D);z||m.set(D,z=new Set),z.add(O),z.size>=Math.max(1,Math.trunc(Number(ie(C,"inputFlows")??2)||2))&&(z.clear(),Q("out"),Q("completed"));break}case"flow/throttle":{if(O==="reset"){h.delete(D);break}let z=Math.max(0,H(K("duration",0))),$=h.get(D);$===void 0||A-$>=z?(h.set(D,A),I(D,"lastRemainingTime",0),Q()):I(D,"lastRemainingTime",Math.max(0,z-(A-$)));break}case"flow/delay":case"flow/setDelay":{if(O==="cancel"){for(let he=b.length-1;he>=0;he--)b[he].nodeIdx===D&&b.splice(he,1);I(D,"lastDelayIndex",-1);break}let z=Math.max(0,H(K("duration",ie(C,"duration")??0))),$=C.flows?.done??C.flows?.out;if(z<=0){I(D,"lastDelayIndex",-1),$&&U($);break}b.length>=ji&&b.shift();let oe=E++;I(D,"lastDelayIndex",oe),b.push({id:oe,nodeIdx:D,rem:z,done:$}),Y==="flow/setDelay"&&C.flows?.out&&C.flows?.done&&Q("out");break}case"flow/cancelDelay":{let z=Math.trunc(H(K("delayIndex",-1),-1));if(z<0)b.length=0;else for(let $=b.length-1;$>=0;$--)b[$].id===z&&b.splice($,1);Q();break}case"variable/set":B(ie(C,"variable")??ie(C,"id"),K("value")),Q();break;case"variable/interpolate":{let z=ie(C,"variable")??ie(C,"id"),$=K("value",K("target")),oe=Math.max(0,H(K("duration",ie(C,"duration")??.3),.3));z!==void 0&&$!==void 0&&q({key:`var:${String(z)}`,varKey:z,from:ge(K("from")??a.get(z)??0),to:ge($),dur:oe,elapsed:0,quat:!1,linear:ie(C,"easing")==="linear",done:C.flows?.done}),Q();break}case"pointer/set":{let z=j(D,C),$=K("value");z&&$!==void 0&&(_(`ptr:${z}`),Z(z,$)),Q();break}case"pointer/interpolate":{let z=j(D,C),$=K("value",K("target")),oe=Math.max(0,H(K("duration",ie(C,"duration")??.3),.3));if(z&&$!==void 0){let he=K("from")??J(z);he!==void 0&&(oe<=0?(Z(z,$),Q("done")):q({key:`ptr:${z}`,ptr:z,from:ge(he),to:ge($),dur:oe,elapsed:0,quat:z.endsWith("/rotation"),linear:ie(C,"easing")==="linear",done:C.flows?.done}))}Q();break}case"animation/start":{let z=K("animation")??ie(C,"animation")??ie(C,"clipName"),$=typeof z=="number"?e?.animations?.[z]?.name??n?.animations?.[z]?.name:typeof z=="string"?z:void 0;e?.playAnimation?.($),w=!0,Q();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),Y==="animation/resetAt"&&e?.evaluateAnimation?.(H(K("time",0))),w=!0,Q();break;case"event/send":case"customEvent/send":{let z=P(ie(C,"event")??ie(C,"id")),$={};for(let oe of Object.keys(C.values||{}))De.has(oe)||($[oe]=K(oe));z&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:z,values:$}})),G(z,$,v)),Q();break}default:Q();break}}};this.readScenePointer=J,this.writeScenePointer=Z,this.fireOnStart=()=>{r.forEach(S=>{T(S)==="event/onStart"&&W(S.flows?.out)}),k()},this.fireOnSelect=S=>{if(!S)return;let v=typeof S.meshIndex=="number"?S.meshIndex:-1,L=typeof S.nodeIndex=="number"?S.nodeIndex:e?.meshes?.[v]?.nodeIndex??-1;r.forEach((U,M)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(T(U)))return;let D=ie(U,"nodeIndex")??ie(U,"node")??V(M,"nodeIndex",void 0,new Set),C=ie(U,"meshName");if(typeof C=="string"&&C?S.meshName===C:D==null||Number(D)<0||Number.isNaN(Number(D))||N(L,Math.trunc(Number(D)))){if(I(M,"nodeIndex",L),I(M,"meshIndex",v),Array.isArray(S.hitPoint)){let Y=[H(S.hitPoint[0]),H(S.hitPoint[1]),H(S.hitPoint[2])];I(M,"hitPoint",Y),I(M,"point",Y),I(M,"intersectionPoint",Y)}if(Array.isArray(S.normal)){let Y=[H(S.normal[0]),H(S.normal[1],1),H(S.normal[2])];I(M,"normal",Y),I(M,"hitNormal",Y)}typeof S.distance=="number"&&I(M,"distance",S.distance),W(U.flows?.out)}}),k()},this.receiveCustomEvent=(S,v={})=>G(S,v,{steps:0});function G(S,v,L){if(!(p>=Ki)){p++;try{let U=P(S);r.forEach((M,D)=>{if(!/^(customE|e)vent\/receive$/.test(T(M)))return;let C=ie(M,"event")??ie(M,"id");if(!(P(C)!==U&&String(C)!==String(S))){for(let[O,Y]of Object.entries(v))De.has(O)||I(D,O,ge(Y));W(M.flows?.out,L)}}),k()}finally{p--}}}this.tick=S=>{if(!Number.isFinite(S)||S<0)return;let v=Math.min(S,.25);A+=v,r.forEach((U,M)=>{T(U)==="event/onTick"&&(I(M,"timeDelta",v),I(M,"dt",v),I(M,"timeElapsed",A),W(U.flows?.out))});let L=[];for(let U=d.length-1;U>=0;U--){let M=d[U];M.elapsed+=v;let D=M.dur>1e-6?Oe(M.elapsed/M.dur):1,C=M.linear?D:D*D*(3-2*D),O=ei(M.from,M.to,C,M.quat);M.ptr?Z(M.ptr,O):M.varKey!==void 0&&B(M.varKey,O),D>=1&&(d.splice(U,1),M.done&&L.push(M.done))}for(let U=b.length-1;U>=0;U--){let M=b[U];M.rem-=v,M.rem<=0&&(b.splice(U,1),M.done&&L.push(M.done))}for(let U of L)W(U);k()},this.dispose=()=>{d.length=0,b.length=0,a.clear(),c.clear(),s.clear(),m.clear(),h.clear(),f.clear()}}},Se=new WeakMap,bn=new WeakMap;function eo(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||St().some(l=>l.name==="xr-live-head-follow"))return;let n=t.gltf,i=n?.nodes;if(!Array.isArray(i)||i.length===0)return;let r=Math.min(e,.1),o=(bn.get(t)||0)+r,u=!1;for(let l=0;l<i.length;l++){let a=i[l],c=Rr(a?.extras?.xr?.orbit);if(!c)continue;let s=0,m=0,h=0;if(Array.isArray(c.target))s=c.target[0],m=c.target[1],h=c.target[2];else if(typeof c.target=="string"&&c.target!=="head"){let E=i.find(A=>A?.name===c.target);Array.isArray(E?.translation)&&(s=H(E.translation[0]),m=H(E.translation[1]),h=H(E.translation[2]))}let f=c.phase+c.speed*o,d=s+Math.cos(f)*c.radius,b=m+c.height,g=h+Math.sin(f)*c.radius;if(a.translation=[d,b,g],c.faceCenter){let E=Math.atan2(s-d,h-g);a.rotation=[0,Math.sin(E*.5),0,Math.cos(E*.5)]}u=!0}if(u){bn.set(t,o);let l=_e(n);t.worldMatrices=l;for(let a of t.meshes||[])a.nodeIndex>=0&&a.nodeIndex<l.length&&(a.transform.set(l[a.nodeIndex]),ue(a.normalMatrix,a.transform))}}function yn(t){if(!(!t||typeof t!="object"))return Se.get(t)||Se.get(t.viewer)||Se.get(t._view)}function Zn(t,e,n){let i=yn(t);return i?(i.receiveCustomEvent(e,n),!0):!1}var Jn={name:"khr-interactivity",sendInteractivityEvent:Zn,getInteractivityVM:yn,onLoadModel(t,e){if(!t||typeof t!="object")return;Se.get(t)?.dispose(),Se.delete(t),bn.delete(t);let n=e?.extensions?.KHR_interactivity,i=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!i||!Array.isArray(i.nodes))return;let r=new yt(t,e,i);Se.set(t,r),r.fireOnStart()},onMeshSelect(t,e){Se.get(t)?.fireOnSelect(e)},onUpdate(t,e){Se.get(t)?.tick(e),eo(t,e)},onDestroy(t,e){Se.get(e)?.dispose(),Se.delete(e),bn.delete(e)}};var gt=new Map,Qn=new WeakMap;function ri(t,e){gt.set(t,e)}var er={name:"materials",onBuildPrimitiveVAO(t,e,n,i,r){return(((i?.materials&&n.material!==void 0?i.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(t,e){let n=Qn.get(t);n||(n=t.createTexture(),Qn.set(t,n));let i=Math.max(1,e.canvas.width),r=Math.max(1,e.canvas.height);t.activeTexture(33990),t.bindTexture(3553,n),t.copyTexImage2D(3553,0,6408,0,0,i,r,0),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553)},onResolveShader(t,e,n,i){if(!e)return null;if(e.name&>.has(e.name)){let d=gt.get(e.name);return{vs:d.vs||n,fs:d.fs||i}}let r=e.extensions||{},o=r.KHR_materials_clearcoat,u=r.KHR_materials_sheen,l=!!r.KHR_materials_transmission,a=!!r.KHR_materials_ior,c=r.KHR_materials_iridescence;if(!o&&!u&&!r.KHR_materials_unlit&&!l&&!r.KHR_materials_volume&&!a&&!r.KHR_materials_dispersion&&!c)return null;if(r.KHR_materials_unlit)return{vs:n,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let s=i;l&&(s=s.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
327
|
-
uniform
|
|
328
|
-
out vec4 fragColor;`)
|
|
329
|
-
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(f,1.5,1,10)},dV=${
|
|
331
|
+
}`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let c=Yn.get(t),l=t.getUniformLocation(e,"uHasSH");if(c&&c.length>=27){l&&t.uniform1i(l,1);let a=t.getUniformLocation(e,"uSH");a&&t.uniform3fv(a,c)}else l&&t.uniform1i(l,0)},onAttributeChanged(t,e,n,r){e==="environment-image"&&t.viewer?this.setEnvironmentImage?.(t.viewer,r):e==="skybox-image"&&t.viewer&&this.setSkyboxImage?.(t.viewer,r)}};var Kn=new WeakMap;function Zn(t,e){let n=e||t.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=t.mockHotspots||t.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let i=0;i<r.length;i++){let o=r[i],c=o.getAttribute("data-position");if(!c)continue;let l=c.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let a=o.getAttribute("data-normal"),s;if(a){let m=a.trim().split(/\s+/).map(h=>parseFloat(h));m.length>=3&&!m.some(isNaN)&&(s=[m[0],m[1],m[2]])}let u=n.projectPointToScreen([l[0],l[1],l[2]],s);o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.transform=`translate(-50%, -50%) translate3d(${u.x}px, ${u.y}px, 0)`,o.style.zIndex="3",u.visible?(o.style.opacity="1",o.style.pointerEvents="auto",o.removeAttribute("data-occluded")):(o.style.opacity="0",o.style.pointerEvents="none",o.setAttribute("data-occluded",""))}}var Jn={name:"hotspots",updateHotspotsForElement:Zn,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{Zn(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Kn.set(t,e)},onCameraChange(t,e){e&&Zn(e,t)},onElementDisconnected(t){let e=Kn.get(t);e&&(e.disconnect(),Kn.delete(t))}};var ti=1024,Qn=256,gn=2048,Ki=128,Zi=64,Ji=16,Qi=1e4,eo=8,ke=new Set(["__proto__","constructor","prototype"]),ni={neg:t=>-t,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:t=>t-Math.floor(t),sqrt:t=>Math.sqrt(Math.max(0,t)),cbrt:Math.cbrt,exp:Math.exp,log:t=>t>0?Math.log(t):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:t=>Math.asin(Math.max(-1,Math.min(1,t))),acos:t=>Math.acos(Math.max(-1,Math.min(1,t))),atan:Math.atan,rad:t=>t*Math.PI/180,deg:t=>t*180/Math.PI,saturate:t=>Math.max(0,Math.min(1,t))},ri={add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>Math.abs(e)<1e-12?0:t/e,rem:(t,e)=>Math.abs(e)<1e-12?0:t%e,mod:(t,e)=>Math.abs(e)<1e-12?0:t%e,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},xn={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},vn=(t,e)=>t!==null&&typeof t=="object"&&!ke.has(e)&&Object.prototype.hasOwnProperty.call(t,e),Ae=t=>Array.isArray(t)?[...t]:t,ai=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&vn(t,"value")?t.value:t,se=(t,e)=>vn(t.configuration,e)?ai(t.configuration[e]):void 0,W=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Xe=t=>Math.max(0,Math.min(1,t)),Ee=t=>typeof t=="boolean"?t:typeof t=="number"?t!==0&&!Number.isNaN(t):typeof t=="string"?t.length>0&&t!=="false":!!t;function Rt(t){if(typeof t!="string"||!t.startsWith("/"))return null;let e=[];for(let n of t.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||ke.has(r)||ke.has(n))return null;e.push(r)}return{segments:e}}var nt=(t,e)=>{if(t===void 0||!/^\d+$/.test(t))return-1;let n=Number(t);return Number.isSafeInteger(n)&&n>=0&&n<e?n:-1},ii=t=>{let e=W(t[0]),n=W(t[1]),r=W(t[2]),i=W(t[3],1),o=Math.hypot(e,n,r,i);return o>1e-8?[e/o,n/o,r/o,i/o]:[0,0,0,1]},oi=(t,e,n,r)=>{if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(Array.isArray(t)&&Array.isArray(e)){if(r&&t.length===4&&e.length===4){let i=[0,0,0,1];return bn(i,ii(t),ii(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},er=(t,e,n)=>Array.isArray(t)&&Array.isArray(e)?t.slice(0,e.length).map((r,i)=>n(W(r),W(e[i]))):Array.isArray(t)?t.map(r=>n(W(r),W(e))):Array.isArray(e)?e.map(r=>n(W(t),W(r))):n(W(t),W(e)),to=(t,e)=>Array.isArray(t)?t.map(n=>e(W(n))):e(W(t)),si=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((n,r)=>Math.abs(n-e[r])<=1e-6):t===e,Tt=class{constructor(e,n,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>ti)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ti})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>Qn)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Qn})`);let c=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],a=new Map,s=new Map,u=new Map,m=new Map,h=new Map,f=new Map,d=[],p=[],v=new Map,_=1,S=0,y=0,w=0,g=0,C=!1,b=!1,A=!1;o.forEach((T,x)=>{if(!T||typeof T!="object")return;let D=Ae(ai(T.value));a.set(x,D);let k=T.id??T.name;typeof k=="string"&&k&&!ke.has(k)&&a.set(k,D)}),(n?.nodes||[]).forEach((T,x)=>{for(let D of T?.children||[])typeof D=="number"&&v.set(D,x)});let R=T=>T.op||typeof T.declaration=="number"&&c[T.declaration]?.op||"",E=(T,x,D)=>{if(ke.has(x))return;let k=s.get(T);k||s.set(T,k=Object.create(null)),k[x]=D},O=(T,x)=>{if(typeof T!="number"&&typeof T!="string"||typeof T=="string"&&ke.has(T)||!a.has(T)&&a.size>=Qn*2)return;let D=Ae(x);if(a.set(T,D),typeof T=="number"){let k=o[T]?.id??o[T]?.name;typeof k=="string"&&!ke.has(k)&&a.set(k,D)}},H=T=>typeof T=="number"?l[T]?.id??String(T):typeof T=="string"?/^\d+$/.test(T)&&l[Number(T)]?.id?l[Number(T)].id:T:"",F=(T,x)=>{for(let D=T,k=0;D!==void 0&&D>=0&&k<128;D=v.get(D),k++)if(D===x)return!0;return!1},M=T=>{for(let x=d.length-1;x>=0;x--)d[x].key===T&&d.splice(x,1)},G=T=>{M(T.key),d.length>=Ki&&d.shift(),d.push(T)},B=T=>{let x=Rt(T)?.segments;if(x){if(x[0]==="nodes"&&Array.isArray(n?.nodes)){let D=n.nodes[nt(x[1],n.nodes.length)];if(!D)return;let k=x[2];if(k in xn){let I=xn[k],L=D[k]||I;return I.map((P,N)=>W(L[N],P))}if(k==="weights"){let I=Array.isArray(D.weights)?D.weights:[0],L=x.length===4?nt(x[3],64):-2;return L===-2?I.map(P=>W(P)):L>=0?W(I[L]):void 0}if(k==="visible"||k==="extensions"&&x[3]==="KHR_node_visibility"&&x[4]==="visible")return D.extensions?.KHR_node_visibility?.visible??D.visible??!0}else if(x[0]==="materials"&&Array.isArray(n?.materials)){let D=n.materials[nt(x[1],n.materials.length)];if(!D)return;let k=D.pbrMetallicRoughness||{};if(x[2]==="pbrMetallicRoughness"){if(x[3]==="baseColorFactor"){let I=k.baseColorFactor||[1,1,1,1];return[W(I[0],1),W(I[1],1),W(I[2],1),W(I[3],1)]}if(x[3]==="metallicFactor"||x[3]==="roughnessFactor")return W(k[x[3]],1)}if(x[2]==="emissiveFactor"){let I=D.emissiveFactor||[0,0,0];return[W(I[0]),W(I[1]),W(I[2])]}if(x[2]==="alphaCutoff")return W(D.alphaCutoff,.5)}}},Q=(T,x)=>{let D=Rt(T)?.segments;if(!D)return!1;if(D[0]==="nodes"&&Array.isArray(n?.nodes)){let k=nt(D[1],n.nodes.length),I=n.nodes[k];if(!I)return!1;let L=D[2];if(L in xn&&Array.isArray(x)){let P=xn[L];if(x.length<P.length)return!1;let N=P.map((Z,$)=>W(x[$],Z));if(L==="rotation"){let Z=Math.hypot(...N);N=Z>1e-8?N.map($=>$/Z):[0,0,0,1]}I[L]=N,delete I.matrix;let K=e?.initialNodeTransforms?.[k];return K&&(K[L[0]]=[...N]),C=!0,!0}if(L==="weights"){Array.isArray(I.weights)||(I.weights=[]);let P=(N,K)=>{for(let Z of e?.meshes||[])if(Z.nodeIndex===k)for(let $ of Z.primitives||[])$.pluginData?.morph?.weights&&($.pluginData.morph.weights[N]=K)};if(D.length===4){let N=nt(D[3],64);if(N<0)return!1;P(N,I.weights[N]=W(x))}else if(Array.isArray(x))I.weights=x.slice(0,64).map(N=>W(N)),I.weights.forEach((N,K)=>P(K,N));else return!1;return A=!0,!0}if(L==="visible"||L==="extensions"&&D[3]==="KHR_node_visibility"&&D[4]==="visible"){let P=Ee(x);return I.visible=P,(!I.extensions||typeof I.extensions!="object")&&(I.extensions={}),I.extensions.KHR_node_visibility={visible:P},b=!0,!0}}else if(D[0]==="materials"&&Array.isArray(n?.materials)){let k=nt(D[1],n.materials.length),I=n.materials[k];if(!I)return!1;let L=I.pbrMetallicRoughness||(I.pbrMetallicRoughness={}),P=N=>{for(let K of e?.meshes||[])for(let Z of K.primitives||[])(Z.materialIndex??0)===k&&N(Z)};if(D[2]==="pbrMetallicRoughness"){if(D[3]==="baseColorFactor"&&Array.isArray(x)&&x.length>=3){let N=[Xe(W(x[0],1)),Xe(W(x[1],1)),Xe(W(x[2],1)),x[3]!==void 0?Xe(W(x[3],1)):L.baseColorFactor?.[3]??1];return L.baseColorFactor=N,P(K=>K.baseColor=[...N]),A=!0}if(D[3]==="metallicFactor"||D[3]==="roughnessFactor"){let N=D[3]==="metallicFactor",K=Xe(W(x,N?0:.5));return L[D[3]]=K,P(Z=>Z[N?"metallic":"roughness"]=K),A=!0}}if(D[2]==="emissiveFactor"&&Array.isArray(x)&&x.length>=3)return I.emissiveFactor=[0,1,2].map(N=>Math.max(0,W(x[N]))),A=!0;if(D[2]==="alphaCutoff")return I.alphaCutoff=Xe(W(x,.5)),A=!0}return!1},j=(T,x,D=new Set)=>{let k=se(x,"pointer");if(typeof k!="string"||!k.startsWith("/"))return null;let I=k.replace(/\{([a-zA-Z0-9_]+)\}/g,(L,P)=>{let N=Math.trunc(Number(z(T,P,void 0,D)??se(x,P)));return Number.isSafeInteger(N)&&N>=0?String(N):"-1"});return Rt(I)?I:null},z=(T,x,D,k)=>{let I=i[T]?.values;if(!vn(I,x))return D;let L=I[x];if(L==null)return D;if(typeof L!="object"||Array.isArray(L))return Ae(L);let P=L;return typeof P.node=="number"?X(P.node,P.socket||"value",k):vn(P,"value")?Ae(P.value):D},X=(T,x,D)=>{if(T<0||T>=i.length||D.has(T)||D.size>128||++w>Qi)return;let k=i[T],I=R(k);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(I))return Ae(s.get(T)?.[x]);D.add(T);try{let L=(P,N=0)=>z(T,P,N,D);if(I==="variable/get"){let P=se(k,"variable")??se(k,"id");return typeof P=="number"||typeof P=="string"?Ae(a.get(P)):void 0}if(I==="pointer/get"){let P=j(T,k,D);return P?B(P):void 0}if(I.startsWith("math/")){let P=I.slice(5);if(P in ni)return to(L("a"),ni[P]);if(P in ri){let N=/^(mul|div|rem|mod|pow)$/.test(P)?1:0;return er(L("a",P==="mul"?1:0),L("b",N),ri[P])}if(P==="pi")return Math.PI;if(P==="e")return Math.E;if(P==="random")return Math.random();if(P==="clamp")return er(er(L("a"),L("b",L("min",0)),Math.max),L("c",L("max",1)),Math.min);if(P==="mix"||P==="quatSlerp")return oi(L("a",0),L("b",1),W(L("c",L("t",.5)),.5),P==="quatSlerp");if(P==="dot"){let N=L("a"),K=L("b");return Array.isArray(N)&&Array.isArray(K)?N.reduce((Z,$,V)=>Z+($||0)*(K[V]||0),0):W(N)*W(K)}if(P==="cross"){let N=L("a",[0,0,0]),K=L("b",[0,0,0]);return Array.isArray(N)&&Array.isArray(K)?[(N[1]||0)*(K[2]||0)-(N[2]||0)*(K[1]||0),(N[2]||0)*(K[0]||0)-(N[0]||0)*(K[2]||0),(N[0]||0)*(K[1]||0)-(N[1]||0)*(K[0]||0)]:[0,0,0]}if(P==="length"){let N=L("a");return Array.isArray(N)?Math.hypot(...N):Math.abs(W(N))}if(P==="distance"){let N=L("a"),K=L("b");return Array.isArray(N)&&Array.isArray(K)?Math.hypot(...N.map((Z,$)=>(Z||0)-(K[$]||0))):Math.abs(W(N)-W(K))}if(P==="normalize"){let N=L("a");if(!Array.isArray(N))return W(N)>=0?1:-1;let K=Math.hypot(...N);return K>1e-8?N.map(Z=>Z/K):N.map(()=>0)}if(P.startsWith("combine"))return["a","b","c","d"].slice(0,Number(P[7])||2).map(N=>W(L(N)));if(P.startsWith("extract")){let N=L("a");return Array.isArray(N)?N[x==="0"||x==="x"?0:x==="1"||x==="y"?1:x==="2"||x==="z"?2:3]??0:0}if(P==="eq")return si(L("a"),L("b"));if(P==="ne")return!si(L("a"),L("b"));if(P==="lt")return W(L("a"))<W(L("b"));if(P==="le")return W(L("a"))<=W(L("b"));if(P==="gt")return W(L("a"))>W(L("b"));if(P==="ge")return W(L("a"))>=W(L("b"));if(P==="isNaN")return Number.isNaN(Number(L("a")));if(P==="isInf"){let N=Number(L("a"));return!Number.isFinite(N)&&!Number.isNaN(N)}return P==="and"?Ee(L("a",!1))&&Ee(L("b",!1)):P==="or"?Ee(L("a",!1))||Ee(L("b",!1)):P==="xor"?Ee(L("a",!1))!==Ee(L("b",!1)):P==="not"?!Ee(L("a",!1)):P==="select"?Ae(Ee(L("condition",!1))?L("a"):L("b")):void 0}return I==="type/boolToInt"||I==="type/boolToFloat"?Ee(L("a",!1))?1:0:I==="type/intToBool"||I==="type/floatToBool"?W(L("a",0))!==0:I==="type/intToFloat"?W(L("a",0)):I==="type/floatToInt"?Math.trunc(W(L("a",0))):void 0}finally{D.delete(T)}},U=()=>{if(C){C=!1,A=!0;let T=Le(n);if(e){e.worldMatrices=T;for(let x of e.meshes||[])x.nodeIndex>=0&&x.nodeIndex<T.length&&(x.transform.set(T[x.nodeIndex]),de(x.normalMatrix,x.transform))}}if(b){b=!1,A=!0;let T=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(T))for(let x of e.meshes){let D=!0;for(let k=x.nodeIndex,I=0;k!==void 0&&k>=0&&I<128;k=v.get(k),I++){let L=T[k];if(L?.visible===!1||L?.extensions?.KHR_node_visibility?.visible===!1){D=!1;break}}x.visible=D}}A&&(A=!1,e?.render?.())},q=(T,x={steps:0})=>{if(!T||typeof T.node!="number")return;x.steps===0&&(w=0);let D=[T],k=I=>{D.length+x.steps<gn&&D.push(I)};for(;D.length>0&&x.steps<gn;){x.steps++;let I=D.shift();if(!I||I.node<0||I.node>=i.length)continue;let L=I.node,P=i[L];if(!P)continue;let N=I.socket||"in",K=R(P),Z=(V,J=void 0)=>z(L,V,J,new Set),$=(V="out")=>{let J=P.flows?.[V];J&&k(J)};switch(K){case"flow/branch":$(Ee(Z("condition",!1))?"true":"false");break;case"flow/sequence":for(let V of Object.keys(P.flows||{}).sort((J,te)=>Number(J)-Number(te)||J.localeCompare(te)))$(V);break;case"flow/switch":{let V=P.flows?.[String(Z("selection",Z("value",0)))]??P.flows?.default;V&&k(V);break}case"flow/for":{let V=Math.trunc(W(Z("startIndex",0))),J=Math.trunc(W(Z("endIndex",0))),te=Math.max(1,Math.trunc(W(Z("step",1),1))),ie=P.flows?.body;if(ie&&J>V&&g<eo){let Re=Math.min(Math.ceil((J-V)/te),gn);g++;try{for(let he=0;he<Re&&x.steps<gn;he++)E(L,"index",V+he*te),q(ie,x)}finally{g--}}let ue=P.flows?.completed??P.flows?.out;ue&&k(ue);break}case"flow/doN":{let V=N==="reset"?0:(u.get(L)||0)+1;if(u.set(L,V),E(L,"currentCount",V),E(L,"count",V),N!=="reset"){let J=Math.trunc(W(Z("n",se(P,"stopIterations")??se(P,"n")??1),1));V<=J&&$()}break}case"flow/multiGate":{if(N==="reset"){f.set(L,0);break}let V=Object.keys(P.flows||{}).sort();if(!V.length)break;let J=se(P,"isRandom")?Math.floor(Math.random()*V.length):f.get(L)||0;J<V.length&&($(V[J]),f.set(L,se(P,"isLoop")!==!1?(J+1)%V.length:J+1));break}case"flow/waitAll":{if(N==="reset"){m.delete(L);break}let V=m.get(L);V||m.set(L,V=new Set),V.add(N),V.size>=Math.max(1,Math.trunc(Number(se(P,"inputFlows")??2)||2))&&(V.clear(),$("out"),$("completed"));break}case"flow/throttle":{if(N==="reset"){h.delete(L);break}let V=Math.max(0,W(Z("duration",0))),J=h.get(L);J===void 0||S-J>=V?(h.set(L,S),E(L,"lastRemainingTime",0),$()):E(L,"lastRemainingTime",Math.max(0,V-(S-J)));break}case"flow/delay":case"flow/setDelay":{if(N==="cancel"){for(let ie=p.length-1;ie>=0;ie--)p[ie].nodeIdx===L&&p.splice(ie,1);E(L,"lastDelayIndex",-1);break}let V=Math.max(0,W(Z("duration",se(P,"duration")??0))),J=P.flows?.done??P.flows?.out;if(V<=0){E(L,"lastDelayIndex",-1),J&&k(J);break}p.length>=Zi&&p.shift();let te=_++;E(L,"lastDelayIndex",te),p.push({id:te,nodeIdx:L,rem:V,done:J}),K==="flow/setDelay"&&P.flows?.out&&P.flows?.done&&$("out");break}case"flow/cancelDelay":{let V=Math.trunc(W(Z("delayIndex",-1),-1));if(V<0)p.length=0;else for(let J=p.length-1;J>=0;J--)p[J].id===V&&p.splice(J,1);$();break}case"variable/set":O(se(P,"variable")??se(P,"id"),Z("value")),$();break;case"variable/interpolate":{let V=se(P,"variable")??se(P,"id"),J=Z("value",Z("target")),te=Math.max(0,W(Z("duration",se(P,"duration")??.3),.3));V!==void 0&&J!==void 0&&G({key:`var:${String(V)}`,varKey:V,from:Ae(Z("from")??a.get(V)??0),to:Ae(J),dur:te,elapsed:0,quat:!1,linear:se(P,"easing")==="linear",done:P.flows?.done}),$();break}case"pointer/set":{let V=j(L,P),J=Z("value");V&&J!==void 0&&(M(`ptr:${V}`),Q(V,J)),$();break}case"pointer/interpolate":{let V=j(L,P),J=Z("value",Z("target")),te=Math.max(0,W(Z("duration",se(P,"duration")??.3),.3));if(V&&J!==void 0){let ie=Z("from")??B(V);ie!==void 0&&(te<=0?(Q(V,J),$("done")):G({key:`ptr:${V}`,ptr:V,from:Ae(ie),to:Ae(J),dur:te,elapsed:0,quat:V.endsWith("/rotation"),linear:se(P,"easing")==="linear",done:P.flows?.done}))}$();break}case"animation/start":{let V=Z("animation")??se(P,"animation")??se(P,"clipName"),J=typeof V=="number"?e?.animations?.[V]?.name??n?.animations?.[V]?.name:typeof V=="string"?V:void 0;e?.playAnimation?.(J),A=!0,$();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),K==="animation/resetAt"&&e?.evaluateAnimation?.(W(Z("time",0))),A=!0,$();break;case"event/send":case"customEvent/send":{let V=H(se(P,"event")??se(P,"id")),J={};for(let te of Object.keys(P.values||{}))ke.has(te)||(J[te]=Z(te));V&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:V,values:J}})),Y(V,J,x)),$();break}default:$();break}}};this.readScenePointer=B,this.writeScenePointer=Q,this.fireOnStart=()=>{i.forEach(T=>{R(T)==="event/onStart"&&q(T.flows?.out)}),U()},this.fireOnSelect=T=>{if(!T)return;let x=typeof T.meshIndex=="number"?T.meshIndex:-1,D=typeof T.nodeIndex=="number"?T.nodeIndex:e?.meshes?.[x]?.nodeIndex??-1;i.forEach((k,I)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(R(k)))return;let L=se(k,"nodeIndex")??se(k,"node")??z(I,"nodeIndex",void 0,new Set),P=se(k,"meshName");if(typeof P=="string"&&P?T.meshName===P:L==null||Number(L)<0||Number.isNaN(Number(L))||F(D,Math.trunc(Number(L)))){if(E(I,"nodeIndex",D),E(I,"meshIndex",x),Array.isArray(T.hitPoint)){let K=[W(T.hitPoint[0]),W(T.hitPoint[1]),W(T.hitPoint[2])];E(I,"hitPoint",K),E(I,"point",K),E(I,"intersectionPoint",K)}if(Array.isArray(T.normal)){let K=[W(T.normal[0]),W(T.normal[1],1),W(T.normal[2])];E(I,"normal",K),E(I,"hitNormal",K)}typeof T.distance=="number"&&E(I,"distance",T.distance),q(k.flows?.out)}}),U()},this.receiveCustomEvent=(T,x={})=>Y(T,x,{steps:0});function Y(T,x,D){if(!(y>=Ji)){y++;try{let k=H(T);i.forEach((I,L)=>{if(!/^(customE|e)vent\/receive$/.test(R(I)))return;let P=se(I,"event")??se(I,"id");if(!(H(P)!==k&&String(P)!==String(T))){for(let[N,K]of Object.entries(x))ke.has(N)||E(L,N,Ae(K));q(I.flows?.out,D)}}),U()}finally{y--}}}this.tick=T=>{if(!Number.isFinite(T)||T<0)return;let x=Math.min(T,.25);S+=x,i.forEach((k,I)=>{R(k)==="event/onTick"&&(E(I,"timeDelta",x),E(I,"dt",x),E(I,"timeElapsed",S),q(k.flows?.out))});let D=[];for(let k=d.length-1;k>=0;k--){let I=d[k];I.elapsed+=x;let L=I.dur>1e-6?Xe(I.elapsed/I.dur):1,P=I.linear?L:L*L*(3-2*L),N=oi(I.from,I.to,P,I.quat);I.ptr?Q(I.ptr,N):I.varKey!==void 0&&O(I.varKey,N),L>=1&&(d.splice(k,1),I.done&&D.push(I.done))}for(let k=p.length-1;k>=0;k--){let I=p[k];I.rem-=x,I.rem<=0&&(p.splice(k,1),I.done&&D.push(I.done))}for(let k of D)q(k);U()},this.dispose=()=>{d.length=0,p.length=0,a.clear(),s.clear(),u.clear(),m.clear(),h.clear(),f.clear()}}},Ie=new WeakMap,wn=new WeakMap;function no(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||Pt().some(l=>l.name==="xr-live-head-follow"))return;let n=t.gltf,r=n?.nodes;if(!Array.isArray(r)||r.length===0)return;let i=Math.min(e,.1),o=(wn.get(t)||0)+i,c=!1;for(let l=0;l<r.length;l++){let a=r[l],s=Cr(a?.extras?.xr?.orbit);if(!s)continue;let u=0,m=0,h=0;if(Array.isArray(s.target))u=s.target[0],m=s.target[1],h=s.target[2];else if(typeof s.target=="string"&&s.target!=="head"){let _=r.find(S=>S?.name===s.target);Array.isArray(_?.translation)&&(u=W(_.translation[0]),m=W(_.translation[1]),h=W(_.translation[2]))}let f=s.phase+s.speed*o,d=u+Math.cos(f)*s.radius,p=m+s.height,v=h+Math.sin(f)*s.radius;if(a.translation=[d,p,v],s.faceCenter){let _=Math.atan2(u-d,h-v);a.rotation=[0,Math.sin(_*.5),0,Math.cos(_*.5)]}c=!0}if(c){wn.set(t,o);let l=Le(n);t.worldMatrices=l;for(let a of t.meshes||[])a.nodeIndex>=0&&a.nodeIndex<l.length&&(a.transform.set(l[a.nodeIndex]),de(a.normalMatrix,a.transform))}}function An(t){if(!(!t||typeof t!="object"))return Ie.get(t)||Ie.get(t.viewer)||Ie.get(t._view)}function tr(t,e,n){let r=An(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var nr={name:"khr-interactivity",sendInteractivityEvent:tr,getInteractivityVM:An,onLoadModel(t,e){if(!t||typeof t!="object")return;Ie.get(t)?.dispose(),Ie.delete(t),wn.delete(t);let n=e?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let i=new Tt(t,e,r);Ie.set(t,i),i.fireOnStart()},onMeshSelect(t,e){Ie.get(t)?.fireOnSelect(e)},onUpdate(t,e){Ie.get(t)?.tick(e),no(t,e)},onDestroy(t,e){Ie.get(e)?.dispose(),Ie.delete(e),wn.delete(e)}};var St=new Map,rr=new WeakMap;function ci(t,e){St.set(t,e)}var ir={name:"materials",onBuildPrimitiveVAO(t,e,n,r,i){return(((r?.materials&&n.material!==void 0?r.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(t,e){let n=rr.get(t);n||(n=t.createTexture(),rr.set(t,n));let r=Math.max(1,e.canvas.width),i=Math.max(1,e.canvas.height);t.activeTexture(33990),t.bindTexture(3553,n),t.copyTexImage2D(3553,0,6408,0,0,r,i,0),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553)},onResolveShader(t,e,n,r){if(!e)return null;if(e.name&&St.has(e.name)){let d=St.get(e.name);return{vs:d.vs||n,fs:d.fs||r}}let i=e.extensions||{},o=i.KHR_materials_clearcoat,c=i.KHR_materials_sheen,l=!!i.KHR_materials_transmission,a=!!i.KHR_materials_ior,s=i.KHR_materials_iridescence;if(!o&&!c&&!i.KHR_materials_unlit&&!l&&!i.KHR_materials_volume&&!a&&!i.KHR_materials_dispersion&&!s)return null;if(i.KHR_materials_unlit)return{vs:n,fs:r.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let u=r;if(l){let d=u.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
332
|
+
`;u=u.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
333
|
+
${d}out vec4 fragColor;`)}let m=(d,p,v=0,_=1e6,S=3)=>{let y=Number(d);return(Number.isFinite(y)?Math.min(_,Math.max(v,y)):p).toFixed(S)},h=Number(i.KHR_materials_ior?.ior??1.5),f=Number.isFinite(h)?Math.min(10,Math.max(1,h)):1.5;if(a){let d=Math.pow((f-1)/(f+1),2);u=u.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(d,.04,0,1,4)}),base.rgb,metallic);`)}if(s){let d=m(s.iridescenceFactor,1,0,1),p=m(s.iridescenceIor,1.3,1,10);u=u.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${p}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${d}*pow(1.-NoV,2.));`)}if(l){let d=m(i.KHR_materials_transmission?.transmissionFactor,1,0,1),p=i.KHR_materials_volume||{},v=m(p.thicknessFactor,.5,0,1e4),_=m(p.attenuationDistance,1,.001,1e6),S=Array.isArray(p.attenuationColor)?p.attenuationColor:[1,1,1],y=m(i.KHR_materials_dispersion?.dispersion,0,0,10);u=u.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
334
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(f,1.5,1,10)},dV=${y},tV=${v},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
330
335
|
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
331
336
|
vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
|
|
332
|
-
vec3 aCol=vec3(${m(
|
|
333
|
-
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${
|
|
334
|
-
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${d});`)}if(o&&!
|
|
335
|
-
layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,
|
|
336
|
-
precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,gn=new WeakMap,ii=new Float32Array(20);function oi(t,e){let[n,i,r,o,u,l]=e;return[t[0]*n+t[4]*i+t[8]*r+t[12],t[1]*n+t[5]*i+t[9]*r+t[13],t[2]*n+t[6]*i+t[10]*r+t[14],Math.abs(t[0])*o+Math.abs(t[4])*u+Math.abs(t[8])*l,Math.abs(t[1])*o+Math.abs(t[5])*u+Math.abs(t[9])*l,Math.abs(t[2])*o+Math.abs(t[6])*u+Math.abs(t[10])*l]}function ro(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,i=1e9,r=-1e9,o=-1e9,u=-1e9;for(let l of t.primitives||[]){let a=l.positions;if(a)for(let c=0;c<a.length;c+=3)a[c]<e&&(e=a[c]),a[c+1]<n&&(n=a[c+1]),a[c+2]<i&&(i=a[c+2]),a[c]>r&&(r=a[c]),a[c+1]>o&&(o=a[c+1]),a[c+2]>u&&(u=a[c+2])}return t._lb=e<=r?[(e+r)*.5,(n+o)*.5,(i+u)*.5,(r-e)*.5,(o-n)*.5,(u-i)*.5]:null}function io(t){let e=gn.get(t);if(e)return e;let n=(l,a)=>{let c=t.createShader(l);return t.shaderSource(c,a),t.compileShader(c),c},i=t.createProgram();t.attachShader(i,n(35633,to)),t.attachShader(i,n(35632,no)),t.linkProgram(i);let r=t.createVertexArray(),o=t.createBuffer(),u=t.createBuffer();return t.bindVertexArray(r),t.bindBuffer(34962,o),t.bufferData(34962,80,35048),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,5126,!1,20,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,5126,!1,20,12),t.bindBuffer(34963,u),t.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),t.bindVertexArray(null),e={prog:i,vao:r,vbo:o,ibo:u,uMVP:t.getUniformLocation(i,"uMVP"),uIntensity:t.getUniformLocation(i,"uShadowIntensity"),uSoftness:t.getUniformLocation(i,"uShadowSoftness")},gn.set(t,e),e}var xt={name:"contact-shadow",onAfterRender(t,e,n){let i=e.shadowIntensity;if(i<=0||!e.bounds)return;let r=io(t),o=(e.backdropMeshes?.length??0)>0,u=[],l=[];for(let s of e.meshes||[]){if(!s||s.visible===!1||s.isPluginMesh||s.name==="__xr_reticle__"||s.name?.startsWith("__xr_slot_"))continue;let m=ro(s);if(!m)continue;s.transform&&(m=oi(s.transform,m)),e.modelRootMatrix&&(m=oi(e.modelRootMatrix,m));let[h,f,d,b,g,E]=m,A=[h,d,b,E,f-g,f+g];/floor|table|pedestal|ground|base|plane/i.test(s.name||"")||g<.14&&Math.min(b,E)>.45?l.push(A):u.push(A)}let a=[],c=(e.bounds.min?e.bounds.min[1]:e.bounds.center[1]-e.bounds.radius)+.002;for(let[s,m,h,f,d]of u){let b=-1/0;for(let[E,A,p,R,,x]of l)d>=x-.08&&Math.abs(s-E)<=p&&Math.abs(m-A)<=R&&x+.002>b&&(b=x+.002);o&&(b=Math.max(b,s>=.04&&s<=.36&&m>=-.34&&m<=-.04&&d>=.01?.036:Math.hypot(s,m)<=.66&&d>=-.06?.003:-.477)),isFinite(b)||(b=c);let g=a.find(E=>Math.hypot(s-E[0],m-E[1])<.06&&Math.abs(b-E[5])<.05);g?(g[2]=Math.max(g[2],h*.78),g[3]=Math.max(g[3],f*.78),g[4]=Math.min(g[4],d)):a.push([s,m,h,f,d,b])}if(a.length===0){let s=e.bounds.center,m=Math.max(.1,e.bounds.radius*1.5)/1.45;a.push([s[0],s[2],m,m,c,c])}t.useProgram(r.prog),t.uniformMatrix4fv(r.uMVP,!1,n),t.enable(3042),(t.blendFuncSeparate||t.blendFunc).call(t,770,771,1,771),t.depthMask(!1),t.bindVertexArray(r.vao),t.bindBuffer(34962,r.vbo);for(let[s,m,h,f,d,b]of a){let g=Math.max(0,d-b),E=i/(1+g*2);if(E<.02)continue;let A=1+Math.min(.75,g*.85),p=Math.max(.045,h*1.45*A),R=Math.max(.045,f*1.45*A);ii.set([s-p,b,m-R,0,0,s+p,b,m-R,1,0,s+p,b,m+R,1,1,s-p,b,m+R,0,1]),t.bufferSubData(34962,0,ii),t.uniform1f(r.uIntensity,E),t.uniform1f(r.uSoftness,Math.min(1,e.shadowSoftness+Math.min(.45,g*.6))),t.drawElements(4,6,5123,0)}t.bindVertexArray(null),t.depthMask(!0),t.disable(3042)},onDestroy(t){let e=gn.get(t);e&&(t.deleteVertexArray(e.vao),t.deleteBuffer(e.vbo),t.deleteBuffer(e.ibo),t.deleteProgram(e.prog),gn.delete(t))}};var si=new WeakMap;function oo(t){let r=new Float32Array(192),o=new Float32Array(32*2*3),u=new Float32Array(32*2*2),l=new Uint16Array(32*6);for(let g=0;g<32;g++){let E=g/32*Math.PI*2,A=Math.cos(E),p=Math.sin(E),R=g*2,x=g*2+1;r[R*3]=A*.12,r[R*3+1]=.002,r[R*3+2]=p*.12,r[x*3]=A*.15,r[x*3+1]=.002,r[x*3+2]=p*.15,o[R*3+1]=1,o[x*3+1]=1;let F=(g+1)%32*2,y=F+1,w=g*6;l[w]=R,l[w+1]=F,l[w+2]=x,l[w+3]=x,l[w+4]=F,l[w+5]=y}let a=t.createVertexArray();t.bindVertexArray(a);let c=(g,E,A)=>{let p=t.createBuffer();return t.bindBuffer(34962,p),t.bufferData(34962,g,35044),t.enableVertexAttribArray(E),t.vertexAttribPointer(E,A,5126,!1,0,0),p},s=c(r,0,3),m=c(o,1,3),h=c(u,2,2),f=t.createBuffer();t.bindBuffer(34963,f),t.bufferData(34963,l,35044),t.bindVertexArray(null);let d=se(),b=new Float32Array(9);return b[0]=1,b[4]=1,b[8]=1,{name:"__xr_reticle__",nodeIndex:-1,visible:!1,transform:d,normalMatrix:b,primitives:[{vao:a,indexCount:l.length,indexType:5123,baseColor:[1,1,1,.95],metallic:0,roughness:.2,positions:r,indices:l,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:[s,m,h,f]}]}}function ai(t,e,n){let i=Math.cos(n),r=Math.sin(n);t.set(e),t[0]=i,t[1]=0,t[2]=-r,t[4]=0,t[5]=1,t[6]=0,t[8]=r,t[9]=0,t[10]=i}var tr={name:"webxr-suite",onConfigureXRSessionInit(t,e){let n=new Set(e.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation"),n.add("dom-overlay"),e.optionalFeatures=Array.from(n);let i=t?.querySelector?.('[slot="ar-overlay"]')||t;i&&(e.domOverlay={root:i},i.addEventListener("beforexrselect",r=>{r.preventDefault()}))},onXRFrame(t,e,n,i){if(!t||!e||!n||!i)return;let r=si.get(e);if(!r){r={initialized:!0,hitTestSource:null,lightProbe:null,reticleMesh:oo(t.gl),lastHitMatrix:null,hasPlaced:!1,rotationY:0,isDragging:!1,lastTouchAngle:null},si.set(e,r),t.meshes.push(r.reticleMesh),typeof e.requestReferenceSpace=="function"&&e.requestReferenceSpace("viewer").then(s=>typeof e.requestHitTestSource=="function"?e.requestHitTestSource({space:s}):null).then(s=>{r&&s&&(r.hitTestSource=s)}).catch(()=>{}),typeof e.requestLightProbe=="function"&&e.requestLightProbe().then(s=>{r&&s&&(r.lightProbe=s)}).catch(()=>{});let o=()=>r?.lastHitMatrix&&ai(t.modelRootMatrix,r.lastHitMatrix,r.rotationY),u=s=>Math.atan2(s.touches[1].clientY-s.touches[0].clientY,s.touches[1].clientX-s.touches[0].clientX);e.addEventListener("select",()=>{r?.lastHitMatrix&&(r.hasPlaced=!0,o())});let l=s=>{r&&(s.touches.length===1&&r.hasPlaced?r.isDragging=!0:s.touches.length===2&&(r.isDragging=!1,r.lastTouchAngle=u(s)))},a=s=>{if(r){if(s.touches.length===1&&r.isDragging)o();else if(s.touches.length===2&&r.lastTouchAngle!==null){let m=u(s);r.rotationY+=m-r.lastTouchAngle,r.lastTouchAngle=m,o()}}},c=()=>{r&&(r.isDragging=!1,r.lastTouchAngle=null)};typeof window<"u"&&(window.addEventListener("touchstart",l,{passive:!0}),window.addEventListener("touchmove",a,{passive:!0}),window.addEventListener("touchend",c,{passive:!0})),e.addEventListener("end",()=>{if(r?.reticleMesh){let s=t.meshes.indexOf(r.reticleMesh);s!==-1&&t.meshes.splice(s,1)}t.modelRootMatrix=se(),typeof window<"u"&&(window.removeEventListener("touchstart",l),window.removeEventListener("touchmove",a),window.removeEventListener("touchend",c))})}if(r.hitTestSource&&typeof n.getHitTestResults=="function"){let o=n.getHitTestResults(r.hitTestSource);if(o&&o.length>0){let u=o[0].getPose(i);if(u?.transform?.matrix){let l=u.transform.matrix;r.lastHitMatrix=l,r.reticleMesh.visible=!r.hasPlaced||r.isDragging,r.reticleMesh.transform.set(l),ue(r.reticleMesh.normalMatrix,r.reticleMesh.transform),r.hasPlaced||ai(t.modelRootMatrix,l,r.rotationY)}}else r.reticleMesh.visible=!1}if(r.lightProbe&&typeof n.getLightEstimate=="function"){let o=n.getLightEstimate(r.lightProbe);if(o){let u=o.primaryLightDirection,l=o.primaryLightIntensity;if(u&&l&&Array.isArray(t.lights)){let a=t.lights.find(s=>s.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(a)),a.direction=[u.x,u.y,u.z];let c=Math.max(l.x,l.y,l.z,.001);a.color=[l.x/c,l.y/c,l.z/c],a.intensity=c}o.sphericalHarmonicsCoefficients&&hn(t.gl,o.sphericalHarmonicsCoefficients)}}}};fe(xt);fe(Yn);fe(Gn);fe(er);fe(tr);fe(Jn);function rr(){if(typeof window>"u"||typeof navigator>"u")return!1;let t=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(t)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function ir(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function or(){if(typeof navigator>"u")return!1;let t=navigator;if(!t.xr||typeof t.xr.isSessionSupported!="function")return!1;try{return await t.xr.isSessionSupported("immersive-ar")?!0:await t.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function ui(){return(await vn()).bestMode}async function vn(){let[t,e,n]=await Promise.all([or(),Promise.resolve(rr()),Promise.resolve(ir())]),i=[];e&&i.push("quick-look"),t&&i.push("webxr"),n&&i.push("scene-viewer");let r=null;return e?r="quick-look":t?r="webxr":n&&(r="scene-viewer"),{webxr:t,quickLook:e,sceneViewer:n,availableModes:i,bestMode:r}}function ci(t,e={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,i=!1;if(typeof t=="string"){if(n=so(t),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(t),i=!0;let r=[];if(e.allowScale===!1&&r.push("allowsContentScaling=0"),e.canonicalWebPageUrl){let l=xn(e.canonicalWebPageUrl,!1);l&&r.push(`canonicalWebPageURL=${encodeURIComponent(l)}`)}e.checkoutTitle&&r.push(`checkoutTitle=${encodeURIComponent(e.checkoutTitle)}`),e.checkoutSubtitle&&r.push(`checkoutSubtitle=${encodeURIComponent(e.checkoutSubtitle)}`),e.price&&r.push(`price=${encodeURIComponent(e.price)}`),r.length>0&&(n+=`#${r.join("&")}`);let o=document.createElement("a");o.setAttribute("rel","ar"),o.setAttribute("href",n);let u=document.createElement("img");u.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),u.style.display="none",o.appendChild(u),document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),i&&URL.revokeObjectURL(n.split("#")[0])},3e3)}function xn(t,e=!1){if(typeof t!="string")return"";let n=t.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!n)return"";if(/^[\\/]{2}/.test(n))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${n.slice(0,32)}`);let i=n.toLowerCase();if(i.startsWith("https://")||i.startsWith("http://")||e&&i.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(n))return n;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${n.slice(0,32)}`)}function so(t){try{return xn(t,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(t||"").trim().slice(0,32)}`)}}function ao(t,e={}){let n=xn(t,!0),i=e.mode||"ar_preferred",r=new URLSearchParams({file:n,mode:i,resizable:e.resizable!==!1?"true":"false",enable_vertical_placement:e.enableVerticalPlacement?"true":"false"});return e.title&&r.set("title",e.title),e.link&&r.set("link",xn(e.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${r.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function co(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=ao(t,e);window.location.href=n}var nr=class{constructor(e={}){this.session=null;this.refSpace=null;this.viewerSpace=null;this.hitTestSource=null;this.isPlaced=!1;this.placedMatrix=new Float32Array(16);this.currentHitMatrix=null;this.view=null;this.options=e}isSessionActive(){return this.session!==null}hasPlacedModel(){return this.isPlaced}getPlacedMatrix(){return this.placedMatrix}async start(e,n){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");let i=navigator.xr;this.view=e;let r={requiredFeatures:this.options.requiredFeatures||[],optionalFeatures:this.options.optionalFeatures||["local","hit-test","dom-overlay","light-estimation"]},o=n||e?.container;for(let a of ce)a.onConfigureXRSessionInit?.(o,r);let u="immersive-ar";try{await i.isSessionSupported("immersive-ar")||(u="immersive-vr")}catch{u="immersive-vr"}try{this.session=await i.requestSession(u,r)}catch(a){throw this.options.onError?.(a),a}this.session.addEventListener("end",()=>{this.cleanup(),this.options.onExit?.()}),this.session.addEventListener("select",()=>{this.handleSelect()});let l=e.getGLContext?.();if(l&&l.makeXRCompatible&&await l.makeXRCompatible(),l&&typeof window<"u"&&typeof window.XRWebGLLayer=="function"&&typeof this.session.updateRenderState=="function"){let a=new window.XRWebGLLayer(this.session,l);this.session.updateRenderState({baseLayer:a})}if(this.refSpace=await this.session.requestReferenceSpace("local"),this.viewerSpace=await this.session.requestReferenceSpace("viewer"),this.session.requestHitTestSource)try{this.hitTestSource=await this.session.requestHitTestSource({space:this.viewerSpace})}catch{}this.session.requestAnimationFrame(this.onXRFrame.bind(this))}async stop(){this.session&&(await this.session.end(),this.cleanup())}handleSelect(){this.currentHitMatrix&&!this.isPlaced&&(this.placedMatrix.set(this.currentHitMatrix),this.isPlaced=!0,this.options.onPlaced?.(this.placedMatrix))}onXRFrame(e,n){if(!this.session)return;this.session.requestAnimationFrame(this.onXRFrame.bind(this));let i=n.getViewerPose(this.refSpace);if(!i)return;let r=this.view?.getGLContext?.(),o=this.session.renderState?.baseLayer;if(r&&o&&o.framebuffer&&r.bindFramebuffer(36160,o.framebuffer),this.hitTestSource&&!this.isPlaced){let u=n.getHitTestResults(this.hitTestSource);for(let l of u){let a=l.getPose(this.refSpace);if(a){let c=a.transform.matrix,s=c[5];if(this.options.arPlacement==="wall"&&Math.abs(s)>.35||this.options.arPlacement==="floor"&&Math.abs(s)<.65)continue;this.currentHitMatrix=c,this.options.onHit?.(this.currentHitMatrix);break}}}for(let u of ce)u.onXRFrame?.(this.view,this.session,n,this.refSpace);for(let u of i.views)this.view&&typeof this.view.renderXRView=="function"&&this.view.renderXRView(u,this.isPlaced?this.placedMatrix:this.currentHitMatrix,this.isPlaced);r&&o&&o.framebuffer&&r.bindFramebuffer(36160,null)}cleanup(){this.hitTestSource&&(this.hitTestSource.cancel?.(),this.hitTestSource=null),this.session=null,this.refSpace=null,this.viewerSpace=null,this.currentHitMatrix=null,this.isPlaced=!1,this.view=null}};async function wn(t){let e=await vn(),n=t.preferredModes||["quick-look","webxr","scene-viewer"],i=null;for(let l of n)if(e.availableModes.includes(l)){i=l;break}if(i||(i=e.bestMode),!i)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let r={...t.quickLookOptions,allowScale:t.arScale==="fixed"?!1:t.quickLookOptions?.allowScale},o={...t.sceneViewerOptions,resizable:t.arScale==="fixed"?!1:t.sceneViewerOptions?.resizable,enableVerticalPlacement:t.arPlacement==="wall"?!0:t.sceneViewerOptions?.enableVerticalPlacement},u={...t.webXROptions,arPlacement:t.arPlacement||t.webXROptions?.arPlacement};try{if(i==="quick-look"){let l;if(t.model instanceof Blob&&t.model.type==="model/vnd.usdz+zip")l=t.model;else{if(typeof t.model=="string")return ci(t.model,r),{mode:"quick-look",success:!0};l=We(t.model)}return ci(l,r),{mode:"quick-look",success:!0}}if(i==="scene-viewer"){let l=t.glbUrl||(typeof t.model=="string"?t.model:null);if(!l)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return co(l,o),{mode:"scene-viewer",success:!0}}if(i==="webxr"){if(!t.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let l=new nr(u);return await l.start(t.view),{mode:"webxr",success:!0,session:l}}}catch(l){return{mode:i,success:!1,error:l}}return{mode:i,success:!1,error:new Error(`Unhandled AR mode: ${i}`)}}Ee.registerAR({activateAR:wn,createUSDZBlob:We});Ee.registerScriptRunner(Ye);fe(xt);Ee.registerScriptRunner(Ye);typeof window<"u"&&(window.ThreeLiveBundle=sr);return yi(sr);})();
|
|
337
|
+
vec3 aCol=vec3(${m(S[0],1,0,1)},${m(S[1],1,0,1)},${m(S[2],1,0,1)});
|
|
338
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${_},.001));
|
|
339
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${d});`)}if(o&&!r.includes("uClearcoat")){let d=m(o.clearcoatFactor,1,0,1),p=m(o.clearcoatRoughnessFactor,0,0,1);u=u.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${p},NoV)*${d};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${p})*ccF;fragColor=vec4(color,base.a);`)}if(c){let d=Array.isArray(c.sheenColorFactor)?c.sheenColorFactor:[1,1,1],p=`color+=vec3(${m(d[0],1,0,1)},${m(d[1],1,0,1)},${m(d[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;u.includes("color=applyToneMapping(color,uToneMapping);")?u=u.replace("color=applyToneMapping(color,uToneMapping);",`${p}color=applyToneMapping(color,uToneMapping);`):u=u.replace("fragColor=vec4(color,base.a);",`${p}fragColor=vec4(color,base.a);`)}return{vs:n,fs:u}},onBeforeDrawPrimitive(t,e,n,r,i,o){let c=n.materialIndex;if(c!==void 0&&o?.materials){let l=o.materials[c];l?.name&&St.has(l.name)&&St.get(l.name).onBindUniforms?.(t,e,n)}if(n.isTransmissive){let l=rr.get(t);if(l){t.activeTexture(33990),t.bindTexture(3553,l);let a=t.getUniformLocation(e,"uTransmissionTex");a&&t.uniform1i(a,6);let s=t.getUniformLocation(e,"uViewportSize");s&&t.uniform2f(s,t.drawingBufferWidth||1,t.drawingBufferHeight||1)}}}};var ro=`#version 300 es
|
|
340
|
+
layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,io=`#version 300 es
|
|
341
|
+
precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Rn=new WeakMap,ui=new Float32Array(20);function or(t,e){let[n,r,i,o,c,l]=e;return[t[0]*n+t[4]*r+t[8]*i+t[12],t[1]*n+t[5]*r+t[9]*i+t[13],t[2]*n+t[6]*r+t[10]*i+t[14],Math.abs(t[0])*o+Math.abs(t[4])*c+Math.abs(t[8])*l,Math.abs(t[1])*o+Math.abs(t[5])*c+Math.abs(t[9])*l,Math.abs(t[2])*o+Math.abs(t[6])*c+Math.abs(t[10])*l]}function oo(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,c=-1e9;for(let l of t.primitives||[]){let a=l.positions;if(a)for(let s=0;s<a.length;s+=3)a[s]<e&&(e=a[s]),a[s+1]<n&&(n=a[s+1]),a[s+2]<r&&(r=a[s+2]),a[s]>i&&(i=a[s]),a[s+1]>o&&(o=a[s+1]),a[s+2]>c&&(c=a[s+2])}return t._lb=e<=i?[(e+i)*.5,(n+o)*.5,(r+c)*.5,(i-e)*.5,(o-n)*.5,(c-r)*.5]:null}function so(t){let e=Rn.get(t);if(e)return e;let n=(l,a)=>{let s=t.createShader(l);return t.shaderSource(s,a),t.compileShader(s),s},r=t.createProgram();t.attachShader(r,n(35633,ro)),t.attachShader(r,n(35632,io)),t.linkProgram(r);let i=t.createVertexArray(),o=t.createBuffer(),c=t.createBuffer();return t.bindVertexArray(i),t.bindBuffer(34962,o),t.bufferData(34962,80,35048),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,5126,!1,20,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,5126,!1,20,12),t.bindBuffer(34963,c),t.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),t.bindVertexArray(null),e={prog:r,vao:i,vbo:o,ibo:c,uMVP:t.getUniformLocation(r,"uMVP"),uIntensity:t.getUniformLocation(r,"uShadowIntensity"),uSoftness:t.getUniformLocation(r,"uShadowSoftness")},Rn.set(t,e),e}var Et={name:"contact-shadow",onAfterRender(t,e,n){let r=e.shadowIntensity;if(r<=0||!e.bounds)return;let i=so(t),o=!e.xrSessionActive&&(e.backdropMeshes?.length??0)>0,c=[],l=[];for(let p of e.meshes||[]){if(!p||p.visible===!1||p.isPluginMesh||p.name==="__xr_reticle__"||p.name?.startsWith("__xr_slot_"))continue;let v=oo(p);if(!v)continue;p.transform&&(v=or(p.transform,v)),e.modelRootMatrix&&(v=or(e.modelRootMatrix,v));let[_,S,y,w,g,C]=v,b=[_,y,w,C,S-g,S+g];/floor|table|pedestal|ground|base|plane/i.test(p.name||"")||g<.14&&Math.min(w,C)>.45?l.push(b):c.push(b)}let a=[],s=e.bounds.center||[0,0,0],u=Math.max(.05,Number(e.bounds.radius)||.5),m=e.bounds.min,h=m?[s[0],s[1],s[2],u,Math.max(.01,s[1]-m[1]),u]:[s[0],s[1],s[2],u,u,u];e.modelRootMatrix&&(h=or(e.modelRootMatrix,h));let d=e.xrSessionActive&&l.length===0&&String(e.container?.tagName||"").toLowerCase()==="xr-live"?(e.modelRootMatrix?e.modelRootMatrix[5]*-.25+e.modelRootMatrix[13]:-.25)+.002:h[1]-h[4]+.002;for(let[p,v,_,S,y]of c){let w=-1/0;for(let[C,b,A,R,,E]of l)y>=E-.08&&Math.abs(p-C)<=A&&Math.abs(v-b)<=R&&E+.002>w&&(w=E+.002);o&&(w=Math.max(w,p>=.04&&p<=.36&&v>=-.34&&v<=-.04&&y>=.01?.036:Math.hypot(p,v)<=.66&&y>=-.06?.003:-.477)),isFinite(w)||(w=d);let g=a.find(C=>Math.hypot(p-C[0],v-C[1])<.06&&Math.abs(w-C[5])<.05);g?(g[2]=Math.max(g[2],_*.78),g[3]=Math.max(g[3],S*.78),g[4]=Math.min(g[4],y)):a.push([p,v,_,S,y,w])}if(a.length===0){let p=Math.max(.1,h[3]*1.5)/1.45;a.push([h[0],h[2],p,p,d,d])}t.useProgram(i.prog),t.uniformMatrix4fv(i.uMVP,!1,n),t.enable(3042),(t.blendFuncSeparate||t.blendFunc).call(t,770,771,1,771),t.depthMask(!1),t.bindVertexArray(i.vao),t.bindBuffer(34962,i.vbo);for(let[p,v,_,S,y,w]of a){let g=Math.max(0,y-w),C=r/(1+g*2);if(C<.02)continue;let b=1+Math.min(.75,g*.85),A=Math.max(.045,_*1.45*b),R=Math.max(.045,S*1.45*b);ui.set([p-A,w,v-R,0,0,p+A,w,v-R,1,0,p+A,w,v+R,1,1,p-A,w,v+R,0,1]),t.bufferSubData(34962,0,ui),t.uniform1f(i.uIntensity,C),t.uniform1f(i.uSoftness,Math.min(1,e.shadowSoftness+Math.min(.45,g*.6))),t.drawElements(4,6,5123,0)}t.bindVertexArray(null),t.depthMask(!0),t.disable(3042)},onDestroy(t){let e=Rn.get(t);e&&(t.deleteVertexArray(e.vao),t.deleteBuffer(e.vbo),t.deleteBuffer(e.ibo),t.deleteProgram(e.prog),Rn.delete(t))}};var li=new WeakMap,ar={name:"webxr-suite",onConfigureXRSessionInit(t,e){let n=new Set(e.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=t?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),e.domOverlay={root:r},r.addEventListener?.("beforexrselect",i=>{i.preventDefault()})),e.optionalFeatures=Array.from(n)},onXRFrame(t,e,n,r){if(!t||!e||!n||!r)return;let i=li.get(e);if(i||(i={lightProbe:null},li.set(e,i),typeof e.requestLightProbe=="function"&&e.requestLightProbe().then(o=>{i&&o&&(i.lightProbe=o)}).catch(()=>{})),i.lightProbe&&typeof n.getLightEstimate=="function"){let o=n.getLightEstimate(i.lightProbe);if(o){let c=o.primaryLightDirection,l=o.primaryLightIntensity;if(c&&l&&Array.isArray(t.lights)){let a=t.lights.find(u=>u.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(a)),a.direction=[c.x,c.y,c.z];let s=Math.max(l.x,l.y,l.z,.001);a.color=[l.x/s,l.y/s,l.z/s],a.intensity=s}o.sphericalHarmonicsCoefficients&&t.gl&&yn(t.gl,o.sphericalHarmonicsCoefficients)}}}};ye(Et);ye(Jn);ye(jn);ye(ir);ye(ar);ye(nr);function ur(){if(typeof window>"u"||typeof navigator>"u")return!1;let t=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(t)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function lr(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function mr(){if(typeof navigator>"u")return!1;let t=navigator;if(!t.xr||typeof t.xr.isSessionSupported!="function")return!1;try{return await t.xr.isSessionSupported("immersive-ar")?!0:await t.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function di(){return(await Sn()).bestMode}async function Sn(){let[t,e,n]=await Promise.all([mr(),Promise.resolve(ur()),Promise.resolve(lr())]),r=[];e&&r.push("quick-look"),t&&r.push("webxr"),n&&r.push("scene-viewer");let i=null;return e?i="quick-look":t?i="webxr":n&&(i="scene-viewer"),{webxr:t,quickLook:e,sceneViewer:n,availableModes:r,bestMode:i}}function mi(t,e={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,r=!1;if(typeof t=="string"){if(n=ao(t),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(t),r=!0;let i=[];if(e.allowScale===!1&&i.push("allowsContentScaling=0"),e.canonicalWebPageUrl){let l=Tn(e.canonicalWebPageUrl,!1);l&&i.push(`canonicalWebPageURL=${encodeURIComponent(l)}`)}e.checkoutTitle&&i.push(`checkoutTitle=${encodeURIComponent(e.checkoutTitle)}`),e.checkoutSubtitle&&i.push(`checkoutSubtitle=${encodeURIComponent(e.checkoutSubtitle)}`),e.price&&i.push(`price=${encodeURIComponent(e.price)}`),i.length>0&&(n+=`#${i.join("&")}`);let o=document.createElement("a");o.setAttribute("rel","ar"),o.setAttribute("href",n);let c=document.createElement("img");c.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),c.style.display="none",o.appendChild(c),document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),r&&URL.revokeObjectURL(n.split("#")[0])},3e3)}function Tn(t,e=!1){if(typeof t!="string")return"";let n=t.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!n)return"";if(/^[\\/]{2}/.test(n))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${n.slice(0,32)}`);let r=n.toLowerCase();if(r.startsWith("https://")||r.startsWith("http://")||e&&r.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(n))return n;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${n.slice(0,32)}`)}function ao(t){try{return Tn(t,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(t||"").trim().slice(0,32)}`)}}function co(t,e={}){let n=Tn(t,!0),r=e.mode||"ar_preferred",i=new URLSearchParams({file:n,mode:r,resizable:e.resizable!==!1?"true":"false",enable_vertical_placement:e.enableVerticalPlacement?"true":"false"});return e.title&&i.set("title",e.title),e.link&&i.set("link",Tn(e.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${i.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function uo(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=co(t,e);window.location.href=n}var We=null;function lo(t,e){let r=new Float32Array(144),i=new Float32Array(24*6),o=new Float32Array(24*4),c=new Uint16Array(24*6);for(let m=0;m<24;m++){let h=m/24*Math.PI*2,f=Math.cos(h),d=Math.sin(h),p=m*2,v=p+1,_=(m+1)%24*2;r[p*3]=f*.11,r[p*3+1]=.002,r[p*3+2]=d*.11,r[v*3]=f*.145,r[v*3+1]=.002,r[v*3+2]=d*.145,i[p*3+1]=i[v*3+1]=1,c.set([p,_,v,v,_,_+1],m*6)}let l=t.createVertexArray();t.bindVertexArray(l);let a=(m,h,f)=>{let d=t.createBuffer();return t.bindBuffer(34962,d),t.bufferData(34962,m,35044),t.enableVertexAttribArray(h),t.vertexAttribPointer(h,f,5126,!1,0,0),d},s=[a(r,0,3),a(i,1,3),a(o,2,2)],u=t.createBuffer();return s.push(u),t.bindBuffer(34963,u),t.bufferData(34963,c,35044),t.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:c.length,indexType:5123,baseColor:e&&e.length>=3?[e[0],e[1],e[2],e[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:c,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:s}]}}function hi(t,e,n,r,i){let o=Math.cos(r),c=Math.sin(r),l=Math.max(.01,i);t.fill(0),t[0]=l*o,t[2]=-l*c,t[5]=l,t[8]=l*c,t[10]=l*o,t[12]=e[0]-l*(o*n[0]+c*n[2]),t[13]=e[1]-l*n[1],t[14]=e[2]-l*(-c*n[0]+o*n[2]),t[15]=1}var cr=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,n){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");We&&We!==this&&We.isSessionActive()&&await We.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||e?.container,c=String(o?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,a=Number(l?.radius)||1,s=Array.isArray(l?.center)?l.center:[0,0,0],u=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],m=typeof navigator<"u"&&navigator.userAgent||"",h=/Android|iPhone|iPad|iPod/i.test(m)&&!/Quest|Oculus|Pico|Vision/i.test(m),f=c?i.arScale==="fixed"?1:h?.55:1:i.arScale==="fixed"?1:a>.45?.3/a:a<.05?.12/Math.max(a,.001):1,d=c?[0,-.25,0]:[s[0]||0,i.arPlacement==="wall"?s[1]:u[1]??0,s[2]||0],p="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(p="immersive-vr")}catch{p="immersive-vr"}let v=o?.querySelector?.('[slot="ar-overlay"]')||null,_=!1,S=null,y=()=>{_&&v?.parentNode&&v.parentNode.removeChild(v),v=null,S=null,_=!1};if(p==="immersive-ar"){if(v)v.addEventListener?.("beforexrselect",x=>x.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let x=document.createElement("div");x.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 D=document.createElement("button");D.type="button",D.textContent="\u2715 Exit AR",D.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",D.addEventListener("beforexrselect",k=>k.preventDefault()),D.addEventListener("click",k=>{k.stopPropagation(),this.stop().catch(()=>{})}),S=document.createElement("div"),S.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",S.textContent="Move phone to detect a surface \u2022 Tap to place",x.appendChild(D),x.appendChild(S),document.body.appendChild(x),v=x,_=!0}}let w=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),g={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(w)};v&&(w.add("dom-overlay"),g.optionalFeatures=Array.from(w),g.domOverlay={root:v});for(let x of ce)x.onConfigureXRSessionInit?.(o,g);Array.isArray(g.optionalFeatures)&&g.optionalFeatures.includes("dom-overlay")&&!g.domOverlay?.root&&(g.optionalFeatures=g.optionalFeatures.filter(x=>x!=="dom-overlay"));let C=x=>{let D=String(x?.name||"");return D==="NotAllowedError"||D==="SecurityError"};try{this.s=await r.requestSession(p,g)}catch(x){if(y(),C(x))throw i.onError?.(x),x;try{this.s=await r.requestSession(p,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(D){if(C(D))throw i.onError?.(D),D;try{this.s=await r.requestSession(p)}catch(k){throw i.onError?.(k),k}}}let b=this.s;We=this,this.placed=!1;let A=null,R=null,E=null,O=null,H=null,F=[0,-.25,-1.2],M=[0,-.25,-1.2],G=new Float32Array(16),B=!1,Q=1,j=0,z=!1,X=null,U=null,q=0,Y=null,T=()=>{We===this&&(We=null),Y?.(),Y=null;try{R?.cancel?.()}catch{}if(R=null,E){let x=e?.meshes;if(Array.isArray(x)){let k=x.indexOf(E);k!==-1&&x.splice(k,1)}let D=e.getGLContext?.()||e?.gl;if(D)for(let k of E.primitives||[]){D.deleteVertexArray?.(k.vao);for(let I of k.buffers||[])D.deleteBuffer?.(I)}E=null}e?.setXRSessionActive?.(!1),y(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=T,b.addEventListener("end",()=>{T(),i.onExit?.()}),b.addEventListener("select",()=>{if(!this.placed){let x=H||F;M=[x[0],x[1],x[2]],hi(this.placedMat,M,d,j,f*Q),this.placed=!0,E&&(E.visible=!1),S&&(S.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let x=e.getGLContext?.()||e?.gl;x&&typeof x.makeXRCompatible=="function"&&await x.makeXRCompatible();let D=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;x&&typeof D=="function"&&typeof b.updateRenderState=="function"&&b.updateRenderState({baseLayer:new D(b,x,{alpha:!0})});try{A=await b.requestReferenceSpace("local")}catch{try{A=await b.requestReferenceSpace("local-floor")}catch{A=await b.requestReferenceSpace("viewer")}}let k=await b.requestReferenceSpace("viewer").catch(()=>A);if(typeof b.requestHitTestSource=="function"&&k&&(R=await b.requestHitTestSource({space:k}).catch(()=>null)),p==="immersive-ar"&&x&&typeof x.createVertexArray=="function"&&Array.isArray(e.meshes)&&(E=lo(x,i.reticleColor),e.meshes.push(E)),typeof window<"u"&&typeof window.addEventListener=="function"){let L=$=>Math.hypot($.touches[1].clientX-$.touches[0].clientX,$.touches[1].clientY-$.touches[0].clientY),P=$=>Math.atan2($.touches[1].clientY-$.touches[0].clientY,$.touches[1].clientX-$.touches[0].clientX),N=$=>{this.s&&($.touches.length===1&&this.placed?z=!0:$.touches.length>=2&&(z=!1,X=L($),U=P($)))},K=$=>{if(!this.s||$.touches.length<2)return;let V=L($),J=P($);if(X&&X>4&&i.arScale!=="fixed"&&(Q=Math.max(.15,Math.min(6,Q*(V/X)))),U!==null){let te=J-U;te>Math.PI&&(te-=Math.PI*2),te<-Math.PI&&(te+=Math.PI*2),j-=te}X=V,U=J},Z=$=>{(!$.touches||$.touches.length===0)&&(z=!1),(!$.touches||$.touches.length<2)&&(X=null,U=null)};window.addEventListener("touchstart",N,{passive:!0}),window.addEventListener("touchmove",K,{passive:!0}),window.addEventListener("touchend",Z,{passive:!0}),window.addEventListener("touchcancel",Z,{passive:!0}),Y=()=>{window.removeEventListener("touchstart",N),window.removeEventListener("touchmove",K),window.removeEventListener("touchend",Z),window.removeEventListener("touchcancel",Z)}}e.setXRSessionActive?.(!0);let I=(L,P)=>{if(this.s!==b)return;b.requestAnimationFrame(I);let N=q>0?Math.min(Math.max((L-q)/1e3,0),.1):1/60;q=L,e?.stepXRUpdate?.(N);let K=P.getViewerPose(A);if(!K)return;let Z=K.views?.[0];if(!B&&Z?.transform){let ie=Z.transform.position,ue=Z.transform.matrix,Re=ie?.x??(ue?ue[12]:0),he=ie?.y??(ue?ue[13]:0),xe=ie?.z??(ue?ue[14]:0),Me=ue?-ue[8]:0,ne=ue?-ue[10]:-1,be=Math.hypot(Me,ne);be>1e-4?(Me/=be,ne/=be):(Me=0,ne=-1),F=[Re+Me*1.2,he-.25,xe+ne*1.2],j=Math.atan2(-Me,-ne),B=!0}if(R&&typeof P.getHitTestResults=="function"&&(!this.placed||z)){let ie=P.getHitTestResults(R)||[],ue=!1;for(let Re of ie){let he=Re.getPose(A);if(he?.transform?.matrix){let xe=he.transform.matrix,Me=xe[5];if(i.arPlacement==="wall"&&Math.abs(Me)>.35||i.arPlacement==="floor"&&Math.abs(Me)<.65)continue;O||(O=new Float32Array(16)),O.set(xe),H=[xe[12],xe[13],xe[14]],this.placed&&z&&(M=[xe[12],xe[13],xe[14]]),E&&(E.visible=!this.placed||z,E.transform.set(xe)),!this.placed&&S&&(S.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(O),ue=!0;break}}!ue&&E&&(E.visible=!1)}hi(G,this.placed?M:H||F,d,j,f*Q),this.placed&&this.placedMat.set(G),e.modelRootMatrix&&e.modelRootMatrix.set(G);for(let ie of ce)ie.onXRFrame?.(e,b,P,A);let $=e.getGLContext?.()||e?.gl,V=b.renderState?.baseLayer;$&&V&&V.framebuffer!==void 0&&$.bindFramebuffer($.FRAMEBUFFER,V.framebuffer);let J=p==="immersive-ar",te=K.views||[];for(let ie=0;ie<te.length;ie++){let ue=te[ie];if(typeof e.renderXRView=="function"){let Re;if(V&&typeof V.getViewport=="function"){let he=V.getViewport(ue);he&&he.width>0&&he.height>0&&(Re=[he.x,he.y,he.width,he.height])}else V?.framebufferWidth>0&&V?.framebufferHeight>0&&(Re=[0,0,V.framebufferWidth,V.framebufferHeight]);e.renderXRView(ue,G,this.placed,Re,J,ie)}}$&&V&&V.framebuffer&&$.bindFramebuffer($.FRAMEBUFFER,null)};b.requestAnimationFrame(I)}catch(x){throw typeof b.end=="function"&&await b.end().catch(()=>{}),T(),i.onError?.(x),x}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function En(t){let e=await Sn(),n=t.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let l of n)if(e.availableModes.includes(l)){r=l;break}if(r||(r=e.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let i={...t.quickLookOptions,allowScale:t.arScale==="fixed"?!1:t.quickLookOptions?.allowScale},o={...t.sceneViewerOptions,resizable:t.arScale==="fixed"?!1:t.sceneViewerOptions?.resizable,enableVerticalPlacement:t.arPlacement==="wall"?!0:t.sceneViewerOptions?.enableVerticalPlacement},c={...t.webXROptions,arScale:t.arScale||t.webXROptions?.arScale,arPlacement:t.arPlacement||t.webXROptions?.arPlacement};try{if(r==="quick-look"){let l;if(t.model instanceof Blob&&t.model.type==="model/vnd.usdz+zip")l=t.model;else{if(typeof t.model=="string")return mi(t.model,i),{mode:"quick-look",success:!0};l=Ke(t.model)}return mi(l,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let l=t.glbUrl||(typeof t.model=="string"?t.model:null);if(!l)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return uo(l,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!t.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let l=new cr(c);return await l.start(t.view,t.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}`)}}De.registerAR({activateAR:En,createUSDZBlob:Ke});De.registerScriptRunner(et);ye(Et);De.registerScriptRunner(et);typeof window<"u"&&(window.ThreeLiveBundle=hr);return xi(hr);})();
|