three-live 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/index.d.ts +66 -2
- package/dist/three-author-engine.js +85 -42
- package/dist/three-author.cjs +84 -42
- package/dist/three-author.d.ts +66 -2
- package/dist/three-author.js +84 -42
- package/dist/three-convert.cjs +84 -42
- package/dist/three-convert.d.ts +66 -2
- package/dist/three-convert.js +84 -42
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +66 -2
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +66 -2
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +48 -6
- package/dist/three-live-element.d.ts +66 -2
- package/dist/three-live-element.js +48 -6
- package/dist/three-live-full.cjs +176 -55
- package/dist/three-live-full.js +176 -55
- package/dist/three-live-full.min.js +176 -55
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +510 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +48 -6
- package/dist/three-live-viewer.d.ts +66 -2
- package/dist/three-live-viewer.js +48 -6
- package/dist/three-live-viewer.min.js +48 -6
- package/dist/three-live.cjs +86 -44
- package/dist/three-live.js +86 -44
- package/dist/three-live.min.js +86 -44
- package/dist/three-view.cjs +48 -6
- package/dist/three-view.d.ts +66 -2
- package/dist/three-view.js +48 -6
- package/dist/three-xr.cjs +83 -41
- package/dist/three-xr.d.ts +66 -2
- package/dist/three-xr.js +83 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
package/dist/three-live-full.cjs
CHANGED
|
@@ -14,16 +14,32 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var _n=Object.defineProperty;var pi=Object.getOwnPropertyDescriptor;var bi=Object.getOwnPropertyNames;var yi=Object.prototype.hasOwnProperty;var gi=(t,e)=>{for(var n in e)_n(t,n,{get:e[n],enumerable:!0})},xi=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of bi(e))!yi.call(t,i)&&i!==n&&_n(t,i,{get:()=>e[i],enumerable:!(r=pi(e,i))||r.enumerable});return t};var vi=t=>xi(_n({},"__esModule",{value:!0}),t);var dr={};gi(dr,{AmbientLight:()=>bt,BoxGeometry:()=>dt,BufferAttribute:()=>re,BufferGeometry:()=>we,Camera:()=>gt,CapsuleGeometry:()=>mn,CircleGeometry:()=>dn,Clock:()=>on,Color:()=>Re,ConeGeometry:()=>$t,CylinderGeometry:()=>Oe,DirectionalLight:()=>tn,DodecahedronGeometry:()=>un,Euler:()=>mt,Float32BufferAttribute:()=>Ht,Group:()=>en,HemisphereLight:()=>wt,IcosahedronGeometry:()=>an,InteractivityVM:()=>Tt,Light:()=>Xe,Material:()=>Ce,MathUtils:()=>Ur,Matrix3:()=>zt,Matrix4:()=>ze,Mesh:()=>Je,MeshBasicMaterial:()=>Kt,MeshLambertMaterial:()=>Zt,MeshPhongMaterial:()=>Jt,MeshPhysicalMaterial:()=>Qt,MeshStandardMaterial:()=>He,Object3D:()=>Te,OctahedronGeometry:()=>cn,PerspectiveCamera:()=>nn,PlaneGeometry:()=>Gt,PointLight:()=>yt,PolyhedronFallbackGeometry:()=>We,Quaternion:()=>ht,RawShaderMaterial:()=>qr,RectAreaLight:()=>Yr,RingGeometry:()=>hn,Scene:()=>xt,SceneQuotaValidator:()=>_e,ShaderMaterial:()=>vt,SphereGeometry:()=>ft,SpotLight:()=>fn,THREE:()=>At,TetrahedronGeometry:()=>ln,Texture:()=>pt,TextureLoader:()=>jt,ThreeLiveElement:()=>Pe,ThreeView:()=>fe,TorusGeometry:()=>qt,TorusKnotGeometry:()=>Yt,Uint16BufferAttribute:()=>Xt,Uint32BufferAttribute:()=>Wt,Vector2:()=>Bt,Vector3:()=>le,Vector4:()=>Vt,WebGLRenderer:()=>rn,activateAR:()=>En,authorScriptRunner:()=>tt,buildSandboxWorkerSource:()=>Vn,clearAuthorWarnings:()=>$r,contactShadowPlugin:()=>Et,createUSDZBlob:()=>Ze,crossFadeTo:()=>Wn,environmentMapPlugin:()=>Kn,exportSceneToCanvas3D:()=>Un,exportSceneToGLB:()=>On,exportSceneToUSDZ:()=>Or,generateUSDZ:()=>at,getARCapabilities:()=>Mn,getAllowClientScripts:()=>zr,getAuthorWarnings:()=>Gr,getBestARMode:()=>fi,getEnvironmentSH:()=>ti,getInteractivityVM:()=>Sn,getSandboxEngineSrc:()=>Bn,getSandboxIframeSrc:()=>Vr,glbToUSDZ:()=>st,hotspotPlugin:()=>Qn,interactivityPlugin:()=>rr,isAllowedSandboxEngineUrl:()=>Be,isQuickLookSupported:()=>lr,isSceneViewerSupported:()=>mr,isWebXRSupported:()=>hr,keyframeAnimationPlugin:()=>Gn,materialsPlugin:()=>or,morphPlugin:()=>$n,noopProxy:()=>ut,parseAnimations:()=>Xn,parseSafeGltfPointer:()=>Rt,registerMaterialShader:()=>ui,sampleChannel:()=>nt,sceneToCanvas3D:()=>je,sceneToGLB:()=>ot,sceneToUSDZ:()=>Ke,sendInteractivityEvent:()=>nr,setAllowClientScripts:()=>Vi,setEnvironmentSH:()=>gn,setMorphTargetWeight:()=>Zr,setSandboxEngineSrc:()=>Ni,setSandboxIframeSrc:()=>Oi,skinningPlugin:()=>Yn,threeAuthorPlugin:()=>lt,threeMicroPlugin:()=>ji,toGLBData:()=>ke,toTrustedWorkerScriptURL:()=>Br,validateSandboxWorkerMessage:()=>zn,warnUnsupported:()=>Ae,webxrPlugin:()=>cr});module.exports=vi(dr);function fr(t,e,n){let r=[],i=new Map,o=[],a=[],l=[],c=new Map,s=y=>{let v=i.get(y);return v===void 0&&(v=r.length,r.push({op:y}),i.set(y,v)),v},u=y=>{let v=c.get(y);return v===void 0&&(v=l.length,l.push({id:y}),c.set(y,v)),v},m=(y,v={})=>o.push({declaration:s(y),...v})-1,h=(y,v,g)=>a.push({id:y,type:v,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 v=Array.isArray(y.declarations)?y.declarations:[];for(let g of v)g?.op&&s(g.op);Array.isArray(y.variables)&&a.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 I=g.op||(typeof g.declaration=="number"?v[g.declaration]?.op:"");o.push(I?{...g,declaration:s(I)}:{...g})}}}let p=(y,v,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,v)}/${g}`:g==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${g}`,x=new Map;t.forEach((y,v)=>{typeof y?.name=="string"&&!x.has(y.name)&&x.set(y.name,v)});let P=(y,v)=>typeof y.target=="string"&&x.has(y.target)?x.get(y.target):typeof y.targetNode=="number"?y.targetNode:v,E=y=>{let v=t[y];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<t.length;y++){let v=t[y],g=v?.extras?.interactivity;if(!g||typeof g!="object")continue;let I=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,b=R=>{let _=Array.isArray(R)?R:[R],B=[];for(let D=0;D<_.length;D++){let C=_[D];if(!C||typeof C!="object")continue;let G=C.action||"interpolate",V=typeof C.duration=="number"?C.duration:.35;if(G==="toggleTransform"){let J=C.property==="rotation"||C.property==="scale"?C.property:"translation",j=J==="rotation"?v.rotation||[0,0,0,1]:J==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],H=`/nodes/${y}/${J}`,X=h(`__toggle_${y}_${D}`,"bool",!1),N=m("variable/get",{configuration:{variable:X}}),$=m("math/not",{values:{a:f(N)}}),Y=m("variable/set",{configuration:{variable:X},values:{value:f($)}}),T=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(C.to)?C.to:j},duration:{value:V}}}),A=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(C.from)?C.from:j},duration:{value:V}}});o[Y].flows={out:{node:m("flow/branch",{values:{condition:f(N)},flows:{true:{node:T},false:{node:A}}})}},B.push(Y)}else if(G==="interpolate"){let J=C.to??C.value;if(J===void 0)continue;let j={value:{value:J},duration:{value:V}};C.from!==void 0&&(j.from={value:C.from}),B.push(m("pointer/interpolate",{configuration:{pointer:typeof C.pointer=="string"?C.pointer:p(P(C,y),E(P(C,y)),C.property)},values:j}))}else if(G==="setProperty"){if(C.value===void 0)continue;B.push(m("pointer/set",{configuration:{pointer:typeof C.pointer=="string"?C.pointer:p(P(C,y),E(P(C,y)),C.property)},values:{value:{value:C.value}}}))}else if(G==="toggleVisibility"){let J=P(C,y),j=h(`__vis_${J}_${D}`,"bool",!0),H=m("variable/get",{configuration:{variable:j}}),X=m("math/not",{values:{a:f(H)}}),N=m("variable/set",{configuration:{variable:j},values:{value:f(X)}});o[N].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${J}/extensions/KHR_node_visibility/visible`},values:{value:f(H)}})}},B.push(N)}else if(G==="cycleMaterialColor"&&Array.isArray(C.colors)&&C.colors.length>0){let J=typeof C.duration=="number"?C.duration:.25,j=`/materials/${Math.max(0,I)}/pbrMetallicRoughness/baseColorFactor`,H=h(`__color_idx_${y}_${D}`,"int",0),X=m("variable/get",{configuration:{variable:H}}),N=m("math/add",{values:{a:f(X),b:{value:1}}}),$=m("math/rem",{values:{a:f(N),b:{value:C.colors.length}}}),Y=m("variable/set",{configuration:{variable:H},values:{value:f($)}}),T={};for(let A=0;A<C.colors.length;A++){let S=C.colors[A],k=Array.isArray(S)&&S.length>=3?[S[0],S[1],S[2],S[3]??1]:[1,1,1,1];T[String(A)]={node:J>0?m("pointer/interpolate",{configuration:{pointer:j},values:{value:{value:k},duration:{value:J}}}):m("pointer/set",{configuration:{pointer:j},values:{value:{value:k}}})}}o[Y].flows={out:{node:m("flow/switch",{values:{selection:f(X)},flows:T})}},B.push(Y)}else if(G==="playAnimation")B.push(m("animation/start",{configuration:{animation:C.animation??C.clip??0}}));else if(G==="stopAnimation")B.push(m("animation/stop"));else if(G==="sendEvent"){let J={};for(let[j,H]of Object.entries(C.values||{}))J[j]={value:H};B.push(m("event/send",{configuration:{event:u(String(C.event??C.id??"custom"))},values:J}))}}if(!B.length)return null;if(B.length===1)return B[0];let z={};return B.forEach((D,C)=>{z[String(C)]={node:D}}),m("flow/sequence",{flows:z})},w=(R,_,B)=>{let z=b(_);z!==null&&m(R,{...B?{configuration:B}:{},flows:{out:{node:z}}})};if(g.onSelect&&w("pointer/onSelect",g.onSelect,{nodeIndex:y}),g.onHoverIn&&w("pointer/onHoverIn",g.onHoverIn,{nodeIndex:y}),g.onHoverOut&&w("pointer/onHoverOut",g.onHoverOut,{nodeIndex:y}),g.onStart&&w("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[R,_]of Object.entries(g.onReceive))w("event/receive",_,{event:u(R)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:a,events:l}],graph:0}:null}var Pt='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).',It="Security Error: client-side scripts require allow-client-scripts opt-in.";var Lt="__THREE_LIVE_REGISTRY__";function ie(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Lt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Lt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Lt]=e}}return t[Lt]}var ue=ie().plugins;function ge(t){let e=ie().plugins;e.some(n=>n.name===t.name)||e.push(t)}function Dt(){return ie().plugins}function se(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Ft(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 a=1/(r-i);return t[10]=(i+r)*a,t[14]=2*i*r*a,t}function qe(t,e,n,r){let[i,o,a]=e,[l,c,s]=r,[u,m,h]=n,f=i-u,d=o-m,p=a-h,x=Math.hypot(f,d,p);x<=1e-5?(f=0,d=0,p=1):(f/=x,d/=x,p/=x);let P=c*p-s*d,E=s*f-l*p,y=l*d-c*f;x=Math.hypot(P,E,y),x<=1e-5?(P=0,E=0,y=0):(P/=x,E/=x,y/=x);let v=d*y-p*E,g=p*P-f*y,I=f*E-d*P;return x=Math.hypot(v,g,I),x<=1e-5?(v=0,g=0,I=0):(v/=x,g/=x,I/=x),t[0]=P,t[1]=v,t[2]=f,t[3]=0,t[4]=E,t[5]=g,t[6]=d,t[7]=0,t[8]=y,t[9]=I,t[10]=p,t[11]=0,t[12]=-(P*i+E*o+y*a),t[13]=-(v*i+g*o+I*a),t[14]=-(f*i+d*o+p*a),t[15]=1,t}function be(t,e,n){let r=e[0],i=e[1],o=e[2],a=e[3],l=e[4],c=e[5],s=e[6],u=e[7],m=e[8],h=e[9],f=e[10],d=e[11],p=e[12],x=e[13],P=e[14],E=e[15],y=n[0],v=n[1],g=n[2],I=n[3];return t[0]=y*r+v*l+g*m+I*p,t[1]=y*i+v*c+g*h+I*x,t[2]=y*o+v*s+g*f+I*P,t[3]=y*a+v*u+g*d+I*E,y=n[4],v=n[5],g=n[6],I=n[7],t[4]=y*r+v*l+g*m+I*p,t[5]=y*i+v*c+g*h+I*x,t[6]=y*o+v*s+g*f+I*P,t[7]=y*a+v*u+g*d+I*E,y=n[8],v=n[9],g=n[10],I=n[11],t[8]=y*r+v*l+g*m+I*p,t[9]=y*i+v*c+g*h+I*x,t[10]=y*o+v*s+g*f+I*P,t[11]=y*a+v*u+g*d+I*E,y=n[12],v=n[13],g=n[14],I=n[15],t[12]=y*r+v*l+g*m+I*p,t[13]=y*i+v*c+g*h+I*x,t[14]=y*o+v*s+g*f+I*P,t[15]=y*a+v*u+g*d+I*E,t}function Ye(t,e,n,r){let i=e[0],o=e[1],a=e[2],l=e[3],c=i+i,s=o+o,u=a+a,m=i*c,h=i*s,f=i*u,d=o*s,p=o*u,x=a*u,P=l*c,E=l*s,y=l*u,v=r[0],g=r[1],I=r[2];return t[0]=(1-(d+x))*v,t[1]=(h+y)*v,t[2]=(f-E)*v,t[3]=0,t[4]=(h-y)*g,t[5]=(1-(m+x))*g,t[6]=(p+P)*g,t[7]=0,t[8]=(f+E)*I,t[9]=(p-P)*I,t[10]=(1-(m+d))*I,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],a=e[5],l=e[6],c=e[8],s=e[9],u=e[10],m=u*a-l*s,h=-u*o+l*c,f=s*o-a*c,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*a)*d,t[3]=h*d,t[4]=(u*n-i*c)*d,t[5]=(-l*n+i*o)*d,t[6]=f*d,t[7]=(-s*n+r*c)*d,t[8]=(a*n-r*o)*d),t}function kt(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],a=e[4],l=e[5],c=e[6],s=e[7],u=e[8],m=e[9],h=e[10],f=e[11],d=e[12],p=e[13],x=e[14],P=e[15],E=n*l-r*a,y=n*c-i*a,v=n*s-o*a,g=r*c-i*l,I=r*s-o*l,b=i*s-o*c,w=u*p-m*d,R=u*x-h*d,_=u*P-f*d,B=m*x-h*p,z=m*P-f*p,D=h*P-f*x,C=E*D-y*z+v*B+g*_-I*R+b*w;return C?(C=1/C,t[0]=(l*D-c*z+s*B)*C,t[1]=(i*z-r*D-o*B)*C,t[2]=(p*b-x*I+P*g)*C,t[3]=(h*I-m*b-f*g)*C,t[4]=(c*_-a*D-s*R)*C,t[5]=(n*D-i*_+o*R)*C,t[6]=(x*v-d*b-P*y)*C,t[7]=(u*b-h*v+f*y)*C,t[8]=(a*z-l*_+s*w)*C,t[9]=(r*_-n*z-o*w)*C,t[10]=(d*I-p*v+P*E)*C,t[11]=(m*v-u*I-f*E)*C,t[12]=(l*R-a*B-c*w)*C,t[13]=(n*B-r*R+i*w)*C,t[14]=(p*y-d*g-x*E)*C,t[15]=(u*g-m*y+h*E)*C,t):null}function Cn(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],a=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],c=i[3]*e+i[7]*n+i[11]*r+i[15],s=c!==0?1/c:1;t[0]=o*s,t[1]=a*s,t[2]=l*s}function pr(t,e,n,r,i,o,a,l,c,s,u,m,h,f,d,p,x=0){let P=s-a,E=u-l,y=m-c,v=h-a,g=f-l,I=d-c,b=i*I-o*g,w=o*v-r*I,R=r*g-i*v,_=P*b+E*w+y*R;if(_>-1e-7&&_<1e-7)return!1;let B=1/_,z=t-a,D=e-l,C=n-c,G=B*(z*b+D*w+C*R);if(G<-x||G>1+x)return!1;let V=D*y-C*E,J=C*P-z*y,j=z*E-D*P,H=B*(r*V+i*J+o*j);if(H<-x||G+H>1+x)return!1;let X=B*(v*V+g*J+I*j);if(X>1e-4&&X<p.distance){p.distance=X,p.point=[t+r*X,e+i*X,n+o*X];let N=E*I-y*g,$=y*v-P*I,Y=P*g-E*v,T=Math.hypot(N,$,Y)||1;return p.normal=[N/T,$/T,Y/T],!0}return!1}function Fe(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(se());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,a=128,l=(u,m,h=0)=>{if(h>a||u<0||u>=n||o.has(u))return;o.add(u);let f=t.nodes[u];if(!f)return;let d=se();if(e&&e[u])d.set(e[u]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let x=f.translation||[0,0,0],P=f.rotation||[0,0,0,1],E=f.scale||[1,1,1];Ye(d,P,x,E)}let p=r[u];if(m?be(p,m,d):p.set(d),Array.isArray(f.children))for(let x of f.children)typeof x=="number"&&l(x,p,h+1)},c=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))c.push(...s.nodes);else for(let u=0;u<n;u++)i.has(u)||c.push(u);for(let u of c)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!c.includes(u)&&l(u,null);return r}function wi(t){return new TextDecoder().decode(t)}var xr=ie().decoders;function Ai(t,e){xr.set(t.toLowerCase(),e)}function it(t){return xr.get(t.toLowerCase())}function vr(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),a=12,l=null,c=null;for(;a+8<=o&&a+8<=e.byteLength;){let h=n.getUint32(a,!0),f=n.getUint32(a+4,!0),d=a+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),x=wi(p);l=JSON.parse(x,(P,E)=>P==="__proto__"||P==="constructor"||P==="prototype"?void 0:E)}else f===5130562&&(c=e.slice(d,d+h));a=d+h}if(!l)throw new Error("Missing JSON chunk in GLB");let s=l.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!it("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!it("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!it("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=c||new ArrayBuffer(0),m={gltf:l,bin:u,animations:[]};for(let h of ue)h.onParseGLB?.(m);return m}function Si(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 ke(t){if(Si(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return vr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var wr=`#version 300 es
|
|
17
|
+
"use strict";var Or=Object.defineProperty;var Ws=Object.getOwnPropertyDescriptor;var $s=Object.getOwnPropertyNames;var qs=Object.prototype.hasOwnProperty;var Ys=(e,t)=>{for(var n in t)Or(e,n,{get:t[n],enumerable:!0})},js=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $s(t))!qs.call(e,i)&&i!==n&&Or(e,i,{get:()=>t[i],enumerable:!(r=Ws(t,i))||r.enumerable});return e};var Ks=e=>js(Or({},"__esModule",{value:!0}),e);var $i={};Ys($i,{AmbientLight:()=>gn,BoxGeometry:()=>hn,BufferAttribute:()=>we,BufferGeometry:()=>je,Camera:()=>vn,CapsuleGeometry:()=>yr,CircleGeometry:()=>xr,Clock:()=>mr,Color:()=>Je,ConeGeometry:()=>Jn,CylinderGeometry:()=>St,DirectionalLight:()=>cr,DodecahedronGeometry:()=>pr,Euler:()=>mn,Float32BufferAttribute:()=>jn,Group:()=>ar,HemisphereLight:()=>wn,IKSolver:()=>ho,IcosahedronGeometry:()=>hr,InstancedMesh:()=>yn,InteractivityVM:()=>_n,Light:()=>Pt,MAX_BSP_DEPTH:()=>ao,MAX_CSG_TRIANGLES:()=>so,MAX_INSTANCES_PER_MESH:()=>bn,MAX_SHAPE_POINTS:()=>uo,MAX_TEXT_GEOMETRY_CHARS:()=>co,Material:()=>st,MathUtils:()=>Xo,Matrix3:()=>Yn,Matrix4:()=>It,Mesh:()=>Lt,MeshBasicMaterial:()=>rr,MeshLambertMaterial:()=>ir,MeshPhongMaterial:()=>or,MeshPhysicalMaterial:()=>sr,MeshStandardMaterial:()=>Ct,Object3D:()=>et,OctahedronGeometry:()=>dr,PerspectiveCamera:()=>ur,PlaneGeometry:()=>Qn,PointLight:()=>xn,PolyhedronFallbackGeometry:()=>Dt,Quaternion:()=>fn,RawShaderMaterial:()=>ts,RectAreaLight:()=>ns,RingGeometry:()=>gr,Scene:()=>Tn,SceneQuotaValidator:()=>ot,ShaderMaterial:()=>An,SphereGeometry:()=>dn,SpotLight:()=>vr,THREE:()=>Nt,TetrahedronGeometry:()=>br,Texture:()=>pn,TextureLoader:()=>nr,ThreeLiveElement:()=>at,ThreeView:()=>He,TorusGeometry:()=>er,TorusKnotGeometry:()=>tr,Uint16BufferAttribute:()=>Kn,Uint32BufferAttribute:()=>Zn,Vector2:()=>$n,Vector3:()=>ke,Vector4:()=>qn,WebGLRenderer:()=>lr,activateAR:()=>Sr,applyMeshoptFilter:()=>Ui,authorScriptRunner:()=>Qt,buildSandboxWorkerSource:()=>ui,cadPlugin:()=>Vr,clearAuthorWarnings:()=>es,computeOutlineClipOffset:()=>Vs,contactShadowPlugin:()=>En,createUSDZBlob:()=>jt,crossFadeTo:()=>pi,decodeMeshoptBuffer:()=>Oi,decodeMeshoptGLB:()=>Nr,encodeMeshoptBuffer:()=>Ns,environmentMapPlugin:()=>_i,evaluateKawaseBloom:()=>Os,evaluateToneMapping:()=>So,exportSceneToCanvas3D:()=>si,exportSceneToGLB:()=>ai,exportSceneToUSDZ:()=>$o,extractMaterialVariants:()=>Hi,extractPrimitiveVariantMappings:()=>Bs,generateUSDZ:()=>an,getARCapabilities:()=>Mr,getAllowClientScripts:()=>jo,getAuthorWarnings:()=>Jo,getBestARMode:()=>ls,getEnvironmentSH:()=>hs,getInteractivityVM:()=>Lr,getSandboxEngineSrc:()=>ci,getSandboxIframeSrc:()=>Yo,glbToUSDZ:()=>sn,hotspotPlugin:()=>Li,ikPlugin:()=>jr,installCadExtension:()=>Fn,interactivityPlugin:()=>ki,isAllowedSandboxEngineUrl:()=>Et,isQuickLookSupported:()=>wi,isSceneViewerSupported:()=>Mi,isWebXRSupported:()=>Si,keyframeAnimationPlugin:()=>bi,materialsPlugin:()=>Fi,meshoptDecoder:()=>kr,meshoptPlugin:()=>Vi,morphPlugin:()=>yi,noopProxy:()=>un,parseAnimations:()=>di,parseHexRgb:()=>zi,parseSafeGltfPointer:()=>Rn,postprocessingPlugin:()=>Gi,quatFromUnitVectors:()=>Vn,registerMaterialShader:()=>Ts,sampleChannel:()=>en,sceneToCanvas3D:()=>qt,sceneToGLB:()=>on,sceneToUSDZ:()=>Yt,selectMaterialVariant:()=>zs,sendInteractivityEvent:()=>Ni,setAllowClientScripts:()=>Da,setEnvironmentSH:()=>Er,setMorphTargetWeight:()=>ss,setSandboxEngineSrc:()=>Ia,setSandboxIframeSrc:()=>La,skinningPlugin:()=>xi,solveFABRIK:()=>qr,solveTwoBoneIK:()=>$r,threeAuthorPlugin:()=>ln,threeMicroPlugin:()=>Ga,toGLBData:()=>ht,toTrustedWorkerScriptURL:()=>qo,validateSandboxWorkerMessage:()=>li,variantsPlugin:()=>Xi,warnUnsupported:()=>Ke,webxrPlugin:()=>Wi});module.exports=Ks($i);function oo(e,t,n){let r=[],i=new Map,o=[],a=[],u=[],s=new Map,c=b=>{let A=i.get(b);return A===void 0&&(A=r.length,r.push({op:b}),i.set(b,A)),A},l=b=>{let A=s.get(b);return A===void 0&&(A=u.length,u.push({id:b}),s.set(b,A)),A},f=(b,A={})=>o.push({declaration:c(b),...A})-1,m=(b,A,w)=>a.push({id:b,type:A,value:w})-1,h=b=>({node:b,socket:"value"}),p=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let b=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(b&&Array.isArray(b.nodes)){let A=Array.isArray(b.declarations)?b.declarations:[];for(let w of A)w?.op&&c(w.op);Array.isArray(b.variables)&&a.push(...b.variables);for(let w of b.events||[])w?.id&&l(w.id);for(let w of b.nodes){if(!w||typeof w!="object")continue;let P=w.op||(typeof w.declaration=="number"?A[w.declaration]?.op:"");o.push(P?{...w,declaration:c(P)}:{...w})}}}let d=(b,A,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,A)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,A)}/${w}`:w==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${w}`,y=new Map;e.forEach((b,A)=>{typeof b?.name=="string"&&!y.has(b.name)&&y.set(b.name,A)});let T=(b,A)=>typeof b.target=="string"&&y.has(b.target)?y.get(b.target):typeof b.targetNode=="number"?b.targetNode:A,S=b=>{let A=e[b];return(typeof A?.mesh=="number"?t[A.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<e.length;b++){let A=e[b],w=A?.extras?.interactivity;if(!w||typeof w!="object")continue;let P=(typeof A.mesh=="number"?t[A.mesh]?.primitives?.[0]?.material:0)??0,N=_=>{let v=Array.isArray(_)?_:[_],g=[];for(let k=0;k<v.length;k++){let R=v[k];if(!R||typeof R!="object")continue;let B=R.action||"interpolate",Z=typeof R.duration=="number"?R.duration:.35;if(B==="toggleTransform"){let j=R.property==="rotation"||R.property==="scale"?R.property:"translation",ie=j==="rotation"?A.rotation||[0,0,0,1]:j==="scale"?A.scale||[1,1,1]:A.translation||[0,0,0],ee=`/nodes/${b}/${j}`,ne=m(`__toggle_${b}_${k}`,"bool",!1),X=f("variable/get",{configuration:{variable:ne}}),ae=f("math/not",{values:{a:h(X)}}),se=f("variable/set",{configuration:{variable:ne},values:{value:h(ae)}}),F=f("pointer/interpolate",{configuration:{pointer:ee},values:{value:{value:Array.isArray(R.to)?R.to:ie},duration:{value:Z}}}),H=f("pointer/interpolate",{configuration:{pointer:ee},values:{value:{value:Array.isArray(R.from)?R.from:ie},duration:{value:Z}}});o[se].flows={out:{node:f("flow/branch",{values:{condition:h(X)},flows:{true:{node:F},false:{node:H}}})}},g.push(se)}else if(B==="interpolate"){let j=R.to??R.value;if(j===void 0)continue;let ie={value:{value:j},duration:{value:Z}};R.from!==void 0&&(ie.from={value:R.from}),g.push(f("pointer/interpolate",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:d(T(R,b),S(T(R,b)),R.property)},values:ie}))}else if(B==="setProperty"){if(R.value===void 0)continue;g.push(f("pointer/set",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:d(T(R,b),S(T(R,b)),R.property)},values:{value:{value:R.value}}}))}else if(B==="toggleVisibility"){let j=T(R,b),ie=m(`__vis_${j}_${k}`,"bool",!0),ee=f("variable/get",{configuration:{variable:ie}}),ne=f("math/not",{values:{a:h(ee)}}),X=f("variable/set",{configuration:{variable:ie},values:{value:h(ne)}});o[X].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${j}/extensions/KHR_node_visibility/visible`},values:{value:h(ee)}})}},g.push(X)}else if(B==="cycleMaterialColor"&&Array.isArray(R.colors)&&R.colors.length>0){let j=typeof R.duration=="number"?R.duration:.25,ie=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,ee=m(`__color_idx_${b}_${k}`,"int",0),ne=f("variable/get",{configuration:{variable:ee}}),X=f("math/add",{values:{a:h(ne),b:{value:1}}}),ae=f("math/rem",{values:{a:h(X),b:{value:R.colors.length}}}),se=f("variable/set",{configuration:{variable:ee},values:{value:h(ae)}}),F={};for(let H=0;H<R.colors.length;H++){let E=R.colors[H],V=Array.isArray(E)&&E.length>=3?[E[0],E[1],E[2],E[3]??1]:[1,1,1,1];F[String(H)]={node:j>0?f("pointer/interpolate",{configuration:{pointer:ie},values:{value:{value:V},duration:{value:j}}}):f("pointer/set",{configuration:{pointer:ie},values:{value:{value:V}}})}}o[se].flows={out:{node:f("flow/switch",{values:{selection:h(ne)},flows:F})}},g.push(se)}else if(B==="playAnimation")g.push(f("animation/start",{configuration:{animation:R.animation??R.clip??0}}));else if(B==="stopAnimation")g.push(f("animation/stop"));else if(B==="sendEvent"){let j={};for(let[ie,ee]of Object.entries(R.values||{}))j[ie]={value:ee};g.push(f("event/send",{configuration:{event:l(String(R.event??R.id??"custom"))},values:j}))}}if(!g.length)return null;if(g.length===1)return g[0];let M={};return g.forEach((k,R)=>{M[String(R)]={node:k}}),f("flow/sequence",{flows:M})},I=(_,v,g)=>{let M=N(v);M!==null&&f(_,{...g?{configuration:g}:{},flows:{out:{node:M}}})};if(w.onSelect&&I("pointer/onSelect",w.onSelect,{nodeIndex:b}),w.onHoverIn&&I("pointer/onHoverIn",w.onHoverIn,{nodeIndex:b}),w.onHoverOut&&I("pointer/onHoverOut",w.onHoverOut,{nodeIndex:b}),w.onStart&&I("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[_,v]of Object.entries(w.onReceive))I("event/receive",v,{event:l(_)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:a,events:u}],graph:0}:null}var Ln='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).',Pn="Security Error: client-side scripts require allow-client-scripts opt-in.";var Dn="__THREE_LIVE_REGISTRY__";function ge(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Dn]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Dn,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Dn]=t}}return e[Dn]}var Ne=ge().plugins;function Nn(e){let t=ge();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function Fe(e){let t=ge().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function kn(){return ge().plugins}var so=8192,ao=2048,co=128,uo=4096;function Fn(e,t){if(!e||!e.BufferGeometry)return null;let n=e.Vector2,r=e.Vector3,i=e.Quaternion,o=e.Matrix4,a=e.Matrix3,u=e.Color,s=e.BufferAttribute,c=e.BufferGeometry,l=e.Material,f=e.MeshStandardMaterial,m=e.Mesh,h=8192,p=2048,d=128,y=4096,T=(D,x)=>{let C=D==null?NaN:Number(D);return Number.isFinite(C)?C:x};class S{constructor(x){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(x)&&x.length>0&&this.fromPoints(x)}fromPoints(x){if(!x.length)return this;this.moveTo(x[0].x,x[0].y);for(let C=1;C<x.length;C++)this.lineTo(x[C].x,x[C].y);return this}moveTo(x,C){let L=Number(x)||0,z=Number(C)||0;return this.currentPoint.set(L,z),this.segments.push({type:"move",pts:[L,z]}),this}lineTo(x,C){let L=Number(x)||0,z=Number(C)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(L,z),this.segments.push({type:"line",pts:[L,z]}),this}quadraticCurveTo(x,C,L,z){let W=this.currentPoint.x,$=this.currentPoint.y,Y=Number(x)||0,Q=Number(C)||0,q=Number(L)||0,J=Number(z)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[W,$]}),this.currentPoint.set(q,J),this.segments.push({type:"quad",pts:[W,$,Y,Q,q,J]}),this}bezierCurveTo(x,C,L,z,W,$){let Y=this.currentPoint.x,Q=this.currentPoint.y,q=Number(x)||0,J=Number(C)||0,oe=Number(L)||0,te=Number(z)||0,me=Number(W)||0,fe=Number($)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[Y,Q]}),this.currentPoint.set(me,fe),this.segments.push({type:"cubic",pts:[Y,Q,q,J,oe,te,me,fe]}),this}absarc(x,C,L,z,W,$=!1){return this.absellipse(x,C,L,L,z,W,$,0)}arc(x,C,L,z,W,$=!1){return this.absarc(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(C)||0),L,z,W,$)}absellipse(x,C,L,z,W,$,Y=!1,Q=0){let q=Number(x)||0,J=Number(C)||0,oe=Math.max(0,Number(L)||0),te=Math.max(0,Number(z)||0),me=Number(W)||0,fe=Number($)||0,he=Y?1:0,de=Number(Q)||0;this.segments.push({type:"arc",pts:[q,J,oe,te,me,fe,he,de]});let ce=Math.cos(de),pe=Math.sin(de),ve=oe*Math.cos(fe),be=te*Math.sin(fe);return this.currentPoint.set(q+ve*ce-be*pe,J+ve*pe+be*ce),this}ellipse(x,C,L,z,W,$,Y=!1,Q=0){return this.absellipse(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(C)||0),L,z,W,$,Y,Q)}closePath(){if(this.segments.length>0){let x=this.segments[0],C=0,L=0;if(x.type==="arc"){let z=x.pts[0],W=x.pts[1],$=x.pts[2],Y=x.pts[3],Q=x.pts[4],q=x.pts[7],J=Math.cos(q),oe=Math.sin(q),te=$*Math.cos(Q),me=Y*Math.sin(Q);C=z+te*J-me*oe,L=W+te*oe+me*J}else C=x.pts[0],L=x.pts[1];Math.hypot(this.currentPoint.x-C,this.currentPoint.y-L)>1e-6&&this.lineTo(C,L)}return this}getPoints(x=12){let C=Math.max(1,Math.min(128,Math.floor(Number(x)||12))),L=[],z=(W,$)=>{if(L.length>0){let Y=L[L.length-1];if(Math.hypot(Y.x-W,Y.y-$)<1e-6)return}L.push(new n(W,$))};for(let W of this.segments){let $=W.pts;if(W.type==="move"||W.type==="line")z($[0],$[1]);else if(W.type==="quad"){let Y=$[0],Q=$[1],q=$[2],J=$[3],oe=$[4],te=$[5];z(Y,Q);for(let me=1;me<=C;me++){let fe=me/C,he=1-fe;z(he*he*Y+2*he*fe*q+fe*fe*oe,he*he*Q+2*he*fe*J+fe*fe*te)}}else if(W.type==="cubic"){let Y=$[0],Q=$[1],q=$[2],J=$[3],oe=$[4],te=$[5],me=$[6],fe=$[7];z(Y,Q);for(let he=1;he<=C;he++){let de=he/C,ce=1-de,pe=ce*ce,ve=de*de;z(pe*ce*Y+3*pe*de*q+3*ce*ve*oe+ve*de*me,pe*ce*Q+3*pe*de*J+3*ce*ve*te+ve*de*fe)}}else if(W.type==="arc"){let Y=$[0],Q=$[1],q=$[2],J=$[3],oe=$[4],te=$[5],me=$[6]!==0,fe=$[7],he=Math.PI*2,de=te-oe,ce=Math.abs(de)<1e-9;for(;de<0;)de+=he;for(;de>he;)de-=he;de<1e-9&&(de=ce?0:he),me&&!ce&&(de=de===he?-he:de-he);let pe=Math.cos(fe),ve=Math.sin(fe),be=Math.max(2,C);for(let Ce=0;Ce<=be;Ce++){let Se=Ce/be,Ue=oe+Se*de,_e=q*Math.cos(Ue),Le=J*Math.sin(Ue);z(Y+_e*pe-Le*ve,Q+_e*ve+Le*pe)}}}if(L.length>2){let W=L[0],$=L[L.length-1];Math.hypot(W.x-$.x,W.y-$.y)<1e-6&&L.pop()}return L}getSpacedPoints(x=12){return this.getPoints(x)}}class b extends S{constructor(x){super(x),this.holes=[]}extractPoints(x=12){return{shape:this.getPoints(x),holes:this.holes.map(C=>C.getPoints(x))}}}function A(D){let x=0,C=D.length;for(let L=0,z=C-1;L<C;z=L++)x+=D[z].x*D[L].y-D[L].x*D[z].y;return x*.5}function w(D,x,C,L,z,W,$,Y){let Q=$-C,q=Y-L,J=z-C,oe=W-L,te=D-C,me=x-L,fe=Q*Q+q*q,he=Q*J+q*oe,de=Q*te+q*me,ce=J*J+oe*oe,pe=J*te+oe*me,ve=fe*ce-he*he;if(Math.abs(ve)<1e-12)return!1;let be=1/ve,Ce=(ce*de-he*pe)*be,Se=(fe*pe-he*de)*be;return Ce>=-1e-7&&Se>=-1e-7&&Ce+Se<=1+1e-7}function P(D,x){let C=D.slice();A(C)<0&&C.reverse();let L=C.map(Q=>new n(Q.x,Q.y)),z=C.map((Q,q)=>q),W=[];for(let Q of x){if(!Q||Q.length<3)continue;let q=Q.slice();A(q)>0&&q.reverse();let J=[],oe=-1/0,te=0;for(let me=0;me<q.length;me++){let fe=q[me],he=L.length;L.push(new n(fe.x,fe.y)),J.push(he),fe.x>oe&&(oe=fe.x,te=me)}W.push({pts:q,indices:J,maxX:oe,maxIdx:te})}W.sort((Q,q)=>q.maxX-Q.maxX);let $=(Q,q,J)=>(q.x-Q.x)*(J.y-Q.y)-(q.y-Q.y)*(J.x-Q.x),Y=(Q,q,J)=>{for(let oe=0;oe<J.length;oe++){let te=J[oe],me=J[(oe+1)%J.length];if($(Q,q,te)*$(Q,q,me)<0&&$(te,me,Q)*$(te,me,q)<0)return!0}return!1};for(let Q of W){let q=Q.pts[Q.maxIdx],J=q.x,oe=z.length,te=z.map(ce=>L[ce]),me=ce=>Math.hypot(te[ce].x-J,te[ce].y-q.y),fe=te.map((ce,pe)=>pe).sort((ce,pe)=>+(te[ce].x<J)-+(te[pe].x<J)||me(ce)-me(pe)),he=fe[0];for(let ce of fe){let pe=te[ce],ve=te[(ce+oe-1)%oe],be=te[(ce+1)%oe],Ce=$(pe,be,q)>=0,Se=$(ve,pe,q)>=0;if(($(ve,pe,be)>=0?Ce&&Se:Ce||Se)&&!Y(q,pe,te)&&!W.some(_e=>Y(q,pe,_e.pts))){he=ce;break}}let de=[];for(let ce=0;ce<=he;ce++)de.push(z[ce]);for(let ce=0;ce<=Q.indices.length;ce++){let pe=Q.indices[(Q.maxIdx+ce)%Q.indices.length];de.push(pe)}for(let ce=he;ce<z.length;ce++)de.push(z[ce]);z=de}return{merged:z.map(Q=>L[Q]),mergedIndices:z,allVertices:L}}function N(D,x){let C=[],L=D.slice();if(L.length<3)return C;let z=L.length*L.length+64,W=0;for(;L.length>2&&z-- >0;){let $=L.length,Y=L[(W+$-1)%$],Q=L[W%$],q=L[(W+1)%$],J=x[Y],oe=x[Q],te=x[q];if((oe.x-J.x)*(te.y-J.y)-(oe.y-J.y)*(te.x-J.x)>1e-9){let fe=!0;for(let he=0;he<$;he++){let de=L[he];if(de===Y||de===Q||de===q)continue;let ce=x[de];if(w(ce.x,ce.y,J.x,J.y,oe.x,oe.y,te.x,te.y)&&Math.hypot(ce.x-J.x,ce.y-J.y)>=1e-6&&Math.hypot(ce.x-oe.x,ce.y-oe.y)>=1e-6&&Math.hypot(ce.x-te.x,ce.y-te.y)>=1e-6){fe=!1;break}}if(fe){C.push([Y,Q,q]),L.splice(W%$,1),W=Math.max(0,W%$-1);continue}}W++,W>=$*2&&(C.push([Y,Q,q]),L.splice((W-1)%$,1),W=0)}return C}function I(D,x){let C=D instanceof b?D.extractPoints(x):{shape:D.getPoints(x),holes:[]},L=C.shape.length;for(let z of C.holes)L+=z.length;if(L>y)throw new RangeError(`SecurityError: shape point count (${L}) exceeds MAX_SHAPE_POINTS (${y})`);return C}class _ extends c{constructor(x=new b,C=12){super();let L=Array.isArray(x)?x:[x],z=[],W=[],$=[],Y=[];for(let Q of L){if(!(Q instanceof S))continue;let q=I(Q,C);if(q.shape.length<3)continue;let{mergedIndices:J,allVertices:oe}=P(q.shape,q.holes),te=N(J,oe),me=z.length/3,fe=1/0,he=1/0,de=-1/0,ce=-1/0;for(let be of oe)be.x<fe&&(fe=be.x),be.y<he&&(he=be.y),be.x>de&&(de=be.x),be.y>ce&&(ce=be.y);let pe=Math.max(1e-6,de-fe),ve=Math.max(1e-6,ce-he);for(let be of oe)z.push(be.x,be.y,0),W.push(0,0,1),$.push((be.x-fe)/pe,(be.y-he)/ve);for(let[be,Ce,Se]of te)Y.push(me+be,me+Ce,me+Se)}this.setAttribute("position",new s(new Float32Array(z),3)),this.setAttribute("normal",new s(new Float32Array(W),3)),this.setAttribute("uv",new s(new Float32Array($),2)),this.setIndex(Y)}}function v(D){let x=D.length,C=[];for(let L=0;L<x;L++){let z=D[(L+x-1)%x],W=D[L],$=D[(L+1)%x],Y=W.x-z.x,Q=W.y-z.y,q=Math.hypot(Y,Q)||1;Y/=q,Q/=q;let J=$.x-W.x,oe=$.y-W.y,te=Math.hypot(J,oe)||1;J/=te,oe/=te;let me=Q,fe=-Y,he=oe,de=-J,ce=me+he,pe=fe+de,ve=Math.hypot(ce,pe);if(ve>1e-6){ce/=ve,pe/=ve;let be=Math.max(.35,ce*me+pe*fe);C.push(new n(ce/be,pe/be))}else C.push(new n(me,fe))}return C}class g extends c{constructor(x=new b,C={}){super();let L=Array.isArray(x)?x:[x],z=Math.max(1,Math.min(64,Math.floor(T(C.curveSegments,12)))),W=T(C.depth??C.amount,1),$=Math.max(1,Math.min(32,Math.floor(T(C.steps,1)))),Y=!!(C.bevelEnabled??!1),Q=Y?Math.max(0,T(C.bevelThickness,.06)):0,q=Y?Math.max(0,T(C.bevelSize,Q*.8)):0,J=Y?T(C.bevelOffset,0):0,oe=Y?Math.max(1,Math.min(8,Math.floor(T(C.bevelSegments,2)))):0,te=[],me=[],fe=[],he=[];for(let de of L){if(!(de instanceof S))continue;let ce=I(de,z);if(ce.shape.length<3)continue;let pe=ce.shape.slice();A(pe)<0&&pe.reverse();let ve=[];for(let ye of ce.holes){if(ye.length<3)continue;let Ee=ye.slice();A(Ee)>0&&Ee.reverse(),ve.push(Ee)}let{mergedIndices:be,allVertices:Ce}=P(pe,ve),Se=N(be,Ce),Ue=[pe,...ve],_e=[];for(let ye of Ue){let Ee=v(ye);for(let Ie of Ee)_e.push(Ie)}let Le=1/0,Ge=1/0,ze=-1/0,Ye=-1/0;for(let ye of Ce)ye.x<Le&&(Le=ye.x),ye.y<Ge&&(Ge=ye.y),ye.x>ze&&(ze=ye.x),ye.y>Ye&&(Ye=ye.y);let Xe=Math.max(1e-6,ze-Le),nt=Math.max(1e-6,Ye-Ge),Ut=-Q,Ot=W+Q,bt=te.length/3;for(let ye=0;ye<Ce.length;ye++){let Ee=Ce[ye],Ie=_e[ye]??new n(0,0),Oe=Ee.x+Ie.x*J,Ve=Ee.y+Ie.y*J;te.push(Oe,Ve,Ut),me.push(0,0,-1),fe.push((Oe-Le)/Xe,(Ve-Ge)/nt)}for(let[ye,Ee,Ie]of Se)he.push(bt+ye,bt+Ie,bt+Ee);let yt=te.length/3;for(let ye=0;ye<Ce.length;ye++){let Ee=Ce[ye],Ie=_e[ye]??new n(0,0),Oe=Ee.x+Ie.x*J,Ve=Ee.y+Ie.y*J;te.push(Oe,Ve,Ot),me.push(0,0,1),fe.push((Oe-Le)/Xe,(Ve-Ge)/nt)}for(let[ye,Ee,Ie]of Se)he.push(yt+ye,yt+Ee,yt+Ie);let $e=[];if(Y&&oe>0)for(let ye=0;ye<oe;ye++){let Ie=ye/oe*Math.PI/2;$e.push({z:-Q*Math.cos(Ie),expand:J+q*Math.sin(Ie)})}for(let ye=0;ye<=$;ye++){let Ee=ye/$;$e.push({z:Ee*W,expand:J+q})}if(Y&&oe>0)for(let ye=1;ye<=oe;ye++){let Ie=ye/oe*Math.PI/2;$e.push({z:W+Q*Math.sin(Ie),expand:J+q*Math.cos(Ie)})}let rt=0;for(let ye of Ue){let Ee=ye.length;for(let Ie=0;Ie<$e.length-1;Ie++){let Oe=$e[Ie],Ve=$e[Ie+1];for(let qe=0;qe<Ee;qe++){let lt=(qe+1)%Ee,gt=ye[qe],xt=ye[lt],vt=_e[rt+qe],Tt=_e[rt+lt],At=gt.x+vt.x*Oe.expand,wt=gt.y+vt.y*Oe.expand,Rt=xt.x+Tt.x*Oe.expand,mt=xt.y+Tt.y*Oe.expand,Hs=xt.x+Tt.x*Ve.expand,Xs=xt.y+Tt.y*Ve.expand,qi=gt.x+vt.x*Ve.expand,Yi=gt.y+vt.y*Ve.expand,ji=Rt-At,Ki=mt-wt,Zi=0,Qi=qi-At,Ji=Yi-wt,eo=Ve.z-Oe.z,Vt=Ki*eo-Zi*Ji,Bt=Zi*Qi-ji*eo,zt=ji*Ji-Ki*Qi,Ur=Math.hypot(Vt,Bt,zt)||1;Vt/=Ur,Bt/=Ur,zt/=Ur;let Gt=te.length/3;te.push(At,wt,Oe.z,Rt,mt,Oe.z,Hs,Xs,Ve.z,qi,Yi,Ve.z),me.push(Vt,Bt,zt,Vt,Bt,zt,Vt,Bt,zt,Vt,Bt,zt);let to=qe/Ee,no=(qe+1)/Ee,ro=Ie/($e.length-1),io=(Ie+1)/($e.length-1);fe.push(to,ro,no,ro,no,io,to,io),he.push(Gt,Gt+1,Gt+2,Gt,Gt+2,Gt+3)}}rt+=Ee}}this.setAttribute("position",new s(new Float32Array(te),3)),this.setAttribute("normal",new s(new Float32Array(me),3)),this.setAttribute("uv",new s(new Float32Array(fe),2)),this.setIndex(he)}}function M(D){return{x:D.x,y:D.y,z:D.z,nx:D.nx,ny:D.ny,nz:D.nz,u:D.u,v:D.v}}function k(D){return{x:D.x,y:D.y,z:D.z,nx:-D.nx,ny:-D.ny,nz:-D.nz,u:D.u,v:D.v}}function R(D,x,C){let L=D.nx+(x.nx-D.nx)*C,z=D.ny+(x.ny-D.ny)*C,W=D.nz+(x.nz-D.nz)*C,$=Math.hypot(L,z,W)||1;return{x:D.x+(x.x-D.x)*C,y:D.y+(x.y-D.y)*C,z:D.z+(x.z-D.z)*C,nx:L/$,ny:z/$,nz:W/$,u:D.u+(x.u-D.u)*C,v:D.v+(x.v-D.v)*C}}function B(D){if(D.length<3)return null;let x=D[0],C=D[1],L=D[2],z=C.x-x.x,W=C.y-x.y,$=C.z-x.z,Y=L.x-x.x,Q=L.y-x.y,q=L.z-x.z,J=W*q-$*Q,oe=$*Y-z*q,te=z*Q-W*Y,me=Math.hypot(J,oe,te);if(me<1e-9)return null;J/=me,oe/=me,te/=me;let fe=J*x.x+oe*x.y+te*x.z;return{vertices:D,nx:J,ny:oe,nz:te,w:fe}}function Z(D){D.vertices.reverse();for(let x=0;x<D.vertices.length;x++)D.vertices[x]=k(D.vertices[x]);D.nx=-D.nx,D.ny=-D.ny,D.nz=-D.nz,D.w=-D.w}let j=1e-5,ie=0,ee=1,ne=2,X=3;function ae(D,x,C,L,z,W,$,Y,Q){let q=0,J=[];for(let oe=0;oe<z.vertices.length;oe++){let te=z.vertices[oe],me=D*te.x+x*te.y+C*te.z-L,fe=me<-j?ne:me>j?ee:ie;q|=fe,J.push(fe)}switch(q){case ie:{D*z.nx+x*z.ny+C*z.nz>0?W.push(z):$.push(z);break}case ee:Y.push(z);break;case ne:Q.push(z);break;case X:{let oe=[],te=[],me=z.vertices.length;for(let pe=0;pe<me;pe++){let ve=(pe+1)%me,be=J[pe],Ce=J[ve],Se=z.vertices[pe],Ue=z.vertices[ve];if(be!==ne&&oe.push(Se),be!==ee&&te.push(be!==ne?M(Se):Se),(be|Ce)===X){let _e=Ue.x-Se.x,Le=Ue.y-Se.y,Ge=Ue.z-Se.z,ze=D*_e+x*Le+C*Ge,Ye=Math.abs(ze)>1e-12?(L-(D*Se.x+x*Se.y+C*Se.z))/ze:.5,Xe=R(Se,Ue,Math.max(0,Math.min(1,Ye)));oe.push(Xe),te.push(M(Xe))}}let{nx:fe,ny:he,nz:de,w:ce}=z;oe.length>=3&&Y.push({vertices:oe,nx:fe,ny:he,nz:de,w:ce}),te.length>=3&&Q.push({vertices:te,nx:fe,ny:he,nz:de,w:ce});break}default:break}}class se{constructor(x,C=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,x&&x.length>0&&this.build(x,C)}invert(){for(let C=0;C<this.polygons.length;C++)Z(this.polygons[C]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let x=this.front;this.front=this.back,this.back=x}clipPolygons(x,C=0){if(!this.hasPlane||x.length===0)return x.slice();if(C>=p)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${p})`);let L=[],z=[];for(let W=0;W<x.length;W++)ae(this.nx,this.ny,this.nz,this.w,x[W],L,z,L,z);return this.front&&L.length>0&&(L=this.front.clipPolygons(L,C+1)),this.back?z=z.length>0?this.back.clipPolygons(z,C+1):[]:z=[],L.concat(z)}clipTo(x,C=0){this.polygons.length>0&&(this.polygons=x.clipPolygons(this.polygons,0)),C<p&&(this.front&&this.front.clipTo(x,C+1),this.back&&this.back.clipTo(x,C+1))}allPolygons(x=[]){for(let C=0;C<this.polygons.length;C++)x.push(this.polygons[C]);return this.front&&this.front.allPolygons(x),this.back&&this.back.allPolygons(x),x}build(x,C=0){if(!x.length)return;if(!this.hasPlane){let W=x[0];this.nx=W.nx,this.ny=W.ny,this.nz=W.nz,this.w=W.w,this.hasPlane=!0}if(C>=p)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${p})`);let L=[],z=[];for(let W=0;W<x.length;W++)ae(this.nx,this.ny,this.nz,this.w,x[W],this.polygons,this.polygons,L,z);L.length>0&&(this.front||(this.front=new se),this.front.build(L,C+1)),z.length>0&&(this.back||(this.back=new se),this.back.build(z,C+1))}}function F(D,x){let C=D.attributes.position;if(!C||C.count===0)return[];let L=D.attributes.normal,z=D.attributes.uv,W=D.index?D.index.array:null,$=Math.floor(W?W.length/3:C.count/3);if($>h)throw new RangeError(`SecurityError: CSG input triangle count (${$}) exceeds MAX_CSG_TRIANGLES (${h})`);let Y=x?x.elements:null,Q=Y?Y[0]*(Y[5]*Y[10]-Y[9]*Y[6])-Y[4]*(Y[1]*Y[10]-Y[9]*Y[2])+Y[8]*(Y[1]*Y[6]-Y[5]*Y[2])<0:!1,q=Y?new a().getNormalMatrix(x).elements:null,J=te=>{let me=C.getX(te),fe=C.getY(te),he=C.getZ(te),de=L?L.getX(te):NaN,ce=L?L.getY(te):NaN,pe=L?L.getZ(te):NaN;if(Y&&q){let Ce=Y[0]*me+Y[4]*fe+Y[8]*he+Y[12],Se=Y[1]*me+Y[5]*fe+Y[9]*he+Y[13],Ue=Y[2]*me+Y[6]*fe+Y[10]*he+Y[14];me=Ce,fe=Se,he=Ue;let _e=q[0]*de+q[3]*ce+q[6]*pe,Le=q[1]*de+q[4]*ce+q[7]*pe,Ge=q[2]*de+q[5]*ce+q[8]*pe,ze=Math.hypot(_e,Le,Ge)||1;de=_e/ze,ce=Le/ze,pe=Ge/ze}let ve=z?z.getX(te):0,be=z?z.getY(te):0;return{x:me,y:fe,z:he,nx:de,ny:ce,nz:pe,u:ve,v:be}},oe=[];for(let te=0;te<$;te++){let me=W?W[te*3]:te*3,fe=W?W[te*3+1]:te*3+1,he=W?W[te*3+2]:te*3+2,de=B(Q?[J(me),J(he),J(fe)]:[J(me),J(fe),J(he)]);de&&oe.push(de)}return oe}function H(D){let x=[],C=[],L=[],z=[];for(let $ of D){let Y=$.vertices;if(Y.length<3)continue;let Q=x.length/3;for(let q of Y)x.push(q.x,q.y,q.z),Number.isFinite(q.nx)&&q.nx*q.nx+q.ny*q.ny+q.nz*q.nz>.5?C.push(q.nx,q.ny,q.nz):C.push($.nx,$.ny,$.nz),L.push(q.u,q.v);for(let q=1;q<Y.length-1;q++)z.push(Q,Q+q,Q+q+1)}let W=new c;return W.setAttribute("position",new s(new Float32Array(x),3)),W.setAttribute("normal",new s(new Float32Array(C),3)),W.setAttribute("uv",new s(new Float32Array(L),2)),W.setIndex(z),W}function E(D,x,C){if(D.length+x.length>h)throw new RangeError(`SecurityError: Combined CSG triangle count (${D.length+x.length}) exceeds MAX_CSG_TRIANGLES (${h})`);if(D.length===0)return C==="union"?x:[];if(x.length===0)return C==="intersect"?[]:D;let L=new se(D),z=new se(x);return C==="union"?(L.clipTo(z),z.clipTo(L),z.invert(),z.clipTo(L),z.invert(),L.build(z.allPolygons()),L.allPolygons()):C==="subtract"?(L.invert(),L.clipTo(z),z.clipTo(L),z.invert(),z.clipTo(L),z.invert(),L.build(z.allPolygons()),L.invert(),L.allPolygons()):(L.invert(),z.clipTo(L),z.invert(),L.clipTo(z),z.clipTo(L),L.build(z.allPolygons()),L.invert(),L.allPolygons())}function V(D,x,C,L=null,z=null){let W=F(D,L),$=F(x,z);return H(E(W,$,C))}function O(D,x,C){let L=D instanceof m||!!D?.isMesh,z=x instanceof m||!!x?.isMesh,W=L?D.geometry:D,$=z?x.geometry:x,Y=null;if(z)if(x.updateMatrix(),L){D.updateMatrix();let oe=new o().makeScale(1/(D.scale.x||1),1/(D.scale.y||1),1/(D.scale.z||1)),te=Math.hypot(D.quaternion.x,D.quaternion.y,D.quaternion.z,D.quaternion.w)||1,me=new o().compose(new r(0,0,0),new i(-D.quaternion.x/te,-D.quaternion.y/te,-D.quaternion.z/te,D.quaternion.w/te),new r(1,1,1)),fe=new o().makeTranslation(-D.position.x,-D.position.y,-D.position.z);Y=oe.multiply(me).multiply(fe).multiply(x.matrix)}else Y=x.matrix;let Q=V(W,$,C,null,Y),q=L?D.material:new f,J=new m(Q,q);return L&&(J.position.copy(D.position),J.quaternion.copy(D.quaternion),J.scale.copy(D.scale),J.name=D.name),J}let U={toGeometry:V,subtract(D,x){return O(D,x,"subtract")},union(D,x){return O(D,x,"union")},intersect(D,x){return O(D,x,"intersect")}},G={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class K extends c{constructor(x="",C={}){super();let L=String(x??"").slice(0,d),z=Math.max(.005,Math.min(100,T(C.size,.2))),W=!!(C.bevelEnabled??!1),$=W?Math.max(0,Math.min(2,T(C.bevelThickness,z*.04))):0,Y=W?Math.max(0,Math.min(2,T(C.bevelSize,z*.03))):0,Q=Math.max(.001,Math.min(20,T(C.depth??C.height,z*.2)))+$*2,q=z*.085+Y,J=z*.68,oe=z*.82,te=[],me=[],fe=[],he=[],de=(ve,be,Ce,Se,Ue,_e,Le)=>{let Ge=Ce-ve,ze=Se-be,Ye=Math.hypot(Ge,ze),Xe=1,nt=0;Ye>1e-6&&(Xe=Ge/Ye,nt=ze/Ye);let Ut=-nt*Ue,Ot=Xe*Ue,bt=Xe*Ue*.6,yt=nt*Ue*.6,$e=ve-bt+Ut,rt=be-yt+Ot,ye=ve-bt-Ut,Ee=be-yt-Ot,Ie=Ce+bt-Ut,Oe=Se+yt-Ot,Ve=Ce+bt+Ut,qe=Se+yt+Ot,lt=(gt,xt,vt,Tt,At,wt,Rt)=>{let mt=te.length/3;te.push(gt[0],gt[1],gt[2],xt[0],xt[1],xt[2],vt[0],vt[1],vt[2],Tt[0],Tt[1],Tt[2]),me.push(At,wt,Rt,At,wt,Rt,At,wt,Rt,At,wt,Rt),fe.push(0,0,1,0,1,1,0,1),he.push(mt,mt+1,mt+2,mt,mt+2,mt+3)};lt([$e,rt,Le],[ye,Ee,Le],[Ie,Oe,Le],[Ve,qe,Le],0,0,1),lt([ye,Ee,_e],[$e,rt,_e],[Ve,qe,_e],[Ie,Oe,_e],0,0,-1),lt([$e,rt,_e],[ye,Ee,_e],[ye,Ee,Le],[$e,rt,Le],-Xe,-nt,0),lt([Ie,Oe,_e],[Ve,qe,_e],[Ve,qe,Le],[Ie,Oe,Le],Xe,nt,0),lt([ye,Ee,_e],[Ie,Oe,_e],[Ie,Oe,Le],[ye,Ee,Le],nt,-Xe,0),lt([Ve,qe,_e],[$e,rt,_e],[$e,rt,Le],[Ve,qe,Le],-nt,Xe,0)},ce=0,pe=0;for(let ve=0;ve<L.length;ve++){let be=L[ve];if(be===`
|
|
18
|
+
`){ce=0,pe-=z*1.35;continue}if(be===" "||be===" "){ce+=oe*(be===" "?.75:3);continue}if(be==="\r")continue;let Ce=be.toUpperCase(),Se=be!==Ce&&be>="a"&&be<="z",Ue=G[Ce]??G["?"],_e=Se?z*.76:z,Le=Se?J*.88:J;for(let Ge of Ue)for(let ze=0;ze<Ge.length-1;ze++){let Ye=Ge[ze],Xe=Ge[ze+1];de(ce+Ye[0]*Le,pe+Ye[1]*_e,ce+Xe[0]*Le,pe+Xe[1]*_e,q,-Q*.5,Q*.5)}ce+=Se?oe*.88:oe}this.setAttribute("position",new s(new Float32Array(te),3)),this.setAttribute("normal",new s(new Float32Array(me),3)),this.setAttribute("uv",new s(new Float32Array(fe),2)),this.setIndex(he),C.center!==!1?this.center():this.computeBoundingBox()}}function ue(D){if(!D)return;let x=D,C=D.userData?.xr?.text;if(C!=null&&C!==!1){let z=x.geometry?.attributes?.position;if((!z||z.count===0)&&D.userData._textApplied!==!0){let W="",$=.08,Y=.015,Q;if(typeof C=="string"||typeof C=="number")W=String(C);else if(typeof C=="object"){let q=C;W=String(q.text??q.value??""),q.size!==void 0&&($=Number(q.size)||.08),(q.depth!==void 0||q.height!==void 0)&&(Y=Number(q.depth??q.height)||$*.2),(typeof q.color=="string"||typeof q.color=="number")&&(Q=q.color)}W.trim().length>0&&(x.geometry=new K(W,{size:$,depth:Y}),D.userData._textApplied=!0,x.material instanceof l?Q!==void 0&&D.userData._autoTextColorApplied!==!0&&(x.material.color=new u(Q),D.userData._autoTextColorApplied=!0):x.material=new f({color:Q??16317180}))}}let L=D.userData?.csg;if(L&&typeof L=="object"&&D.userData._csgApplied!==!0&&x.geometry instanceof c&&x.geometry.attributes.position?.count>0){D.userData._csgApplied=!0;let z=Array.isArray(L)?L:[L],W=x.geometry;for(let $ of z){if(!$||typeof $!="object")continue;let Y=$,Q=String(Y.op??Y.operation??"subtract"),q=Q==="union"||Q==="intersect"?Q:"subtract",J=Y.target??Y.mesh??Y.geometry;if(J instanceof m||J instanceof c)try{let oe=q==="union"?U.union(x,J):q==="intersect"?U.intersect(x,J):U.subtract(x,J);x.geometry!==W&&x.geometry.dispose?.(),x.geometry=oe.geometry}catch(oe){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",oe)}}}}let re={Path:S,Shape:b,ShapeGeometry:_,ExtrudeGeometry:g,TextGeometry:K,CSG:U,MAX_CSG_TRIANGLES:h,MAX_BSP_DEPTH:p,MAX_TEXT_GEOMETRY_CHARS:d,MAX_SHAPE_POINTS:y,materializeDeclarativeGeometry:ue};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,re),t.materializeDeclarativeGeometry=ue),re}var Vr={name:"cad",onRegister(){Nn(Fn);let e=ge(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);t&&Fn(t,e)}};function Te(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Un(e,t,n,r,i){let o=1/Math.tan(t/2);e.fill(0),e[0]=o/n,e[5]=o,e[11]=-1;let a=1/(r-i);return e[10]=(i+r)*a,e[14]=2*i*r*a,e}function Ht(e,t,n,r){let[i,o,a]=t,[u,s,c]=r,[l,f,m]=n,h=i-l,p=o-f,d=a-m,y=Math.hypot(h,p,d);y<=1e-5?(h=0,p=0,d=1):(h/=y,p/=y,d/=y);let T=s*d-c*p,S=c*h-u*d,b=u*p-s*h;y=Math.hypot(T,S,b),y<=1e-5?(T=0,S=0,b=0):(T/=y,S/=y,b/=y);let A=p*b-d*S,w=d*T-h*b,P=h*S-p*T;return y=Math.hypot(A,w,P),y<=1e-5?(A=0,w=0,P=0):(A/=y,w/=y,P/=y),e[0]=T,e[1]=A,e[2]=h,e[3]=0,e[4]=S,e[5]=w,e[6]=p,e[7]=0,e[8]=b,e[9]=P,e[10]=d,e[11]=0,e[12]=-(T*i+S*o+b*a),e[13]=-(A*i+w*o+P*a),e[14]=-(h*i+p*o+d*a),e[15]=1,e}function Re(e,t,n){let r=t[0],i=t[1],o=t[2],a=t[3],u=t[4],s=t[5],c=t[6],l=t[7],f=t[8],m=t[9],h=t[10],p=t[11],d=t[12],y=t[13],T=t[14],S=t[15],b=n[0],A=n[1],w=n[2],P=n[3];return e[0]=b*r+A*u+w*f+P*d,e[1]=b*i+A*s+w*m+P*y,e[2]=b*o+A*c+w*h+P*T,e[3]=b*a+A*l+w*p+P*S,b=n[4],A=n[5],w=n[6],P=n[7],e[4]=b*r+A*u+w*f+P*d,e[5]=b*i+A*s+w*m+P*y,e[6]=b*o+A*c+w*h+P*T,e[7]=b*a+A*l+w*p+P*S,b=n[8],A=n[9],w=n[10],P=n[11],e[8]=b*r+A*u+w*f+P*d,e[9]=b*i+A*s+w*m+P*y,e[10]=b*o+A*c+w*h+P*T,e[11]=b*a+A*l+w*p+P*S,b=n[12],A=n[13],w=n[14],P=n[15],e[12]=b*r+A*u+w*f+P*d,e[13]=b*i+A*s+w*m+P*y,e[14]=b*o+A*c+w*h+P*T,e[15]=b*a+A*l+w*p+P*S,e}function Qe(e,t,n,r){let i=t[0],o=t[1],a=t[2],u=t[3],s=i+i,c=o+o,l=a+a,f=i*s,m=i*c,h=i*l,p=o*c,d=o*l,y=a*l,T=u*s,S=u*c,b=u*l,A=r[0],w=r[1],P=r[2];return e[0]=(1-(p+y))*A,e[1]=(m+b)*A,e[2]=(h-S)*A,e[3]=0,e[4]=(m-b)*w,e[5]=(1-(f+y))*w,e[6]=(d+T)*w,e[7]=0,e[8]=(h+S)*P,e[9]=(d-T)*P,e[10]=(1-(f+p))*P,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function De(e,t){let n=t[0],r=t[1],i=t[2],o=t[4],a=t[5],u=t[6],s=t[8],c=t[9],l=t[10],f=l*a-u*c,m=-l*o+u*s,h=c*o-a*s,p=n*f+r*m+i*h;return p&&(p=1/p,e[0]=f*p,e[1]=m*p,e[2]=h*p,e[3]=(-l*r+i*c)*p,e[4]=(l*n-i*s)*p,e[5]=(-c*n+r*s)*p,e[6]=(u*r-i*a)*p,e[7]=(-u*n+i*o)*p,e[8]=(a*n-r*o)*p),e}function Xt(e,t){let n=t[0],r=t[1],i=t[2],o=t[3],a=t[4],u=t[5],s=t[6],c=t[7],l=t[8],f=t[9],m=t[10],h=t[11],p=t[12],d=t[13],y=t[14],T=t[15],S=n*u-r*a,b=n*s-i*a,A=n*c-o*a,w=r*s-i*u,P=r*c-o*u,N=i*c-o*s,I=l*d-f*p,_=l*y-m*p,v=l*T-h*p,g=f*y-m*d,M=f*T-h*d,k=m*T-h*y,R=S*k-b*M+A*g+w*v-P*_+N*I;return R?(R=1/R,e[0]=(u*k-s*M+c*g)*R,e[1]=(i*M-r*k-o*g)*R,e[2]=(d*N-y*P+T*w)*R,e[3]=(m*P-f*N-h*w)*R,e[4]=(s*v-a*k-c*_)*R,e[5]=(n*k-i*v+o*_)*R,e[6]=(y*A-p*N-T*b)*R,e[7]=(l*N-m*A+h*b)*R,e[8]=(a*M-u*v+c*I)*R,e[9]=(r*v-n*M-o*I)*R,e[10]=(p*P-d*A+T*S)*R,e[11]=(f*A-l*P-h*S)*R,e[12]=(u*_-a*g-s*I)*R,e[13]=(n*g-r*_+i*I)*R,e[14]=(d*b-p*w-y*S)*R,e[15]=(l*w-f*b+m*S)*R,e):null}function Br(e,t,n,r,i){let o=i[0]*t+i[4]*n+i[8]*r+i[12],a=i[1]*t+i[5]*n+i[9]*r+i[13],u=i[2]*t+i[6]*n+i[10]*r+i[14],s=i[3]*t+i[7]*n+i[11]*r+i[15],c=s!==0?1/s:1;e[0]=o*c,e[1]=a*c,e[2]=u*c}function lo(e,t,n,r,i,o,a,u,s,c,l,f,m,h,p,d,y=0){let T=c-a,S=l-u,b=f-s,A=m-a,w=h-u,P=p-s,N=i*P-o*w,I=o*A-r*P,_=r*w-i*A,v=T*N+S*I+b*_;if(v>-1e-7&&v<1e-7)return!1;let g=1/v,M=e-a,k=t-u,R=n-s,B=g*(M*N+k*I+R*_);if(B<-y||B>1+y)return!1;let Z=k*b-R*S,j=R*T-M*b,ie=M*S-k*T,ee=g*(r*Z+i*j+o*ie);if(ee<-y||B+ee>1+y)return!1;let ne=g*(A*Z+w*j+P*ie);if(ne>1e-4&&ne<d.distance){d.distance=ne,d.point=[e+r*ne,t+i*ne,n+o*ne];let X=S*P-b*w,ae=b*A-T*P,se=T*w-S*A,F=Math.hypot(X,ae,se)||1;return d.normal=[X/F,ae/F,se/F],!0}return!1}function ft(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let l=0;l<n;l++)r.push(Te());if(n===0)return r;let i=new Set;for(let l of e.nodes)if(Array.isArray(l.children))for(let f of l.children)i.add(f);let o=new Set,a=128,u=(l,f,m=0)=>{if(m>a||l<0||l>=n||o.has(l))return;o.add(l);let h=e.nodes[l];if(!h)return;let p=Te();if(t&&t[l])p.set(t[l]);else if(h.matrix&&h.matrix.length===16)p.set(h.matrix);else{let y=h.translation||[0,0,0],T=h.rotation||[0,0,0,1],S=h.scale||[1,1,1];Qe(p,T,y,S)}let d=r[l];if(f?Re(d,f,p):d.set(p),Array.isArray(h.children))for(let y of h.children)typeof y=="number"&&u(y,d,m+1)},s=[],c=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(c&&Array.isArray(c.nodes))s.push(...c.nodes);else for(let l=0;l<n;l++)i.has(l)||s.push(l);for(let l of s)u(l,null);for(let l=0;l<n;l++)!i.has(l)&&!s.includes(l)&&u(l,null);return r}function Hr(e,t){function n(s,c,l,f){let m=typeof s=="number"?s:Number(s);return Number.isFinite(m)?Math.max(c,Math.min(l,m)):f}function r(s,c){let f=s[0]*c[0]+s[1]*c[1]+s[2]*c[2]+1;if(f<1e-6){if(Math.abs(s[0])>Math.abs(s[2])){let T=Math.hypot(s[1],s[0])||1;return[-s[1]/T,s[0]/T,0,0]}let y=Math.hypot(s[2],s[1])||1;return[0,-s[2]/y,s[1]/y,0]}let m=s[1]*c[2]-s[2]*c[1],h=s[2]*c[0]-s[0]*c[2],p=s[0]*c[1]-s[1]*c[0],d=Math.hypot(m,h,p,f)||1;return[m/d,h/d,p/d,f/d]}function i(s,c,l,f,m){let h=c[0]-s[0],p=c[1]-s[1],d=c[2]-s[2],y=Math.hypot(h,p,d),T=l[0]-c[0],S=l[1]-c[1],b=l[2]-c[2],A=Math.hypot(T,S,b);if(y<1e-6||A<1e-6)return{rootPos:[s[0],s[1],s[2]],midPos:[c[0],c[1],c[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let w=[h/y,p/y,d/y],P=[T/A,S/A,b/A],N=f[0]-s[0],I=f[1]-s[1],_=f[2]-s[2],v=Math.hypot(N,I,_),g=v>1e-6?[N/v,I/v,_/v]:w,M=Math.abs(y-A)+1e-5,k=Math.max(M,y+A-1e-5),R=Math.max(M,Math.min(k,v>1e-6?v:M)),B=n((y*y+R*R-A*A)/(2*y*R),-1,1,1),Z=Math.sqrt(Math.max(0,1-B*B)),j=m?m[0]-s[0]:h,ie=m?m[1]-s[1]:p,ee=m?m[2]-s[2]:d,ne=j*g[0]+ie*g[1]+ee*g[2],X=j-g[0]*ne,ae=ie-g[1]*ne,se=ee-g[2]*ne,F=Math.hypot(X,ae,se);if(F<=1e-6){let x=Math.abs(g[1])<.99?0:1,C=Math.abs(g[1])<.99?1:0,L=0;X=g[1]*L-g[2]*C,ae=g[2]*x-g[0]*L,se=g[0]*C-g[1]*x,F=Math.hypot(X,ae,se)||1}let H=[X/F,ae/F,se/F],E=[s[0]+g[0]*(y*B)+H[0]*(y*Z),s[1]+g[1]*(y*B)+H[1]*(y*Z),s[2]+g[2]*(y*B)+H[2]*(y*Z)],V=[s[0]+g[0]*R,s[1]+g[1]*R,s[2]+g[2]*R],O=V[0]-E[0],U=V[1]-E[1],G=V[2]-E[2],K=Math.hypot(O,U,G),ue=K>1e-6?[O/K,U/K,G/K]:g,re=[E[0]+ue[0]*A,E[1]+ue[1]*A,E[2]+ue[2]*A],D=[(E[0]-s[0])/y,(E[1]-s[1])/y,(E[2]-s[2])/y];return{rootPos:[s[0],s[1],s[2]],midPos:E,effectorPos:re,rootRotation:r(w,D),midRotation:r(P,ue)}}function o(s,c,l=8,f=.001){let m=s.length;if(m<2)return{positions:s.map(v=>[v[0],v[1],v[2]]),rotations:[],iterations:0};let h=s.map(v=>[v[0],v[1],v[2]]),p=[],d=[],y=0;for(let v=0;v<m-1;v++){let g=h[v+1][0]-h[v][0],M=h[v+1][1]-h[v][1],k=h[v+1][2]-h[v][2],R=Math.hypot(g,M,k);p.push(R),y+=R,d.push(R>1e-6?[g/R,M/R,k/R]:[0,1,0])}let T=[h[0][0],h[0][1],h[0][2]],S=Math.round(n(l,1,32,8)),b=n(f,1e-5,.1,.001),A=c[0]-T[0],w=c[1]-T[1],P=c[2]-T[2],N=Math.hypot(A,w,P),I=0;if(N>=y&&y>1e-6){let v=N>1e-6?[A/N,w/N,P/N]:d[0];h[0]=[T[0],T[1],T[2]];for(let g=0;g<m-1;g++){let M=p[g];h[g+1]=[h[g][0]+v[0]*M,h[g][1]+v[1]*M,h[g][2]+v[2]*M]}I=1}else for(let v=1;v<=S;v++){let g=h[m-1];if(Math.hypot(g[0]-c[0],g[1]-c[1],g[2]-c[2])<=b)break;I=v;let k=(R,B,Z,j,ie)=>{let ee=B[0]-R[0],ne=B[1]-R[1],X=B[2]-R[2],ae=Math.hypot(ee,ne,X);if(ae>1e-6){let se=Z/ae;return[R[0]+ee*se,R[1]+ne*se,R[2]+X*se]}return[R[0]+j[0]*Z*ie,R[1]+j[1]*Z*ie,R[2]+j[2]*Z*ie]};h[m-1]=[c[0],c[1],c[2]];for(let R=m-2;R>=0;R--)h[R]=k(h[R+1],h[R],p[R],d[R],-1);h[0]=[T[0],T[1],T[2]];for(let R=0;R<m-1;R++)h[R+1]=k(h[R],h[R+1],p[R],d[R],1)}let _=[];for(let v=0;v<m-1;v++){let g=h[v+1][0]-h[v][0],M=h[v+1][1]-h[v][1],k=h[v+1][2]-h[v][2],R=Math.hypot(g,M,k),B=R>1e-6?[g/R,M/R,k/R]:d[v];_.push(r(d[v],B))}return{positions:h,rotations:_,iterations:I}}function a(s){if(!s||typeof s!="object"||Array.isArray(s))return null;let c=s;if(c.enabled===!1)return null;let l=b=>{if(typeof b!="string")return;let A=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},f=b=>Array.isArray(b)&&b.length===3&&b.every(A=>typeof A=="number"&&Number.isFinite(A))?[n(b[0],-1e3,1e3,0),n(b[1],-1e3,1e3,0),n(b[2],-1e3,1e3,0)]:void 0,m=l(c.root),h=l(c.effector);if(!m||!h)return null;let p=l(c.mid),d=f(c.target)??l(c.target);if(!d)return null;let y=c.pole??c.poleTarget,T=f(y)??l(y),S=c.solver==="fabrik"?"fabrik":c.solver==="two-bone"||p?"two-bone":"fabrik";return{root:m,...p?{mid:p}:{},effector:h,target:d,...T?{pole:T}:{},solver:S,iterations:Math.round(n(c.iterations,1,32,8)),tolerance:n(c.tolerance,1e-5,.1,.001),weight:n(c.weight,0,1,1)}}let u=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:a});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=u),{clampNum:n,parseIKTrait:a,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:u}}var Wt=Hr(),fo=Wt.clampNum,Zs=Wt.parseIKTrait,Vn=Wt.quatFromUnitVectors,$r=Wt.solveTwoBoneIK,qr=Wt.solveFABRIK,ho=Wt.IKSolver;function Xr(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function Qs(e,t){let n=e?.transform??e?.modelMatrix;!n||n.length<16||(n[12]=t[0],n[13]=t[1],n[14]=t[2])}function Js(e,t,n,r,i){let o=fo(i,0,1,1),a=t[0]+(n[0]-t[0])*o,u=t[1]+(n[1]-t[1])*o,s=t[2]+(n[2]-t[2])*o,c=a-e[0],l=u-e[1],f=s-e[2],m=Math.hypot(c,l,f);if(m>1e-6&&r>1e-6){let T=r/m;return[e[0]+c*T,e[1]+l*T,e[2]+f*T]}let h=n[0]-e[0],p=n[1]-e[1],d=n[2]-e[2],y=Math.hypot(h,p,d);if(y>1e-6&&r>1e-6){let T=r/y;return[e[0]+h*T,e[1]+p*T,e[2]+d*T]}return[a,u,s]}function ea(e,t){let n=e?.modelRootMatrix;if(!n||n.length!==16)return t;let r=new Float32Array(16);return Xt(r,n instanceof Float32Array?n:Float32Array.from(n))?[r[0]*t[0]+r[4]*t[1]+r[8]*t[2]+r[12],r[1]*t[0]+r[5]*t[1]+r[9]*t[2]+r[13],r[2]*t[0]+r[6]*t[1]+r[10]*t[2]+r[14]]:t}function zr(e,t){e.__ikWarned||(e.__ikWarned=new Set);let n=e.__ikWarned;n.has(t)||(n.add(t),console.warn(`[three-live] ik: joint '${t}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function Wr(e,t,n){if(Array.isArray(e))return[e[0],e[1],e[2]];let r=t.get(e);if(r)return Xr(r);let i;if(e==="head"?i=n?.headPose?.position??n?.headPose??n?.cameraPosition:e==="hand-left"?i=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left:e==="hand-right"&&(i=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let o=i;return ea(n,[o[0],o[1],o[2]])}return null}function Gr(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function ta(e){return[-e[0],-e[1],-e[2],e[3]]}function Yr(e){let t=Math.hypot(e[0],e[1],e[2],e[3]);return t>1e-12?[e[0]/t,e[1]/t,e[2]/t,e[3]/t]:[0,0,0,1]}function na(e,t){if(t>=1)return e;if(t<=0)return[0,0,0,1];let[n,r,i,o]=e;o<0&&(n=-n,r=-r,i=-i,o=-o);let a=Math.acos(Math.min(1,o)),u=Math.sin(a);if(u<1e-9)return[0,0,0,1];let s=Math.sin(a*t)/u;return Yr([n*s,r*s,i*s,Math.cos(a*t)])}function ra(e){let t=Math.hypot(e[0],e[1],e[2])||1,n=Math.hypot(e[4],e[5],e[6])||1,r=Math.hypot(e[8],e[9],e[10])||1,i=e[0]/t,o=e[1]/t,a=e[2]/t,u=e[4]/n,s=e[5]/n,c=e[6]/n,l=e[8]/r,f=e[9]/r,m=e[10]/r,h=i+s+m,p;if(h>0){let d=Math.sqrt(h+1)*2;p=[(c-f)/d,(l-a)/d,(o-u)/d,.25*d]}else if(i>s&&i>m){let d=Math.sqrt(1+i-s-m)*2;p=[.25*d,(u+o)/d,(l+a)/d,(c-f)/d]}else if(s>m){let d=Math.sqrt(1+s-i-m)*2;p=[(u+o)/d,.25*d,(f+c)/d,(l-a)/d]}else{let d=Math.sqrt(1+m-i-s)*2;p=[(l+a)/d,(f+c)/d,.25*d,(o-u)/d]}return Yr(p)}function ia(e,t,n){let[r,i,o,a]=n,u=1-2*(i*i+o*o),s=2*(r*i-o*a),c=2*(r*o+i*a),l=2*(r*i+o*a),f=1-2*(r*r+o*o),m=2*(i*o-r*a),h=2*(r*o-i*a),p=2*(i*o+r*a),d=1-2*(r*r+i*i);for(let y=0;y<3;y++){let T=t[y*4],S=t[y*4+1],b=t[y*4+2];e[y*4]=u*T+s*S+c*b,e[y*4+1]=l*T+f*S+m*b,e[y*4+2]=h*T+p*S+d*b}}function On(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],o=Math.hypot(n,r,i);return o>1e-9?[n/o,r/o,i/o]:null}function po(e){e?.normalMatrix&&e?.transform&&De(e.normalMatrix,e.transform)}var mo=new WeakMap;function oa(e){let t=mo.get(e);return t||(t=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((n,r)=>{for(let i of Array.isArray(n?.children)?n.children:[])typeof i=="number"&&i>=0&&i<t.length&&(t[i]=r)}),mo.set(e,t)),t}function sa(e,t,n){let r=e?.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let o=new Map;i.forEach((v,g)=>{typeof v?.name=="string"&&v.name&&!o.has(v.name)&&o.set(v.name,g)});let u=(t.mid?[t.root,t.mid,t.effector]:[t.root,t.effector]).map(v=>o.get(v));if(u.some(v=>v===void 0))return!1;let s=u,c=oa(r);for(let v=1;v<s.length;v++){let g=c[s[v]],M=0;for(;g>=0&&g!==s[v-1]&&M++<256;)g=c[g];if(g!==s[v-1])return!1}let l=s[0],f=e.initialNodeTransforms,m=new Map,h=[],p=[l];for(;p.length&&h.length<4096;){let v=p.pop();if(m.has(v))continue;let g=f?.[v],M=i[v];m.set(v,{t:g?[g.t[0],g.t[1],g.t[2]]:M?.translation?[...M.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:M?.rotation?[...M.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.s[2]]:M?.scale?[...M.scale]:[1,1,1]}),h.push(v);for(let k of Array.isArray(M?.children)?M.children:[])typeof k=="number"&&p.push(k)}let d=c[l],y=d>=0&&e.worldMatrices?.[d]?.length===16?Float32Array.from(e.worldMatrices[d]):Te(),T=new Map,S=()=>{let v=(g,M)=>{let k=m.get(g);if(!k)return;let R=Te();Qe(R,k.r,k.t,k.s);let B=Te();Re(B,M,R),T.set(g,B);for(let Z of Array.isArray(i[g]?.children)?i[g].children:[])typeof Z=="number"&&v(Z,B)};v(l,y)},b=v=>{let g=T.get(v);return[g[12],g[13],g[14]]};S();let A=s.map(b),w=v=>{if(typeof v=="string"&&!n.has(v)){let g=o.get(v),M=g!==void 0?T.get(g)??e.worldMatrices?.[g]:void 0;if(M&&M.length===16)return[M[12],M[13],M[14]]}return Wr(v,n,e)},P=w(t.target);if(!P)return!0;let N=t.pole?w(t.pole)??void 0:void 0,I=bo(A,t,P,N),_=fo(t.weight,0,1,1);for(let v=0;v<s.length-1;v++){let g=On(b(s[v]),b(s[v+1])),M=On(I[v],I[v+1]);if(!g||!M)continue;let k=na(Vn(g,M),_),R=s[v],B=c[R],Z=B===d||B<0?y:T.get(B)??y,j=ra(Z),ie=m.get(R);ie.r=Yr(Gr(ta(j),Gr(k,Gr(j,ie.r)))),S()}if(Array.isArray(e.worldMatrices))for(let[v,g]of T)e.worldMatrices[v]?.set&&e.worldMatrices[v].set(g);for(let v of e.meshes??[]){let g=T.get(v?.nodeIndex);g&&v.transform?.set&&(v.transform.set(g),po(v))}return!0}function bo(e,t,n,r){if(t.solver==="two-bone"&&e.length===3){let i=$r(e[0],e[1],e[2],n,r);return[e[0],i.midPos,i.effectorPos]}return qr(e,n,t.iterations,t.tolerance).positions}function aa(e,t,n){let r=e.__ikRestOffsets,i=e.__ikRestMats;if(!(!r||!i))for(let o=0;o<t.length-1;o++){let a=t[o]?.transform??t[o]?.modelMatrix,u=i[o],s=On([0,0,0],r[o]),c=On(n[o],n[o+1]);!a||a.length<16||!u||u.length<16||!s||!c||(ia(a,u,Vn(s,c)),po(t[o]))}}var jr={name:"ik",onRegister(){let e=ge();Nn(Hr),Hr(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let n=null;for(let r of t){let i=r?.userData?.xr?.ik??r?.extras?.xr?.ik??r?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let o=Zs(i);if(!o||o.weight<=0)continue;if(!n){n=new Map;for(let A of t)A&&typeof A.name=="string"&&A.name&&n.set(A.name,A)}if(sa(e,o,n))continue;let a=n.get(o.root),u=n.get(o.effector),s=o.mid?n.get(o.mid):void 0;if(a||zr(r,o.root),u||zr(r,o.effector),o.mid&&!s&&zr(r,o.mid),!a||!u)continue;let c=Wr(o.target,n,e);if(!c)continue;let l=o.pole?Wr(o.pole,n,e)??void 0:void 0,f=s?[a,s,u]:[a,u],m=f.map(A=>A.name||"").join(">");if(!r.__ikRestOffsets||r.__ikRestKey!==m){let A=f.map(Xr),w=[];for(let P=0;P<A.length-1;P++)w.push([A[P+1][0]-A[P][0],A[P+1][1]-A[P][1],A[P+1][2]-A[P][2]]);r.__ikRestOffsets=w,r.__ikRestKey=m,r.__ikRestMats=f.map(P=>Array.from(P.transform??P.modelMatrix??[]))}let h=r.__ikRestOffsets,d=[Xr(a)],y=[];for(let A=0;A<h.length;A++){let w=d[A],P=h[A];d.push([w[0]+P[0],w[1]+P[1],w[2]+P[2]]),y.push(Math.hypot(P[0],P[1],P[2]))}let T=bo(d,o,c,l),S=d[0],b=[d[0]];for(let A=1;A<f.length;A++){let w=h[A-1],P=[S[0]+w[0],S[1]+w[1],S[2]+w[2]],N=[S[0]+(T[A][0]-T[A-1][0]),S[1]+(T[A][1]-T[A-1][1]),S[2]+(T[A][2]-T[A-1][2])],I=Js(S,P,N,y[A-1],o.weight);Qs(f[A],I),S=I,b.push(I)}aa(r,f,b)}}};var ca={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function it(e,t,n,r){if(!n||n.bufferView===void 0)return null;let i=e.bufferViews?.[n.bufferView];if(!i)return null;let o=Number(n.count??0);if(!Number.isInteger(o)||o<=0)return null;let a=n.componentType??5126,u=ca[a];if(!u)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let s=u*r,c=i.byteStride&&i.byteStride>0?i.byteStride:s,l=(i.byteOffset||0)+(n.byteOffset||0);if(!Number.isInteger(l)||l<0||c<s||l+(o-1)*c+s>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&c===s&&l%4===0)return new Float32Array(t,l,o*r);let f=new DataView(t),m=n.normalized===!0,h=new Float32Array(o*r);for(let p=0;p<o;p++){let d=l+p*c;for(let y=0;y<r;y++){let T=d+y*u,S;switch(a){case 5126:S=f.getFloat32(T,!0);break;case 5120:S=f.getInt8(T),m&&(S=Math.max(S/127,-1));break;case 5121:S=f.getUint8(T),m&&(S/=255);break;case 5122:S=f.getInt16(T,!0),m&&(S=Math.max(S/32767,-1));break;case 5123:S=f.getUint16(T,!0),m&&(S/=65535);break;default:S=f.getUint32(T,!0),m&&(S/=4294967295)}h[p*r+y]=S}}return h}function yo(e,t){let n=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,i=Number(t.scale?.[0]??1),o=Number(t.scale?.[1]??1),a=Number(t.rotation??0)||0,u=Math.cos(a),s=Math.sin(a),c=(Number.isFinite(i)?i:1)*u,l=(Number.isFinite(i)?i:1)*s,f=-(Number.isFinite(o)?o:1)*s,m=(Number.isFinite(o)?o:1)*u;for(let h=0;h+1<e.length;h+=2){let p=e[h],d=e[h+1];e[h]=c*p+l*d+n,e[h+1]=f*p+m*d+r}}var To=["neutral","reinhard","none","aces","agx"];function _t(e){let t=String(e??"").trim().toLowerCase();return To.includes(t)?t:"neutral"}function ua(e){return To.indexOf(_t(e))}function la(e){return new TextDecoder().decode(e)}var Ao=ge().decoders;function ma(e,t){Ao.set(e.toLowerCase(),t)}function $t(e){return Ao.get(e.toLowerCase())}function wo(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,n=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let m=n.getUint8(0);throw m===123||m===32||m===10||m===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),a=12,u=null,s=null;for(;a+8<=o&&a+8<=t.byteLength;){let m=n.getUint32(a,!0),h=n.getUint32(a+4,!0),p=a+8;if(p+m>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+m} bytes, buffer has ${t.byteLength}`);if(h===1313821514){let d=new Uint8Array(t,p,m),y=la(d);u=JSON.parse(y,(T,S)=>T==="__proto__"||T==="constructor"||T==="prototype"?void 0:S)}else h===5130562&&(s=t.slice(p,p+m));a=p+m}if(!u)throw new Error("Missing JSON chunk in GLB");let c=u.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!$t("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(m)&&!$t("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!$t("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let l=s||new ArrayBuffer(0),f={gltf:u,bin:l,animations:[]};for(let m of Ne)m.onParseGLB?.(f);return f}function fa(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function ht(e){if(fa(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return wo(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Mo=`#version 300 es
|
|
18
19
|
layout(location=0) in vec3 aPosition;
|
|
19
20
|
layout(location=1) in vec3 aNormal;
|
|
20
21
|
layout(location=2) in vec2 aUV;
|
|
21
22
|
uniform mat4 uMVP,uModel;
|
|
22
23
|
uniform mat3 uNormalMatrix;
|
|
23
24
|
uniform vec4 uUvTransform;
|
|
25
|
+
layout(location=8) in vec4 aInst0;
|
|
26
|
+
layout(location=9) in vec4 aInst1;
|
|
27
|
+
layout(location=10) in vec4 aInst2;
|
|
28
|
+
layout(location=11) in vec4 aInst3;
|
|
29
|
+
layout(location=12) in vec4 aInstColor;
|
|
30
|
+
uniform int uInstanced;
|
|
31
|
+
uniform mat4 uViewProj;
|
|
32
|
+
out vec4 vInstTint;
|
|
33
|
+
mat4 xrModel(){return uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;}
|
|
34
|
+
mat4 xrMVP(){return uInstanced==1?uViewProj*xrModel():uMVP;}
|
|
35
|
+
mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):uNormalMatrix;}
|
|
36
|
+
#define uModel xrModel()
|
|
37
|
+
#define uMVP xrMVP()
|
|
38
|
+
#define uNormalMatrix xrNormalMatrix()
|
|
24
39
|
out vec3 vNormal,vWorldPos;
|
|
25
40
|
out vec2 vUV;
|
|
26
41
|
void main(){
|
|
42
|
+
vInstTint=uInstanced==1?aInstColor:vec4(1.0);
|
|
27
43
|
vec3 rawN=uNormalMatrix*aNormal;
|
|
28
44
|
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
29
45
|
vec4 world=uModel*vec4(aPosition,1.0);
|
|
@@ -32,12 +48,14 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
32
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
-
}`,
|
|
51
|
+
}`,ha=`#version 300 es
|
|
36
52
|
precision highp float;
|
|
37
53
|
in vec3 vNormal,vWorldPos;
|
|
38
54
|
in vec2 vUV;
|
|
39
55
|
uniform vec4 uBaseColor;
|
|
40
|
-
|
|
56
|
+
in vec4 vInstTint;
|
|
57
|
+
#define uBaseColor (uBaseColor*vInstTint)
|
|
58
|
+
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
41
59
|
uniform vec2 uClearcoat;
|
|
42
60
|
uniform vec3 uCameraPos,uAmbientColor;
|
|
43
61
|
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
|
|
@@ -108,9 +126,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
|
108
126
|
return mix(color,newPeak*vec3(1.0),g);
|
|
109
127
|
}
|
|
110
128
|
|
|
129
|
+
vec3 acesToneMapping(vec3 color){
|
|
130
|
+
color*=0.6;
|
|
131
|
+
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
vec3 agxToneMapping(vec3 color){
|
|
135
|
+
color=max(color,vec3(0.0));
|
|
136
|
+
vec3 inset=vec3(
|
|
137
|
+
0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
|
|
138
|
+
0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
|
|
139
|
+
0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
|
|
140
|
+
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
141
|
+
vec3 x2=ev*ev;
|
|
142
|
+
vec3 x4=x2*x2;
|
|
143
|
+
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
144
|
+
vec3 outset=vec3(
|
|
145
|
+
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
146
|
+
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
147
|
+
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
148
|
+
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
149
|
+
}
|
|
150
|
+
|
|
111
151
|
vec3 applyToneMapping(vec3 color,int mode){
|
|
112
152
|
if(mode==0)return neutralToneMapping(color);
|
|
113
153
|
if(mode==1)return color/(color+vec3(1.0));
|
|
154
|
+
if(mode==3)return acesToneMapping(color);
|
|
155
|
+
if(mode==4)return agxToneMapping(color);
|
|
114
156
|
return color;
|
|
115
157
|
}
|
|
116
158
|
|
|
@@ -194,19 +236,20 @@ if(uClearcoat.x>0.0){
|
|
|
194
236
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
195
237
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
196
238
|
}
|
|
239
|
+
color*=uExposure;
|
|
197
240
|
color=applyToneMapping(color,uToneMapping);
|
|
198
241
|
float outAlpha=base.a;
|
|
199
242
|
/*XRD_O*/
|
|
200
243
|
fragColor=vec4(color,outAlpha);
|
|
201
|
-
}
|
|
244
|
+
}`;function So(e,t,n=1){t=_t(t);let r=Number.isFinite(n)?Math.max(0,n):1,i=Math.max(0,(Number(e[0])||0)*r),o=Math.max(0,(Number(e[1])||0)*r),a=Math.max(0,(Number(e[2])||0)*r),u=T=>Math.max(0,Math.min(1,T));if(t==="none")return[u(i),u(o),u(a)];if(t==="reinhard")return[i/(i+1),o/(o+1),a/(a+1)];if(t==="aces"){let T=S=>{let b=S*.6;return u(b*(2.51*b+.03)/(b*(2.43*b+.59)+.14))};return[T(i),T(o),T(a)]}if(t==="agx"){let T=.84247906*i+.0784336*o+.07922375*a,S=.04232824*i+.87846864*o+.07916613*a,b=.04237565*i+.0784336*o+.87914297*a,A=g=>{let M=u((Math.log2(Math.max(g,1e-6))+12.47393)/16.5),k=M*M,R=k*k;return 15.5*R*k-40.14*R*M+31.96*R-6.868*k*M+.4298*k+.1191*M-.00232},w=A(T),P=A(S),N=A(b),I=1.196879*w-.09802088*P-.09902974*N,_=-.05289685*w+1.15190313*P-.09896118*N,v=-.05297164*w-.09804345*P+1.15107367*N;return[u(Math.pow(Math.max(I,0),2.2)),u(Math.pow(Math.max(_,0),2.2)),u(Math.max(0,Math.pow(Math.max(v,0),2.2)))]}let s=.76,c=.15,l=Math.min(i,o,a),f=l<.08?l-6.25*l*l:.04;i-=f,o-=f,a-=f;let m=Math.max(i,o,a);if(m<s)return[u(i),u(o),u(a)];let h=1-s,p=1-h*h/(m+h-s),d=p/m;i*=d,o*=d,a*=d;let y=1-1/(c*(m-p)+1);return[u(i+(p-i)*y),u(o+(p-o)*y),u(a+(p-a)*y)]}var da=`#version 300 es
|
|
202
245
|
layout(location=0) in vec3 aPosition;
|
|
203
246
|
uniform mat4 uMVP;
|
|
204
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
247
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,pa=`#version 300 es
|
|
205
248
|
precision highp float;
|
|
206
249
|
uniform vec4 uColorId;
|
|
207
250
|
out vec4 fragColor;
|
|
208
|
-
void main(){fragColor=uColorId;}`;function br(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 In(t,e,n){let r=br(t,35633,e),i=br(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let a=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${a}`)}return o}function Ln(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var yr=["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","uViewportSize","uSectionPlane","uSectionEnabled"];function Ar(){let t=ie().xrDepthShader;return{fs:Ri.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...yr,...t.uniformNames]:yr}}function Ei(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 Pn(t,e,n,r,i,o,a){if(r===void 0||!e.accessors?.[r])return null;let l=e.accessors[r],c=e.bufferViews[l.bufferView],s=(c.byteOffset||0)+(l.byteOffset||0),u=c.byteStride&&c.byteStride>o*4?c.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,c.byteOffset||0,Math.floor(c.byteLength/4)),d=(l.byteOffset||0)>>2;for(let p=0;p<l.count;p++){let x=d+p*u;for(let P=0;P<o;P++)m[p*o+P]=f[x+P]}}let h=t.createBuffer();return a.push(h),t.bindBuffer(34962,h),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var Sr=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 gr(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,a=[],l=Fe(i),c=[];if(Array.isArray(i.nodes))for(let w=0;w<i.nodes.length;w++){let R=i.nodes[w];R.mesh!==void 0&&i.meshes&&i.meshes[R.mesh]&&c.push({node:R,nodeIdx:w,meshIdx:R.mesh})}let s=c.length>0?c:(i.meshes||[]).map((w,R)=>({node:w,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 w=i.extensions.KHR_lights_punctual.lights;for(let R of w){let _=R.type==="directional"?"directional":R.type==="point"?"point":"ambient";u.push({type:_,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 w=0;w<i.textures.length;w++){let R=i.textures[w],_=i.images[R.source];if(_){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),_.bufferView!==void 0){let z=i.bufferViews[_.bufferView],D=o.slice(z.byteOffset||0,(z.byteOffset||0)+z.byteLength),C=new Blob([D],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(C).then(G=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,G),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let z=Ei(_.uri);if(z){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,D),t.generateMipmap(3553),r?.()},D.src=z}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.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,p=0;for(let w=0;w<s.length;w++){let R=s[w],_=i.meshes[R.meshIdx],B=R.nodeIdx>=0?l[R.nodeIdx]:se(),z=new Float32Array(9);de(z,B);let D={name:R.node.name||_.name||`Mesh_${R.meshIdx}`,nodeIndex:R.nodeIdx,transform:B,normalMatrix:z,primitives:[],extras:R.node.extras||_.extras};for(let C of _.primitives||[]){if(C.extensions?.KHR_draco_mesh_compression){let te=it("draco");te&&te.decodePrimitive(i,C,o)}let G=[],V=t.createVertexArray();t.bindVertexArray(V);let J=i.accessors[C.attributes.POSITION],j=Number(J?.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,J?.min&&J?.max)for(let te=0;te<3;te++){let he=B[12+te],Ee=B[12+te];for(let De=0;De<3;De++){let _t=B[De*4+te]*J.min[De],Ct=B[De*4+te]*J.max[De];he+=_t<Ct?_t:Ct,Ee+=_t>Ct?_t:Ct}he<h[te]&&(h[te]=he),Ee>f[te]&&(f[te]=Ee)}let H=Pn(t,i,o,C.attributes.POSITION,0,3,G);Pn(t,i,o,C.attributes.NORMAL,1,3,G),Pn(t,i,o,C.attributes.TEXCOORD_0,2,2,G);let X=0,N=5123,$=null;if(C.indices!==void 0){let te=i.accessors[C.indices],Ee=(i.bufferViews[te.bufferView].byteOffset||0)+(te.byteOffset||0);if(X=Number(te.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,N=te.componentType===5125?5125||5125:5123||5123;let De=t.createBuffer();G.push(De),t.bindBuffer(34963,De),te.componentType===5125?($=new Uint32Array(o,Ee,te.count),t.bufferData(34963,$,35044)):($=new Uint16Array(o,Ee,te.count),t.bufferData(34963,$,35044))}else X=J.count;let Y={};for(let te of ue)if(te.onBuildPrimitiveVAO){let he=te.onBuildPrimitiveVAO(t,V,C,i,o);he&&(Y[te.name]=he)}t.bindVertexArray(null);let T=i.materials&&C.material!==void 0?i.materials[C.material]:null,A=Ar(),S=wr,k=A.fs,M=!1;for(let te of ue)if(te.onResolveShader){let he=te.onResolveShader(C,T,S,k);he&&(S=he.vs,k=he.fs,M=!0)}let L=M?In(t,S,k):null,F=L?Ln(t,L,A.uniforms):null,U=T?.pbrMetallicRoughness,K=U?.baseColorFactor||[.8,.8,.8,1],Z=U?.metallicFactor??.1,Q=U?.roughnessFactor??.5,O=T?.extensions?.KHR_materials_clearcoat,q=O?O.clearcoatFactor??1:0,ee=Math.max(.04,O?.clearcoatRoughnessFactor??.04),ae=U?.baseColorTexture!==void 0&&m[U.baseColorTexture.index]?m[U.baseColorTexture.index]:null,Ve=U?.metallicRoughnessTexture!==void 0&&m[U.metallicRoughnessTexture.index]?m[U.metallicRoughnessTexture.index]:null,pe=T?.normalTexture!==void 0&&m[T.normalTexture.index]?m[T.normalTexture.index]:null,ce=T?.normalTexture?.scale??1,Le=T?.occlusionTexture!==void 0&&m[T.occlusionTexture.index]?m[T.occlusionTexture.index]:null,xe=T?.occlusionTexture?.strength??1,ve=!!(T?.extensions?.KHR_materials_transmission||Y.materials?.isTransmissive);D.primitives.push({vao:V,indexCount:X,indexType:N,baseColor:K,metallic:Z,roughness:Q,clearcoat:q,clearcoatRoughness:ee,positions:H,indices:$,texture:ae,metallicRoughnessTexture:Ve,normalTexture:pe,occlusionTexture:Le,normalScale:ce,occlusionStrength:xe,buffers:G,materialIndex:C.material,pluginData:Y,customProgram:L,customUniforms:F,isTransmissive:ve})}a.push(D)}isFinite(h[0])||(h=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let x=[(h[0]+f[0])/2,(h[1]+f[1])/2,(h[2]+f[2])/2],P=f[0]-h[0],E=f[1]-h[1],y=f[2]-h[2],v=Math.max(Math.hypot(P,E,y)/2,.5),g=[h[0],h[1],h[2]],I=[f[0],f[1],f[2]],b=e.animations;if(!b){for(let w of ue)if(w.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:a,bounds:{center:x,radius:v,min:g,max:I},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=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.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:se(),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 s=e.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",e.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(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;let c=Ar();this.renderProg=In(l,wr,c.fs),this.pickProg=In(l,Ti,Mi),this.uRender=Ln(l,this.renderProg,c.uniforms),this.uPick=Ln(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){Ai(e,n)}static getDecoder(e){return it(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:a,worldMatrices:l}=gr(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=a||[],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 ue)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 c=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c))),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(vr(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(ke(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=ke(e),{meshes:i}=gr(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=[],a=[],l=[];for(let c of this.lights){let s=c.color||[1,1,1],u=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")r=[s[0]*u,s[1]*u,s[2]*u];else if(c.type==="directional"&&i.length<6){let m=c.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(c.type==="point"&&a.length<6){let m=c.position||[0,0,0];a.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,a.length/3),a.length>0&&(n.uniform3fv(e.uPointLightPos,a),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 ue)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ue)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],a=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,c=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:a,metallicFactor:l,roughnessFactor:c,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 ue)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=se();be(r,this.projMatrix,this.viewMatrix);let[i,o,a]=e,l=n?n[0]:0,c=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],a=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],c=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]*a+r[12],h=r[1]*i+r[5]*o+r[9]*a+r[13],f=r[2]*i+r[6]*o+r[10]*a+r[14],d=r[3]*i+r[7]*o+r[11]*a+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=m/d,x=h/d,P=f/d,E=this.canvas.getBoundingClientRect(),y=E.width||this.canvas.clientWidth||this.canvas.width||300,v=E.height||this.canvas.clientHeight||this.canvas.height||150,g=(p*.5+.5)*y,I=(-x*.5+.5)*v,b=p>=-1.1&&p<=1.1&&x>=-1.1&&x<=1.1&&P>=-1&&P<=1;if(b&&n){let w=this.customTarget||this.bounds.center,R=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=w[1]+this.currDistance*Math.sin(this.currPhi),B=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),z=[i-R,o-_,a-B];l*z[0]+c*z[1]+s*z[2]>.05&&(b=!1)}return{x:g,y:I,z:P,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 a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-i*a[0]+o*l[0])*s,c[1]+=(-i*a[1]+o*l[1])*s,c[2]+=(-i*a[2]+o*l[2])*s,this.customTarget=c}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,a=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),c=i.height>0?Math.floor((n-i.top)*(a/i.height)):Math.floor(n);return this.performMeshPick(l,c,!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),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=se();be(l,this.projMatrix,this.viewMatrix);let c=[],s=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(a-1,a-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==a)&&this.resizePickingFbo(o,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,a),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 w=this.meshes[b];if(w.visible===!1||w.isPluginMesh)continue;let R=b+1,_=(R&255)/255,B=(R>>8&255)/255,z=(R>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,B,z,1),be(this.modelMatrix,this.modelRootMatrix,w.transform),be(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let D of w.primitives)i.bindVertexArray(D.vao),i.drawElements(4,D.indexCount,D.indexType,0)}let g=new Uint8Array(4);i.readPixels(s,u,1,1,6408,5121,g),i.bindFramebuffer(36160,null);let I=g[0]+(g[1]<<8)+(g[2]<<16);I>0&&I<=this.meshes.length&&(c=[this.meshes[I-1]])}c.length===0&&(c=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,x=p[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=p[1]+this.currDistance*Math.sin(this.currPhi),E=p[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let g of c){be(this.modelMatrix,this.modelRootMatrix,g.transform),be(this.mvpMatrix,l,this.modelMatrix);let I=se();if(!kt(I,this.mvpMatrix))continue;let b=(s+.5)/o*2-1,w=(u+.5)/a*2-1,R=[0,0,0],_=[0,0,0];Cn(R,b,w,-1,I),Cn(_,b,w,1,I);let B=_[0]-R[0],z=_[1]-R[1],D=_[2]-R[2],C=Math.hypot(B,z,D)||1,G=B/C,V=z/C,J=D/C,j={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((X=>{for(let N of g.primitives){if(!N.positions)continue;let $=N.positions,Y=N.indices,T=Math.floor(Y?Y.length/3:$.length/9);for(let A=0;A<T;A++){let S=Y?Y[A*3]:A*3,k=Y?Y[A*3+1]:A*3+1,M=Y?Y[A*3+2]:A*3+2;pr(R[0],R[1],R[2],G,V,J,$[S*3],$[S*3+1],$[S*3+2],$[k*3],$[k*3+1],$[k*3+2],$[M*3],$[M*3+1],$[M*3+2],j,X)}}})(1e-4),isFinite(j.distance)){let X=j.point[0],N=j.point[1],$=j.point[2],Y=this.modelMatrix,T=Y[0]*X+Y[4]*N+Y[8]*$+Y[12],A=Y[1]*X+Y[5]*N+Y[9]*$+Y[13],S=Y[2]*X+Y[6]*N+Y[10]*$+Y[14],k=T-x,M=A-P,L=S-E,F=Math.hypot(k,M,L);if(F<h){de(this.normalMatrix,this.modelMatrix);let U=this.normalMatrix,K=j.normal[0],Z=j.normal[1],Q=j.normal[2],O=U[0]*K+U[3]*Z+U[6]*Q,q=U[1]*K+U[4]*Z+U[7]*Q,ee=U[2]*K+U[5]*Z+U[8]*Q,ae=Math.hypot(O,q,ee)||1;O/=ae,q/=ae,ee/=ae,O*k+q*M+ee*L>0&&(O=-O,q=-q,ee=-ee),m=g,h=Math.round(F*1e3)/1e3,f=[Math.round(T*1e3)/1e3,Math.round(A*1e3)/1e3,Math.round(S*1e3)/1e3],d=[Math.round(O*1e3)/1e3,Math.round(q*1e3)/1e3,Math.round(ee*1e3)/1e3]}}}if(!m)return null;let v={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 ue)g.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(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,a=i?Math.max(1,n-r):r,l=(o+.5)/a*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);Ft(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),a=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);qe(this.viewMatrix,[i,o,a],r,[0,1,0]),be(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 ue)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 ue)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 a of ue)a.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 a of ue)a.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let 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 a={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,n,r,i,o=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,c=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:c,eyePos:u,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),g=Math.max(1,this.canvas.height||1),I=Math.max(1,Math.floor(v*.5)),b=Math.max(1,v-I),w=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),R=this.customTarget||this.bounds.center,_=R[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),B=R[1]+this.currDistance*Math.sin(this.currPhi),z=R[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),D=Math.cos(this.currTheta),C=-Math.sin(this.currTheta),G=.032,V=se(),J=se(),j=[_-D*G,B,z-C*G],H=[R[0]-D*G*.25,R[1],R[2]-C*G*.25];Ft(V,this.fov,I/g,.1,w),qe(J,j,H,[0,1,0]);let X=se(),N=se(),$=[_+D*G,B,z+C*G],Y=[R[0]+D*G*.25,R[1],R[2]+C*G*.25];Ft(X,this.fov,b/g,.1,w),qe(N,$,Y,[0,1,0]),this.render({viewMatrix:J,projMatrix:V,eyePos:j,viewport:[0,0,I,g],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:N,projMatrix:X,eyePos:$,viewport:[I,0,b,g],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,g);return}let n=this.gl,r=0,i=0,o=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],a=e.viewport[3],n.viewport(r,i,o,a)):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=se(),c=e?.viewMatrix??this.viewMatrix;be(l,e?.projMatrix??this.projMatrix,c);let s=ie().xrDepthShader,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 v of ue)v.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 x=e?.eye||"none",P=!1,E=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=v=>{for(let g=0;g<E.length;g++){let I=E[g];if(I.visible===!1)continue;let b=this.selectedMeshName!==""&&I.name===this.selectedMeshName;g<p||I.worldSpace===!0||I.name==="__xr_reticle__"?this.modelMatrix.set(I.transform):be(this.modelMatrix,this.modelRootMatrix,I.transform),be(this.mvpMatrix,l,this.modelMatrix),de(I.normalMatrix,this.modelMatrix);let w=I.extras?.xr?.stereo||I.userData?.xr?.stereo,R=0,_=0,B=1,z=1;w==="sbs"?(B=.5,R=x==="right"?.5:0):w==="ou"&&(z=.5,_=x==="right"?.5:0);for(let D of I.primitives){let C=!!D.isTransmissive;if(!v&&C){P=!0;continue}if(v&&!C)continue;let G=D.customProgram||this.renderProg,V=D.customUniforms||this.uRender;n.useProgram(G),n.uniform1i(V.uToneMapping,u),n.uniform1f(V.uEnvIntensity,this.envIntensity),n.uniform3f(V.uCameraPos,h,f,d),n.uniform1f(V.uEmissive,b?1:0),n.uniformMatrix4fv(V.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(V.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(V.uNormalMatrix,!1,I.normalMatrix),V.uUvTransform&&n.uniform4f(V.uUvTransform,R,_,B,z),V.uViewportSize&&n.uniform2f(V.uViewportSize,Math.max(1,o),Math.max(1,a)),s?.bind(n,V,this.xrDepthState,c,[r,i,Math.max(1,o),Math.max(1,a)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(V.uEnvironmentMap,4),n.uniform1i(V.uHasEnvironmentMap,1)):n.uniform1i(V.uHasEnvironmentMap,0),this.bindLights(V),V.uSectionEnabled&&n.uniform1i(V.uSectionEnabled,0);for(let J of ue)J.onBeforeDrawPrimitive?.(n,G,D,I,this.worldMatrices||[],this.gltf);n.uniform4fv(V.uBaseColor,D.baseColor),n.uniform1f(V.uMetallic,D.metallic),n.uniform1f(V.uRoughness,D.roughness),V.uClearcoat&&n.uniform2f(V.uClearcoat,D.clearcoat??0,D.clearcoatRoughness??.04),D.texture?(n.activeTexture(33984),n.bindTexture(3553,D.texture),n.uniform1i(V.uBaseColorTexture,0),n.uniform1i(V.uHasTexture,1)):n.uniform1i(V.uHasTexture,0),D.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,D.metallicRoughnessTexture),n.uniform1i(V.uMetallicRoughnessTexture,1),n.uniform1i(V.uHasMetallicRoughnessTexture,1)):n.uniform1i(V.uHasMetallicRoughnessTexture,0),D.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,D.normalTexture),n.uniform1i(V.uNormalTexture,2),n.uniform1i(V.uHasNormalTexture,1),n.uniform1f(V.uNormalScale,D.normalScale)):n.uniform1i(V.uHasNormalTexture,0),D.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,D.occlusionTexture),n.uniform1i(V.uOcclusionTexture,3),n.uniform1i(V.uHasOcclusionTexture,1),n.uniform1f(V.uOcclusionStrength,D.occlusionStrength)):n.uniform1i(V.uHasOcclusionTexture,0),n.bindVertexArray(D.vao),n.drawElements(4,D.indexCount,D.indexType,0)}}};if(y(!1),P){for(let v of ue)v.onBeforeTransmissivePass?.(n,this);y(!0)}for(let v of ue)v.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 ue)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=ge,fe.getRegisteredPlugins=Dt;function _i(t){return t+3&-4}function Ci(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 je(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],a=[],l=[],c=new Set,s=[],u=[],m=new Map,h=[];function f(b,w){let R=new Uint8Array(b.buffer,b.byteOffset,b.byteLength),_=_i(R.byteLength),B=new Uint8Array(_);B.set(R),n.push(B);let z=i.length;return i.push({buffer:0,byteOffset:r,byteLength:R.byteLength,target:w}),r+=_,z}function d(b,w,R,_,B,z,D){let C=f(b,R),G=o.length,V={bufferView:C,byteOffset:0,componentType:_,count:B,type:w};return z&&(V.min=z),D&&(V.max=D),o.push(V),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 x(b){let w={name:b.name||""},R=b.position,_=b.quaternion,B=b.scale;if((R.x||R.y||R.z)&&(w.translation=[R.x,R.y,R.z]),(_.x||_.y||_.z||_.w!==1)&&(w.rotation=[_.x,_.y,_.z,_.w]),(B.x!==1||B.y!==1||B.z!==1)&&(w.scale=[B.x,B.y,B.z]),b.userData&&Object.keys(b.userData).length>0&&(w.extras=JSON.parse(JSON.stringify(b.userData,(D,C)=>{if(!(D==="__proto__"||D==="prototype"||D==="constructor"))return typeof C=="function"?void 0:C})),b.userData.xr)){let D=Ci(b.userData.xr);w.extensions={...w.extensions||{},MOZ_hubs_components:D,ANDROID_xr_scenecore:D},ie().xrTraitSerializer?.gltfNode(w,b.userData.xr),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(b.geometry){let D=b.geometry,C=D.attributes.position;if(C&&C.count>0){let G=[1/0,1/0,1/0],V=[-1/0,-1/0,-1/0];for(let X=0;X<C.count;X++){let N=C.getX(X),$=C.getY(X),Y=C.getZ(X);N<G[0]&&(G[0]=N),N>V[0]&&(V[0]=N),$<G[1]&&(G[1]=$),$>V[1]&&(V[1]=$),Y<G[2]&&(G[2]=Y),Y>V[2]&&(V[2]=Y)}let j={attributes:{POSITION:d(C.array,"VEC3",34962,5126,C.count,G,V)}};if(D.attributes.normal&&(j.attributes.NORMAL=d(D.attributes.normal.array,"VEC3",34962,5126,D.attributes.normal.count)),D.attributes.uv&&(j.attributes.TEXCOORD_0=d(D.attributes.uv.array,"VEC2",34962,5126,D.attributes.uv.count)),D.index){let X=D.index.array instanceof Uint32Array;j.indices=d(D.index.array,"SCALAR",34963,X?5125:5123,D.index.count)}if(b.material){let X=m.get(b.material);if(X===void 0){X=u.length,m.set(b.material,X);let N=b.material,$={name:N.name||"",pbrMetallicRoughness:{baseColorFactor:[N.color.r,N.color.g,N.color.b,N.opacity],metallicFactor:N.metalness,roughnessFactor:N.roughness},doubleSided:N.side===2||N.doubleSided};if(N.emissive&&(N.emissive.r>0||N.emissive.g>0||N.emissive.b>0)){let T=N.emissiveIntensity??1;$.emissiveFactor=[N.emissive.r*T,N.emissive.g*T,N.emissive.b*T]}let Y={};N.clearcoat>0&&(Y.KHR_materials_clearcoat={clearcoatFactor:N.clearcoat,clearcoatRoughnessFactor:N.clearcoatRoughness||0}),N.sheen>0&&(Y.KHR_materials_sheen={sheenColorFactor:N.sheenColor?[N.sheenColor.r,N.sheenColor.g,N.sheenColor.b]:[1,1,1],sheenRoughnessFactor:N.sheenRoughness||0}),N.transmission>0&&(Y.KHR_materials_transmission={transmissionFactor:N.transmission}),N.thickness>0&&(Y.KHR_materials_volume={thicknessFactor:N.thickness,attenuationDistance:N.attenuationDistance??1/0,attenuationColor:N.attenuationColor?[N.attenuationColor.r,N.attenuationColor.g,N.attenuationColor.b]:[1,1,1]}),N.ior!==void 0&&N.ior!==1.5&&(Y.KHR_materials_ior={ior:N.ior}),N.dispersion>0&&(Y.KHR_materials_dispersion={dispersion:N.dispersion}),N.iridescence>0&&(Y.KHR_materials_iridescence={iridescenceFactor:N.iridescence,iridescenceIor:N.iridescenceIOR??1.3}),Object.keys(Y).length>0&&($.extensions=Y),u.push($)}j.material=X}let H=a.length;a.push({primitives:[j],name:b.name,...w.extras?{extras:w.extras}:{}}),w.mesh=H}}let z=l.length;if(l.push(w),s.push(b),b.children.length>0){w.children=[];for(let D of b.children)w.children.push(x(D))}return z}for(let b of t.children)p.push(x(b));let P=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),E=[];if(typeof P=="function"&&s.length>0){let b=e?.duration??4,w=e?.fps??15,R=Math.max(2,Math.round(b*w)+1),_=new Float32Array(R),B=s.map(H=>({px:H.position.x,py:H.position.y,pz:H.position.z,qx:H.quaternion.x,qy:H.quaternion.y,qz:H.quaternion.z,qw:H.quaternion.w,sx:H.scale.x,sy:H.scale.y,sz:H.scale.z})),z=s.map(()=>new Float32Array(R*3)),D=s.map(()=>new Float32Array(R*4)),C=s.map(()=>new Float32Array(R*3));for(let H=0;H<R;H++){let X=H/(R-1)*b;_[H]=X;try{P(X)}catch{}for(let N=0;N<s.length;N++){let $=s[N];z[N][H*3]=$.position.x,z[N][H*3+1]=$.position.y,z[N][H*3+2]=$.position.z,D[N][H*4]=$.quaternion.x,D[N][H*4+1]=$.quaternion.y,D[N][H*4+2]=$.quaternion.z,D[N][H*4+3]=$.quaternion.w,C[N][H*3]=$.scale.x,C[N][H*3+1]=$.scale.y,C[N][H*3+2]=$.scale.z}}for(let H=0;H<s.length;H++){let X=s[H],N=B[H];X.position.set(N.px,N.py,N.pz),X.quaternion.set(N.qx,N.qy,N.qz,N.qw),X.scale.set(N.sx,N.sy,N.sz)}t.updateMatrixWorld(!0);let G=null,V=()=>(G===null&&(G=d(_,"SCALAR",0,5126,R,[0],[b])),G),J=[],j=[];for(let H=0;H<s.length;H++){let X=B[H],N=!1,$=!1,Y=!1;for(let T=0;T<R;T++)(Math.abs(z[H][T*3]-X.px)>1e-4||Math.abs(z[H][T*3+1]-X.py)>1e-4||Math.abs(z[H][T*3+2]-X.pz)>1e-4)&&(N=!0),(Math.abs(D[H][T*4]-X.qx)>1e-4||Math.abs(D[H][T*4+1]-X.qy)>1e-4||Math.abs(D[H][T*4+2]-X.qz)>1e-4||Math.abs(D[H][T*4+3]-X.qw)>1e-4)&&($=!0),(Math.abs(C[H][T*3]-X.sx)>1e-4||Math.abs(C[H][T*3+1]-X.sy)>1e-4||Math.abs(C[H][T*3+2]-X.sz)>1e-4)&&(Y=!0);if(N){let T=d(z[H],"VEC3",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"translation"}})}if($){let T=d(D[H],"VEC4",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"rotation"}})}if(Y){let T=d(C[H],"VEC3",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"scale"}})}}j.length>0&&E.push({name:"ProceduralLoop",samplers:J,channels:j})}let y=fr(l,a,t.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:p}],scene:0,nodes:l,meshes:a,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...y||c.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...c]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},g=new Uint8Array(r),I=0;for(let b of n)g.set(b,I),I+=b.byteLength;return{gltf:v,bin:g.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function Ut(t){return new TextEncoder().encode(t)}function ot(t,e){let{gltf:n,bin:r}=je(t,e),i=JSON.stringify(n),o=Ut(i),a=(4-o.byteLength%4)%4,l=o.byteLength+a,c=20+l+8+r.byteLength,s=new Uint8Array(c),u=new DataView(s.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,c,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),s.set(o,20);for(let h=0;h<a;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 Pi(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 a=o.count,l=new Float32Array(a*3),c=r.matrixWorld.elements;for(let b=0;b<a;b++){let w=o.getX(b),R=o.getY(b),_=o.getZ(b);l[b*3]=c[0]*w+c[4]*R+c[8]*_+c[12],l[b*3+1]=c[1]*w+c[5]*R+c[9]*_+c[13],l[b*3+2]=c[2]*w+c[6]*R+c[10]*_+c[14]}let s;if(i.attributes.normal){let b=i.attributes.normal;s=new Float32Array(a*3);let w=new Float32Array(9);de(w,c);for(let R=0;R<a;R++){let _=b.getX(R),B=b.getY(R),z=b.getZ(R),D=w[0]*_+w[3]*B+w[6]*z,C=w[1]*_+w[4]*B+w[7]*z,G=w[2]*_+w[5]*B+w[8]*z,V=Math.hypot(D,C,G)||1;s[R*3]=D/V,s[R*3+1]=C/V,s[R*3+2]=G/V}}let u;if(i.attributes.uv){let b=i.attributes.uv;u=new Float32Array(a*2);for(let w=0;w<a;w++)u[w*2]=b.getX(w),u[w*2+1]=b.getY(w)}let m;if(i.index)m=i.index.array;else{m=a>65535?new Uint32Array(a):new Uint16Array(a);for(let b=0;b<a;b++)m[b]=b}let h="DefaultMaterial",f=[.8,.8,.8],d=.5,p=.1,x=0,P=0,E=1.5,y=1,v=[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"&&(x=b.clearcoat),typeof b.clearcoatRoughness=="number"&&(P=b.clearcoatRoughness),typeof b.ior=="number"&&(E=b.ior);let w=typeof b.opacity=="number"?b.opacity:1,R=typeof b.transmission=="number"?b.transmission:0;if(y=w*(1-R),b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let _=b.emissiveIntensity??1;v=[b.emissive.r*_,b.emissive.g*_,b.emissive.b*_]}}let g,I=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 I=="function"){let b=e?.duration??4,w=e?.fps??4,R=Math.max(2,Math.round(b*w)+1),_=[],B=[],z=[],D=[],C=[r.position.x,r.position.y,r.position.z],G=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],V=[r.scale.x,r.scale.y,r.scale.z],J=!1;for(let j=0;j<R;j++){let H=j/(R-1)*b;_.push(H);try{I(H)}catch{}B.push([r.position.x,r.position.y,r.position.z]),z.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),D.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-C[0])>1e-4||Math.abs(r.position.y-C[1])>1e-4||Math.abs(r.position.z-C[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-V[0])>1e-4)&&(J=!0)}r.position.set(C[0],C[1],C[2]),r.quaternion.set(G[0],G[1],G[2],G[3]),r.scale.set(V[0],V[1],V[2]),J&&(g={times:_,translations:B,rotations:z,scales:D})}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:x,clearcoatRoughness:P,ior:E,opacity:y,emissiveColor:v,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||[],a=n.bufferViews||[],l=n.materials||[],c=n.meshes||[],s=n.nodes||[];function u(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let p=a[d.bufferView||0],x=(p.byteOffset||0)+(d.byteOffset||0),P=p.byteLength||0,E=i.slice(x,x+P);return{acc:d,buffer:E}}let m=new Map;if(s.length>0){let f=Fe(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function h(f,d,p,x){let P=c[f];if(!P)return;let E=new Float32Array(9);de(E,d);for(let y=0;y<(P.primitives||[]).length;y++){let v=P.primitives[y],g=v.attributes?.POSITION;if(g===void 0)continue;let{acc:I,buffer:b}=u(g),w=new Float32Array(b,0,I.count*3),R=new Float32Array(w.length);for(let A=0;A<I.count;A++){let S=w[A*3],k=w[A*3+1],M=w[A*3+2];R[A*3]=d[0]*S+d[4]*k+d[8]*M+d[12],R[A*3+1]=d[1]*S+d[5]*k+d[9]*M+d[13],R[A*3+2]=d[2]*S+d[6]*k+d[10]*M+d[14]}let _,B=v.attributes?.NORMAL;if(B!==void 0){let{acc:A,buffer:S}=u(B),k=new Float32Array(S,0,A.count*3);_=new Float32Array(k.length);for(let M=0;M<A.count;M++){let L=k[M*3],F=k[M*3+1],U=k[M*3+2],K=E[0]*L+E[3]*F+E[6]*U,Z=E[1]*L+E[4]*F+E[7]*U,Q=E[2]*L+E[5]*F+E[8]*U,O=Math.hypot(K,Z,Q)||1;_[M*3]=K/O,_[M*3+1]=Z/O,_[M*3+2]=Q/O}}let z,D=v.attributes?.TEXCOORD_0;if(D!==void 0){let{acc:A,buffer:S}=u(D);z=new Float32Array(S,0,A.count*2)}let C;if(v.indices!==void 0){let{acc:A,buffer:S}=u(v.indices);A.componentType===5125?C=new Uint32Array(S,0,A.count):C=new Uint16Array(S,0,A.count);let k=I.count;for(let M of C)if(M>=k)throw new Error(`SecurityError: Index buffer value (${M}) out of vertex bounds [0, ${k}).`)}else{let A=I.count;C=A>65535?new Uint32Array(A):new Uint16Array(A);for(let S=0;S<A;S++)C[S]=S}let G="DefaultMaterial",V=[.8,.8,.8],J=.5,j=.1,H=0,X=0,N=1.5,$=1,Y=[0,0,0];if(v.material!==void 0&&l[v.material]){let A=l[v.material];G=A.name||`Material_${v.material}`;let S=A.pbrMetallicRoughness||{},k=1;Array.isArray(S.baseColorFactor)&&(V=[S.baseColorFactor[0],S.baseColorFactor[1],S.baseColorFactor[2]],typeof S.baseColorFactor[3]=="number"&&(k=S.baseColorFactor[3])),typeof S.roughnessFactor=="number"&&(J=S.roughnessFactor),typeof S.metallicFactor=="number"&&(j=S.metallicFactor),Array.isArray(A.emissiveFactor)&&A.emissiveFactor.length>=3&&(Y=[A.emissiveFactor[0],A.emissiveFactor[1],A.emissiveFactor[2]]);let M=A.extensions||{};M.KHR_materials_clearcoat&&(H=M.KHR_materials_clearcoat.clearcoatFactor??0,X=M.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),M.KHR_materials_ior&&typeof M.KHR_materials_ior.ior=="number"&&(N=M.KHR_materials_ior.ior);let L=M.KHR_materials_transmission?.transmissionFactor??0;$=k*(1-L)}let T=(P.primitives||[]).length>1?`${p}_p${y}`:p;e.push({name:T,positions:R,indices:C,normals:_,uvs:z,materialName:G,color:V,roughness:J,metallic:j,clearcoat:H,clearcoatRoughness:X,ior:N,opacity:$,emissiveColor:Y,xrTraits:x?.xr||P.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<c.length){let p=m.get(f)||se(),x=d.name||c[d.mesh].name||`Node_${f}`;h(d.mesh,p,x,d.extras)}}else{let f=se();for(let d=0;d<c.length;d++){let p=c[d].name||`Mesh_${d}`;h(d,f,p,c[d].extras)}}return e}function Dn(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 ne(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 Mr(t){let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ne(t[r*3])}, ${ne(t[r*3+1])}, ${ne(t[r*3+2])})`;return n.join(", ")}function Ii(t,e){let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ne(t[r*2])}, ${ne(1-t[r*2+1])})`;return n.join(", ")}function Li(t){return Array.from(t).join(", ")}function Fn(t){let e=new Map;for(let c of t){let s=Dn(c.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:c.color||[.8,.8,.8],roughness:c.roughness??.5,metallic:c.metallic??0,clearcoat:c.clearcoat??0,clearcoatRoughness:c.clearcoatRoughness??0,ior:c.ior??1.5,opacity:c.opacity??1,emissiveColor:c.emissiveColor||[0,0,0]})}let n=0,r=null;for(let c of t){if(c.timeSamples&&c.timeSamples.times.length>0){let s=c.timeSamples.times[c.timeSamples.times.length-1];s>n&&(n=s)}c.xrTraits?.anchor&&!r&&(r=c.xrTraits.anchor==="vertical"||c.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
209
|
-
endTimeCode = ${
|
|
251
|
+
void main(){fragColor=uColorId;}`;function go(e,t,n){let r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,35713)){let i=e.getShaderInfoLog(r);throw e.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Qr(e,t,n){let r=go(e,35633,t),i=go(e,35632,n),o=e.createProgram();if(e.attachShader(o,r),e.attachShader(o,i),e.linkProgram(o),!e.getProgramParameter(o,35714)){let a=e.getProgramInfoLog(o);throw e.deleteProgram(o),new Error(`Program link error: ${a}`)}return o}function Jr(e,t,n){let r={};for(let i of n)r[i]=e.getUniformLocation(t,i);return r}var xo=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Eo(){let e=ge().xrDepthShader;return{fs:ha.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...xo,...e.uniformNames]:xo}}function ba(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let n=t.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:n.startsWith("https://")||n.startsWith("blob:")?t:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Kr(e,t,n,r,i,o,a,u){if(r===void 0||!t.accessors?.[r])return null;let s=it(t,n,t.accessors[r],o);if(!s)return null;u&&(s=s.slice(),yo(s,u));let c=e.createBuffer();return a.push(c),e.bindBuffer(34962,c),e.bufferData(34962,s,35044),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,o,5126,!1,0,0),s}function Zr(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function Ro(e,t,n){let r=Eo(),i=Mo,o=r.fs,a=!1;for(let s of Ne)if(s.onResolveShader){let c=s.onResolveShader(t,n,i,o);c&&(i=c.vs,o=c.fs,a=!0)}let u=a?Qr(e,i,o):null;return{program:u,uniforms:u?Jr(e,u,r.uniforms):null}}function ya(e,t,n){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=t.instanceColors,a=new Float32Array(i*20);for(let s=0;s<i;s++)a.set(r.subarray(s*16,s*16+16),s*20),a[s*20+16]=o?o[s*3]:1,a[s*20+17]=o?o[s*3+1]:1,a[s*20+18]=o?o[s*3+2]:1,a[s*20+19]=1;let u=e.createBuffer();n.push(u),e.bindBuffer(34962,u),e.bufferData(34962,a,35044);for(let s=0;s<5;s++)e.enableVertexAttribArray(8+s),e.vertexAttribPointer(8+s,4,5126,!1,80,s*16),e.vertexAttribDivisor(8+s,1);return!0}function ga(e,t){let n=e.materials?.[t?.material];if(!n)return null;let r=[n.pbrMetallicRoughness?.baseColorTexture,n.pbrMetallicRoughness?.metallicRoughnessTexture,n.normalTexture,n.occlusionTexture,n.emissiveTexture];for(let i of r){let o=i?.extensions?.KHR_texture_transform;if(o&&typeof o=="object")return o}return null}var _o=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Io=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Bn(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function Co(e,t){let n=e?.pbrMetallicRoughness,r=n?.baseColorFactor,i=e?.extensions?.KHR_materials_clearcoat,o=a=>a!==void 0&&t[a.index]?t[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:n?.metallicFactor??.1,roughness:n?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:o(n?.baseColorTexture),metallicRoughnessTexture:o(n?.metallicRoughnessTexture),normalTexture:o(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:o(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Lo(e,t,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),e.deleteTexture(o))};for(let o of t)for(let a of o.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let s of a.buffers)e.deleteBuffer(s);i(a.texture),i(a.metallicRoughnessTexture),i(a.normalTexture),i(a.occlusionTexture);let u=new Set;a.customProgram&&u.add(a.customProgram);for(let s of a.programCache?.values()??[])s.program&&u.add(s.program);for(let s of u)e.deleteProgram(s)}if(n)for(let o of n)i(o)}function vo(e,t,n=Io,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return xa(e,t,n,r,i)}catch(o){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Lo(e,a,i.gpuTextures),i.vao&&e.deleteVertexArray(i.vao);for(let u of i.buffers)e.deleteBuffer(u);throw o}}function xa(e,t,n,r,i){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=t,a=$t("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(o,t);let u=t.bin,s=[];i.meshes=s;let c=[],l=o.extensions?.KHR_materials_variants;l&&Array.isArray(l.variants)&&l.variants.forEach((M,k)=>{c.push(typeof M?.name=="string"&&M.name?M.name:`Variant_${k}`)});let f=ft(o),m=[];if(Array.isArray(o.nodes))for(let M=0;M<o.nodes.length;M++){let k=o.nodes[M];k.mesh!==void 0&&o.meshes&&o.meshes[k.mesh]&&m.push({node:k,nodeIdx:M,meshIdx:k.mesh})}let h=m.length>0?m:(o.meshes||[]).map((M,k)=>({node:M,nodeIdx:-1,meshIdx:k})),p=[];if(Array.isArray(t.lights)&&t.lights.length>0)p.push(...t.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let M=o.extensions.KHR_lights_punctual.lights;for(let k of M){let R=k.type==="directional"?"directional":k.type==="point"?"point":"ambient";p.push({type:R,color:k.color||[1,1,1],intensity:k.intensity!==void 0?k.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),h.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${h.length}`);let d=[];if(i.gpuTextures=d,o.textures&&o.images){if(o.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${o.textures.length}`);for(let M=0;M<o.textures.length;M++){let k=o.textures[M],R=o.images[k.source];if(R){let B=e.createTexture();if(e.bindTexture(3553,B),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),R.bufferView!==void 0){let Z=o.bufferViews[R.bufferView],j=u.slice(Z.byteOffset||0,(Z.byteOffset||0)+Z.byteLength),ie=new Blob([j],{type:R.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(ie).then(ee=>{e.bindTexture(3553,B),e.texImage2D(3553,0,6408,6408,5121,ee),e.generateMipmap(3553),r?.()}).catch(()=>{})}else if(R.uri){let Z=ba(R.uri);if(Z){let j=new Image;j.crossOrigin="anonymous",j.referrerPolicy="no-referrer",j.onload=()=>{e.bindTexture(3553,B),e.texImage2D(3553,0,6408,6408,5121,j),e.generateMipmap(3553),r?.()},j.src=Z}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",R.uri)}d.push(B)}else d.push(null)}}let y=[1/0,1/0,1/0],T=[-1/0,-1/0,-1/0],S=0,b=0;for(let M=0;M<h.length;M++){let k=h[M],R=o.meshes[k.meshIdx],B=k.nodeIdx>=0?f[k.nodeIdx]:Te(),Z=new Float32Array(9);De(Z,B);let j={name:k.node.name||R.name||`Mesh_${k.meshIdx}`,nodeIndex:k.nodeIdx,transform:B,normalMatrix:Z,primitives:[],extras:k.node.extras||R.extras};i.mesh=j;let ie=k.node?.extensions?.EXT_mesh_gpu_instancing;if(ie&&ie.attributes&&typeof ie.attributes=="object"){let ee=ie.attributes,ne=ee.TRANSLATION!==void 0?o.accessors?.[ee.TRANSLATION]:null,X=ee.ROTATION!==void 0?o.accessors?.[ee.ROTATION]:null,ae=ee.SCALE!==void 0?o.accessors?.[ee.SCALE]:null,se=ee._COLOR_0!==void 0?o.accessors?.[ee._COLOR_0]:null,F=Number(ne?.count??X?.count??ae?.count??0);if(!Number.isFinite(F)||F<0||F>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${F}`);if(F>0){let H=(re,D)=>{if(!re||re.bufferView===void 0||!o.bufferViews?.[re.bufferView])return null;let x=re.componentType??5126,C=z=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${z})`),null);if(x!==5120&&x!==5121&&x!==5122&&x!==5123&&x!==5126)return C(`componentType ${x}`);if(!(Number(re.count)>=F))return C(`count ${re.count} < ${F}`);let L=null;try{L=it(o,u,{...re,count:F},D)}catch{return C("out of bounds")}return!L||!L.every(Number.isFinite)?C("non-finite value"):L},E=H(ne,3),V=H(X,4),O=H(ae,3),U=se?.type==="VEC4"?4:3,G=H(se,U),K=new Float32Array(F*16),ue=Te();for(let re=0;re<F;re++){let D=E?[E[re*3],E[re*3+1],E[re*3+2]]:[0,0,0],x=V?[V[re*4],V[re*4+1],V[re*4+2],V[re*4+3]]:[0,0,0,1],C=O?[O[re*3],O[re*3+1],O[re*3+2]]:[1,1,1];Qe(ue,x,D,C),K.set(ue,re*16)}if(j.instanceMatrices=K,G){let re=new Float32Array(F*3);for(let D=0;D<F;D++)re[D*3]=G[D*U],re[D*3+1]=G[D*U+1],re[D*3+2]=G[D*U+2];j.instanceColors=re}}}for(let ee of R.primitives||[]){if(ee.extensions?.KHR_draco_mesh_compression){let L=$t("draco");L&&L.decodePrimitive(o,ee,u)}let ne=[],X=e.createVertexArray();i.vao=X,i.buffers=ne,e.bindVertexArray(X);let ae=ya(e,j,ne),se=o.accessors[ee.attributes.POSITION],F=Number(se?.count??0);if(!Number.isFinite(F)||F<0||S+F>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(S+=F,se?.min&&se?.max){let L=z=>{for(let W=0;W<3;W++){let $=z[12+W],Y=z[12+W];for(let Q=0;Q<3;Q++){let q=z[Q*4+W]*se.min[Q],J=z[Q*4+W]*se.max[Q];$+=q<J?q:J,Y+=q>J?q:J}$<y[W]&&(y[W]=$),Y>T[W]&&(T[W]=Y)}};if(j.instanceMatrices&&j.instanceMatrices.length>=16){let z=j.instanceMatrices.length>>4,W=Te();for(let $=0;$<z;$++){let Y=j.instanceMatrices.subarray($*16,$*16+16);Re(W,B,Y),L(W)}}else L(B)}let H=Kr(e,o,u,ee.attributes.POSITION,0,3,ne);Kr(e,o,u,ee.attributes.NORMAL,1,3,ne),Kr(e,o,u,ee.attributes.TEXCOORD_0,2,2,ne,ga(o,ee));let E=0,V=5123,O=null;if(ee.indices!==void 0){let L=o.accessors[ee.indices],W=(o.bufferViews[L.bufferView].byteOffset||0)+(L.byteOffset||0);if(E=Number(L.count??0),!Number.isFinite(E)||E<0||b+E>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);b+=E,V=L.componentType===5125?5125||5125:5123||5123;let $=e.createBuffer();ne.push($),e.bindBuffer(34963,$),L.componentType===5125?(O=new Uint32Array(u,W,L.count),e.bufferData(34963,O,35044)):L.componentType===5121?(O=Uint16Array.from(new Uint8Array(u,W,L.count)),e.bufferData(34963,O,35044)):(O=W%2===0?new Uint16Array(u,W,L.count):new Uint16Array(u.slice(W,W+L.count*2)),e.bufferData(34963,O,35044))}else E=se.count;let U={};for(let L of Ne)if(L.onBuildPrimitiveVAO){let z=L.onBuildPrimitiveVAO(e,X,ee,o,u);z&&(U[L.name]=z)}e.bindVertexArray(null);let G=o.materials&&ee.material!==void 0?o.materials[ee.material]:null,{program:K,uniforms:ue}=Ro(e,ee,G),re=Co(G,d),D=!!(G?.extensions?.KHR_materials_transmission||U.materials?.isTransmissive),x=ee.extensions?.KHR_materials_variants?.mappings,C=Array.isArray(x)?x.filter(L=>L&&typeof L.material=="number"&&Array.isArray(L.variants)).map(L=>({material:L.material|0,variants:L.variants.map(z=>Number(z)|0)})):void 0;j.primitives.push({vao:X,instanced:ae,indexCount:E,indexType:V,...re,positions:H,indices:O,buffers:ne,materialIndex:ee.material,defaultMaterialIndex:ee.material,variantMappings:C,primitiveDef:ee,programCache:new Map([[ee.material??-1,{program:K,uniforms:ue}]]),pluginData:U,customProgram:K,customUniforms:ue,isTransmissive:D})}s.push(j)}isFinite(y[0])||(y=[-1,-1,-1]),isFinite(T[0])||(T=[1,1,1]);let A=[(y[0]+T[0])/2,(y[1]+T[1])/2,(y[2]+T[2])/2],w=T[0]-y[0],P=T[1]-y[1],N=T[2]-y[2],I=Math.max(Math.hypot(w,P,N)/2,.5),_=[y[0],y[1],y[2]],v=[T[0],T[1],T[2]],g=t.animations;if(!g){for(let M of Ne)if(M.onParseGLB?.(t),t.animations){g=t.animations;break}}return g||(g=[]),{meshes:s,bounds:{center:A,radius:I,min:_,max:v},lights:p,animations:g,worldMatrices:f,gpuTextures:d,availableVariants:c}}function rn(e){let t=e.customTarget||e.bounds.center,n=e.currDistance*Math.cos(e.currPhi);return[t[0]+n*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+n*Math.cos(e.currTheta)]}var He=class{constructor(t,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=Te();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=Te();this.viewMatrix=Te();this.activeViewMatrix=null;this.modelMatrix=Te();this.mvpMatrix=Te();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:Te(),rawValueToMeters:.001,format:0};this.container=t;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let s=t.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",t.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Zr(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=_t(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let u=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!u)throw new Error("WebGL2 not supported");this.gl=u,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(t,n){ma(t,n)}static getDecoder(t){return $t(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=n=>{n.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,n=Eo();this.renderProg=Qr(t,Mo,n.fs),this.pickProg=Qr(t,da,pa),this.uRender=Jr(t,this.renderProg,n.uniforms),this.uPick=Jr(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let n of Ne)n.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,n,r,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,n,r),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null)}resizePickingFbo(t,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,t),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(t,n){this.lastGlbData=t,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:a,worldMatrices:u,gpuTextures:s,availableVariants:c}=vo(this.gl,t,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=a||[],this.worldMatrices=u||[],this.gpuTextures=s||[],this.availableVariants=c||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let m of t.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of Ne)m.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 l=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=Zr(l));let f=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;f!==void 0&&(this.envIntensity=Math.max(0,Number(f)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(wo(t))}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(t){this.loadGLBData(ht(t))}setBackdropGLB(t,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let r=ht(t),{meshes:i}=vo(this.gl,r,Io,()=>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(t,n,r,i=1){this.clearColor=[t,n,r,i]}updateMeshTransforms(t){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;t instanceof Map?i=t.get(r.name)??t.get(n):Array.isArray(t)?i=t[n]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,r.name)?i=t[r.name]:Object.prototype.hasOwnProperty.call(t,n)&&(i=t[n])),i&&i.length===16&&(r.transform.set(i),De(r.normalMatrix,r.transform))}}bindLights(t=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],a=[],u=[];for(let s of this.lights){let c=s.color||[1,1,1],l=s.intensity!==void 0?s.intensity:1;if(s.type==="ambient")r=[c[0]*l,c[1]*l,c[2]*l];else if(s.type==="directional"&&i.length<6){let f=s.direction||[.5,1,.8];i.push(f[0],f[1],f[2]),o.push(c[0]*l,c[1]*l,c[2]*l)}else if(s.type==="point"&&a.length<6){let f=s.position||[0,0,0];a.push(f[0],f[1],f[2]),u.push(c[0]*l,c[1]*l,c[2]*l)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(t.uAmbientColor,r),n.uniform1i(t.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(t.uDirLightDir,i),n.uniform3fv(t.uDirLightColor,o)),n.uniform1i(t.uNumPointLights,a.length/3),a.length>0&&(n.uniform3fv(t.uPointLightPos,a),n.uniform3fv(t.uPointLightColor,u)),n.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Zr(t)}getExposure(){return this.exposure}setShadow(t,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=_t(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let n of Ne)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let n of Ne)if(n.setSkyboxImage){await n.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:t,phi:n,radius:r,toString(){return`${t.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((n,r)=>{let i=this.meshes.flatMap(l=>l.primitives.filter(f=>f.materialIndex===r||t.length===1&&f.materialIndex===void 0)),o=i[0],a=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],u=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,s=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:u,roughnessFactor:s,setBaseColorFactor:l=>{let f=[l[0],l[1],l[2],l[3]??1];c.baseColorFactor=f,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=f);for(let m of i)m.baseColor=f;this.render()},setMetallicFactor:l=>{c.metallicFactor=l,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=l);for(let f of i)f.metallic=l;this.render()},setRoughnessFactor:l=>{c.roughnessFactor=l,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=l);for(let f of i)f.roughness=l;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(t){if(this.animations.length!==0){if(t){let n=this.animations.find(r=>r.name===t);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let n=this.applyVariantMaterial(t);return n&&this.gl&&this.render(),n}applyVariantMaterial(t){let n=t===null||t==="",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(t),r<0)return!1;this.activeVariantName=t}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let a of o.primitives){let u=a.defaultMaterialIndex;if(!n&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){u=c.material;break}}let s=u!==void 0?i[u]:void 0;a.materialIndex=s?u:void 0,Object.assign(a,Co(s,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,s??null)}return!0}applyPrimitiveProgram(t,n,r){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let i=n??-1,o=t.programCache.get(i);o||(o=Ro(this.gl,{...t.primitiveDef,material:n},r),t.programCache.set(i,o)),t.customProgram=o.program,t.customUniforms=o.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let n of Ne)if(n.evaluateAnimation){n.evaluateAnimation(this,t);return}}setTarget(t,n,r){this.customTarget=[t,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(t){let n=Math.max(10,Math.min(90,t));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!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(t){t.minTheta!==void 0&&(this.minTheta=t.minTheta*Math.PI/180),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*Math.PI/180),t.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,t.minPhi*Math.PI/180)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,t.maxPhi*Math.PI/180)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let 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,t))}setCamera(t,n,r,i){t!==void 0&&(this.targetTheta=this.clampTheta(t*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(t,n,r,i){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*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(t,n){let r=Te();Re(r,this.projMatrix,this.viewMatrix);let[i,o,a]=t,u=n?n[0]:0,s=n?n[1]:0,c=n?n[2]:0,l=this.modelRootMatrix;l&&(i=l[0]*t[0]+l[4]*t[1]+l[8]*t[2]+l[12],o=l[1]*t[0]+l[5]*t[1]+l[9]*t[2]+l[13],a=l[2]*t[0]+l[6]*t[1]+l[10]*t[2]+l[14],n&&(u=l[0]*n[0]+l[4]*n[1]+l[8]*n[2],s=l[1]*n[0]+l[5]*n[1]+l[9]*n[2],c=l[2]*n[0]+l[6]*n[1]+l[10]*n[2]));let f=r[0]*i+r[4]*o+r[8]*a+r[12],m=r[1]*i+r[5]*o+r[9]*a+r[13],h=r[2]*i+r[6]*o+r[10]*a+r[14],p=r[3]*i+r[7]*o+r[11]*a+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let d=f/p,y=m/p,T=h/p,S=this.canvas.getBoundingClientRect(),b=S.width||this.canvas.clientWidth||this.canvas.width||300,A=S.height||this.canvas.clientHeight||this.canvas.height||150,w=(d*.5+.5)*b,P=(-y*.5+.5)*A,N=d>=-1.1&&d<=1.1&&y>=-1.1&&y<=1.1&&T>=-1&&T<=1;if(N&&n){let[I,_,v]=rn(this),g=[i-I,o-_,a-v];u*g[0]+s*g[1]+c*g[2]>.05&&(N=!1)}return{x:w,y:P,z:T,visible:N}}setSelectedMesh(t){this.selectedMeshName=t||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let t=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},t.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,t.setPointerCapture(n.pointerId))},t.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 a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],u=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],s=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;s[0]+=(-i*a[0]+o*u[0])*c,s[1]+=(-i*a[1]+o*u[1])*c,s[2]+=(-i*a[2]+o*u[2])*c,this.customTarget=s}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},t.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{t.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=t.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(t.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},t.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)},t.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),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=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}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=this.canvas;this.boundContextLost&&(t.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(t.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(t.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(t.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(t.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(t.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(t.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(t.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(t,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,a=r.height||300,u=i.width>0?Math.floor((t-i.left)*(o/i.width)):Math.floor(t),s=i.height>0?Math.floor((n-i.top)*(a/i.height)):Math.floor(n);return this.performMeshPick(u,s,!1)}performMeshPick(t,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,o);let u=Te();Re(u,this.projMatrix,this.viewMatrix);let s=[],c=Math.max(0,Math.min(o-1,t)),l=Math.max(0,Math.min(a-1,a-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==a)&&this.resizePickingFbo(o,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,a),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let N=0;N<this.meshes.length;N++){let I=this.meshes[N];if(I.visible===!1||I.isPluginMesh)continue;let _=N+1,v=(_&255)/255,g=(_>>8&255)/255,M=(_>>16&255)/255;i.uniform4f(this.uPick.uColorId,v,g,M,1),Re(this.modelMatrix,this.modelRootMatrix,I.transform);let k=I.instanceMatrices;if(k&&k.length>=16){let R=k.length>>4,B=Te();for(let Z of I.primitives){i.bindVertexArray(Z.vao);for(let j=0;j<R;j++)Re(B,this.modelMatrix,k.subarray(j*16,j*16+16)),Re(this.mvpMatrix,u,B),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Bn(i,Z)}}else{Re(this.mvpMatrix,u,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let R of I.primitives)i.bindVertexArray(R.vao),Bn(i,R)}}let w=new Uint8Array(4);i.readPixels(c,l,1,1,6408,5121,w),i.bindFramebuffer(36160,null);let P=w[0]+(w[1]<<8)+(w[2]<<16);P>0&&P<=this.meshes.length&&(s=[this.meshes[P-1]])}s.length===0&&(s=this.meshes.filter(w=>w.visible!==!1));let f=null,m=1/0,h=[0,0,0],p=[0,1,0],[d,y,T]=rn(this),S=Te();for(let w of s){Re(S,this.modelRootMatrix,w.transform);let P=w.instanceMatrices,N=P&&P.length>=16?P.length>>4:1;for(let I=0;I<N;I++){P&&P.length>=16?Re(this.modelMatrix,S,P.subarray(I*16,I*16+16)):this.modelMatrix.set(S),Re(this.mvpMatrix,u,this.modelMatrix);let _=Te();if(!Xt(_,this.mvpMatrix))continue;let v=(c+.5)/o*2-1,g=(l+.5)/a*2-1,M=[0,0,0],k=[0,0,0];Br(M,v,g,-1,_),Br(k,v,g,1,_);let R=k[0]-M[0],B=k[1]-M[1],Z=k[2]-M[2],j=Math.hypot(R,B,Z)||1,ie=R/j,ee=B/j,ne=Z/j,X={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((se=>{for(let F of w.primitives){if(!F.positions)continue;let H=F.positions,E=F.indices,V=Math.floor(E?E.length/3:H.length/9);for(let O=0;O<V;O++){let U=E?E[O*3]:O*3,G=E?E[O*3+1]:O*3+1,K=E?E[O*3+2]:O*3+2;lo(M[0],M[1],M[2],ie,ee,ne,H[U*3],H[U*3+1],H[U*3+2],H[G*3],H[G*3+1],H[G*3+2],H[K*3],H[K*3+1],H[K*3+2],X,se)}}})(1e-4),isFinite(X.distance)){let se=X.point[0],F=X.point[1],H=X.point[2],E=this.modelMatrix,V=E[0]*se+E[4]*F+E[8]*H+E[12],O=E[1]*se+E[5]*F+E[9]*H+E[13],U=E[2]*se+E[6]*F+E[10]*H+E[14],G=V-d,K=O-y,ue=U-T,re=Math.hypot(G,K,ue);if(re<m){De(this.normalMatrix,this.modelMatrix);let D=this.normalMatrix,x=X.normal[0],C=X.normal[1],L=X.normal[2],z=D[0]*x+D[3]*C+D[6]*L,W=D[1]*x+D[4]*C+D[7]*L,$=D[2]*x+D[5]*C+D[8]*L,Y=Math.hypot(z,W,$)||1;z/=Y,W/=Y,$/=Y,z*G+W*K+$*ue>0&&(z=-z,W=-W,$=-$),f=w,m=Math.round(re*1e3)/1e3,h=[Math.round(V*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(U*1e3)/1e3],p=[Math.round(z*1e3)/1e3,Math.round(W*1e3)/1e3,Math.round($*1e3)/1e3]}}}}if(!f)return null;let A={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:m,hitPoint:h,normal:p,screenX:t,screenY:n};if(r){for(let w of Ne)w.onMeshSelect?.(this,A);this.opts.onMeshClick&&this.opts.onMeshClick(A),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:A}))}return A}mapStereoPickX(t,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return t;let r=Math.max(1,Math.floor(n*.5)),i=t>=r,o=i?t-r:t,a=i?Math.max(1,n-r):r,u=(o+.5)/a*2-1;return Math.floor((u*.5+1)*.5*n)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Un(this.projMatrix,this.fov,t,.1,n);let r=this.customTarget||this.bounds.center;Ht(this.viewMatrix,rn(this),r,[0,1,0]),Re(this.mvpMatrix,this.projMatrix,this.viewMatrix),De(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*t)),i=Math.max(1,Math.floor(n.height*t));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(t){let n=this.xrSessionActive;if(this.xrSessionActive=t,n&&!t){this.xrDepthState.enabled=!1;for(let r of Ne)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(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let n of Ne)n.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let t=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(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=t,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]=t,o[11]=0,o[12]=r-(t*r+n*i),o[13]=0,o[14]=i-(-n*r+t*i),o[15]=1}setVisible(t){this.isVisible=t}update(t){for(let a of Ne)a.onUpdate?.(this,t);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let a of Ne)a.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let 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 a={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(t,n,r,i,o=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let u=t?.transform?.inverse?.matrix||this.viewMatrix,s=t?.projectionMatrix||this.projMatrix,c=t?.transform?.position,l=c?[c.x,c.y,c.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:u,projMatrix:s,eyePos:l,viewport:i,eye:t?.eye||"none",clear:a>0?!1:t?.eye!=="right",isAR:o})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let b=Math.max(2,this.canvas.width||2),A=Math.max(1,this.canvas.height||1),w=Math.max(1,Math.floor(b*.5)),P=Math.max(1,b-w),N=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),I=this.customTarget||this.bounds.center,[_,v,g]=rn(this),M=Math.cos(this.currTheta),k=-Math.sin(this.currTheta),R=.032,B=Te(),Z=Te(),j=[_-M*R,v,g-k*R],ie=[I[0]-M*R*.25,I[1],I[2]-k*R*.25];Un(B,this.fov,w/A,.1,N),Ht(Z,j,ie,[0,1,0]);let ee=Te(),ne=Te(),X=[_+M*R,v,g+k*R],ae=[I[0]+M*R*.25,I[1],I[2]+k*R*.25];Un(ee,this.fov,P/A,.1,N),Ht(ne,X,ae,[0,1,0]),this.render({viewMatrix:Z,projMatrix:B,eyePos:j,viewport:[0,0,w,A],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:ne,projMatrix:ee,eyePos:X,viewport:[w,0,P,A],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,b,A);return}let n=this.gl,r=0,i=0,o=this.canvas.width,a=this.canvas.height;t?.viewport?(r=t.viewport[0],i=t.viewport[1],o=t.viewport[2],a=t.viewport[3],n.viewport(r,i,o,a)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!t||t.clear!==!1)&&(t?.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 u=Te(),s=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=s,Re(u,t?.projMatrix??this.projMatrix,s);let c=ge().xrDepthShader,l=ua(this.toneMapping),[f,m,h]=t?t.eyePos:rn(this);for(let b of Ne)b.onBeforeDrawScene?.(this,n,u,[f,m,h],l);let p=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let d=t?.eye||"none",y=!1,T=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,S=b=>{for(let A=0;A<T.length;A++){let w=T[A];if(w.visible===!1)continue;let P=this.selectedMeshName!==""&&w.name===this.selectedMeshName;A<p||w.worldSpace===!0||w.name==="__xr_reticle__"?this.modelMatrix.set(w.transform):Re(this.modelMatrix,this.modelRootMatrix,w.transform),Re(this.mvpMatrix,u,this.modelMatrix),De(w.normalMatrix,this.modelMatrix);let N=w.extras?.xr?.stereo||w.userData?.xr?.stereo,I=0,_=0,v=1,g=1;N==="sbs"?(v=.5,I=d==="right"?.5:0):N==="ou"&&(g=.5,_=d==="right"?.5:0);for(let M of w.primitives){let k=!!M.isTransmissive;if(!b&&k){y=!0;continue}if(b&&!k)continue;let R=M.customProgram||this.renderProg,B=M.customUniforms||this.uRender;n.useProgram(R),n.uniform1i(B.uToneMapping,l),n.uniform1f(B.uEnvIntensity,this.envIntensity),B.uExposure&&n.uniform1f(B.uExposure,this.exposure),n.uniform3f(B.uCameraPos,f,m,h),n.uniform1f(B.uEmissive,P?1:0),n.uniformMatrix4fv(B.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(B.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(B.uNormalMatrix,!1,w.normalMatrix),B.uUvTransform&&n.uniform4f(B.uUvTransform,I,_,v,g),B.uViewportSize&&n.uniform2f(B.uViewportSize,Math.max(1,o),Math.max(1,a)),c?.bind(n,B,this.xrDepthState,s,[r,i,Math.max(1,o),Math.max(1,a)]),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),B.uSectionEnabled&&n.uniform1i(B.uSectionEnabled,0);for(let j of Ne)j.onBeforeDrawPrimitive?.(n,R,M,w,this.worldMatrices||[],this.gltf);n.uniform4fv(B.uBaseColor,M.baseColor),n.uniform1f(B.uMetallic,M.metallic),n.uniform1f(B.uRoughness,M.roughness),B.uClearcoat&&n.uniform2f(B.uClearcoat,M.clearcoat??0,M.clearcoatRoughness??.04),M.texture?(n.activeTexture(33984),n.bindTexture(3553,M.texture),n.uniform1i(B.uBaseColorTexture,0),n.uniform1i(B.uHasTexture,1)):n.uniform1i(B.uHasTexture,0),M.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,M.metallicRoughnessTexture),n.uniform1i(B.uMetallicRoughnessTexture,1),n.uniform1i(B.uHasMetallicRoughnessTexture,1)):n.uniform1i(B.uHasMetallicRoughnessTexture,0),M.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,M.normalTexture),n.uniform1i(B.uNormalTexture,2),n.uniform1i(B.uHasNormalTexture,1),n.uniform1f(B.uNormalScale,M.normalScale)):n.uniform1i(B.uHasNormalTexture,0),M.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,M.occlusionTexture),n.uniform1i(B.uOcclusionTexture,3),n.uniform1i(B.uHasOcclusionTexture,1),n.uniform1f(B.uOcclusionStrength,M.occlusionStrength)):n.uniform1i(B.uHasOcclusionTexture,0),n.bindVertexArray(M.vao);let Z=w.instanceMatrices;if(Z&&Z.length>=16&&M.instanced&&B.uInstanced&&B.uViewProj){let j=Z.length>>4;n.uniform1i(B.uInstanced,1),n.uniformMatrix4fv(B.uViewProj,!1,u),M.indices?n.drawElementsInstanced(4,M.indexCount,M.indexType,0,j):n.drawArraysInstanced(4,0,M.indexCount,j),n.uniform1i(B.uInstanced,0)}else if(Z&&Z.length>=16){let j=Z.length>>4,ie=w.instanceColors,ee=Te(),ne=new Float32Array(9),X=[M.baseColor[0],M.baseColor[1],M.baseColor[2],M.baseColor[3]];for(let ae=0;ae<j;ae++)Re(ee,this.modelMatrix,Z.subarray(ae*16,ae*16+16)),Re(this.mvpMatrix,u,ee),De(ne,ee),n.uniformMatrix4fv(B.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(B.uModel,!1,ee),n.uniformMatrix3fv(B.uNormalMatrix,!1,ne),ie&&(X[0]=M.baseColor[0]*ie[ae*3],X[1]=M.baseColor[1]*ie[ae*3+1],X[2]=M.baseColor[2]*ie[ae*3+2],X[3]=M.baseColor[3],n.uniform4fv(B.uBaseColor,X)),Bn(n,M)}else Bn(n,M)}}};if(S(!1),y){for(let b of Ne)b.onBeforeTransmissivePass?.(n,this);S(!0)}for(let b of Ne)b.onAfterRender?.(n,this,u)}disposeMeshListGpuResources(t,n){Lo(this.gl,t,n)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of Ne)n.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};He.registerPlugin=Fe,He.getRegisteredPlugins=kn;function va(e){return e+3&-4}function Ta(e,t=0){let n=(X,ae)=>typeof X=="number"&&Number.isFinite(X)?X:ae,r=n(e[t+12],0),i=n(e[t+13],0),o=n(e[t+14],0),a=n(e[t+0],1),u=n(e[t+1],0),s=n(e[t+2],0),c=n(e[t+4],0),l=n(e[t+5],1),f=n(e[t+6],0),m=n(e[t+8],0),h=n(e[t+9],0),p=n(e[t+10],1),d=Math.hypot(a,u,s),y=Math.hypot(c,l,f),T=Math.hypot(m,h,p);a*(l*p-h*f)-c*(u*p-h*s)+m*(u*f-l*s)<0&&(d=-d);let b=Math.abs(d)>1e-8?1/d:0,A=Math.abs(y)>1e-8?1/y:0,w=Math.abs(T)>1e-8?1/T:0,P=a*b,N=u*b,I=s*b,_=c*A,v=l*A,g=f*A,M=m*w,k=h*w,R=p*w,B=P+v+R,Z=0,j=0,ie=0,ee=1;if(B>0){let X=.5/Math.sqrt(B+1);ee=.25/X,Z=(g-k)*X,j=(M-I)*X,ie=(N-_)*X}else if(P>v&&P>R){let X=2*Math.sqrt(Math.max(0,1+P-v-R));X>1e-8&&(ee=(g-k)/X,Z=.25*X,j=(_+N)/X,ie=(M+I)/X)}else if(v>R){let X=2*Math.sqrt(Math.max(0,1+v-P-R));X>1e-8&&(ee=(M-I)/X,Z=(_+N)/X,j=.25*X,ie=(g+k)/X)}else{let X=2*Math.sqrt(Math.max(0,1+R-P-v));X>1e-8&&(ee=(N-_)/X,Z=(M+I)/X,j=(g+k)/X,ie=.25*X)}let ne=Math.hypot(Z,j,ie,ee);return ne>1e-8&&Number.isFinite(ne)?(Z/=ne,j/=ne,ie/=ne,ee/=ne):(Z=0,j=0,ie=0,ee=1),{t:[r,i,o],r:[Z,j,ie,ee],s:[d,y,T]}}function Aa(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}function qt(e,t){e.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],a=[],u=[],s=new Set,c=[],l=[],f=new Map,m=[],h=[];function p(_){let v=f.get(_);if(v!==void 0)return v;v=l.length,f.set(_,v);let g=_,M=g.color?.r??.8,k=g.color?.g??.8,R=g.color?.b??.8,B=g.opacity??1,Z={name:g.name||"",pbrMetallicRoughness:{baseColorFactor:[M,k,R,B],metallicFactor:g.metalness??.1,roughnessFactor:g.roughness??.5},doubleSided:g.side===2||!!g.doubleSided};if(g.emissive&&(g.emissive.r>0||g.emissive.g>0||g.emissive.b>0)){let ie=g.emissiveIntensity??1;Z.emissiveFactor=[g.emissive.r*ie,g.emissive.g*ie,g.emissive.b*ie]}let j={};return g.clearcoat&&g.clearcoat>0&&(j.KHR_materials_clearcoat={clearcoatFactor:g.clearcoat,clearcoatRoughnessFactor:g.clearcoatRoughness||0}),g.sheen&&g.sheen>0&&(j.KHR_materials_sheen={sheenColorFactor:g.sheenColor?[g.sheenColor.r,g.sheenColor.g,g.sheenColor.b]:[1,1,1],sheenRoughnessFactor:g.sheenRoughness||0}),g.transmission&&g.transmission>0&&(j.KHR_materials_transmission={transmissionFactor:g.transmission}),g.thickness&&g.thickness>0&&(j.KHR_materials_volume={thicknessFactor:g.thickness,attenuationDistance:g.attenuationDistance??1/0,attenuationColor:g.attenuationColor?[g.attenuationColor.r,g.attenuationColor.g,g.attenuationColor.b]:[1,1,1]}),g.ior!==void 0&&g.ior!==1.5&&(j.KHR_materials_ior={ior:g.ior}),g.dispersion&&g.dispersion>0&&(j.KHR_materials_dispersion={dispersion:g.dispersion}),g.iridescence&&g.iridescence>0&&(j.KHR_materials_iridescence={iridescenceFactor:g.iridescence,iridescenceIor:g.iridescenceIOR??1.3}),Object.keys(j).length>0&&(Z.extensions=j),l.push(Z),v}function d(_,v){let g=new Uint8Array(_.buffer,_.byteOffset,_.byteLength),M=va(g.byteLength),k=new Uint8Array(M);k.set(g),n.push(k);let R=i.length;return i.push({buffer:0,byteOffset:r,byteLength:g.byteLength,target:v}),r+=M,R}function y(_,v,g,M,k,R,B){let Z=d(_,g),j=o.length,ie={bufferView:Z,byteOffset:0,componentType:M,count:k,type:v};return R&&(ie.min=R),B&&(ie.max=B),o.push(ie),j}e.traverse(_=>{(_.isLight||_.color&&_.intensity!==void 0)&&h.push({type:_.type,color:[_.color.r,_.color.g,_.color.b],intensity:_.intensity,position:[_.position.x,_.position.y,_.position.z]})});let T=[];function S(_){let v={name:_.name||""},g=_.position,M=_.quaternion,k=_.scale;if((g.x||g.y||g.z)&&(v.translation=[g.x,g.y,g.z]),(M.x||M.y||M.z||M.w!==1)&&(v.rotation=[M.x,M.y,M.z,M.w]),(k.x!==1||k.y!==1||k.z!==1)&&(v.scale=[k.x,k.y,k.z]),_.userData&&Object.keys(_.userData).length>0&&(v.extras=JSON.parse(JSON.stringify(_.userData,(B,Z)=>{if(!(B==="__proto__"||B==="prototype"||B==="constructor"))return typeof Z=="function"?void 0:Z})),_.userData.xr)){let B=Aa(_.userData.xr);v.extensions={...v.extensions||{},MOZ_hubs_components:B,ANDROID_xr_scenecore:B},ge().xrTraitSerializer?.gltfNode(v,_.userData.xr),s.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(_.geometry){let B=_.geometry,Z=B.attributes.position;if(Z&&Z.count>0){let j=[1/0,1/0,1/0],ie=[-1/0,-1/0,-1/0];for(let F=0;F<Z.count;F++){let H=Z.getX(F),E=Z.getY(F),V=Z.getZ(F);H<j[0]&&(j[0]=H),H>ie[0]&&(ie[0]=H),E<j[1]&&(j[1]=E),E>ie[1]&&(ie[1]=E),V<j[2]&&(j[2]=V),V>ie[2]&&(ie[2]=V)}let ne={attributes:{POSITION:y(Z.array,"VEC3",34962,5126,Z.count,j,ie)}};if(B.attributes.normal&&(ne.attributes.NORMAL=y(B.attributes.normal.array,"VEC3",34962,5126,B.attributes.normal.count)),B.attributes.uv&&(ne.attributes.TEXCOORD_0=y(B.attributes.uv.array,"VEC2",34962,5126,B.attributes.uv.count)),B.index){let F=B.index.array instanceof Uint32Array;ne.indices=y(B.index.array,"SCALAR",34963,F?5125:5123,B.index.count)}_.material&&(ne.material=p(_.material));let X=_.userData?.variants;if(X&&typeof X=="object"){let F=new Map;for(let H of Object.keys(X)){if(!H||H==="__proto__"||H==="constructor"||H==="prototype")continue;let E=X[H];if(!E||typeof E!="object")continue;let V=m.indexOf(H);if(V===-1&&m.length<256&&(V=m.length,m.push(H)),V===-1)continue;let O=p(E),U=F.get(O);U||(U=[],F.set(O,U)),U.push(V)}if(F.size>0){let H=[];for(let[E,V]of F.entries())H.push({material:E,variants:V});ne.extensions={...ne.extensions||{},KHR_materials_variants:{mappings:H}},s.add("KHR_materials_variants")}}let ae=_;if(ae.isInstancedMesh&&typeof ae.count=="number"&&ae.count>0&&ae.instanceMatrix?.array){let F=Math.min(1e4,Math.floor(ae.count)),H=ae.instanceMatrix.array,E=new Float32Array(F*3),V=new Float32Array(F*4),O=new Float32Array(F*3);for(let G=0;G<F;G++){let{t:K,r:ue,s:re}=Ta(H,G*16);E[G*3]=K[0],E[G*3+1]=K[1],E[G*3+2]=K[2],V[G*4]=ue[0],V[G*4+1]=ue[1],V[G*4+2]=ue[2],V[G*4+3]=ue[3],O[G*3]=re[0],O[G*3+1]=re[1],O[G*3+2]=re[2]}let U={TRANSLATION:y(E,"VEC3",0,5126,F),ROTATION:y(V,"VEC4",0,5126,F),SCALE:y(O,"VEC3",0,5126,F)};if(ae.instanceColor?.array&&ae.instanceColor.array.length>=F*3){let G=new Float32Array(ae.instanceColor.array.subarray(0,F*3));U._COLOR_0=y(G,"VEC3",0,5126,F)}v.extensions={...v.extensions||{},EXT_mesh_gpu_instancing:{attributes:U}},s.add("EXT_mesh_gpu_instancing")}let se=a.length;a.push({primitives:[ne],name:_.name,...v.extras?{extras:v.extras}:{}}),v.mesh=se}}let R=u.length;if(u.push(v),c.push(_),_.children.length>0){v.children=[];for(let B of _.children)v.children.push(S(B))}return R}for(let _ of e.children)T.push(S(_));let b=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),A=[];if(typeof b=="function"&&c.length>0){let _=t?.duration??4,v=t?.fps??15,g=Math.max(2,Math.round(_*v)+1),M=new Float32Array(g),k=c.map(X=>({px:X.position.x,py:X.position.y,pz:X.position.z,qx:X.quaternion.x,qy:X.quaternion.y,qz:X.quaternion.z,qw:X.quaternion.w,sx:X.scale.x,sy:X.scale.y,sz:X.scale.z})),R=c.map(()=>new Float32Array(g*3)),B=c.map(()=>new Float32Array(g*4)),Z=c.map(()=>new Float32Array(g*3));for(let X=0;X<g;X++){let ae=X/(g-1)*_;M[X]=ae;try{b(ae)}catch{}for(let se=0;se<c.length;se++){let F=c[se];R[se][X*3]=F.position.x,R[se][X*3+1]=F.position.y,R[se][X*3+2]=F.position.z,B[se][X*4]=F.quaternion.x,B[se][X*4+1]=F.quaternion.y,B[se][X*4+2]=F.quaternion.z,B[se][X*4+3]=F.quaternion.w,Z[se][X*3]=F.scale.x,Z[se][X*3+1]=F.scale.y,Z[se][X*3+2]=F.scale.z}}for(let X=0;X<c.length;X++){let ae=c[X],se=k[X];ae.position.set(se.px,se.py,se.pz),ae.quaternion.set(se.qx,se.qy,se.qz,se.qw),ae.scale.set(se.sx,se.sy,se.sz)}e.updateMatrixWorld(!0);let j=null,ie=()=>(j===null&&(j=y(M,"SCALAR",0,5126,g,[0],[_])),j),ee=[],ne=[];for(let X=0;X<c.length;X++){let ae=k[X],se=!1,F=!1,H=!1;for(let E=0;E<g;E++)(Math.abs(R[X][E*3]-ae.px)>1e-4||Math.abs(R[X][E*3+1]-ae.py)>1e-4||Math.abs(R[X][E*3+2]-ae.pz)>1e-4)&&(se=!0),(Math.abs(B[X][E*4]-ae.qx)>1e-4||Math.abs(B[X][E*4+1]-ae.qy)>1e-4||Math.abs(B[X][E*4+2]-ae.qz)>1e-4||Math.abs(B[X][E*4+3]-ae.qw)>1e-4)&&(F=!0),(Math.abs(Z[X][E*3]-ae.sx)>1e-4||Math.abs(Z[X][E*3+1]-ae.sy)>1e-4||Math.abs(Z[X][E*3+2]-ae.sz)>1e-4)&&(H=!0);if(se){let E=y(R[X],"VEC3",0,5126,g),V=ee.length;ee.push({input:ie(),interpolation:"LINEAR",output:E}),ne.push({sampler:V,target:{node:X,path:"translation"}})}if(F){let E=y(B[X],"VEC4",0,5126,g),V=ee.length;ee.push({input:ie(),interpolation:"LINEAR",output:E}),ne.push({sampler:V,target:{node:X,path:"rotation"}})}if(H){let E=y(Z[X],"VEC3",0,5126,g),V=ee.length;ee.push({input:ie(),interpolation:"LINEAR",output:E}),ne.push({sampler:V,target:{node:X,path:"scale"}})}}ne.length>0&&A.push({name:"ProceduralLoop",samplers:ee,channels:ne})}let w=oo(u,a,e.userData),P={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:u,meshes:a,materials:l,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...A.length>0?{animations:A}:{},...w||s.size>0?{extensionsUsed:[...w?["KHR_interactivity"]:[],...s]}:{},...w||m.length>0?{extensions:{...w?{KHR_interactivity:w}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(_=>({name:_}))}}:{}}}:{}},N=new Uint8Array(r),I=0;for(let _ of n)N.set(_,I),I+=_.byteLength;return{gltf:P,bin:N.buffer,lights:h,environmentIntensity:e.environmentIntensity}}function Gn(e){return new TextEncoder().encode(e)}function on(e,t){let{gltf:n,bin:r}=qt(e,t),i=JSON.stringify(n),o=Gn(i),a=(4-o.byteLength%4)%4,u=o.byteLength+a,s=20+u+8+r.byteLength,c=new Uint8Array(s),l=new DataView(c.buffer);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0),l.setUint32(8,s,!0),l.setUint32(12,u,!0),l.setUint32(16,1313821514,!0),c.set(o,20);for(let m=0;m<a;m++)c[20+o.byteLength+m]=32;let f=20+u;return l.setUint32(f,r.byteLength,!0),l.setUint32(f+4,5130562,!0),c.set(new Uint8Array(r),f+8),c}function wa(e,t){e.updateMatrixWorld(!0);let n=[];return e.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let a=o.count,u=new Float32Array(a*3),s=r.matrixWorld.elements;for(let I=0;I<a;I++){let _=o.getX(I),v=o.getY(I),g=o.getZ(I);u[I*3]=s[0]*_+s[4]*v+s[8]*g+s[12],u[I*3+1]=s[1]*_+s[5]*v+s[9]*g+s[13],u[I*3+2]=s[2]*_+s[6]*v+s[10]*g+s[14]}let c;if(i.attributes.normal){let I=i.attributes.normal;c=new Float32Array(a*3);let _=new Float32Array(9);De(_,s);for(let v=0;v<a;v++){let g=I.getX(v),M=I.getY(v),k=I.getZ(v),R=_[0]*g+_[3]*M+_[6]*k,B=_[1]*g+_[4]*M+_[7]*k,Z=_[2]*g+_[5]*M+_[8]*k,j=Math.hypot(R,B,Z)||1;c[v*3]=R/j,c[v*3+1]=B/j,c[v*3+2]=Z/j}}let l;if(i.attributes.uv){let I=i.attributes.uv;l=new Float32Array(a*2);for(let _=0;_<a;_++)l[_*2]=I.getX(_),l[_*2+1]=I.getY(_)}let f;if(i.index)f=i.index.array;else{f=a>65535?new Uint32Array(a):new Uint16Array(a);for(let I=0;I<a;I++)f[I]=I}let m="DefaultMaterial",h=[.8,.8,.8],p=.5,d=.1,y=0,T=0,S=1.5,b=1,A=[0,0,0];if(r.material){let I=r.material;m=I.name||`Material_${n.length}`,I.color&&(h=[I.color.r,I.color.g,I.color.b]),typeof I.roughness=="number"&&(p=I.roughness),typeof I.metalness=="number"&&(d=I.metalness),typeof I.clearcoat=="number"&&(y=I.clearcoat),typeof I.clearcoatRoughness=="number"&&(T=I.clearcoatRoughness),typeof I.ior=="number"&&(S=I.ior);let _=typeof I.opacity=="number"?I.opacity:1,v=typeof I.transmission=="number"?I.transmission:0;if(b=_*(1-v),I.emissive&&(I.emissive.r>0||I.emissive.g>0||I.emissive.b>0)){let g=I.emissiveIntensity??1;A=[I.emissive.r*g,I.emissive.g*g,I.emissive.b*g]}}let w,P=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof P=="function"){let I=t?.duration??4,_=t?.fps??4,v=Math.max(2,Math.round(I*_)+1),g=[],M=[],k=[],R=[],B=[r.position.x,r.position.y,r.position.z],Z=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],j=[r.scale.x,r.scale.y,r.scale.z],ie=!1;for(let ee=0;ee<v;ee++){let ne=ee/(v-1)*I;g.push(ne);try{P(ne)}catch{}M.push([r.position.x,r.position.y,r.position.z]),k.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),R.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-B[0])>1e-4||Math.abs(r.position.y-B[1])>1e-4||Math.abs(r.position.z-B[2])>1e-4||Math.abs(r.quaternion.x-Z[0])>1e-4||Math.abs(r.quaternion.y-Z[1])>1e-4||Math.abs(r.quaternion.z-Z[2])>1e-4||Math.abs(r.quaternion.w-Z[3])>1e-4||Math.abs(r.scale.x-j[0])>1e-4)&&(ie=!0)}r.position.set(B[0],B[1],B[2]),r.quaternion.set(Z[0],Z[1],Z[2],Z[3]),r.scale.set(j[0],j[1],j[2]),ie&&(w={times:g,translations:M,rotations:k,scales:R})}let N=r;if(N.isInstancedMesh&&typeof N.count=="number"&&N.count>0&&N.instanceMatrix?.array){let I=Math.min(1e3,Math.floor(N.count)),_=N.instanceMatrix.array,v=N.instanceColor?.array,g=r.name||`Mesh_${n.length}`,M=new Float32Array(16),k=new Float32Array(9);for(let R=0;R<I;R++){let B=_.subarray(R*16,(R+1)*16);Re(M,s,B);let Z=new Float32Array(a*3);for(let ne=0;ne<a;ne++){let X=o.getX(ne),ae=o.getY(ne),se=o.getZ(ne);Z[ne*3]=M[0]*X+M[4]*ae+M[8]*se+M[12],Z[ne*3+1]=M[1]*X+M[5]*ae+M[9]*se+M[13],Z[ne*3+2]=M[2]*X+M[6]*ae+M[10]*se+M[14]}let j;if(i.attributes.normal){let ne=i.attributes.normal;j=new Float32Array(a*3),De(k,M);for(let X=0;X<a;X++){let ae=ne.getX(X),se=ne.getY(X),F=ne.getZ(X),H=k[0]*ae+k[3]*se+k[6]*F,E=k[1]*ae+k[4]*se+k[7]*F,V=k[2]*ae+k[5]*se+k[8]*F,O=Math.hypot(H,E,V)||1;j[X*3]=H/O,j[X*3+1]=E/O,j[X*3+2]=V/O}}let ie=h,ee=m;v&&v.length>=(R+1)*3&&(ie=[h[0]*v[R*3],h[1]*v[R*3+1],h[2]*v[R*3+2]],ee=`${m}_inst_${R}`),n.push({name:`${g}_${R}`,positions:Z,indices:f,normals:j,uvs:l,materialName:ee,color:ie,roughness:p,metallic:d,clearcoat:y,clearcoatRoughness:T,ior:S,opacity:b,emissiveColor:A,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:u,indices:f,normals:c,uvs:l,materialName:m,color:h,roughness:p,metallic:d,clearcoat:y,clearcoatRoughness:T,ior:S,opacity:b,emissiveColor:A,xrTraits:r.userData?.xr,timeSamples:w})}}),n}function No(e){let t=[],n=e.gltf,r=ge().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,e);let i=e.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),a=n.accessors||[],u=n.bufferViews||[],s=n.materials||[],c=n.meshes||[],l=n.nodes||[];function f(p){let d=a[p];if(!d)throw new Error(`Accessor ${p} not found`);let y=u[d.bufferView||0],T=(y.byteOffset||0)+(d.byteOffset||0),S=y.byteLength||0,b=o.slice(T,T+S);return{acc:d,buffer:b}}let m=new Map;if(l.length>0){let p=ft(n);for(let d=0;d<p.length;d++)m.set(d,p[d])}function h(p,d,y,T){let S=c[p];if(!S)return;let b=new Float32Array(9);De(b,d);for(let A=0;A<(S.primitives||[]).length;A++){let w=S.primitives[A],P=w.attributes?.POSITION;if(P===void 0)continue;let{acc:N,buffer:I}=f(P),_=new Float32Array(I,0,N.count*3),v=new Float32Array(_.length);for(let E=0;E<N.count;E++){let V=_[E*3],O=_[E*3+1],U=_[E*3+2];v[E*3]=d[0]*V+d[4]*O+d[8]*U+d[12],v[E*3+1]=d[1]*V+d[5]*O+d[9]*U+d[13],v[E*3+2]=d[2]*V+d[6]*O+d[10]*U+d[14]}let g,M=w.attributes?.NORMAL;if(M!==void 0){let{acc:E,buffer:V}=f(M),O=new Float32Array(V,0,E.count*3);g=new Float32Array(O.length);for(let U=0;U<E.count;U++){let G=O[U*3],K=O[U*3+1],ue=O[U*3+2],re=b[0]*G+b[3]*K+b[6]*ue,D=b[1]*G+b[4]*K+b[7]*ue,x=b[2]*G+b[5]*K+b[8]*ue,C=Math.hypot(re,D,x)||1;g[U*3]=re/C,g[U*3+1]=D/C,g[U*3+2]=x/C}}let k,R=w.attributes?.TEXCOORD_0;if(R!==void 0){let{acc:E,buffer:V}=f(R);k=new Float32Array(V,0,E.count*2)}let B;if(w.indices!==void 0){let{acc:E,buffer:V}=f(w.indices);E.componentType===5125?B=new Uint32Array(V,0,E.count):B=new Uint16Array(V,0,E.count);let O=N.count;for(let U of B)if(U>=O)throw new Error(`SecurityError: Index buffer value (${U}) out of vertex bounds [0, ${O}).`)}else{let E=N.count;B=E>65535?new Uint32Array(E):new Uint16Array(E);for(let V=0;V<E;V++)B[V]=V}let Z="DefaultMaterial",j=[.8,.8,.8],ie=.5,ee=.1,ne=0,X=0,ae=1.5,se=1,F=[0,0,0];if(w.material!==void 0&&s[w.material]){let E=s[w.material];Z=E.name||`Material_${w.material}`;let V=E.pbrMetallicRoughness||{},O=1;Array.isArray(V.baseColorFactor)&&(j=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&(O=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(ie=V.roughnessFactor),typeof V.metallicFactor=="number"&&(ee=V.metallicFactor),Array.isArray(E.emissiveFactor)&&E.emissiveFactor.length>=3&&(F=[E.emissiveFactor[0],E.emissiveFactor[1],E.emissiveFactor[2]]);let U=E.extensions||{};U.KHR_materials_clearcoat&&(ne=U.KHR_materials_clearcoat.clearcoatFactor??0,X=U.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),U.KHR_materials_ior&&typeof U.KHR_materials_ior.ior=="number"&&(ae=U.KHR_materials_ior.ior);let G=U.KHR_materials_transmission?.transmissionFactor??0;se=O*(1-G)}let H=(S.primitives||[]).length>1?`${y}_p${A}`:y;t.push({name:H,positions:v,indices:B,normals:g,uvs:k,materialName:Z,color:j,roughness:ie,metallic:ee,clearcoat:ne,clearcoatRoughness:X,ior:ae,opacity:se,emissiveColor:F,xrTraits:T?.xr||S.extras?.xr})}}if(l.length>0)for(let p=0;p<l.length;p++){let d=l[p];if(d.mesh!==void 0&&d.mesh<c.length){let y=m.get(p)||Te(),T=d.name||c[d.mesh].name||`Node_${p}`,S=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(S&&typeof S=="object"){let b=S.TRANSLATION,A=S.ROTATION,w=S.SCALE,P=b!==void 0?(()=>{let{acc:v,buffer:g}=f(b);return new Float32Array(g,0,v.count*3)})():null,N=A!==void 0?(()=>{let{acc:v,buffer:g}=f(A);return new Float32Array(g,0,v.count*4)})():null,I=w!==void 0?(()=>{let{acc:v,buffer:g}=f(w);return new Float32Array(g,0,v.count*3)})():null,_=Math.min(1e3,P?P.length/3:N?N.length/4:I?I.length/3:0);if(_>0){let v=new Float32Array(16),g=new Float32Array(16);for(let M=0;M<_;M++){let k=P?[P[M*3],P[M*3+1],P[M*3+2]]:[0,0,0],R=N?[N[M*4],N[M*4+1],N[M*4+2],N[M*4+3]]:[0,0,0,1],B=I?[I[M*3],I[M*3+1],I[M*3+2]]:[1,1,1];Qe(v,R,k,B),Re(g,y,v),h(d.mesh,g,`${T}_${M}`,d.extras)}continue}}h(d.mesh,y,T,d.extras)}}else{let p=Te();for(let d=0;d<c.length;d++){let y=c[d].name||`Mesh_${d}`;h(d,p,y,c[d].extras)}}return t}function ei(e,t){if(!e||typeof e!="string")return t;let n=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||t}function Po(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Ae(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}function Do(e){let t=e.length/3,n=new Array(t);for(let r=0;r<t;r++)n[r]=`(${Ae(e[r*3])}, ${Ae(e[r*3+1])}, ${Ae(e[r*3+2])})`;return n.join(", ")}function Ma(e,t){let n=new Array(t);for(let r=0;r<t;r++)n[r]=`(${Ae(e[r*2])}, ${Ae(1-e[r*2+1])})`;return n.join(", ")}function Sa(e){return Array.from(e).join(", ")}function ti(e){let t=new Map;for(let s of e){let c=ei(s.materialName,"DefaultMaterial");t.has(c)||t.set(c,{color:s.color||[.8,.8,.8],roughness:s.roughness??.5,metallic:s.metallic??0,clearcoat:s.clearcoat??0,clearcoatRoughness:s.clearcoatRoughness??0,ior:s.ior??1.5,opacity:s.opacity??1,emissiveColor:s.emissiveColor||[0,0,0]})}let n=0,r=null;for(let s of e){if(s.timeSamples&&s.timeSamples.times.length>0){let c=s.timeSamples.times[s.timeSamples.times.length-1];c>n&&(n=c)}s.xrTraits?.anchor&&!r&&(r=s.xrTraits.anchor==="vertical"||s.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
252
|
+
endTimeCode = ${Ae(n)}
|
|
210
253
|
timeCodesPerSecond = 1.0
|
|
211
254
|
`);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
|
|
212
255
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
@@ -223,85 +266,87 @@ kind = "component"
|
|
|
223
266
|
{
|
|
224
267
|
${o}def Scope "Materials"
|
|
225
268
|
{
|
|
226
|
-
`;for(let[c
|
|
227
|
-
`,
|
|
228
|
-
`),
|
|
229
|
-
`),
|
|
230
|
-
`),(
|
|
231
|
-
`),a+=`def Material "${
|
|
269
|
+
`;for(let[s,c]of t.entries()){let[l,f,m]=c.color,[h,p,d]=c.emissiveColor,y="";c.clearcoat>0&&(y+=`float inputs:clearcoat = ${Ae(c.clearcoat)}
|
|
270
|
+
`,y+=`float inputs:clearcoatRoughness = ${Ae(c.clearcoatRoughness)}
|
|
271
|
+
`),c.ior!==1.5&&(y+=`float inputs:ior = ${Ae(c.ior)}
|
|
272
|
+
`),c.opacity<1&&(y+=`float inputs:opacity = ${Ae(c.opacity)}
|
|
273
|
+
`),(h>0||p>0||d>0)&&(y+=`color3f inputs:emissiveColor = (${Ae(h)}, ${Ae(p)}, ${Ae(d)})
|
|
274
|
+
`),a+=`def Material "${s}"
|
|
232
275
|
{
|
|
233
276
|
def Shader "PBRShader"
|
|
234
277
|
{
|
|
235
278
|
uniform token info:id = "UsdPreviewSurface"
|
|
236
|
-
color3f inputs:diffuseColor = (${
|
|
237
|
-
float inputs:metallic = ${
|
|
238
|
-
float inputs:roughness = ${
|
|
239
|
-
${
|
|
279
|
+
color3f inputs:diffuseColor = (${Ae(l)}, ${Ae(f)}, ${Ae(m)})
|
|
280
|
+
float inputs:metallic = ${Ae(c.metallic)}
|
|
281
|
+
float inputs:roughness = ${Ae(c.roughness)}
|
|
282
|
+
${y}token outputs:surface
|
|
240
283
|
}
|
|
241
|
-
token outputs:surface.connect = </Root/Materials/${
|
|
284
|
+
token outputs:surface.connect = </Root/Materials/${s}/PBRShader.outputs:surface>
|
|
242
285
|
}
|
|
243
286
|
`}a+=`}
|
|
244
287
|
def Scope "Meshes"
|
|
245
288
|
{
|
|
246
|
-
`;let
|
|
289
|
+
`;let u=new Set;for(let s=0;s<e.length;s++){let c=e[s],l=c.positions.length/3,f=1/0,m=1/0,h=1/0,p=-1/0,d=-1/0,y=-1/0;for(let N=0;N<l;N++){let I=c.positions[N*3],_=c.positions[N*3+1],v=c.positions[N*3+2];I<f&&(f=I),I>p&&(p=I),_<m&&(m=_),_>d&&(d=_),v<h&&(h=v),v>y&&(y=v)}isFinite(f)||(f=m=h=-1,p=d=y=1);let T=Math.floor(c.indices.length/3),S=ei(c.materialName,"DefaultMaterial"),b=ei(c.name,`Mesh_${s}`);u.has(b)&&(b=`${b}_${s}`),u.add(b);let A=T>0?T===1?"3":"3, ".repeat(T-1)+"3":"",w=c.xrTraits,P="";if(w){let N=[];w.physics&&w.physics!=="none"&&N.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let I=ge().xrTraitSerializer?.usdLines(w,Po)??[];if(!I.length)for(let _ of["grab","billboard","follow","anchor","physics"]){let v=_==="follow"&&typeof w.follow=="object"?w.follow.mode??"head":w[_];v!==void 0&&I.push(`string ${_} = "${Po(v)}"`)}I.length>0&&N.push(`customData = {
|
|
247
290
|
dictionary xr = {
|
|
248
|
-
${
|
|
291
|
+
${I.join(`
|
|
249
292
|
`)}
|
|
250
293
|
}
|
|
251
|
-
}`),
|
|
252
|
-
${
|
|
294
|
+
}`),N.length>0&&(P=` (
|
|
295
|
+
${N.join(`
|
|
253
296
|
`)}
|
|
254
|
-
)`)}if(a+=`def Mesh "${
|
|
297
|
+
)`)}if(a+=`def Mesh "${b}"${P}
|
|
255
298
|
{
|
|
256
|
-
`,
|
|
257
|
-
bool physics:kinematicEnabled = ${
|
|
299
|
+
`,w?.physics&&w.physics!=="none"){let N=w.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
|
|
300
|
+
bool physics:kinematicEnabled = ${N}
|
|
258
301
|
bool physics:collisionEnabled = true
|
|
259
|
-
`}if(
|
|
260
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
261
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
302
|
+
`}if(c.timeSamples&&c.timeSamples.times.length>0){let N=c.timeSamples,I=N.times.map((g,M)=>{let k=N.translations?.[M]||[0,0,0];return`${Ae(g)}: (${Ae(k[0])}, ${Ae(k[1])}, ${Ae(k[2])})`}).join(", "),_=N.times.map((g,M)=>{let k=N.rotations?.[M]||[0,0,0,1];return`${Ae(g)}: (${Ae(k[3])}, ${Ae(k[0])}, ${Ae(k[1])}, ${Ae(k[2])})`}).join(", "),v=N.times.map((g,M)=>{let k=N.scales?.[M]||[1,1,1];return`${Ae(g)}: (${Ae(k[0])}, ${Ae(k[1])}, ${Ae(k[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${I} }
|
|
303
|
+
quatf xformOp:orient.timeSamples = { ${_} }
|
|
304
|
+
double3 xformOp:scale.timeSamples = { ${v} }
|
|
262
305
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
263
|
-
`}a+=`float3[] extent = [(${
|
|
264
|
-
int[] faceVertexCounts = [${
|
|
265
|
-
int[] faceVertexIndices = [${
|
|
266
|
-
point3f[] points = [${
|
|
267
|
-
`,
|
|
306
|
+
`}a+=`float3[] extent = [(${Ae(f)}, ${Ae(m)}, ${Ae(h)}), (${Ae(p)}, ${Ae(d)}, ${Ae(y)})]
|
|
307
|
+
int[] faceVertexCounts = [${A}]
|
|
308
|
+
int[] faceVertexIndices = [${Sa(c.indices)}]
|
|
309
|
+
point3f[] points = [${Do(c.positions)}]
|
|
310
|
+
`,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${Do(c.normals)}] (
|
|
268
311
|
interpolation = "vertex"
|
|
269
312
|
)
|
|
270
|
-
`),
|
|
313
|
+
`),c.uvs&&c.uvs.length===l*2&&(a+=`texCoord2f[] primvars:st = [${Ma(c.uvs,l)}] (
|
|
271
314
|
interpolation = "vertex"
|
|
272
315
|
)
|
|
273
|
-
`),a+=`rel material:binding = </Root/Materials/${
|
|
316
|
+
`),a+=`rel material:binding = </Root/Materials/${S}>
|
|
274
317
|
}
|
|
275
318
|
`}return a+=`}
|
|
276
319
|
}
|
|
277
|
-
`,a}function _r(t,e){if(t&&typeof t.traverse=="function"){let i=Pi(t,e);return Fn(i)}let n=ke(t),r=Er(n);return Fn(r)}var Nt=null;function Cr(t){if(!Nt){Nt=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;Nt[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=Nt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function kn(t){let e=[],n=0,r=[];for(let u of t){let m=Ut(u.filename),h=Cr(u.data),f=u.data.length,d=30+m.length,p=n+d,x=0,P=p%64;P!==0&&(x=64-P);let E=new Uint8Array(d+x),y=new DataView(E.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,x,!0),E.set(m,30),x>0&&E.fill(0,30+m.length),e.push({offset:n,size:f,crc:h,filenameBytes:m,entry:u}),r.push(E),r.push(u.data),n+=E.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,a=new Uint8Array(22),l=new DataView(a.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(a),n+=22;let c=new Uint8Array(n),s=0;for(let u of r)c.set(u,s),s+=u.length;return c}function Ke(t){let e=_r(t),n=Ut(e);return kn([{filename:"model.usda",data:n}])}function st(t){let e=ke(t),n=Er(e),r=Fn(n),i=Ut(r);return kn([{filename:"model.usda",data:i}])}function at(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ke(t):st(t)}function Ze(t){let e=at(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function Ot(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Di(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Fi(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Pr(t){let e=Fi(t);if(!e)return null;let n=e.target;return{target:Di(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Ot(e.radius,.01,50,.5),speed:Ot(e.speed,-20,20,.5),height:Ot(e.height,-10,10,0),phase:Ot(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}var Bt=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,a=n.x,l=n.y,c=n.z;return this.x=i*c-o*l,this.y=o*a-r*c,this.z=r*l-i*a,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,a=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])*a,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*a,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*a,this}},Vt=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}},mt=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}},ht=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,a=Math.cos(r/2),l=Math.cos(i/2),c=Math.cos(o/2),s=Math.sin(r/2),u=Math.sin(i/2),m=Math.sin(o/2);return this._x=s*l*c+a*u*m,this._y=a*u*c-s*l*m,this._z=a*l*m+s*u*c,this._w=a*l*c-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,a=e.w,l=n.x,c=n.y,s=n.z,u=n.w;return this._x=r*u+a*l+i*s-o*c,this._y=i*u+a*c+o*l-r*s,this._z=o*u+a*s+r*c-i*l,this._w=a*u-r*l-i*c-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},ze=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 Ye(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 be(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return qe(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}},zt=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}},Re=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}},Ht=class extends re{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Xt=class extends re{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Wt=class extends re{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},we=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,a=new le,l=new le,c=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)),a.set(e.getX(f),e.getY(f),e.getZ(f)),l.subVectors(a,o),c.subVectors(i,o),l.cross(c).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)),a.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),l.subVectors(a,o),c.subVectors(i,o),l.cross(c).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(){}},dt=class extends we{constructor(e=1,n=1,r=1){super();let i=e/2,o=n/2,a=r/2,l=[-i,-o,a,i,-o,a,i,o,a,-i,o,a,i,-o,-a,-i,-o,-a,-i,o,-a,i,o,-a,-i,o,a,i,o,a,i,o,-a,-i,o,-a,-i,-o,-a,i,-o,-a,i,-o,a,-i,-o,a,i,-o,a,i,-o,-a,i,o,-a,i,o,a,-i,-o,-a,-i,-o,a,-i,o,a,-i,o,-a],c=[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(c),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},Gt=class extends we{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],a=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],c=[0,2,1,2,3,1];this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},ft=class extends we{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=[],a=[],l=[],c=[];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,x=-e*Math.cos(d)*Math.sin(p),P=e*Math.cos(p),E=e*Math.sin(d)*Math.sin(p);i.push(x,P,E);let y=Math.hypot(x,P,E)||1;o.push(x/y,P/y,E/y),a.push(f,1-m),u.push(i.length/3-1)}c.push(u)}for(let s=0;s<r;s++)for(let u=0;u<n;u++){let m=c[s][u+1],h=c[s][u],f=c[s+1][u],d=c[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(a),2)),this.setIndex(l)}},Oe=class extends we{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],a=[],l=[],c=[],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,x=p*Math.PI*2,P=Math.sin(x),E=Math.cos(x);o.push(h*P,f,h*E),a.push(P,0,E),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;c.push(m,h,d,h,f,d)}if(e>0){let u=o.length/3;o.push(0,s,0),a.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),a.push(0,1,0),l.push(p*.5+.5,d*.5+.5)}for(let h=0;h<i;h++)c.push(u,m+h,m+h+1)}if(n>0){let u=o.length/3;o.push(0,-s,0),a.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),a.push(0,-1,0),l.push(p*.5+.5,1-(d*.5+.5))}for(let h=0;h<i;h++)c.push(u,m+h+1,m+h)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},$t=class extends Oe{constructor(e=1,n=1,r=16){super(0,e,n,r)}},qt=class extends we{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=[],a=[],l=[],c=[];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 x=e*Math.cos(h),P=e*Math.sin(h),E=f-x,y=d-P,v=p,g=Math.hypot(E,y,v)||1;a.push(E/g,y/g,v/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;c.push(m,h,d,h,f,d)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},Yt=class extends we{constructor(e=1,n=.4,r=64,i=8,o=2,a=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],c=[],s=[],u=[],m=new le,h=new le,f=new le,d=new le,p=new le;function x(y,v){let g=Math.cos(v),I=Math.sin(v),b=a/o*v,w=e*(2+Math.cos(b))*.5;y.set(w*g,w*I,e*Math.sin(b)*.5)}let P=[];for(let y=0;y<=i;++y){let v=y/i*Math.PI*2;P.push(-n*Math.cos(v),n*Math.sin(v),y/i)}for(let y=0;y<=r;++y){let v=y/r,g=v*o*Math.PI*2;x(m,g),x(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 I=0;I<=i;++I){let b=I*3,w=P[b],R=P[b+1],_=P[b+2],B=w*d.x+R*p.x,z=w*d.y+R*p.y,D=w*d.z+R*p.z;l.push(m.x+B,m.y+z,m.z+D);let C=Math.hypot(B,z,D)||1;c.push(B/C,z/C,D/C),s.push(v,_)}}let E=i+1;for(let y=1;y<=r;y++){let v=E*(y-1),g=v+E;for(let I=1;I<=i;I++){let b=v+(I-1),w=g+(I-1),R=g+I,_=v+I;u.push(b,w,_,w,R,_)}}this.setAttribute("position",new re(new Float32Array(l),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},pt=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(){}},jt=class{load(e,n){let r=new pt(e);return n?.(r),r}};function ye(t,e){return t!==void 0?Number(t):e}function Nn(t,e){return t!==void 0?!!t:e}var Ce=class{constructor(e={}){this.name=e.name||"",this.color=new Re(e.color!==void 0?e.color:16777215),this.emissive=new Re(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ye(e.emissiveIntensity,1),this.roughness=ye(e.roughness,.5),this.metalness=ye(e.metalness,.1),this.opacity=ye(e.opacity,1),this.transparent=Nn(e.transparent,!1),this.wireframe=Nn(e.wireframe,!1),this.side=ye(e.side,2),this.doubleSided=Nn(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ye(e.clearcoat,0),this.clearcoatRoughness=ye(e.clearcoatRoughness,0),this.sheen=ye(e.sheen,0),this.sheenColor=new Re(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ye(e.sheenRoughness,0),this.transmission=ye(e.transmission,0),this.thickness=ye(e.thickness,0),this.attenuationColor=new Re(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ye(e.attenuationDistance,1/0),this.ior=ye(e.ior,1.5),this.dispersion=ye(e.dispersion,0),this.iridescence=ye(e.iridescence,0),this.iridescenceIOR=ye(e.iridescenceIOR,1.3)}dispose(){}},He=class extends Ce{},Kt=class extends Ce{},Zt=class extends Ce{},Jt=class extends Ce{},Qt=class extends Ce{},Te=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 mt,this.quaternion=new ht,this.scale=new le(1,1,1),this.matrix=new ze,this.matrixWorld=new ze,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 ze;o.lookAt(this.position,i,new le(0,1,0));let a=o.elements,l=a[0],c=a[4],s=a[8],u=a[1],m=a[5],h=a[9],f=a[2],d=a[6],p=a[10],x=l+m+p;if(x>0){let P=.5/Math.sqrt(x+1);this.quaternion.set((d-h)*P,(s-f)*P,(u-c)*P,.25/P)}}},en=class extends Te{},Je=class extends Te{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof we?n:n?(Ae("unsupported geometry","BoxGeometry"),new dt(.5,.5,.5)):new we,this.material=i instanceof Ce?i:i?(Ae("unsupported material","MeshStandardMaterial"),new He({color:13421772})):new He}},Xe=class extends Te{constructor(e=16777215,n=1){super(),this.color=new Re(e),this.intensity=Number(n),this.type="directional"}},bt=class extends Xe{constructor(e,n){super(e,n),this.type="ambient"}},tn=class extends Xe{constructor(n,r){super(n,r);this.target=new Te;this.type="directional"}},yt=class extends Xe{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}},gt=class extends Te{},nn=class extends gt{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)}},xt=class extends Te{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return _e.validate(this),je(this)}toGLB(){return _e.validate(this),ot(this)}toUSDZ(){return _e.validate(this),Ke(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Je){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},Un=je,On=ot,Or=Ke;var _e=class{static validate(e){let n=0,r=0,i=0,o=new Set,a=(c,s,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${c} (${s}). Found: ${u}`)},l=(c,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${c} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(c=>{if(c instanceof Je){i++,i>1e3&&a("MESHES",1e3,i);let s=c.geometry;if(s){let u=0;if(s.attributes.position&&(u=l("vertex",s.attributes.position.count),n+=u,n>1e5&&a("VERTICES",1e5,n)),s.index){let m=l("index",s.index.count);r+=m,r>3e5&&a("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(c.material){let u=c.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&a("TEXTURES",16,o.size);for(let c of o){let s=c,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)&&a("TEXTURE_DIMENSION",2048,Math.max(m,h))}}},rn=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 Re(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,a)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(a&&a.length?self.postMessage(o,a):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),a={};for(let[l,c]of o.entries())a[l]=Array.from(c);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let o=Un(e),a=On(e),l=(o.lights||[]).map(c=>({type:c.type,color:c.color,intensity:c.intensity,position:c.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[a.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 Ir(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var on=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=Ir(),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=Ir();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function ki(){}var ut=new Proxy(ki,{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:ut},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>ut,construct:()=>ut}),Lr=(()=>{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 et(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Be(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,et());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 Dr,ct;function Br(t){if(!Be(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(ct===void 0||Dr!==n){Dr=n;try{ct=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Be(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{ct=null}}return ct?ct.createScriptURL(t):t}function Ni(t){ie().sandboxEngineSrc=t}function Bn(){let t=ie().sandboxEngineSrc;if(t)return t;if(Lr)return Lr;try{if(typeof document>"u")return null;let e=et(),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)&&Be(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ui(){let t=Bn();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(!Be(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,et()).href}function Oi(t){ie().sandboxIframeSrc=t}function Vr(){let t=ie().sandboxIframeSrc;if(t)return t;let e=Bn();if(!e||!Be(e))return null;let n=new URL(e,et());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Bi(){let t=Vr();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(!Be(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,et()).href}function Vi(t){ie().allowClientScripts=t}function zr(){return!!ie().allowClientScripts}function zi(t){if(!Be(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,et()).href}var Hi=["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 Xi(t){let e=self,n=t.nonce,r=t.engineSrc,i=t.allowedScriptUrl,o=t.allowClientScripts,a=t.revoked,l=e.postMessage.bind(e);function c(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 I={createScriptURL:function(w){if(w!==r&&(!i||w!==i))throw new TypeError("Disallowed worker importScripts URL");return w}};o&&(I.createScript=function(w){return String(w)});let b=e.trustedTypes.createPolicy("three-live#worker-boot",I);g=b.createScriptURL(r),i&&(u=b.createScriptURL(i)),o&&typeof b.createScript=="function"&&(m=b.createScript.bind(b))}catch{}s(g)}catch(g){c('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"){c('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<a.length;g++){let I=a[g],b=e;for(;b&&b!==Object.prototype;){if(b!==e)try{delete b[I]}catch{}try{Object.defineProperty(b,I,{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"],x=!1;function P(g,I){if(g.type==="3D_MODEL_READY"){if(x)return;x=!0}g.nonce=n,I&&I.length?l(g,I):l(g)}let E=function(g,I){if(!g||p.indexOf(g.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");P(g,I)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:E,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let v=!1;e.onmessage=function(g){let I=g&&g.data;if(!(!I||I.nonce!==n)&&!(I.type!=="EXECUTE"&&I.type!=="EXECUTE_URL")&&!v){v=!0;try{let b=new h.Scene,w=new h.PerspectiveCamera(60,1,.1,1e3),R=new h.WebGLRenderer({isSandboxed:!0});if(I.type==="EXECUTE_URL"){if(!i||I.scriptUrl!==i||typeof s!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=u||i,B=s;if(s=null,u=null,e.THREE=h,e.scene=b,e.camera=w,e.renderer=R,B(_),typeof e.__THREE_LIVE_SCENE__=="function"){let z=e.__THREE_LIVE_SCENE__(h,b,w,R);z&&typeof z.toGLB=="function"&&(b=z)}else e.scene&&typeof e.scene.toGLB=="function"&&(b=e.scene)}else{if(!o){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
320
|
+
`,a}function ko(e,t){if(e&&typeof e.traverse=="function"){let i=wa(e,t);return ti(i)}let n=ht(e),r=No(n);return ti(r)}var zn=null;function Fo(e){if(!zn){zn=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;zn[n]=r}}let t=4294967295;for(let n=0;n<e.length;n++)t=zn[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function ni(e){let t=[],n=0,r=[];for(let l of e){let f=Gn(l.filename),m=Fo(l.data),h=l.data.length,p=30+f.length,d=n+p,y=0,T=d%64;T!==0&&(y=64-T);let S=new Uint8Array(p+y),b=new DataView(S.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,m,!0),b.setUint32(18,h,!0),b.setUint32(22,h,!0),b.setUint16(26,f.length,!0),b.setUint16(28,y,!0),S.set(f,30),y>0&&S.fill(0,30+f.length),t.push({offset:n,size:h,crc:m,filenameBytes:f,entry:l}),r.push(S),r.push(l.data),n+=S.length+l.data.length}let i=n;for(let l of t){let f=new Uint8Array(46+l.filenameBytes.length),m=new DataView(f.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint16(14,0,!0),m.setUint32(16,l.crc,!0),m.setUint32(20,l.size,!0),m.setUint32(24,l.size,!0),m.setUint16(28,l.filenameBytes.length,!0),m.setUint16(30,0,!0),m.setUint16(32,0,!0),m.setUint16(34,0,!0),m.setUint16(36,0,!0),m.setUint32(38,0,!0),m.setUint32(42,l.offset,!0),f.set(l.filenameBytes,46),r.push(f),n+=f.length}let o=n-i,a=new Uint8Array(22),u=new DataView(a.buffer);u.setUint32(0,101010256,!0),u.setUint16(4,0,!0),u.setUint16(6,0,!0),u.setUint16(8,t.length,!0),u.setUint16(10,t.length,!0),u.setUint32(12,o,!0),u.setUint32(16,i,!0),u.setUint16(20,0,!0),r.push(a),n+=22;let s=new Uint8Array(n),c=0;for(let l of r)s.set(l,c),c+=l.length;return s}function Yt(e){let t=ko(e),n=Gn(t);return ni([{filename:"model.usda",data:n}])}function sn(e){let t=ht(e),n=No(t),r=ti(n),i=Gn(r);return ni([{filename:"model.usda",data:i}])}function an(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():e&&typeof e.traverse=="function"?Yt(e):sn(e)}function jt(e){let t=an(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function dt(e,t,n,r){let i=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(t,Math.min(n,i))}function Ea(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function ri(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ra(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function Uo(e){let t=ri(e);if(!t)return null;let n=t.target;return{target:Ea(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:dt(t.radius,.01,50,.5),speed:dt(t.speed,-20,20,.5),height:dt(t.height,-10,10,0),phase:dt(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function Hn(e,t){let n=Ra(e,16)?.trim();if(!n)return t;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:t}function ii(e){if(e===!1||e===null||e===void 0)return null;if(typeof e=="number")return!Number.isFinite(e)||e<=0?null:{enabled:!0,strength:dt(e,0,5,.35),threshold:.8,radius:.5};if(e===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let t=ri(e);if(!t||t.enabled===!1)return null;let n=dt(t.strength??t.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:dt(t.threshold,0,4,.8),radius:dt(t.radius,0,2,.5)}}function Xn(e){if(!e)return null;if(typeof e=="string")return{enabled:!0,color:Hn(e,"#38bdf8"),thickness:3,pulse:!1};if(e===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let t=ri(e);if(!t||t.enabled===!1)return null;let n=t.thickness??t.width;return{enabled:!0,color:Hn(t.color,"#38bdf8"),thickness:dt(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:t.pulse===!0}}var $n=class e{constructor(t=0,n=0){this.x=Number(t),this.y=Number(n)}set(t,n){return this.x=Number(t),this.y=Number(n),this}clone(){return new e(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}},ke=class e{constructor(t=0,n=0,r=0){this.x=Number(t),this.y=Number(n),this.z=Number(r)}set(t,n,r){return this.x=Number(t),this.y=Number(n),this.z=Number(r),this}clone(){return new e(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addVectors(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5&&(this.x/=t,this.y/=t,this.z/=t),this}cross(t){let n=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(t,n){let r=t.x,i=t.y,o=t.z,a=n.x,u=n.y,s=n.z;return this.x=i*s-o*u,this.y=o*a-r*s,this.z=r*u-i*a,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}applyMatrix4(t){let n=this.x,r=this.y,i=this.z,o=t.elements,a=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])*a,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*a,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*a,this}},qn=class{constructor(t=0,n=0,r=0,i=1){this.x=Number(t),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(t,n,r,i){return this.x=Number(t),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},mn=class e{constructor(t=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(t),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,n,r,i=this.order){return this._x=Number(t),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this.order=t.order,this._onChangeCallback?.(),this}clone(){return new e(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},fn=class e{constructor(t=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(t),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,n,r,i){return this._x=Number(t),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback?.(),this}clone(){return new e(this._x,this._y,this._z,this._w)}setFromEuler(t,n=!0){let r=t.x,i=t.y,o=t.z,a=Math.cos(r/2),u=Math.cos(i/2),s=Math.cos(o/2),c=Math.sin(r/2),l=Math.sin(i/2),f=Math.sin(o/2);return this._x=c*u*s+a*l*f,this._y=a*l*s-c*u*f,this._z=a*u*f+c*l*s,this._w=a*u*s-c*l*f,n&&this._onChangeCallback?.(),this}setFromAxisAngle(t,n){let r=n/2,i=Math.sin(r);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,n){let r=t.x,i=t.y,o=t.z,a=t.w,u=n.x,s=n.y,c=n.z,l=n.w;return this._x=r*l+a*u+i*c-o*s,this._y=i*l+a*s+o*u-r*c,this._z=o*l+a*c+r*s-i*u,this._w=a*l-r*u-i*s-o*c,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},It=class e{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new e;return t.copy(this),t}compose(t,n,r){return Qe(this.elements,[n.x,n.y,n.z,n.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,n){return Re(this.elements,t.elements,n.elements),this}lookAt(t,n,r){return Ht(this.elements,[t.x,t.y,t.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let n=new ke(0,0,0),r=new ke(1,1,1);return this.compose(n,t,r)}makeTranslation(t,n,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(t,n,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},Yn=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[4]=1,t[8]=1,this}getNormalMatrix(t){return De(this.elements,t.elements),this}},Je=class e{constructor(t,n,r){this.r=1;this.g=1;this.b=1;t!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(t,n,r):this.set(t))}set(t){if(typeof t=="number")this.setHex(t);else if(typeof t=="string")if(t.startsWith("#")){let n=parseInt(t.slice(1),16);this.setHex(n)}else t==="red"?this.setRGB(1,0,0):t==="green"?this.setRGB(0,1,0):t==="blue"?this.setRGB(0,0,1):t==="white"?this.setRGB(1,1,1):t==="black"&&this.setRGB(0,0,0);else t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b));return this}setHex(t){let n=Math.floor(t);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(t,n,r){return this.r=Number(t),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(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new e(this.r,this.g,this.b)}},Xo={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,n)=>Math.max(t,Math.min(n,e)),lerp:(e,t,n)=>e+(t-e)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},we=class{constructor(t,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(t)?this.array=new Float32Array(t):this.array=t,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(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,n){return this.array[t*this.itemSize]=n,this.needsUpdate=!0,this}setY(t,n){return this.array[t*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(t,n){return this.array[t*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(t,n,r,i){let o=t*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},jn=class extends we{constructor(t,n){super(t instanceof Float32Array?t:new Float32Array(t),n)}},Kn=class extends we{constructor(t,n){super(t instanceof Uint16Array?t:new Uint16Array(t),n)}},Zn=class extends we{constructor(t,n){super(t instanceof Uint32Array?t:new Uint32Array(t),n)}},je=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(t,n){return this.attributes[t]=n,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof we)this.index=t;else if(Array.isArray(t)){let n=0;for(let i=0;i<t.length;i++)t[i]>n&&(n=t[i]);let r=n>65535?new Uint32Array(t):new Uint16Array(t);this.index=new we(r,1)}else t&&t.buffer&&(this.index=new we(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let n=t.count,r=new Float32Array(n*3),i=new ke,o=new ke,a=new ke,u=new ke,s=new ke;if(this.index){let c=this.index.array;for(let l=0;l<c.length;l+=3){let f=c[l],m=c[l+1],h=c[l+2];i.set(t.getX(f),t.getY(f),t.getZ(f)),o.set(t.getX(m),t.getY(m),t.getZ(m)),a.set(t.getX(h),t.getY(h),t.getZ(h)),u.subVectors(a,o),s.subVectors(i,o),u.cross(s).normalize();for(let p of[f,m,h])r[p*3]+=u.x,r[p*3+1]+=u.y,r[p*3+2]+=u.z}}else for(let c=0;c<n;c+=3){i.set(t.getX(c),t.getY(c),t.getZ(c)),o.set(t.getX(c+1),t.getY(c+1),t.getZ(c+1)),a.set(t.getX(c+2),t.getY(c+2),t.getZ(c+2)),u.subVectors(a,o),s.subVectors(i,o),u.cross(s).normalize();for(let l=0;l<3;l++)r[(c+l)*3]=u.x,r[(c+l)*3+1]=u.y,r[(c+l)*3+2]=u.z}for(let c=0;c<n;c++){let l=r[c*3],f=r[c*3+1],m=r[c*3+2],h=Math.hypot(l,f,m)||1;r[c*3]=l/h,r[c*3+1]=f/h,r[c*3+2]=m/h}return this.setAttribute("normal",new we(r,3)),this}setFromBuffers(t,n,r,i){this.setAttribute("position",new we(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("normal",new we(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new we(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let t=this.attributes.position,n=new ke(1/0,1/0,1/0),r=new ke(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let i=0;i<t.count;i++){let o=t.getX(i),a=t.getY(i),u=t.getZ(i);o<n.x&&(n.x=o),a<n.y&&(n.y=a),u<n.z&&(n.z=u),o>r.x&&(r.x=o),a>r.y&&(r.y=a),u>r.z&&(r.z=u)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let t=this.computeBoundingBox(),n=(t.min.x+t.max.x)*.5,r=(t.min.y+t.max.y)*.5,i=(t.min.z+t.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let a=0;a<o.count;a++)o.setXYZ(a,o.getX(a)-n,o.getY(a)-r,o.getZ(a)-i);this.computeBoundingBox()}return this}dispose(){}},hn=class extends je{constructor(t=1,n=1,r=1){super();let i=t/2,o=n/2,a=r/2,u=[-i,-o,a,i,-o,a,i,o,a,-i,o,a,i,-o,-a,-i,-o,-a,-i,o,-a,i,o,-a,-i,o,a,i,o,a,i,o,-a,-i,o,-a,-i,-o,-a,i,-o,-a,i,-o,a,-i,-o,a,i,-o,a,i,-o,-a,i,o,-a,i,o,a,-i,-o,-a,-i,-o,a,-i,o,a,-i,o,-a],s=[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],l=[];for(let f=0;f<6;f++){let m=f*4;l.push(m,m+1,m+2,m,m+2,m+3)}this.setAttribute("position",new we(new Float32Array(u),3)),this.setAttribute("normal",new we(new Float32Array(s),3)),this.setAttribute("uv",new we(new Float32Array(c),2)),this.setIndex(l)}},Qn=class extends je{constructor(t=1,n=1){super();let r=t/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],a=[0,0,1,0,0,1,0,0,1,0,0,1],u=[0,1,1,1,0,0,1,0],s=[0,2,1,2,3,1];this.setAttribute("position",new we(new Float32Array(o),3)),this.setAttribute("normal",new we(new Float32Array(a),3)),this.setAttribute("uv",new we(new Float32Array(u),2)),this.setIndex(s)}},dn=class extends je{constructor(t=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));let i=[],o=[],a=[],u=[],s=[];for(let c=0;c<=r;c++){let l=[],f=c/r;for(let m=0;m<=n;m++){let h=m/n,p=h*Math.PI*2,d=f*Math.PI,y=-t*Math.cos(p)*Math.sin(d),T=t*Math.cos(d),S=t*Math.sin(p)*Math.sin(d);i.push(y,T,S);let b=Math.hypot(y,T,S)||1;o.push(y/b,T/b,S/b),a.push(h,1-f),l.push(i.length/3-1)}s.push(l)}for(let c=0;c<r;c++)for(let l=0;l<n;l++){let f=s[c][l+1],m=s[c][l],h=s[c+1][l],p=s[c+1][l+1];c!==0&&u.push(f,m,p),c!==r-1&&u.push(m,h,p)}this.setAttribute("position",new we(new Float32Array(i),3)),this.setAttribute("normal",new we(new Float32Array(o),3)),this.setAttribute("uv",new we(new Float32Array(a),2)),this.setIndex(u)}},St=class extends je{constructor(t=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],a=[],u=[],s=[],c=r/2;for(let l=0;l<=1;l++){let f=l,m=l===0?t:n,h=l===0?c:-c;for(let p=0;p<=i;p++){let d=p/i,y=d*Math.PI*2,T=Math.sin(y),S=Math.cos(y);o.push(m*T,h,m*S),a.push(T,0,S),u.push(d,1-f)}}for(let l=0;l<i;l++){let f=l,m=l+i+1,h=l+i+2,p=l+1;s.push(f,m,p,m,h,p)}if(t>0){let l=o.length/3;o.push(0,c,0),a.push(0,1,0),u.push(.5,.5);let f=o.length/3;for(let m=0;m<=i;m++){let h=m/i*Math.PI*2,p=Math.sin(h),d=Math.cos(h);o.push(t*p,c,t*d),a.push(0,1,0),u.push(d*.5+.5,p*.5+.5)}for(let m=0;m<i;m++)s.push(l,f+m,f+m+1)}if(n>0){let l=o.length/3;o.push(0,-c,0),a.push(0,-1,0),u.push(.5,.5);let f=o.length/3;for(let m=0;m<=i;m++){let h=m/i*Math.PI*2,p=Math.sin(h),d=Math.cos(h);o.push(n*p,-c,n*d),a.push(0,-1,0),u.push(d*.5+.5,1-(p*.5+.5))}for(let m=0;m<i;m++)s.push(l,f+m+1,f+m)}this.setAttribute("position",new we(new Float32Array(o),3)),this.setAttribute("normal",new we(new Float32Array(a),3)),this.setAttribute("uv",new we(new Float32Array(u),2)),this.setIndex(s)}},Jn=class extends St{constructor(t=1,n=1,r=16){super(0,t,n,r)}},er=class extends je{constructor(t=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],a=[],u=[],s=[];for(let c=0;c<=r;c++){let l=c/r*Math.PI*2;for(let f=0;f<=i;f++){let m=f/i*Math.PI*2,h=(t+n*Math.cos(l))*Math.cos(m),p=(t+n*Math.cos(l))*Math.sin(m),d=n*Math.sin(l);o.push(h,p,d);let y=t*Math.cos(m),T=t*Math.sin(m),S=h-y,b=p-T,A=d,w=Math.hypot(S,b,A)||1;a.push(S/w,b/w,A/w),u.push(f/i,c/r)}}for(let c=1;c<=r;c++)for(let l=1;l<=i;l++){let f=(i+1)*c+l-1,m=(i+1)*(c-1)+l-1,h=(i+1)*(c-1)+l,p=(i+1)*c+l;s.push(f,m,p,m,h,p)}this.setAttribute("position",new we(new Float32Array(o),3)),this.setAttribute("normal",new we(new Float32Array(a),3)),this.setAttribute("uv",new we(new Float32Array(u),2)),this.setIndex(s)}},tr=class extends je{constructor(t=1,n=.4,r=64,i=8,o=2,a=3){super(),r=Math.floor(r),i=Math.floor(i);let u=[],s=[],c=[],l=[],f=new ke,m=new ke,h=new ke,p=new ke,d=new ke;function y(b,A){let w=Math.cos(A),P=Math.sin(A),N=a/o*A,I=t*(2+Math.cos(N))*.5;b.set(I*w,I*P,t*Math.sin(N)*.5)}let T=[];for(let b=0;b<=i;++b){let A=b/i*Math.PI*2;T.push(-n*Math.cos(A),n*Math.sin(A),b/i)}for(let b=0;b<=r;++b){let A=b/r,w=A*o*Math.PI*2;y(f,w),y(m,w+.01),h.subVectors(m,f).normalize(),p.addVectors(f,m).normalize(),d.crossVectors(h,p).normalize(),p.crossVectors(d,h).normalize();for(let P=0;P<=i;++P){let N=P*3,I=T[N],_=T[N+1],v=T[N+2],g=I*p.x+_*d.x,M=I*p.y+_*d.y,k=I*p.z+_*d.z;u.push(f.x+g,f.y+M,f.z+k);let R=Math.hypot(g,M,k)||1;s.push(g/R,M/R,k/R),c.push(A,v)}}let S=i+1;for(let b=1;b<=r;b++){let A=S*(b-1),w=A+S;for(let P=1;P<=i;P++){let N=A+(P-1),I=w+(P-1),_=w+P,v=A+P;l.push(N,I,v,I,_,v)}}this.setAttribute("position",new we(new Float32Array(u),3)),this.setAttribute("normal",new we(new Float32Array(s),3)),this.setAttribute("uv",new we(new Float32Array(c),2)),this.setIndex(l)}},pn=class{constructor(t=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},nr=class{load(t,n){let r=new pn(t);return n?.(r),r}};function We(e,t){return e!==void 0?Number(e):t}function oi(e,t){return e!==void 0?!!e:t}var st=class{constructor(t={}){this.name=t.name||"",this.color=new Je(t.color!==void 0?t.color:16777215),this.emissive=new Je(t.emissive!==void 0?t.emissive:0),this.emissiveIntensity=We(t.emissiveIntensity,1),this.roughness=We(t.roughness,.5),this.metalness=We(t.metalness,.1),this.opacity=We(t.opacity,1),this.transparent=oi(t.transparent,!1),this.wireframe=oi(t.wireframe,!1),this.side=We(t.side,2),this.doubleSided=oi(t.doubleSided,!0),this.map=t.map||null,this.clearcoat=We(t.clearcoat,0),this.clearcoatRoughness=We(t.clearcoatRoughness,0),this.sheen=We(t.sheen,0),this.sheenColor=new Je(t.sheenColor!==void 0?t.sheenColor:0),this.sheenRoughness=We(t.sheenRoughness,0),this.transmission=We(t.transmission,0),this.thickness=We(t.thickness,0),this.attenuationColor=new Je(t.attenuationColor!==void 0?t.attenuationColor:16777215),this.attenuationDistance=We(t.attenuationDistance,1/0),this.ior=We(t.ior,1.5),this.dispersion=We(t.dispersion,0),this.iridescence=We(t.iridescence,0),this.iridescenceIOR=We(t.iridescenceIOR,1.3)}dispose(){}},Ct=class extends st{},rr=class extends st{},ir=class extends st{},or=class extends st{},sr=class extends st{},et=class e{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 ke,this.rotation=new mn,this.quaternion=new fn,this.scale=new ke(1,1,1),this.matrix=new It,this.matrixWorld=new It,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,n=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),i=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(n,r,i)})}add(...t){for(let n of t)n&&n instanceof e&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...t){for(let n of t){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(t){t(this);for(let n of this.children)n.traverse(t)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){Wo(this),(this.matrixAutoUpdate||t)&&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(t)}lookAt(t,n,r){let i=typeof t=="object"?t:new ke(t,n,r);this.updateMatrixWorld(!0);let o=new It;o.lookAt(this.position,i,new ke(0,1,0));let a=o.elements,u=a[0],s=a[4],c=a[8],l=a[1],f=a[5],m=a[9],h=a[2],p=a[6],d=a[10],y=u+f+d;if(y>0){let T=.5/Math.sqrt(y+1);this.quaternion.set((p-m)*T,(c-h)*T,(l-s)*T,.25/T)}}},ar=class extends et{},Lt=class extends et{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof je?n:n?(Ke("unsupported geometry","BoxGeometry"),new hn(.5,.5,.5)):new je,this.material=i instanceof st?i:i?(Ke("unsupported material","MeshStandardMaterial"),new Ct({color:13421772})):new Ct}};function Wo(e){let t=ge().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var bn=1e4,yn=class extends Lt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>bn)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${bn})`);this.count=Math.floor(o);let a=new Float32Array(this.count*16);for(let u=0;u<this.count;u++){let s=u*16;a[s]=1,a[s+5]=1,a[s+10]=1,a[s+15]=1}this.instanceMatrix=new we(a,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,a=i*16;if(!(a+16>o.length))for(let u=0;u<16;u++){let s=Number(r.elements[u]);o[a+u]=Number.isFinite(s)?s:u%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,a=i*16;if(!(a+16>o.length))for(let u=0;u<16;u++)r.elements[u]=o[a+u]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let u=new Float32Array(this.count*3);u.fill(1),this.instanceColor=new we(u,3)}let o=this.instanceColor.array,a=i*3;o[a]=Number.isFinite(r.r)?r.r:1,o[a+1]=Number.isFinite(r.g)?r.g:1,o[a+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,a=i*3;r.setRGB(o[a],o[a+1],o[a+2])}dispose(){}},Pt=class extends et{constructor(t=16777215,n=1){super(),this.color=new Je(t),this.intensity=Number(n),this.type="directional"}},gn=class extends Pt{constructor(t,n){super(t,n),this.type="ambient"}},cr=class extends Pt{constructor(n,r){super(n,r);this.target=new et;this.type="directional"}},xn=class extends Pt{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}},vn=class extends et{},ur=class extends vn{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new ke(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Tn=class extends et{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return ot.validate(this),qt(this)}toGLB(){return ot.validate(this),on(this)}toUSDZ(){return ot.validate(this),Yt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Lt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},si=qt,ai=on,$o=Yt;var ot=class{static validate(t){let n=0,r=0,i=0,o=new Set,a=(s,c,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${s} (${c}). Found: ${l}`)},u=(s,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${s} count (${String(c)}), which cannot be bounds-checked.`);return c};t.traverse(s=>{if(Wo(s),s instanceof Lt||s.geometry?.attributes?.position?.count){if(i++,i>1e3&&a("MESHES",1e3,i),s instanceof yn){let l=u("instance",s.count);(l<0||l>bn)&&a("INSTANCES",bn,l)}let c=s.geometry;if(c){let l=0;if(c.attributes.position&&(l=u("vertex",c.attributes.position.count),n+=l,n>1e5&&a("VERTICES",1e5,n)),c.index){let f=u("index",c.index.count);r+=f,r>3e5&&a("INDICES",3e5,r);let m=c.index.array;if(m&&l>0){let h=Math.min(f,m.length);for(let p=0;p<h;p++){let d=m[p];if(!Number.isFinite(d)||d<0||d>=l)throw new Error(`SecurityError: Index buffer value (${String(d)}) out of vertex bounds [0, ${l}).`)}}}}if(s.material){let l=s.material;l.map&&o.add(l.map),l.normalMap&&o.add(l.normalMap),l.roughnessMap&&o.add(l.roughnessMap)}}}),o.size>16&&a("TEXTURES",16,o.size);for(let s of o){let c=s,l=c.image,f=Number(l?.width??c.width??0)||0,m=Number(l?.height??c.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(m)||f>2048||m>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(f,m))}}},lr=class{constructor(t={}){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=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||n,this.containerId=t.containerId||""}setSize(t,n){return this}setPixelRatio(t){return this}setClearColor(t,n=1){let r=new Je(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(t,n){if(this.isSandboxed){ot.validate(t);let i=(o,a)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(a&&a.length?self.postMessage(o,a):self.postMessage(o))};if(this.hasInitialModelRendered){let o=t.getMeshTransforms(),a={};for(let[u,s]of o.entries())a[u]=Array.from(s);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let o=si(t),a=ai(t),u=(o.lights||[]).map(s=>({type:s.type,color:s.color,intensity:s.intensity,position:s.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:u,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[a.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(t.getMeshTransforms()):(r.loadModel(t.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Oo(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var mr=class{constructor(t=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=t,t&&this.start()}start(){this.startTime=Oo(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Oo();t=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=t}return t}};function _a(){}var un=new Proxy(_a,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:un},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>un,construct:()=>un}),Vo=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function Zt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Et(e,t){if(!e||typeof e!="string")return!1;let n=e.trim();if(!n)return!1;try{let r=new URL(n,Zt());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Bo,cn;function qo(e){if(!Et(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return e;if(cn===void 0||Bo!==n){Bo=n;try{cn=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Et(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{cn=null}}return cn?cn.createScriptURL(e):e}function Ia(e){ge().sandboxEngineSrc=e}function ci(){let e=ge().sandboxEngineSrc;if(e)return e;if(Vo)return Vo;try{if(typeof document>"u")return null;let t=Zt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Et(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ca(){let e=ci();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Et(e))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Zt()).href}function La(e){ge().sandboxIframeSrc=e}function Yo(){let e=ge().sandboxIframeSrc;if(e)return e;let t=ci();if(!t||!Et(t))return null;let n=new URL(t,Zt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Pa(){let e=Yo();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Et(e))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Zt()).href}function Da(e){ge().allowClientScripts=e}function jo(){return!!ge().allowClientScripts}function Na(e){if(!Et(e))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Zt()).href}var ka=["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 Fa(e,t){let n=self,r=e.nonce,i=e.engineSrc,o=e.allowedScriptUrl,a=e.allowClientScripts,u=e.revoked,s=n.postMessage.bind(n);function c(P){s({type:"ERROR",nonce:r,message:String(P)})}let l=typeof n.importScripts=="function"?n.importScripts.bind(n):null,f=o,m=null;try{let P=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let N={createScriptURL:function(_){if(_!==i&&(!o||_!==o))throw new TypeError("Disallowed worker importScripts URL");return _}};a&&(N.createScript=function(_){return String(_)});let I=n.trustedTypes.createPolicy("three-live#worker-boot",N);P=I.createScriptURL(i),o&&(f=I.createScriptURL(o)),a&&typeof I.createScript=="function"&&(m=I.createScript.bind(I))}catch{}l(P)}catch(P){c('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: '+(P&&P.message||P));return}let h=n.THREE;if(!h||typeof h.Scene!="function"){c('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}if(Array.isArray(t)){let P=n.__THREE_LIVE_REGISTRY__;for(let N=0;N<t.length;N++)if(typeof t[N]=="function")try{t[N](h,P)}catch{}}for(let P=0;P<u.length;P++){let N=u[P],I=n;for(;I&&I!==Object.prototype;){if(I!==n)try{delete I[N]}catch{}try{Object.defineProperty(I,N,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{I=Object.getPrototypeOf(I)}catch{break}}}let p=Object.freeze({now:function(){return Date.now()}}),d=n;for(;d&&d!==Object.prototype;){if(d!==n)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let y=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],T=!1;function S(P,N){if(P.type==="3D_MODEL_READY"){if(T)return;T=!0}P.nonce=r,N&&N.length?s(P,N):s(P)}let b=function(P,N){if(!P||y.indexOf(P.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+y.join(", ")+").");S(P,N)},A=n;for(;A&&A!==Object.prototype;){if(A===n||Object.prototype.hasOwnProperty.call(A,"postMessage"))try{Object.defineProperty(A,"postMessage",{value:b,writable:!1,configurable:!1})}catch{}try{A=Object.getPrototypeOf(A)}catch{break}}let w=!1;n.onmessage=function(P){let N=P&&P.data;if(!(!N||N.nonce!==r)&&!(N.type!=="EXECUTE"&&N.type!=="EXECUTE_URL")&&!w){w=!0;try{let I=new h.Scene,_=new h.PerspectiveCamera(60,1,.1,1e3),v=new h.WebGLRenderer({isSandboxed:!0});if(N.type==="EXECUTE_URL"){if(!o||N.scriptUrl!==o||typeof l!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let g=f||o,M=l;if(l=null,f=null,n.THREE=h,n.scene=I,n.camera=_,n.renderer=v,M(g),typeof n.__THREE_LIVE_SCENE__=="function"){let k=n.__THREE_LIVE_SCENE__(h,I,_,v);k&&typeof k.toGLB=="function"&&(I=k)}else n.scene&&typeof n.scene.toGLB=="function"&&(I=n.scene)}else{if(!a){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let g=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
278
321
|
return (function () {
|
|
279
|
-
`+
|
|
322
|
+
`+N.script+`
|
|
280
323
|
})();
|
|
281
324
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
282
|
-
`+
|
|
283
|
-
})();`);m=null;let B=_(h,b,w,R);B&&typeof B.toGLB=="function"&&(b=B)}if(!x){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(b);let _=b.toGLB(),B=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);P({type:"3D_MODEL_READY",glbBuffer:B},[B])}l({type:"DONE",nonce:n})}catch(b){c(b&&b.message||b)}}},l({type:"READY",nonce:n})}function Vn(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Hi};return`'use strict';(${Xi.toString()})(${JSON.stringify(o)});`}function Hr(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 Xr(){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 Wi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Gi=1024,$i=256;function Fr(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 zn(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,Gi)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Fr(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 a=Object.create(null),l=i;for(let c of o){if(c.length>$i||c==="__proto__"||c==="constructor"||c==="prototype")return null;let s=l[c];if(!Fr(s))return null;a[c]=s}return{type:"3D_UPDATE_TRANSFORMS",transforms:a}}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 qi(t){let e=Wi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Wr(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 Yi(t,e,n,r){let i=Xr(),o=Vn(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=n,Ue++;let l=!1,c=!1,s={modelDispatched:!1},u,m=()=>{if(l||c)return;let p=a.contentWindow;!p||typeof p.postMessage!="function"||(c=!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||!a.contentWindow||p.source!==a.contentWindow)return;let x=p.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){m();return}let P=zn(x,i);P&&Wr(P,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 a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{l||(h(),Hr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),a.onload=()=>{m()},a.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(a),{terminate:h}}function kr(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=Ui()}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=Bi()}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(Yi(t,i,h,n))}catch(f){return Promise.reject(f)}}let o=Xr(),a=Vn(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([a],{type:"application/javascript"}),f=URL.createObjectURL(h);try{let d=Br(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 c=!1,s={modelDispatched:!1},u,m=()=>{c||(c=!0,u!==void 0&&clearTimeout(u),Ue=Math.max(0,Ue-1),l.terminate())};return u=setTimeout(()=>{c||(m(),Hr(n))},3e3),l.onmessage=h=>{let f=zn(h.data,o);f&&Wr(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 Nr(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 tt={execute(t,e,n,r){let i=(l,c)=>{let s=new Error(l);return n.onError?.(s),c&&n.onToast?.(c),Promise.reject(s)},o=Nr(e,i);if(o)return o;try{qi(t)}catch(l){let c=l instanceof Error?l.message:String(l);return i(c,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??zr()?kr({kind:"script",script:t},e,n,i):i(Pt,It)},executeUrl(t,e,n){let r=(a,l)=>{let c=new Error(a);return n.onError?.(c),l&&n.onToast?.(l),Promise.reject(c)},i=Nr(e,r);if(i)return i;let o;try{o=zi(t)}catch(a){let l=a instanceof Error?a.message:String(a);return r(l,"Security Error: disallowed scene script URL.")}return kr({kind:"url",scriptUrl:o},e,n,r)}},sn=new Set;function Ae(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;sn.has(n)||(sn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Gr(){return Array.from(sn)}function $r(){sn.clear()}var vt=class extends He{constructor(e={}){Ae("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}},qr=vt,We=class extends ft{constructor(e=1,n=0,r="PolyhedronGeometry"){Ae(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},an=class extends We{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},cn=class extends We{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},un=class extends We{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},ln=class extends We{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},mn=class extends Oe{constructor(e=1,n=1,r=4,i=8){Ae("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},hn=class extends Oe{constructor(e=.5,n=1,r=16){Ae("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},dn=class extends Oe{constructor(e=1,n=16){Ae("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},fn=class extends yt{constructor(n,r,i=0,o=Math.PI/3,a=0,l=2){Ae("SpotLight","PointLight");super(n,r,i,l);this.target=new Te;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=a}},wt=class extends bt{constructor(e,n,r){Ae("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new Re(n??4473924)}},Yr=wt,jr={Vector2:Bt,Vector3:le,Vector4:Vt,Euler:mt,Quaternion:ht,Matrix4:ze,Matrix3:zt,Color:Re,MathUtils:Ur,BufferAttribute:re,Float32BufferAttribute:Ht,Uint16BufferAttribute:Xt,Uint32BufferAttribute:Wt,BufferGeometry:we,BoxGeometry:dt,PlaneGeometry:Gt,SphereGeometry:ft,CylinderGeometry:Oe,ConeGeometry:$t,TorusGeometry:qt,TorusKnotGeometry:Yt,IcosahedronGeometry:an,OctahedronGeometry:cn,DodecahedronGeometry:un,TetrahedronGeometry:ln,CapsuleGeometry:mn,RingGeometry:hn,CircleGeometry:dn,Texture:pt,TextureLoader:jt,Material:Ce,MeshStandardMaterial:He,MeshBasicMaterial:Kt,MeshLambertMaterial:Zt,MeshPhongMaterial:Jt,MeshPhysicalMaterial:Qt,ShaderMaterial:vt,RawShaderMaterial:qr,Object3D:Te,Group:en,Mesh:Je,Light:Xe,AmbientLight:bt,DirectionalLight:tn,PointLight:yt,SpotLight:fn,HemisphereLight:wt,RectAreaLight:Yr,Camera:gt,PerspectiveCamera:nn,Scene:xt,WebGLRenderer:rn,Clock:on,SceneQuotaValidator:_e,exportSceneToCanvas3D:Un,exportSceneToGLB:On,exportSceneToUSDZ:Or,generateUSDZ:at,glbToUSDZ:st,sceneToCanvas3D:je,sceneToGLB:ot,sceneToUSDZ:Ke,authorScriptRunner:tt,getAuthorWarnings:Gr,clearAuthorWarnings:$r};Object.freeze(_e);Object.freeze(_e.prototype);Object.freeze(xt.prototype);Object.freeze(jr);var At=new Proxy(jr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Ae(`THREE.${e}`,"no-op proxy"),ut),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")}}),lt={name:"three_author",THREE:At},ji=lt,Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Qe.THREE>"u"&&(Qe.THREE=At);typeof Qe.requestAnimationFrame!="function"&&(Qe.requestAnimationFrame=()=>(Ae("requestAnimationFrame","single-frame static evaluation"),0));typeof Qe.cancelAnimationFrame!="function"&&(Qe.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=At,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=lt,t.ThreeLivePlugins.three_author=lt,t.ThreeLivePlugins["three-author"]=lt}var Ki=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 Ki{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 ie().arProvider}static set arProvider(n){ie().arProvider=n}static get scriptRunner(){return ie().scriptRunner}static set scriptRunner(n){ie().scriptRunner=n}static get sandboxEngineSrc(){return ie().sandboxEngineSrc??null}static set sandboxEngineSrc(n){ie().sandboxEngineSrc=n}static get sandboxIframeSrc(){return ie().sandboxIframeSrc??null}static set sandboxIframeSrc(n){ie().sandboxIframeSrc=n}static get allowClientScripts(){return!!ie().allowClientScripts}static set allowClientScripts(n){ie().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")||(ie().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,a,l]=i.hitPoint||i.point,[c,s,u]=i.normal;return{position:{x:o,y:a,z:l,toString(){return`${o}m ${a}m ${l}m`}},normal:{x:c,y:s,z:u,toString(){return`${c}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=ke(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let a=this.getAttribute("selected-mesh");a&&this.viewer.setSelectedMesh(a),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||"",a=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),l=/Android|iPhone|iPad|iPod/i.test(o);if(a&&!l&&typeof document<"u"&&this.currentModel&&me.arProvider.createUSDZBlob)try{let c=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:me.arProvider.createUSDZBlob(this.currentModel),s=URL.createObjectURL(c),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")),a=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:a,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 c=this.getAttribute("camera-orbit");c&&this.applyCameraOrbit(c),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 a=document.createElementNS(r,"path");a.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 c=document.createElementNS(r,"line");c.setAttribute("x1","12"),c.setAttribute("y1","22.08"),c.setAttribute("x2","12"),c.setAttribute("y2","12"),o.appendChild(a),o.appendChild(l),o.appendChild(c),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=c=>c.endsWith("rad")?parseFloat(c)*180/Math.PI:parseFloat(c.replace(/deg$/,"")),o=r[0]==="auto"?void 0:i(r[0]),a=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)||a!==void 0&&!isNaN(a))&&this.viewer.setInitialCamera(o!==void 0&&!isNaN(o)?o:void 0,a!==void 0&&!isNaN(a)?a: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 a=!1;n(r,{onModelReady:c=>{this.loadModelWithLimits(c,Sr).then(()=>{a||(a=!0,i(c))},s=>{let u=s instanceof Error?s.message:String(s);this.showToast(u),a||(a=!0,o(s))})},onUpdateTransforms:c=>this.viewer?.updateMeshTransforms(c),onError:c=>{this.showToast(c.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:c}})),a||(a=!0,o(c))},onToast:c=>this.showToast(c)}).then(c=>{c&&(this.scriptHandle=c)},c=>{c instanceof Error&&c.message&&this.showToast(c.message),a||(a=!0,o(c))})})}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(Pt);return this.showToast(It),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 Pe=me;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",Pe);function pn(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function yn(t,e,n,r){let i=e[0],o=e[1],a=e[2],l=e[3],c=n[0],s=n[1],u=n[2],m=n[3],h=i*c+o*s+a*u+l*m;if(h<0&&(c=-c,s=-s,u=-u,m=-m,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=o,t[2]=a,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+c),t[1]=.5*(o+s),t[2]=.5*(a+u),t[3]=.5*(l+m),t;let p=Math.sin((1-r)*f)/d,x=Math.sin(r*f)/d;return t[0]=i*p+c*x,t[1]=o*p+s*x,t[2]=a*p+u*x,t[3]=l*p+m*x,t}function Kr(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 Xn(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}`,a=[],l=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let c of i.channels){if(!c.target||c.target.node===void 0||!c.target.path)continue;let s=i.samplers[c.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),x=pn(e,d,u.count);x.length>0&&x[x.length-1]>l&&(l=x[x.length-1]);let P=c.target.path==="rotation"?4:c.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,u.count))):3,E=pn(e,p,m.count*(c.target.path==="weights"?1:P)),y=s.interpolation==="STEP"?"STEP":"LINEAR";a.push({nodeIndex:c.target.node,path:c.target.path,times:x,values:E,interpolation:y})}a.length>0&&n.push({name:o,duration:l,channels:a})}return n}function nt(t,e,n){let{times:r,values:i,path:o,interpolation:a}=t,l=r.length;if(l===0)return;let c=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/l)):3;if(e<=r[0]){for(let E=0;E<c;E++)n[E]=i[E];return}if(e>=r[l-1]){let E=(l-1)*c;for(let y=0;y<c;y++)n[y]=i[E+y];return}let s=0,u=l-1;for(;s<=u;){let E=s+u>>1;r[E]<=e?s=E+1:u=E-1}let m=Math.max(0,u),h=Math.min(l-1,m+1);if(a==="STEP"||m===h){let E=m*c;for(let y=0;y<c;y++)n[y]=i[E+y];return}let f=r[m],d=r[h],p=(e-f)/Math.max(1e-5,d-f),x=m*c,P=h*c;if(o==="rotation"){let E=[i[x],i[x+1],i[x+2],i[x+3]],y=[i[P],i[P+1],i[P+2],i[P+3]];yn(n,E,y,p)}else for(let E=0;E<c;E++)n[E]=i[x+E]+p*(i[P+E]-i[x+E])}var bn=new WeakMap;function Wn(t,e,n=.3){if(!t?.animations)return;let r=t.animations.find(l=>l.name===e);if(!r)return;let i=bn.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),bn.set(t,i));let o=n>0?1/n:1e3;for(let l of i)l.clip.name!==e&&(l.fadeSpeed=-o);let a=i.find(l=>l.clip.name===e);a?a.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),t.currentClip=r,t.isPlayingAnimation=!0}function Hn(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=bn.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],a=[0,0,0,1],l=[1,1,1],c=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")nt(f,m.time,o),Kr(d.t,d.t,o,h);else if(f.path==="rotation")nt(f,m.time,a),yn(d.r,d.r,a,h);else if(f.path==="scale")nt(f,m.time,l),Kr(d.s,d.s,l,h);else if(f.path==="weights"&&(nt(f,m.time,c),t.meshes)){for(let p of t.meshes)if(p.nodeIndex===f.nodeIndex){for(let x of p.primitives)if(x.pluginData?.morph?.weights){let P=x.pluginData.morph.weights,E=x.pluginData.morph.numTargets||P.length;for(let y=0;y<E;y++)P[y]=P[y]*(1-h)+c[y]*h}}}}}let s=[];for(let m=0;m<r;m++){let h=se(),{t:f,r:d,s:p}=i[m];Ye(h,d,f,p),s.push(h)}let u=Fe(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 Gn={name:"keyframes",evaluateAnimation:Hn,crossFadeTo:Wn,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=Xn(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=bn.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),Hn(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),Hn(t,t.animationTime))}};var St=64;function Zr(t,e,n){if(!(!t?.meshes||e<0||e>=St))for(let r of t.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var $n={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;
|
|
325
|
+
`+N.script+`
|
|
326
|
+
})();`);m=null;let M=g(h,I,_,v);M&&typeof M.toGLB=="function"&&(I=M)}if(!T){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(I);let g=I.toGLB(),M=g instanceof ArrayBuffer?g:g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);S({type:"3D_MODEL_READY",glbBuffer:M},[M])}s({type:"DONE",nonce:r})}catch(I){c(I&&I.message||I)}}},s({type:"READY",nonce:r})}function ui(e,t,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:i,revoked:ka},a=(ge().workerExtensionInstallers??[]).map(u=>`(${u.toString()})`).join(",");return`'use strict';(${Fa.toString()})(${JSON.stringify(o)},[${a}]);`}function Ko(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Mt=0;function Zo(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ua(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Oa=1024,Va=256;function zo(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let n=e[t];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function li(e,t){if(!e||typeof e!="object")return null;let n=e;if(n.nonce!==t)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,Oa)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!zo(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 a=Object.create(null),u=i;for(let s of o){if(s.length>Va||s==="__proto__"||s==="constructor"||s==="prototype")return null;let c=u[s];if(!zo(c))return null;a[s]=c}return{type:"3D_UPDATE_TRANSFORMS",transforms:a}}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 Ba(e){let t=Ua(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Qo(e,t,n,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":n();return;case"ERROR":n(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function za(e,t,n,r){let i=Zo(),o=ui(t,i,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=n,Mt++;let u=!1,s=!1,c={modelDispatched:!1},l,f=()=>{if(u||s)return;let d=a.contentWindow;!d||typeof d.postMessage!="function"||(s=!0,d.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:e.script},"*"))},m=()=>{},h=d=>{if(u||!a.contentWindow||d.source!==a.contentWindow)return;let y=d.data;if(y&&typeof y=="object"&&y.type==="IFRAME_READY"){f();return}let T=li(y,i);T&&Qo(T,r,m,c)};m=()=>{u||(u=!0,l!==void 0&&clearTimeout(l),Mt=Math.max(0,Mt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",h),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},l=setTimeout(()=>{u||(m(),Ko(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",h),a.onload=()=>{f()},a.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){m();let d=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(d),d}return p.appendChild(a),{terminate:m}}function Go(e,t,n,r){if(t==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Mt>=32)return r(`SecurityError: ${Mt} 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=Ca()}catch(m){let h=m instanceof Error?m.message:String(m);return r(h,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let m;try{m=Pa()}catch(h){let p=h instanceof Error?h.message:String(h);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(za(e,i,m,n))}catch(h){return Promise.reject(h)}}let o=Zo(),a=ui(i,o,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),u;try{let m=new Blob([a],{type:"application/javascript"}),h=URL.createObjectURL(m);try{let p=qo(h);u=new Worker(p)}finally{URL.revokeObjectURL(h)}}catch(m){let h=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${h}`,"Security Error: Failed to start Worker sandbox.")}Mt++;let s=!1,c={modelDispatched:!1},l,f=()=>{s||(s=!0,l!==void 0&&clearTimeout(l),Mt=Math.max(0,Mt-1),u.terminate())};return l=setTimeout(()=>{s||(f(),Ko(n))},3e3),u.onmessage=m=>{let h=li(m.data,o);h&&Qo(h,n,f,c)},u.onerror=m=>{f(),n.onError?.(new Error(`Worker execution error: ${m.message}`))},e.kind==="url"?u.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:o}):u.postMessage({type:"EXECUTE",script:e.script,nonce:o}),Promise.resolve({terminate:f})}function Ho(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Qt={execute(e,t,n,r){let i=(u,s)=>{let c=new Error(u);return n.onError?.(c),s&&n.onToast?.(s),Promise.reject(c)},o=Ho(t,i);if(o)return o;try{Ba(e)}catch(u){let s=u instanceof Error?u.message:String(u);return i(s,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??jo()?Go({kind:"script",script:e},t,n,i):i(Ln,Pn)},executeUrl(e,t,n){let r=(a,u)=>{let s=new Error(a);return n.onError?.(s),u&&n.onToast?.(u),Promise.reject(s)},i=Ho(t,r);if(i)return i;let o;try{o=Na(e)}catch(a){let u=a instanceof Error?a.message:String(a);return r(u,"Security Error: disallowed scene script URL.")}return Go({kind:"url",scriptUrl:o},t,n,r)}},fr=new Set;function Ke(e,t){let n=`[three-live] ${e} is unsupported; degraded to ${t}.`;fr.has(n)||(fr.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Jo(){return Array.from(fr)}function es(){fr.clear()}var An=class extends Ct{constructor(t={}){Ke("ShaderMaterial","MeshStandardMaterial");let n=t.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??t.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=n}},ts=An,Dt=class extends dn{constructor(t=1,n=0,r="PolyhedronGeometry"){Ke(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(t,i,i)}},hr=class extends Dt{constructor(t=1,n=0){super(t,n,"IcosahedronGeometry")}},dr=class extends Dt{constructor(t=1,n=0){super(t,n,"OctahedronGeometry")}},pr=class extends Dt{constructor(t=1,n=0){super(t,n,"DodecahedronGeometry")}},br=class extends Dt{constructor(t=1,n=0){super(t,n,"TetrahedronGeometry")}},yr=class extends St{constructor(t=1,n=1,r=4,i=8){Ke("CapsuleGeometry","CylinderGeometry"),super(t,t,n+t*2,i)}},gr=class extends St{constructor(t=.5,n=1,r=16){Ke("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},xr=class extends St{constructor(t=1,n=16){Ke("CircleGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,n))}},vr=class extends xn{constructor(n,r,i=0,o=Math.PI/3,a=0,u=2){Ke("SpotLight","PointLight");super(n,r,i,u);this.target=new et;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=a}},wn=class extends gn{constructor(t,n,r){Ke("HemisphereLight","AmbientLight"),super(t,r),this.groundColor=new Je(n??4473924)}},ns=wn,rs={Vector2:$n,Vector3:ke,Vector4:qn,Euler:mn,Quaternion:fn,Matrix4:It,Matrix3:Yn,Color:Je,MathUtils:Xo,BufferAttribute:we,Float32BufferAttribute:jn,Uint16BufferAttribute:Kn,Uint32BufferAttribute:Zn,BufferGeometry:je,BoxGeometry:hn,PlaneGeometry:Qn,SphereGeometry:dn,CylinderGeometry:St,ConeGeometry:Jn,TorusGeometry:er,TorusKnotGeometry:tr,IcosahedronGeometry:hr,OctahedronGeometry:dr,DodecahedronGeometry:pr,TetrahedronGeometry:br,CapsuleGeometry:yr,RingGeometry:gr,CircleGeometry:xr,Texture:pn,TextureLoader:nr,Material:st,MeshStandardMaterial:Ct,MeshBasicMaterial:rr,MeshLambertMaterial:ir,MeshPhongMaterial:or,MeshPhysicalMaterial:sr,ShaderMaterial:An,RawShaderMaterial:ts,Object3D:et,Group:ar,Mesh:Lt,InstancedMesh:yn,Light:Pt,AmbientLight:gn,DirectionalLight:cr,PointLight:xn,SpotLight:vr,HemisphereLight:wn,RectAreaLight:ns,Camera:vn,PerspectiveCamera:ur,Scene:Tn,WebGLRenderer:lr,Clock:mr,SceneQuotaValidator:ot,exportSceneToCanvas3D:si,exportSceneToGLB:ai,exportSceneToUSDZ:$o,generateUSDZ:an,glbToUSDZ:sn,sceneToCanvas3D:qt,sceneToGLB:on,sceneToUSDZ:Yt,authorScriptRunner:Qt,getAuthorWarnings:Jo,clearAuthorWarnings:es};Object.freeze(ot);Object.freeze(ot.prototype);Object.freeze(Tn.prototype);Object.freeze(rs);var Nt=new Proxy(rs,{get:(e,t)=>{if(t in e)return e[t];let n=ge().authorNamespace;return n&&typeof t=="string"&&t in n?n[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Ke(`THREE.${t}`,"no-op proxy"),un)},has:(e,t)=>{if(t in e)return!0;let n=ge().authorNamespace;return!!(n&&typeof t=="string"&&t in n)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Wn=ge();Wn.threeNamespace=Nt;if(Wn.workerExtensionInstallers)for(let e of Wn.workerExtensionInstallers)e(Nt,Wn);var ln={name:"three_author",THREE:Nt},Ga=ln,Kt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Kt.THREE>"u"&&(Kt.THREE=Nt);typeof Kt.requestAnimationFrame!="function"&&(Kt.requestAnimationFrame=()=>(Ke("requestAnimationFrame","single-frame static evaluation"),0));typeof Kt.cancelAnimationFrame!="function"&&(Kt.cancelAnimationFrame=()=>{});if(typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=Nt,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=ln,e.ThreeLivePlugins.three_author=ln,e.ThreeLivePlugins["three-author"]=ln}function Jt(e,t){let n=e?.trim(),r=n?Number(n):NaN;return Number.isFinite(r)?r:t}var Ha=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(e,t){super(e,t),this.detail=t?.detail??null}});var Be=class Be extends Ha{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 ge().arProvider}static set arProvider(n){ge().arProvider=n}static get scriptRunner(){return ge().scriptRunner}static set scriptRunner(n){ge().scriptRunner=n}static get sandboxEngineSrc(){return ge().sandboxEngineSrc??null}static set sandboxEngineSrc(n){ge().sandboxEngineSrc=n}static get sandboxIframeSrc(){return ge().sandboxIframeSrc??null}static set sandboxIframeSrc(n){ge().sandboxIframeSrc=n}static get allowClientScripts(){return!!ge().allowClientScripts}static set allowClientScripts(n){ge().allowClientScripts=n}static registerScriptRunner(n){Be.scriptRunner=n}static registerDecoder(n,r){He.registerDecoder(n,r)}static getDecoder(n){return He.getDecoder(n)}static registerAR(n){typeof n=="function"?Be.arProvider={activateAR:n}:Be.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof Be&&i.updateARButtonVisibility()})}static isARSupported(){return!!Be.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.loadModel(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 He.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of He.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.loadModel(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?.setToneMapping(_t(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"variant-name":this.viewer&&this.selectVariant(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 He.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")||(ge().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||Be.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 Be.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 _t(this.getAttribute("tone-mapping"))}set toneMapping(n){this.setAttribute("tone-mapping",n)}get bloom(){return this.getFloatAttr("bloom",0)}set bloom(n){this.setAttribute("bloom",String(n))}get bloomThreshold(){return Jt(this.getAttribute("bloom-threshold"),.62)}set bloomThreshold(n){this.setAttribute("bloom-threshold",String(n))}get bloomRadius(){return Jt(this.getAttribute("bloom-radius"),.75)}set bloomRadius(n){this.setAttribute("bloom-radius",String(n))}get outlineSelected(){return this.getBoolAttr("outline-selected")}set outlineSelected(n){this.setBoolAttr("outline-selected",n)}get outlineColor(){return this.getAttr("outline-color")||"#38bdf8"}set outlineColor(n){this.setAttr("outline-color",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 variantName(){return this.viewer?this.viewer.getVariantName():this.getAttr("variant-name")}set variantName(n){this.setAttr("variant-name",n)}get availableVariants(){return this.viewer?this.viewer.getAvailableVariants():[]}selectVariant(n){if(!this.viewer)return!1;let r=this.viewer.selectVariant(n);return r&&this.dispatchEvent(new CustomEvent("variant-applied",{bubbles:!0,composed:!0,detail:{variantName:this.viewer.getVariantName()}})),r}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,a,u]=i.hitPoint||i.point,[s,c,l]=i.normal;return{position:{x:o,y:a,z:u,toString(){return`${o}m ${a}m ${u}m`}},normal:{x:s,y:c,z:l,toString(){return`${s}m ${c}m ${l}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 s=await fetch(n);if(!s.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${s.status}`);i=await s.arrayBuffer()}else i=n;let o=ht(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let a=this.getAttribute("selected-mesh");a&&this.viewer.setSelectedMesh(a);let u=this.getAttribute("variant-name");u&&this.selectVariant(u),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(!Be.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 Be.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||"",a=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),u=/Android|iPhone|iPad|iPod/i.test(o);if(a&&!u&&typeof document<"u"&&this.currentModel&&Be.arProvider.createUSDZBlob)try{let s=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:Be.arProvider.createUSDZBlob(this.currentModel),c=URL.createObjectURL(s),l=document.createElement("a");l.href=c,l.download="three_live_model.usdz",document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(c),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")),a=this.parseCameraTarget(this.getAttribute("camera-target")),u=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new He(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,variantName:this.getAttribute("variant-name")||void 0,fieldOfView:u,cameraTarget:a,minCameraOrbit:i,maxCameraOrbit:o,onMeshClick:c=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:c}))},onCameraChange:c=>{this.updateHotspots();for(let l of He.getRegisteredPlugins())l.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 s=this.getAttribute("camera-orbit");s&&this.applyCameraOrbit(s),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 a=document.createElementNS(r,"path");a.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 u=document.createElementNS(r,"polyline");u.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let s=document.createElementNS(r,"line");s.setAttribute("x1","12"),s.setAttribute("y1","22.08"),s.setAttribute("x2","12"),s.setAttribute("y2","12"),o.appendChild(a),o.appendChild(u),o.appendChild(s),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")&&!!Be.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=this.parseOrbitLimit(n);(r.theta!==void 0||r.phi!==void 0)&&this.viewer.setInitialCamera(r.theta,r.phi,r.distance)}}parseOrbitLimit(n){if(!n)return{};let r=n.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let o=this.parseFieldOfView(r[0]);o!==void 0&&(i.theta=o)}if(r.length>1&&r[1]!=="auto"){let o=this.parseFieldOfView(r[1]);o!==void 0&&(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 He.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(n){let r=Be.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 a=!1;n(r,{onModelReady:s=>{this.loadModelWithLimits(s,_o).then(()=>{a||(a=!0,i(s))},c=>{let l=c instanceof Error?c.message:String(c);this.showToast(l),a||(a=!0,o(c))})},onUpdateTransforms:s=>this.viewer?.updateMeshTransforms(s),onError:s=>{this.showToast(s.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:s}})),a||(a=!0,o(s))},onToast:s=>this.showToast(s)}).then(s=>{s&&(this.scriptHandle=s)},s=>{s instanceof Error&&s.message&&this.showToast(s.message),a||(a=!0,o(s))})})}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(!Be.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Ln);return this.showToast(Pn),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}))}};Be.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","bloom","bloom-threshold","bloom-radius","outline","outline-selected","outline-color","environment-image","skybox-image","autoplay","animation-name","variant-name","auto-rotate","auto-rotate-delay","rotation-per-second"],Be.registerPlugin=He.registerPlugin,Be.getRegisteredPlugins=He.getRegisteredPlugins;var at=Be;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",at);function is(e,t,n){return t%4===0?new Float32Array(e,t,n):new Float32Array(e.slice(t,t+n*4))}function Ar(e,t,n,r){let i=t[0],o=t[1],a=t[2],u=t[3],s=n[0],c=n[1],l=n[2],f=n[3],m=i*s+o*c+a*l+u*f;if(m<0&&(s=-s,c=-c,l=-l,f=-f,m=-m),Math.abs(m)>=1)return e[0]=i,e[1]=o,e[2]=a,e[3]=u,e;let h=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(i+s),e[1]=.5*(o+c),e[2]=.5*(a+l),e[3]=.5*(u+f),e;let d=Math.sin((1-r)*h)/p,y=Math.sin(r*h)/p;return e[0]=i*d+s*y,e[1]=o*d+c*y,e[2]=a*d+l*y,e[3]=u*d+f*y,e}function os(e,t,n,r){return e[0]=t[0]+r*(n[0]-t[0]),e[1]=t[1]+r*(n[1]-t[1]),e[2]=t[2]+r*(n[2]-t[2]),e}function di(e,t){if(!Array.isArray(e?.animations))return[];let n=[];for(let r=0;r<e.animations.length;r++){let i=e.animations[r],o=i.name||`Animation_${r}`,a=[],u=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let s of i.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let c=i.samplers[s.sampler];if(!c)continue;let l=e.accessors?.[c.input],f=e.accessors?.[c.output];if(!l||!f)continue;let m=e.bufferViews?.[l.bufferView],h=e.bufferViews?.[f.bufferView];if(!m||!h)continue;let p=(m.byteOffset||0)+(l.byteOffset||0),d=(h.byteOffset||0)+(f.byteOffset||0),y=it(e,t,l,1)??is(t,p,l.count);y.length>0&&y[y.length-1]>u&&(u=y[y.length-1]);let T=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(f.count/Math.max(1,l.count))):3,S=s.target.path==="weights"?1:T,b=it(e,t,f,S)??is(t,d,f.count*S),A=c.interpolation==="STEP"?"STEP":"LINEAR";a.push({nodeIndex:s.target.node,path:s.target.path,times:y,values:b,interpolation:A})}a.length>0&&n.push({name:o,duration:u,channels:a})}return n}function en(e,t,n){let{times:r,values:i,path:o,interpolation:a}=e,u=r.length;if(u===0)return;let s=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/u)):3;if(t<=r[0]){for(let S=0;S<s;S++)n[S]=i[S];return}if(t>=r[u-1]){let S=(u-1)*s;for(let b=0;b<s;b++)n[b]=i[S+b];return}let c=0,l=u-1;for(;c<=l;){let S=c+l>>1;r[S]<=t?c=S+1:l=S-1}let f=Math.max(0,l),m=Math.min(u-1,f+1);if(a==="STEP"||f===m){let S=f*s;for(let b=0;b<s;b++)n[b]=i[S+b];return}let h=r[f],p=r[m],d=(t-h)/Math.max(1e-5,p-h),y=f*s,T=m*s;if(o==="rotation"){let S=[i[y],i[y+1],i[y+2],i[y+3]],b=[i[T],i[T+1],i[T+2],i[T+3]];Ar(n,S,b,d)}else for(let S=0;S<s;S++)n[S]=i[y+S]+d*(i[T+S]-i[y+S])}var Tr=new WeakMap;function pi(e,t,n=.3){if(!e?.animations)return;let r=e.animations.find(u=>u.name===t);if(!r)return;let i=Tr.get(e);i||(i=[],e.currentClip&&i.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Tr.set(e,i));let o=n>0?1/n:1e3;for(let u of i)u.clip.name!==t&&(u.fadeSpeed=-o);let a=i.find(u=>u.clip.name===t);a?a.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),e.currentClip=r,e.isPlayingAnimation=!0}function hi(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let n=Tr.get(e);if(!n||n.length===0){if(!e.currentClip)return;n=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let r=e.gltf.nodes.length,i=[];for(let f=0;f<r;f++){let m=e.initialNodeTransforms[f];m?i.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let o=[0,0,0],a=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let f of n){let m=Math.max(0,Math.min(1,f.weight));if(!(m<=1e-4))for(let h of f.clip.channels){if(h.nodeIndex<0||h.nodeIndex>=r)continue;let p=i[h.nodeIndex];if(h.path==="translation")en(h,f.time,o),os(p.t,p.t,o,m);else if(h.path==="rotation")en(h,f.time,a),Ar(p.r,p.r,a,m);else if(h.path==="scale")en(h,f.time,u),os(p.s,p.s,u,m);else if(h.path==="weights"&&(en(h,f.time,s),e.meshes)){for(let d of e.meshes)if(d.nodeIndex===h.nodeIndex){for(let y of d.primitives)if(y.pluginData?.morph?.weights){let T=y.pluginData.morph.weights,S=y.pluginData.morph.numTargets||T.length;for(let b=0;b<S;b++)T[b]=T[b]*(1-m)+s[b]*m}}}}}let c=[];for(let f=0;f<r;f++){let m=Te(),{t:h,r:p,s:d}=i[f];Qe(m,p,h,d),c.push(m)}let l=ft(e.gltf,c);e.worldMatrices=l;for(let f of e.meshes)f.nodeIndex>=0&&f.nodeIndex<l.length&&(f.transform.set(l[f.nodeIndex]),De(f.normalMatrix,f.transform))}var bi={name:"keyframes",evaluateAnimation:hi,crossFadeTo:pi,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=di(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let n=Tr.get(e);if(n&&n.length>0){for(let r=n.length-1;r>=0;r--){let i=n[r];if(i.time+=t,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*t,i.weight<=0){n.splice(r,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(e.animationTime=n[n.length-1].time),hi(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),hi(e,e.animationTime))}};var Mn=64;function ss(e,t,n){if(!(!e?.meshes||t<0||t>=Mn))for(let r of e.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[t]=n)}}var yi={name:"morph",onResolveShader(e,t,n,r){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let i=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
284
327
|
uniform sampler2D uMorphDeltasTex;
|
|
285
|
-
uniform float uMorphWeights[${
|
|
328
|
+
uniform float uMorphWeights[${Mn}];
|
|
286
329
|
uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
287
|
-
for (int m = 0; m < ${
|
|
330
|
+
for (int m = 0; m < ${Mn}; m++) {
|
|
288
331
|
if (m >= uNumMorphTargets) break;
|
|
289
332
|
float w = uMorphWeights[m];
|
|
290
333
|
if (abs(w) > 0.0001) {
|
|
291
334
|
morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
|
|
292
335
|
}
|
|
293
336
|
}
|
|
294
|
-
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,
|
|
337
|
+
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(e,t,n,r,i){let o=n?.targets;if(!Array.isArray(o)||o.length===0)return null;let a=n.attributes?.POSITION,u=r?.accessors?.[a];if(!u)return null;let s=u.count,c=Math.min(o.length,Mn),l=new Float32Array(s*c*4);for(let h=0;h<c;h++){let p=o[h].POSITION;if(p===void 0)continue;let d=r.accessors?.[p],y=r.bufferViews?.[d?.bufferView];if(!d||!y)continue;let T=it(r,i,d,3);if(!T||T.length<s*3)continue;let S=h*s*4;for(let b=0;b<s;b++)l[S+b*4]=T[b*3],l[S+b*4+1]=T[b*3+1],l[S+b*4+2]=T[b*3+2],l[S+b*4+3]=0}let f=e.createTexture();e.bindTexture(3553,f),e.texImage2D(3553,0,34836,s,c,0,6408,5126,l),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(Mn);return{hasMorph:!0,morphTex:f,numTargets:c,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=n.pluginData?.morph;if(!a?.hasMorph||!a.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,a.morphTex);let u=e.getUniformLocation(t,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(t,"uNumMorphTargets");s&&e.uniform1i(s,a.numTargets);let c=e.getUniformLocation(t,"uMorphWeights[0]");c&&e.uniform1fv(c,a.weights)}};var gi=64,xi={name:"skinning",onResolveShader(e,t,n,r){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let i=n.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
|
|
295
338
|
layout(location=4) in uvec4 aJoints;
|
|
296
339
|
layout(location=5) in vec4 aWeights;
|
|
297
|
-
uniform mat4 uJointMatrix[${
|
|
340
|
+
uniform mat4 uJointMatrix[${gi}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
|
|
298
341
|
aWeights.x * uJointMatrix[int(aJoints.x)] +
|
|
299
342
|
aWeights.y * uJointMatrix[int(aJoints.y)] +
|
|
300
343
|
aWeights.z * uJointMatrix[int(aJoints.z)] +
|
|
301
344
|
aWeights.w * uJointMatrix[int(aJoints.w)];
|
|
302
|
-
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,
|
|
303
|
-
out vec2
|
|
304
|
-
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},Jr.set(e,o)}let a=kt(Qr,n)||Qr;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 c=e.getUniformLocation(o.program,"uInvVP");c&&e.uniformMatrix4fv(c,!1,a);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];
|
|
345
|
+
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(e,t,n,r,i){let o=n?.attributes;if(!o||o.JOINTS_0===void 0||o.WEIGHTS_0===void 0)return null;let a=r.accessors[o.JOINTS_0],u=r.accessors[o.WEIGHTS_0];if(!a||!u)return null;let s=r.bufferViews[a.bufferView],c=r.bufferViews[u.bufferView];if(!s||!c)return null;let l=(s.byteOffset||0)+(a.byteOffset||0),f=(c.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let h=a.componentType===5121?5121:5123,p=h===5121?new Uint8Array(i,l,a.count*4):new Uint16Array(i,l,a.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,h,0,0);let d=e.createBuffer();e.bindBuffer(34962,d);let y=it(r,i,u,4)??new Float32Array(i,f,u.count*4);return e.bufferData(34962,y,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,d]}},onBeforeDrawPrimitive(e,t,n,r,i,o){if(!n.pluginData?.skinning?.hasSkin)return;let a=o?.nodes?.[r.nodeIndex]?.skin;if(a===void 0||!o.skins||!o.skins[a])return;let s=o.skins[a].joints||[],c=new Float32Array(gi*16);for(let f=0;f<s.length&&f<gi;f++){let m=s[f],h=i[m]||Te();c.subarray(f*16,(f+1)*16).set(h)}let l=e.getUniformLocation(t,"uJointMatrix[0]");l&&e.uniformMatrix4fv(l,!1,c)}};Fe(yi);Fe(bi);Fe(xi);Fe(jr);Fe(Vr);var Xa=`#version 300 es
|
|
346
|
+
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.);}`,Wa=`#version 300 es
|
|
347
|
+
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);}`,Sn=new WeakMap,as=new Float32Array(20);function vi(e,t){let[n,r,i,o,a,u]=t;return[e[0]*n+e[4]*r+e[8]*i+e[12],e[1]*n+e[5]*r+e[9]*i+e[13],e[2]*n+e[6]*r+e[10]*i+e[14],Math.abs(e[0])*o+Math.abs(e[4])*a+Math.abs(e[8])*u,Math.abs(e[1])*o+Math.abs(e[5])*a+Math.abs(e[9])*u,Math.abs(e[2])*o+Math.abs(e[6])*a+Math.abs(e[10])*u]}function $a(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,a=-1e9;for(let u of e.primitives||[]){let s=u.positions;if(s)for(let c=0;c<s.length;c+=3)s[c]<t&&(t=s[c]),s[c+1]<n&&(n=s[c+1]),s[c+2]<r&&(r=s[c+2]),s[c]>i&&(i=s[c]),s[c+1]>o&&(o=s[c+1]),s[c+2]>a&&(a=s[c+2])}return e._lb=t<=i?[(t+i)*.5,(n+o)*.5,(r+a)*.5,(i-t)*.5,(o-n)*.5,(a-r)*.5]:null}function qa(e){let t=Sn.get(e);if(t)return t;let n=(u,s)=>{let c=e.createShader(u);return e.shaderSource(c,s),e.compileShader(c),c},r=e.createProgram();e.attachShader(r,n(35633,Xa)),e.attachShader(r,n(35632,Wa)),e.linkProgram(r);let i=e.createVertexArray(),o=e.createBuffer(),a=e.createBuffer();return e.bindVertexArray(i),e.bindBuffer(34962,o),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,a),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:r,vao:i,vbo:o,ibo:a,uMVP:e.getUniformLocation(r,"uMVP"),uIntensity:e.getUniformLocation(r,"uShadowIntensity"),uSoftness:e.getUniformLocation(r,"uShadowSoftness")},Sn.set(e,t),t}var En={name:"contact-shadow",onContextRestored(e){Sn.delete(e)},onAfterRender(e,t,n){let r=t.shadowIntensity;if(r<=0||!t.bounds)return;let i=qa(e),o=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,a=[],u=[];for(let d of t.meshes||[]){if(!d||d.visible===!1||d.isPluginMesh||d.name==="__xr_reticle__"||d.name?.startsWith("__xr_slot_"))continue;let y=$a(d);if(!y)continue;d.transform&&(y=vi(d.transform,y)),t.modelRootMatrix&&(y=vi(t.modelRootMatrix,y));let[T,S,b,A,w,P]=y,N=[T,b,A,P,S-w,S+w];/floor|table|pedestal|ground|base|plane/i.test(d.name||"")||w<.14&&Math.min(A,P)>.45?u.push(N):a.push(N)}let s=[],c=t.bounds.center||[0,0,0],l=Math.max(.05,Number(t.bounds.radius)||.5),f=t.bounds.min,m=f?[c[0],c[1],c[2],l,Math.max(.01,c[1]-f[1]),l]:[c[0],c[1],c[2],l,l,l];t.modelRootMatrix&&(m=vi(t.modelRootMatrix,m));let p=t.xrSessionActive&&u.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:m[1]-m[4]+.002;for(let[d,y,T,S,b]of a){let A=-1/0;for(let[P,N,I,_,,v]of u)b>=v-.08&&Math.abs(d-P)<=I&&Math.abs(y-N)<=_&&v+.002>A&&(A=v+.002);o&&(A=Math.max(A,d>=.04&&d<=.36&&y>=-.34&&y<=-.04&&b>=.01?.036:Math.hypot(d,y)<=.66&&b>=-.06?.003:-.477)),isFinite(A)||(A=p);let w=s.find(P=>Math.hypot(d-P[0],y-P[1])<.06&&Math.abs(A-P[5])<.05);w?(w[2]=Math.max(w[2],T*.78),w[3]=Math.max(w[3],S*.78),w[4]=Math.min(w[4],b)):s.push([d,y,T,S,b,A])}if(s.length===0){let d=Math.max(.1,m[3]*1.5)/1.45;s.push([m[0],m[2],d,d,p,p])}e.useProgram(i.prog),e.uniformMatrix4fv(i.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(i.vao),e.bindBuffer(34962,i.vbo);for(let[d,y,T,S,b,A]of s){let w=Math.max(0,b-A),P=r/(1+w*2);if(P<.02)continue;let N=1+Math.min(.75,w*.85),I=Math.max(.045,T*1.45*N),_=Math.max(.045,S*1.45*N);as.set([d-I,A,y-_,0,0,d+I,A,y-_,1,0,d+I,A,y+_,1,1,d-I,A,y+_,0,1]),e.bufferSubData(34962,0,as),e.uniform1f(i.uIntensity,P),e.uniform1f(i.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,w*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Sn.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Sn.delete(e))}};function wi(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function Mi(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function Si(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function ls(){return(await Mr()).bestMode}async function Mr(){let[e,t,n]=await Promise.all([Si(),Promise.resolve(wi()),Promise.resolve(Mi())]),r=[];t&&r.push("quick-look"),e&&r.push("webxr"),n&&r.push("scene-viewer");let i=null;return t?i="quick-look":e?i="webxr":n&&(i="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:n,availableModes:r,bestMode:i}}function cs(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,r=!1;if(typeof e=="string"){if(n=Ya(e),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(e),r=!0;let i=[];if(t.allowScale===!1&&i.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let u=wr(t.canonicalWebPageUrl,!1);u&&i.push(`canonicalWebPageURL=${encodeURIComponent(u)}`)}t.checkoutTitle&&i.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&i.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&i.push(`price=${encodeURIComponent(t.price)}`),i.length>0&&(n+=`#${i.join("&")}`);let o=document.createElement("a");o.setAttribute("rel","ar"),o.setAttribute("href",n);let a=document.createElement("img");a.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),a.style.display="none",o.appendChild(a),document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),r&&URL.revokeObjectURL(n.split("#")[0])},3e3)}function wr(e,t=!1){if(typeof e!="string")return"";let n=e.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://")||t&&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 Ya(e){try{return wr(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function ja(e,t={}){let n=wr(e,!0),r=t.mode||"ar_preferred",i=new URLSearchParams({file:n,mode:r,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&i.set("title",t.title),t.link&&i.set("link",wr(t.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 Ka(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=ja(e,t);window.location.href=n}var kt=null;function Za(e,t){let r=new Float32Array(144),i=new Float32Array(24*6),o=new Float32Array(24*4),a=new Uint16Array(24*6);for(let f=0;f<24;f++){let m=f/24*Math.PI*2,h=Math.cos(m),p=Math.sin(m),d=f*2,y=d+1,T=(f+1)%24*2;r[d*3]=h*.11,r[d*3+1]=.002,r[d*3+2]=p*.11,r[y*3]=h*.145,r[y*3+1]=.002,r[y*3+2]=p*.145,i[d*3+1]=i[y*3+1]=1,a.set([d,T,y,y,T,T+1],f*6)}let u=e.createVertexArray();e.bindVertexArray(u);let s=(f,m,h)=>{let p=e.createBuffer();return e.bindBuffer(34962,p),e.bufferData(34962,f,35044),e.enableVertexAttribArray(m),e.vertexAttribPointer(m,h,5126,!1,0,0),p},c=[s(r,0,3),s(i,1,3),s(o,2,2)],l=e.createBuffer();return c.push(l),e.bindBuffer(34963,l),e.bufferData(34963,a,35044),e.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:u,indexCount:a.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:a,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:c}]}}function us(e,t,n,r,i){let o=Math.cos(r),a=Math.sin(r),u=Math.max(.01,i);e.fill(0),e[0]=u*o,e[2]=-u*a,e[5]=u,e[8]=u*a,e[10]=u*o,e[12]=t[0]-u*(o*n[0]+a*n[2]),e[13]=t[1]-u*n[1],e[14]=t[2]-u*(-a*n[0]+o*n[2]),e[15]=1}var Ai=class{constructor(t={}){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=t}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(t,n){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");kt&&kt!==this&&kt.isSessionActive()&&await kt.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||t?.container,a=String(o?.tagName||"").toLowerCase()==="xr-live",u=t?.bounds,s=Number(u?.radius)||1,c=Array.isArray(u?.center)?u.center:[0,0,0],l=Array.isArray(u?.min)?u.min:[-.5,-.5,-.5],f=typeof navigator<"u"&&navigator.userAgent||"",m=/Android|iPhone|iPad|iPod/i.test(f)&&!/Quest|Oculus|Pico|Vision/i.test(f),h=a?i.arScale==="fixed"?1:m?.55:1:i.arScale==="fixed"?1:s>.45?.3/s:s<.05?.12/Math.max(s,.001):1,p=a?[0,-.25,0]:[c[0]||0,i.arPlacement==="wall"?c[1]:l[1]??0,c[2]||0],d="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(d="immersive-vr")}catch{d="immersive-vr"}let y=o?.querySelector?.('[slot="ar-overlay"]')||null,T=!1,S=null,b=()=>{T&&y?.parentNode&&y.parentNode.removeChild(y),y=null,S=null,T=!1};if(d==="immersive-ar"){if(y)y.addEventListener?.("beforexrselect",E=>E.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let E=document.createElement("div");E.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 V=document.createElement("button");V.type="button",V.textContent="\u2715 Exit AR",V.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",V.addEventListener("beforexrselect",O=>O.preventDefault()),V.addEventListener("click",O=>{O.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",E.appendChild(V),E.appendChild(S),document.body.appendChild(E),y=E,T=!0}}let A=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),w={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(A)};y&&(A.add("dom-overlay"),w.optionalFeatures=Array.from(A),w.domOverlay={root:y});for(let E of Ne)E.onConfigureXRSessionInit?.(o,w);Array.isArray(w.optionalFeatures)&&w.optionalFeatures.includes("dom-overlay")&&!w.domOverlay?.root&&(w.optionalFeatures=w.optionalFeatures.filter(E=>E!=="dom-overlay"));let P=E=>{let V=String(E?.name||"");return V==="NotAllowedError"||V==="SecurityError"};try{this.s=await r.requestSession(d,w)}catch(E){if(b(),P(E))throw i.onError?.(E),E;try{this.s=await r.requestSession(d,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(V){if(P(V))throw i.onError?.(V),V;try{this.s=await r.requestSession(d)}catch(O){throw i.onError?.(O),O}}}let N=this.s;kt=this,this.placed=!1;let I=null,_=null,v=null,g=null,M=null,k=[0,-.25,-1.2],R=[0,-.25,-1.2],B=new Float32Array(16),Z=new Float32Array(16),j=!1,ie=1,ee=0,ne=!1,X=null,ae=null,se=0,F=null,H=()=>{kt===this&&(kt=null),F?.(),F=null;try{_?.cancel?.()}catch{}if(_=null,v){let E=t?.meshes;if(Array.isArray(E)){let O=E.indexOf(v);O!==-1&&E.splice(O,1)}let V=t.getGLContext?.()||t?.gl;if(V)for(let O of v.primitives||[]){V.deleteVertexArray?.(O.vao);for(let U of O.buffers||[])V.deleteBuffer?.(U)}v=null}t?.setXRSessionActive?.(!1),b(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=H,N.addEventListener("end",()=>{H(),i.onExit?.()}),N.addEventListener("select",()=>{if(!this.placed){let E=M||k;R=[E[0],E[1],E[2]],us(this.placedMat,R,p,ee,h*ie),this.placed=!0,v&&(v.visible=!1),S&&(S.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let E=t.getGLContext?.()||t?.gl;E&&typeof E.makeXRCompatible=="function"&&await E.makeXRCompatible();let V=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;E&&typeof V=="function"&&typeof N.updateRenderState=="function"&&N.updateRenderState({baseLayer:new V(N,E,{alpha:!0})});try{I=await N.requestReferenceSpace("local")}catch{try{I=await N.requestReferenceSpace("local-floor")}catch{I=await N.requestReferenceSpace("viewer")}}let O=await N.requestReferenceSpace("viewer").catch(()=>I);if(typeof N.requestHitTestSource=="function"&&O&&(_=await N.requestHitTestSource({space:O}).catch(()=>null)),d==="immersive-ar"&&E&&typeof E.createVertexArray=="function"&&Array.isArray(t.meshes)&&(v=Za(E,i.reticleColor),t.meshes.push(v)),typeof window<"u"&&typeof window.addEventListener=="function"){let G=x=>Math.hypot(x.touches[1].clientX-x.touches[0].clientX,x.touches[1].clientY-x.touches[0].clientY),K=x=>Math.atan2(x.touches[1].clientY-x.touches[0].clientY,x.touches[1].clientX-x.touches[0].clientX),ue=x=>{this.s&&(x.touches.length===1&&this.placed?ne=!0:x.touches.length>=2&&(ne=!1,X=G(x),ae=K(x)))},re=x=>{if(!this.s||x.touches.length<2)return;let C=G(x),L=K(x);if(X&&X>4&&i.arScale!=="fixed"&&(ie=Math.max(.15,Math.min(6,ie*(C/X)))),ae!==null){let z=L-ae;z>Math.PI&&(z-=Math.PI*2),z<-Math.PI&&(z+=Math.PI*2),ee-=z}X=C,ae=L},D=x=>{(!x.touches||x.touches.length===0)&&(ne=!1),(!x.touches||x.touches.length<2)&&(X=null,ae=null)};window.addEventListener("touchstart",ue,{passive:!0}),window.addEventListener("touchmove",re,{passive:!0}),window.addEventListener("touchend",D,{passive:!0}),window.addEventListener("touchcancel",D,{passive:!0}),F=()=>{window.removeEventListener("touchstart",ue),window.removeEventListener("touchmove",re),window.removeEventListener("touchend",D),window.removeEventListener("touchcancel",D)}}t.setXRSessionActive?.(!0);let U=(G,K)=>{if(this.s!==N)return;N.requestAnimationFrame(U);let ue=se>0?Math.min(Math.max((G-se)/1e3,0),.1):1/60;se=G,t?.stepXRUpdate?.(ue);let re=K.getViewerPose(I);if(!re)return;let D=re.views?.[0];if(!j&&D?.transform){let $=D.transform.position,Y=D.transform.matrix,Q=$?.x??(Y?Y[12]:0),q=$?.y??(Y?Y[13]:0),J=$?.z??(Y?Y[14]:0),oe=Y?-Y[8]:0,te=Y?-Y[10]:-1,me=Math.hypot(oe,te);me>1e-4?(oe/=me,te/=me):(oe=0,te=-1),k=[Q+oe*1.2,q-.25,J+te*1.2],ee=Math.atan2(-oe,-te),j=!0}if(_&&typeof K.getHitTestResults=="function"&&(!this.placed||ne)){let $=K.getHitTestResults(_)||[],Y=!1;for(let Q of $){let q=Q.getPose(I);if(q?.transform?.matrix){let J=q.transform.matrix,oe=J[5];if(i.arPlacement==="wall"&&Math.abs(oe)>.35||i.arPlacement==="floor"&&Math.abs(oe)<.65)continue;g||(g=new Float32Array(16)),g.set(J),M=[J[12],J[13],J[14]],this.placed&&ne&&(R=[J[12],J[13],J[14]]),v&&(v.visible=!this.placed||ne,v.transform.set(J)),!this.placed&&S&&(S.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(g),Y=!0;break}}!Y&&v&&(v.visible=!1)}us(B,this.placed?R:M||k,p,ee,h*ie),this.placed&&this.placedMat.set(B);let x=t.xrRigMatrix;x instanceof Float32Array&&x.length===16?Re(Z,x,B):Z.set(B),t.modelRootMatrix&&t.modelRootMatrix.set(Z);for(let $ of Ne)$.onXRFrame?.(t,N,K,I);let C=t.getGLContext?.()||t?.gl,L=N.renderState?.baseLayer;C&&L&&L.framebuffer!==void 0&&C.bindFramebuffer(36160,L.framebuffer);let z=d==="immersive-ar",W=re.views||[];for(let $=0;$<W.length;$++){let Y=W[$];if(typeof t.renderXRView=="function"){let Q;if(L&&typeof L.getViewport=="function"){let q=L.getViewport(Y);q&&q.width>0&&q.height>0&&(Q=[q.x,q.y,q.width,q.height])}else L?.framebufferWidth>0&&L?.framebufferHeight>0&&(Q=[0,0,L.framebufferWidth,L.framebufferHeight]);t.renderXRView(Y,Z,this.placed,Q,z,$)}}C&&L&&L.framebuffer&&C.bindFramebuffer(36160,null)};N.requestAnimationFrame(U)}catch(E){throw typeof N.end=="function"&&await N.end().catch(()=>{}),H(),i.onError?.(E),E}}async stop(){let t=this.s;if(t)try{await t.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function Sr(e){let t=await Mr(),n=e.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let u of n)if(t.availableModes.includes(u)){r=u;break}if(r||(r=t.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let i={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},o={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},a={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(r==="quick-look"){let u;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")u=e.model;else{if(typeof e.model=="string")return cs(e.model,i),{mode:"quick-look",success:!0};u=jt(e.model)}return cs(u,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let u=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!u)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Ka(u,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let u=new Ai(a);return await u.start(e.view,e.element),{mode:"webxr",success:!0,session:u}}}catch(u){return{mode:r,success:!1,error:u}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}at.registerAR({activateAR:Sr,createUSDZBlob:jt});at.registerScriptRunner(Qt);Fe(En);var Ri=new WeakMap;function Er(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Ri.set(e,n)}function hs(e){return Ri.get(e)}async function Qa(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let o=await(await fetch(t)).blob();n=await createImageBitmap(o)}else if(typeof Image<"u")n=await new Promise((i,o)=>{let a=new Image;a.crossOrigin="anonymous",a.onload=()=>i(a),a.onerror=o,a.src=t});else return null;else n=t;let r=e.createTexture();return e.bindTexture(3553,r),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),r}var Ei=new WeakMap,ms=new Float32Array(16);async function fs(e,t,n){let r=n?await Qa(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=r}var _i={name:"environment-map",onContextRestored(e){Ei.delete(e)},setEnvironmentImage(e,t){return fs(e,"environmentTexture",t)},setSkyboxImage(e,t){return fs(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,r,i){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let o=Ei.get(t);if(!o){let f=(p,d)=>{let y=t.createShader(p);return t.shaderSource(y,d),t.compileShader(y),y},m=t.createProgram();t.attachShader(m,f(35633,`#version 300 es
|
|
348
|
+
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.);}`)),t.attachShader(m,f(35632,`#version 300 es
|
|
349
|
+
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.);}`)),t.linkProgram(m);let h=typeof t.createVertexArray=="function"?t.createVertexArray():null;o={program:m,vao:h},Ei.set(t,o)}let a=Xt(ms,n)||ms;t.depthMask(!1),t.useProgram(o.program),o.vao&&t.bindVertexArray(o.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let u=t.getUniformLocation(o.program,"uSkyboxMap");u&&t.uniform1i(u,0);let s=t.getUniformLocation(o.program,"uInvVP");s&&t.uniformMatrix4fv(s,!1,a);let c=t.getUniformLocation(o.program,"uCameraPos");c&&t.uniform3f(c,r[0],r[1],r[2]);let l=t.getUniformLocation(o.program,"uExposure");l&&t.uniform1f(l,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,r){if(r.includes("evalSHIrradiance"))return null;let i=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
305
350
|
uniform int uHasSH;
|
|
306
351
|
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);}
|
|
307
352
|
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));}
|
|
@@ -314,14 +359,90 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
|
|
|
314
359
|
}else if(uHasSH==1){
|
|
315
360
|
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
316
361
|
envDiffuse=evalSHIrradiance(N);
|
|
317
|
-
}`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=jn.get(t),l=t.getUniformLocation(e,"uHasSH");if(a&&a.length>=27){l&&t.uniform1i(l,1);let c=t.getUniformLocation(e,"uSH");c&&t.uniform3fv(c,a)}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 Zn=new WeakMap;function Jn(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],a=o.getAttribute("data-position");if(!a)continue;let l=a.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let c=o.getAttribute("data-normal"),s;if(c){let m=c.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 Qn={name:"hotspots",updateHotspotsForElement:Jn,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{Jn(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Zn.set(t,e)},onCameraChange(t,e){e&&Jn(e,t)},onElementDisconnected(t){let e=Zn.get(t);e&&(e.disconnect(),Zn.delete(t))}};var ni=1024,er=256,xn=2048,Ji=128,Qi=64,eo=16,to=1e4,no=8,Ne=new Set(["__proto__","constructor","prototype"]),ri={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))},ii={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},vn={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},wn=(t,e)=>t!==null&&typeof t=="object"&&!Ne.has(e)&&Object.prototype.hasOwnProperty.call(t,e),Se=t=>Array.isArray(t)?[...t]:t,ci=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&wn(t,"value")?t.value:t,oe=(t,e)=>wn(t.configuration,e)?ci(t.configuration[e]):void 0,W=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Ge=t=>Math.max(0,Math.min(1,t)),Me=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||Ne.has(r)||Ne.has(n))return null;e.push(r)}return{segments:e}}var rt=(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},oi=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]},si=(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 yn(i,oi(t),oi(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},tr=(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)),ro=(t,e)=>Array.isArray(t)?t.map(n=>e(W(n))):e(W(t)),ai=(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>ni)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ni})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>er)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${er})`);let a=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],c=new Map,s=new Map,u=new Map,m=new Map,h=new Map,f=new Map,d=[],p=[],x=new Map,P=1,E=0,y=0,v=0,g=0,I=!1,b=!1,w=!1;o.forEach((T,A)=>{if(!T||typeof T!="object")return;let S=Se(ci(T.value));c.set(A,S);let k=T.id??T.name;typeof k=="string"&&k&&!Ne.has(k)&&c.set(k,S)}),(n?.nodes||[]).forEach((T,A)=>{for(let S of T?.children||[])typeof S=="number"&&x.set(S,A)});let R=T=>T.op||typeof T.declaration=="number"&&a[T.declaration]?.op||"",_=(T,A,S)=>{if(Ne.has(A))return;let k=s.get(T);k||s.set(T,k=Object.create(null)),k[A]=S},B=(T,A)=>{if(typeof T!="number"&&typeof T!="string"||typeof T=="string"&&Ne.has(T)||!c.has(T)&&c.size>=er*2)return;let S=Se(A);if(c.set(T,S),typeof T=="number"){let k=o[T]?.id??o[T]?.name;typeof k=="string"&&!Ne.has(k)&&c.set(k,S)}},z=T=>typeof T=="number"?l[T]?.id??String(T):typeof T=="string"?/^\d+$/.test(T)&&l[Number(T)]?.id?l[Number(T)].id:T:"",D=(T,A)=>{for(let S=T,k=0;S!==void 0&&S>=0&&k<128;S=x.get(S),k++)if(S===A)return!0;return!1},C=T=>{for(let A=d.length-1;A>=0;A--)d[A].key===T&&d.splice(A,1)},G=T=>{C(T.key),d.length>=Ji&&d.shift(),d.push(T)},V=T=>{let A=Rt(T)?.segments;if(A){if(A[0]==="nodes"&&Array.isArray(n?.nodes)){let S=n.nodes[rt(A[1],n.nodes.length)];if(!S)return;let k=A[2];if(k in vn){let M=vn[k],L=S[k]||M;return M.map((F,U)=>W(L[U],F))}if(k==="weights"){let M=Array.isArray(S.weights)?S.weights:[0],L=A.length===4?rt(A[3],64):-2;return L===-2?M.map(F=>W(F)):L>=0?W(M[L]):void 0}if(k==="visible"||k==="extensions"&&A[3]==="KHR_node_visibility"&&A[4]==="visible")return S.extensions?.KHR_node_visibility?.visible??S.visible??!0}else if(A[0]==="materials"&&Array.isArray(n?.materials)){let S=n.materials[rt(A[1],n.materials.length)];if(!S)return;let k=S.pbrMetallicRoughness||{};if(A[2]==="pbrMetallicRoughness"){if(A[3]==="baseColorFactor"){let M=k.baseColorFactor||[1,1,1,1];return[W(M[0],1),W(M[1],1),W(M[2],1),W(M[3],1)]}if(A[3]==="metallicFactor"||A[3]==="roughnessFactor")return W(k[A[3]],1)}if(A[2]==="emissiveFactor"){let M=S.emissiveFactor||[0,0,0];return[W(M[0]),W(M[1]),W(M[2])]}if(A[2]==="alphaCutoff")return W(S.alphaCutoff,.5)}}},J=(T,A)=>{let S=Rt(T)?.segments;if(!S)return!1;if(S[0]==="nodes"&&Array.isArray(n?.nodes)){let k=rt(S[1],n.nodes.length),M=n.nodes[k];if(!M)return!1;let L=S[2];if(L in vn&&Array.isArray(A)){let F=vn[L];if(A.length<F.length)return!1;let U=F.map((Z,Q)=>W(A[Q],Z));if(L==="rotation"){let Z=Math.hypot(...U);U=Z>1e-8?U.map(Q=>Q/Z):[0,0,0,1]}M[L]=U,delete M.matrix;let K=e?.initialNodeTransforms?.[k];return K&&(K[L[0]]=[...U]),I=!0,!0}if(L==="weights"){Array.isArray(M.weights)||(M.weights=[]);let F=(U,K)=>{for(let Z of e?.meshes||[])if(Z.nodeIndex===k)for(let Q of Z.primitives||[])Q.pluginData?.morph?.weights&&(Q.pluginData.morph.weights[U]=K)};if(S.length===4){let U=rt(S[3],64);if(U<0)return!1;F(U,M.weights[U]=W(A))}else if(Array.isArray(A))M.weights=A.slice(0,64).map(U=>W(U)),M.weights.forEach((U,K)=>F(K,U));else return!1;return w=!0,!0}if(L==="visible"||L==="extensions"&&S[3]==="KHR_node_visibility"&&S[4]==="visible"){let F=Me(A);return M.visible=F,(!M.extensions||typeof M.extensions!="object")&&(M.extensions={}),M.extensions.KHR_node_visibility={visible:F},b=!0,!0}}else if(S[0]==="materials"&&Array.isArray(n?.materials)){let k=rt(S[1],n.materials.length),M=n.materials[k];if(!M)return!1;let L=M.pbrMetallicRoughness||(M.pbrMetallicRoughness={}),F=U=>{for(let K of e?.meshes||[])for(let Z of K.primitives||[])(Z.materialIndex??0)===k&&U(Z)};if(S[2]==="pbrMetallicRoughness"){if(S[3]==="baseColorFactor"&&Array.isArray(A)&&A.length>=3){let U=[Ge(W(A[0],1)),Ge(W(A[1],1)),Ge(W(A[2],1)),A[3]!==void 0?Ge(W(A[3],1)):L.baseColorFactor?.[3]??1];return L.baseColorFactor=U,F(K=>K.baseColor=[...U]),w=!0}if(S[3]==="metallicFactor"||S[3]==="roughnessFactor"){let U=S[3]==="metallicFactor",K=Ge(W(A,U?0:.5));return L[S[3]]=K,F(Z=>Z[U?"metallic":"roughness"]=K),w=!0}}if(S[2]==="emissiveFactor"&&Array.isArray(A)&&A.length>=3)return M.emissiveFactor=[0,1,2].map(U=>Math.max(0,W(A[U]))),w=!0;if(S[2]==="alphaCutoff")return M.alphaCutoff=Ge(W(A,.5)),w=!0}return!1},j=(T,A,S=new Set)=>{let k=oe(A,"pointer");if(typeof k!="string"||!k.startsWith("/"))return null;let M=k.replace(/\{([a-zA-Z0-9_]+)\}/g,(L,F)=>{let U=Math.trunc(Number(H(T,F,void 0,S)??oe(A,F)));return Number.isSafeInteger(U)&&U>=0?String(U):"-1"});return Rt(M)?M:null},H=(T,A,S,k)=>{let M=i[T]?.values;if(!wn(M,A))return S;let L=M[A];if(L==null)return S;if(typeof L!="object"||Array.isArray(L))return Se(L);let F=L;return typeof F.node=="number"?X(F.node,F.socket||"value",k):wn(F,"value")?Se(F.value):S},X=(T,A,S)=>{if(T<0||T>=i.length||S.has(T)||S.size>128||++v>to)return;let k=i[T],M=R(k);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(M))return Se(s.get(T)?.[A]);S.add(T);try{let L=(F,U=0)=>H(T,F,U,S);if(M==="variable/get"){let F=oe(k,"variable")??oe(k,"id");return typeof F=="number"||typeof F=="string"?Se(c.get(F)):void 0}if(M==="pointer/get"){let F=j(T,k,S);return F?V(F):void 0}if(M.startsWith("math/")){let F=M.slice(5);if(F in ri)return ro(L("a"),ri[F]);if(F in ii){let U=/^(mul|div|rem|mod|pow)$/.test(F)?1:0;return tr(L("a",F==="mul"?1:0),L("b",U),ii[F])}if(F==="pi")return Math.PI;if(F==="e")return Math.E;if(F==="random")return Math.random();if(F==="clamp")return tr(tr(L("a"),L("b",L("min",0)),Math.max),L("c",L("max",1)),Math.min);if(F==="mix"||F==="quatSlerp")return si(L("a",0),L("b",1),W(L("c",L("t",.5)),.5),F==="quatSlerp");if(F==="dot"){let U=L("a"),K=L("b");return Array.isArray(U)&&Array.isArray(K)?U.reduce((Z,Q,O)=>Z+(Q||0)*(K[O]||0),0):W(U)*W(K)}if(F==="cross"){let U=L("a",[0,0,0]),K=L("b",[0,0,0]);return Array.isArray(U)&&Array.isArray(K)?[(U[1]||0)*(K[2]||0)-(U[2]||0)*(K[1]||0),(U[2]||0)*(K[0]||0)-(U[0]||0)*(K[2]||0),(U[0]||0)*(K[1]||0)-(U[1]||0)*(K[0]||0)]:[0,0,0]}if(F==="length"){let U=L("a");return Array.isArray(U)?Math.hypot(...U):Math.abs(W(U))}if(F==="distance"){let U=L("a"),K=L("b");return Array.isArray(U)&&Array.isArray(K)?Math.hypot(...U.map((Z,Q)=>(Z||0)-(K[Q]||0))):Math.abs(W(U)-W(K))}if(F==="normalize"){let U=L("a");if(!Array.isArray(U))return W(U)>=0?1:-1;let K=Math.hypot(...U);return K>1e-8?U.map(Z=>Z/K):U.map(()=>0)}if(F.startsWith("combine"))return["a","b","c","d"].slice(0,Number(F[7])||2).map(U=>W(L(U)));if(F.startsWith("extract")){let U=L("a");return Array.isArray(U)?U[A==="0"||A==="x"?0:A==="1"||A==="y"?1:A==="2"||A==="z"?2:3]??0:0}if(F==="eq")return ai(L("a"),L("b"));if(F==="ne")return!ai(L("a"),L("b"));if(F==="lt")return W(L("a"))<W(L("b"));if(F==="le")return W(L("a"))<=W(L("b"));if(F==="gt")return W(L("a"))>W(L("b"));if(F==="ge")return W(L("a"))>=W(L("b"));if(F==="isNaN")return Number.isNaN(Number(L("a")));if(F==="isInf"){let U=Number(L("a"));return!Number.isFinite(U)&&!Number.isNaN(U)}return F==="and"?Me(L("a",!1))&&Me(L("b",!1)):F==="or"?Me(L("a",!1))||Me(L("b",!1)):F==="xor"?Me(L("a",!1))!==Me(L("b",!1)):F==="not"?!Me(L("a",!1)):F==="select"?Se(Me(L("condition",!1))?L("a"):L("b")):void 0}return M==="type/boolToInt"||M==="type/boolToFloat"?Me(L("a",!1))?1:0:M==="type/intToBool"||M==="type/floatToBool"?W(L("a",0))!==0:M==="type/intToFloat"?W(L("a",0)):M==="type/floatToInt"?Math.trunc(W(L("a",0))):void 0}finally{S.delete(T)}},N=()=>{if(I){I=!1,w=!0;let T=Fe(n);if(e){e.worldMatrices=T;for(let A of e.meshes||[])A.nodeIndex>=0&&A.nodeIndex<T.length&&(A.transform.set(T[A.nodeIndex]),de(A.normalMatrix,A.transform))}}if(b){b=!1,w=!0;let T=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(T))for(let A of e.meshes){let S=!0;for(let k=A.nodeIndex,M=0;k!==void 0&&k>=0&&M<128;k=x.get(k),M++){let L=T[k];if(L?.visible===!1||L?.extensions?.KHR_node_visibility?.visible===!1){S=!1;break}}A.visible=S}}w&&(w=!1,e?.render?.())},$=(T,A={steps:0})=>{if(!T||typeof T.node!="number")return;A.steps===0&&(v=0);let S=[T],k=M=>{S.length+A.steps<xn&&S.push(M)};for(;S.length>0&&A.steps<xn;){A.steps++;let M=S.shift();if(!M||M.node<0||M.node>=i.length)continue;let L=M.node,F=i[L];if(!F)continue;let U=M.socket||"in",K=R(F),Z=(O,q=void 0)=>H(L,O,q,new Set),Q=(O="out")=>{let q=F.flows?.[O];q&&k(q)};switch(K){case"flow/branch":Q(Me(Z("condition",!1))?"true":"false");break;case"flow/sequence":for(let O of Object.keys(F.flows||{}).sort((q,ee)=>Number(q)-Number(ee)||q.localeCompare(ee)))Q(O);break;case"flow/switch":{let O=F.flows?.[String(Z("selection",Z("value",0)))]??F.flows?.default;O&&k(O);break}case"flow/for":{let O=Math.trunc(W(Z("startIndex",0))),q=Math.trunc(W(Z("endIndex",0))),ee=Math.max(1,Math.trunc(W(Z("step",1),1))),ae=F.flows?.body;if(ae&&q>O&&g<no){let pe=Math.min(Math.ceil((q-O)/ee),xn);g++;try{for(let ce=0;ce<pe&&A.steps<xn;ce++)_(L,"index",O+ce*ee),$(ae,A)}finally{g--}}let Ve=F.flows?.completed??F.flows?.out;Ve&&k(Ve);break}case"flow/doN":{let O=U==="reset"?0:(u.get(L)||0)+1;if(u.set(L,O),_(L,"currentCount",O),_(L,"count",O),U!=="reset"){let q=Math.trunc(W(Z("n",oe(F,"stopIterations")??oe(F,"n")??1),1));O<=q&&Q()}break}case"flow/multiGate":{if(U==="reset"){f.set(L,0);break}let O=Object.keys(F.flows||{}).sort();if(!O.length)break;let q=oe(F,"isRandom")?Math.floor(Math.random()*O.length):f.get(L)||0;q<O.length&&(Q(O[q]),f.set(L,oe(F,"isLoop")!==!1?(q+1)%O.length:q+1));break}case"flow/waitAll":{if(U==="reset"){m.delete(L);break}let O=m.get(L);O||m.set(L,O=new Set),O.add(U),O.size>=Math.max(1,Math.trunc(Number(oe(F,"inputFlows")??2)||2))&&(O.clear(),Q("out"),Q("completed"));break}case"flow/throttle":{if(U==="reset"){h.delete(L);break}let O=Math.max(0,W(Z("duration",0))),q=h.get(L);q===void 0||E-q>=O?(h.set(L,E),_(L,"lastRemainingTime",0),Q()):_(L,"lastRemainingTime",Math.max(0,O-(E-q)));break}case"flow/delay":case"flow/setDelay":{if(U==="cancel"){for(let ae=p.length-1;ae>=0;ae--)p[ae].nodeIdx===L&&p.splice(ae,1);_(L,"lastDelayIndex",-1);break}let O=Math.max(0,W(Z("duration",oe(F,"duration")??0))),q=F.flows?.done??F.flows?.out;if(O<=0){_(L,"lastDelayIndex",-1),q&&k(q);break}p.length>=Qi&&p.shift();let ee=P++;_(L,"lastDelayIndex",ee),p.push({id:ee,nodeIdx:L,rem:O,done:q}),K==="flow/setDelay"&&F.flows?.out&&F.flows?.done&&Q("out");break}case"flow/cancelDelay":{let O=Math.trunc(W(Z("delayIndex",-1),-1));if(O<0)p.length=0;else for(let q=p.length-1;q>=0;q--)p[q].id===O&&p.splice(q,1);Q();break}case"variable/set":B(oe(F,"variable")??oe(F,"id"),Z("value")),Q();break;case"variable/interpolate":{let O=oe(F,"variable")??oe(F,"id"),q=Z("value",Z("target")),ee=Math.max(0,W(Z("duration",oe(F,"duration")??.3),.3));O!==void 0&&q!==void 0&&G({key:`var:${String(O)}`,varKey:O,from:Se(Z("from")??c.get(O)??0),to:Se(q),dur:ee,elapsed:0,quat:!1,linear:oe(F,"easing")==="linear",done:F.flows?.done}),Q();break}case"pointer/set":{let O=j(L,F),q=Z("value");O&&q!==void 0&&(C(`ptr:${O}`),J(O,q)),Q();break}case"pointer/interpolate":{let O=j(L,F),q=Z("value",Z("target")),ee=Math.max(0,W(Z("duration",oe(F,"duration")??.3),.3));if(O&&q!==void 0){let ae=Z("from")??V(O);ae!==void 0&&(ee<=0?(J(O,q),Q("done")):G({key:`ptr:${O}`,ptr:O,from:Se(ae),to:Se(q),dur:ee,elapsed:0,quat:O.endsWith("/rotation"),linear:oe(F,"easing")==="linear",done:F.flows?.done}))}Q();break}case"animation/start":{let O=Z("animation")??oe(F,"animation")??oe(F,"clipName"),q=typeof O=="number"?e?.animations?.[O]?.name??n?.animations?.[O]?.name:typeof O=="string"?O:void 0;e?.playAnimation?.(q),w=!0,Q();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),K==="animation/resetAt"&&e?.evaluateAnimation?.(W(Z("time",0))),w=!0,Q();break;case"event/send":case"customEvent/send":{let O=z(oe(F,"event")??oe(F,"id")),q={};for(let ee of Object.keys(F.values||{}))Ne.has(ee)||(q[ee]=Z(ee));O&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:O,values:q}})),Y(O,q,A)),Q();break}default:Q();break}}};this.readScenePointer=V,this.writeScenePointer=J,this.fireOnStart=()=>{i.forEach(T=>{R(T)==="event/onStart"&&$(T.flows?.out)}),N()},this.fireOnSelect=T=>{if(!T)return;let A=typeof T.meshIndex=="number"?T.meshIndex:-1,S=typeof T.nodeIndex=="number"?T.nodeIndex:e?.meshes?.[A]?.nodeIndex??-1;i.forEach((k,M)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(R(k)))return;let L=oe(k,"nodeIndex")??oe(k,"node")??H(M,"nodeIndex",void 0,new Set),F=oe(k,"meshName");if(typeof F=="string"&&F?T.meshName===F:L==null||Number(L)<0||Number.isNaN(Number(L))||D(S,Math.trunc(Number(L)))){if(_(M,"nodeIndex",S),_(M,"meshIndex",A),Array.isArray(T.hitPoint)){let K=[W(T.hitPoint[0]),W(T.hitPoint[1]),W(T.hitPoint[2])];_(M,"hitPoint",K),_(M,"point",K),_(M,"intersectionPoint",K)}if(Array.isArray(T.normal)){let K=[W(T.normal[0]),W(T.normal[1],1),W(T.normal[2])];_(M,"normal",K),_(M,"hitNormal",K)}typeof T.distance=="number"&&_(M,"distance",T.distance),$(k.flows?.out)}}),N()},this.receiveCustomEvent=(T,A={})=>Y(T,A,{steps:0});function Y(T,A,S){if(!(y>=eo)){y++;try{let k=z(T);i.forEach((M,L)=>{if(!/^(customE|e)vent\/receive$/.test(R(M)))return;let F=oe(M,"event")??oe(M,"id");if(!(z(F)!==k&&String(F)!==String(T))){for(let[U,K]of Object.entries(A))Ne.has(U)||_(L,U,Se(K));$(M.flows?.out,S)}}),N()}finally{y--}}}this.tick=T=>{if(!Number.isFinite(T)||T<0)return;let A=Math.min(T,.25);E+=A,i.forEach((k,M)=>{R(k)==="event/onTick"&&(_(M,"timeDelta",A),_(M,"dt",A),_(M,"timeElapsed",E),$(k.flows?.out))});let S=[];for(let k=d.length-1;k>=0;k--){let M=d[k];M.elapsed+=A;let L=M.dur>1e-6?Ge(M.elapsed/M.dur):1,F=M.linear?L:L*L*(3-2*L),U=si(M.from,M.to,F,M.quat);M.ptr?J(M.ptr,U):M.varKey!==void 0&&B(M.varKey,U),L>=1&&(d.splice(k,1),M.done&&S.push(M.done))}for(let k=p.length-1;k>=0;k--){let M=p[k];M.rem-=A,M.rem<=0&&(p.splice(k,1),M.done&&S.push(M.done))}for(let k of S)$(k);N()},this.dispose=()=>{d.length=0,p.length=0,c.clear(),s.clear(),u.clear(),m.clear(),h.clear(),f.clear()}}},Ie=new WeakMap,An=new WeakMap;function io(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||Dt().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=(An.get(t)||0)+i,a=!1;for(let l=0;l<r.length;l++){let c=r[l],s=Pr(c?.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 P=r.find(E=>E?.name===s.target);Array.isArray(P?.translation)&&(u=W(P.translation[0]),m=W(P.translation[1]),h=W(P.translation[2]))}let f=s.phase+s.speed*o,d=u+Math.cos(f)*s.radius,p=m+s.height,x=h+Math.sin(f)*s.radius;if(c.translation=[d,p,x],s.faceCenter){let P=Math.atan2(u-d,h-x);c.rotation=[0,Math.sin(P*.5),0,Math.cos(P*.5)]}a=!0}if(a){An.set(t,o);let l=Fe(n);t.worldMatrices=l;for(let c of t.meshes||[])c.nodeIndex>=0&&c.nodeIndex<l.length&&(c.transform.set(l[c.nodeIndex]),de(c.normalMatrix,c.transform))}}function Sn(t){if(!(!t||typeof t!="object"))return Ie.get(t)||Ie.get(t.viewer)||Ie.get(t._view)}function nr(t,e,n){let r=Sn(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var rr={name:"khr-interactivity",sendInteractivityEvent:nr,getInteractivityVM:Sn,onLoadModel(t,e){if(!t||typeof t!="object")return;Ie.get(t)?.dispose(),Ie.delete(t),An.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),io(t,e)},onDestroy(t,e){Ie.get(e)?.dispose(),Ie.delete(e),An.delete(e)}};var Mt=new Map,ir=new WeakMap;function ui(t,e){Mt.set(t,e)}var or={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=ir.get(t);n||(n=t.createTexture(),ir.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&&Mt.has(e.name)){let d=Mt.get(e.name);return{vs:d.vs||n,fs:d.fs||r}}let i=e.extensions||{},o=i.KHR_materials_clearcoat,a=i.KHR_materials_sheen,l=!!i.KHR_materials_transmission,c=!!i.KHR_materials_ior,s=i.KHR_materials_iridescence;if(!o&&!a&&!i.KHR_materials_unlit&&!l&&!i.KHR_materials_volume&&!c&&!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;
|
|
318
|
-
`;
|
|
319
|
-
${
|
|
320
|
-
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${
|
|
362
|
+
}`),{vs:n,fs:i}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=Ri.get(e),u=e.getUniformLocation(t,"uHasSH");if(a&&a.length>=27){u&&e.uniform1i(u,1);let s=e.getUniformLocation(t,"uSH");s&&e.uniform3fv(s,a)}else u&&e.uniform1i(u,0)},onAttributeChanged(e,t,n,r){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,r):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,r)}};var Ii=new WeakMap;function Ci(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let i=0;i<r.length;i++){let o=r[i],a=o.getAttribute("data-position");if(!a)continue;let u=a.trim().split(/\s+/).map(f=>parseFloat(f.replace(/m$/,"")));if(u.length<3||u.some(isNaN))continue;let s=o.getAttribute("data-normal"),c;if(s){let f=s.trim().split(/\s+/).map(m=>parseFloat(m));f.length>=3&&!f.some(isNaN)&&(c=[f[0],f[1],f[2]])}let l=n.projectPointToScreen([u[0],u[1],u[2]],c);o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.transform=`translate(-50%, -50%) translate3d(${l.x}px, ${l.y}px, 0)`,o.style.zIndex="3",l.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 Li={name:"hotspots",updateHotspotsForElement:Ci,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Ci(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ii.set(e,t)},onCameraChange(e,t){t&&Ci(t,e)},onElementDisconnected(e){let t=Ii.get(e);t&&(t.disconnect(),Ii.delete(e))}};var ds=1024,Pi=256,Rr=2048,Ja=128,ec=64,tc=16,nc=1e4,rc=8,pt=new Set(["__proto__","constructor","prototype"]),ps={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},bs={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},_r={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Ir=(e,t)=>e!==null&&typeof e=="object"&&!pt.has(t)&&Object.prototype.hasOwnProperty.call(e,t),Ze=e=>Array.isArray(e)?[...e]:e,vs=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Ir(e,"value")?e.value:e,Pe=(e,t)=>Ir(e.configuration,t)?vs(e.configuration[t]):void 0,le=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},Ft=e=>Math.max(0,Math.min(1,e)),tt=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function Rn(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||pt.has(r)||pt.has(n))return null;t.push(r)}return{segments:t}}var tn=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},ys=e=>{let t=le(e[0]),n=le(e[1]),r=le(e[2]),i=le(e[3],1),o=Math.hypot(t,n,r,i);return o>1e-8?[t/o,n/o,r/o,i/o]:[0,0,0,1]},gs=(e,t,n,r)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(r&&e.length===4&&t.length===4){let i=[0,0,0,1];return Ar(i,ys(e),ys(t),n),i}return e.slice(0,t.length).map((i,o)=>i+(t[o]-i)*n)}return n>=.5?t:e},Di=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((r,i)=>n(le(r),le(t[i]))):Array.isArray(e)?e.map(r=>n(le(r),le(t))):Array.isArray(t)?t.map(r=>n(le(e),le(r))):n(le(e),le(t)),ic=(e,t)=>Array.isArray(e)?e.map(n=>t(le(n))):t(le(e)),xs=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,r)=>Math.abs(n-t[r])<=1e-6):e===t,_n=class{constructor(t,n,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>ds)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ds})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>Pi)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Pi})`);let a=Array.isArray(r.declarations)?r.declarations:[],u=Array.isArray(r.events)?r.events:[],s=new Map,c=new Map,l=new Map,f=new Map,m=new Map,h=new Map,p=[],d=[],y=new Map,T=1,S=0,b=0,A=0,w=0,P=!1,N=!1,I=!1;o.forEach((F,H)=>{if(!F||typeof F!="object")return;let E=Ze(vs(F.value));s.set(H,E);let V=F.id??F.name;typeof V=="string"&&V&&!pt.has(V)&&s.set(V,E)}),(n?.nodes||[]).forEach((F,H)=>{for(let E of F?.children||[])typeof E=="number"&&y.set(E,H)});let _=F=>F.op||typeof F.declaration=="number"&&a[F.declaration]?.op||"",v=(F,H,E)=>{if(pt.has(H))return;let V=c.get(F);V||c.set(F,V=Object.create(null)),V[H]=E},g=(F,H)=>{if(typeof F!="number"&&typeof F!="string"||typeof F=="string"&&pt.has(F)||!s.has(F)&&s.size>=Pi*2)return;let E=Ze(H);if(s.set(F,E),typeof F=="number"){let V=o[F]?.id??o[F]?.name;typeof V=="string"&&!pt.has(V)&&s.set(V,E)}},M=F=>typeof F=="number"?u[F]?.id??String(F):typeof F=="string"?/^\d+$/.test(F)&&u[Number(F)]?.id?u[Number(F)].id:F:"",k=(F,H)=>{for(let E=F,V=0;E!==void 0&&E>=0&&V<128;E=y.get(E),V++)if(E===H)return!0;return!1},R=F=>{for(let H=p.length-1;H>=0;H--)p[H].key===F&&p.splice(H,1)},B=F=>{R(F.key),p.length>=Ja&&p.shift(),p.push(F)},Z=F=>{let H=Rn(F)?.segments;if(H){if(H[0]==="nodes"&&Array.isArray(n?.nodes)){let E=n.nodes[tn(H[1],n.nodes.length)];if(!E)return;let V=H[2];if(V in _r){let O=_r[V],U=E[V]||O;return O.map((G,K)=>le(U[K],G))}if(V==="weights"){let O=Array.isArray(E.weights)?E.weights:[0],U=H.length===4?tn(H[3],64):-2;return U===-2?O.map(G=>le(G)):U>=0?le(O[U]):void 0}if(V==="visible"||V==="extensions"&&H[3]==="KHR_node_visibility"&&H[4]==="visible")return E.extensions?.KHR_node_visibility?.visible??E.visible??!0}else if(H[0]==="materials"&&Array.isArray(n?.materials)){let E=n.materials[tn(H[1],n.materials.length)];if(!E)return;let V=E.pbrMetallicRoughness||{};if(H[2]==="pbrMetallicRoughness"){if(H[3]==="baseColorFactor"){let O=V.baseColorFactor||[1,1,1,1];return[le(O[0],1),le(O[1],1),le(O[2],1),le(O[3],1)]}if(H[3]==="metallicFactor"||H[3]==="roughnessFactor")return le(V[H[3]],1)}if(H[2]==="emissiveFactor"){let O=E.emissiveFactor||[0,0,0];return[le(O[0]),le(O[1]),le(O[2])]}if(H[2]==="alphaCutoff")return le(E.alphaCutoff,.5)}}},j=(F,H)=>{let E=Rn(F)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(n?.nodes)){let V=tn(E[1],n.nodes.length),O=n.nodes[V];if(!O)return!1;let U=E[2];if(U in _r&&Array.isArray(H)){let G=_r[U];if(H.length<G.length)return!1;let K=G.map((re,D)=>le(H[D],re));if(U==="rotation"){let re=Math.hypot(...K);K=re>1e-8?K.map(D=>D/re):[0,0,0,1]}O[U]=K,delete O.matrix;let ue=t?.initialNodeTransforms?.[V];return ue&&(ue[U[0]]=[...K]),P=!0,!0}if(U==="weights"){Array.isArray(O.weights)||(O.weights=[]);let G=(K,ue)=>{for(let re of t?.meshes||[])if(re.nodeIndex===V)for(let D of re.primitives||[])D.pluginData?.morph?.weights&&(D.pluginData.morph.weights[K]=ue)};if(E.length===4){let K=tn(E[3],64);if(K<0)return!1;G(K,O.weights[K]=le(H))}else if(Array.isArray(H))O.weights=H.slice(0,64).map(K=>le(K)),O.weights.forEach((K,ue)=>G(ue,K));else return!1;return I=!0,!0}if(U==="visible"||U==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let G=tt(H);return O.visible=G,(!O.extensions||typeof O.extensions!="object")&&(O.extensions={}),O.extensions.KHR_node_visibility={visible:G},N=!0,!0}}else if(E[0]==="materials"&&Array.isArray(n?.materials)){let V=tn(E[1],n.materials.length),O=n.materials[V];if(!O)return!1;let U=O.pbrMetallicRoughness||(O.pbrMetallicRoughness={}),G=K=>{for(let ue of t?.meshes||[])for(let re of ue.primitives||[])(re.materialIndex??0)===V&&K(re)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(H)&&H.length>=3){let K=[Ft(le(H[0],1)),Ft(le(H[1],1)),Ft(le(H[2],1)),H[3]!==void 0?Ft(le(H[3],1)):U.baseColorFactor?.[3]??1];return U.baseColorFactor=K,G(ue=>ue.baseColor=[...K]),I=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let K=E[3]==="metallicFactor",ue=Ft(le(H,K?0:.5));return U[E[3]]=ue,G(re=>re[K?"metallic":"roughness"]=ue),I=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(H)&&H.length>=3)return O.emissiveFactor=[0,1,2].map(K=>Math.max(0,le(H[K]))),I=!0;if(E[2]==="alphaCutoff")return O.alphaCutoff=Ft(le(H,.5)),I=!0}return!1},ie=(F,H,E=new Set)=>{let V=Pe(H,"pointer");if(typeof V!="string"||!V.startsWith("/"))return null;let O=V.replace(/\{([a-zA-Z0-9_]+)\}/g,(U,G)=>{let K=Math.trunc(Number(ee(F,G,void 0,E)??Pe(H,G)));return Number.isSafeInteger(K)&&K>=0?String(K):"-1"});return Rn(O)?O:null},ee=(F,H,E,V)=>{let O=i[F]?.values;if(!Ir(O,H))return E;let U=O[H];if(U==null)return E;if(typeof U!="object"||Array.isArray(U))return Ze(U);let G=U;return typeof G.node=="number"?ne(G.node,G.socket||"value",V):Ir(G,"value")?Ze(G.value):E},ne=(F,H,E)=>{if(F<0||F>=i.length||E.has(F)||E.size>128||++A>nc)return;let V=i[F],O=_(V);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(O))return Ze(c.get(F)?.[H]);E.add(F);try{let U=(G,K=0)=>ee(F,G,K,E);if(O==="variable/get"){let G=Pe(V,"variable")??Pe(V,"id");return typeof G=="number"||typeof G=="string"?Ze(s.get(G)):void 0}if(O==="pointer/get"){let G=ie(F,V,E);return G?Z(G):void 0}if(O.startsWith("math/")){let G=O.slice(5);if(G in ps)return ic(U("a"),ps[G]);if(G in bs){let K=/^(mul|div|rem|mod|pow)$/.test(G)?1:0;return Di(U("a",G==="mul"?1:0),U("b",K),bs[G])}if(G==="pi")return Math.PI;if(G==="e")return Math.E;if(G==="random")return Math.random();if(G==="clamp")return Di(Di(U("a"),U("b",U("min",0)),Math.max),U("c",U("max",1)),Math.min);if(G==="mix"||G==="quatSlerp")return gs(U("a",0),U("b",1),le(U("c",U("t",.5)),.5),G==="quatSlerp");if(G==="dot"){let K=U("a"),ue=U("b");return Array.isArray(K)&&Array.isArray(ue)?K.reduce((re,D,x)=>re+(D||0)*(ue[x]||0),0):le(K)*le(ue)}if(G==="cross"){let K=U("a",[0,0,0]),ue=U("b",[0,0,0]);return Array.isArray(K)&&Array.isArray(ue)?[(K[1]||0)*(ue[2]||0)-(K[2]||0)*(ue[1]||0),(K[2]||0)*(ue[0]||0)-(K[0]||0)*(ue[2]||0),(K[0]||0)*(ue[1]||0)-(K[1]||0)*(ue[0]||0)]:[0,0,0]}if(G==="length"){let K=U("a");return Array.isArray(K)?Math.hypot(...K):Math.abs(le(K))}if(G==="distance"){let K=U("a"),ue=U("b");return Array.isArray(K)&&Array.isArray(ue)?Math.hypot(...K.map((re,D)=>(re||0)-(ue[D]||0))):Math.abs(le(K)-le(ue))}if(G==="normalize"){let K=U("a");if(!Array.isArray(K))return le(K)>=0?1:-1;let ue=Math.hypot(...K);return ue>1e-8?K.map(re=>re/ue):K.map(()=>0)}if(G.startsWith("combine"))return["a","b","c","d"].slice(0,Number(G[7])||2).map(K=>le(U(K)));if(G.startsWith("extract")){let K=U("a");return Array.isArray(K)?K[H==="0"||H==="x"?0:H==="1"||H==="y"?1:H==="2"||H==="z"?2:3]??0:0}if(G==="eq")return xs(U("a"),U("b"));if(G==="ne")return!xs(U("a"),U("b"));if(G==="lt")return le(U("a"))<le(U("b"));if(G==="le")return le(U("a"))<=le(U("b"));if(G==="gt")return le(U("a"))>le(U("b"));if(G==="ge")return le(U("a"))>=le(U("b"));if(G==="isNaN")return Number.isNaN(Number(U("a")));if(G==="isInf"){let K=Number(U("a"));return!Number.isFinite(K)&&!Number.isNaN(K)}return G==="and"?tt(U("a",!1))&&tt(U("b",!1)):G==="or"?tt(U("a",!1))||tt(U("b",!1)):G==="xor"?tt(U("a",!1))!==tt(U("b",!1)):G==="not"?!tt(U("a",!1)):G==="select"?Ze(tt(U("condition",!1))?U("a"):U("b")):void 0}return O==="type/boolToInt"||O==="type/boolToFloat"?tt(U("a",!1))?1:0:O==="type/intToBool"||O==="type/floatToBool"?le(U("a",0))!==0:O==="type/intToFloat"?le(U("a",0)):O==="type/floatToInt"?Math.trunc(le(U("a",0))):void 0}finally{E.delete(F)}},X=()=>{if(P){P=!1,I=!0;let F=ft(n);if(t){t.worldMatrices=F;for(let H of t.meshes||[])H.nodeIndex>=0&&H.nodeIndex<F.length&&(H.transform.set(F[H.nodeIndex]),De(H.normalMatrix,H.transform))}}if(N){N=!1,I=!0;let F=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(F))for(let H of t.meshes){let E=!0;for(let V=H.nodeIndex,O=0;V!==void 0&&V>=0&&O<128;V=y.get(V),O++){let U=F[V];if(U?.visible===!1||U?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}H.visible=E}}I&&(I=!1,t?.render?.())},ae=(F,H={steps:0})=>{if(!F||typeof F.node!="number")return;H.steps===0&&(A=0);let E=[F],V=O=>{E.length+H.steps<Rr&&E.push(O)};for(;E.length>0&&H.steps<Rr;){H.steps++;let O=E.shift();if(!O||O.node<0||O.node>=i.length)continue;let U=O.node,G=i[U];if(!G)continue;let K=O.socket||"in",ue=_(G),re=(x,C=void 0)=>ee(U,x,C,new Set),D=(x="out")=>{let C=G.flows?.[x];C&&V(C)};switch(ue){case"flow/branch":D(tt(re("condition",!1))?"true":"false");break;case"flow/sequence":for(let x of Object.keys(G.flows||{}).sort((C,L)=>Number(C)-Number(L)||C.localeCompare(L)))D(x);break;case"flow/switch":{let x=G.flows?.[String(re("selection",re("value",0)))]??G.flows?.default;x&&V(x);break}case"flow/for":{let x=Math.trunc(le(re("startIndex",0))),C=Math.trunc(le(re("endIndex",0))),L=Math.max(1,Math.trunc(le(re("step",1),1))),z=G.flows?.body;if(z&&C>x&&w<rc){let $=Math.min(Math.ceil((C-x)/L),Rr);w++;try{for(let Y=0;Y<$&&H.steps<Rr;Y++)v(U,"index",x+Y*L),ae(z,H)}finally{w--}}let W=G.flows?.completed??G.flows?.out;W&&V(W);break}case"flow/doN":{let x=K==="reset"?0:(l.get(U)||0)+1;if(l.set(U,x),v(U,"currentCount",x),v(U,"count",x),K!=="reset"){let C=Math.trunc(le(re("n",Pe(G,"stopIterations")??Pe(G,"n")??1),1));x<=C&&D()}break}case"flow/multiGate":{if(K==="reset"){h.set(U,0);break}let x=Object.keys(G.flows||{}).sort();if(!x.length)break;let C=Pe(G,"isRandom")?Math.floor(Math.random()*x.length):h.get(U)||0;C<x.length&&(D(x[C]),h.set(U,Pe(G,"isLoop")!==!1?(C+1)%x.length:C+1));break}case"flow/waitAll":{if(K==="reset"){f.delete(U);break}let x=f.get(U);x||f.set(U,x=new Set),x.add(K),x.size>=Math.max(1,Math.trunc(Number(Pe(G,"inputFlows")??2)||2))&&(x.clear(),D("out"),D("completed"));break}case"flow/throttle":{if(K==="reset"){m.delete(U);break}let x=Math.max(0,le(re("duration",0))),C=m.get(U);C===void 0||S-C>=x?(m.set(U,S),v(U,"lastRemainingTime",0),D()):v(U,"lastRemainingTime",Math.max(0,x-(S-C)));break}case"flow/delay":case"flow/setDelay":{if(K==="cancel"){for(let z=d.length-1;z>=0;z--)d[z].nodeIdx===U&&d.splice(z,1);v(U,"lastDelayIndex",-1);break}let x=Math.max(0,le(re("duration",Pe(G,"duration")??0))),C=G.flows?.done??G.flows?.out;if(x<=0){v(U,"lastDelayIndex",-1),C&&V(C);break}d.length>=ec&&d.shift();let L=T++;v(U,"lastDelayIndex",L),d.push({id:L,nodeIdx:U,rem:x,done:C}),ue==="flow/setDelay"&&G.flows?.out&&G.flows?.done&&D("out");break}case"flow/cancelDelay":{let x=Math.trunc(le(re("delayIndex",-1),-1));if(x<0)d.length=0;else for(let C=d.length-1;C>=0;C--)d[C].id===x&&d.splice(C,1);D();break}case"variable/set":g(Pe(G,"variable")??Pe(G,"id"),re("value")),D();break;case"variable/interpolate":{let x=Pe(G,"variable")??Pe(G,"id"),C=re("value",re("target")),L=Math.max(0,le(re("duration",Pe(G,"duration")??.3),.3));x!==void 0&&C!==void 0&&B({key:`var:${String(x)}`,varKey:x,from:Ze(re("from")??s.get(x)??0),to:Ze(C),dur:L,elapsed:0,quat:!1,linear:Pe(G,"easing")==="linear",done:G.flows?.done}),D();break}case"pointer/set":{let x=ie(U,G),C=re("value");x&&C!==void 0&&(R(`ptr:${x}`),j(x,C)),D();break}case"pointer/interpolate":{let x=ie(U,G),C=re("value",re("target")),L=Math.max(0,le(re("duration",Pe(G,"duration")??.3),.3));if(x&&C!==void 0){let z=re("from")??Z(x);z!==void 0&&(L<=0?(j(x,C),D("done")):B({key:`ptr:${x}`,ptr:x,from:Ze(z),to:Ze(C),dur:L,elapsed:0,quat:x.endsWith("/rotation"),linear:Pe(G,"easing")==="linear",done:G.flows?.done}))}D();break}case"animation/start":{let x=re("animation")??Pe(G,"animation")??Pe(G,"clipName"),C=typeof x=="number"?t?.animations?.[x]?.name??n?.animations?.[x]?.name:typeof x=="string"?x:void 0;t?.playAnimation?.(C),I=!0,D();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),ue==="animation/resetAt"&&t?.evaluateAnimation?.(le(re("time",0))),I=!0,D();break;case"event/send":case"customEvent/send":{let x=M(Pe(G,"event")??Pe(G,"id")),C={};for(let L of Object.keys(G.values||{}))pt.has(L)||(C[L]=re(L));x&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:x,values:C}})),se(x,C,H)),D();break}default:D();break}}};this.readScenePointer=Z,this.writeScenePointer=j,this.fireOnStart=()=>{i.forEach(F=>{_(F)==="event/onStart"&&ae(F.flows?.out)}),X()},this.fireOnSelect=F=>{if(!F)return;let H=typeof F.meshIndex=="number"?F.meshIndex:-1,E=typeof F.nodeIndex=="number"?F.nodeIndex:t?.meshes?.[H]?.nodeIndex??-1;i.forEach((V,O)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(_(V)))return;let U=Pe(V,"nodeIndex")??Pe(V,"node")??ee(O,"nodeIndex",void 0,new Set),G=Pe(V,"meshName");if(typeof G=="string"&&G?F.meshName===G:U==null||Number(U)<0||Number.isNaN(Number(U))||k(E,Math.trunc(Number(U)))){if(v(O,"nodeIndex",E),v(O,"meshIndex",H),Array.isArray(F.hitPoint)){let ue=[le(F.hitPoint[0]),le(F.hitPoint[1]),le(F.hitPoint[2])];v(O,"hitPoint",ue),v(O,"point",ue),v(O,"intersectionPoint",ue)}if(Array.isArray(F.normal)){let ue=[le(F.normal[0]),le(F.normal[1],1),le(F.normal[2])];v(O,"normal",ue),v(O,"hitNormal",ue)}typeof F.distance=="number"&&v(O,"distance",F.distance),ae(V.flows?.out)}}),X()},this.receiveCustomEvent=(F,H={})=>se(F,H,{steps:0});function se(F,H,E){if(!(b>=tc)){b++;try{let V=M(F);i.forEach((O,U)=>{if(!/^(customE|e)vent\/receive$/.test(_(O)))return;let G=Pe(O,"event")??Pe(O,"id");if(!(M(G)!==V&&String(G)!==String(F))){for(let[K,ue]of Object.entries(H))pt.has(K)||v(U,K,Ze(ue));ae(O.flows?.out,E)}}),X()}finally{b--}}}this.tick=F=>{if(!Number.isFinite(F)||F<0)return;let H=Math.min(F,.25);S+=H,i.forEach((V,O)=>{_(V)==="event/onTick"&&(v(O,"timeDelta",H),v(O,"dt",H),v(O,"timeElapsed",S),ae(V.flows?.out))});let E=[];for(let V=p.length-1;V>=0;V--){let O=p[V];O.elapsed+=H;let U=O.dur>1e-6?Ft(O.elapsed/O.dur):1,G=O.linear?U:U*U*(3-2*U),K=gs(O.from,O.to,G,O.quat);O.ptr?j(O.ptr,K):O.varKey!==void 0&&g(O.varKey,K),U>=1&&(p.splice(V,1),O.done&&E.push(O.done))}for(let V=d.length-1;V>=0;V--){let O=d[V];O.rem-=H,O.rem<=0&&(d.splice(V,1),O.done&&E.push(O.done))}for(let V of E)ae(V);X()},this.dispose=()=>{p.length=0,d.length=0,s.clear(),c.clear(),l.clear(),f.clear(),m.clear(),h.clear()}}},ct=new WeakMap,Cr=new WeakMap;function oc(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||kn().some(s=>s.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let o=Math.min(t,.1),a=(Cr.get(e)||0)+o,u=!1;for(let s=0;s<i.length;s++){let c=i[s],l=Uo(c?.extras?.xr?.orbit);if(!l)continue;let f=0,m=0,h=0;if(Array.isArray(l.target))f=l.target[0],m=l.target[1],h=l.target[2];else if(typeof l.target=="string"&&l.target!=="head"){let S=i.find(b=>b?.name===l.target);Array.isArray(S?.translation)&&(f=le(S.translation[0]),m=le(S.translation[1]),h=le(S.translation[2]))}let p=l.phase+l.speed*a,d=f+Math.cos(p)*l.radius,y=m+l.height,T=h+Math.sin(p)*l.radius;if(c.translation=[d,y,T],l.faceCenter){let S=Math.atan2(f-d,h-T);c.rotation=[0,Math.sin(S*.5),0,Math.cos(S*.5)]}u=!0}if(u){Cr.set(e,a);let s=ft(r);e.worldMatrices=s;for(let c of e.meshes||[])c.nodeIndex>=0&&c.nodeIndex<s.length&&(c.transform.set(s[c.nodeIndex]),De(c.normalMatrix,c.transform))}}function Lr(e){if(!(!e||typeof e!="object"))return ct.get(e)||ct.get(e.viewer)||ct.get(e._view)}function Ni(e,t,n){let r=Lr(e);return r?(r.receiveCustomEvent(t,n),!0):!1}var ki={name:"khr-interactivity",sendInteractivityEvent:Ni,getInteractivityVM:Lr,onLoadModel(e,t){if(!e||typeof e!="object")return;ct.get(e)?.dispose(),ct.delete(e),Cr.delete(e);let n=t?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let i=new _n(e,t,r);ct.set(e,i),i.fireOnStart()},onMeshSelect(e,t){ct.get(e)?.fireOnSelect(t)},onUpdate(e,t){ct.get(e)?.tick(t),oc(e,t)},onDestroy(e,t){ct.get(t)?.dispose(),ct.delete(t),Cr.delete(t)}};var In=new Map,Pr=new WeakMap;function Ts(e,t){In.set(e,t)}var Fi={name:"materials",onContextRestored(e){Pr.delete(e)},onBuildPrimitiveVAO(e,t,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(e,t){let n=Pr.get(e);n||(n=e.createTexture(),Pr.set(e,n));let r=Math.max(1,t.canvas.width),i=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,r,i,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,n,r){if(!t)return null;if(t.name&&In.has(t.name)){let p=In.get(t.name);return{vs:p.vs||n,fs:p.fs||r}}let i=t.extensions||{},o=i.KHR_materials_clearcoat,a=i.KHR_materials_sheen,u=!!i.KHR_materials_transmission,s=!!i.KHR_materials_ior,c=i.KHR_materials_iridescence;if(!o&&!a&&!i.KHR_materials_unlit&&!u&&!i.KHR_materials_volume&&!s&&!i.KHR_materials_dispersion&&!c)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 l=r;if(u){let p=l.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
363
|
+
`;l=l.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
364
|
+
${p}out vec4 fragColor;`)}let f=(p,d,y=0,T=1e6,S=3)=>{let b=Number(p);return(Number.isFinite(b)?Math.min(T,Math.max(y,b)):d).toFixed(S)},m=Number(i.KHR_materials_ior?.ior??1.5),h=Number.isFinite(m)?Math.min(10,Math.max(1,m)):1.5;if(s){let p=Math.pow((h-1)/(h+1),2);l=l.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${f(p,.04,0,1,4)}),base.rgb,metallic);`)}if(c){let p=f(c.iridescenceFactor,1,0,1),d=f(c.iridescenceIor,1.3,1,10);l=l.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${d}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${p}*pow(1.-NoV,2.));`)}if(u){let p=f(i.KHR_materials_transmission?.transmissionFactor,1,0,1),d=i.KHR_materials_volume||{},y=f(d.thicknessFactor,.5,0,1e4),T=f(d.attenuationDistance,1,.001,1e6),S=Array.isArray(d.attenuationColor)?d.attenuationColor:[1,1,1],b=f(i.KHR_materials_dispersion?.dispersion,0,0,10);l=l.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
365
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${f(h,1.5,1,10)},dV=${b},tV=${y},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
321
366
|
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
322
367
|
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);
|
|
323
|
-
vec3 aCol=vec3(${
|
|
324
|
-
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${
|
|
325
|
-
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(a){let d=Array.isArray(a.sheenColorFactor)?a.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 a=n.materialIndex;if(a!==void 0&&o?.materials){let l=o.materials[a];l?.name&&Mt.has(l.name)&&Mt.get(l.name).onBindUniforms?.(t,e,n)}if(n.isTransmissive){let l=ir.get(t);if(l){t.activeTexture(33990),t.bindTexture(3553,l);let c=t.getUniformLocation(e,"uTransmissionTex");c&&t.uniform1i(c,6);let s=t.getUniformLocation(e,"uViewportSize");s&&t.uniform2f(s,t.drawingBufferWidth||1,t.drawingBufferHeight||1)}}}};var oo=`#version 300 es
|
|
326
|
-
layout(location=0) in vec3 aPosition;
|
|
327
|
-
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,li=new Float32Array(20);function sr(t,e){let[n,r,i,o,a,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])*a+Math.abs(t[8])*l,Math.abs(t[1])*o+Math.abs(t[5])*a+Math.abs(t[9])*l,Math.abs(t[2])*o+Math.abs(t[6])*a+Math.abs(t[10])*l]}function ao(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,a=-1e9;for(let l of t.primitives||[]){let c=l.positions;if(c)for(let s=0;s<c.length;s+=3)c[s]<e&&(e=c[s]),c[s+1]<n&&(n=c[s+1]),c[s+2]<r&&(r=c[s+2]),c[s]>i&&(i=c[s]),c[s+1]>o&&(o=c[s+1]),c[s+2]>a&&(a=c[s+2])}return t._lb=e<=i?[(e+i)*.5,(n+o)*.5,(r+a)*.5,(i-e)*.5,(o-n)*.5,(a-r)*.5]:null}function co(t){let e=Rn.get(t);if(e)return e;let n=(l,c)=>{let s=t.createShader(l);return t.shaderSource(s,c),t.compileShader(s),s},r=t.createProgram();t.attachShader(r,n(35633,oo)),t.attachShader(r,n(35632,so)),t.linkProgram(r);let i=t.createVertexArray(),o=t.createBuffer(),a=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,a),t.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),t.bindVertexArray(null),e={prog:r,vao:i,vbo:o,ibo:a,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=co(t),o=!e.xrSessionActive&&(e.backdropMeshes?.length??0)>0,a=[],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 x=ao(p);if(!x)continue;p.transform&&(x=sr(p.transform,x)),e.modelRootMatrix&&(x=sr(e.modelRootMatrix,x));let[P,E,y,v,g,I]=x,b=[P,y,v,I,E-g,E+g];/floor|table|pedestal|ground|base|plane/i.test(p.name||"")||g<.14&&Math.min(v,I)>.45?l.push(b):a.push(b)}let c=[],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=sr(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,x,P,E,y]of a){let v=-1/0;for(let[I,b,w,R,,_]of l)y>=_-.08&&Math.abs(p-I)<=w&&Math.abs(x-b)<=R&&_+.002>v&&(v=_+.002);o&&(v=Math.max(v,p>=.04&&p<=.36&&x>=-.34&&x<=-.04&&y>=.01?.036:Math.hypot(p,x)<=.66&&y>=-.06?.003:-.477)),isFinite(v)||(v=d);let g=c.find(I=>Math.hypot(p-I[0],x-I[1])<.06&&Math.abs(v-I[5])<.05);g?(g[2]=Math.max(g[2],P*.78),g[3]=Math.max(g[3],E*.78),g[4]=Math.min(g[4],y)):c.push([p,x,P,E,y,v])}if(c.length===0){let p=Math.max(.1,h[3]*1.5)/1.45;c.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,x,P,E,y,v]of c){let g=Math.max(0,y-v),I=r/(1+g*2);if(I<.02)continue;let b=1+Math.min(.75,g*.85),w=Math.max(.045,P*1.45*b),R=Math.max(.045,E*1.45*b);li.set([p-w,v,x-R,0,0,p+w,v,x-R,1,0,p+w,v,x+R,1,1,p-w,v,x+R,0,1]),t.bufferSubData(34962,0,li),t.uniform1f(i.uIntensity,I),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 mi=new WeakMap,cr={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=mi.get(e);if(i||(i={lightProbe:null},mi.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 a=o.primaryLightDirection,l=o.primaryLightIntensity;if(a&&l&&Array.isArray(t.lights)){let c=t.lights.find(u=>u.type==="directional");c||(c={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(c)),c.direction=[a.x,a.y,a.z];let s=Math.max(l.x,l.y,l.z,.001);c.color=[l.x/s,l.y/s,l.z/s],c.intensity=s}o.sphericalHarmonicsCoefficients&&t.gl&&gn(t.gl,o.sphericalHarmonicsCoefficients)}}}};ge(Et);ge(Qn);ge(Kn);ge(or);ge(cr);ge(rr);function lr(){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 mr(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function hr(){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 fi(){return(await Mn()).bestMode}async function Mn(){let[t,e,n]=await Promise.all([hr(),Promise.resolve(lr()),Promise.resolve(mr())]),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 hi(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=uo(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 a=document.createElement("img");a.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),a.style.display="none",o.appendChild(a),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 uo(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 lo(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 mo(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=lo(t,e);window.location.href=n}var $e=null;function ho(t,e){let r=new Float32Array(144),i=new Float32Array(24*6),o=new Float32Array(24*4),a=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,x=p+1,P=(m+1)%24*2;r[p*3]=f*.11,r[p*3+1]=.002,r[p*3+2]=d*.11,r[x*3]=f*.145,r[x*3+1]=.002,r[x*3+2]=d*.145,i[p*3+1]=i[x*3+1]=1,a.set([p,P,x,x,P,P+1],m*6)}let l=t.createVertexArray();t.bindVertexArray(l);let c=(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=[c(r,0,3),c(i,1,3),c(o,2,2)],u=t.createBuffer();return s.push(u),t.bindBuffer(34963,u),t.bufferData(34963,a,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:a.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:a,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:s}]}}function di(t,e,n,r,i){let o=Math.cos(r),a=Math.sin(r),l=Math.max(.01,i);t.fill(0),t[0]=l*o,t[2]=-l*a,t[5]=l,t[8]=l*a,t[10]=l*o,t[12]=e[0]-l*(o*n[0]+a*n[2]),t[13]=e[1]-l*n[1],t[14]=e[2]-l*(-a*n[0]+o*n[2]),t[15]=1}var ur=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.");$e&&$e!==this&&$e.isSessionActive()&&await $e.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||e?.container,a=String(o?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,c=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=a?i.arScale==="fixed"?1:h?.55:1:i.arScale==="fixed"?1:c>.45?.3/c:c<.05?.12/Math.max(c,.001):1,d=a?[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 x=o?.querySelector?.('[slot="ar-overlay"]')||null,P=!1,E=null,y=()=>{P&&x?.parentNode&&x.parentNode.removeChild(x),x=null,E=null,P=!1};if(p==="immersive-ar"){if(x)x.addEventListener?.("beforexrselect",S=>S.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let S=document.createElement("div");S.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 k=document.createElement("button");k.type="button",k.textContent="\u2715 Exit AR",k.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",k.addEventListener("beforexrselect",M=>M.preventDefault()),k.addEventListener("click",M=>{M.stopPropagation(),this.stop().catch(()=>{})}),E=document.createElement("div"),E.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",E.textContent="Move phone to detect a surface \u2022 Tap to place",S.appendChild(k),S.appendChild(E),document.body.appendChild(S),x=S,P=!0}}let v=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),g={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(v)};x&&(v.add("dom-overlay"),g.optionalFeatures=Array.from(v),g.domOverlay={root:x});for(let S of ue)S.onConfigureXRSessionInit?.(o,g);Array.isArray(g.optionalFeatures)&&g.optionalFeatures.includes("dom-overlay")&&!g.domOverlay?.root&&(g.optionalFeatures=g.optionalFeatures.filter(S=>S!=="dom-overlay"));let I=S=>{let k=String(S?.name||"");return k==="NotAllowedError"||k==="SecurityError"};try{this.s=await r.requestSession(p,g)}catch(S){if(y(),I(S))throw i.onError?.(S),S;try{this.s=await r.requestSession(p,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(k){if(I(k))throw i.onError?.(k),k;try{this.s=await r.requestSession(p)}catch(M){throw i.onError?.(M),M}}}let b=this.s;$e=this,this.placed=!1;let w=null,R=null,_=null,B=null,z=null,D=[0,-.25,-1.2],C=[0,-.25,-1.2],G=new Float32Array(16),V=new Float32Array(16),J=!1,j=1,H=0,X=!1,N=null,$=null,Y=0,T=null,A=()=>{$e===this&&($e=null),T?.(),T=null;try{R?.cancel?.()}catch{}if(R=null,_){let S=e?.meshes;if(Array.isArray(S)){let M=S.indexOf(_);M!==-1&&S.splice(M,1)}let k=e.getGLContext?.()||e?.gl;if(k)for(let M of _.primitives||[]){k.deleteVertexArray?.(M.vao);for(let L of M.buffers||[])k.deleteBuffer?.(L)}_=null}e?.setXRSessionActive?.(!1),y(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=A,b.addEventListener("end",()=>{A(),i.onExit?.()}),b.addEventListener("select",()=>{if(!this.placed){let S=z||D;C=[S[0],S[1],S[2]],di(this.placedMat,C,d,H,f*j),this.placed=!0,_&&(_.visible=!1),E&&(E.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let S=e.getGLContext?.()||e?.gl;S&&typeof S.makeXRCompatible=="function"&&await S.makeXRCompatible();let k=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;S&&typeof k=="function"&&typeof b.updateRenderState=="function"&&b.updateRenderState({baseLayer:new k(b,S,{alpha:!0})});try{w=await b.requestReferenceSpace("local")}catch{try{w=await b.requestReferenceSpace("local-floor")}catch{w=await b.requestReferenceSpace("viewer")}}let M=await b.requestReferenceSpace("viewer").catch(()=>w);if(typeof b.requestHitTestSource=="function"&&M&&(R=await b.requestHitTestSource({space:M}).catch(()=>null)),p==="immersive-ar"&&S&&typeof S.createVertexArray=="function"&&Array.isArray(e.meshes)&&(_=ho(S,i.reticleColor),e.meshes.push(_)),typeof window<"u"&&typeof window.addEventListener=="function"){let F=O=>Math.hypot(O.touches[1].clientX-O.touches[0].clientX,O.touches[1].clientY-O.touches[0].clientY),U=O=>Math.atan2(O.touches[1].clientY-O.touches[0].clientY,O.touches[1].clientX-O.touches[0].clientX),K=O=>{this.s&&(O.touches.length===1&&this.placed?X=!0:O.touches.length>=2&&(X=!1,N=F(O),$=U(O)))},Z=O=>{if(!this.s||O.touches.length<2)return;let q=F(O),ee=U(O);if(N&&N>4&&i.arScale!=="fixed"&&(j=Math.max(.15,Math.min(6,j*(q/N)))),$!==null){let ae=ee-$;ae>Math.PI&&(ae-=Math.PI*2),ae<-Math.PI&&(ae+=Math.PI*2),H-=ae}N=q,$=ee},Q=O=>{(!O.touches||O.touches.length===0)&&(X=!1),(!O.touches||O.touches.length<2)&&(N=null,$=null)};window.addEventListener("touchstart",K,{passive:!0}),window.addEventListener("touchmove",Z,{passive:!0}),window.addEventListener("touchend",Q,{passive:!0}),window.addEventListener("touchcancel",Q,{passive:!0}),T=()=>{window.removeEventListener("touchstart",K),window.removeEventListener("touchmove",Z),window.removeEventListener("touchend",Q),window.removeEventListener("touchcancel",Q)}}e.setXRSessionActive?.(!0);let L=(F,U)=>{if(this.s!==b)return;b.requestAnimationFrame(L);let K=Y>0?Math.min(Math.max((F-Y)/1e3,0),.1):1/60;Y=F,e?.stepXRUpdate?.(K);let Z=U.getViewerPose(w);if(!Z)return;let Q=Z.views?.[0];if(!J&&Q?.transform){let pe=Q.transform.position,ce=Q.transform.matrix,Le=pe?.x??(ce?ce[12]:0),xe=pe?.y??(ce?ce[13]:0),ve=pe?.z??(ce?ce[14]:0),te=ce?-ce[8]:0,he=ce?-ce[10]:-1,Ee=Math.hypot(te,he);Ee>1e-4?(te/=Ee,he/=Ee):(te=0,he=-1),D=[Le+te*1.2,xe-.25,ve+he*1.2],H=Math.atan2(-te,-he),J=!0}if(R&&typeof U.getHitTestResults=="function"&&(!this.placed||X)){let pe=U.getHitTestResults(R)||[],ce=!1;for(let Le of pe){let xe=Le.getPose(w);if(xe?.transform?.matrix){let ve=xe.transform.matrix,te=ve[5];if(i.arPlacement==="wall"&&Math.abs(te)>.35||i.arPlacement==="floor"&&Math.abs(te)<.65)continue;B||(B=new Float32Array(16)),B.set(ve),z=[ve[12],ve[13],ve[14]],this.placed&&X&&(C=[ve[12],ve[13],ve[14]]),_&&(_.visible=!this.placed||X,_.transform.set(ve)),!this.placed&&E&&(E.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(B),ce=!0;break}}!ce&&_&&(_.visible=!1)}di(G,this.placed?C:z||D,d,H,f*j),this.placed&&this.placedMat.set(G);let O=e.xrRigMatrix;O instanceof Float32Array&&O.length===16?be(V,O,G):V.set(G),e.modelRootMatrix&&e.modelRootMatrix.set(V);for(let pe of ue)pe.onXRFrame?.(e,b,U,w);let q=e.getGLContext?.()||e?.gl,ee=b.renderState?.baseLayer;q&&ee&&ee.framebuffer!==void 0&&q.bindFramebuffer(36160,ee.framebuffer);let ae=p==="immersive-ar",Ve=Z.views||[];for(let pe=0;pe<Ve.length;pe++){let ce=Ve[pe];if(typeof e.renderXRView=="function"){let Le;if(ee&&typeof ee.getViewport=="function"){let xe=ee.getViewport(ce);xe&&xe.width>0&&xe.height>0&&(Le=[xe.x,xe.y,xe.width,xe.height])}else ee?.framebufferWidth>0&&ee?.framebufferHeight>0&&(Le=[0,0,ee.framebufferWidth,ee.framebufferHeight]);e.renderXRView(ce,V,this.placed,Le,ae,pe)}}q&&ee&&ee.framebuffer&&q.bindFramebuffer(36160,null)};b.requestAnimationFrame(L)}catch(S){throw typeof b.end=="function"&&await b.end().catch(()=>{}),A(),i.onError?.(S),S}}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 Mn(),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},a={...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 hi(t.model,i),{mode:"quick-look",success:!0};l=Ze(t.model)}return hi(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 mo(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 ur(a);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}`)}}Pe.registerAR({activateAR:En,createUSDZBlob:Ze});Pe.registerScriptRunner(tt);ge(Et);Pe.registerScriptRunner(tt);typeof window<"u"&&(window.ThreeLiveBundle=dr);
|
|
368
|
+
vec3 aCol=vec3(${f(S[0],1,0,1)},${f(S[1],1,0,1)},${f(S[2],1,0,1)});
|
|
369
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${T},.001));
|
|
370
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${p});`)}if(o&&!r.includes("uClearcoat")){let p=f(o.clearcoatFactor,1,0,1),d=f(o.clearcoatRoughnessFactor,0,0,1);l=l.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${d},NoV)*${p};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${d})*ccF;fragColor=vec4(color,base.a);`)}if(a){let p=Array.isArray(a.sheenColorFactor)?a.sheenColorFactor:[1,1,1],d=`color+=vec3(${f(p[0],1,0,1)},${f(p[1],1,0,1)},${f(p[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;l.includes("color=applyToneMapping(color,uToneMapping);")?l=l.replace("color=applyToneMapping(color,uToneMapping);",`${d}color=applyToneMapping(color,uToneMapping);`):l=l.replace("fragColor=vec4(color,base.a);",`${d}fragColor=vec4(color,base.a);`)}return{vs:n,fs:l}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=n.materialIndex;if(a!==void 0&&o?.materials){let u=o.materials[a];u?.name&&In.has(u.name)&&In.get(u.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let u=Pr.get(e);if(u){e.activeTexture(33990),e.bindTexture(3553,u);let s=e.getUniformLocation(t,"uTransmissionTex");s&&e.uniform1i(s,6);let c=e.getUniformLocation(t,"uViewportSize");c&&e.uniform2f(c,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var As=64*1024*1024,ws=128*1024*1024,sc=16777216;function ac(e){return(e>>>1^-(e&1))&255}function cc(e){return(e>>>1^-(e&1))&65535}function uc(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Ms(e){return(e<<1^e>>31)>>>0}function Rs(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw Me(`unknown filter "${String(e)}"`)}var xe=Math.fround;function nn(e){return Math.trunc(xe(e+(e>=0?.5:-.5)))}function Ui(e,t,n,r="NONE"){if(Rs(r),!r||r==="NONE"||t<=0)return;let i=new DataView(e.buffer,e.byteOffset,e.byteLength);if(r==="OCTAHEDRAL"){if(n!==4&&n!==8)throw Me(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let f=n===8,m=f?32767:127,h=y=>f?i.getInt16(y,!0):i.getInt8(y),p=(y,T)=>f?i.setInt16(y,T,!0):i.setInt8(y,T<<24>>24),d=f?2:1;for(let y=0;y<t;y++){let T=y*n,S=h(T),b=h(T+d),A=xe(h(T+2*d)-Math.abs(S)-Math.abs(b)),w=A>=0?0:A;S=xe(S+(S>=0?w:-w)),b=xe(b+(b>=0?w:-w));let P=xe(Math.sqrt(xe(xe(xe(S*S)+xe(b*b))+xe(A*A))));if(P===0){p(T,0),p(T+d,0),p(T+2*d,m);continue}let N=xe(m/P);p(T,nn(xe(S*N))),p(T+d,nn(xe(b*N))),p(T+2*d,nn(xe(A*N)))}return}if(r==="QUATERNION"){if(n!==8)throw Me(`QUATERNION filter requires byteStride 8 (got ${n})`);let f=xe(32767/xe(Math.SQRT2));for(let m=0;m<t;m++){let h=m*8,p=i.getInt16(h+6,!0),d=p|3,y=i.getInt16(h,!0),T=i.getInt16(h+2,!0),S=i.getInt16(h+4,!0),b=xe(d*d),A=xe(xe(xe(xe(b*2)-xe(y*y))-xe(T*T))-xe(S*S)),w=xe(Math.sqrt(A>=0?A:0)),P=xe(f/d),N=p&3,I=[0,0,0,0];I[N+1&3]=nn(xe(y*P)),I[N+2&3]=nn(xe(T*P)),I[N+3&3]=nn(xe(S*P)),I[N]=Math.trunc(xe(xe(w*P)+.5));for(let _=0;_<4;_++)i.setInt16(h+_*2,I[_]<<16>>16,!0)}return}if(r==="EXPONENTIAL"){if(n<4||n%4!==0)throw Me(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let f=t*n>>>2;for(let m=0;m<f;m++){let h=m*4,p=i.getUint32(h,!0),d=p<<8>>8,y=p>>24;i.setUint32(h,y+127<<23>>>0,!0);let T=i.getFloat32(h,!0);i.setFloat32(h,xe(T*d),!0)}return}if(n!==4&&n!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${n})`);let o=n===8,a=o?65535:255,u=f=>o?i.getUint16(f,!0):i.getUint8(f),s=f=>o?i.getInt16(f,!0):i.getInt8(f),c=(f,m)=>o?i.setUint16(f,m&65535,!0):i.setUint8(f,m&255),l=o?2:1;for(let f=0;f<t;f++){let m=f*n,h=u(m+3*l);h|=h>>1,h|=h>>2,h|=h>>4,h|=h>>8;let p=u(m),d=s(m+l),y=s(m+2*l),T=p+d-y,S=p+y,b=p-d-y,A=u(m+3*l);A=A<<1&h|A&1;let w=h===0?0:xe(a/h);c(m,Math.trunc(xe(xe(T*w)+.5))),c(m+l,Math.trunc(xe(xe(S*w)+.5))),c(m+2*l,Math.trunc(xe(xe(b*w)+.5))),c(m+3*l,Math.trunc(xe(xe(A*w)+.5)))}}var _s=160,ut=16,lc=24,Is=32,mc=24,fc=[0,2,4,8],hc=[0,1,2,4,8];function Cs(e){let t=Math.floor(8192/e)&~(ut-1);return t<256?t:256}function Me(e){return new Error(`EXT_meshopt_compression: ${e}`)}function dc(e,t,n,r,i){if(i===0)return n.fill(0,r,r+ut),t;if(i===8)return n.set(e.subarray(t,t+ut),r),t+ut;let o=(1<<i)-1,a=8/i,u=t+ut*i/8;for(let s=0;s<ut;s++){let c=e[t+Math.floor(s/a)],l=s%a,f=i===1?c>>l&1:c>>8-i-l*i&o;n[r+s]=f===o?e[u++]:f}return u}function Ss(e,t,n,r,i,o,a,u){let s=o/ut,c=s+3>>2;if(n-t<c)throw Me("truncated ATTRIBUTES stream");let l=t;t+=c;for(let f=0;f<s;f++){if(n-t<lc)throw Me("truncated ATTRIBUTES stream");let m=e[l+(f>>2)]>>(f&3)*2&3;t=dc(e,t,r,i+f*ut,a[u+m])}return t}function pc(e,t,n,r){if(n%4!==0||n>256)throw Me(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let i=e.byteLength;if(i<1)throw Me("truncated ATTRIBUTES stream");let o=e[0];if((o&240)!==_s)throw Me(`unsupported ATTRIBUTES header 0x${o.toString(16)}`);let a=o&15;if(a>1)throw Me(`unsupported ATTRIBUTES codec version ${a}`);let u=n+(a===0?0:n/4),s=a===0?Is:mc,c=u<s?s:u;if(i-1<c)throw Me("truncated ATTRIBUTES stream");let l=i-u,f=e.slice(l,l+n),m=l+n,h=Cs(n),p=new Uint8Array(256*4),d=1;for(let y=0;y<t;){let T=Math.min(h,t-y),S=T+ut-1&~(ut-1),b=a===0?0:n/4;if(i-d<b)throw Me("truncated ATTRIBUTES stream");let A=d;d+=b;for(let w=0;w<n;w+=4){let P=a===0?0:e[A+w/4];for(let _=0;_<4;_++){let v=P>>_*2&3;if(v===3){if(i-d<T)throw Me("truncated ATTRIBUTES stream");p.set(e.subarray(d,d+T),_*T),d+=T}else v===2?p.fill(0,_*T,_*T+T):d=a===0?Ss(e,d,i,p,_*T,S,fc,0):Ss(e,d,i,p,_*T,S,hc,v)}let N=a===0?0:e[m+w/4],I=N&3;if(I===0)for(let _=0;_<4;_++){let v=f[w+_];for(let g=0;g<T;g++)v=ac(p[_*T+g])+v&255,r[(y+g)*n+w+_]=v}else if(I===1)for(let _=0;_<4;_+=2){let v=f[w+_]|f[w+_+1]<<8,g=_*T;for(let M=0;M<T;M++){let k=p[g+M]|p[g+T+M]<<8;v=cc(k)+v&65535;let R=(y+M)*n+w+_;r[R]=v&255,r[R+1]=v>>8}}else if(I===2){let _=32-(N>>4)&31,v=(f[w]|f[w+1]<<8|f[w+2]<<16|f[w+3]<<24)>>>0;for(let g=0;g<T;g++){let M=(p[g]|p[T+g]<<8|p[2*T+g]<<16|p[3*T+g]<<24)>>>0;M=((M<<_|M>>>(32-_&31))^v)>>>0,v=M;let k=(y+g)*n+w;r[k]=M&255,r[k+1]=M>>>8&255,r[k+2]=M>>>16&255,r[k+3]=M>>>24}}else throw Me(`invalid ATTRIBUTES channel ${N}`)}f.set(r.subarray((y+T-1)*n,(y+T)*n)),y+=T}if(i-d!==c)throw Me("ATTRIBUTES trailing data")}var Ls=224,Ps=208;function Ds(e,t){let n=e[t.pos++]??0;if(n<128)return n;let r=n&127,i=7;for(let o=0;o<4;o++){let a=e[t.pos++]??0;if(r=(r|(a&127)<<i)>>>0,i+=7,a<128)break}return r>>>0}function Dr(e,t,n){let r=Ds(e,t),i=r>>>1^-(r&1);return n+i>>>0}function bc(e,t,n){if(t%3!==0)throw Me(`TRIANGLES count must be divisible by 3 (got ${t})`);let r=t/3;if(e.byteLength<1+r+16)throw Me("truncated TRIANGLES stream");let i=e[0];if((i&240)!==Ls)throw Me(`unsupported TRIANGLES header 0x${i.toString(16)}`);let o=i&15;if(o>1)throw Me(`unsupported TRIANGLES codec version ${o}`);let a=new Uint32Array(16).fill(4294967295),u=new Uint32Array(16).fill(4294967295),s=new Uint32Array(16).fill(4294967295),c=0,l=0,f=(P,N)=>{a[c]=P,u[c]=N,c=c+1&15},m=(P,N=1)=>{s[l]=P,l=l+N&15},h=0,p=0,d=o>=1?13:15,y=1+r,T=e.byteLength-16,S=T,b={pos:y},A=0,w=(P,N,I)=>{n(A++,P),n(A++,N),n(A++,I)};for(let P=1;P<y;P++){let N=e[P];if(N<240){let I=N>>4,_=c-1-I&15,v=a[_],g=u[_],M=0,k=N&15;if(k<d){let R=s[l-1-k&15];M=k===0?h:R;let B=k===0?1:0;h=h+B>>>0,m(M,B)}else{if(b.pos>T)throw Me("truncated TRIANGLES stream");M=k!==15?p+(k*2-27)>>>0:Dr(e,b,p),p=M,m(M)}f(M,g),f(v,M),w(v,g,M)}else if(N<254){let I=e[S+(N&15)],_=I>>4,v=I&15,g=h;h=h+1>>>0;let M=s[l-_&15],k=_===0?h:M,R=_===0?1:0;h=h+R>>>0;let B=s[l-v&15],Z=v===0?h:B,j=v===0?1:0;h=h+j>>>0,w(g,k,Z),m(g),m(k,R),m(Z,j),f(k,g),f(Z,k),f(g,Z)}else{if(b.pos>T)throw Me("truncated TRIANGLES stream");let I=e[b.pos++],_=N===254?0:15,v=I>>4,g=I&15;I===0&&(h=0);let M=0;_===0&&(M=h,h=h+1>>>0);let k;v===0?(k=h,h=h+1>>>0):k=s[l-v&15];let R;g===0?(R=h,h=h+1>>>0):R=s[l-g&15],_===15&&(p=M=Dr(e,b,p)),v===15&&(p=k=Dr(e,b,p)),g===15&&(p=R=Dr(e,b,p)),w(M,k,R),m(M),m(k,v===0||v===15?1:0),m(R,g===0||g===15?1:0),f(k,M),f(R,k),f(M,R)}}if(b.pos!==T)throw Me("TRIANGLES trailing data")}function yc(e,t,n){if(e.byteLength<1+t+4)throw Me("truncated INDICES stream");let r=e[0];if((r&240)!==Ps)throw Me(`unsupported INDICES header 0x${r.toString(16)}`);let i=r&15;if(i>1)throw Me(`unsupported INDICES codec version ${i}`);let o=e.byteLength-4,a=[0,0],u={pos:1};for(let s=0;s<t;s++){if(u.pos>=o)throw Me("truncated INDICES stream");let c=Ds(e,u),l=c&1;c>>>=1;let f=c>>>1^-(c&1),m=a[l]+f>>>0;a[l]=m,n(s,m)}if(u.pos!==o)throw Me("INDICES trailing data")}function Oi(e,t,n,r,i="NONE"){if(Rs(i),!Number.isInteger(t)||t<0||t>sc||!Number.isInteger(n)||n<=0||n>256)throw Me(`invalid count (${t}) or byteStride (${n})`);let o=t*n;if(o>As)throw Me(`decompressed size (${o}) exceeds MAX_MESHOPT_BUFFER_BYTES (${As})`);if(t===0)return new Uint8Array(0);let a=new Uint8Array(o);if(r==="ATTRIBUTES")return pc(e,t,n,a),Ui(a,t,n,i),a;if(r==="TRIANGLES"||r==="INDICES"){if(n!==2&&n!==4)throw Me(`${r} byteStride must be 2 or 4 (got ${n})`);if(i&&i!=="NONE")throw Me(`filter ${i} is only valid for ATTRIBUTES`);let u=new DataView(a.buffer),s=n===2?(c,l)=>u.setUint16(c*2,l&65535,!0):(c,l)=>u.setUint32(c*4,l>>>0,!0);return r==="TRIANGLES"?bc(e,t,s):yc(e,t,s),a}throw Me(`unknown mode "${String(r)}"`)}function Es(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Ns(e,t,n,r){let i=t*n;if(e.byteLength<i)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${i})`);if(r==="ATTRIBUTES"){if(n%4!==0||n>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let u=[_s],s=Cs(n),c=new Uint8Array(n);t>0&&c.set(e.subarray(0,n));let l=c.slice(),f=new Uint8Array(256);for(let m=0;m<t;){let h=Math.min(s,t-m),p=h+15&-16;for(let d=0;d<n;d++){f.fill(0);let y=c[d];for(let b=0;b<h;b++){let A=e[(m+b)*n+d];f[b]=uc(A-y&255),y=A}c[d]=y;let T=p/16,S=u.length;for(let b=0;b<T+3>>2;b++)u.push(0);for(let b=0;b<T;b++){let A=f.subarray(b*16,b*16+16);if(!A.every(w=>w===0)){u[S+(b>>2)]|=3<<(b&3)*2;for(let w of A)u.push(w)}}}m+=h}for(let m=n;m<Is;m++)u.push(0);for(let m=0;m<n;m++)u.push(l[m]);return new Uint8Array(u)}if(n!==2&&n!==4)throw new Error(`encodeMeshoptBuffer: ${r} byteStride must be 2 or 4 (got ${n})`);let o=new DataView(e.buffer,e.byteOffset,e.byteLength),a=u=>n===2?o.getUint16(u*2,!0):o.getUint32(u*4,!0);if(r==="INDICES"){let u=[Ps|1],s=0;for(let c=0;c<t;c++){let l=a(c),f=l-s|0;s=l,Es(u,Ms(f)<<1>>>0)}return u.push(0,0,0,0),new Uint8Array(u)}if(r==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let u=t/3,s=[Ls|1];for(let l=0;l<u;l++)s.push(255);let c=0;for(let l=0;l<u;l++){s.push(255);for(let f=0;f<3;f++){let m=a(l*3+f);Es(s,Ms(m-c|0)),c=m}}for(let l=0;l<16;l++)s.push(0);return new Uint8Array(s)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(r)}"`)}function Nr(e,t){let n=t&&typeof t=="object"?t:e,r=t&&typeof t=="object"?e:n?.gltf;if(!r||!Array.isArray(r.bufferViews))return;let i=new Uint8Array(n.bin),o=[],a=0;for(let f=0;f<r.bufferViews.length;f++){let m=r.bufferViews[f],h=m?.extensions?.KHR_meshopt_compression,p=h??m?.extensions?.EXT_meshopt_compression;if(!p||typeof p!="object")continue;let d=h?"KHR_meshopt_compression":"EXT_meshopt_compression",y=Number(p.count),T=Number(p.byteStride),S=Number(p.byteOffset??0),b=Number(p.byteLength??0),A=p.mode||"ATTRIBUTES",w=p.filter||"NONE";if(w==="COLOR"&&!h)throw Me(`bufferView ${f} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(p.buffer??0)!==0)throw new Error(`${d}: bufferView ${f} references buffer ${String(p.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(S)||S<0||!Number.isInteger(b)||b<0||S+b>i.byteLength)throw new Error(`${d}: bufferView ${f} compressed range [${S}, ${S+b}] out of bounds (${i.byteLength})`);let P=y*T;if(a+=P,a>ws)throw Me(`total decompressed size (${a}) exceeds MAX_MESHOPT_TOTAL_BYTES (${ws})`);let N=i.subarray(S,S+b),I=Oi(N,y,T,A,w);o.push({index:f,bytes:I,ext:p})}if(o.length===0)return;let u=i.byteLength+3&-4,s=0;for(let f of o)s+=f.bytes.byteLength+3&-4;let c=new Uint8Array(u+s);c.set(i,0);let l=u;for(let f of o){c.set(f.bytes,l);let m=r.bufferViews[f.index];m.buffer=0,m.byteOffset=l,m.byteLength=f.bytes.byteLength,m._decoded=f.bytes,f.ext.mode==="ATTRIBUTES"&&m.byteStride===void 0&&(m.byteStride=Number(f.ext.byteStride)),m.extensions&&(delete m.extensions.EXT_meshopt_compression,delete m.extensions.KHR_meshopt_compression),l+=f.bytes.byteLength+3&-4}n.bin=c.buffer}var kr={decodeBufferViews(e,t){Nr(t)},decodePrimitive(e,t,n){let r=t?.extensions;r?.EXT_meshopt_compression&&delete r.EXT_meshopt_compression,r?.KHR_meshopt_compression&&delete r.KHR_meshopt_compression}};ge().decoders.set("meshopt",kr);var Vi={name:"meshopt",onParseGLB(e){ge().decoders.set("meshopt",kr),Nr(e)}};var gc=`#version 300 es
|
|
371
|
+
layout(location=0) in vec3 aPosition;
|
|
372
|
+
layout(location=1) in vec3 aNormal;
|
|
373
|
+
uniform mat4 uMVP,uVP;
|
|
374
|
+
uniform mat3 uNormalMatrix;
|
|
375
|
+
uniform vec2 uViewportSize;
|
|
376
|
+
uniform float uOutlineThickness;
|
|
377
|
+
void main(){
|
|
378
|
+
vec4 clipPos=uMVP*vec4(aPosition,1.0);
|
|
379
|
+
vec3 nPart=length(aNormal)>1e-5?normalize(aNormal):vec3(0.0);
|
|
380
|
+
vec3 pPart=length(aPosition)>1e-5?normalize(aPosition)*0.65:vec3(0.0);
|
|
381
|
+
vec3 rawN=nPart+pPart;
|
|
382
|
+
vec3 worldN=uNormalMatrix*(length(rawN)>1e-5?normalize(rawN):vec3(0.0,1.0,0.0));
|
|
383
|
+
float nLen=length(worldN);
|
|
384
|
+
vec3 n=nLen>1e-5?(worldN/nLen):vec3(0.0,1.0,0.0);
|
|
385
|
+
vec4 clipN=uVP*vec4(n,0.0);
|
|
386
|
+
vec2 dir=length(clipN.xy)>1e-5?normalize(clipN.xy):vec2(0.0);
|
|
387
|
+
vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w;
|
|
388
|
+
clipPos.xy+=pxOffset;
|
|
389
|
+
clipPos.z+=1e-4*clipPos.w;
|
|
390
|
+
gl_Position=clipPos;
|
|
391
|
+
}`,xc=`#version 300 es
|
|
392
|
+
precision highp float;
|
|
393
|
+
uniform vec4 uOutlineColor;
|
|
394
|
+
out vec4 fragColor;
|
|
395
|
+
void main(){
|
|
396
|
+
fragColor=uOutlineColor;
|
|
397
|
+
}`,ks=`#version 300 es
|
|
398
|
+
out vec2 vUV;
|
|
399
|
+
void main(){
|
|
400
|
+
vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
|
|
401
|
+
vUV=pos;
|
|
402
|
+
gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
|
|
403
|
+
}`,vc=`#version 300 es
|
|
404
|
+
precision highp float;
|
|
405
|
+
in vec2 vUV;
|
|
406
|
+
uniform sampler2D uSourceTex;
|
|
407
|
+
uniform vec2 uTexelSize;
|
|
408
|
+
uniform float uThreshold;
|
|
409
|
+
out vec4 fragColor;
|
|
410
|
+
vec3 prefilter(vec3 c){
|
|
411
|
+
float br=max(c.r,max(c.g,c.b));
|
|
412
|
+
float knee=max(uThreshold*0.5,1e-4);
|
|
413
|
+
float soft=clamp(br-uThreshold+knee,0.0,2.0*knee);
|
|
414
|
+
soft=(soft*soft)/(4.0*knee+1e-4);
|
|
415
|
+
float contrib=max(soft,br-uThreshold)/max(br,1e-4);
|
|
416
|
+
return c*clamp(contrib,0.0,1.0);
|
|
417
|
+
}
|
|
418
|
+
void main(){
|
|
419
|
+
vec2 h=uTexelSize*0.5;
|
|
420
|
+
vec3 c=prefilter(texture(uSourceTex,vUV).rgb)*0.5;
|
|
421
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,-h.y)).rgb)*0.125;
|
|
422
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
|
|
423
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
|
|
424
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
|
|
425
|
+
fragColor=vec4(c,1.0);
|
|
426
|
+
}`,Tc=`#version 300 es
|
|
427
|
+
precision highp float;
|
|
428
|
+
in vec2 vUV;
|
|
429
|
+
uniform sampler2D uBloomTex;
|
|
430
|
+
uniform vec2 uTexelSize;
|
|
431
|
+
uniform float uRadius;
|
|
432
|
+
uniform float uStrength;
|
|
433
|
+
out vec4 fragColor;
|
|
434
|
+
void main(){
|
|
435
|
+
vec2 d=uTexelSize*max(0.25,uRadius*2.5);
|
|
436
|
+
vec3 sum=vec3(0.0);
|
|
437
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x*2.0,0.0)).rgb;
|
|
438
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x,d.y)).rgb*2.0;
|
|
439
|
+
sum+=texture(uBloomTex,vUV+vec2(0.0,d.y*2.0)).rgb;
|
|
440
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x,d.y)).rgb*2.0;
|
|
441
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x*2.0,0.0)).rgb;
|
|
442
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x,-d.y)).rgb*2.0;
|
|
443
|
+
sum+=texture(uBloomTex,vUV+vec2(0.0,-d.y*2.0)).rgb;
|
|
444
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
|
|
445
|
+
vec3 bloom=(sum/12.0)*uStrength;
|
|
446
|
+
float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
|
|
447
|
+
fragColor=vec4(bloom,a);
|
|
448
|
+
}`,Fr=3,Cn=new WeakMap;function zi(e,t=[.22,.74,.97]){let n=Hn(e,"");if(!n.startsWith("#"))return[t[0],t[1],t[2]];let r=n.slice(1);if(r.length===3){let i=+("0x"+r[0]+r[0])/255,o=+("0x"+r[1]+r[1])/255,a=+("0x"+r[2]+r[2])/255;return[i,o,a]}if(r.length===6){let i=+("0x"+r.slice(0,2))/255,o=+("0x"+r.slice(2,4))/255,a=+("0x"+r.slice(4,6))/255;return[i,o,a]}return[t[0],t[1],t[2]]}function Os(e,t,n=.8,r=.5){let i=Number.isFinite(t)?Math.max(0,t):0;if(i<=0)return[0,0,0];let o=Math.max(0,Number(e[0])||0),a=Math.max(0,Number(e[1])||0),u=Math.max(0,Number(e[2])||0),s=Math.max(o,a,u);if(s<=1e-6)return[0,0,0];let c=Number.isFinite(n)?Math.max(0,n):.8,l=Math.max(c*Math.max(0,r),1e-4),f=Math.max(0,Math.min(2*l,s-c+l)),m=f*f/(4*l+1e-4),p=Math.min(1,Math.max(0,Math.max(m,s-c)/Math.max(s,1e-4)))*i;return[o*p,a*p,u*p]}function Vs(e,t,n,r){let i=Number(e[0])||0,o=Number(e[1])||0,a=Math.hypot(i,o);if(a<=1e-5||t<=0||n<=0)return[0,0];let u=Math.max(1,Number(r[0])||1),s=Math.max(1,Number(r[1])||1),c=Math.max(0,n)*2*t;return[i/a*(c/u),o/a*(c/s)]}function Bi(e,t,n){let r=e.createProgram();if(!r)return null;let i=[];for(let[o,a]of[[35633,t],[35632,n]]){let u=e.createShader(o);u&&(e.shaderSource(u,a),e.compileShader(u),e.attachShader(r,u),i.push(u))}e.linkProgram(r);for(let o of i)e.detachShader?.(r,o),e.deleteShader?.(o);return i.length<2||typeof e.getProgramParameter=="function"&&!e.getProgramParameter(r,35714)?(e.deleteProgram?.(r),null):r}var Fs=new WeakSet;function Us(e){let t=Cn.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Cn.delete(e)}if(Fs.has(e)||e.isContextLost?.())return null;let n=Bi(e,gc,xc),r=Bi(e,ks,vc),i=Bi(e,ks,Tc);if(!n||!r||!i){for(let a of[n,r,i])a&&e.deleteProgram(a);return Fs.add(e),null}let o=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:n,uOutlineMVP:e.getUniformLocation(n,"uMVP"),uOutlineVP:e.getUniformLocation(n,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(n,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(n,"uViewportSize"),uOutlineThickness:e.getUniformLocation(n,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(n,"uOutlineColor"),downProg:r,uDownSourceTex:e.getUniformLocation(r,"uSourceTex"),uDownTexelSize:e.getUniformLocation(r,"uTexelSize"),uDownThreshold:e.getUniformLocation(r,"uThreshold"),upProg:i,uUpBloomTex:e.getUniformLocation(i,"uBloomTex"),uUpTexelSize:e.getUniformLocation(i,"uTexelSize"),uUpRadius:e.getUniformLocation(i,"uRadius"),uUpStrength:e.getUniformLocation(i,"uStrength"),fsVao:o,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Cn.set(e,t),t}function Ac(e,t,n,r){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let i=Math.max(2,n|0),o=Math.max(2,r|0);if(t.sceneTex&&t.bloomFbo.length===Fr&&t.texWidth===i&&t.texHeight===o)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,i,o,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let a=i,u=o;for(let s=0;s<Fr;s++)a=Math.max(1,a>>1),u=Math.max(1,u>>1),t.mipWidth[s]=a,t.mipHeight[s]=u,t.bloomTex[s]||(t.bloomTex[s]=e.createTexture()),e.bindTexture(3553,t.bloomTex[s]),e.texImage2D(3553,0,6408,a,u,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[s]||(t.bloomFbo[s]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[s]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[s],0);return e.bindFramebuffer(36160,null),t.texWidth=i,t.texHeight=o,!0}function wc(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let r=t.getAttribute("bloom");if(r!==null){let i=r.trim().toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let o=i===""||i==="true"?.35:Number(i);if(!Number.isFinite(o)||o<=0)return null;let a=ii({strength:o,threshold:Jt(t.getAttribute("bloom-threshold"),.62),radius:Jt(t.getAttribute("bloom-radius"),.75)});if(a)return a}}let n=null;for(let r of e.meshes||[]){if(r.visible===!1)continue;let i=r?.extras?.xr?.bloom??r?.userData?.xr?.bloom,o=ii(i);o&&(!n||o.strength>n.strength)&&(n=o)}return n}function Mc(e,t){if(e==null)return null;let n=e.trim(),r=n.toLowerCase();if(r==="false"||r==="0"||r==="none")return null;let i=t,o=3.5,a=!1;if(n&&r!=="true"){let u=n.split(/\s+/);for(let s of u)if(s.startsWith("#"))i=s;else if(s.toLowerCase()==="pulse")a=!0;else{let c=Number(s);Number.isFinite(c)&&c>0&&(o=c)}}return Xn({color:i,thickness:o,pulse:a})}var Sc=new Set(["floor","pedestal","ground","table","grid","pad"]);function Ec(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Sc.has(t))}function Rc(e,t){let n=e.container,r=typeof n?.getAttribute=="function"?n.getAttribute("outline"):null;if(r!=null){let l=r.trim().toLowerCase();if(l==="false"||l==="0"||l==="none")return null}let i=t?.extras?.xr?.outline??t?.userData?.xr?.outline,o=Xn(i);if(o)return o;let a=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",u=Mc(r,a),s=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",c=e.getSelectedMesh?.()||"";if(c)return t.name!==c?null:u||(s?Xn({color:a,thickness:3,pulse:!1}):null);if(u){let l=t.name||"";return Ec(l)?null:u}return null}var Gi={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,n){if(!t.meshes||t.meshes.length===0)return;let r=Math.max(1,t.canvas?.width||300),i=Math.max(1,t.canvas?.height||150),o=[];for(let m of t.meshes){if(m.visible===!1)continue;let h=Rc(t,m);h&&o.push({mesh:m,trait:h})}let a=o.length>0?Us(e):null;if(a){let m=a,h=Te(),p=Te(),d=new Float32Array(9),y=(typeof performance<"u"?performance.now():Date.now())*.001,T=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,S=Math.max(1,T?.[2]||r),b=Math.max(1,T?.[3]||i);e.useProgram(m.outlineProg),m.uOutlineViewportSize&&e.uniform2f(m.uOutlineViewportSize,S,b),m.uOutlineVP&&e.uniformMatrix4fv(m.uOutlineVP,!1,n),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:A,trait:w}of o){let[P,N,I]=zi(w.color),_=w.pulse?.8+.25*Math.sin(y*4):1;m.uOutlineColor&&e.uniform4f(m.uOutlineColor,P,N,I,1),m.uOutlineThickness&&e.uniform1f(m.uOutlineThickness,w.thickness*_),A.worldSpace===!0?h.set(A.transform):Re(h,t.modelRootMatrix,A.transform);let v=A.instanceMatrices;for(let g of A.primitives)if(!(g.pluginData?.skinning?.hasSkin||g.pluginData?.morph?.hasMorph))if(e.bindVertexArray(g.vao),v&&v.length>=16){let M=v.length>>4,k=Te();for(let R=0;R<M;R++)Re(k,h,v.subarray(R*16,R*16+16)),Re(p,n,k),De(d,k),e.uniformMatrix4fv(m.uOutlineMVP,!1,p),e.uniformMatrix3fv(m.uOutlineNormalMatrix,!1,d),g.indices?e.drawElements(4,g.indexCount,g.indexType,0):e.drawArrays(4,0,g.indexCount)}else Re(p,n,h),De(d,h),e.uniformMatrix4fv(m.uOutlineMVP,!1,p),e.uniformMatrix3fv(m.uOutlineNormalMatrix,!1,d),g.indices?e.drawElements(4,g.indexCount,g.indexType,0):e.drawArrays(4,0,g.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let u=wc(t);if(!u||u.strength<=0)return;let s=Us(e);if(!s||!Ac(e,s,r,i)||!s.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,s.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,r,i),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(s.downProg),e.uniform1i(s.uDownSourceTex,0),e.bindVertexArray(s.fsVao);let c=s.sceneTex,l=r,f=i;for(let m=0;m<Fr;m++){let h=s.mipWidth[m],p=s.mipHeight[m];e.bindFramebuffer(36160,s.bloomFbo[m]),e.viewport(0,0,h,p),e.bindTexture(3553,c),e.uniform2f(s.uDownTexelSize,1/l,1/f),e.uniform1f(s.uDownThreshold,m===0?u.threshold:0),e.drawArrays(4,0,3),c=s.bloomTex[m],l=h,f=p}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(s.upProg),e.uniform1i(s.uUpBloomTex,0),e.uniform1f(s.uUpRadius,u.radius);for(let m=Fr-1;m>=1;m--){let h=m-1;e.bindFramebuffer(36160,s.bloomFbo[h]),e.viewport(0,0,s.mipWidth[h],s.mipHeight[h]),e.bindTexture(3553,s.bloomTex[m]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[m],1/s.mipHeight[m]),e.uniform1f(s.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,r,i),e.bindTexture(3553,s.bloomTex[0]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[0],1/s.mipHeight[0]),e.uniform1f(s.uUpStrength,u.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Cn.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let n of t.bloomTex)n&&e.deleteTexture(n);for(let n of t.bloomFbo)n&&e.deleteFramebuffer(n);Cn.delete(e)}}};function Hi(e){let n=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(n))return[];let r=[];for(let i=0;i<n.length&&r.length<256;i++){let o=n[i]?.name;r.push(typeof o=="string"&&o.length>0?o:`Variant_${i}`)}return r}function Bs(e){let n=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(n))return[];let r=[];for(let i of n){if(!i||typeof i!="object")continue;let o=i,a=Number(o.material);if(!Number.isInteger(a)||a<0)continue;let u=[];if(Array.isArray(o.variants))for(let s of o.variants){let c=Number(s);Number.isInteger(c)&&c>=0&&u.push(c)}u.length>0&&r.push({material:a,variants:u})}return r}function zs(e,t,n,r=0){let i=e;if(i&&typeof i.selectVariant=="function"&&!Array.isArray(t))return i.selectVariant(typeof t=="string"?t:null);let o=e,a=Array.isArray(t)?t:[],u=n??null;if(!u)return r;let c=Hi(o).indexOf(u);if(c<0)return r;for(let l of a)if(l.variants.includes(c))return l.material;return r}var Xi={name:"variants",onLoadModel(e,t){let n=e.getVariantName?.();n&&e.selectVariant(n)}};var Gs=new WeakMap,Wi={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=e?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),t.domOverlay={root:r},r.addEventListener?.("beforexrselect",i=>{i.preventDefault()})),t.optionalFeatures=Array.from(n)},onXRFrame(e,t,n,r){if(!e||!t||!n||!r)return;let i=Gs.get(t);if(i||(i={lightProbe:null},Gs.set(t,i),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(o=>{i&&o&&(i.lightProbe=o)}).catch(()=>{})),i.lightProbe&&typeof n.getLightEstimate=="function"){let o=n.getLightEstimate(i.lightProbe);if(o){let a=o.primaryLightDirection,u=o.primaryLightIntensity;if(a&&u&&Array.isArray(e.lights)){let s=e.lights.find(l=>l.type==="directional");s||(s={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(s)),s.direction=[a.x,a.y,a.z];let c=Math.max(u.x,u.y,u.z,.001);s.color=[u.x/c,u.y/c,u.z/c],s.intensity=c}o.sphericalHarmonicsCoefficients&&e.gl&&Er(e.gl,o.sphericalHarmonicsCoefficients)}}}};Fe(En);Fe(Li);Fe(_i);Fe(Fi);Fe(Wi);Fe(ki);Fe(Vi);Fe(Xi);Fe(Gi);at.registerScriptRunner(Qt);typeof window<"u"&&(window.ThreeLiveBundle=$i);
|