three-live 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/three-author-engine.js +89 -62
- package/dist/three-author.cjs +86 -59
- package/dist/three-author.d.ts +1 -0
- package/dist/three-author.js +86 -59
- package/dist/three-convert.cjs +79 -52
- package/dist/three-convert.d.ts +1 -0
- package/dist/three-convert.js +80 -53
- package/dist/three-live-animation.d.ts +1 -0
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +1 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +2 -2
- package/dist/three-live-element.d.ts +1 -0
- package/dist/three-live-element.js +2 -2
- package/dist/three-live-full.cjs +94 -67
- package/dist/three-live-full.js +102 -75
- package/dist/three-live-full.min.js +95 -68
- package/dist/three-live-studio.d.ts +1 -0
- package/dist/three-live-viewer.cjs +2 -2
- package/dist/three-live-viewer.d.ts +1 -0
- package/dist/three-live-viewer.js +2 -2
- package/dist/three-live-viewer.min.js +2 -2
- package/dist/three-live.cjs +85 -58
- package/dist/three-live.js +85 -58
- package/dist/three-live.min.js +85 -58
- package/dist/three-view.d.ts +1 -0
- package/dist/three-xr.cjs +80 -53
- package/dist/three-xr.d.ts +1 -0
- package/dist/three-xr.js +83 -56
- package/package.json +19 -1
package/dist/three-author.cjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var Sn=Object.defineProperty,zr=Object.getOwnPropertyDescriptor,Gr=Object.getOwnPropertyNames,Hr=Object.prototype.hasOwnProperty,Xr=(e,t)=>{for(var i in t)Sn(e,i,{get:t[i],enumerable:!0})},$r=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gr(t))!Hr.call(e,s)&&s!==i&&Sn(e,s,{get:()=>t[s],enumerable:!(r=zr(t,s))||r.enumerable});return e},jr=e=>$r(Sn({},"__esModule",{value:!0}),e),Ii={};Xr(Ii,{AmbientLight:()=>mt,BoxGeometry:()=>ot,BufferAttribute:()=>be,BufferGeometry:()=>me,Camera:()=>ft,CapsuleGeometry:()=>mn,CatmullRomCurve3:()=>jt,CircleGeometry:()=>hn,Clock:()=>sn,Color:()=>Te,ConeGeometry:()=>Vt,CubicBezierCurve3:()=>$t,Curve3:()=>Ie,CylinderGeometry:()=>at,DataTexture:()=>Kt,DirectionalLight:()=>tn,DodecahedronGeometry:()=>ln,EdgesGeometry:()=>pn,Euler:()=>it,Float32BufferAttribute:()=>Ft,Group:()=>en,HemisphereLight:()=>yt,IcosahedronGeometry:()=>un,InstancedMesh:()=>lt,LatheGeometry:()=>ct,Light:()=>ze,Line:()=>ke,LineBasicMaterial:()=>Ye,LineCurve3:()=>Ht,LineDashedMaterial:()=>fn,LineLoop:()=>bn,LineSegments:()=>gn,MAX_INSTANCES_PER_MESH:()=>ut,Material:()=>Me,MathUtils:()=>Sr,Matrix3:()=>Pt,Matrix4:()=>Fe,Mesh:()=>Re,MeshBasicMaterial:()=>qt,MeshLambertMaterial:()=>Zt,MeshPhongMaterial:()=>Jt,MeshPhysicalMaterial:()=>Qt,MeshStandardMaterial:()=>Ve,Object3D:()=>_e,OctahedronGeometry:()=>cn,PerspectiveCamera:()=>nn,PlaneGeometry:()=>Ot,PointLight:()=>ht,Points:()=>yn,PointsMaterial:()=>gt,PolyhedronFallbackGeometry:()=>Ai,PolyhedronGeometry:()=>Ne,QuadraticBezierCurve3:()=>Xt,Quaternion:()=>st,RawShaderMaterial:()=>kr,RectAreaLight:()=>Br,RingGeometry:()=>bt,Scene:()=>dt,SceneQuotaValidator:()=>Ee,ShaderMaterial:()=>pt,SphereGeometry:()=>Bt,SpotLight:()=>xn,THREE:()=>He,TetrahedronGeometry:()=>an,Texture:()=>We,TextureLoader:()=>Yt,TorusGeometry:()=>zt,TorusKnotGeometry:()=>Gt,TubeGeometry:()=>Wt,Uint16BufferAttribute:()=>kt,Uint32BufferAttribute:()=>Ut,Vector2:()=>Se,Vector3:()=>Z,Vector4:()=>Lt,WebGLRenderer:()=>rn,WireframeGeometry:()=>dn,authorScriptRunner:()=>Lr,buildSandboxWorkerSource:()=>Vn,clearAuthorWarnings:()=>Fr,default:()=>Di,exportSceneToCanvas3D:()=>kn,exportSceneToGLB:()=>Un,exportSceneToUSDZ:()=>Ar,generateUSDZ:()=>Pn,getAllowClientScripts:()=>Cr,getAuthorWarnings:()=>Pr,getSandboxEngineSrc:()=>On,getSandboxIframeSrc:()=>Rr,glbToUSDZ:()=>Rt,isAllowedSandboxEngineUrl:()=>Ke,noopProxy:()=>nt,sceneToCanvas3D:()=>je,sceneToGLB:()=>Qe,sceneToUSDZ:()=>et,setAllowClientScripts:()=>gi,setSandboxEngineSrc:()=>fi,setSandboxIframeSrc:()=>pi,threeAuthorPlugin:()=>rt,threeMicroPlugin:()=>Ci,toTrustedWorkerScriptURL:()=>Er,validateSandboxWorkerMessage:()=>zn,warnUnsupported:()=>Ge}),module.exports=jr(Ii);function Gn(e,t,i){let r=[],s=new Map,n=[],o=[],a=[],h=new Map,l=m=>{let p=s.get(m);return p===void 0&&(p=r.length,r.push({op:m}),s.set(m,p)),p},c=m=>{let p=h.get(m);return p===void 0&&(p=a.length,a.push({id:m}),h.set(m,p)),p},f=(m,p={})=>n.push({declaration:l(m),...p})-1,y=(m,p,v)=>o.push({id:m,type:p,value:v})-1,g=m=>({node:m,socket:"value"}),u=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(u&&typeof u=="object"){let m=Array.isArray(u.graphs)?u.graphs[u.graph??0]:u;if(m&&Array.isArray(m.nodes)){let p=Array.isArray(m.declarations)?m.declarations:[];for(let v of p)v?.op&&l(v.op);Array.isArray(m.variables)&&o.push(...m.variables);for(let v of m.events||[])v?.id&&c(v.id);for(let v of m.nodes){if(!v||typeof v!="object")continue;let R=v.op||(typeof v.declaration=="number"?p[v.declaration]?.op:"");n.push(R?{...v,declaration:l(R)}:{...v})}}}let b=(m,p,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,p)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,p)}/${v}`:v==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${v}`,w=new Map;e.forEach((m,p)=>{typeof m?.name=="string"&&!w.has(m.name)&&w.set(m.name,p)});let M=(m,p)=>typeof m.target=="string"&&w.has(m.target)?w.get(m.target):typeof m.targetNode=="number"?m.targetNode:p,x=m=>{let p=e[m];return(typeof p?.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<e.length;m++){let p=e[m],v=p?.extras?.interactivity;if(!v||typeof v!="object")continue;let R=(typeof p.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0,L=N=>{let _=Array.isArray(N)?N:[N],A=[];for(let C=0;C<_.length;C++){let d=_[C];if(!d||typeof d!="object")continue;let k=d.action||"interpolate",$=typeof d.duration=="number"?d.duration:.35;if(k==="toggleTransform"){let S=d.property==="rotation"||d.property==="scale"?d.property:"translation",D=S==="rotation"?p.rotation||[0,0,0,1]:S==="scale"?p.scale||[1,1,1]:p.translation||[0,0,0],T=`/nodes/${m}/${S}`,P=y(`__toggle_${m}_${C}`,"bool",!1),j=f("variable/get",{configuration:{variable:P}}),W=f("math/not",{values:{a:g(j)}}),O=f("variable/set",{configuration:{variable:P},values:{value:g(W)}}),Y=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.to)?d.to:D},duration:{value:$}}}),U=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.from)?d.from:D},duration:{value:$}}});n[O].flows={out:{node:f("flow/branch",{values:{condition:g(j)},flows:{true:{node:Y},false:{node:U}}})}},A.push(O)}else if(k==="interpolate"){let S=d.to??d.value;if(S===void 0)continue;let D={value:{value:S},duration:{value:$}};d.from!==void 0&&(D.from={value:d.from}),A.push(f("pointer/interpolate",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:D}))}else if(k==="setProperty"){if(d.value===void 0)continue;A.push(f("pointer/set",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:{value:{value:d.value}}}))}else if(k==="toggleVisibility"){let S=M(d,m),D=y(`__vis_${S}_${C}`,"bool",!0),T=f("variable/get",{configuration:{variable:D}}),P=f("math/not",{values:{a:g(T)}}),j=f("variable/set",{configuration:{variable:D},values:{value:g(P)}});n[j].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${S}/extensions/KHR_node_visibility/visible`},values:{value:g(T)}})}},A.push(j)}else if(k==="cycleMaterialColor"&&Array.isArray(d.colors)&&d.colors.length>0){let S=typeof d.duration=="number"?d.duration:.25,D=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,T=y(`__color_idx_${m}_${C}`,"int",0),P=f("variable/get",{configuration:{variable:T}}),j=f("math/add",{values:{a:g(P),b:{value:1}}}),W=f("math/rem",{values:{a:g(j),b:{value:d.colors.length}}}),O=f("variable/set",{configuration:{variable:T},values:{value:g(W)}}),Y={};for(let U=0;U<d.colors.length;U++){let X=d.colors[U],V=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];Y[String(U)]={node:S>0?f("pointer/interpolate",{configuration:{pointer:D},values:{value:{value:V},duration:{value:S}}}):f("pointer/set",{configuration:{pointer:D},values:{value:{value:V}}})}}n[O].flows={out:{node:f("flow/switch",{values:{selection:g(P)},flows:Y})}},A.push(O)}else if(k==="playAnimation")A.push(f("animation/start",{configuration:{animation:d.animation??d.clip??0}}));else if(k==="stopAnimation")A.push(f("animation/stop"));else if(k==="sendEvent"){let S={};for(let[D,T]of Object.entries(d.values||{}))S[D]={value:T};A.push(f("event/send",{configuration:{event:c(String(d.event??d.id??"custom"))},values:S}))}}if(!A.length)return null;if(A.length===1)return A[0];let E={};return A.forEach((C,d)=>{E[String(d)]={node:C}}),f("flow/sequence",{flows:E})},I=(N,_,A)=>{let E=L(_);E!==null&&f(N,{...A?{configuration:A}:{},flows:{out:{node:E}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:m}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:m}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:m}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[N,_]of Object.entries(v.onReceive))I("event/receive",_,{event:c(N)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:o,events:a}],graph:0}:null}var Hn='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).',Xn="Security Error: client-side scripts require allow-client-scripts opt-in.",vt="__THREE_LIVE_REGISTRY__";function ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[vt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,vt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[vt]=t}}return e[vt]}var he=ae().plugins;function $n(e){let t=ae().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function jn(){return ae().plugins}function ce(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Mt(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let o=1/(r-s);return e[10]=(s+r)*o,e[14]=2*s*r*o,e}function Xe(e,t,i,r){let[s,n,o]=t,[a,h,l]=r,[c,f,y]=i,g=s-c,u=n-f,b=o-y,w=Math.hypot(g,u,b);w<=1e-5?(g=0,u=0,b=1):(g/=w,u/=w,b/=w);let M=h*b-l*u,x=l*g-a*b,m=a*u-h*g;w=Math.hypot(M,x,m),w<=1e-5?(M=0,x=0,m=0):(M/=w,x/=w,m/=w);let p=u*m-b*x,v=b*M-g*m,R=g*x-u*M;return w=Math.hypot(p,v,R),w<=1e-5?(p=0,v=0,R=0):(p/=w,v/=w,R/=w),e[0]=M,e[1]=p,e[2]=g,e[3]=0,e[4]=x,e[5]=v,e[6]=u,e[7]=0,e[8]=m,e[9]=R,e[10]=b,e[11]=0,e[12]=-(M*s+x*n+m*o),e[13]=-(p*s+v*n+R*o),e[14]=-(g*s+u*n+b*o),e[15]=1,e}function de(e,t,i){let r=t[0],s=t[1],n=t[2],o=t[3],a=t[4],h=t[5],l=t[6],c=t[7],f=t[8],y=t[9],g=t[10],u=t[11],b=t[12],w=t[13],M=t[14],x=t[15],m=i[0],p=i[1],v=i[2],R=i[3];return e[0]=m*r+p*a+v*f+R*b,e[1]=m*s+p*h+v*y+R*w,e[2]=m*n+p*l+v*g+R*M,e[3]=m*o+p*c+v*u+R*x,m=i[4],p=i[5],v=i[6],R=i[7],e[4]=m*r+p*a+v*f+R*b,e[5]=m*s+p*h+v*y+R*w,e[6]=m*n+p*l+v*g+R*M,e[7]=m*o+p*c+v*u+R*x,m=i[8],p=i[9],v=i[10],R=i[11],e[8]=m*r+p*a+v*f+R*b,e[9]=m*s+p*h+v*y+R*w,e[10]=m*n+p*l+v*g+R*M,e[11]=m*o+p*c+v*u+R*x,m=i[12],p=i[13],v=i[14],R=i[15],e[12]=m*r+p*a+v*f+R*b,e[13]=m*s+p*h+v*y+R*w,e[14]=m*n+p*l+v*g+R*M,e[15]=m*o+p*c+v*u+R*x,e}function qe(e,t,i,r){let s=t[0],n=t[1],o=t[2],a=t[3],h=s+s,l=n+n,c=o+o,f=s*h,y=s*l,g=s*c,u=n*l,b=n*c,w=o*c,M=a*h,x=a*l,m=a*c,p=r[0],v=r[1],R=r[2];return e[0]=(1-(u+w))*p,e[1]=(y+m)*p,e[2]=(g-x)*p,e[3]=0,e[4]=(y-m)*v,e[5]=(1-(f+w))*v,e[6]=(b+M)*v,e[7]=0,e[8]=(g+x)*R,e[9]=(b-M)*R,e[10]=(1-(f+u))*R,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Ae(e,t,i=0){let r=t[0],s=t[1],n=t[2],o=t[4],a=t[5],h=t[6],l=t[8],c=t[9],f=t[10],y=f*a-h*c,g=-f*o+h*l,u=c*o-a*l,b=r*y+s*g+n*u;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=y*b,e[1]=g*b,e[2]=u*b,e[3]=(-f*s+n*c)*b,e[4]=(f*r-n*l)*b,e[5]=(-c*r+s*l)*b,e[6]=(h*s-n*a)*b,e[7]=(-h*r+n*o)*b,e[8]=(a*r-s*o)*b),e}function Wn(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],f=t[9],y=t[10],g=t[11],u=t[12],b=t[13],w=t[14],M=t[15],x=i*a-r*o,m=i*h-s*o,p=i*l-n*o,v=r*h-s*a,R=r*l-n*a,L=s*l-n*h,I=c*b-f*u,N=c*w-y*u,_=c*M-g*u,A=f*w-y*b,E=f*M-g*b,C=y*M-g*w,d=x*C-m*E+p*A+v*_-R*N+L*I;return d?(d=1/d,e[0]=(a*C-h*E+l*A)*d,e[1]=(s*E-r*C-n*A)*d,e[2]=(b*L-w*R+M*v)*d,e[3]=(y*R-f*L-g*v)*d,e[4]=(h*_-o*C-l*N)*d,e[5]=(i*C-s*_+n*N)*d,e[6]=(w*p-u*L-M*m)*d,e[7]=(c*L-y*p+g*m)*d,e[8]=(o*E-a*_+l*I)*d,e[9]=(r*_-i*E-n*I)*d,e[10]=(u*R-b*p+M*x)*d,e[11]=(f*p-c*R-g*x)*d,e[12]=(a*N-o*A-h*I)*d,e[13]=(i*A-r*N+s*I)*d,e[14]=(b*m-u*v-w*x)*d,e[15]=(c*v-f*m+y*x)*d,e):null}function Tn(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],o=s[1]*t+s[5]*i+s[9]*r+s[13],a=s[2]*t+s[6]*i+s[10]*r+s[14],h=s[3]*t+s[7]*i+s[11]*r+s[15],l=h!==0?1/h:1;e[0]=n*l,e[1]=o*l,e[2]=a*l}function Kn(e,t,i,r,s,n,o,a,h,l,c,f,y,g,u,b,w=0){let M=l-o,x=c-a,m=f-h,p=y-o,v=g-a,R=u-h,L=s*R-n*v,I=n*p-r*R,N=r*v-s*p,_=M*L+x*I+m*N;if(_>-1e-7&&_<1e-7)return!1;let A=1/_,E=e-o,C=t-a,d=i-h,k=A*(E*L+C*I+d*N);if(k<-w||k>1+w)return!1;let $=C*m-d*x,S=d*M-E*m,D=E*x-C*M,T=A*(r*$+s*S+n*D);if(T<-w||k+T>1+w)return!1;let P=A*(p*$+v*S+R*D);if(P>1e-4&&P<b.distance){b.distance=P,b.point=[e+r*P,t+s*P,i+n*P];let j=x*R-m*v,W=m*p-M*R,O=M*v-x*p,Y=Math.hypot(j,W,O)||1;return b.normal=[j/Y,W/Y,O/Y],!0}return!1}function Yn(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let c=0;c<i;c++)r.push(ce());if(i===0)return r;let s=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let f of c.children)s.add(f);let n=new Set,o=128,a=(c,f,y=0)=>{if(y>o||c<0||c>=i||n.has(c))return;n.add(c);let g=e.nodes[c];if(!g)return;let u=ce();if(t&&t[c])u.set(t[c]);else if(g.matrix&&g.matrix.length===16)u.set(g.matrix);else{let w=g.translation||[0,0,0],M=g.rotation||[0,0,0,1],x=g.scale||[1,1,1];qe(u,M,w,x)}let b=r[c];if(f?de(b,f,u):b.set(u),Array.isArray(g.children))for(let w of g.children)typeof w=="number"&&a(w,b,y+1)},h=[],l=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(l&&Array.isArray(l.nodes))h.push(...l.nodes);else for(let c=0;c<i;c++)s.has(c)||h.push(c);for(let c of h)a(c,null);for(let c=0;c<i;c++)!s.has(c)&&!h.includes(c)&&a(c,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function _n(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let o=i.componentType??5126,a=Wr[o];if(!a)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let h=a*r,l=s.byteStride&&s.byteStride>0?s.byteStride:h,c=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(c)||c<0||l<h||c+(n-1)*l+h>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(o===5126&&l===h&&c%4===0)return new Float32Array(t,c,n*r);let f=new DataView(t),y=i.normalized===!0,g=new Float32Array(n*r);for(let u=0;u<n;u++){let b=c+u*l;for(let w=0;w<r;w++){let M=b+w*a,x;switch(o){case 5126:x=f.getFloat32(M,!0);break;case 5120:x=f.getInt8(M),y&&(x=Math.max(x/127,-1));break;case 5121:x=f.getUint8(M),y&&(x/=255);break;case 5122:x=f.getInt16(M,!0),y&&(x=Math.max(x/32767,-1));break;case 5123:x=f.getUint16(M,!0),y&&(x/=65535);break;default:x=f.getUint32(M,!0),y&&(x/=4294967295)}g[u*r+w]=x}}return g}function qn(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),o=Number(t.rotation??0)||0,a=Math.cos(o),h=Math.sin(o),l=(Number.isFinite(s)?s:1)*a,c=(Number.isFinite(s)?s:1)*h,f=-(Number.isFinite(n)?n:1)*h,y=(Number.isFinite(n)?n:1)*a;for(let g=0;g+1<e.length;g+=2){let u=e[g],b=e[g+1];e[g]=l*u+c*b+i,e[g+1]=f*u+y*b+r}}function wt(e,t,i,r=!0){let s=[],n=null;try{for(let[o,a]of[[35633,t],[35632,i]]){let h=e.createShader(o);if(!h){if(r)throw new Error("Shader allocation failed");return null}if(s.push(h),e.shaderSource(h,a),e.compileShader(h),e.getShaderParameter&&!e.getShaderParameter(h,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(h)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let o of s)e.attachShader(n,o);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let o=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${o}`);return null}return n}finally{for(let o of s)n&&e.detachShader?.(n,o),e.deleteShader?.(o)}}var Qn=["neutral","reinhard","none","aces","agx"];function Rn(e){let t=String(e??"").trim().toLowerCase();return Qn.includes(t)?t:"neutral"}function Kr(e){return Qn.indexOf(Rn(e))}function Yr(e){return new TextDecoder().decode(e)}var er=ae().decoders;function qr(e,t){er.set(e.toLowerCase(),t)}function $e(e){return er.get(e.toLowerCase())}function tr(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let y=i.getUint8(0);throw y===123||y===32||y===10||y===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 s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),o=12,a=null,h=null;for(;o+8<=n&&o+8<=t.byteLength;){let y=i.getUint32(o,!0),g=i.getUint32(o+4,!0),u=o+8;if(u+y>t.byteLength)throw new Error(`Truncated GLB chunk: required ${u+y} bytes, buffer has ${t.byteLength}`);if(g===1313821514){let b=new Uint8Array(t,u,y),w=Yr(b);a=JSON.parse(w,(M,x)=>M==="__proto__"||M==="constructor"||M==="prototype"?void 0:x)}else g===5130562&&(h=t.slice(u,u+y));o=u+y}if(!a)throw new Error("Missing JSON chunk in GLB");let l=a.extensionsRequired||[];if(l.includes("KHR_draco_mesh_compression")&&!$e("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let y of["EXT_meshopt_compression","KHR_meshopt_compression"])if(l.includes(y)&&!$e("meshopt"))throw new Error(`Model requires ${y}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!$e("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=h||new ArrayBuffer(0),f={gltf:a,bin:c,animations:[]};for(let y of he)y.onParseGLB?.(f);return f}function Zr(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 Je(e){if(Zr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return tr(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var nr=`#version 300 es
|
|
16
|
+
*/var wn=Object.defineProperty,Vr=Object.getOwnPropertyDescriptor,zr=Object.getOwnPropertyNames,Gr=Object.prototype.hasOwnProperty,Hr=(e,t)=>{for(var i in t)wn(e,i,{get:t[i],enumerable:!0})},$r=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of zr(t))!Gr.call(e,s)&&s!==i&&wn(e,s,{get:()=>t[s],enumerable:!(r=Vr(t,s))||r.enumerable});return e},Xr=e=>$r(wn({},"__esModule",{value:!0}),e),Di={};Hr(Di,{AmbientLight:()=>ht,BoxGeometry:()=>at,BufferAttribute:()=>ge,BufferGeometry:()=>de,Camera:()=>dt,CapsuleGeometry:()=>dn,CatmullRomCurve3:()=>Yt,CircleGeometry:()=>pn,Clock:()=>cn,Color:()=>we,ConeGeometry:()=>Ht,CubicBezierCurve3:()=>Kt,Curve3:()=>Fe,CylinderGeometry:()=>ct,DataTexture:()=>Zt,DirectionalLight:()=>sn,DodecahedronGeometry:()=>fn,EdgesGeometry:()=>yn,Euler:()=>ot,Float32BufferAttribute:()=>Ot,Group:()=>rn,HemisphereLight:()=>xt,IcosahedronGeometry:()=>hn,InstancedMesh:()=>mt,LatheGeometry:()=>ut,Light:()=>Ge,Line:()=>Ve,LineBasicMaterial:()=>Je,LineCurve3:()=>Wt,LineDashedMaterial:()=>bn,LineLoop:()=>xn,LineSegments:()=>vn,MAX_INSTANCES_PER_MESH:()=>lt,Material:()=>Me,MathUtils:()=>Tr,Matrix3:()=>Ut,Matrix4:()=>Be,Mesh:()=>Ie,MeshBasicMaterial:()=>Qt,MeshLambertMaterial:()=>en,MeshPhongMaterial:()=>tn,MeshPhysicalMaterial:()=>nn,MeshStandardMaterial:()=>ze,Object3D:()=>Ae,OctahedronGeometry:()=>mn,PerspectiveCamera:()=>on,PlaneGeometry:()=>zt,PointLight:()=>ft,Points:()=>Mn,PointsMaterial:()=>yt,PolyhedronFallbackGeometry:()=>wi,PolyhedronGeometry:()=>ke,QuadraticBezierCurve3:()=>jt,Quaternion:()=>Ye,RawShaderMaterial:()=>Fr,RectAreaLight:()=>Or,RingGeometry:()=>gt,Scene:()=>pt,SceneQuotaValidator:()=>De,ShaderMaterial:()=>bt,SphereGeometry:()=>Gt,SpotLight:()=>Tn,THREE:()=>$e,TetrahedronGeometry:()=>ln,Texture:()=>qe,TextureLoader:()=>Jt,TorusGeometry:()=>$t,TorusKnotGeometry:()=>Xt,TubeGeometry:()=>qt,Uint16BufferAttribute:()=>Bt,Uint32BufferAttribute:()=>Vt,Vector2:()=>Se,Vector3:()=>ee,Vector4:()=>kt,WebGLRenderer:()=>an,WireframeGeometry:()=>gn,authorScriptRunner:()=>Nr,buildSandboxWorkerSource:()=>Bn,clearAuthorWarnings:()=>Pr,default:()=>Ci,exportSceneToCanvas3D:()=>Fn,exportSceneToGLB:()=>kn,exportSceneToUSDZ:()=>wr,generateUSDZ:()=>Ln,getAllowClientScripts:()=>Rr,getAuthorWarnings:()=>Lr,getSandboxEngineSrc:()=>Un,getSandboxIframeSrc:()=>Er,glbToUSDZ:()=>It,isAllowedSandboxEngineUrl:()=>Ze,noopProxy:()=>it,sceneToCanvas3D:()=>Ke,sceneToGLB:()=>tt,sceneToUSDZ:()=>nt,setAllowClientScripts:()=>bi,setSandboxEngineSrc:()=>hi,setSandboxIframeSrc:()=>di,threeAuthorPlugin:()=>st,threeMicroPlugin:()=>Ri,toTrustedWorkerScriptURL:()=>Ar,validateSandboxWorkerMessage:()=>Vn,warnUnsupported:()=>He}),module.exports=Xr(Di);function zn(e,t,i){let r=[],s=new Map,n=[],a=[],o=[],l=new Map,h=c=>{let m=s.get(c);return m===void 0&&(m=r.length,r.push({op:c}),s.set(c,m)),m},u=c=>{let m=l.get(c);return m===void 0&&(m=o.length,o.push({id:c}),l.set(c,m)),m},f=(c,m={})=>n.push({declaration:h(c),...m})-1,g=(c,m,v)=>a.push({id:c,type:m,value:v})-1,w=c=>({node:c,socket:"value"}),p=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let c=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(c&&Array.isArray(c.nodes)){let m=Array.isArray(c.declarations)?c.declarations:[];for(let v of m)v?.op&&h(v.op);Array.isArray(c.variables)&&a.push(...c.variables);for(let v of c.events||[])v?.id&&u(v.id);for(let v of c.nodes){if(!v||typeof v!="object")continue;let S=v.op||(typeof v.declaration=="number"?m[v.declaration]?.op:"");n.push(S?{...v,declaration:h(S)}:{...v})}}}let b=(c,m,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,m)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,m)}/${v}`:v==="visible"?`/nodes/${c}/extensions/KHR_node_visibility/visible`:`/nodes/${c}/${v}`,T=new Map;e.forEach((c,m)=>{typeof c?.name=="string"&&!T.has(c.name)&&T.set(c.name,m)});let x=(c,m)=>typeof c.target=="string"&&T.has(c.target)?T.get(c.target):typeof c.targetNode=="number"?c.targetNode:m,M=c=>{let m=e[c];return(typeof m?.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0};for(let c=0;c<e.length;c++){let m=e[c],v=m?.extras?.interactivity;if(!v||typeof v!="object")continue;let S=(typeof m.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0,D=P=>{let N=Array.isArray(P)?P:[P],C=[];for(let E=0;E<N.length;E++){let y=N[E];if(!y||typeof y!="object")continue;let F=y.action||"interpolate",z=typeof y.duration=="number"?y.duration:.35;if(F==="toggleTransform"){let A=y.property==="rotation"||y.property==="scale"?y.property:"translation",_=A==="rotation"?m.rotation||[0,0,0,1]:A==="scale"?m.scale||[1,1,1]:m.translation||[0,0,0],d=`/nodes/${c}/${A}`,R=g(`__toggle_${c}_${E}`,"bool",!1),G=f("variable/get",{configuration:{variable:R}}),H=f("math/not",{values:{a:w(G)}}),B=f("variable/set",{configuration:{variable:R},values:{value:w(H)}}),Z=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.to)?y.to:_},duration:{value:z}}}),k=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.from)?y.from:_},duration:{value:z}}});n[B].flows={out:{node:f("flow/branch",{values:{condition:w(G)},flows:{true:{node:Z},false:{node:k}}})}},C.push(B)}else if(F==="interpolate"){let A=y.to??y.value;if(A===void 0)continue;let _={value:{value:A},duration:{value:z}};y.from!==void 0&&(_.from={value:y.from}),C.push(f("pointer/interpolate",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:_}))}else if(F==="setProperty"){if(y.value===void 0)continue;C.push(f("pointer/set",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:{value:{value:y.value}}}))}else if(F==="toggleVisibility"){let A=x(y,c),_=g(`__vis_${A}_${E}`,"bool",!0),d=f("variable/get",{configuration:{variable:_}}),R=f("math/not",{values:{a:w(d)}}),G=f("variable/set",{configuration:{variable:_},values:{value:w(R)}});n[G].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:w(d)}})}},C.push(G)}else if(F==="cycleMaterialColor"&&Array.isArray(y.colors)&&y.colors.length>0){let A=typeof y.duration=="number"?y.duration:.25,_=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,d=g(`__color_idx_${c}_${E}`,"int",0),R=f("variable/get",{configuration:{variable:d}}),G=f("math/add",{values:{a:w(R),b:{value:1}}}),H=f("math/rem",{values:{a:w(G),b:{value:y.colors.length}}}),B=f("variable/set",{configuration:{variable:d},values:{value:w(H)}}),Z={};for(let k=0;k<y.colors.length;k++){let Y=y.colors[k],ie=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];Z[String(k)]={node:A>0?f("pointer/interpolate",{configuration:{pointer:_},values:{value:{value:ie},duration:{value:A}}}):f("pointer/set",{configuration:{pointer:_},values:{value:{value:ie}}})}}n[B].flows={out:{node:f("flow/switch",{values:{selection:w(R)},flows:Z})}},C.push(B)}else if(F==="playAnimation")C.push(f("animation/start",{configuration:{animation:y.animation??y.clip??0}}));else if(F==="stopAnimation")C.push(f("animation/stop"));else if(F==="sendEvent"){let A={};for(let[_,d]of Object.entries(y.values||{}))A[_]={value:d};C.push(f("event/send",{configuration:{event:u(String(y.event??y.id??"custom"))},values:A}))}}if(!C.length)return null;if(C.length===1)return C[0];let L={};return C.forEach((E,y)=>{L[String(y)]={node:E}}),f("flow/sequence",{flows:L})},I=(P,N,C)=>{let L=D(N);L!==null&&f(P,{...C?{configuration:C}:{},flows:{out:{node:L}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:c}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:c}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:c}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[P,N]of Object.entries(v.onReceive))I("event/receive",N,{event:u(P)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:a,events:o}],graph:0}:null}var Gn='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).',Hn="Security Error: client-side scripts require allow-client-scripts opt-in.",vt="__THREE_LIVE_REGISTRY__";function le(){let e=typeof globalThis<"u"?globalThis:{};if(!e[vt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,vt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[vt]=t}}return e[vt]}var pe=le().plugins;function $n(e){let t=le().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function Xn(){return le().plugins}function he(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Mt(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let a=1/(r-s);return e[10]=(s+r)*a,e[14]=2*s*r*a,e}function We(e,t,i,r){let[s,n,a]=t,[o,l,h]=r,[u,f,g]=i,w=s-u,p=n-f,b=a-g,T=Math.hypot(w,p,b);T<=1e-5?(w=0,p=0,b=1):(w/=T,p/=T,b/=T);let x=l*b-h*p,M=h*w-o*b,c=o*p-l*w;T=Math.hypot(x,M,c),T<=1e-5?(x=0,M=0,c=0):(x/=T,M/=T,c/=T);let m=p*c-b*M,v=b*x-w*c,S=w*M-p*x;return T=Math.hypot(m,v,S),T<=1e-5?(m=0,v=0,S=0):(m/=T,v/=T,S/=T),e[0]=x,e[1]=m,e[2]=w,e[3]=0,e[4]=M,e[5]=v,e[6]=p,e[7]=0,e[8]=c,e[9]=S,e[10]=b,e[11]=0,e[12]=-(x*s+M*n+c*a),e[13]=-(m*s+v*n+S*a),e[14]=-(w*s+p*n+b*a),e[15]=1,e}function be(e,t,i){let r=t[0],s=t[1],n=t[2],a=t[3],o=t[4],l=t[5],h=t[6],u=t[7],f=t[8],g=t[9],w=t[10],p=t[11],b=t[12],T=t[13],x=t[14],M=t[15],c=i[0],m=i[1],v=i[2],S=i[3];return e[0]=c*r+m*o+v*f+S*b,e[1]=c*s+m*l+v*g+S*T,e[2]=c*n+m*h+v*w+S*x,e[3]=c*a+m*u+v*p+S*M,c=i[4],m=i[5],v=i[6],S=i[7],e[4]=c*r+m*o+v*f+S*b,e[5]=c*s+m*l+v*g+S*T,e[6]=c*n+m*h+v*w+S*x,e[7]=c*a+m*u+v*p+S*M,c=i[8],m=i[9],v=i[10],S=i[11],e[8]=c*r+m*o+v*f+S*b,e[9]=c*s+m*l+v*g+S*T,e[10]=c*n+m*h+v*w+S*x,e[11]=c*a+m*u+v*p+S*M,c=i[12],m=i[13],v=i[14],S=i[15],e[12]=c*r+m*o+v*f+S*b,e[13]=c*s+m*l+v*g+S*T,e[14]=c*n+m*h+v*w+S*x,e[15]=c*a+m*u+v*p+S*M,e}function Qe(e,t,i,r){let s=t[0],n=t[1],a=t[2],o=t[3],l=s+s,h=n+n,u=a+a,f=s*l,g=s*h,w=s*u,p=n*h,b=n*u,T=a*u,x=o*l,M=o*h,c=o*u,m=r[0],v=r[1],S=r[2];return e[0]=(1-(p+T))*m,e[1]=(g+c)*m,e[2]=(w-M)*m,e[3]=0,e[4]=(g-c)*v,e[5]=(1-(f+T))*v,e[6]=(b+x)*v,e[7]=0,e[8]=(w+M)*S,e[9]=(b-x)*S,e[10]=(1-(f+p))*S,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Ce(e,t,i=0){let r=t[0],s=t[1],n=t[2],a=t[4],o=t[5],l=t[6],h=t[8],u=t[9],f=t[10],g=f*o-l*u,w=-f*a+l*h,p=u*a-o*h,b=r*g+s*w+n*p;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=g*b,e[1]=w*b,e[2]=p*b,e[3]=(-f*s+n*u)*b,e[4]=(f*r-n*h)*b,e[5]=(-u*r+s*h)*b,e[6]=(l*s-n*o)*b,e[7]=(-l*r+n*a)*b,e[8]=(o*r-s*a)*b),e}function Wn(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],a=t[4],o=t[5],l=t[6],h=t[7],u=t[8],f=t[9],g=t[10],w=t[11],p=t[12],b=t[13],T=t[14],x=t[15],M=i*o-r*a,c=i*l-s*a,m=i*h-n*a,v=r*l-s*o,S=r*h-n*o,D=s*h-n*l,I=u*b-f*p,P=u*T-g*p,N=u*x-w*p,C=f*T-g*b,L=f*x-w*b,E=g*x-w*T,y=M*E-c*L+m*C+v*N-S*P+D*I;return y?(y=1/y,e[0]=(o*E-l*L+h*C)*y,e[1]=(s*L-r*E-n*C)*y,e[2]=(b*D-T*S+x*v)*y,e[3]=(g*S-f*D-w*v)*y,e[4]=(l*N-a*E-h*P)*y,e[5]=(i*E-s*N+n*P)*y,e[6]=(T*m-p*D-x*c)*y,e[7]=(u*D-g*m+w*c)*y,e[8]=(a*L-o*N+h*I)*y,e[9]=(r*N-i*L-n*I)*y,e[10]=(p*S-b*m+x*M)*y,e[11]=(f*m-u*S-w*M)*y,e[12]=(o*P-a*C-l*I)*y,e[13]=(i*C-r*P+s*I)*y,e[14]=(b*c-p*v-T*M)*y,e[15]=(u*v-f*c+g*M)*y,e):null}function An(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],a=s[1]*t+s[5]*i+s[9]*r+s[13],o=s[2]*t+s[6]*i+s[10]*r+s[14],l=s[3]*t+s[7]*i+s[11]*r+s[15],h=l!==0?1/l:1;e[0]=n*h,e[1]=a*h,e[2]=o*h}function jn(e,t,i,r,s,n,a,o,l,h,u,f,g,w,p,b,T=0){let x=h-a,M=u-o,c=f-l,m=g-a,v=w-o,S=p-l,D=s*S-n*v,I=n*m-r*S,P=r*v-s*m,N=x*D+M*I+c*P;if(N>-1e-7&&N<1e-7)return!1;let C=1/N,L=e-a,E=t-o,y=i-l,F=C*(L*D+E*I+y*P);if(F<-T||F>1+T)return!1;let z=E*c-y*M,A=y*x-L*c,_=L*M-E*x,d=C*(r*z+s*A+n*_);if(d<-T||F+d>1+T)return!1;let R=C*(m*z+v*A+S*_);if(R>1e-4&&R<b.distance){b.distance=R,b.point=[e+r*R,t+s*R,i+n*R];let G=M*S-c*v,H=c*m-x*S,B=x*v-M*m,Z=Math.hypot(G,H,B)||1;return b.normal=[G/Z,H/Z,B/Z],!0}return!1}function Kn(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let u=0;u<i;u++)r.push(he());if(i===0)return r;let s=new Set;for(let u of e.nodes)if(Array.isArray(u.children))for(let f of u.children)s.add(f);let n=new Set,a=128,o=(u,f,g=0)=>{if(g>a||u<0||u>=i||n.has(u))return;n.add(u);let w=e.nodes[u];if(!w)return;let p=he();if(t&&t[u])p.set(t[u]);else if(w.matrix&&w.matrix.length===16)p.set(w.matrix);else{let T=w.translation||[0,0,0],x=w.rotation||[0,0,0,1],M=w.scale||[1,1,1];Qe(p,x,T,M)}let b=r[u];if(f?be(b,f,p):b.set(p),Array.isArray(w.children))for(let T of w.children)typeof T=="number"&&o(T,b,g+1)},l=[],h=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(h&&Array.isArray(h.nodes))l.push(...h.nodes);else for(let u=0;u<i;u++)s.has(u)||l.push(u);for(let u of l)o(u,null);for(let u=0;u<i;u++)!s.has(u)&&!l.includes(u)&&o(u,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function En(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let a=i.componentType??5126,o=Wr[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,h=s.byteStride&&s.byteStride>0?s.byteStride:l,u=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(u)||u<0||h<l||u+(n-1)*h+l>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&h===l&&u%4===0)return new Float32Array(t,u,n*r);let f=new DataView(t),g=i.normalized===!0,w=new Float32Array(n*r);for(let p=0;p<n;p++){let b=u+p*h;for(let T=0;T<r;T++){let x=b+T*o,M;switch(a){case 5126:M=f.getFloat32(x,!0);break;case 5120:M=f.getInt8(x),g&&(M=Math.max(M/127,-1));break;case 5121:M=f.getUint8(x),g&&(M/=255);break;case 5122:M=f.getInt16(x,!0),g&&(M=Math.max(M/32767,-1));break;case 5123:M=f.getUint16(x,!0),g&&(M/=65535);break;default:M=f.getUint32(x,!0),g&&(M/=4294967295)}w[p*r+T]=M}}return w}function Yn(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),a=Number(t.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),h=(Number.isFinite(s)?s:1)*o,u=(Number.isFinite(s)?s:1)*l,f=-(Number.isFinite(n)?n:1)*l,g=(Number.isFinite(n)?n:1)*o;for(let w=0;w+1<e.length;w+=2){let p=e[w],b=e[w+1];e[w]=h*p+u*b+i,e[w+1]=f*p+g*b+r}}function Tt(e,t,i,r=!0){let s=[],n=null;try{for(let[a,o]of[[35633,t],[35632,i]]){let l=e.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(s.push(l),e.shaderSource(l,o),e.compileShader(l),e.getShaderParameter&&!e.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(l)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let a of s)e.attachShader(n,a);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let a=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${a}`);return null}return n}finally{for(let a of s)n&&e.detachShader?.(n,a),e.deleteShader?.(a)}}var Jn=["neutral","reinhard","none","aces","agx"];function Dn(e){let t=String(e??"").trim().toLowerCase();return Jn.includes(t)?t:"neutral"}function jr(e){return Jn.indexOf(Dn(e))}function Kr(e){return new TextDecoder().decode(e)}var Qn=le().decoders;function Yr(e,t){Qn.set(e.toLowerCase(),t)}function je(e){return Qn.get(e.toLowerCase())}function er(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let g=i.getUint8(0);throw g===123||g===32||g===10||g===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 s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=n&&a+8<=t.byteLength;){let g=i.getUint32(a,!0),w=i.getUint32(a+4,!0),p=a+8;if(p+g>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+g} bytes, buffer has ${t.byteLength}`);if(w===1313821514){let b=new Uint8Array(t,p,g),T=Kr(b);o=JSON.parse(T,(x,M)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:M)}else w===5130562&&(l=t.slice(p,p+g));a=p+g}if(!o)throw new Error("Missing JSON chunk in GLB");let h=o.extensionsRequired||[];if(h.includes("KHR_draco_mesh_compression")&&!je("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let g of["EXT_meshopt_compression","KHR_meshopt_compression"])if(h.includes(g)&&!je("meshopt"))throw new Error(`Model requires ${g}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(h.includes("KHR_texture_basisu")&&!je("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=l||new ArrayBuffer(0),f={gltf:o,bin:u,animations:[]};for(let g of pe)g.onParseGLB?.(f);return f}function qr(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 wt(e){if(qr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return er(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var tr=`#version 300 es
|
|
17
17
|
layout(location=0) in vec3 aPos;
|
|
18
18
|
layout(location=3) in vec3 aOff;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
@@ -48,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
48
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
49
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
50
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
51
|
-
}`,
|
|
51
|
+
}`,Zr=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -239,19 +239,19 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
239
|
float outAlpha=base.a;
|
|
240
240
|
/*XRD_O*/
|
|
241
241
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
242
|
+
}`,Jr=`#version 300 es
|
|
243
243
|
layout(location=0) in vec3 aPosition;
|
|
244
244
|
uniform mat4 uMVP;
|
|
245
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
245
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Qr=`#version 300 es
|
|
246
246
|
precision highp float;
|
|
247
247
|
uniform vec4 uColorId;
|
|
248
248
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function Cn(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var Zn=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function rr(){let e=ae().xrDepthShader;return{fs:Jr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...Zn,...e.uniformNames]:Zn}}function ti(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function An(e,t,i,r,s,n,o,a){if(r===void 0||!t.accessors?.[r])return null;let h=_n(t,i,t.accessors[r],n);if(!h)return null;a&&(h=h.slice(),qn(h,a));let l=e.createBuffer();return o.push(l),e.bindBuffer(34962,l),e.bufferData(34962,h,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),h}function En(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ir(e,t,i){let r=rr(),s=nr,n=r.fs,o=!1;for(let h of he)if(h.onResolveShader){let l=h.onResolveShader(t,i,s,n);l&&(s=l.vs,n=l.fs,o=!0)}let a=o?wt(e,s,n):null;return{program:a,uniforms:a?Cn(e,a,r.uniforms):null}}function ni(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,o=new Float32Array(s*20);for(let h=0;h<s;h++)o.set(r.subarray(h*16,h*16+16),h*20),o[h*20+16]=n?n[h*3]:1,o[h*20+17]=n?n[h*3+1]:1,o[h*20+18]=n?n[h*3+2]:1,o[h*20+19]=1;let a=e.createBuffer();i.push(a),e.bindBuffer(34962,a),e.bufferData(34962,o,35044);for(let h=0;h<5;h++)e.enableVertexAttribArray(8+h),e.vertexAttribPointer(8+h,4,5126,!1,80,h*16),e.vertexAttribDivisor(8+h,1);return!0}function ri(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Hi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),sr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function St(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function or(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=o=>o!==void 0&&t[o.index]?t[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function ar(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let o of n.primitives){if(o.vao&&e.deleteVertexArray(o.vao),o.buffers)for(let h of o.buffers)e.deleteBuffer(h);s(o.texture),s(o.metallicRoughnessTexture),s(o.normalTexture),s(o.occlusionTexture);let a=new Set;o.customProgram&&a.add(o.customProgram);for(let h of o.programCache?.values()??[])h.program&&a.add(h.program);for(let h of a)e.deleteProgram(h)}if(i)for(let n of i)s(n)}function Jn(e,t,i=sr,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ii(e,t,i,r,s)}catch(n){let o=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;ar(e,o,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let a of s.buffers)e.deleteBuffer(a);throw n}}function ii(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,o=$e("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(n,t);let a=t.bin,h=[];s.meshes=h;let l=[],c=n.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((C,d)=>{l.push(typeof C?.name=="string"&&C.name?C.name:`Variant_${d}`)});let f=Yn(n),y=[];if(Array.isArray(n.nodes))for(let C=0;C<n.nodes.length;C++){let d=n.nodes[C];d.mesh!==void 0&&n.meshes&&n.meshes[d.mesh]&&y.push({node:d,nodeIdx:C,meshIdx:d.mesh})}let g=y.length>0?y:(n.meshes||[]).map((C,d)=>({node:C,nodeIdx:-1,meshIdx:d})),u=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let C of b)u.push({...C,type:C.type||C.light_type||"point",innerConeAngle:C.innerConeAngle??C.inner_cone_angle,outerConeAngle:C.outerConeAngle??C.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let C=n.extensions.KHR_lights_punctual.lights;for(let d of C){let k=d.type==="directional"?"directional":d.type==="point"?"point":d.type==="spot"?"spot":"ambient";u.push({type:k,color:d.color||[1,1,1],intensity:d.intensity!==void 0?d.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]})),g.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${g.length}`);let w=[];if(s.gpuTextures=w,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let C=0;C<n.textures.length;C++){let d=n.textures[C],k=n.images[d.source];if(k){let $=e.createTexture();e.bindTexture(3553,$),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let S=D=>{e.bindTexture(3553,$),e.texImage2D(3553,0,6408,6408,5121,D),e.generateMipmap(3553),r?.()};if(k.bufferView!==void 0){let D=n.bufferViews[k.bufferView],T=D.byteOffset||0,P=new Blob([a.slice(T,T+D.byteLength)],{type:k.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(P).then(S).catch(()=>{})}else if(k.uri){let D=ti(k.uri);if(D){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>S(T),T.src=D}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",k.uri)}w.push($)}else w.push(null)}}let M=[1/0,1/0,1/0],x=[-1/0,-1/0,-1/0],m=0,p=0;for(let C=0;C<g.length;C++){let d=g[C],k=n.meshes[d.meshIdx],$=d.nodeIdx>=0?f[d.nodeIdx]:ce(),S=new Float32Array(9);Ae(S,$);let D={name:d.node.name||k.name||`Mesh_${d.meshIdx}`,nodeIndex:d.nodeIdx,transform:$,normalMatrix:S,primitives:[],extras:d.node.extras||k.extras,...d.node?.visible===!1||d.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=D;let T=d.node?.extensions?.EXT_mesh_gpu_instancing;if(T&&T.attributes&&typeof T.attributes=="object"){let P=T.attributes,j=P.TRANSLATION!==void 0?n.accessors?.[P.TRANSLATION]:null,W=P.ROTATION!==void 0?n.accessors?.[P.ROTATION]:null,O=P.SCALE!==void 0?n.accessors?.[P.SCALE]:null,Y=P._COLOR_0!==void 0?n.accessors?.[P._COLOR_0]:null,U=Number(j?.count??W?.count??O?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let X=(z,xt)=>{if(!z||z.bufferView===void 0||!n.bufferViews?.[z.bufferView])return null;let te=z.componentType??5126,ie=ee=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${ee})`),null);if(te!==5120&&te!==5121&&te!==5122&&te!==5123&&te!==5126)return ie(`componentType ${te}`);if(!(Number(z.count)>=U))return ie(`count ${z.count} < ${U}`);let J=null;try{J=_n(n,a,{...z,count:U},xt)}catch{return ie("out of bounds")}return!J||!J.every(Number.isFinite)?ie("non-finite value"):J},V=X(j,3),G=X(W,4),F=X(O,3),H=Y?.type==="VEC4"?4:3,B=X(Y,H),K=new Float32Array(U*16),q=ce();for(let z=0;z<U;z++){let xt=V?[V[z*3],V[z*3+1],V[z*3+2]]:[0,0,0],te=G?[G[z*4],G[z*4+1],G[z*4+2],G[z*4+3]]:[0,0,0,1],ie=F?[F[z*3],F[z*3+1],F[z*3+2]]:[1,1,1];qe(q,te,xt,ie),K.set(q,z*16)}if(D.instanceMatrices=K,B){let z=new Float32Array(U*3);for(let xt=0;xt<U;xt++)z[xt*3]=B[xt*H],z[xt*3+1]=B[xt*H+1],z[xt*3+2]=B[xt*H+2];D.instanceColors=z}}}for(let P of k.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let J=$e("draco");J&&J.decodePrimitive(n,P,a)}let j=[],W=e.createVertexArray();s.vao=W,s.buffers=j,e.bindVertexArray(W);let O=ni(e,D,j),Y=n.accessors[P.attributes.POSITION],U=Number(Y?.count??0);if(!Number.isFinite(U)||U<0||m+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(m+=U,Y?.min&&Y?.max){let J=ee=>{for(let re=0;re<3;re++){let ge=ee[12+re],se=ee[12+re];for(let ne=0;ne<3;ne++){let ue=ee[ne*4+re]*Y.min[ne],le=ee[ne*4+re]*Y.max[ne];ge+=ue<le?ue:le,se+=ue>le?ue:le}ge<M[re]&&(M[re]=ge),se>x[re]&&(x[re]=se)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let ee=D.instanceMatrices.length>>4,re=ce();for(let ge=0;ge<ee;ge++){let se=D.instanceMatrices.subarray(ge*16,ge*16+16);de(re,$,se),J(re)}}else J($)}let X=An(e,n,a,P.attributes.POSITION,0,3,j);An(e,n,a,P.attributes.NORMAL,1,3,j),An(e,n,a,P.attributes.TEXCOORD_0,2,2,j,ri(n,P));let V=0,G=5123,F=null;if(P.indices!==void 0){let J=n.accessors[P.indices],ee=(n.bufferViews[J.bufferView].byteOffset||0)+(J.byteOffset||0);if(V=Number(J.count??0),!Number.isFinite(V)||V<0||p+V>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);p+=V,G=J.componentType===5125?5125:5123;let re=e.createBuffer();j.push(re),e.bindBuffer(34963,re),J.componentType===5125?F=new Uint32Array(a,ee,J.count):J.componentType===5121?F=Uint16Array.from(new Uint8Array(a,ee,J.count)):F=ee%2===0?new Uint16Array(a,ee,J.count):new Uint16Array(a.slice(ee,ee+J.count*2)),e.bufferData(34963,F,35044)}else V=Y.count;let H={};for(let J of he)if(J.onBuildPrimitiveVAO){let ee=J.onBuildPrimitiveVAO(e,W,P,n,a);ee&&(H[J.name]=ee)}e.bindVertexArray(null);let B=n.materials&&P.material!==void 0?n.materials[P.material]:null,{program:K,uniforms:q}=ir(e,P,B),z=or(B,w),xt=!!(B?.extensions?.KHR_materials_transmission||H.materials?.isTransmissive),te=P.extensions?.KHR_materials_variants?.mappings,ie=Array.isArray(te)?te.filter(J=>J&&typeof J.material=="number"&&Array.isArray(J.variants)).map(J=>({material:J.material|0,variants:J.variants.map(ee=>Number(ee)|0)})):void 0;D.primitives.push({vao:W,instanced:O,indexCount:V,indexType:G,...z,positions:X,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:ie,primitiveDef:P,programCache:new Map([[P.material??-1,{program:K,uniforms:q}]]),pluginData:H,customProgram:K,customUniforms:q,isTransmissive:xt})}h.push(D)}isFinite(M[0])||(M=[-1,-1,-1]),isFinite(x[0])||(x=[1,1,1]);let v=[(M[0]+x[0])/2,(M[1]+x[1])/2,(M[2]+x[2])/2],R=x[0]-M[0],L=x[1]-M[1],I=x[2]-M[2],N=Math.max(Math.hypot(R,L,I)/2,.5),_=[M[0],M[1],M[2]],A=[x[0],x[1],x[2]],E=t.animations;if(!E){for(let C of he)if(C.onParseGLB?.(t),t.animations){E=t.animations;break}}return E||(E=[]),{meshes:h,bounds:{center:v,radius:N,min:_,max:A},lights:u,animations:E,worldMatrices:f,gpuTextures:w,availableVariants:l}}function Ze(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var Tt=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ce(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ce(),this.viewMatrix=ce(),this.activeViewMatrix=null,this.modelMatrix=ce(),this.mvpMatrix=ce(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ce(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(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=En(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=Rn(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 o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){qr(e,t)}static getDecoder(e){return $e(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=rr();this.renderProg=wt(e,nr,t.fs),this.pickProg=wt(e,Qr,ei),this.uRender=Cn(e,this.renderProg,t.uniforms),this.uPick=Cn(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of he)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:o,gpuTextures:a,availableVariants:h}=Jn(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=o||[],this.gpuTextures=a||[],this.availableVariants=h||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of he)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let l=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=En(l));let c=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(tr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of he)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Je(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Je(e),{meshes:r}=Jn(this.gl,i,sr,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Ae(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Ae(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],o=[],a=[],h=[];for(let l of this.lights){let c=l.color||[1,1,1],f=l.intensity!==void 0?l.intensity:1;if(l.type==="ambient")i=[c[0]*f,c[1]*f,c[2]*f];else if(l.type==="directional"&&r.length<6){let y=l.direction||[.5,1,.8];r.push(y[0],y[1],y[2]),s.push(c[0]*f,c[1]*f,c[2]*f)}else if((l.type==="point"||l.type==="spot")&&n.length<6){let y=l.position||[0,0,0];if(n.push(y[0],y[1],y[2]),o.push(c[0]*f,c[1]*f,c[2]*f),l.type==="spot"){let g=l.direction||[0,-1,0],u=Math.max(.01,Math.min(Math.PI/2,l.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(u-1e-4,l.innerConeAngle??0));a.push(g[0],g[1],g[2]),h.push(Math.cos(b),Math.cos(u))}else a.push(0,-1,0),h.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,o),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,a),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,h)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=En(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Rn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of he)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of he)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(l=>l.primitives.filter(c=>c.materialIndex===i||e.length===1&&c.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],o=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,h={baseColorFactor:n,metallicFactor:o,roughnessFactor:a,setBaseColorFactor:l=>{let c=[l[0],l[1],l[2],l[3]??1];h.baseColorFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=c);for(let f of r)f.baseColor=c;this.render()},setMetallicFactor:l=>{h.metallicFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=l);for(let c of r)c.metallic=l;this.render()},setRoughnessFactor:l=>{h.roughnessFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=l);for(let c of r)c.roughness=l;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:h}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let o=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let h of n.variantMappings)if(Array.isArray(h.variants)&&h.variants.includes(i)){o=h.material;break}}let a=o!==void 0?r[o]:void 0;n.materialIndex=a?o:void 0,Object.assign(n,or(a,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=ir(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of he)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=ce();de(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,o=t?t[0]:0,a=t?t[1]:0,h=t?t[2]:0,l=this.modelRootMatrix;l&&(r=l[0]*e[0]+l[4]*e[1]+l[8]*e[2]+l[12],s=l[1]*e[0]+l[5]*e[1]+l[9]*e[2]+l[13],n=l[2]*e[0]+l[6]*e[1]+l[10]*e[2]+l[14],t&&(o=l[0]*t[0]+l[4]*t[1]+l[8]*t[2],a=l[1]*t[0]+l[5]*t[1]+l[9]*t[2],h=l[2]*t[0]+l[6]*t[1]+l[10]*t[2]));let c=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],y=i[2]*r+i[6]*s+i[10]*n+i[14],g=i[3]*r+i[7]*s+i[11]*n+i[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let u=c/g,b=f/g,w=y/g,M=this.canvas.getBoundingClientRect(),x=M.width||this.canvas.clientWidth||this.canvas.width||300,m=M.height||this.canvas.clientHeight||this.canvas.height||150,p=(u*.5+.5)*x,v=(-b*.5+.5)*m,R=u>=-1.1&&u<=1.1&&b>=-1.1&&b<=1.1&&w>=-1&&w<=1;if(R&&t){let[L,I,N]=Ze(this),_=[r-L,s-I,n-N];o*_[0]+a*_[1]+h*_[2]>.05&&(R=!1)}return{x:p,y:v,z:w,visible:R}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],a=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],h=this.customTarget?[...this.customTarget]:[...this.bounds.center],l=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;h[0]+=(-s*o[0]+n*a[0])*l,h[1]+=(-s*o[1]+n*a[1])*l,h[2]+=(-s*o[2]+n*a[2])*l,this.customTarget=h}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,o=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),a=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(o,a,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let o=ce();de(o,this.projMatrix,this.viewMatrix);let a=[],h=Math.max(0,Math.min(s-1,e)),l=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let R=this.meshes[v];if(R.visible===!1||R.isPluginMesh)continue;let L=v+1,I=(L&255)/255,N=(L>>8&255)/255,_=(L>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,N,_,1),de(this.modelMatrix,this.modelRootMatrix,R.transform);let A=R.instanceMatrices;if(A&&A.length>=16){let E=A.length>>4,C=ce();for(let d of R.primitives){r.bindVertexArray(d.vao);for(let k=0;k<E;k++)de(C,this.modelMatrix,A.subarray(k*16,k*16+16)),de(this.mvpMatrix,o,C),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),St(r,d)}}else{de(this.mvpMatrix,o,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let E of R.primitives)r.bindVertexArray(E.vao),St(r,E)}}let m=new Uint8Array(4);r.readPixels(h,l,1,1,6408,5121,m),r.bindFramebuffer(36160,null);let p=m[0]+(m[1]<<8)+(m[2]<<16);p>0&&p<=this.meshes.length&&(a=[this.meshes[p-1]])}a.length===0&&(a=this.meshes.filter(m=>m.visible!==!1));let c=null,f=1/0,y=[0,0,0],g=[0,1,0],[u,b,w]=Ze(this),M=ce();for(let m of a){de(M,this.modelRootMatrix,m.transform);let p=m.instanceMatrices,v=p&&p.length>=16?p.length>>4:1;for(let R=0;R<v;R++){p&&p.length>=16?de(this.modelMatrix,M,p.subarray(R*16,R*16+16)):this.modelMatrix.set(M),de(this.mvpMatrix,o,this.modelMatrix);let L=ce();if(!Wn(L,this.mvpMatrix))continue;let I=(h+.5)/s*2-1,N=(l+.5)/n*2-1,_=[0,0,0],A=[0,0,0];Tn(_,I,N,-1,L),Tn(A,I,N,1,L);let E=A[0]-_[0],C=A[1]-_[1],d=A[2]-_[2],k=Math.hypot(E,C,d)||1,$=E/k,S=C/k,D=d/k,T={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let j of m.primitives){if(!j.positions)continue;let W=j.positions,O=j.indices,Y=Math.floor(O?O.length/3:W.length/9);for(let U=0;U<Y;U++){let X=O?O[U*3]:U*3,V=O?O[U*3+1]:U*3+1,G=O?O[U*3+2]:U*3+2;Kn(_[0],_[1],_[2],$,S,D,W[X*3],W[X*3+1],W[X*3+2],W[V*3],W[V*3+1],W[V*3+2],W[G*3],W[G*3+1],W[G*3+2],T,P)}}})(1e-4),isFinite(T.distance)){let P=T.point[0],j=T.point[1],W=T.point[2],O=this.modelMatrix,Y=O[0]*P+O[4]*j+O[8]*W+O[12],U=O[1]*P+O[5]*j+O[9]*W+O[13],X=O[2]*P+O[6]*j+O[10]*W+O[14],V=Y-u,G=U-b,F=X-w,H=Math.hypot(V,G,F);if(H<f){Ae(this.normalMatrix,this.modelMatrix);let B=this.normalMatrix,K=T.normal[0],q=T.normal[1],z=T.normal[2],xt=B[0]*K+B[3]*q+B[6]*z,te=B[1]*K+B[4]*q+B[7]*z,ie=B[2]*K+B[5]*q+B[8]*z,J=Math.hypot(xt,te,ie)||1;xt/=J,te/=J,ie/=J,xt*V+te*G+ie*F>0&&(xt=-xt,te=-te,ie=-ie),c=m,f=Math.round(H*1e3)/1e3,y=[Math.round(Y*1e3)/1e3,Math.round(U*1e3)/1e3,Math.round(X*1e3)/1e3],g=[Math.round(xt*1e3)/1e3,Math.round(te*1e3)/1e3,Math.round(ie*1e3)/1e3]}}}}if(!c)return null;let x={meshIndex:this.meshes.indexOf(c),meshName:c.name,nodeIndex:c.nodeIndex,distance:f,hitPoint:y,normal:g,screenX:e,screenY:t};if(i){for(let m of he)m.onMeshSelect?.(this,x);this.opts.onMeshClick&&this.opts.onMeshClick(x),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:x}))}return x}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,o=(s+.5)/n*2-1;return Math.floor((o*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Mt(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;Xe(this.viewMatrix,Ze(this),i,[0,1,0]),de(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ae(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of he)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of he)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of he)n.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let n of he)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let o=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,h=e?.transform?.position,l=h?[h.x,h.y,h.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:o,projMatrix:a,eyePos:l,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let x=Math.max(2,this.canvas.width||2),m=Math.max(1,this.canvas.height||1),p=Math.max(1,Math.floor(x*.5)),v=Math.max(1,x-p),R=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[I,N,_]=Ze(this),A=Math.cos(this.currTheta),E=-Math.sin(this.currTheta),C=.032,d=ce(),k=ce(),$=[I-A*C,N,_-E*C],S=[L[0]-A*C*.25,L[1],L[2]-E*C*.25];Mt(d,this.fov,p/m,.1,R),Xe(k,$,S,[0,1,0]);let D=ce(),T=ce(),P=[I+A*C,N,_+E*C],j=[L[0]+A*C*.25,L[1],L[2]+E*C*.25];Mt(D,this.fov,v/m,.1,R),Xe(T,P,j,[0,1,0]),this.render({viewMatrix:k,projMatrix:d,eyePos:$,viewport:[0,0,p,m],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:T,projMatrix:D,eyePos:P,viewport:[p,0,v,m],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,x,m);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let o=ce(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,de(o,e?.projMatrix??this.projMatrix,a);let h=ae().xrDepthShader,l=Kr(this.toneMapping),[c,f,y]=e?e.eyePos:Ze(this);for(let x of he)x.onBeforeDrawScene?.(this,t,o,[c,f,y],l);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let u=e?.eye||"none",b=!1,w=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,M=x=>{for(let m=0;m<w.length;m++){let p=w[m];if(p.visible===!1)continue;let v=this.selectedMeshName!==""&&p.name===this.selectedMeshName;m<g||p.worldSpace===!0||p.name==="__xr_reticle__"?this.modelMatrix.set(p.transform):de(this.modelMatrix,this.modelRootMatrix,p.transform),de(this.mvpMatrix,o,this.modelMatrix),Ae(p.normalMatrix,this.modelMatrix);let R=p.extras?.xr?.stereo||p.userData?.xr?.stereo,L=0,I=0,N=1,_=1;R==="sbs"?(N=.5,L=u==="right"?.5:0):R==="ou"&&(_=.5,I=u==="right"?.5:0);for(let A of p.primitives){let E=!!A.isTransmissive;if(!x&&E){b=!0;continue}if(x&&!E)continue;let C=A.customProgram||this.renderProg,d=A.customUniforms||this.uRender;t.useProgram(C),t.vertexAttrib3f(3,0,0,0),d.uInstanced&&t.uniform1i(d.uInstanced,0),t.uniform1i(d.uToneMapping,l),t.uniform1f(d.uEnvIntensity,this.envIntensity),d.uExposure&&t.uniform1f(d.uExposure,this.exposure),t.uniform3f(d.uCameraPos,c,f,y),t.uniform1f(d.uEmissive,v?1:0),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(d.uNormalMatrix,!1,p.normalMatrix),d.uUvTransform&&t.uniform4f(d.uUvTransform,L,I,N,_),d.uViewportSize&&t.uniform2f(d.uViewportSize,Math.max(1,s),Math.max(1,n)),h?.bind(t,d,this.xrDepthState,a,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(d.uEnvironmentMap,4),t.uniform1i(d.uHasEnvironmentMap,1)):t.uniform1i(d.uHasEnvironmentMap,0),this.bindLights(d),d.uSectionEnabled&&t.uniform1i(d.uSectionEnabled,0);for(let $ of he)$.onBeforeDrawPrimitive?.(t,C,A,p,this.worldMatrices||[],this.gltf);t.uniform4fv(d.uBaseColor,A.baseColor),t.uniform1f(d.uMetallic,A.metallic),t.uniform1f(d.uRoughness,A.roughness),d.uClearcoat&&t.uniform2f(d.uClearcoat,A.clearcoat??0,A.clearcoatRoughness??.04),A.texture?(t.activeTexture(33984),t.bindTexture(3553,A.texture),t.uniform1i(d.uBaseColorTexture,0),t.uniform1i(d.uHasTexture,1)):t.uniform1i(d.uHasTexture,0),A.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,A.metallicRoughnessTexture),t.uniform1i(d.uMetallicRoughnessTexture,1),t.uniform1i(d.uHasMetallicRoughnessTexture,1)):t.uniform1i(d.uHasMetallicRoughnessTexture,0),A.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,A.normalTexture),t.uniform1i(d.uNormalTexture,2),t.uniform1i(d.uHasNormalTexture,1),t.uniform1f(d.uNormalScale,A.normalScale)):t.uniform1i(d.uHasNormalTexture,0),A.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,A.occlusionTexture),t.uniform1i(d.uOcclusionTexture,3),t.uniform1i(d.uHasOcclusionTexture,1),t.uniform1f(d.uOcclusionStrength,A.occlusionStrength)):t.uniform1i(d.uHasOcclusionTexture,0),t.bindVertexArray(A.vao);let k=p.instanceMatrices;if(A.instanceCount!==void 0)t.drawElementsInstanced(4,A.indexCount,A.indexType,0,A.instanceCount);else if(k&&k.length>=16&&A.instanced&&d.uInstanced&&d.uViewProj){let $=k.length>>4;t.uniform1i(d.uInstanced,1),t.uniformMatrix4fv(d.uViewProj,!1,o),A.indices?t.drawElementsInstanced(4,A.indexCount,A.indexType,0,$):t.drawArraysInstanced(4,0,A.indexCount,$),t.uniform1i(d.uInstanced,0)}else if(k&&k.length>=16){let $=k.length>>4,S=p.instanceColors,D=ce(),T=new Float32Array(9),P=[A.baseColor[0],A.baseColor[1],A.baseColor[2],A.baseColor[3]];for(let j=0;j<$;j++)de(D,this.modelMatrix,k.subarray(j*16,j*16+16)),de(this.mvpMatrix,o,D),Ae(T,D),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,D),t.uniformMatrix3fv(d.uNormalMatrix,!1,T),S&&(P[0]=A.baseColor[0]*S[j*3],P[1]=A.baseColor[1]*S[j*3+1],P[2]=A.baseColor[2]*S[j*3+2],P[3]=A.baseColor[3],t.uniform4fv(d.uBaseColor,P)),St(t,A)}else St(t,A)}}};if(M(!1),b){for(let x of he)x.onBeforeTransmissivePass?.(t,this);M(!0)}for(let x of he)x.onAfterRender?.(t,this,o,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ar(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of he)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Tt.registerPlugin=$n,Tt.getRegisteredPlugins=jn;function si(e){return e+3&-4}var Q=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function lr(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function mr(e,t=0){let[i,r,s,,n,o,a,,h,l,c,,f,y,g]=Array.from({length:15},(T,P)=>Q(e[t+P],P%5===0?1:0)),u=Math.hypot(i,r,s),b=Math.hypot(n,o,a),w=Math.hypot(h,l,c);i*(o*c-l*a)-n*(r*c-l*s)+h*(r*a-o*s)<0&&(u=-u);let M=Math.abs(u)>1e-8?1/u:0,x=Math.abs(b)>1e-8?1/b:0,m=Math.abs(w)>1e-8?1/w:0,p=i*M,v=r*M,R=s*M,L=n*x,I=o*x,N=a*x,_=h*m,A=l*m,E=c*m,C=p+I+E,d=0,k=0,$=0,S=1;if(C>0){let T=.5/Math.sqrt(C+1);S=.25/T,d=(N-A)*T,k=(_-R)*T,$=(v-L)*T}else if(p>I&&p>E){let T=2*Math.sqrt(Math.max(0,1+p-I-E));T>1e-8&&(S=(N-A)/T,d=.25*T,k=(L+v)/T,$=(_+R)/T)}else if(I>E){let T=2*Math.sqrt(Math.max(0,1+I-p-E));T>1e-8&&(S=(_-R)/T,d=(L+v)/T,k=.25*T,$=(N+A)/T)}else{let T=2*Math.sqrt(Math.max(0,1+E-p-I));T>1e-8&&(S=(v-L)/T,d=(_+R)/T,k=(N+A)/T,$=.25*T)}let D=Math.hypot(d,k,$,S);return D>1e-8&&Number.isFinite(D)?(d/=D,k/=D,$/=D,S/=D):(d=0,k=0,$=0,S=1),{t:[f,y,g],r:[d,k,$,S],s:[u,b,w]}}function oi(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Le=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function hr(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:Le(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function je(e,t){return fr(e,t)[0]}function fr(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],o=[],a=[],h=new Set,l=[],c=[],f=new Map,y=[],g=[],u=[],b=new Map,w=[],M=[];function x(S){let D=f.get(S);if(D!==void 0)return D;D=c.length,f.set(S,D);let T=S,P=T.color?.r??.8,j=T.color?.g??.8,W=T.color?.b??.8,O=T.opacity??1,Y={baseColorFactor:[P,j,W,O],metallicFactor:T.metalness??0,roughnessFactor:T.roughness??.5},U={};if(T.map){let G="";typeof T.map=="string"?G=T.map:typeof T.map.source=="string"?G=T.map.source:typeof T.map.image=="string"&&(G=T.map.image);let F=G.trim(),H=F&&!/[\x00-\x1f\x7f\\]|\.\./.test(F)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(F)||!F.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(F))?F:null;if(H){let K=b.get(H);if(K===void 0){let q=y.length;y.push({uri:H}),g.length===0&&g.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),K=u.length,u.push({sampler:0,source:q}),b.set(H,K)}Y.baseColorTexture={index:K}}let B=T.map.avgColor;Array.isArray(B)&&B.length>=3&&(U.avgColor=[B[0],B[1],B[2]])}let X={name:T.name||"",pbrMetallicRoughness:Y,doubleSided:T.side===2||!!T.doubleSided,...Object.keys(U).length>0?{extras:U}:{}};if(T.emissive&&(T.emissive.r>0||T.emissive.g>0||T.emissive.b>0)){let G=T.emissiveIntensity??1;X.emissiveFactor=[T.emissive.r*G,T.emissive.g*G,T.emissive.b*G]}let V={};return T.clearcoat&&T.clearcoat>0&&(V.KHR_materials_clearcoat={clearcoatFactor:T.clearcoat,clearcoatRoughnessFactor:T.clearcoatRoughness||0}),T.sheen&&T.sheen>0&&(V.KHR_materials_sheen={sheenColorFactor:T.sheenColor?[T.sheenColor.r,T.sheenColor.g,T.sheenColor.b]:[1,1,1],sheenRoughnessFactor:T.sheenRoughness||0}),T.transmission&&T.transmission>0&&(V.KHR_materials_transmission={transmissionFactor:T.transmission}),T.thickness&&T.thickness>0&&(V.KHR_materials_volume={thicknessFactor:T.thickness,attenuationDistance:T.attenuationDistance??1/0,attenuationColor:T.attenuationColor?[T.attenuationColor.r,T.attenuationColor.g,T.attenuationColor.b]:[1,1,1]}),T.ior!==void 0&&T.ior!==1.5&&(V.KHR_materials_ior={ior:T.ior}),T.dispersion&&T.dispersion>0&&(V.KHR_materials_dispersion={dispersion:T.dispersion}),T.iridescence&&T.iridescence>0&&(V.KHR_materials_iridescence={iridescenceFactor:T.iridescence,iridescenceIor:T.iridescenceIOR??1.3}),Object.keys(V).length>0&&(X.extensions=V),c.push(X),D}function m(S,D){let T=new Uint8Array(S.buffer,S.byteOffset,S.byteLength),P=si(T.byteLength),j=new Uint8Array(P);j.set(T),i.push(j);let W=s.length;return s.push({buffer:0,byteOffset:r,byteLength:T.byteLength,target:D}),r+=P,W}function p(S,D,T,P,j,W,O){let Y=m(S,T),U=n.length,X={bufferView:Y,byteOffset:0,componentType:P,count:j,type:D};return W&&(X.min=W),O&&(X.max=O),n.push(X),U}e.traverse(S=>{if(S.isLight||S.color&&S.intensity!==void 0){let D=S.matrixWorld?.elements,T=Q(D?D[12]:S.position?.x,0),P=Q(D?D[13]:S.position?.y,0),j=Q(D?D[14]:S.position?.z,0),W=S.target,O=W?.parent?W?.matrixWorld?.elements:void 0,Y=Q(O?O[12]:W?.position?.x,0),U=Q(O?O[13]:W?.position?.y,0),X=Q(O?O[14]:W?.position?.z,0),V=Y-T,G=U-P,F=X-j,H=Math.hypot(V,G,F),B=Math.max(.01,Math.min(Math.PI/2,Q(S.angle,Math.PI/3))),K=Math.max(0,Math.min(1,Q(S.penumbra,0)));M.push({type:S.type,color:[S.color.r,S.color.g,S.color.b],intensity:S.intensity,position:[T,P,j],...S.type==="spot"?{direction:H>1e-6?[V/H,G/H,F/H]:[0,-1,0],outerConeAngle:B,innerConeAngle:Math.max(0,B*(1-K)),range:Math.max(0,Q(S.distance,0))}:S.type==="point"?{range:Math.max(0,Q(S.distance,0))}:{}})}});let v=[],R=new Set([e]),L=[];if(Array.isArray(e.children))for(let S=e.children.length-1;S>=0;S--)L.push({obj:e.children[S],parentKids:v});for(;L.length>0;){let{obj:S,parentKids:D}=L.pop();if(!S||typeof S!="object"||R.has(S))continue;R.add(S),S._bakeAuthorGeometry?.(),ae().materializeDeclarativeGeometry?.(S);let T=!!(S.userData&&(S.userData.xr&&typeof S.userData.xr=="object"&&Object.keys(S.userData.xr).length>0||S.userData.interactivity&&typeof S.userData.interactivity=="object"&&Object.keys(S.userData.interactivity).length>0)),P={name:S.name||(T?`Node_${a.length}`:"")},j=Q(S.position?.x,0),W=Q(S.position?.y,0),O=Q(S.position?.z,0),Y=Q(S.quaternion?.x,0),U=Q(S.quaternion?.y,0),X=Q(S.quaternion?.z,0),V=Q(S.quaternion?.w,1),G=Q(S.scale?.x,1),F=Q(S.scale?.y,1),H=Q(S.scale?.z,1);if((j||W||O)&&(P.translation=[j,W,O]),(Y||U||X||V!==1)&&(P.rotation=[Y,U,X,V]),(G!==1||F!==1||H!==1)&&(P.scale=[G,F,H]),S.visible===!1&&(P.extensions={...P.extensions||{},KHR_node_visibility:{visible:!1}},h.add("KHR_node_visibility")),S.userData&&Object.keys(S.userData).length>0&&(P.extras=JSON.parse(JSON.stringify(S.userData,(q,z)=>{if(!(q==="__proto__"||q==="prototype"||q==="constructor"))return typeof z=="function"?void 0:z})),S.userData.xr)){let q=oi(S.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},ae().xrTraitSerializer?.gltfNode(P,S.userData.xr),h.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(S.geometry){let q=S.geometry,z=q.attributes.position;if(z&&z.count>0){let xt=[1/0,1/0,1/0],te=[-1/0,-1/0,-1/0];for(let se=0;se<z.count;se++){let ne=z.getX(se),ue=z.getY(se),le=z.getZ(se);ne<xt[0]&&(xt[0]=ne),ne>te[0]&&(te[0]=ne),ue<xt[1]&&(xt[1]=ue),ue>te[1]&&(te[1]=ue),le<xt[2]&&(xt[2]=le),le>te[2]&&(te[2]=le)}let ie={attributes:{POSITION:p(z.array,"VEC3",34962,5126,z.count,xt,te)}};if(q.attributes.normal&&(ie.attributes.NORMAL=p(q.attributes.normal.array,"VEC3",34962,5126,q.attributes.normal.count)),q.attributes.uv&&(ie.attributes.TEXCOORD_0=p(q.attributes.uv.array,"VEC2",34962,5126,q.attributes.uv.count)),q.index){let se=q.index.array instanceof Uint32Array;ie.indices=p(q.index.array,"SCALAR",34963,se?5125:5123,q.index.count)}let J=Array.isArray(S.material)?S.material[0]:S.material;J&&(ie.material=x(J));let ee=S.userData?.variants;if(ee&&typeof ee=="object"){let se=new Map;for(let ne of Object.keys(ee)){if(!ne||ne==="__proto__"||ne==="constructor"||ne==="prototype")continue;let ue=ee[ne];if(!ue||typeof ue!="object")continue;let le=w.indexOf(ne);if(le===-1&&w.length<256&&(le=w.length,w.push(ne)),le===-1)continue;let xe=x(ue),Ue=se.get(xe);Ue||(Ue=[],se.set(xe,Ue)),Ue.push(le)}if(se.size>0){let ne=[];for(let[ue,le]of se.entries())ne.push({material:ue,variants:le});ie.extensions={...ie.extensions||{},KHR_materials_variants:{mappings:ne}},h.add("KHR_materials_variants")}}let re=S;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let se=Math.min(1e4,Math.floor(re.count)),ne=re.instanceMatrix.array,ue=new Float32Array(se*3),le=new Float32Array(se*4),xe=new Float32Array(se*3);for(let fe=0;fe<se;fe++){let{t:Be,r:Oe,s:Pi}=mr(ne,fe*16);ue[fe*3]=Be[0],ue[fe*3+1]=Be[1],ue[fe*3+2]=Be[2],le[fe*4]=Oe[0],le[fe*4+1]=Oe[1],le[fe*4+2]=Oe[2],le[fe*4+3]=Oe[3],xe[fe*3]=Pi[0],xe[fe*3+1]=Pi[1],xe[fe*3+2]=Pi[2]}let Ue={TRANSLATION:p(ue,"VEC3",0,5126,se),ROTATION:p(le,"VEC4",0,5126,se),SCALE:p(xe,"VEC3",0,5126,se)};if(re.instanceColor?.array&&re.instanceColor.array.length>=se*3){let fe=new Float32Array(re.instanceColor.array.subarray(0,se*3));Ue._COLOR_0=p(fe,"VEC3",0,5126,se)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:Ue}},h.add("EXT_mesh_gpu_instancing")}let ge=o.length;o.push({primitives:[ie],name:S.name,...P.extras?{extras:P.extras}:{}}),P.mesh=ge}}let B=a.length;a.push(P),l.push(S),D.push(B);let K=S.children;if(Array.isArray(K)&&K.length>0){let q=[];P.children=q;for(let z=K.length-1;z>=0;z--)L.push({obj:K[z],parentKids:q})}}for(let S=0;S<a.length;S++){let D=a[S];D.children&&D.children.length===0?delete D.children:D.children&&D.children.length>0&&(D.extras?.xr?.lod||D.extensions?.ANDROID_xr_scenecore?.lod||l[S]?.isLOD)&&(D.extensions={...D.extensions||{},MSFT_lod:{ids:[...D.children]}},h.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),N=[];if(typeof I=="function"&&l.length>0){let S=t?.duration??4,D=t?.fps??15,T=Math.max(2,Math.round(S*D)+1),P=new Float32Array(T),j=l.map(F=>[Q(F.position?.x,0),Q(F.position?.y,0),Q(F.position?.z,0),Q(F.quaternion?.x,0),Q(F.quaternion?.y,0),Q(F.quaternion?.z,0),Q(F.quaternion?.w,1),Q(F.scale?.x,1),Q(F.scale?.y,1),Q(F.scale?.z,1)]),W=l.map(()=>new Float32Array(T*3)),O=l.map(()=>new Float32Array(T*4)),Y=l.map(()=>new Float32Array(T*3));for(let F=0;F<T;F++){let H=F/(T-1)*S;P[F]=H;try{I(H)}catch{}for(let B=0;B<l.length;B++){let K=l[B];W[B][F*3]=Q(K.position?.x,0),W[B][F*3+1]=Q(K.position?.y,0),W[B][F*3+2]=Q(K.position?.z,0);let q=Q(K.quaternion?.x,0),z=Q(K.quaternion?.y,0),xt=Q(K.quaternion?.z,0),te=Q(K.quaternion?.w,1),ie=Math.hypot(q,z,xt,te)||1;if(q/=ie,z/=ie,xt/=ie,te/=ie,F>0){let J=(F-1)*4,ee=O[B];ee[J]*q+ee[J+1]*z+ee[J+2]*xt+ee[J+3]*te<0&&(q=-q,z=-z,xt=-xt,te=-te)}O[B][F*4]=q,O[B][F*4+1]=z,O[B][F*4+2]=xt,O[B][F*4+3]=te,Y[B][F*3]=Q(K.scale?.x,1),Y[B][F*3+1]=Q(K.scale?.y,1),Y[B][F*3+2]=Q(K.scale?.z,1)}}for(let F=0;F<l.length;F++){let H=l[F],B=j[F];H.position?.set(B[0],B[1],B[2]),H.quaternion?.set(B[3],B[4],B[5],B[6]),H.scale?.set(B[7],B[8],B[9])}e.updateMatrixWorld(!0);let U=null,X=()=>(U===null&&(U=p(P,"SCALAR",0,5126,T,[0],[S])),U),V=[],G=[];for(let F=0;F<l.length;F++){let H=j[F],B=(q,z,xt)=>q.some((te,ie)=>Math.abs(te-H[xt+ie%z])>1e-4),K=(q,z,xt,te)=>{q&&G.push({sampler:V.push({input:X(),interpolation:"LINEAR",output:p(z,xt,0,5126,T)})-1,target:{node:F,path:te}})};K(B(W[F],3,0),W[F],"VEC3","translation"),K(B(O[F],4,3),O[F],"VEC4","rotation"),K(B(Y[F],3,7),Y[F],"VEC3","scale")}G.length>0&&N.push({name:"ProceduralLoop",samplers:V,channels:G})}let _=Gn(a,o,e.userData),A=[],E=[],C=[];for(let S=0;S<a.length;S++){let D=a[S],T=hr(D.extras?.xr);if(!T)continue;let{ae:P,src:j,preset:W,volume:O,loop:Y,isGlobal:U}=T,X=D.name||`Node_${S}`,V=E.length;E.push({name:`${X}_source`,gain:O,loop:Y,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:A.push({uri:j})-1}:{},...W?{extras:{preset:W,pitch:Le(P.pitch,.25,4,1)}}:{}});let G=C.length,F=Le(P.refDistance,.05,100,1),H=Le(P.coneInnerAngle,0,360,360),B=Le(P.coneOuterAngle,H,360,360);C.push({name:`${X}_emitter`,type:U?"global":"positional",gain:O,sources:[V],...U?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:Le(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:Le(P.rolloffFactor,0,10,1),coneInnerAngle:+(H*Math.PI/180).toFixed(6),coneOuterAngle:+(B*Math.PI/180).toFixed(6),coneOuterGain:Le(P.coneOuterGain,0,1,0)}}}),D.extensions={...D.extensions||{},KHR_audio_emitter:{emitter:G}},h.add("KHR_audio_emitter")}let d={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:a,meshes:o,materials:c,...y.length>0?{images:y}:{},...g.length>0?{samplers:g}:{},...u.length>0?{textures:u}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...N.length>0?{animations:N}:{},..._||h.size>0?{extensionsUsed:[..._?["KHR_interactivity"]:[],...h]}:{},..._||w.length>0||C.length>0?{extensions:{..._?{KHR_interactivity:_}:{},...w.length>0?{KHR_materials_variants:{variants:w.map(S=>({name:S}))}}:{},...C.length>0?{KHR_audio_emitter:{...A.length>0?{audio:A}:{},sources:E,emitters:C}}:{}}}:{}},k=new Uint8Array(r),$=0;for(let S of i)k.set(S,$),$+=S.byteLength;return[{gltf:d,bin:k.buffer,lights:M,environmentIntensity:e.environmentIntensity},l]}function Nn(e){return new TextEncoder().encode(e)}function Qe(e,t){let{gltf:i,bin:r}=je(e,t),s=JSON.stringify(i),n=Nn(s),o=(4-n.byteLength%4)%4,a=n.byteLength+o,h=20+a+8+r.byteLength,l=new Uint8Array(h),c=new DataView(l.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,h,!0),c.setUint32(12,a,!0),c.setUint32(16,1313821514,!0),l.set(n,20);for(let y=0;y<o;y++)l[20+n.byteLength+y]=32;let f=20+a;return c.setUint32(f,r.byteLength,!0),c.setUint32(f+4,5130562,!0),l.set(new Uint8Array(r),f+8),l}function ai(e,t){let[i,r]=fr(e,t);return Ln(i,r)}function Ln(e,t){let i=[],r=e.gltf,s=ae().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,o=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),a=r.accessors||[],h=r.bufferViews||[],l=r.materials||[],c=r.meshes||[],f=r.nodes||[],y=new Set,g=l.map((w,M)=>lr(y,At(w?.name,`Material_${M}`)));function u(w){let M=a[w];if(!M)throw new Error(`Accessor ${w} not found`);let x=h[M.bufferView||0],m=(x.byteOffset||0)+(M.byteOffset||0),p=x.byteLength||0;return{acc:M,buffer:o.slice(m,m+p)}}function b(w,M,x,m){let p=[],v=c[w];if(!v)return p;let R=v.primitives||[];for(let L=0;L<R.length;L++){let I=R[L],N=I.attributes?.POSITION;if(N===void 0)continue;let{acc:_,buffer:A}=u(N),E=new Float32Array(A,0,_.count*3),C,d=I.attributes?.NORMAL;if(d!==void 0){let{acc:V,buffer:G}=u(d),F=new Float32Array(G,0,V.count*3);C=new Float32Array(F.length);for(let H=0;H<V.count;H++){let B=F[H*3],K=F[H*3+1],q=F[H*3+2],z=Math.hypot(B,K,q)||1;C[H*3]=B/z,C[H*3+1]=K/z,C[H*3+2]=q/z}}let k,$=I.attributes?.TEXCOORD_0;if($!==void 0){let{acc:V,buffer:G}=u($);k=new Float32Array(G,0,V.count*2)}let S;if(I.indices!==void 0){let{acc:V,buffer:G}=u(I.indices);S=V.componentType===5125?new Uint32Array(G,0,V.count):new Uint16Array(G,0,V.count);let F=_.count;for(let H of S)if(H>=F)throw new Error(`SecurityError: Index buffer value (${H}) out of vertex bounds [0, ${F}).`)}else{let V=_.count;S=V>65535?new Uint32Array(V):new Uint16Array(V);for(let G=0;G<V;G++)S[G]=G}let D="DefaultMaterial",T=[.8,.8,.8],P=.5,j=0,W=0,O=0,Y=1.5,U=1,X=[0,0,0];if(I.material!==void 0&&l[I.material]){let V=l[I.material];D=g[I.material]||`Material_${I.material}`;let G=V.pbrMetallicRoughness||{},F=(q,z)=>Array.isArray(q)&&q.length>=3?[q[0],q[1],q[2]]:z;T=F(G.baseColorFactor,[1,1,1]);let H=V.extras?.avgColor;Array.isArray(H)&&H.length>=3&&(T=[T[0]*H[0],T[1]*H[1],T[2]*H[2]]);let B=Array.isArray(G.baseColorFactor)&&typeof G.baseColorFactor[3]=="number"?G.baseColorFactor[3]:1;typeof G.roughnessFactor=="number"&&(P=G.roughnessFactor),typeof G.metallicFactor=="number"&&(j=G.metallicFactor),X=F(V.emissiveFactor,[0,0,0]);let K=V.extensions||{};K.KHR_materials_clearcoat&&(W=K.KHR_materials_clearcoat.clearcoatFactor??0,O=K.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof K.KHR_materials_ior?.ior=="number"&&(Y=K.KHR_materials_ior.ior),U=B*(1-(K.KHR_materials_transmission?.transmissionFactor??0))}p.push({name:R.length>1?`${M}_p${L}`:M,positions:E,indices:S,normals:C,uvs:k,materialName:D,color:T,roughness:P,metallic:j,clearcoat:W,clearcoatRoughness:O,ior:Y,opacity:U,emissiveColor:X,xrTraits:x||v.extras?.xr,...m?{invisible:!0}:{}})}return p}if(f.length>0){let w=new Float32Array(0),M=new Uint16Array(0),x=(E,C)=>{if(E===void 0)return null;let{acc:d,buffer:k}=u(E);return new Float32Array(k,0,d.count*C)},m=(E,C)=>Array.isArray(E)&&E.length>=3?[Q(E[0],C),Q(E[1],C),Q(E[2],C)]:[C,C,C],p=(E,C,d)=>E&&E.length>=(C+1)*3?[E[C*3],E[C*3+1],E[C*3+2]]:d,v=(E,C,d)=>E&&E.length>=(C+1)*4?[E[C*4],E[C*4+1],E[C*4+2],E[C*4+3]]:d,R=new Map,L=r.animations?.[0];if(L&&Array.isArray(L.channels)&&Array.isArray(L.samplers))for(let E of L.channels){let C=L.samplers[E?.sampler],d=E?.target?.node,k=E?.target?.path;if(!C||typeof d!="number"||C.input===void 0)continue;let $=R.get(d);$||($={input:C.input},R.set(d,$)),k==="translation"?$.t=C.output:k==="rotation"?$.r=C.output:k==="scale"&&($.s=C.output)}let I=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(I)||I.length===0){let E=new Set;for(let C of f)if(Array.isArray(C?.children))for(let d of C.children)E.add(d);I=[];for(let C=0;C<f.length;C++)E.has(C)||I.push(C);I.length===0&&(I=[0])}let N=new Set,_=[],A=(E,C)=>{if(Array.isArray(E))for(let d=E.length-1;d>=0;d--)_.push({idx:E[d],out:C})};for(A(I,i);_.length>0;){let{idx:E,out:C}=_.pop();if(typeof E!="number"||E<0||E>=f.length||N.has(E))continue;N.add(E);let d=f[E];if(!d)continue;let k=[0,0,0],$=[0,0,0,1],S=[1,1,1];if(Array.isArray(d.matrix)&&d.matrix.length===16){let U=mr(d.matrix);k=U.t,$=U.r,S=U.s}else k=m(d.translation,0),Array.isArray(d.rotation)&&d.rotation.length>=4&&($=[Q(d.rotation[0],0),Q(d.rotation[1],0),Q(d.rotation[2],0),Q(d.rotation[3],1)]),S=m(d.scale,1);let D,T=R.get(E);if(T){let U=x(T.input,1);if(U&&U.length>0){let X=x(T.t,3),V=x(T.r,4),G=x(T.s,3),F=Array.from(U),H=[],B=[],K=[];for(let q=0;q<U.length;q++)H.push(p(X,q,k)),B.push(v(V,q,$)),K.push(p(G,q,S));D={times:F,translations:H,rotations:B,scales:K}}}let P=Array.isArray(d.children)?d.children:[],j=typeof d.mesh=="number"&&d.mesh>=0&&d.mesh<c.length,W=t?.[E]?.userData?.xr??d.extras?.xr;if(!j&&P.length===0&&(d.camera!==void 0||d.extensions?.KHR_lights_punctual||!d.name&&!d.extras&&!W&&!D))continue;let O=(U,X,V)=>({name:U,positions:w,indices:M,isXform:!0,xrTraits:W,timeSamples:D,translation:k,rotation:$,scale:S,children:X,...V?{invisible:!0}:{}}),Y=d.visible===!1||d.extensions?.KHR_node_visibility?.visible===!1||t?.[E]?.visible===!1;if(j){let U=d.name||c[d.mesh]?.name||`Mesh_${E}`,X=b(d.mesh,U,W,Y),V=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(V&&typeof V=="object"&&X.length>0){let G=x(V.TRANSLATION,3),F=x(V.ROTATION,4),H=x(V.SCALE,3),B=x(V._COLOR_0,3),K=Math.min(1e3,G?G.length/3:F?F.length/4:H?H.length/3:0);if(K>0){let q=[];for(let z=0;z<K;z++){let xt=p(G,z,[0,0,0]),te=v(F,z,[0,0,0,1]),ie=p(H,z,[1,1,1]);for(let J of X){let ee=J.color||[.8,.8,.8],re=B&&B.length>=(z+1)*3;q.push({...J,name:`${J.name}_${z}`,materialName:re?`${J.materialName}_inst_${z}`:J.materialName,color:re?[ee[0]*B[z*3],ee[1]*B[z*3+1],ee[2]*B[z*3+2]]:J.color,translation:xt,rotation:te,scale:ie})}}A(P,q),C.push(O(U,q,Y));continue}}if(X.length===1)X[0].translation=k,X[0].rotation=$,X[0].scale=S,X[0].timeSamples=D,P.length>0&&(X[0].children=[],A(P,X[0].children)),C.push(X[0]);else{let G=[...X];A(P,G),C.push(O(U,G,Y))}}else{let U=[];A(P,U),C.push(O(d.name||`Group_${E}`,U,Y))}}}else for(let w=0;w<c.length;w++){let M=c[w].name||`Mesh_${w}`;i.push(...b(w,M,c[w].extras?.xr))}return i}function At(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function Dn(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function pe(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var Ce=(e,t,i)=>`(${pe(e)}, ${pe(t)}, ${pe(i)})`,cr=(e,t,i,r)=>`(${pe(e)}, ${pe(t)}, ${pe(i)}, ${pe(r)})`;function ur(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Ce(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ci(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${pe(e[r*2])}, ${pe(1-e[r*2+1])})`;return i.join(", ")}function ui(e){return Array.from(e).join(", ")}function In(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let u=s.pop();if(!u.isXform&&u.positions&&u.positions.length>0){let b=At(u.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}if(u.timeSamples&&u.timeSamples.times.length>0){let b=u.timeSamples.times[u.timeSamples.times.length-1];b>i&&(i=b)}if(u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal"),u.children)for(let b=u.children.length-1;b>=0;b--)s.push(u.children[b])}let n="";i>0&&(n=`startTimeCode = 0
|
|
250
|
-
endTimeCode = ${
|
|
249
|
+
void main(){fragColor=uColorId;}`;function In(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var qn=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function nr(){let e=le().xrDepthShader;return{fs:Zr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...qn,...e.uniformNames]:qn}}function ei(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Rn(e,t,i,r,s,n,a,o){if(r===void 0||!t.accessors?.[r])return null;let l=En(t,i,t.accessors[r],n);if(!l)return null;o&&(l=l.slice(),Yn(l,o));let h=e.createBuffer();return a.push(h),e.bindBuffer(34962,h),e.bufferData(34962,l,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),l}function Cn(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function rr(e,t,i){let r=nr(),s=tr,n=r.fs,a=!1;for(let l of pe)if(l.onResolveShader){let h=l.onResolveShader(t,i,s,n);h&&(s=h.vs,n=h.fs,a=!0)}let o=a?Tt(e,s,n):null;return{program:o,uniforms:o?In(e,o,r.uniforms):null}}function ti(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,a=new Float32Array(s*20);for(let l=0;l<s;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=n?n[l*3]:1,a[l*20+17]=n?n[l*3+1]:1,a[l*20+18]=n?n[l*3+2]:1,a[l*20+19]=1;let o=e.createBuffer();i.push(o),e.bindBuffer(34962,o),e.bufferData(34962,a,35044);for(let l=0;l<5;l++)e.enableVertexAttribArray(8+l),e.vertexAttribPointer(8+l,4,5126,!1,80,l*16),e.vertexAttribDivisor(8+l,1);return!0}function ni(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Gi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ir=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function _t(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function sr(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=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:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function or(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let a of n.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)e.deleteBuffer(l);s(a.texture),s(a.metallicRoughnessTexture),s(a.normalTexture),s(a.occlusionTexture);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)e.deleteProgram(l)}if(i)for(let n of i)s(n)}function Zn(e,t,i=ir,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ri(e,t,i,r,s)}catch(n){let a=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;or(e,a,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let o of s.buffers)e.deleteBuffer(o);throw n}}function ri(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,a=je("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(n,t);let o=t.bin,l=[];s.meshes=l;let h=[],u=n.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((E,y)=>{h.push(typeof E?.name=="string"&&E.name?E.name:`Variant_${y}`)});let f=Kn(n),g=[];if(Array.isArray(n.nodes))for(let E=0;E<n.nodes.length;E++){let y=n.nodes[E];y.mesh!==void 0&&n.meshes&&n.meshes[y.mesh]&&g.push({node:y,nodeIdx:E,meshIdx:y.mesh})}let w=g.length>0?g:(n.meshes||[]).map((E,y)=>({node:E,nodeIdx:-1,meshIdx:y})),p=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let E of b)p.push({...E,type:E.type||E.light_type||"point",innerConeAngle:E.innerConeAngle??E.inner_cone_angle,outerConeAngle:E.outerConeAngle??E.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let E=n.extensions.KHR_lights_punctual.lights;for(let y of E){let F=y.type==="directional"?"directional":y.type==="point"?"point":y.type==="spot"?"spot":"ambient";p.push({type:F,color:y.color||[1,1,1],intensity:y.intensity!==void 0?y.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]})),w.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${w.length}`);let T=[];if(s.gpuTextures=T,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let E=0;E<n.textures.length;E++){let y=n.textures[E],F=n.images[y.source];if(F){let z=e.createTexture();e.bindTexture(3553,z),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let A=_=>{e.bindTexture(3553,z),e.texImage2D(3553,0,6408,6408,5121,_),e.generateMipmap(3553),r?.()};if(F.bufferView!==void 0){let _=n.bufferViews[F.bufferView],d=_.byteOffset||0,R=new Blob([o.slice(d,d+_.byteLength)],{type:F.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(R).then(A).catch(()=>{})}else if(F.uri){let _=ei(F.uri);if(_){let d=new Image;d.crossOrigin="anonymous",d.referrerPolicy="no-referrer",d.onload=()=>A(d),d.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",F.uri)}T.push(z)}else T.push(null)}}let x=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],c=0,m=0;for(let E=0;E<w.length;E++){let y=w[E],F=n.meshes[y.meshIdx],z=y.nodeIdx>=0?f[y.nodeIdx]:he(),A=new Float32Array(9);Ce(A,z);let _={name:y.node.name||F.name||`Mesh_${y.meshIdx}`,nodeIndex:y.nodeIdx,transform:z,normalMatrix:A,primitives:[],extras:y.node.extras||F.extras,...y.node?.visible===!1||y.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=_;let d=y.node?.extensions?.EXT_mesh_gpu_instancing;if(d&&d.attributes&&typeof d.attributes=="object"){let R=d.attributes,G=R.TRANSLATION!==void 0?n.accessors?.[R.TRANSLATION]:null,H=R.ROTATION!==void 0?n.accessors?.[R.ROTATION]:null,B=R.SCALE!==void 0?n.accessors?.[R.SCALE]:null,Z=R._COLOR_0!==void 0?n.accessors?.[R._COLOR_0]:null,k=Number(G?.count??H?.count??B?.count??0);if(!Number.isFinite(k)||k<0||k>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${k}`);if(k>0){let Y=(U,$)=>{if(!U||U.bufferView===void 0||!n.bufferViews?.[U.bufferView])return null;let j=U.componentType??5126,q=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(j!==5120&&j!==5121&&j!==5122&&j!==5123&&j!==5126)return q(`componentType ${j}`);if(!(Number(U.count)>=k))return q(`count ${U.count} < ${k}`);let K=null;try{K=En(n,o,{...U,count:k},$)}catch{return q("out of bounds")}return!K||!K.every(Number.isFinite)?q("non-finite value"):K},ie=Y(G,3),re=Y(H,4),O=Y(B,3),J=Z?.type==="VEC4"?4:3,V=Y(Z,J),W=new Float32Array(k*16),X=he();for(let U=0;U<k;U++){let $=ie?[ie[U*3],ie[U*3+1],ie[U*3+2]]:[0,0,0],j=re?[re[U*4],re[U*4+1],re[U*4+2],re[U*4+3]]:[0,0,0,1],q=O?[O[U*3],O[U*3+1],O[U*3+2]]:[1,1,1];Qe(X,j,$,q),W.set(X,U*16)}if(_.instanceMatrices=W,V){let U=new Float32Array(k*3);for(let $=0;$<k;$++)U[$*3]=V[$*J],U[$*3+1]=V[$*J+1],U[$*3+2]=V[$*J+2];_.instanceColors=U}}}for(let R of F.primitives||[]){if(R.extensions?.KHR_draco_mesh_compression){let K=je("draco");K&&K.decodePrimitive(n,R,o)}let G=[],H=e.createVertexArray();s.vao=H,s.buffers=G,e.bindVertexArray(H);let B=ti(e,_,G),Z=n.accessors[R.attributes.POSITION],k=Number(Z?.count??0);if(!Number.isFinite(k)||k<0||c+k>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(c+=k,Z?.min&&Z?.max){let K=Q=>{for(let te=0;te<3;te++){let fe=Q[12+te],se=Q[12+te];for(let ae=0;ae<3;ae++){let oe=Q[ae*4+te]*Z.min[ae],ce=Q[ae*4+te]*Z.max[ae];fe+=oe<ce?oe:ce,se+=oe>ce?oe:ce}fe<x[te]&&(x[te]=fe),se>M[te]&&(M[te]=se)}};if(_.instanceMatrices&&_.instanceMatrices.length>=16){let Q=_.instanceMatrices.length>>4,te=he();for(let fe=0;fe<Q;fe++){let se=_.instanceMatrices.subarray(fe*16,fe*16+16);be(te,z,se),K(te)}}else K(z)}let Y=Rn(e,n,o,R.attributes.POSITION,0,3,G);Rn(e,n,o,R.attributes.NORMAL,1,3,G),Rn(e,n,o,R.attributes.TEXCOORD_0,2,2,G,ni(n,R));let ie=0,re=5123,O=null;if(R.indices!==void 0){let K=n.accessors[R.indices],Q=(n.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(ie=Number(K.count??0),!Number.isFinite(ie)||ie<0||m+ie>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);m+=ie,re=K.componentType===5125?5125:5123;let te=e.createBuffer();G.push(te),e.bindBuffer(34963,te),K.componentType===5125?O=new Uint32Array(o,Q,K.count):K.componentType===5121?O=Uint16Array.from(new Uint8Array(o,Q,K.count)):O=Q%2===0?new Uint16Array(o,Q,K.count):new Uint16Array(o.slice(Q,Q+K.count*2)),e.bufferData(34963,O,35044)}else ie=Z.count;let J={};for(let K of pe)if(K.onBuildPrimitiveVAO){let Q=K.onBuildPrimitiveVAO(e,H,R,n,o);Q&&(J[K.name]=Q)}e.bindVertexArray(null);let V=n.materials&&R.material!==void 0?n.materials[R.material]:null,{program:W,uniforms:X}=rr(e,R,V),U=sr(V,T),$=!!(V?.extensions?.KHR_materials_transmission||J.materials?.isTransmissive),j=R.extensions?.KHR_materials_variants?.mappings,q=Array.isArray(j)?j.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(Q=>Number(Q)|0)})):void 0;_.primitives.push({vao:H,instanced:B,indexCount:ie,indexType:re,...U,positions:Y,indices:O,buffers:G,materialIndex:R.material,defaultMaterialIndex:R.material,variantMappings:q,primitiveDef:R,programCache:new Map([[R.material??-1,{program:W,uniforms:X}]]),pluginData:J,customProgram:W,customUniforms:X,isTransmissive:$})}l.push(_)}isFinite(x[0])||(x=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let v=[(x[0]+M[0])/2,(x[1]+M[1])/2,(x[2]+M[2])/2],S=M[0]-x[0],D=M[1]-x[1],I=M[2]-x[2],P=Math.max(Math.hypot(S,D,I)/2,.5),N=[x[0],x[1],x[2]],C=[M[0],M[1],M[2]],L=t.animations;if(!L){for(let E of pe)if(E.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:l,bounds:{center:v,radius:P,min:N,max:C},lights:p,animations:L,worldMatrices:f,gpuTextures:T,availableVariants:h}}function et(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var St=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=he(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=he(),this.viewMatrix=he(),this.activeViewMatrix=null,this.modelMatrix=he(),this.mvpMatrix=he(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:he(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),r=o}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(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=Cn(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=Dn(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 a=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!a)throw new Error("WebGL2 not supported");this.gl=a,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Yr(e,t)}static getDecoder(e){return je(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=nr();this.renderProg=Tt(e,tr,t.fs),this.pickProg=Tt(e,Jr,Qr),this.uRender=In(e,this.renderProg,t.uniforms),this.uPick=In(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of pe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:a,gpuTextures:o,availableVariants:l}=Zn(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of pe)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let h=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;h!==void 0&&(this.exposure=Cn(h));let u=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(er(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of pe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(wt(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=wt(e),{meshes:r}=Zn(this.gl,i,ir,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Ce(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Ce(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],a=[],o=[],l=[];for(let h of this.lights){let u=h.color||[1,1,1],f=h.intensity!==void 0?h.intensity:1;if(h.type==="ambient")i=[u[0]*f,u[1]*f,u[2]*f];else if(h.type==="directional"&&r.length<6){let g=h.direction||[.5,1,.8];r.push(g[0],g[1],g[2]),s.push(u[0]*f,u[1]*f,u[2]*f)}else if((h.type==="point"||h.type==="spot")&&n.length<6){let g=h.position||[0,0,0];if(n.push(g[0],g[1],g[2]),a.push(u[0]*f,u[1]*f,u[2]*f),h.type==="spot"){let w=h.direction||[0,-1,0],p=Math.max(.01,Math.min(Math.PI/2,h.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(p-1e-4,h.innerConeAngle??0));o.push(w[0],w[1],w[2]),l.push(Math.cos(b),Math.cos(p))}else o.push(0,-1,0),l.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,a),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Cn(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Dn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of pe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of pe)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(h=>h.primitives.filter(u=>u.materialIndex===i||e.length===1&&u.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:n,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:h=>{let u=[h[0],h[1],h[2],h[3]??1];l.baseColorFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=u);for(let f of r)f.baseColor=u;this.render()},setMetallicFactor:h=>{l.metallicFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=h);for(let u of r)u.metallic=h;this.render()},setRoughnessFactor:h=>{l.roughnessFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);for(let u of r)u.roughness=h;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let a=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let l of n.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;n.materialIndex=o?a:void 0,Object.assign(n,sr(o,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=rr(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of pe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=he();be(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,a=t?t[0]:0,o=t?t[1]:0,l=t?t[2]:0,h=this.modelRootMatrix;h&&(r=h[0]*e[0]+h[4]*e[1]+h[8]*e[2]+h[12],s=h[1]*e[0]+h[5]*e[1]+h[9]*e[2]+h[13],n=h[2]*e[0]+h[6]*e[1]+h[10]*e[2]+h[14],t&&(a=h[0]*t[0]+h[4]*t[1]+h[8]*t[2],o=h[1]*t[0]+h[5]*t[1]+h[9]*t[2],l=h[2]*t[0]+h[6]*t[1]+h[10]*t[2]));let u=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],g=i[2]*r+i[6]*s+i[10]*n+i[14],w=i[3]*r+i[7]*s+i[11]*n+i[15];if(w<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=u/w,b=f/w,T=g/w,x=this.canvas.getBoundingClientRect(),M=x.width||this.canvas.clientWidth||this.canvas.width||300,c=x.height||this.canvas.clientHeight||this.canvas.height||150,m=(p*.5+.5)*M,v=(-b*.5+.5)*c,S=p>=-1.1&&p<=1.1&&b>=-1.1&&b<=1.1&&T>=-1&&T<=1;if(S&&t){let[D,I,P]=et(this),N=[r-D,s-I,n-P];a*N[0]+o*N[1]+l*N[2]>.05&&(S=!1)}return{x:m,y:v,z:T,visible:S}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],h=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-s*a[0]+n*o[0])*h,l[1]+=(-s*a[1]+n*o[1])*h,l[2]+=(-s*a[2]+n*o[2])*h,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,a=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),o=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(a,o,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let a=he();be(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(s-1,e)),h=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let S=this.meshes[v];if(S.visible===!1||S.isPluginMesh)continue;let D=v+1,I=(D&255)/255,P=(D>>8&255)/255,N=(D>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,P,N,1),be(this.modelMatrix,this.modelRootMatrix,S.transform);let C=S.instanceMatrices;if(C&&C.length>=16){let L=C.length>>4,E=he();for(let y of S.primitives){r.bindVertexArray(y.vao);for(let F=0;F<L;F++)be(E,this.modelMatrix,C.subarray(F*16,F*16+16)),be(this.mvpMatrix,a,E),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),_t(r,y)}}else{be(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of S.primitives)r.bindVertexArray(L.vao),_t(r,L)}}let c=new Uint8Array(4);r.readPixels(l,h,1,1,6408,5121,c),r.bindFramebuffer(36160,null);let m=c[0]+(c[1]<<8)+(c[2]<<16);m>0&&m<=this.meshes.length&&(o=[this.meshes[m-1]])}o.length===0&&(o=this.meshes.filter(c=>c.visible!==!1));let u=null,f=1/0,g=[0,0,0],w=[0,1,0],[p,b,T]=et(this),x=he();for(let c of o){be(x,this.modelRootMatrix,c.transform);let m=c.instanceMatrices,v=m&&m.length>=16?m.length>>4:1;for(let S=0;S<v;S++){m&&m.length>=16?be(this.modelMatrix,x,m.subarray(S*16,S*16+16)):this.modelMatrix.set(x),be(this.mvpMatrix,a,this.modelMatrix);let D=he();if(!Wn(D,this.mvpMatrix))continue;let I=(l+.5)/s*2-1,P=(h+.5)/n*2-1,N=[0,0,0],C=[0,0,0];An(N,I,P,-1,D),An(C,I,P,1,D);let L=C[0]-N[0],E=C[1]-N[1],y=C[2]-N[2],F=Math.hypot(L,E,y)||1,z=L/F,A=E/F,_=y/F,d={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((R=>{for(let G of c.primitives){if(!G.positions)continue;let H=G.positions,B=G.indices,Z=Math.floor(B?B.length/3:H.length/9);for(let k=0;k<Z;k++){let Y=B?B[k*3]:k*3,ie=B?B[k*3+1]:k*3+1,re=B?B[k*3+2]:k*3+2;jn(N[0],N[1],N[2],z,A,_,H[Y*3],H[Y*3+1],H[Y*3+2],H[ie*3],H[ie*3+1],H[ie*3+2],H[re*3],H[re*3+1],H[re*3+2],d,R)}}})(1e-4),isFinite(d.distance)){let R=d.point[0],G=d.point[1],H=d.point[2],B=this.modelMatrix,Z=B[0]*R+B[4]*G+B[8]*H+B[12],k=B[1]*R+B[5]*G+B[9]*H+B[13],Y=B[2]*R+B[6]*G+B[10]*H+B[14],ie=Z-p,re=k-b,O=Y-T,J=Math.hypot(ie,re,O);if(J<f){Ce(this.normalMatrix,this.modelMatrix);let V=this.normalMatrix,W=d.normal[0],X=d.normal[1],U=d.normal[2],$=V[0]*W+V[3]*X+V[6]*U,j=V[1]*W+V[4]*X+V[7]*U,q=V[2]*W+V[5]*X+V[8]*U,K=Math.hypot($,j,q)||1;$/=K,j/=K,q/=K,$*ie+j*re+q*O>0&&($=-$,j=-j,q=-q),u=c,f=Math.round(J*1e3)/1e3,g=[Math.round(Z*1e3)/1e3,Math.round(k*1e3)/1e3,Math.round(Y*1e3)/1e3],w=[Math.round($*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(q*1e3)/1e3]}}}}if(!u)return null;let M={meshIndex:this.meshes.indexOf(u),meshName:u.name,nodeIndex:u.nodeIndex,distance:f,hitPoint:g,normal:w,screenX:e,screenY:t};if(i){for(let c of pe)c.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,a=(s+.5)/n*2-1;return Math.floor((a*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Mt(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;We(this.viewMatrix,et(this),i,[0,1,0]),be(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of pe)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of pe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of pe)n.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let n of pe)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let a=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,h=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:a,projMatrix:o,eyePos:h,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let M=Math.max(2,this.canvas.width||2),c=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(M*.5)),v=Math.max(1,M-m),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),D=this.customTarget||this.bounds.center,[I,P,N]=et(this),C=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),E=.032,y=he(),F=he(),z=[I-C*E,P,N-L*E],A=[D[0]-C*E*.25,D[1],D[2]-L*E*.25];Mt(y,this.fov,m/c,.1,S),We(F,z,A,[0,1,0]);let _=he(),d=he(),R=[I+C*E,P,N+L*E],G=[D[0]+C*E*.25,D[1],D[2]+L*E*.25];Mt(_,this.fov,v/c,.1,S),We(d,R,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:y,eyePos:z,viewport:[0,0,m,c],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:d,projMatrix:_,eyePos:R,viewport:[m,0,v,c],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,M,c);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let a=he(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,be(a,e?.projMatrix??this.projMatrix,o);let l=le().xrDepthShader,h=jr(this.toneMapping),[u,f,g]=e?e.eyePos:et(this);for(let M of pe)M.onBeforeDrawScene?.(this,t,a,[u,f,g],h);let w=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&w===0)return;let p=e?.eye||"none",b=!1,T=w>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=M=>{for(let c=0;c<T.length;c++){let m=T[c];if(m.visible===!1)continue;let v=this.selectedMeshName!==""&&m.name===this.selectedMeshName;c<w||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):be(this.modelMatrix,this.modelRootMatrix,m.transform),be(this.mvpMatrix,a,this.modelMatrix),Ce(m.normalMatrix,this.modelMatrix);let S=m.extras?.xr?.stereo||m.userData?.xr?.stereo,D=0,I=0,P=1,N=1;S==="sbs"?(P=.5,D=p==="right"?.5:0):S==="ou"&&(N=.5,I=p==="right"?.5:0);for(let C of m.primitives){let L=!!C.isTransmissive;if(!M&&L){b=!0;continue}if(M&&!L)continue;let E=C.customProgram||this.renderProg,y=C.customUniforms||this.uRender;t.useProgram(E),t.vertexAttrib3f(3,0,0,0),y.uInstanced&&t.uniform1i(y.uInstanced,0),t.uniform1i(y.uToneMapping,h),t.uniform1f(y.uEnvIntensity,this.envIntensity),y.uExposure&&t.uniform1f(y.uExposure,this.exposure),t.uniform3f(y.uCameraPos,u,f,g),t.uniform1f(y.uEmissive,v?1:0),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(y.uNormalMatrix,!1,m.normalMatrix),y.uUvTransform&&t.uniform4f(y.uUvTransform,D,I,P,N),y.uViewportSize&&t.uniform2f(y.uViewportSize,Math.max(1,s),Math.max(1,n)),l?.bind(t,y,this.xrDepthState,o,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(y.uEnvironmentMap,4),t.uniform1i(y.uHasEnvironmentMap,1)):t.uniform1i(y.uHasEnvironmentMap,0),this.bindLights(y),y.uSectionEnabled&&t.uniform1i(y.uSectionEnabled,0);for(let z of pe)z.onBeforeDrawPrimitive?.(t,E,C,m,this.worldMatrices||[],this.gltf);t.uniform4fv(y.uBaseColor,C.baseColor),t.uniform1f(y.uMetallic,C.metallic),t.uniform1f(y.uRoughness,C.roughness),y.uClearcoat&&t.uniform2f(y.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(t.activeTexture(33984),t.bindTexture(3553,C.texture),t.uniform1i(y.uBaseColorTexture,0),t.uniform1i(y.uHasTexture,1)):t.uniform1i(y.uHasTexture,0),C.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,C.metallicRoughnessTexture),t.uniform1i(y.uMetallicRoughnessTexture,1),t.uniform1i(y.uHasMetallicRoughnessTexture,1)):t.uniform1i(y.uHasMetallicRoughnessTexture,0),C.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,C.normalTexture),t.uniform1i(y.uNormalTexture,2),t.uniform1i(y.uHasNormalTexture,1),t.uniform1f(y.uNormalScale,C.normalScale)):t.uniform1i(y.uHasNormalTexture,0),C.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,C.occlusionTexture),t.uniform1i(y.uOcclusionTexture,3),t.uniform1i(y.uHasOcclusionTexture,1),t.uniform1f(y.uOcclusionStrength,C.occlusionStrength)):t.uniform1i(y.uHasOcclusionTexture,0),t.bindVertexArray(C.vao);let F=m.instanceMatrices;if(C.instanceCount!==void 0)t.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(F&&F.length>=16&&C.instanced&&y.uInstanced&&y.uViewProj){let z=F.length>>4;t.uniform1i(y.uInstanced,1),t.uniformMatrix4fv(y.uViewProj,!1,a),C.indices?t.drawElementsInstanced(4,C.indexCount,C.indexType,0,z):t.drawArraysInstanced(4,0,C.indexCount,z),t.uniform1i(y.uInstanced,0)}else if(F&&F.length>=16){let z=F.length>>4,A=m.instanceColors,_=he(),d=new Float32Array(9),R=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let G=0;G<z;G++)be(_,this.modelMatrix,F.subarray(G*16,G*16+16)),be(this.mvpMatrix,a,_),Ce(d,_),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,_),t.uniformMatrix3fv(y.uNormalMatrix,!1,d),A&&(R[0]=C.baseColor[0]*A[G*3],R[1]=C.baseColor[1]*A[G*3+1],R[2]=C.baseColor[2]*A[G*3+2],R[3]=C.baseColor[3],t.uniform4fv(y.uBaseColor,R)),_t(t,C)}else _t(t,C)}}};if(x(!1),b){for(let M of pe)M.onBeforeTransmissivePass?.(t,this);x(!0)}for(let M of pe)M.onAfterRender?.(t,this,a,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){or(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of pe)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};St.registerPlugin=$n,St.getRegisteredPlugins=Xn;function ii(e){return e+3&-4}var ne=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function cr(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ur(e,t=0){let[i,r,s,,n,a,o,,l,h,u,,f,g,w]=Array.from({length:15},(d,R)=>ne(e[t+R],R%5===0?1:0)),p=Math.hypot(i,r,s),b=Math.hypot(n,a,o),T=Math.hypot(l,h,u);i*(a*u-h*o)-n*(r*u-h*s)+l*(r*o-a*s)<0&&(p=-p);let x=Math.abs(p)>1e-8?1/p:0,M=Math.abs(b)>1e-8?1/b:0,c=Math.abs(T)>1e-8?1/T:0,m=i*x,v=r*x,S=s*x,D=n*M,I=a*M,P=o*M,N=l*c,C=h*c,L=u*c,E=m+I+L,y=0,F=0,z=0,A=1;if(E>0){let d=.5/Math.sqrt(E+1);A=.25/d,y=(P-C)*d,F=(N-S)*d,z=(v-D)*d}else if(m>I&&m>L){let d=2*Math.sqrt(Math.max(0,1+m-I-L));d>1e-8&&(A=(P-C)/d,y=.25*d,F=(D+v)/d,z=(N+S)/d)}else if(I>L){let d=2*Math.sqrt(Math.max(0,1+I-m-L));d>1e-8&&(A=(N-S)/d,y=(D+v)/d,F=.25*d,z=(P+C)/d)}else{let d=2*Math.sqrt(Math.max(0,1+L-m-I));d>1e-8&&(A=(v-D)/d,y=(N+S)/d,F=(P+C)/d,z=.25*d)}let _=Math.hypot(y,F,z,A);return _>1e-8&&Number.isFinite(_)?(y/=_,F/=_,z/=_,A/=_):(y=0,F=0,z=0,A=1),{t:[f,g,w],r:[y,F,z,A],s:[p,b,T]}}function si(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Ue=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function lr(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:Ue(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Ke(e,t){return mr(e,t)[0]}function mr(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],a=[],o=[],l=new Set,h=[],u=[],f=new Map,g=[],w=[],p=[],b=new Map,T=[],x=[];function M(A){let _=f.get(A);if(_!==void 0)return _;_=u.length,f.set(A,_);let d=A,R=d.color?.r??1,G=d.color?.g??1,H=d.color?.b??1,B=d.opacity??1,Z={baseColorFactor:[R,G,H,B],metallicFactor:d.metalness??0,roughnessFactor:d.roughness??.5},k={},Y=$=>{if(!$)return;let j=(typeof $=="string"?$:typeof $.source=="string"?$.source:typeof $.image=="string"?$.image:"").trim();if(!j||/[\x00-\x1f\x7f\\]|\.\./.test(j)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(j)||!j.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(j)))return;let q=b.get(j);if(q===void 0){let K=g.length;g.push({uri:j}),w.length===0&&w.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),q=p.length,p.push({sampler:0,source:K}),b.set(j,q)}return{index:q}},ie=Y(d.map);ie&&(Z.baseColorTexture=ie);let re=Y(d.roughnessMap||d.metalnessMap);re&&(Z.metallicRoughnessTexture=re);let O=d.map?.avgColor;Array.isArray(O)&&O.length>=3&&(k.avgColor=[O[0],O[1],O[2]]);let J=Y(d.normalMap),V=Y(d.emissiveMap),W=Y(d.aoMap),X={name:d.name||"",pbrMetallicRoughness:Z,doubleSided:d.side===2||!!d.doubleSided,...J?{normalTexture:J}:{},...V?{emissiveTexture:V}:{},...W?{occlusionTexture:W}:{},...Object.keys(k).length>0?{extras:k}:{}};if(d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let $=d.emissiveIntensity??1;X.emissiveFactor=[d.emissive.r*$,d.emissive.g*$,d.emissive.b*$]}let U={};return d.clearcoat&&d.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:d.clearcoat,clearcoatRoughnessFactor:d.clearcoatRoughness||0}),d.sheen&&d.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:d.sheenColor?[d.sheenColor.r,d.sheenColor.g,d.sheenColor.b]:[1,1,1],sheenRoughnessFactor:d.sheenRoughness||0}),d.transmission&&d.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:d.transmission}),d.thickness&&d.thickness>0&&(U.KHR_materials_volume={thicknessFactor:d.thickness,attenuationDistance:d.attenuationDistance??1/0,attenuationColor:d.attenuationColor?[d.attenuationColor.r,d.attenuationColor.g,d.attenuationColor.b]:[1,1,1]}),d.ior!==void 0&&d.ior!==1.5&&(U.KHR_materials_ior={ior:d.ior}),d.dispersion&&d.dispersion>0&&(U.KHR_materials_dispersion={dispersion:d.dispersion}),d.iridescence&&d.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:d.iridescence,iridescenceIor:d.iridescenceIOR??1.3}),Object.keys(U).length>0&&(X.extensions=U),u.push(X),_}function c(A,_){let d=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),R=ii(d.byteLength),G=new Uint8Array(R);G.set(d),i.push(G);let H=s.length;return s.push({buffer:0,byteOffset:r,byteLength:d.byteLength,target:_}),r+=R,H}function m(A,_,d,R,G,H,B){let Z=c(A,d),k=n.length,Y={bufferView:Z,byteOffset:0,componentType:R,count:G,type:_};return H&&(Y.min=H),B&&(Y.max=B),n.push(Y),k}e.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let _=A.matrixWorld?.elements,d=ne(_?_[12]:A.position?.x,0),R=ne(_?_[13]:A.position?.y,0),G=ne(_?_[14]:A.position?.z,0),H=A.target,B=H?.parent?H?.matrixWorld?.elements:void 0,Z=ne(B?B[12]:H?.position?.x,0),k=ne(B?B[13]:H?.position?.y,0),Y=ne(B?B[14]:H?.position?.z,0),ie=Z-d,re=k-R,O=Y-G,J=Math.hypot(ie,re,O),V=Math.max(.01,Math.min(Math.PI/2,ne(A.angle,Math.PI/3))),W=Math.max(0,Math.min(1,ne(A.penumbra,0)));x.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[d,R,G],...A.type==="spot"?{direction:J>1e-6?[ie/J,re/J,O/J]:[0,-1,0],outerConeAngle:V,innerConeAngle:Math.max(0,V*(1-W)),range:Math.max(0,ne(A.distance,0))}:A.type==="point"?{range:Math.max(0,ne(A.distance,0))}:{}})}});let v=[],S=new Set([e]),D=[];if(Array.isArray(e.children))for(let A=e.children.length-1;A>=0;A--)D.push({obj:e.children[A],parentKids:v});for(;D.length>0;){let{obj:A,parentKids:_}=D.pop();if(!A||typeof A!="object"||S.has(A))continue;S.add(A),A._bakeAuthorGeometry?.(),le().materializeDeclarativeGeometry?.(A);let d=!!(A.userData&&(A.userData.xr&&typeof A.userData.xr=="object"&&Object.keys(A.userData.xr).length>0||A.userData.interactivity&&typeof A.userData.interactivity=="object"&&Object.keys(A.userData.interactivity).length>0)),R={name:A.name||(d?`Node_${o.length}`:"")},G=ne(A.position?.x,0),H=ne(A.position?.y,0),B=ne(A.position?.z,0),Z=ne(A.quaternion?.x,0),k=ne(A.quaternion?.y,0),Y=ne(A.quaternion?.z,0),ie=ne(A.quaternion?.w,1),re=ne(A.scale?.x,1),O=ne(A.scale?.y,1),J=ne(A.scale?.z,1);if((G||H||B)&&(R.translation=[G,H,B]),(Z||k||Y||ie!==1)&&(R.rotation=[Z,k,Y,ie]),(re!==1||O!==1||J!==1)&&(R.scale=[re,O,J]),A.visible===!1&&(R.extensions={...R.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(R.extras=JSON.parse(JSON.stringify(A.userData,(X,U)=>{if(!(X==="__proto__"||X==="prototype"||X==="constructor"))return typeof U=="function"?void 0:U})),A.userData.xr)){let X=si(A.userData.xr);R.extensions={...R.extensions||{},MOZ_hubs_components:X,ANDROID_xr_scenecore:X},le().xrTraitSerializer?.gltfNode(R,A.userData.xr),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let X=A.geometry,U=X.attributes.position;if(U&&U.count>0){let $=[1/0,1/0,1/0],j=[-1/0,-1/0,-1/0];for(let se=0;se<U.count;se++){let ae=U.getX(se),oe=U.getY(se),ce=U.getZ(se);ae<$[0]&&($[0]=ae),ae>j[0]&&(j[0]=ae),oe<$[1]&&($[1]=oe),oe>j[1]&&(j[1]=oe),ce<$[2]&&($[2]=ce),ce>j[2]&&(j[2]=ce)}let q={attributes:{POSITION:m(U.array,"VEC3",34962,5126,U.count,$,j)}};if(X.attributes.normal&&(q.attributes.NORMAL=m(X.attributes.normal.array,"VEC3",34962,5126,X.attributes.normal.count)),X.attributes.uv&&(q.attributes.TEXCOORD_0=m(X.attributes.uv.array,"VEC2",34962,5126,X.attributes.uv.count)),X.index){let se=X.index.array instanceof Uint32Array;q.indices=m(X.index.array,"SCALAR",34963,se?5125:5123,X.index.count)}let K=Array.isArray(A.material)?A.material[0]:A.material;K&&(q.material=M(K));let Q=A.userData?.variants;if(Q&&typeof Q=="object"){let se=new Map;for(let ae of Object.keys(Q)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let oe=Q[ae];if(!oe||typeof oe!="object")continue;let ce=T.indexOf(ae);if(ce===-1&&T.length<256&&(ce=T.length,T.push(ae)),ce===-1)continue;let Te=M(oe),Re=se.get(Te);Re||(Re=[],se.set(Te,Re)),Re.push(ce)}if(se.size>0){let ae=[];for(let[oe,ce]of se.entries())ae.push({material:oe,variants:ce});q.extensions={...q.extensions||{},KHR_materials_variants:{mappings:ae}},l.add("KHR_materials_variants")}}let te=A;if(te.isInstancedMesh&&typeof te.count=="number"&&te.count>0&&te.instanceMatrix?.array){let se=Math.min(1e4,Math.floor(te.count)),ae=te.instanceMatrix.array,oe=new Float32Array(se*3),ce=new Float32Array(se*4),Te=new Float32Array(se*3);for(let me=0;me<se;me++){let{t:Ne,r:Ee,s:Xe}=ur(ae,me*16);oe[me*3]=Ne[0],oe[me*3+1]=Ne[1],oe[me*3+2]=Ne[2],ce[me*4]=Ee[0],ce[me*4+1]=Ee[1],ce[me*4+2]=Ee[2],ce[me*4+3]=Ee[3],Te[me*3]=Xe[0],Te[me*3+1]=Xe[1],Te[me*3+2]=Xe[2]}let Re={TRANSLATION:m(oe,"VEC3",0,5126,se),ROTATION:m(ce,"VEC4",0,5126,se),SCALE:m(Te,"VEC3",0,5126,se)};if(te.instanceColor?.array&&te.instanceColor.array.length>=se*3){let me=new Float32Array(te.instanceColor.array.subarray(0,se*3));Re._COLOR_0=m(me,"VEC3",0,5126,se)}R.extensions={...R.extensions||{},EXT_mesh_gpu_instancing:{attributes:Re}},l.add("EXT_mesh_gpu_instancing")}let fe=a.length;a.push({primitives:[q],name:A.name,...R.extras?{extras:R.extras}:{}}),R.mesh=fe}}let V=o.length;o.push(R),h.push(A),_.push(V);let W=A.children;if(Array.isArray(W)&&W.length>0){let X=[];R.children=X;for(let U=W.length-1;U>=0;U--)D.push({obj:W[U],parentKids:X})}}for(let A=0;A<o.length;A++){let _=o[A];_.children&&_.children.length===0?delete _.children:_.children&&_.children.length>0&&(_.extras?.xr?.lod||_.extensions?.ANDROID_xr_scenecore?.lod||h[A]?.isLOD)&&(_.extensions={..._.extensions||{},MSFT_lod:{ids:[..._.children]}},l.add("MSFT_lod"))}let I=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),P=[];if(typeof I=="function"&&h.length>0){let A=t?.duration??4,_=t?.fps??15,d=Math.max(2,Math.round(A*_)+1),R=new Float32Array(d),G=h.map(O=>[ne(O.position?.x,0),ne(O.position?.y,0),ne(O.position?.z,0),ne(O.quaternion?.x,0),ne(O.quaternion?.y,0),ne(O.quaternion?.z,0),ne(O.quaternion?.w,1),ne(O.scale?.x,1),ne(O.scale?.y,1),ne(O.scale?.z,1)]),H=h.map(()=>new Float32Array(d*3)),B=h.map(()=>new Float32Array(d*4)),Z=h.map(()=>new Float32Array(d*3));for(let O=0;O<d;O++){let J=O/(d-1)*A;R[O]=J;try{I(J)}catch{}for(let V=0;V<h.length;V++){let W=h[V];H[V][O*3]=ne(W.position?.x,0),H[V][O*3+1]=ne(W.position?.y,0),H[V][O*3+2]=ne(W.position?.z,0);let X=ne(W.quaternion?.x,0),U=ne(W.quaternion?.y,0),$=ne(W.quaternion?.z,0),j=ne(W.quaternion?.w,1),q=Math.hypot(X,U,$,j)||1;if(X/=q,U/=q,$/=q,j/=q,O>0){let K=(O-1)*4,Q=B[V];Q[K]*X+Q[K+1]*U+Q[K+2]*$+Q[K+3]*j<0&&(X=-X,U=-U,$=-$,j=-j)}B[V][O*4]=X,B[V][O*4+1]=U,B[V][O*4+2]=$,B[V][O*4+3]=j,Z[V][O*3]=ne(W.scale?.x,1),Z[V][O*3+1]=ne(W.scale?.y,1),Z[V][O*3+2]=ne(W.scale?.z,1)}}for(let O=0;O<h.length;O++){let J=h[O],V=G[O];J.position?.set(V[0],V[1],V[2]),J.quaternion?.set(V[3],V[4],V[5],V[6]),J.scale?.set(V[7],V[8],V[9])}e.updateMatrixWorld(!0);let k=null,Y=()=>(k===null&&(k=m(R,"SCALAR",0,5126,d,[0],[A])),k),ie=[],re=[];for(let O=0;O<h.length;O++){let J=G[O],V=(X,U,$)=>X.some((j,q)=>Math.abs(j-J[$+q%U])>1e-4),W=(X,U,$,j)=>{X&&re.push({sampler:ie.push({input:Y(),interpolation:"LINEAR",output:m(U,$,0,5126,d)})-1,target:{node:O,path:j}})};W(V(H[O],3,0),H[O],"VEC3","translation"),W(V(B[O],4,3),B[O],"VEC4","rotation"),W(V(Z[O],3,7),Z[O],"VEC3","scale")}re.length>0&&P.push({name:"ProceduralLoop",samplers:ie,channels:re})}let N=zn(o,a,e.userData),C=[],L=[],E=[];for(let A=0;A<o.length;A++){let _=o[A],d=lr(_.extras?.xr);if(!d)continue;let{ae:R,src:G,preset:H,volume:B,loop:Z,isGlobal:k}=d,Y=_.name||`Node_${A}`,ie=L.length;L.push({name:`${Y}_source`,gain:B,loop:Z,autoPlay:typeof R.autoplay=="boolean"?R.autoplay:!0,...G!==void 0?{audio:C.push({uri:G})-1}:{},...H?{extras:{preset:H,pitch:Ue(R.pitch,.25,4,1)}}:{}});let re=E.length,O=Ue(R.refDistance,.05,100,1),J=Ue(R.coneInnerAngle,0,360,360),V=Ue(R.coneOuterAngle,J,360,360);E.push({name:`${Y}_emitter`,type:k?"global":"positional",gain:B,sources:[ie],...k?{}:{positional:{distanceModel:R.distanceModel==="linear"||R.distanceModel==="exponential"?R.distanceModel:"inverse",refDistance:O,maxDistance:Ue(R.maxDistance,O,500,Math.max(O,25)),rolloffFactor:Ue(R.rolloffFactor,0,10,1),coneInnerAngle:+(J*Math.PI/180).toFixed(6),coneOuterAngle:+(V*Math.PI/180).toFixed(6),coneOuterGain:Ue(R.coneOuterGain,0,1,0)}}}),_.extensions={..._.extensions||{},KHR_audio_emitter:{emitter:re}},l.add("KHR_audio_emitter")}let y={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:o,meshes:a,materials:u,...g.length>0?{images:g}:{},...w.length>0?{samplers:w}:{},...p.length>0?{textures:p}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...N||l.size>0?{extensionsUsed:[...N?["KHR_interactivity"]:[],...l]}:{},...N||T.length>0||E.length>0?{extensions:{...N?{KHR_interactivity:N}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(A=>({name:A}))}}:{},...E.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:L,emitters:E}}:{}}}:{}},F=new Uint8Array(r),z=0;for(let A of i)F.set(A,z),z+=A.byteLength;return[{gltf:y,bin:F.buffer,lights:x,environmentIntensity:e.environmentIntensity},h]}function Nn(e){return new TextEncoder().encode(e)}function tt(e,t){let{gltf:i,bin:r}=Ke(e,t),s=JSON.stringify(i),n=Nn(s),a=(4-n.byteLength%4)%4,o=n.byteLength+a,l=20+o+8+r.byteLength,h=new Uint8Array(l),u=new DataView(h.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,l,!0),u.setUint32(12,o,!0),u.setUint32(16,1313821514,!0),h.set(n,20);for(let g=0;g<a;g++)h[20+n.byteLength+g]=32;let f=20+o;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),h.set(new Uint8Array(r),f+8),h}function oi(e,t){let[i,r]=mr(e,t);return hr(i,r)}function hr(e,t){let i=[],r=e.gltf,s=le().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,a=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=r.accessors||[],l=r.bufferViews||[],h=r.materials||[],u=r.meshes||[],f=r.nodes||[],g=r.textures||[],w=r.images||[],p=r.samplers||[],b=new Set,T=h.map((S,D)=>cr(b,Ct(S?.name,`Material_${D}`))),x=new Map;function M(S){let D=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(S);if(!D)return null;let I=D[2].replace(/\s+/g,""),P=I.endsWith("==")?2:I.endsWith("=")?1:0,N=new Uint8Array((I.length*3>>2)-P),C=E=>{let y=I.charCodeAt(E);return y>96?y-71:y>64?y-65:y>47?y+4:y===43?62:y===47?63:0},L=0;for(let E=0;E<I.length;E+=4){let y=C(E)<<18|C(E+1)<<12|C(E+2)<<6|C(E+3);N[L++]=y>>16&255,L<N.length&&(N[L++]=y>>8&255),L<N.length&&(N[L++]=y&255)}return N}function c(S,D,I){let P=S?.index;if(typeof P!="number")return;let N=g[P],C=N?.source;if(typeof C!="number"||!w[C])return;let L=x.get(C);if(L===void 0){L=null;let F=w[C],z=null;if(typeof F.bufferView=="number"){let A=l[F.bufferView],_=A?.byteOffset||0,d=A?.byteLength||0;A&&d>0&&_>=0&&_+d<=a.byteLength&&(z=new Uint8Array(a,_,d))}else typeof F.uri=="string"&&(z=M(F.uri));if(z&&z.byteLength>0){let A=z[0]===255&&z[1]===216&&z[2]===255||!(z[0]===137&&z[1]===80)&&/jpe?g/i.test(F.mimeType||F.uri||"");L={file:`texture_${C}.${A?"jpg":"png"}`,data:z}}x.set(C,L)}if(!L)return;let E=typeof N.sampler=="number"?p[N.sampler]:void 0,y=F=>F===33071?"clamp":F===33648?"mirror":"repeat";return{file:L.file,data:L.data,wrapS:y(E?.wrapS),wrapT:y(E?.wrapT),...D?{scale:D}:{},...I?{bias:I}:{}}}function m(S){let D=o[S];if(!D)throw new Error(`Accessor ${S} not found`);let I=l[D.bufferView||0],P=(I.byteOffset||0)+(D.byteOffset||0),N=I.byteLength||0;return{acc:D,buffer:a.slice(P,P+N)}}function v(S,D,I,P){let N=[],C=u[S];if(!C)return N;let L=C.primitives||[];for(let E=0;E<L.length;E++){let y=L[E],F=y.attributes?.POSITION;if(F===void 0)continue;let{acc:z,buffer:A}=m(F),_=new Float32Array(A,0,z.count*3),d,R=y.attributes?.NORMAL;if(R!==void 0){let{acc:U,buffer:$}=m(R),j=new Float32Array($,0,U.count*3);d=new Float32Array(j.length);for(let q=0;q<U.count;q++){let K=j[q*3],Q=j[q*3+1],te=j[q*3+2],fe=Math.hypot(K,Q,te)||1;d[q*3]=K/fe,d[q*3+1]=Q/fe,d[q*3+2]=te/fe}}let G,H=y.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:U,buffer:$}=m(H);G=new Float32Array($,0,U.count*2)}let B;if(y.indices!==void 0){let{acc:U,buffer:$}=m(y.indices);B=U.componentType===5125?new Uint32Array($,0,U.count):new Uint16Array($,0,U.count);let j=z.count;for(let q of B)if(q>=j)throw new Error(`SecurityError: Index buffer value (${q}) out of vertex bounds [0, ${j}).`)}else{let U=z.count;B=U>65535?new Uint32Array(U):new Uint16Array(U);for(let $=0;$<U;$++)B[$]=$}let Z="DefaultMaterial",k=[1,1,1],Y=.5,ie=0,re=0,O=0,J=1.5,V=1,W=[0,0,0],X;if(y.material!==void 0&&h[y.material]){let U=h[y.material];Z=T[y.material]||`Material_${y.material}`;let $=U.pbrMetallicRoughness||{},j=(Ne,Ee)=>Array.isArray(Ne)&&Ne.length>=3?[Ne[0],Ne[1],Ne[2]]:Ee;k=j($.baseColorFactor,[1,1,1]);let q=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,K=k[0]!==1||k[1]!==1||k[2]!==1||q!==1,Q=c($.baseColorTexture,K?[k[0],k[1],k[2],q]:void 0),te=U.extras?.avgColor;!Q&&Array.isArray(te)&&te.length>=3&&(k=[k[0]*te[0],k[1]*te[1],k[2]*te[2]]),typeof $.roughnessFactor=="number"&&(Y=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,se=typeof $.metallicFactor=="number"?$.metallicFactor:1,ae=c($.metallicRoughnessTexture,fe!==1||se!==1?[1,fe,se,1]:void 0);W=j(U.emissiveFactor,[0,0,0]);let oe=(W[0]>0||W[1]>0||W[2]>0)&&(W[0]!==1||W[1]!==1||W[2]!==1)?[W[0],W[1],W[2],1]:void 0,ce=c(U.emissiveTexture,oe),Te=c(U.normalTexture,[2,2,2,1],[-1,-1,-1,0]),Re=c(U.occlusionTexture);(Q||ae||Te||ce||Re)&&(X=[Q,ae,Te,ce,Re]);let me=U.extensions||{};me.KHR_materials_clearcoat&&(re=me.KHR_materials_clearcoat.clearcoatFactor??0,O=me.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof me.KHR_materials_ior?.ior=="number"&&(J=me.KHR_materials_ior.ior),V=q*(1-(me.KHR_materials_transmission?.transmissionFactor??0))}N.push({name:L.length>1?`${D}_p${E}`:D,positions:_,indices:B,normals:d,uvs:G,materialName:Z,color:k,roughness:Y,metallic:ie,clearcoat:re,clearcoatRoughness:O,ior:J,opacity:V,emissiveColor:W,...X?{textures:X}:{},xrTraits:I||C.extras?.xr,...P?{invisible:!0}:{}})}return N}if(f.length>0){let S=new Float32Array(0),D=new Uint16Array(0),I=(_,d)=>{if(_===void 0)return null;let{acc:R,buffer:G}=m(_);return new Float32Array(G,0,R.count*d)},P=(_,d)=>Array.isArray(_)&&_.length>=3?[ne(_[0],d),ne(_[1],d),ne(_[2],d)]:[d,d,d],N=(_,d,R)=>_&&_.length>=(d+1)*3?[_[d*3],_[d*3+1],_[d*3+2]]:R,C=(_,d,R)=>_&&_.length>=(d+1)*4?[_[d*4],_[d*4+1],_[d*4+2],_[d*4+3]]:R,L=new Map,E=r.animations?.[0];if(E&&Array.isArray(E.channels)&&Array.isArray(E.samplers))for(let _ of E.channels){let d=E.samplers[_?.sampler],R=_?.target?.node,G=_?.target?.path;if(!d||typeof R!="number"||d.input===void 0)continue;let H=L.get(R);H||(H={input:d.input},L.set(R,H)),G==="translation"?H.t=d.output:G==="rotation"?H.r=d.output:G==="scale"&&(H.s=d.output)}let y=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(y)||y.length===0){let _=new Set;for(let d of f)if(Array.isArray(d?.children))for(let R of d.children)_.add(R);y=[];for(let d=0;d<f.length;d++)_.has(d)||y.push(d);y.length===0&&(y=[0])}let F=new Set,z=[],A=(_,d)=>{if(Array.isArray(_))for(let R=_.length-1;R>=0;R--)z.push({idx:_[R],out:d})};for(A(y,i);z.length>0;){let{idx:_,out:d}=z.pop();if(typeof _!="number"||_<0||_>=f.length||F.has(_))continue;F.add(_);let R=f[_];if(!R)continue;let G=[0,0,0],H=[0,0,0,1],B=[1,1,1];if(Array.isArray(R.matrix)&&R.matrix.length===16){let V=ur(R.matrix);G=V.t,H=V.r,B=V.s}else G=P(R.translation,0),Array.isArray(R.rotation)&&R.rotation.length>=4&&(H=[ne(R.rotation[0],0),ne(R.rotation[1],0),ne(R.rotation[2],0),ne(R.rotation[3],1)]),B=P(R.scale,1);let Z,k=L.get(_);if(k){let V=I(k.input,1);if(V&&V.length>0){let W=I(k.t,3),X=I(k.r,4),U=I(k.s,3),$=Array.from(V),j=[],q=[],K=[];for(let Q=0;Q<V.length;Q++)j.push(N(W,Q,G)),q.push(C(X,Q,H)),K.push(N(U,Q,B));Z={times:$,translations:j,rotations:q,scales:K}}}let Y=Array.isArray(R.children)?R.children:[],ie=typeof R.mesh=="number"&&R.mesh>=0&&R.mesh<u.length,re=t?.[_]?.userData?.xr??R.extras?.xr;if(!ie&&Y.length===0&&(R.camera!==void 0||R.extensions?.KHR_lights_punctual||!R.name&&!R.extras&&!re&&!Z))continue;let O=(V,W,X)=>({name:V,positions:S,indices:D,isXform:!0,xrTraits:re,timeSamples:Z,translation:G,rotation:H,scale:B,children:W,...X?{invisible:!0}:{}}),J=R.visible===!1||R.extensions?.KHR_node_visibility?.visible===!1||t?.[_]?.visible===!1;if(ie){let V=R.name||u[R.mesh]?.name||`Mesh_${_}`,W=v(R.mesh,V,re,J),X=R.extensions?.EXT_mesh_gpu_instancing?.attributes;if(X&&typeof X=="object"&&W.length>0){let U=I(X.TRANSLATION,3),$=I(X.ROTATION,4),j=I(X.SCALE,3),q=I(X._COLOR_0,3),K=Math.min(1e3,U?U.length/3:$?$.length/4:j?j.length/3:0);if(K>0){let Q=[];for(let te=0;te<K;te++){let fe=N(U,te,[0,0,0]),se=C($,te,[0,0,0,1]),ae=N(j,te,[1,1,1]);for(let oe of W){let ce=oe.color||[.8,.8,.8],Te=q&&q.length>=(te+1)*3;Q.push({...oe,name:`${oe.name}_${te}`,materialName:Te?`${oe.materialName}_inst_${te}`:oe.materialName,color:Te?[ce[0]*q[te*3],ce[1]*q[te*3+1],ce[2]*q[te*3+2]]:oe.color,translation:fe,rotation:se,scale:ae})}}A(Y,Q),d.push(O(V,Q,J));continue}}if(W.length===1)W[0].translation=G,W[0].rotation=H,W[0].scale=B,W[0].timeSamples=Z,Y.length>0&&(W[0].children=[],A(Y,W[0].children)),d.push(W[0]);else{let U=[...W];A(Y,U),d.push(O(V,U,J))}}else{let V=[];A(Y,V),d.push(O(R.name||`Group_${_}`,V,J))}}}else for(let S=0;S<u.length;S++){let D=u[S].name||`Mesh_${S}`;i.push(...v(S,D,u[S].extras?.xr))}return i}function Ct(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function At(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ye(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var Le=(e,t,i)=>`(${ye(e)}, ${ye(t)}, ${ye(i)})`,Et=(e,t,i,r)=>`(${ye(e)}, ${ye(t)}, ${ye(i)}, ${ye(r)})`;function ar(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Le(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ai(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${ye(e[r*2])}, ${ye(1-e[r*2+1])})`;return i.join(", ")}function ci(e){return Array.from(e).join(", ")}function ui(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let p=s.pop();if(!p.isXform&&p.positions&&p.positions.length>0){let b=Ct(p.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:p.color||[1,1,1],roughness:p.roughness??.5,metallic:p.metallic??0,clearcoat:p.clearcoat??0,clearcoatRoughness:p.clearcoatRoughness??0,ior:p.ior??1.5,opacity:p.opacity??1,emissiveColor:p.emissiveColor||[0,0,0],textures:p.textures})}if(p.timeSamples&&p.timeSamples.times.length>0){let b=p.timeSamples.times[p.timeSamples.times.length-1];b>i&&(i=b)}if(p.xrTraits?.anchor&&!r&&(r=p.xrTraits.anchor==="vertical"||p.xrTraits.anchor==="wall"?"vertical":"horizontal"),p.children)for(let b=p.children.length-1;b>=0;b--)s.push(p.children[b])}let n="";i>0&&(n=`startTimeCode = 0
|
|
250
|
+
endTimeCode = ${ye(i)}
|
|
251
251
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let
|
|
252
|
+
`);let a="";r&&(a=`uniform token preliminary:anchoring:type = "plane"
|
|
253
253
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
254
|
-
`);let
|
|
254
|
+
`);let o=`#usda 1.0
|
|
255
255
|
(
|
|
256
256
|
defaultPrim = "Root"
|
|
257
257
|
metersPerUnit = 1.0
|
|
@@ -262,90 +262,117 @@ def Xform "Root" (
|
|
|
262
262
|
kind = "component"
|
|
263
263
|
)
|
|
264
264
|
{
|
|
265
|
-
${
|
|
265
|
+
${a}def Scope "Materials"
|
|
266
|
+
{
|
|
267
|
+
`;for(let[p,b]of t.entries()){let[T,x,M]=b.color,[c,m,v]=b.emissiveColor,S=`/Root/Materials/${p}`,[D,I,P,N,C]=b.textures||[],L=(A,_)=>`.connect = <${S}/${A}.outputs:${_}>`,E=D?`color3f inputs:diffuseColor${L("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Le(T,x,M)}`,y=I?`float inputs:metallic${L("MetallicRoughnessTexture","b")}
|
|
268
|
+
float inputs:roughness${L("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${ye(b.metallic)}
|
|
269
|
+
float inputs:roughness = ${ye(b.roughness)}`,F="";b.clearcoat>0&&(F+=`float inputs:clearcoat = ${ye(b.clearcoat)}
|
|
270
|
+
`,F+=`float inputs:clearcoatRoughness = ${ye(b.clearcoatRoughness)}
|
|
271
|
+
`),b.ior!==1.5&&(F+=`float inputs:ior = ${ye(b.ior)}
|
|
272
|
+
`),b.opacity<1&&(F+=`float inputs:opacity = ${ye(b.opacity)}
|
|
273
|
+
`),N?F+=`color3f inputs:emissiveColor${L("EmissiveTexture","rgb")}
|
|
274
|
+
`:(c>0||m>0||v>0)&&(F+=`color3f inputs:emissiveColor = ${Le(c,m,v)}
|
|
275
|
+
`),P&&(F+=`normal3f inputs:normal${L("NormalTexture","rgb")}
|
|
276
|
+
`),C&&(F+=`float inputs:occlusion${L("OcclusionTexture","r")}
|
|
277
|
+
`);let z="";if(D||I||P||N||C){z+=`def Shader "PrimvarReader"
|
|
266
278
|
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
279
|
+
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
|
+
string inputs:varname = "st"
|
|
281
|
+
float2 outputs:result
|
|
282
|
+
}
|
|
283
|
+
`;let A=(_,d,R,G)=>{if(!d)return;let H=d.scale?`float4 inputs:scale = ${Et(d.scale[0],d.scale[1],d.scale[2],d.scale[3])}
|
|
284
|
+
`:"",B=d.bias?`float4 inputs:bias = ${Et(d.bias[0],d.bias[1],d.bias[2],d.bias[3])}
|
|
285
|
+
`:"";z+=`def Shader "${_}"
|
|
286
|
+
{
|
|
287
|
+
uniform token info:id = "UsdUVTexture"
|
|
288
|
+
asset inputs:file = @${At(d.file)}@
|
|
289
|
+
float2 inputs:st${L("PrimvarReader","result")}
|
|
290
|
+
token inputs:sourceColorSpace = "${R}"
|
|
291
|
+
token inputs:wrapS = "${d.wrapS||"repeat"}"
|
|
292
|
+
token inputs:wrapT = "${d.wrapT||"repeat"}"
|
|
293
|
+
${H}${B}${G}}
|
|
294
|
+
`};A("DiffuseTexture",D,"sRGB",`float3 outputs:rgb
|
|
295
|
+
`),A("MetallicRoughnessTexture",I,"raw",`float outputs:g
|
|
296
|
+
float outputs:b
|
|
297
|
+
`),A("NormalTexture",P,"raw",`float3 outputs:rgb
|
|
298
|
+
`),A("EmissiveTexture",N,"sRGB",`float3 outputs:rgb
|
|
299
|
+
`),A("OcclusionTexture",C,"raw",`float outputs:r
|
|
300
|
+
`)}o+=`def Material "${p}"
|
|
273
301
|
{
|
|
274
302
|
def Shader "PBRShader"
|
|
275
303
|
{
|
|
276
304
|
uniform token info:id = "UsdPreviewSurface"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
${R}token outputs:surface
|
|
281
|
-
}
|
|
282
|
-
token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
|
|
305
|
+
${E}
|
|
306
|
+
${y}
|
|
307
|
+
${F}token outputs:surface
|
|
283
308
|
}
|
|
284
|
-
|
|
309
|
+
token outputs:surface${L("PBRShader","surface")}
|
|
310
|
+
${z}}
|
|
311
|
+
`}o+=`}
|
|
285
312
|
def Scope "Meshes"
|
|
286
313
|
{
|
|
287
|
-
`;let
|
|
314
|
+
`;let l=(p,b,T)=>{let x=[];b&&x.push('"MaterialBindingAPI"');let M=!!(p?.rigidBody&&p.rigidBody!=="none"&&(typeof p.rigidBody!="object"||p.rigidBody.enabled!==!1)),c=!!(p?.physics&&p.physics!=="none"||M);c&&x.push(...M?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let m=[];if(x.length>0&&m.push(`prepend apiSchemas = [${x.join(", ")}]`),p){let P=le().xrTraitSerializer?.usdLines(p,At)??[];if(!P.length)for(let N of["grab","billboard","follow","anchor","physics"]){let C=N==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[N];C!==void 0&&P.push(`string ${N} = "${At(C)}"`)}P.length>0&&m.push(`customData = {
|
|
288
315
|
dictionary xr = {
|
|
289
|
-
${
|
|
316
|
+
${P.join(`
|
|
290
317
|
`)}
|
|
291
318
|
}
|
|
292
|
-
}`)}let v=
|
|
293
|
-
${
|
|
319
|
+
}`)}let v=m.length>0?` (
|
|
320
|
+
${m.join(`
|
|
294
321
|
`)}
|
|
295
|
-
)`:"",
|
|
296
|
-
`:"";if(
|
|
297
|
-
bool physics:kinematicEnabled = ${
|
|
322
|
+
)`:"",S=T?`uniform token visibility = "invisible"
|
|
323
|
+
`:"";if(c){let P=p?.rigidBody??p?.physics,N=P?.body??P?.mode??P;S+=`bool physics:rigidBodyEnabled = true
|
|
324
|
+
bool physics:kinematicEnabled = ${N==="static"||N==="kinematic"}
|
|
298
325
|
bool physics:collisionEnabled = true
|
|
299
|
-
`,
|
|
300
|
-
`)}let
|
|
326
|
+
`,P?.mass>0&&Number.isFinite(P.mass)&&(S+=`float physics:mass = ${ye(P.mass)}
|
|
327
|
+
`)}let D=lr(p),I=D?`def SpatialAudio "AudioEmitter"
|
|
301
328
|
{
|
|
302
|
-
${
|
|
303
|
-
`:""}uniform token inputs:auralMode = "${
|
|
304
|
-
uniform token inputs:playbackMode = "${
|
|
305
|
-
double gain = ${
|
|
329
|
+
${D.src?`asset inputs:file = @${At(D.src)}@
|
|
330
|
+
`:""}uniform token inputs:auralMode = "${D.isGlobal?"nonSpatial":"spatial"}"
|
|
331
|
+
uniform token inputs:playbackMode = "${D.loop?"loopFromStart":"onceFromStart"}"
|
|
332
|
+
double gain = ${ye(D.volume)}
|
|
306
333
|
}
|
|
307
|
-
`:"";return{header:v,body:
|
|
308
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
334
|
+
`:"";return{header:v,body:S,tail:I}},h=p=>{if(p.timeSamples&&p.timeSamples.times.length>0){let m=p.timeSamples,v=(P,N,C)=>m.times.map((L,E)=>`${ye(L)}: ${C(P?.[E]||N)}`).join(", "),S=v(m.translations,[0,0,0],P=>Le(P[0],P[1],P[2])),D=v(m.rotations,[0,0,0,1],P=>{let N=Math.hypot(P[0],P[1],P[2],P[3])||1;return Et(P[3]/N,P[0]/N,P[1]/N,P[2]/N)}),I=v(m.scales,[1,1,1],P=>Le(P[0],P[1],P[2]));return`double3 xformOp:translate.timeSamples = { ${S} }
|
|
335
|
+
quatf xformOp:orient.timeSamples = { ${D} }
|
|
309
336
|
double3 xformOp:scale.timeSamples = { ${I} }
|
|
310
337
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
311
|
-
`}let b=[],
|
|
312
|
-
`,b.push('"xformOp:translate"'));let
|
|
313
|
-
`,b.push('"xformOp:orient"'))}let
|
|
314
|
-
`,b.push('"xformOp:scale"')),b.length>0&&(
|
|
315
|
-
`),
|
|
338
|
+
`}let b=[],T="",x=p.translation;x&&(Math.abs(x[0])>1e-7||Math.abs(x[1])>1e-7||Math.abs(x[2])>1e-7)&&(T+=`double3 xformOp:translate = ${Le(x[0],x[1],x[2])}
|
|
339
|
+
`,b.push('"xformOp:translate"'));let M=p.rotation;if(M){let m=Math.hypot(M[0],M[1],M[2],M[3])||1,v=M[0]/m,S=M[1]/m,D=M[2]/m,I=M[3]/m;(1-Math.abs(I)>1e-7||Math.hypot(v,S,D)>1e-7)&&(T+=`quatf xformOp:orient = ${Et(I,v,S,D)}
|
|
340
|
+
`,b.push('"xformOp:orient"'))}let c=p.scale;return c&&(Math.abs(c[0]-1)>1e-7||Math.abs(c[1]-1)>1e-7||Math.abs(c[2]-1)>1e-7)&&(T+=`float3 xformOp:scale = ${Le(c[0],c[1],c[2])}
|
|
341
|
+
`,b.push('"xformOp:scale"')),b.length>0&&(T+=`uniform token[] xformOpOrder = [${b.join(", ")}]
|
|
342
|
+
`),T},u=p=>{let b=p.positions.length/3,T=1/0,x=1/0,M=1/0,c=-1/0,m=-1/0,v=-1/0;for(let N=0;N<b;N++){let C=p.positions[N*3],L=p.positions[N*3+1],E=p.positions[N*3+2];C<T&&(T=C),C>c&&(c=C),L<x&&(x=L),L>m&&(m=L),E<M&&(M=E),E>v&&(v=E)}isFinite(T)||(T=x=M=-1,c=m=v=1);let S=Math.floor(p.indices.length/3),D=Ct(p.materialName,"DefaultMaterial"),I=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",P=`float3[] extent = [${Le(T,x,M)}, ${Le(c,m,v)}]
|
|
316
343
|
int[] faceVertexCounts = [${I}]
|
|
317
|
-
int[] faceVertexIndices = [${
|
|
318
|
-
point3f[] points = [${
|
|
319
|
-
`;return
|
|
344
|
+
int[] faceVertexIndices = [${ci(p.indices)}]
|
|
345
|
+
point3f[] points = [${ar(p.positions)}]
|
|
346
|
+
`;return p.normals&&p.normals.length===p.positions.length&&(P+=`normal3f[] normals = [${ar(p.normals)}] (
|
|
320
347
|
interpolation = "vertex"
|
|
321
348
|
)
|
|
322
|
-
`),
|
|
349
|
+
`),p.uvs&&p.uvs.length===b*2&&(P+=`texCoord2f[] primvars:st = [${ai(p.uvs,b)}] (
|
|
323
350
|
interpolation = "vertex"
|
|
324
351
|
)
|
|
325
|
-
`),
|
|
326
|
-
`,
|
|
327
|
-
`;continue}let{node:b,siblings:
|
|
352
|
+
`),P+=`rel material:binding = </Root/Materials/${D}>
|
|
353
|
+
`,P},f=new Set,g=[];for(let p=e.length-1;p>=0;p--)g.push({node:e[p],siblings:f});let w=0;for(;g.length>0;){let p=g.pop();if(p.close){o+=`}
|
|
354
|
+
`;continue}let{node:b,siblings:T}=p,x=!!(b.isXform||b.positions.length===0),M=cr(T,Ct(b.name,x?`Group_${w}`:`Mesh_${w}`));w++;let c=b.children||[];if(x){let m=l(b.xrTraits,!1,b.invisible);o+=`def Xform "${M}"${m.header}
|
|
328
355
|
{
|
|
329
|
-
${
|
|
356
|
+
${m.body}${h(b)}${m.tail}`,g.push({close:!0});let v=new Set;for(let S=c.length-1;S>=0;S--)g.push({node:c[S],siblings:v})}else if(c.length>0){let m=l(b.xrTraits,!1,b.invisible),v=`${M}_mesh`;o+=`def Xform "${M}"${m.header}
|
|
330
357
|
{
|
|
331
|
-
${
|
|
358
|
+
${m.body}${h(b)}${m.tail}`,o+=`def Mesh "${v}" (
|
|
332
359
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
333
360
|
)
|
|
334
361
|
{
|
|
335
|
-
${
|
|
336
|
-
`,
|
|
362
|
+
${u(b)}}
|
|
363
|
+
`,g.push({close:!0});let S=new Set([v]);for(let D=c.length-1;D>=0;D--)g.push({node:c[D],siblings:S})}else{let m=l(b.xrTraits,!0,b.invisible);o+=`def Mesh "${M}"${m.header}
|
|
337
364
|
{
|
|
338
|
-
${
|
|
339
|
-
`}}return
|
|
365
|
+
${m.body}${h(b)}${u(b)}${m.tail}}
|
|
366
|
+
`}}return o+=`}
|
|
340
367
|
}
|
|
341
|
-
`,a}function li(e,t){if(e&&typeof e.traverse=="function"){let s=ai(e,t);return In(s)}let i=Je(e),r=Ln(i);return In(r)}var _t=null;function Et(e){if(!_t){_t=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;_t[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=_t[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function mi(e){let t=[],i=0,r=[];for(let c of e){let f=Nn(c.filename),y=Et(c.data),g=c.data.length,u=30+f.length,b=(i+u)%64,w=b!==0?64-b:0,M=new Uint8Array(u+w),x=new DataView(M.buffer);x.setUint32(0,67324752,!0),x.setUint16(4,20,!0),x.setUint32(14,y,!0),x.setUint32(18,g,!0),x.setUint32(22,g,!0),x.setUint16(26,f.length,!0),x.setUint16(28,w,!0),M.set(f,30),t.push({offset:i,size:g,crc:y,filenameBytes:f,entry:c}),r.push(M,c.data),i+=M.length+c.data.length}let s=i;for(let c of t){let f=new Uint8Array(46+c.filenameBytes.length),y=new DataView(f.buffer);y.setUint32(0,33639248,!0),y.setUint16(4,20,!0),y.setUint16(6,20,!0),y.setUint32(16,c.crc,!0),y.setUint32(20,c.size,!0),y.setUint32(24,c.size,!0),y.setUint16(28,c.filenameBytes.length,!0),y.setUint32(42,c.offset,!0),f.set(c.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,o=new Uint8Array(22),a=new DataView(o.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,n,!0),a.setUint32(16,s,!0),r.push(o),i+=22;let h=new Uint8Array(i),l=0;for(let c of r)h.set(c,l),l+=c.length;return h}var dr=e=>mi([{filename:"model.usda",data:Nn(e)}]);function et(e){return dr(li(e))}function Rt(e){return dr(In(Ln(Je(e))))}function Pn(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Rt(e)}var Se=class Ni{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new Ni(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}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},Z=class Li{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Li(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,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,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 i=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,s=this.x*t.y-this.y*t.x;return this.x=i,this.y=r,this.z=s,this}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,o=i.x,a=i.y,h=i.z;return this.x=s*h-n*a,this.y=n*o-r*h,this.z=r*a-s*o,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)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,o=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*o,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*o,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*o,this}},Lt=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},it=class Fi{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}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,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,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 Fi(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},st=class ki{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}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,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),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 ki(this._x,this._y,this._z,this._w)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,o=Math.cos(r/2),a=Math.cos(s/2),h=Math.cos(n/2),l=Math.sin(r/2),c=Math.sin(s/2),f=Math.sin(n/2);return this._x=l*a*h+o*c*f,this._y=o*c*h-l*a*f,this._z=o*a*f+l*c*h,this._w=o*a*h-l*c*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,o=t.w,a=i.x,h=i.y,l=i.z,c=i.w;return this._x=r*c+o*a+s*l-n*h,this._y=s*c+o*h+n*a-r*l,this._z=n*c+o*l+r*h-s*a,this._w=o*c-r*a-s*h-n*l,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Fe=class Ui{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 Ui;return t.copy(this),t}compose(t,i,r){return qe(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return de(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return Xe(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new Z(0,0,0),r=new Z(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Pt=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 Ae(this.elements,e.elements),this}},ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Ct=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,pr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Te=class zi{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in pr)this.setHex(pr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>ve(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let a=ve(r);return this.setRGB(a,a,a)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,o=a=>(a<0&&(a+=1),a>1&&(a-=1),a<1/6?n+(s-n)*6*a:a<1/2?s:a<2/3?n+(s-n)*6*(2/3-a):n);return this.setRGB(ve(o(t+1/3)),ve(o(t)),ve(o(t-1/3)))}lerp(t,i){let r=Number(i)||0;return this.r+=(t.r-this.r)*r,this.g+=(t.g-this.g)*r,this.b+=(t.b-this.b)*r,this}lerpColors(t,i,r){let s=Number(r)||0;return this.r=t.r+(i.r-t.r)*s,this.g=t.g+(i.g-t.g)*s,this.b=t.b+(i.b-t.b)*s,this}multiplyScalar(t){let i=Number(t)||0;return this.r*=i,this.g*=i,this.b*=i,this}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.r=ve((i>>16&255)/255),this.g=ve((i>>8&255)/255),this.b=ve((i&255)/255),this}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.r=ve(this.r),this.g=ve(this.g),this.b=ve(this.b),this}convertLinearToSRGB(){return this.r=Ct(this.r),this.g=Ct(this.g),this.b=Ct(this.b),this}getHex(){let t=i=>Math.round(Ct(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}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 zi(this.r,this.g,this.b)}},Sr={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},be=class Oi{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;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/i)}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,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new Oi(new t(this.array),this.itemSize)}},Ft=class extends be{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},kt=class extends be{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Ut=class extends be{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},me=class Vi{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof be)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new be(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new be(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=t.count,r=new Float32Array(i*3),s=new Z,n=new Z,o=new Z,a=new Z,h=new Z,l=this.index?.array,c=l?l.length:i;for(let f=0;f<c;f+=3){let y=l?l[f]:f,g=l?l[f+1]:f+1,u=l?l[f+2]:f+2;s.set(t.getX(y),t.getY(y),t.getZ(y)),n.set(t.getX(g),t.getY(g),t.getZ(g)),o.set(t.getX(u),t.getY(u),t.getZ(u)),a.subVectors(o,n),h.subVectors(s,n),a.cross(h).normalize();for(let b of[y,g,u])r[b*3]+=a.x,r[b*3+1]+=a.y,r[b*3+2]+=a.z}for(let f=0;f<i;f++){let y=r[f*3],g=r[f*3+1],u=r[f*3+2],b=Math.hypot(y,g,u)||1;r[f*3]=y/b,r[f*3+1]=g/b,r[f*3+2]=u/b}return this.setAttribute("normal",new be(r,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new be(t,3)),this.setAttribute("normal",new be(i,3)),this.setAttribute("uv",new be(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new be(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new Z(1/0,1/0,1/0),r=new Z(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),o=t.getY(s),a=t.getZ(s);n<i.x&&(i.x=n),o<i.y&&(i.y=o),a<i.z&&(i.z=a),n>r.x&&(r.x=n),o>r.y&&(r.y=o),a>r.z&&(r.z=a)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let o of[this.attributes.position,this.attributes.normal]){if(!o)continue;let a=o.array;for(let h=0;h<a.length;h+=3){let l=a[h+t],c=a[h+i];a[h+t]=l*s-c*n,a[h+i]=l*n+c*s}o.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new Z;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new Vi;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},ot=class extends me{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,o=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],h=[],l=[];for(let c=0;c<6;c++){let f=c*4;h.push(0,0,1,0,1,1,0,1),l.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(o,a,h,l)}},Ot=class extends me{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],o=[],a=[];for(let h=0;h<=r;h++){let l=h/r;for(let c=0;c<=i;c++){let f=c/i;if(s.push((f-.5)*e,(.5-l)*t,0),n.push(0,0,1),o.push(f,1-l),h>0&&c>0){let y=(i+1)*h+c-1,g=y-(i+1);a.push(g,y,g+1,y,y+1,g+1)}}}this.setFromBuffers(s,n,o,a)}},Bt=class extends me{constructor(e=1,t=16,i=12){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let r=[],s=[],n=[],o=[];for(let a=0;a<=i;a++){let h=a/i;for(let l=0;l<=t;l++){let c=l/t,f=c*Math.PI*2,y=h*Math.PI,g=-Math.cos(f)*Math.sin(y),u=Math.cos(y),b=Math.sin(f)*Math.sin(y);if(r.push(e*g,e*u,e*b),s.push(g,u,b),n.push(c,1-h),a>0&&l>0){let w=(t+1)*a+l,M=w-(t+1),x=M-1,m=w-1;a!==1&&o.push(M,x,w),a!==i&&o.push(x,m,w)}}}this.setFromBuffers(r,s,n,o)}},at=class extends me{constructor(e=1,t=1,i=1,r=16){super(),r=Math.max(3,Math.floor(r));let s=[],n=[],o=[],a=[],h=i/2;for(let c=0;c<=1;c++){let f=c,y=c===0?e:t,g=c===0?h:-h;for(let u=0;u<=r;u++){let b=u/r,w=b*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(y*M,g,y*x),n.push(M,0,x),o.push(b,1-f)}}for(let c=0;c<r;c++){let f=c,y=c+r+1,g=c+r+2,u=c+1;a.push(f,y,u,y,g,u)}let l=(c,f)=>{if(c<=0)return;let y=f*h,g=s.length/3;s.push(0,y,0),n.push(0,f,0),o.push(.5,.5);let u=s.length/3;for(let b=0;b<=r;b++){let w=b/r*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(c*M,y,c*x),n.push(0,f,0),o.push(x*.5+.5,.5+f*M*.5)}for(let b=0;b<r;b++)a.push(g,u+b+(f>0?0:1),u+b+(f>0?1:0))};l(e,1),l(t,-1),this.setFromBuffers(s,n,o,a)}},Vt=class extends at{constructor(e=1,t=1,i=16){super(0,e,t,i)}},zt=class extends me{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],o=[],a=[],h=[];for(let l=0;l<=i;l++){let c=l/i*Math.PI*2,f=Math.cos(c),y=Math.sin(c);for(let g=0;g<=r;g++){let u=g/r*s,b=Math.cos(u),w=Math.sin(u);if(n.push((e+t*f)*b,(e+t*f)*w,t*y),o.push(f*b,f*w,y),a.push(g/r,l/i),l>0&&g>0){let M=(r+1)*l+g-1,x=M-(r+1);h.push(M,x,M+1,x,x+1,M+1)}}}this.setFromBuffers(n,o,a,h)}};function Tr(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),o=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),a=Number(r)||.1,h=[],l=[],c=[],f=[],y=new Z,g=new Z,u=new Z,b=new Z,w=new Z;for(let x=0;x<=n;x++){let m=x/n;s(Math.max(0,m-.001),y),s(Math.min(1,m+.001),g),u.subVectors(g,y).normalize(),x===0&&b.set(Math.abs(u.y)>.9?1:0,Math.abs(u.y)>.9?0:1,0),w.crossVectors(u,b).normalize(),b.crossVectors(w,u).normalize(),s(m,y);for(let p=0;p<=o;p++){let v=p/o*Math.PI*2,R=-a*Math.cos(v),L=a*Math.sin(v),I=R*b.x+L*w.x,N=R*b.y+L*w.y,_=R*b.z+L*w.z;h.push(y.x+I,y.y+N,y.z+_);let A=Math.hypot(I,N,_)||1;l.push(I/A,N/A,_/A),c.push(m,p/o)}}let M=o+1;for(let x=1;x<=n;x++){let m=M*(x-1),p=m+M;for(let v=1;v<=o;v++){let R=m+v-1,L=p+v-1;f.push(R,L,m+v,L,p+v,m+v)}}e.setFromBuffers(h,l,c,f)}var Gt=class extends me{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),Tr(this,i,r,t,(o,a)=>{let h=o*s*Math.PI*2,l=n/s*h,c=e*(2+Math.cos(l))*.5;a.set(c*Math.cos(h),c*Math.sin(h),e*Math.sin(l)*.5)})}},Ie=class{getPoint(e,t=new Z){return t}getPointAt(e,t=new Z){return this.getPoint(e,t)}getTangent(e,t=new Z){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Ht=class extends Ie{constructor(e=new Z,t=new Z){super(),this.v1=e,this.v2=t}getPoint(e,t=new Z){return t.lerpVectors(this.v1,this.v2,e)}},Xt=class extends Ie{constructor(e=new Z,t=new Z,i=new Z){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Z){return t.lerpVectors(this.v0,this.v1,e).lerp(new Z().lerpVectors(this.v1,this.v2,e),e)}},$t=class extends Ie{constructor(e=new Z,t=new Z,i=new Z,r=new Z){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new Z){let i=new Z().lerpVectors(this.v0,this.v1,e),r=new Z().lerpVectors(this.v1,this.v2,e),s=new Z().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},jt=class extends Ie{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new Z){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),o=s-n;!this.closed&&n>=r-1&&(n=r-2,o=1);let a=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],h=a(n-1),l=a(n),c=a(n+1),f=a(n+2),y=o*o,g=y*o,u=(b,w,M,x)=>.5*(2*w+(M-b)*o+(2*b-5*w+4*M-x)*y+(3*w-b-3*M+x)*g);return t.set(u(h.x,l.x,c.x,f.x),u(h.y,l.y,c.y,f.y),u(h.z,l.z,c.z,f.z))}},ct=class extends me{constructor(e=[new Se(0,-.5),new Se(.5,0),new Se(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Se(.2,0),new Se(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),o=[],a=[],h=[],l=[],c=s.length;for(let f=0;f<=n;f++){let y=f/n,g=i+y*r,u=Math.sin(g),b=Math.cos(g);for(let w=0;w<c;w++){let M=s[w],x=Number(M?.x)||0,m=Number(M?.y)||0;o.push(x*u,m,x*b);let p=s[Math.max(0,w-1)],v=s[Math.min(c-1,w+1)],R=(Number(v?.x)||0)-(Number(p?.x)||0),L=(Number(v?.y)||0)-(Number(p?.y)||0),I=Math.hypot(L,R)||1;a.push(L/I*u,-R/I,L/I*b),h.push(y,w/(c-1))}}for(let f=0;f<n;f++){let y=f*c;for(let g=0;g<c-1;g++){let u=y+g,b=y+c+g;l.push(u,b,u+1,b,b+1,u+1)}}this.setFromBuffers(o,a,h,l)}},Wt=class extends me{constructor(e,t=64,i=1,r=8,s=!1){super(),Tr(this,t,r,i,(n,o)=>{let a=e?.getPointAt??e?.getPoint;if(typeof a=="function"){let h=a.call(e,n,o);h&&h!==o&&o.copy(h)}else o.set(0,n,0)})}},Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",We=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Se(1,1),this.offset=new Se(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Kt=class extends We{constructor(e=null,t=1,i=1,r=1023,s=1009,n,o=1001,a=1001,h=1003,l=1003,c=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1;let y=Number(t),g=Number(i),u=e&&typeof e.length=="number"?e:null;this.width=y,this.height=g,this.image={data:u,width:y,height:g},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(o)||1001,this.wrapT=Number(a)||1001,this.magFilter=Number(h)||1003,this.minFilter=Number(l)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),o=s*n,a=this.format,h=a===1021||a===1024||a===1028||t.length===o?1:a===1025||a===1030||t.length===o*2?2:a===1022||t.length===o*3?3:4,l=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,c=Math.min(s,96),f=Math.min(n,96),y=f*(1+c*4),g=new Uint8Array(68+y),u=new DataView(g.buffer);u.setUint32(0,2303741511),u.setUint32(4,218765834),u.setUint32(8,13),u.setUint32(12,1229472850),u.setUint32(16,c),u.setUint32(20,f),g[24]=8,g[25]=6,u.setUint32(29,Et(g.subarray(12,29))),u.setUint32(33,y+11),u.setUint32(37,1229209940),g[41]=120,g[42]=1,g[43]=1,u.setUint16(44,y,!0),u.setUint16(46,~y&65535,!0);let b=48,w=1,M=0,x=0,m=0,p=0,v=0,R=_=>{if(!Number.isFinite(_))return 0;let A=l&&_<=1?_*255:_;return A>0?A<255?A+.5|0:255:0};for(let _=0;_<f;_++){let A=_*n/f|0,E=this.flipY?n-1-A:A;g[b++]=0,M+=w;for(let C=0;C<c;C++){let d=(E*s+(C*s/c|0))*h,k=a===1021?255:R(t[d]??0),$=h>=3||a===1030?R(t[d+1]??0):k,S=h>=3?R(t[d+2]??0):a===1030?0:k,D=h===4?R(t[d+3]??255):a===1021?R(t[d]??255):a===1025?R(t[d+1]??255):255;g[b++]=k,w+=k,M+=w,g[b++]=$,w+=$,M+=w,g[b++]=S,w+=S,M+=w,g[b++]=D,w+=D,M+=w,x+=k,m+=$,p+=S,v+=D}w%=65521,M%=65521}u.setUint32(b,(M<<16|w)>>>0),u.setUint32(b+4,Et(g.subarray(37,b+4))),u.setUint32(b+12,1229278788),u.setUint32(b+16,2923585666);let L=c*f*255,I=this.colorSpace==="srgb-linear";this.avgColor=[I?x/L:ve(x/L),I?m/L:ve(m/L),I?p/L:ve(p/L),v/L];let N=["data:image/png;base64,"];for(let _=0;_<g.length;_+=3){let A=g[_]<<16|(g[_+1]??0)<<8|(g[_+2]??0);N.push(Dt[A>>18&63]+Dt[A>>12&63]+(_+1<g.length?Dt[A>>6&63]:"=")+(_+2<g.length?Dt[A&63]:"="))}this.source=N.join("")}},Yt=class{load(e,t){let i=new We(e);return t?.(i),i}};function ye(e,t){return e!==void 0?Number(e):t}function Fn(e,t){return e!==void 0?!!e:t}var Me=class{constructor(e={}){this.name=e.name||"",this.color=new Te(e.color!==void 0?e.color:16777215),this.emissive=new Te(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ye(e.emissiveIntensity,1),this.roughness=ye(e.roughness,.5),this.metalness=ye(e.metalness,0),this.opacity=ye(e.opacity,1),this.transparent=Fn(e.transparent,!1),this.wireframe=Fn(e.wireframe,!1),this.side=ye(e.side,2),this.doubleSided=Fn(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 Te(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 Te(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(){}},Ve=class extends Me{},qt=class extends Me{},Zt=class extends Me{},Jt=class extends Me{},Qt=class extends Me{},_e=class Bi{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 Z,this.rotation=new it,this.quaternion=new st,this.scale=new Z(1,1,1),this.matrix=new Fe,this.matrixWorld=new Fe,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=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)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof Bi&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let o=n.length-1;o>=0;o--)r.push(n[o])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{_r(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new Z(t,i,r);this.target instanceof Z?this.target.copy(s):this.target?.position instanceof Z&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Fe;n.lookAt(this.position,s,new Z(0,1,0));let o=n.elements,a=o[0],h=o[4],l=o[8],c=o[1],f=o[5],y=o[9],g=o[2],u=o[6],b=o[10],w=a+f+b;if(w>0){let M=.5/Math.sqrt(w+1);this.quaternion.set((u-y)*M,(l-g)*M,(c-h)*M,.25/M)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Fe().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new Z(1,0,0),t)}translateY(t){return this.translateOnAxis(new Z(0,1,0),t)}translateZ(t){return this.translateOnAxis(new Z(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}clone(t=!0){let i=this instanceof ke?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Re?new Re(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},en=class extends _e{},Re=class extends _e{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof me?e:e?(Ge("unsupported geometry","BoxGeometry"),new ot(.5,.5,.5)):new me,this.material=i instanceof Me?i:i?(Ge("unsupported material","MeshStandardMaterial"),new Ve({color:13421772})):new Ve}};function _r(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=ae().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var ut=1e4,lt=class extends Re{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>ut)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${ut})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let o=n*16;s[o]=1,s[o+5]=1,s[o+10]=1,s[o+15]=1}this.instanceMatrix=new be(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let o=Number(t.elements[n]);r[s+n]=Number.isFinite(o)?o:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new be(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},ze=class extends _e{constructor(e=16777215,t=1){super(),this.color=new Te(e),this.intensity=Number(t),this.type="directional"}},mt=class extends ze{constructor(e,t){super(e,t),this.type="ambient"}},tn=class extends ze{constructor(e,t){super(e,t),this.target=new _e,this.type="directional"}},ht=class extends ze{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},ft=class extends _e{},nn=class extends ft{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new Z(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},dt=class extends _e{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ee.validate(this),je(this)}toGLB(){return Ee.validate(this),Qe(this)}toUSDZ(){return Ee.validate(this),et(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Re){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},kn=je,Un=Qe,Ar=et,Ee=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(a,h,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${h}). Found: ${l}`)},o=(a,h)=>{if(!Number.isFinite(h))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(h)}), which cannot be bounds-checked.`);return h};e.traverse(a=>{if(_r(a),a instanceof Re||a.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),a instanceof lt){let l=o("instance",a.count);(l<0||l>ut)&&n("INSTANCES",ut,l)}let h=a.geometry;if(h){let l=0;if(h.attributes.position&&(l=o("vertex",h.attributes.position.count),t+=l,t>1e5&&n("VERTICES",1e5,t)),h.index){let c=o("index",h.index.count);i+=c,i>3e5&&n("INDICES",3e5,i);let f=h.index.array;if(f&&l>0){let y=Math.min(c,f.length);for(let g=0;g<y;g++){let u=f[g];if(!Number.isFinite(u)||u<0||u>=l)throw new Error(`SecurityError: Index buffer value (${String(u)}) out of vertex bounds [0, ${l}).`)}}}}if(a.material){let l=a.material;l.map&&s.add(l.map),l.normalMap&&s.add(l.normalMap),l.roughnessMap&&s.add(l.roughnessMap)}}}),s.size>16&&n("TEXTURES",16,s.size);for(let a of s){let h=a,l=h.image,c=Number(l?.width??h.width??0)||0,f=Number(l?.height??h.height??0)||0;(!Number.isFinite(c)||!Number.isFinite(f)||c>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(c,f))}}},rn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,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 t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let i=new Te(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){Ee.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[o,a]of s.entries())n[o]=Array.from(a);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=kn(e),n=Un(e),o=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:o,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function br(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var sn=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=br(),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 t=br();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function hi(){}var nt=new Proxy(hi,{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:nt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>nt,construct:()=>nt}),gr=(()=>{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 vn(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ke(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,vn());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 yr,tt;function Er(e){if(!Ke(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(tt===void 0||yr!==t){yr=t;try{tt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ke(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{tt=null}}return tt?tt.createScriptURL(e):e}function fi(e){ae().sandboxEngineSrc=e}function On(){let e=ae().sandboxEngineSrc;if(e)return e;if(gr)return gr;try{if(typeof document>"u")return null;let t=vn(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Ke(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Bn(e,t){if(!Ke(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,vn()).href}function di(){let e=On();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.");return Bn(e,"sandbox engine")}function pi(e){ae().sandboxIframeSrc=e}function Rr(){let e=ae().sandboxIframeSrc;if(e)return e;let t=On();if(!t||!Ke(t))return null;let i=new URL(t,vn());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function bi(){let e=Rr();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.");return Bn(e,"sandbox iframe")}function gi(e){ae().allowClientScripts=e}function Cr(){return!!ae().allowClientScripts}function yi(e){return Bn(e,"procedural scene script")}var xi=["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 vi(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,o=e.allowClientScripts,a=e.revoked,h=i.postMessage.bind(i);function l(m){h({type:"ERROR",nonce:r,message:String(m)})}let c=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,y=null;try{let m=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let p={createScriptURL:function(R){if(R!==s&&(!n||R!==n))throw new TypeError("Disallowed worker importScripts URL");return R}};o&&(p.createScript=function(R){return String(R)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",p);m=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),o&&typeof v.createScript=="function"&&(y=v.createScript.bind(v))}catch{}c(m)}catch(m){l('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(m&&m.message||m));return}let g=i.THREE;if(!g||typeof g.Scene!="function"){l('Sandbox loaded "'+s+'" 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 m=i.__THREE_LIVE_REGISTRY__;for(let p=0;p<t.length;p++)if(typeof t[p]=="function")try{t[p](g,m)}catch{}}function u(m,p,v){let R=i;for(;R&&R!==Object.prototype;){if(!v&&R!==i)try{delete R[m]}catch{}if(!v||R===i||Object.prototype.hasOwnProperty.call(R,m))try{Object.defineProperty(R,m,v?{value:p,writable:!1,configurable:!1}:{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}for(let m=0;m<a.length;m++)u(a[m],void 0);u("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],w=!1;function M(m,p){if(m.type==="3D_MODEL_READY"){if(w)return;w=!0}m.nonce=r,p&&p.length?h(m,p):h(m)}u("postMessage",function(m,p){if(!m||b.indexOf(m.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");M(m,p)},!0);let x=!1;i.onmessage=function(m){let p=m&&m.data;if(!(!p||p.nonce!==r)&&!(p.type!=="EXECUTE"&&p.type!=="EXECUTE_URL")&&!x){x=!0;try{let v=new g.Scene,R=new g.PerspectiveCamera(60,1,.1,1e3),L=new g.WebGLRenderer({isSandboxed:!0});if(p.type==="EXECUTE_URL"){if(!n||p.scriptUrl!==n||typeof c!="function"){l("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,N=c;if(c=null,f=null,i.THREE=g,i.scene=v,i.camera=R,i.renderer=L,N(I),typeof i.__THREE_LIVE_SCENE__=="function"){let _=i.__THREE_LIVE_SCENE__(g,v,R,L);_&&typeof _.toGLB=="function"&&(v=_)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!o){l("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=y?(0,eval)(y(`(function (THREE, scene, camera, renderer) {
|
|
368
|
+
`,o}var Rt=null;function Dt(e){if(!Rt){Rt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;Rt[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=Rt[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function li(e){let t=[],i=0,r=[];for(let u of e){let f=Nn(u.filename),g=Dt(u.data),w=u.data.length,p=30+f.length,b=(i+p)%64,T=b!==0?64-b:0;T>0&&T<4&&(T+=64);let x=new Uint8Array(p+T),M=new DataView(x.buffer);M.setUint32(0,67324752,!0),M.setUint16(4,20,!0),M.setUint32(14,g,!0),M.setUint32(18,w,!0),M.setUint32(22,w,!0),M.setUint16(26,f.length,!0),M.setUint16(28,T,!0),x.set(f,30),T>=4&&(M.setUint16(p,6534,!0),M.setUint16(p+2,T-4,!0)),t.push({offset:i,size:w,crc:g,filenameBytes:f,entry:u}),r.push(x,u.data),i+=x.length+u.data.length}let s=i;for(let u of t){let f=new Uint8Array(46+u.filenameBytes.length),g=new DataView(f.buffer);g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint32(16,u.crc,!0),g.setUint32(20,u.size,!0),g.setUint32(24,u.size,!0),g.setUint16(28,u.filenameBytes.length,!0),g.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,n,!0),o.setUint32(16,s,!0),r.push(a),i+=22;let l=new Uint8Array(i),h=0;for(let u of r)l.set(u,h),h+=u.length;return l}function fr(e){let t=[{filename:"model.usda",data:Nn(ui(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let s=r.pop();for(let n of s.textures||[])n?.file&&n.data?.byteLength&&!i.has(n.file)&&(i.add(n.file),t.push({filename:n.file,data:n.data}));if(s.children)for(let n=s.children.length-1;n>=0;n--)r.push(s.children[n])}return li(t)}function nt(e){return fr(oi(e))}function It(e){return fr(hr(wt(e)))}function Ln(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():It(e)}var Se=class Pi{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new Pi(this.x,this.y)}copy(t){return this.set(t.x,t.y)}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}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},ee=class Ni{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Ni(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,i){return this.set(t.x+i.x,t.y+i.y,t.z+i.z)}sub(t){return this.subVectors(this,t)}subVectors(t,i){return this.set(t.x-i.x,t.y-i.y,t.z-i.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.set(this.x+t.x*i,this.y+t.y*i,this.z+t.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,a=i.x,o=i.y,l=i.z;return this.set(s*l-n*o,n*a-r*l,r*o-s*a)}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)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,a=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*a,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*a,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*a,this}},kt=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},ot=class Li{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}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,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new Li(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ye=class Ii{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}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,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new Ii(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,a=Math.cos(r/2),o=Math.cos(s/2),l=Math.cos(n/2),h=Math.sin(r/2),u=Math.sin(s/2),f=Math.sin(n/2);return this._x=h*o*l+a*u*f,this._y=a*u*l-h*o*f,this._z=a*o*f+h*u*l,this._w=a*o*l-h*u*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,a=t.w,o=i.x,l=i.y,h=i.z,u=i.w;return this._x=r*u+a*o+s*h-n*l,this._y=s*u+a*l+n*o-r*h,this._z=n*u+a*h+r*l-s*o,this._w=a*u-r*o-s*l-n*h,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Be=class Fi{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 Fi;return t.copy(this),t}compose(t,i,r){return Qe(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return be(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return We(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new ee(0,0,0),r=new ee(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Ut=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 Ce(this.elements,e.elements),this}},ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Nt=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,dr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},we=class Ui{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in dr)this.setHex(dr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>ve(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=ve(r);return this.setRGB(o,o,o)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?n+(s-n)*6*o:o<1/2?s:o<2/3?n+(s-n)*6*(2/3-o):n);return this.setRGB(ve(a(t+1/3)),ve(a(t)),ve(a(t-1/3)))}lerp(t,i){return this.lerpColors(this,t,i)}lerpColors(t,i,r){let s=Number(r)||0;return this.setRGB(t.r+(i.r-t.r)*s,t.g+(i.g-t.g)*s,t.b+(i.b-t.b)*s)}multiplyScalar(t){let i=Number(t)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.setRGB(ve((i>>16&255)/255),ve((i>>8&255)/255),ve((i&255)/255))}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(ve(this.r),ve(this.g),ve(this.b))}convertLinearToSRGB(){return this.setRGB(Nt(this.r),Nt(this.g),Nt(this.b))}getHex(){let t=i=>Math.round(Nt(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Ui(this.r,this.g,this.b)}},Tr={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},ge=class ki{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;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/i)}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,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new ki(new t(this.array),this.itemSize)}},Ot=class extends ge{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},Bt=class extends ge{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Vt=class extends ge{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},de=class Oi{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof ge)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new ge(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new ge(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=!1;if(typeof i=="function"){let l=i(t.array,this.index?.array);return this.setAttribute("normal",new ge(l,3)),this}let r=t.count,s=t.array,n=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let h=(a?a[l]:l)*3,u=(a?a[l+1]:l+1)*3,f=(a?a[l+2]:l+2)*3,g=s[u],w=s[u+1],p=s[u+2],b=s[f]-g,T=s[f+1]-w,x=s[f+2]-p,M=s[h]-g,c=s[h+1]-w,m=s[h+2]-p,v=T*m-x*c,S=x*M-b*m,D=b*c-T*M;n[h]+=v,n[h+1]+=S,n[h+2]+=D,n[u]+=v,n[u+1]+=S,n[u+2]+=D,n[f]+=v,n[f+1]+=S,n[f+2]+=D}for(let l=0;l<r*3;l+=3){let h=n[l],u=n[l+1],f=n[l+2],g=Math.hypot(h,u,f)||1;n[l]=h/g,n[l+1]=u/g,n[l+2]=f/g}return this.setAttribute("normal",new ge(n,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new ge(t,3)),this.setAttribute("normal",new ge(i,3)),this.setAttribute("uv",new ge(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new ge(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new ee(1/0,1/0,1/0),r=new ee(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),a=t.getY(s),o=t.getZ(s);n<i.x&&(i.x=n),a<i.y&&(i.y=a),o<i.z&&(i.z=o),n>r.x&&(r.x=n),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let h=o[l+t],u=o[l+i];o[l+t]=h*s-u*n,o[l+i]=h*n+u*s}a.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new ee;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new Oi;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},at=class extends de{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,a=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],o=[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],l=[],h=[];for(let u=0;u<6;u++){let f=u*4;l.push(0,0,1,0,1,1,0,1),h.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(a,o,l,h)}},zt=class extends de{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],a=[],o=[];for(let l=0;l<=r;l++){let h=l/r;for(let u=0;u<=i;u++){let f=u/i;if(s.push((f-.5)*e,(.5-h)*t,0),n.push(0,0,1),a.push(f,1-h),l>0&&u>0){let g=(i+1)*l+u-1,w=g-(i+1);o.push(w,g,w+1,g,g+1,w+1)}}}this.setFromBuffers(s,n,a,o)}},Gt=class extends de{constructor(e=1,t=16,i=12,r=0,s=Math.PI*2,n=0,a=Math.PI){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let o=[],l=[],h=[],u=[],f=Math.min(n+a,Math.PI);for(let g=0;g<=i;g++){let w=g/i,p=n+w*a;for(let b=0;b<=t;b++){let T=b/t,x=r+T*s,M=-Math.cos(x)*Math.sin(p),c=Math.cos(p),m=Math.sin(x)*Math.sin(p);if(o.push(e*M,e*c,e*m),l.push(M,c,m),h.push(T,1-w),g>0&&b>0){let v=(t+1)*g+b,S=v-(t+1),D=S-1,I=v-1;(g!==1||n>0)&&u.push(S,D,v),(g!==i||f<Math.PI)&&u.push(D,I,v)}}}this.setFromBuffers(o,l,h,u)}},ct=class extends de{constructor(e=1,t=1,i=1,r=16,s=1,n=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1));let l=[],h=[],u=[],f=[],g=i/2,w=(t-e)/(i||1),p=r+1;for(let T=0;T<=s;T++){let x=T/s,M=x*(t-e)+e,c=g-x*i;for(let m=0;m<=r;m++){let v=m/r,S=a+v*o,D=Math.sin(S),I=Math.cos(S),P=Math.hypot(D,w,I)||1;if(l.push(M*D,c,M*I),h.push(D/P,w/P,I/P),u.push(v,1-x),T<s&&m<r){let N=T*p+m,C=N+p;f.push(N,C,N+1,C,C+1,N+1)}}}let b=(T,x)=>{if(n||T<=0)return;let M=x*g,c=l.length/3;l.push(0,M,0),h.push(0,x,0),u.push(.5,.5);let m=c+1;for(let v=0;v<=r;v++){let S=a+v/r*o,D=Math.sin(S),I=Math.cos(S);l.push(T*D,M,T*I),h.push(0,x,0),u.push(I*.5+.5,.5+x*D*.5),v<r&&f.push(c,m+v+(x>0?0:1),m+v+(x>0?1:0))}};b(e,1),b(t,-1),this.setFromBuffers(l,h,u,f)}},Ht=class extends ct{constructor(e=1,t=1,i=16,r=1,s=!1,n=0,a=Math.PI*2){super(0,e,t,i,r,s,n,a)}},$t=class extends de{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],a=[],o=[],l=[];for(let h=0;h<=i;h++){let u=h/i*Math.PI*2,f=Math.cos(u),g=Math.sin(u);for(let w=0;w<=r;w++){let p=w/r*s,b=Math.cos(p),T=Math.sin(p);if(n.push((e+t*f)*b,(e+t*f)*T,t*g),a.push(f*b,f*T,g),o.push(w/r,h/i),h>0&&w>0){let x=(r+1)*h+w-1,M=x-(r+1);l.push(x,M,x+1,M,M+1,x+1)}}}this.setFromBuffers(n,a,o,l)}};function _r(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],h=[],u=[],f=[],g=[],w=new ee,p=new ee,b=new ee;for(let x=0;x<=n;x++){let M=new ee;s(x/n,M),g.push(M)}let T=a+1;for(let x=0;x<=n;x++){let M=x/n,c=g[x];w.subVectors(g[Math.min(n,x+1)],g[Math.max(0,x-1)]).normalize(),x===0&&p.set(Math.abs(w.y)>.9?1:0,Math.abs(w.y)>.9?0:1,0),b.crossVectors(w,p).normalize(),p.crossVectors(b,w).normalize();for(let m=0;m<=a;m++){let v=m/a*Math.PI*2,S=-Math.cos(v),D=Math.sin(v),I=S*p.x+D*b.x,P=S*p.y+D*b.y,N=S*p.z+D*b.z;if(l.push(c.x+o*I,c.y+o*P,c.z+o*N),h.push(I,P,N),u.push(M,m/a),x>0&&m>0){let C=T*(x-1)+m-1,L=C+T;f.push(C,L,C+1,L,L+1,C+1)}}}e.setFromBuffers(l,h,u,f)}var Xt=class extends de{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),_r(this,i,r,t,(a,o)=>{let l=a*s*Math.PI*2,h=n/s*l,u=e*(2+Math.cos(h))*.5;o.set(u*Math.cos(l),u*Math.sin(l),e*Math.sin(h)*.5)})}},Fe=class{getPoint(e,t=new ee){return t}getPointAt(e,t=new ee){return this.getPoint(e,t)}getTangent(e,t=new ee){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Wt=class extends Fe{constructor(e=new ee,t=new ee){super(),this.v1=e,this.v2=t}getPoint(e,t=new ee){return t.lerpVectors(this.v1,this.v2,e)}},jt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new ee){return t.lerpVectors(this.v0,this.v1,e).lerp(new ee().lerpVectors(this.v1,this.v2,e),e)}},Kt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee,r=new ee){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new ee){let i=new ee().lerpVectors(this.v0,this.v1,e),r=new ee().lerpVectors(this.v1,this.v2,e),s=new ee().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Yt=class extends Fe{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new ee){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),a=s-n;!this.closed&&n>=r-1&&(n=r-2,a=1);let o=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],l=o(n-1),h=o(n),u=o(n+1),f=o(n+2),g=a*a,w=g*a,p=(b,T,x,M)=>.5*(2*T+(x-b)*a+(2*b-5*T+4*x-M)*g+(3*T-b-3*x+M)*w);return t.set(p(l.x,h.x,u.x,f.x),p(l.y,h.y,u.y,f.y),p(l.z,h.z,u.z,f.z))}},ut=class extends de{constructor(e=[new Se(0,-.5),new Se(.5,0),new Se(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Se(.2,0),new Se(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),a=[],o=[],l=[],h=[],u=s.length;for(let f=0;f<=n;f++){let g=f/n,w=i+g*r,p=Math.sin(w),b=Math.cos(w),T=f*u;for(let x=0;x<u;x++){let M=s[x],c=Number(M?.x)||0,m=Number(M?.y)||0;a.push(c*p,m,c*b);let v=s[Math.max(0,x-1)],S=s[Math.min(u-1,x+1)],D=(Number(S?.x)||0)-(Number(v?.x)||0),I=(Number(S?.y)||0)-(Number(v?.y)||0),P=Math.hypot(I,D)||1;if(o.push(I/P*p,-D/P,I/P*b),l.push(g,x/(u-1)),f<n&&x<u-1){let N=T+x,C=N+u;h.push(N,C,N+1,C,C+1,N+1)}}}this.setFromBuffers(a,o,l,h)}},qt=class extends de{constructor(e,t=64,i=1,r=8,s=!1){super(),_r(this,t,r,i,(n,a)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let l=o.call(e,n,a);l&&l!==a&&a.copy(l)}else a.set(0,n,0)})}},Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",qe=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Se(1,1),this.offset=new Se(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Zt=class extends qe{constructor(e=null,t=1,i=1,r=1023,s=1009,n,a=1001,o=1001,l=1003,h=1003,u=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let g=Number(t),w=Number(i),p=e&&typeof e.length=="number"?e:null;this.width=g,this.height=w,this.image={data:p,width:g,height:w},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(h)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),a=s*n,o=this.format,l=o===1021||o===1024||o===1028||t.length===a?1:o===1025||o===1030||t.length===a*2?2:o===1022||t.length===a*3?3:4,h=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,u=Math.min(s,48),f=Math.min(n,48),g=(this.flipY?257:1)^this.colorSpace.length^t.length,w=Math.max(1,t.length>>6|0);for(let L=0;L<t.length;L+=w)g=Math.imul(g^(t[L]*256|0),16777619)|0;if(g===this._sig&&this.source)return;this._sig=g;let p=f*(1+u*4),b=new Uint8Array(68+p),T=new DataView(b.buffer);T.setUint32(0,2303741511),T.setUint32(4,218765834),T.setUint32(8,13),T.setUint32(12,1229472850),T.setUint32(16,u),T.setUint32(20,f),b[24]=8,b[25]=6,T.setUint32(29,Dt(b.subarray(12,29))),T.setUint32(33,p+11),T.setUint32(37,1229209940),b[41]=120,b[42]=1,b[43]=1,T.setUint16(44,p,!0),T.setUint16(46,~p&65535,!0);let x=48,M=1,c=0,m=0,v=0,S=0,D=0,I=L=>{if(!Number.isFinite(L))return 0;let E=h&&L<=1?L*255:L;return E>0?E<255?E+.5|0:255:0};for(let L=0;L<f;L++){let E=L*n/f|0,y=this.flipY?n-1-E:E;b[x++]=0,c+=M;for(let F=0;F<u;F++){let z=(y*s+(F*s/u|0))*l,A=o===1021?255:I(t[z]??0),_=l>=3||o===1030?I(t[z+1]??0):A,d=l>=3?I(t[z+2]??0):o===1030?0:A,R=l===4?I(t[z+3]??255):o===1021?I(t[z]??255):o===1025?I(t[z+1]??255):255;b[x++]=A,M+=A,c+=M,b[x++]=_,M+=_,c+=M,b[x++]=d,M+=d,c+=M,b[x++]=R,M+=R,c+=M,m+=A,v+=_,S+=d,D+=R}M%=65521,c%=65521}T.setUint32(x,(c<<16|M)>>>0),T.setUint32(x+4,Dt(b.subarray(37,x+4))),T.setUint32(x+12,1229278788),T.setUint32(x+16,2923585666);let P=u*f*255,N=this.colorSpace==="srgb-linear";this.avgColor=[N?m/P:ve(m/P),N?v/P:ve(v/P),N?S/P:ve(S/P),D/P];let C=["data:image/png;base64,"];for(let L=0;L<b.length;L+=3){let E=b[L]<<16|(b[L+1]??0)<<8|(b[L+2]??0);C.push(Lt[E>>18&63]+Lt[E>>12&63]+(L+1<b.length?Lt[E>>6&63]:"=")+(L+2<b.length?Lt[E&63]:"="))}this.source=C.join("")}},Jt=class{load(e,t){let i=new qe(e);return t?.(i),i}};function xe(e,t){return e!==void 0?Number(e):t}function Pn(e,t){return e!==void 0?!!e:t}var Me=class{constructor(e={}){this.name=e.name||"",this.color=new we(e.color??16777215),this.emissive=new we(e.emissive??0),this.emissiveIntensity=xe(e.emissiveIntensity,1),this.roughness=xe(e.roughness,.5),this.metalness=xe(e.metalness,0),this.opacity=xe(e.opacity,1),this.transparent=Pn(e.transparent,!1),this.wireframe=Pn(e.wireframe,!1),this.side=xe(e.side,2),this.doubleSided=Pn(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=xe(e.clearcoat,0),this.clearcoatRoughness=xe(e.clearcoatRoughness,0),this.sheen=xe(e.sheen,0),this.sheenColor=new we(e.sheenColor??0),this.sheenRoughness=xe(e.sheenRoughness,0),this.transmission=xe(e.transmission,0),this.thickness=xe(e.thickness,0),this.attenuationColor=new we(e.attenuationColor??16777215),this.attenuationDistance=xe(e.attenuationDistance,1/0),this.ior=xe(e.ior,1.5),this.dispersion=xe(e.dispersion,0),this.iridescence=xe(e.iridescence,0),this.iridescenceIOR=xe(e.iridescenceIOR,1.3)}dispose(){}},ze=class extends Me{},Qt=class extends Me{},en=class extends Me{},tn=class extends Me{},nn=class extends Me{},Ae=class $i{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 ee,this.rotation=new ot,this.quaternion=new Ye,this.scale=new ee(1,1,1),this.matrix=new Be,this.matrixWorld=new Be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=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)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof $i&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let a=n.length-1;a>=0;a--)r.push(n[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Sr(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new ee(t,i,r);this.target instanceof ee?this.target.copy(s):this.target?.position instanceof ee&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Be;n.lookAt(this.position,s,new ee(0,1,0));let a=n.elements,o=a[0],l=a[4],h=a[8],u=a[1],f=a[5],g=a[9],w=a[2],p=a[6],b=a[10],T=o+f+b;if(T>0){let x=.5/Math.sqrt(T+1);this.quaternion.set((p-g)*x,(h-w)*x,(u-l)*x,.25/x)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Be().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new ee(1,0,0),t)}translateY(t){return this.translateOnAxis(new ee(0,1,0),t)}translateZ(t){return this.translateOnAxis(new ee(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let i=this;i&&t.length<64;i=i.parent)t.push(i);return t}_syncWorld(){let t=this._chain();for(let i=t.length-1;i>=0;i--){let r=t[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new ee){let i=this._syncWorld();return t.set(i[12],i[13],i[14])}getWorldScale(t=new ee){let i=this._syncWorld();return t.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(t=new ee){let i=this._syncWorld();return t.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(t=new Ye){let i=this._chain();t.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)t.multiply(i[r].quaternion);return t}clone(t=!0){let i=this instanceof Ve?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Ie?new Ie(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},rn=class extends Ae{},Ie=class extends Ae{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof de?e:e?(He("unsupported geometry","BoxGeometry"),new at(.5,.5,.5)):new de,this.material=i instanceof Me?i:i?(He("unsupported material","MeshStandardMaterial"),new ze({color:13421772})):new ze}};function Sr(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=le().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var lt=1e4,mt=class extends Ie{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>lt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${lt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let a=n*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new ge(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let a=Number(t.elements[n]);r[s+n]=Number.isFinite(a)?a:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new ge(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Ge=class extends Ae{constructor(e=16777215,t=1){super(),this.color=new we(e),this.intensity=Number(t),this.type="directional"}},ht=class extends Ge{constructor(e,t){super(e,t),this.type="ambient"}},sn=class extends Ge{constructor(e,t){super(e,t),this.target=new Ae,this.type="directional"}},ft=class extends Ge{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},dt=class extends Ae{},on=class extends dt{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new ee(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},pt=class extends Ae{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return De.validate(this),Ke(this)}toGLB(){return De.validate(this),tt(this)}toUSDZ(){return De.validate(this),nt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Ie){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Fn=Ke,kn=tt,wr=nt,De=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(o,l,h)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${h}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};e.traverse(o=>{if(Sr(o),o instanceof Ie||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),o instanceof mt){let h=a("instance",o.count);(h<0||h>lt)&&n("INSTANCES",lt,h)}let l=o.geometry;if(l){let h=0;if(l.attributes.position&&(h=a("vertex",l.attributes.position.count),t+=h,t>1e5&&n("VERTICES",1e5,t)),l.index){let u=a("index",l.index.count);i+=u,i>3e5&&n("INDICES",3e5,i);let f=l.index.array;if(f&&h>0){let g=Math.min(u,f.length);for(let w=0;w<g;w++){let p=f[w];if(!Number.isFinite(p)||p<0||p>=h)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${h}).`)}}}}if(o.material){let h=o.material;for(let u of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])h[u]&&s.add(h[u])}}}),s.size>16&&n("TEXTURES",16,s.size);for(let o of s){let l=o,h=l.image,u=Number(h?.width??l.width??0)||0,f=Number(h?.height??l.height??0)||0;(!Number.isFinite(u)||!Number.isFinite(f)||u>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(u,f))}}},an=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,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 t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let i=new we(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){De.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[a,o]of s.entries())n[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Fn(e),n=kn(e),a=(s.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:a,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function pr(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var cn=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=pr(),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 t=pr();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function mi(){}var it=new Proxy(mi,{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:it},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>it,construct:()=>it}),br=(()=>{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 _n(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ze(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,_n());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 gr,rt;function Ar(e){if(!Ze(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(rt===void 0||gr!==t){gr=t;try{rt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ze(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{rt=null}}return rt?rt.createScriptURL(e):e}function hi(e){le().sandboxEngineSrc=e}function Un(){let e=le().sandboxEngineSrc;if(e)return e;if(br)return br;try{if(typeof document>"u")return null;let t=_n(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Ze(s,{requireSameOrigin:!0}))return s}}catch{}return null}function On(e,t){if(!Ze(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,_n()).href}function fi(){let e=Un();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.");return On(e,"sandbox engine")}function di(e){le().sandboxIframeSrc=e}function Er(){let e=le().sandboxIframeSrc;if(e)return e;let t=Un();if(!t||!Ze(t))return null;let i=new URL(t,_n());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function pi(){let e=Er();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.");return On(e,"sandbox iframe")}function bi(e){le().allowClientScripts=e}function Rr(){return!!le().allowClientScripts}function gi(e){return On(e,"procedural scene script")}var yi=["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(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,a=e.allowClientScripts,o=e.revoked,l=i.postMessage.bind(i);function h(c){l({type:"ERROR",nonce:r,message:String(c)})}let u=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,g=null;try{let c=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let m={createScriptURL:function(S){if(S!==s&&(!n||S!==n))throw new TypeError("Disallowed worker importScripts URL");return S}};a&&(m.createScript=function(S){return String(S)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",m);c=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),a&&typeof v.createScript=="function"&&(g=v.createScript.bind(v))}catch{}u(c)}catch(c){h('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(c&&c.message||c));return}let w=i.THREE;if(!w||typeof w.Scene!="function"){h('Sandbox loaded "'+s+'" 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 c=i.__THREE_LIVE_REGISTRY__;for(let m=0;m<t.length;m++)if(typeof t[m]=="function")try{t[m](w,c)}catch{}}function p(c,m,v){let S=i;for(;S&&S!==Object.prototype;){if(!v&&S!==i)try{delete S[c]}catch{}if(!v||S===i||Object.prototype.hasOwnProperty.call(S,c))try{Object.defineProperty(S,c,v?{value:m,writable:!1,configurable:!1}:{value:m,writable:!1,configurable:!1,enumerable:!1})}catch{}try{S=Object.getPrototypeOf(S)}catch{break}}}for(let c=0;c<o.length;c++)p(o[c],void 0);p("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],T=!1;function x(c,m){if(c.type==="3D_MODEL_READY"){if(T)return;T=!0}c.nonce=r,m&&m.length?l(c,m):l(c)}p("postMessage",function(c,m){if(!c||b.indexOf(c.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");x(c,m)},!0);let M=!1;i.onmessage=function(c){let m=c&&c.data;if(!(!m||m.nonce!==r)&&!(m.type!=="EXECUTE"&&m.type!=="EXECUTE_URL")&&!M){M=!0;try{let v=new w.Scene,S=new w.PerspectiveCamera(60,1,.1,1e3),D=new w.WebGLRenderer({isSandboxed:!0});if(m.type==="EXECUTE_URL"){if(!n||m.scriptUrl!==n||typeof u!="function"){h("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,P=u;if(u=null,f=null,i.THREE=w,i.scene=v,i.camera=S,i.renderer=D,P(I),typeof i.__THREE_LIVE_SCENE__=="function"){let N=i.__THREE_LIVE_SCENE__(w,v,S,D);N&&typeof N.toGLB=="function"&&(v=N)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!a){h("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=g?(0,eval)(g(`(function (THREE, scene, camera, renderer) {
|
|
342
369
|
return (function () {
|
|
343
|
-
`+
|
|
370
|
+
`+m.script+`
|
|
344
371
|
;
|
|
345
372
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
346
373
|
})();
|
|
347
374
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
348
|
-
`+
|
|
375
|
+
`+m.script+`
|
|
349
376
|
;
|
|
350
377
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
351
|
-
})();`);y=null;let N=I(g,v,R,L);N&&typeof N.toGLB=="function"&&(v=N)}if(!w){g.SceneQuotaValidator&&g.SceneQuotaValidator.validate(v);let I=v.toGLB(),N=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);M({type:"3D_MODEL_READY",glbBuffer:N},[N])}h({type:"DONE",nonce:r})}catch(v){l(v&&v.message||v)}}},h({type:"READY",nonce:r})}function Vn(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:xi},o=(ae().workerExtensionInstallers??[]).map(a=>`(${a.toString()})`).join(",");return`'use strict';(${vi.toString()})(${JSON.stringify(n)},[${o}]);`}function Dr(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 Pe=0;function Ir(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Mi(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var wi=1024,Si=256;function xr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function zn(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,wi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!xr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),o=r;for(let a of s){if(a.length>Si||a==="__proto__"||a==="constructor"||a==="prototype")return null;let h=o[a];if(!xr(h))return null;n[a]=h}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Ti(e){let t=Mi(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Nr(e,t,i,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":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function _i(e,t,i,r){let s=Ir(),n=Vn(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=i,Pe++;let a=!1,h=!1,l={modelDispatched:!1},c,f=()=>{if(a||h)return;let b=o.contentWindow;!b||typeof b.postMessage!="function"||(h=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},y=()=>{},g=b=>{if(a||!o.contentWindow||b.source!==o.contentWindow)return;let w=b.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){f();return}let M=zn(w,s);M&&Nr(M,r,y,l)};y=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),Pe=Math.max(0,Pe-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",g),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{a||(y(),Dr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",g),o.onload=()=>{f()},o.onerror=()=>{y(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let u=document.body||document.documentElement;if(!u||typeof u.appendChild!="function"){y();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return u.appendChild(o),{terminate:y}}function vr(e,t,i,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(Pe>=32)return r(`SecurityError: ${Pe} 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 s;try{s=di()}catch(y){let g=y instanceof Error?y.message:String(y);return r(g,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let y;try{y=bi()}catch(g){let u=g instanceof Error?g.message:String(g);return r(u,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(_i(e,s,y,i))}catch(g){return Promise.reject(g)}}let n=Ir(),o=Vn(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a;try{let y=new Blob([o],{type:"application/javascript"}),g=URL.createObjectURL(y);try{let u=Er(g);a=new Worker(u)}finally{URL.revokeObjectURL(g)}}catch(y){let g=y instanceof Error?y.message:String(y);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${g}`,"Security Error: Failed to start Worker sandbox.")}Pe++;let h=!1,l={modelDispatched:!1},c,f=()=>{h||(h=!0,c!==void 0&&clearTimeout(c),Pe=Math.max(0,Pe-1),a.terminate())};return c=setTimeout(()=>{h||(f(),Dr(i))},3e3),a.onmessage=y=>{let g=zn(y.data,n);g&&Nr(g,i,f,l)},a.onerror=y=>{f(),i.onError?.(new Error(`Worker execution error: ${y.message}`))},e.kind==="url"?a.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):a.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function Mr(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 wr=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},Lr={execute(e,t,i,r){let s=wr(i),n=Mr(t,s);if(n)return n;try{Ti(e)}catch(o){let a=o instanceof Error?o.message:String(o);return s(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Cr()?vr({kind:"script",script:e},t,i,s):s(Hn,Xn)},executeUrl(e,t,i){let r=wr(i),s=Mr(t,r);if(s)return s;let n;try{n=yi(e)}catch(o){let a=o instanceof Error?o.message:String(o);return r(a,"Security Error: disallowed scene script URL.")}return vr({kind:"url",scriptUrl:n},t,i,r)}},on=new Set;function Ge(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;on.has(i)||(on.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Pr(){return Array.from(on)}function Fr(){on.clear()}var pt=class extends Ve{constructor(e={}){Ge("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},kr=pt,Ne=class extends me{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),o=n+1,a=[],h=[],l=[],c=[],f=new Z,y=new Z,g=new Z,u=(M,x)=>x.set(e[M*3]||0,e[M*3+1]||0,e[M*3+2]||0),b=(M,x)=>{let m=M.clone().normalize();a.push(m.x*s,m.y*s,m.z*s),h.push(x.x,x.y,x.z),l.push(Math.atan2(m.z,-m.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,m.y)))/Math.PI)},w=(M,x,m)=>{let p=a.length/3,v=n===0?new Z().subVectors(m,x).cross(new Z().subVectors(M,x)).normalize():null;b(M,v||M.clone().normalize()),b(x,v||x.clone().normalize()),b(m,v||m.clone().normalize()),c.push(p,p+1,p+2)};for(let M=0;M<t.length;M+=3){u(t[M],f),u(t[M+1],y),u(t[M+2],g);let x=[];for(let m=0;m<=o;m++){x[m]=[];let p=f.clone().lerp(g,m/o),v=y.clone().lerp(g,m/o),R=o-m;for(let L=0;L<=R;L++)x[m][L]=R===0?p.clone():p.clone().lerp(v,L/R)}for(let m=0;m<o;m++)for(let p=0;p<2*(o-m)-1;p++){let v=p>>1;(p&1)===0?w(x[m][v+1],x[m+1][v],x[m][v]):w(x[m][v+1],x[m+1][v+1],x[m+1][v])}}this.setFromBuffers(a,h,l,c)}},Ai=Ne,an=class extends Ne{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},It=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Ur=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],cn=class extends Ne{constructor(e=1,t=0){super(It,Ur,e,t)}},oe=(1+Math.sqrt(5))/2,un=class extends Ne{constructor(e=1,t=0){super([-1,oe,0,1,oe,0,-1,-oe,0,1,-oe,0,0,-1,oe,0,1,oe,0,-1,-oe,0,1,-oe,oe,0,-1,oe,0,1,-oe,0,-1,-oe,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},we=1/oe,ln=class extends Ne{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-we,-oe,0,-we,oe,0,we,-oe,0,we,oe,-we,-oe,0,-we,oe,0,we,-oe,0,we,oe,0,-oe,0,-we,oe,0,-we,-oe,0,we,oe,0,we],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},mn=class extends ct{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,o=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),a=[];for(let h=-1;h<=1;h+=2)for(let l=0;l<=o;l++){if(h>0&&l===0&&n===0)continue;let c=(h<0?l/o-1:l/o)*(Math.PI/2);a.push(new Se(Math.max(0,Math.cos(c)*s),h*n+Math.sin(c)*s))}super(a,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},bt=class extends me{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let o=Math.max(1e-4,Number(t)||1),a=Number(e),h=Number.isFinite(a)?Math.max(0,a):o*.5,l=Math.max(o,h),c=Math.min(l*.999,Math.min(o,h)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),y=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),g=Number.isFinite(Number(s))?Number(s):0,u=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],w=[],M=[],x=[];for(let m=0;m<=y;m++){let p=c+m/y*(l-c);for(let v=0;v<=f;v++){let R=g+v/f*u,L=Math.cos(R),I=Math.sin(R);if(b.push(p*L,p*I,0),w.push(0,0,1),M.push(p/l*L*.5+.5,p/l*I*.5+.5),m<y&&v<f){let N=m*(f+1)+v,_=N+f+1;p>1e-6&&x.push(N,_,N+1),x.push(_,_+1,N+1)}}}this.setFromBuffers(b,w,M,x)}},hn=class extends bt{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},gt=class extends Me{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Ye=class extends Me{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},fn=class extends Ye{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Or(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),o=y=>`${Math.round((r[y*3]||0)*1e4)},${Math.round((r[y*3+1]||0)*1e4)},${Math.round((r[y*3+2]||0)*1e4)}`,a=t===void 0,h=a?1:Math.cos(t*Math.PI/180),l={},c=[],f=(y,g)=>c.push(r[y*3]||0,r[y*3+1]||0,r[y*3+2]||0,r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0);for(let y=0;y<n;y++){let g=s?s[y*3]:y*3,u=s?s[y*3+1]:y*3+1,b=s?s[y*3+2]:y*3+2,w=r[g*3]||0,M=r[g*3+1]||0,x=r[g*3+2]||0,m=(r[u*3]||0)-w,p=(r[u*3+1]||0)-M,v=(r[u*3+2]||0)-x,R=(r[b*3]||0)-w,L=(r[b*3+1]||0)-M,I=(r[b*3+2]||0)-x,N=p*I-v*L,_=v*R-m*I,A=m*L-p*R,E=Math.hypot(N,_,A);if(!a&&E<1e-8)continue;E>0&&(N/=E,_/=E,A/=E);let C=[g,u,b];for(let d=0;d<3;d++){let k=C[d],$=C[(d+1)%3],S=o(k),D=o($);if(S===D)continue;let T=S<D?`${S}|${D}`:`${D}|${S}`,P=l[T];P?P.m||(P.m=1,P.nx*N+P.ny*_+P.nz*A<=h&&f(k,$)):(l[T]={va:k,vb:$,nx:N,ny:_,nz:A,m:a?1:0},a&&f(k,$))}}if(!a){let y=Object.keys(l);for(let g=0;g<y.length;g++){let u=l[y[g]];u&&!u.m&&f(u.va,u.vb)}}return new Float32Array(c)}var dn=class extends me{constructor(e){super(),this.setAttribute("position",new be(Or(e),3)),this.__isSegmentPairs=!0}},pn=class extends me{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new be(Or(e,i),3)),this.__isSegmentPairs=!0}};function Ei(e,t,i=1){let r=new me;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,o=e.index?.array,a=e.__isSegmentPairs?"segments":t,h=o?o.length:s.count,l=Math.min(4096,Math.max(0,a==="segments"?Math.floor(h/2):a==="loop"&&h>=3?h:h-1));if(l===0)return r;e.computeBoundingBox();let c=e.boundingBox,f=c&&c.max.distanceTo(c.min)||1,y=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),g=[],u=[],b=[],w=[];for(let M=0;M<l;M++){let x=a==="segments"?M*2:M,m=a==="segments"?M*2+1:(M+1)%h,p=o?o[x]:x,v=o?o[m]:m,R=n[p*3]||0,L=n[p*3+1]||0,I=n[p*3+2]||0,N=(n[v*3]||0)-R,_=(n[v*3+1]||0)-L,A=(n[v*3+2]||0)-I,E=Math.hypot(N,_,A);if(E<1e-6)continue;let C=N/E,d=_/E,k=A/E,$=(Math.abs(d)<.9?Math.hypot(k,C):Math.hypot(k,d))||1,S=Math.abs(d)<.9?k/$:0,D=Math.abs(d)<.9?0:-k/$,T=Math.abs(d)<.9?-C/$:d/$,P=d*T-k*D,j=k*S-C*T,W=C*D-d*S,O=g.length/3,Y=[[S,D,T],[P,j,W],[-S,-D,-T],[-P,-j,-W]];for(let U=0;U<2;U++){let X=R+U*N,V=L+U*_,G=I+U*A;for(let F=0;F<4;F++){let H=Y[F];g.push(X+H[0]*y,V+H[1]*y,G+H[2]*y),u.push(H[0],H[1],H[2]),b.push(F/4,U)}}for(let U=0;U<4;U++){let X=(U+1)%4;w.push(O+U,O+X,O+4+X,O+U,O+4+X,O+4+U)}}return g.length>0&&r.setFromBuffers(g,u,b,w),r}function Ri(e,t=.05){let i=new me;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,o=Math.min(n,5e3),a=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),h=[],l=[],c=[],f=[];for(let y=0;y<o;y++){let g=n<=5e3?y:Math.floor(y*n/o),u=s[g*3]||0,b=s[g*3+1]||0,w=s[g*3+2]||0,M=y*6;for(let x=0;x<6;x++){let m=It[x*3],p=It[x*3+1],v=It[x*3+2];h.push(u+m*a,b+p*a,w+v*a),l.push(m,p,v),c.push(.5,.5)}for(let x=0;x<24;x++)f.push(M+Ur[x])}return i.setFromBuffers(h,l,c,f),i}var ke=class extends Re{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Me?t:i==="points"?new gt(r):new Ye(r),n=e instanceof me?e:new me;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,o=0;for(let a=0;a<r;a++)s+=i[a*3]||0,n+=i[a*3+1]||0,o+=i[a*3+2]||0;this.material.color.setRGB(s/r,n/r,o/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ri(this._sourceGeo,this.material?.size??.05):Ei(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},bn=class extends ke{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},gn=class extends ke{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},yn=class extends ke{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},xn=class extends ht{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new _e,this.type="spot";let o=Number(r);this.angle=Number.isFinite(o)?Math.max(.01,Math.min(Math.PI/2,o)):Math.PI/3;let a=Number(s);this.penumbra=Number.isFinite(a)?Math.max(0,Math.min(1,a)):0}},yt=class extends mt{constructor(e,t,i){Ge("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new Te(t??4473924)}},Br=yt,Vr={Vector2:Se,Vector3:Z,Vector4:Lt,Euler:it,Quaternion:st,Matrix4:Fe,Matrix3:Pt,Color:Te,MathUtils:Sr,BufferAttribute:be,Float32BufferAttribute:Ft,Uint16BufferAttribute:kt,Uint32BufferAttribute:Ut,BufferGeometry:me,BoxGeometry:ot,PlaneGeometry:Ot,SphereGeometry:Bt,CylinderGeometry:at,ConeGeometry:Vt,TorusGeometry:zt,TorusKnotGeometry:Gt,Curve:Ie,Curve3:Ie,LineCurve3:Ht,QuadraticBezierCurve3:Xt,CubicBezierCurve3:$t,CatmullRomCurve3:jt,LatheGeometry:ct,TubeGeometry:Wt,PolyhedronGeometry:Ne,IcosahedronGeometry:un,OctahedronGeometry:cn,DodecahedronGeometry:ln,TetrahedronGeometry:an,CapsuleGeometry:mn,RingGeometry:bt,CircleGeometry:hn,WireframeGeometry:dn,EdgesGeometry:pn,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:We,DataTexture:Kt,TextureLoader:Yt,Material:Me,MeshStandardMaterial:Ve,MeshBasicMaterial:qt,MeshLambertMaterial:Zt,MeshPhongMaterial:Jt,MeshPhysicalMaterial:Qt,PointsMaterial:gt,LineBasicMaterial:Ye,LineDashedMaterial:fn,ShaderMaterial:pt,RawShaderMaterial:kr,Object3D:_e,Group:en,Mesh:Re,InstancedMesh:lt,Line:ke,LineLoop:bn,LineSegments:gn,Points:yn,Light:ze,AmbientLight:mt,DirectionalLight:tn,PointLight:ht,SpotLight:xn,HemisphereLight:yt,RectAreaLight:Br,Camera:ft,PerspectiveCamera:nn,Scene:dt,WebGLRenderer:rn,Clock:sn,SceneQuotaValidator:Ee,exportSceneToCanvas3D:kn,exportSceneToGLB:Un,exportSceneToUSDZ:Ar,generateUSDZ:Pn,glbToUSDZ:Rt,sceneToCanvas3D:je,sceneToGLB:Qe,sceneToUSDZ:et,authorScriptRunner:Lr,getAuthorWarnings:Pr,clearAuthorWarnings:Fr};Object.freeze(Ee),Object.freeze(Ee.prototype),Object.freeze(dt.prototype),Object.freeze(Vr);var He=new Proxy(Vr,{get:(e,t)=>{if(t in e)return e[t];let i=ae().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Ge(`THREE.${t}`,"no-op proxy"),nt)},has:(e,t)=>{if(t in e)return!0;let i=ae().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},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")}}),Nt=ae();if(Nt.threeNamespace=He,Nt.workerExtensionInstallers)for(let e of Nt.workerExtensionInstallers)e(He,Nt);var rt={name:"three_author",THREE:He},Ci=rt,De=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof De.THREE>"u"&&(De.THREE=He),typeof De.requestAnimationFrame!="function"&&(De.requestAnimationFrame=e=>(typeof e=="function"&&typeof De.__three_live_raf_cb__!="function"&&(De.__three_live_raf_cb__=e),De.__three_live_in_step__||Ge("requestAnimationFrame","single-frame static evaluation"),0)),typeof De.cancelAnimationFrame!="function"&&(De.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=He,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=rt,e.ThreeLivePlugins.three_author=rt,e.ThreeLivePlugins["three-author"]=rt}var Di=He;
|
|
378
|
+
})();`);g=null;let P=I(w,v,S,D);P&&typeof P.toGLB=="function"&&(v=P)}if(!T){w.SceneQuotaValidator&&w.SceneQuotaValidator.validate(v);let I=v.toGLB(),P=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);x({type:"3D_MODEL_READY",glbBuffer:P},[P])}l({type:"DONE",nonce:r})}catch(v){h(v&&v.message||v)}}},l({type:"READY",nonce:r})}function Bn(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:yi},a=(le().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${xi.toString()})(${JSON.stringify(n)},[${a}]);`}function Cr(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 Oe=0;function Dr(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function vi(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Mi=1024,Ti=256;function yr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function Vn(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Mi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!yr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),a=r;for(let o of s){if(o.length>Ti||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!yr(l))return null;n[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function _i(e){let t=vi(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ir(e,t,i,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":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Si(e,t,i,r){let s=Dr(),n=Bn(t,s,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=i,Oe++;let o=!1,l=!1,h={modelDispatched:!1},u,f=()=>{if(o||l)return;let b=a.contentWindow;!b||typeof b.postMessage!="function"||(l=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},g=()=>{},w=b=>{if(o||!a.contentWindow||b.source!==a.contentWindow)return;let T=b.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){f();return}let x=Vn(T,s);x&&Ir(x,r,g,h)};g=()=>{o||(o=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",w),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{o||(g(),Cr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",w),a.onload=()=>{f()},a.onerror=()=>{g(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){g();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return p.appendChild(a),{terminate:g}}function xr(e,t,i,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(Oe>=32)return r(`SecurityError: ${Oe} 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 s;try{s=fi()}catch(g){let w=g instanceof Error?g.message:String(g);return r(w,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let g;try{g=pi()}catch(w){let p=w instanceof Error?w.message:String(w);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Si(e,s,g,i))}catch(w){return Promise.reject(w)}}let n=Dr(),a=Bn(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let g=new Blob([a],{type:"application/javascript"}),w=URL.createObjectURL(g);try{let p=Ar(w);o=new Worker(p)}finally{URL.revokeObjectURL(w)}}catch(g){let w=g instanceof Error?g.message:String(g);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${w}`,"Security Error: Failed to start Worker sandbox.")}Oe++;let l=!1,h={modelDispatched:!1},u,f=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),o.terminate())};return u=setTimeout(()=>{l||(f(),Cr(i))},3e3),o.onmessage=g=>{let w=Vn(g.data,n);w&&Ir(w,i,f,h)},o.onerror=g=>{f(),i.onError?.(new Error(`Worker execution error: ${g.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):o.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function vr(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 Mr=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},Nr={execute(e,t,i,r){let s=Mr(i),n=vr(t,s);if(n)return n;try{_i(e)}catch(a){let o=a instanceof Error?a.message:String(a);return s(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Rr()?xr({kind:"script",script:e},t,i,s):s(Gn,Hn)},executeUrl(e,t,i){let r=Mr(i),s=vr(t,r);if(s)return s;let n;try{n=gi(e)}catch(a){let o=a instanceof Error?a.message:String(a);return r(o,"Security Error: disallowed scene script URL.")}return xr({kind:"url",scriptUrl:n},t,i,r)}},un=new Set;function He(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;un.has(i)||(un.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Lr(){return Array.from(un)}function Pr(){un.clear()}var bt=class extends ze{constructor(e={}){He("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Fr=bt,ke=class extends de{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=n+1,o=[],l=[],h=[],u=[],f=new ee,g=new ee,w=new ee,p=(x,M)=>M.set(e[x*3]||0,e[x*3+1]||0,e[x*3+2]||0),b=(x,M)=>{let c=x.clone().normalize();o.push(c.x*s,c.y*s,c.z*s),l.push(M.x,M.y,M.z),h.push(Math.atan2(c.z,-c.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,c.y)))/Math.PI)},T=(x,M,c)=>{let m=o.length/3,v=n===0?new ee().subVectors(c,M).cross(new ee().subVectors(x,M)).normalize():null;b(x,v||x.clone().normalize()),b(M,v||M.clone().normalize()),b(c,v||c.clone().normalize()),u.push(m,m+1,m+2)};for(let x=0;x<t.length;x+=3){p(t[x],f),p(t[x+1],g),p(t[x+2],w);let M=[];for(let c=0;c<=a;c++){M[c]=[];let m=f.clone().lerp(w,c/a),v=g.clone().lerp(w,c/a),S=a-c;for(let D=0;D<=S;D++)M[c][D]=S===0?m.clone():m.clone().lerp(v,D/S)}for(let c=0;c<a;c++)for(let m=0;m<2*(a-c)-1;m++){let v=m>>1;(m&1)===0?T(M[c][v+1],M[c+1][v],M[c][v]):T(M[c][v+1],M[c+1][v+1],M[c+1][v])}}this.setFromBuffers(o,l,h,u)}},wi=ke,ln=class extends ke{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},Pt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],kr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],mn=class extends ke{constructor(e=1,t=0){super(Pt,kr,e,t)}},ue=(1+Math.sqrt(5))/2,hn=class extends ke{constructor(e=1,t=0){super([-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,0,0,-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,ue,0,-1,ue,0,1,-ue,0,-1,-ue,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},_e=1/ue,fn=class extends ke{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,0,-ue,0,-_e,ue,0,-_e,-ue,0,_e,ue,0,_e],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},dn=class extends ut{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let h=0;h<=a;h++){if(l>0&&h===0&&n===0)continue;let u=(l<0?h/a-1:h/a)*(Math.PI/2);o.push(new Se(Math.max(0,Math.cos(u)*s),l*n+Math.sin(u)*s))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},gt=class extends de{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let a=Math.max(1e-4,Number(t)||1),o=Number(e),l=Number.isFinite(o)?Math.max(0,o):a*.5,h=Math.max(a,l),u=Math.min(h*.999,Math.min(a,l)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),g=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),w=Number.isFinite(Number(s))?Number(s):0,p=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],T=[],x=[],M=[];for(let c=0;c<=g;c++){let m=u+c/g*(h-u);for(let v=0;v<=f;v++){let S=w+v/f*p,D=Math.cos(S),I=Math.sin(S);if(b.push(m*D,m*I,0),T.push(0,0,1),x.push(m/h*D*.5+.5,m/h*I*.5+.5),c<g&&v<f){let P=c*(f+1)+v,N=P+f+1;m>1e-6&&M.push(P,N,P+1),M.push(N,N+1,P+1)}}}this.setFromBuffers(b,T,x,M)}},pn=class extends gt{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},yt=class extends Me{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Je=class extends Me{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},bn=class extends Je{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Ur(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),a=g=>`${Math.round((r[g*3]||0)*1e4)},${Math.round((r[g*3+1]||0)*1e4)},${Math.round((r[g*3+2]||0)*1e4)}`,o=t===void 0,l=o?1:Math.cos(t*Math.PI/180),h={},u=[],f=(g,w)=>u.push(r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0,r[w*3]||0,r[w*3+1]||0,r[w*3+2]||0);for(let g=0;g<n;g++){let w=s?s[g*3]:g*3,p=s?s[g*3+1]:g*3+1,b=s?s[g*3+2]:g*3+2,T=r[w*3]||0,x=r[w*3+1]||0,M=r[w*3+2]||0,c=(r[p*3]||0)-T,m=(r[p*3+1]||0)-x,v=(r[p*3+2]||0)-M,S=(r[b*3]||0)-T,D=(r[b*3+1]||0)-x,I=(r[b*3+2]||0)-M,P=m*I-v*D,N=v*S-c*I,C=c*D-m*S,L=Math.hypot(P,N,C);if(!o&&L<1e-8)continue;L>0&&(P/=L,N/=L,C/=L);let E=[w,p,b];for(let y=0;y<3;y++){let F=E[y],z=E[(y+1)%3],A=a(F),_=a(z);if(A===_)continue;let d=A<_?`${A}|${_}`:`${_}|${A}`,R=h[d];R?R.m||(R.m=1,R.nx*P+R.ny*N+R.nz*C<=l&&f(F,z)):(h[d]={va:F,vb:z,nx:P,ny:N,nz:C,m:o?1:0},o&&f(F,z))}}if(!o){let g=Object.keys(h);for(let w=0;w<g.length;w++){let p=h[g[w]];p&&!p.m&&f(p.va,p.vb)}}return new Float32Array(u)}var gn=class extends de{constructor(e){super(),this.setAttribute("position",new ge(Ur(e),3)),this.__isSegmentPairs=!0}},yn=class extends de{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new ge(Ur(e,i),3)),this.__isSegmentPairs=!0}};function Ai(e,t,i=1){let r=new de;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,a=e.index?.array,o=e.__isSegmentPairs?"segments":t,l=a?a.length:s.count,h=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(h===0)return r;e.computeBoundingBox();let u=e.boundingBox,f=u&&u.max.distanceTo(u.min)||1,g=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),w=[],p=[],b=[],T=[];for(let x=0;x<h;x++){let M=o==="segments"?x*2:x,c=o==="segments"?x*2+1:(x+1)%l,m=a?a[M]:M,v=a?a[c]:c,S=n[m*3]||0,D=n[m*3+1]||0,I=n[m*3+2]||0,P=(n[v*3]||0)-S,N=(n[v*3+1]||0)-D,C=(n[v*3+2]||0)-I,L=Math.hypot(P,N,C);if(L<1e-6)continue;let E=P/L,y=N/L,F=C/L,z=(Math.abs(y)<.9?Math.hypot(F,E):Math.hypot(F,y))||1,A=Math.abs(y)<.9?F/z:0,_=Math.abs(y)<.9?0:-F/z,d=Math.abs(y)<.9?-E/z:y/z,R=y*d-F*_,G=F*A-E*d,H=E*_-y*A,B=w.length/3,Z=[[A,_,d],[R,G,H],[-A,-_,-d],[-R,-G,-H]];for(let k=0;k<2;k++){let Y=S+k*P,ie=D+k*N,re=I+k*C;for(let O=0;O<4;O++){let J=Z[O];w.push(Y+J[0]*g,ie+J[1]*g,re+J[2]*g),p.push(J[0],J[1],J[2]),b.push(O/4,k)}}for(let k=0;k<4;k++){let Y=(k+1)%4;T.push(B+k,B+Y,B+4+Y,B+k,B+4+Y,B+4+k)}}return w.length>0&&r.setFromBuffers(w,p,b,T),r}function Ei(e,t=.05){let i=new de;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,a=Math.min(n,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),l=[],h=[],u=[],f=[];for(let g=0;g<a;g++){let w=n<=5e3?g:Math.floor(g*n/a),p=s[w*3]||0,b=s[w*3+1]||0,T=s[w*3+2]||0,x=g*6;for(let M=0;M<6;M++){let c=Pt[M*3],m=Pt[M*3+1],v=Pt[M*3+2];l.push(p+c*o,b+m*o,T+v*o),h.push(c,m,v),u.push(.5,.5)}for(let M=0;M<24;M++)f.push(x+kr[M])}return i.setFromBuffers(l,h,u,f),i}var Ve=class extends Ie{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Me?t:i==="points"?new yt(r):new Je(r),n=e instanceof de?e:new de;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,a=0;for(let o=0;o<r;o++)s+=i[o*3]||0,n+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(s/r,n/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ei(this._sourceGeo,this.material?.size??.05):Ai(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},xn=class extends Ve{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},vn=class extends Ve{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Mn=class extends Ve{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Tn=class extends ft{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Ae,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(s);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},xt=class extends ht{constructor(e,t,i){He("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new we(t??4473924)}},Or=xt,Br={Vector2:Se,Vector3:ee,Vector4:kt,Euler:ot,Quaternion:Ye,Matrix4:Be,Matrix3:Ut,Color:we,MathUtils:Tr,BufferAttribute:ge,Float32BufferAttribute:Ot,Uint16BufferAttribute:Bt,Uint32BufferAttribute:Vt,BufferGeometry:de,BoxGeometry:at,PlaneGeometry:zt,SphereGeometry:Gt,CylinderGeometry:ct,ConeGeometry:Ht,TorusGeometry:$t,TorusKnotGeometry:Xt,Curve:Fe,Curve3:Fe,LineCurve3:Wt,QuadraticBezierCurve3:jt,CubicBezierCurve3:Kt,CatmullRomCurve3:Yt,LatheGeometry:ut,TubeGeometry:qt,PolyhedronGeometry:ke,IcosahedronGeometry:hn,OctahedronGeometry:mn,DodecahedronGeometry:fn,TetrahedronGeometry:ln,CapsuleGeometry:dn,RingGeometry:gt,CircleGeometry:pn,WireframeGeometry:gn,EdgesGeometry:yn,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:qe,DataTexture:Zt,TextureLoader:Jt,Material:Me,MeshStandardMaterial:ze,MeshBasicMaterial:Qt,MeshLambertMaterial:en,MeshPhongMaterial:tn,MeshPhysicalMaterial:nn,PointsMaterial:yt,LineBasicMaterial:Je,LineDashedMaterial:bn,ShaderMaterial:bt,RawShaderMaterial:Fr,Object3D:Ae,Group:rn,Mesh:Ie,InstancedMesh:mt,Line:Ve,LineLoop:xn,LineSegments:vn,Points:Mn,Light:Ge,AmbientLight:ht,DirectionalLight:sn,PointLight:ft,SpotLight:Tn,HemisphereLight:xt,RectAreaLight:Or,Camera:dt,PerspectiveCamera:on,Scene:pt,WebGLRenderer:an,Clock:cn,SceneQuotaValidator:De,exportSceneToCanvas3D:Fn,exportSceneToGLB:kn,exportSceneToUSDZ:wr,generateUSDZ:Ln,glbToUSDZ:It,sceneToCanvas3D:Ke,sceneToGLB:tt,sceneToUSDZ:nt,authorScriptRunner:Nr,getAuthorWarnings:Lr,clearAuthorWarnings:Pr};Object.freeze(De),Object.freeze(De.prototype),Object.freeze(pt.prototype),Object.freeze(Br);var $e=new Proxy(Br,{get:(e,t)=>{if(t in e)return e[t];let i=le().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&He(`THREE.${t}`,"no-op proxy"),it)},has:(e,t)=>{if(t in e)return!0;let i=le().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},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")}}),Ft=le();if(Ft.threeNamespace=$e,Ft.workerExtensionInstallers)for(let e of Ft.workerExtensionInstallers)e($e,Ft);var st={name:"three_author",THREE:$e},Ri=st,Pe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Pe.THREE>"u"&&(Pe.THREE=$e),typeof Pe.requestAnimationFrame!="function"&&(Pe.requestAnimationFrame=e=>(typeof e=="function"&&typeof Pe.__three_live_raf_cb__!="function"&&(Pe.__three_live_raf_cb__=e),Pe.__three_live_in_step__||He("requestAnimationFrame","single-frame static evaluation"),0)),typeof Pe.cancelAnimationFrame!="function"&&(Pe.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=$e,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=st,e.ThreeLivePlugins.three_author=st,e.ThreeLivePlugins["three-author"]=st}var Ci=$e;
|