UNPKG

phy-engine

Version:

JavaScript 3D Physics for three.js

1 lines 503 kB
import{BufferGeometry as e,BufferAttribute as t,TrianglesDrawMode as s,TriangleFanDrawMode as i,TriangleStripDrawMode as a,Quaternion as r,Matrix4 as o,Loader as n,LoaderUtils as A,FileLoader as l,MeshPhysicalMaterial as h,Vector2 as c,Color as d,LinearSRGBColorSpace as u,SRGBColorSpace as p,SpotLight as g,PointLight as f,DirectionalLight as b,Vector3 as y,InstancedMesh as I,InstancedBufferAttribute as C,Object3D as E,TextureLoader as B,ImageBitmapLoader as w,InterleavedBuffer as v,InterleavedBufferAttribute as x,LinearMipmapLinearFilter as Q,NearestMipmapLinearFilter as k,LinearMipmapNearestFilter as M,NearestMipmapNearestFilter as S,LinearFilter as R,NearestFilter as D,RepeatWrapping as T,MirroredRepeatWrapping as F,ClampToEdgeWrapping as L,PointsMaterial as P,Material as _,LineBasicMaterial as G,MeshStandardMaterial as N,DoubleSide as U,MeshBasicMaterial as O,PropertyBinding as z,SkinnedMesh as H,Mesh as q,LineSegments as j,Line as V,LineLoop as W,Points as J,Group as K,PerspectiveCamera as Y,MathUtils as X,OrthographicCamera as Z,Skeleton as $,AnimationClip as ee,Bone as te,InterpolateDiscrete as se,InterpolateLinear as ie,Texture as ae,VectorKeyframeTrack as re,NumberKeyframeTrack as oe,QuaternionKeyframeTrack as ne,ColorManagement as Ae,FrontSide as le,Interpolant as he,Box3 as ce,Sphere as de,Vector4 as ue,Curve as pe,Euler as ge,MeshPhongMaterial as me,MeshLambertMaterial as fe,EquirectangularReflectionMapping as be,AmbientLight as ye,Float32BufferAttribute as Ie,Uint16BufferAttribute as Ce,Matrix3 as Ee,ShapeUtils as Be,DataTextureLoader as we,HalfFloatType as ve,FloatType as xe,DataUtils as Qe,RGBAFormat as ke,RedFormat as Me,NoColorSpace as Se,RGBA_S3TC_DXT1_Format as Re,RGB_PVRTC_4BPPV1_Format as De,RGB_ETC2_Format as Te,RGB_ETC1_Format as Fe,RGBA_S3TC_DXT5_Format as Le,RGBA_PVRTC_4BPPV1_Format as Pe,RGBA_ETC2_EAC_Format as _e,RGBA_BPTC_Format as Ge,RGB_BPTC_UNSIGNED_Format as Ne,RGBA_ASTC_4x4_Format as Ue,UnsignedByteType as Oe,CompressedCubeTexture as ze,CompressedArrayTexture as He,CompressedTexture as qe,RGBA_ASTC_6x6_Format as je,RGFormat as Ve,DataTexture as We,Data3DTexture as Je,LoadingManager as Ke,AnimationMixer as Ye,ObjectSpaceNormalMap as Xe,SphereGeometry as Ze,CylinderGeometry as $e,BoxGeometry as et,PlaneGeometry as tt,CanvasTexture as st,ShadowMaterial as it,MeshToonMaterial as at,BackSide as rt,SrcAlphaSaturateFactor as ot,OneMinusDstColorFactor as nt,DstColorFactor as At,OneMinusDstAlphaFactor as lt,DstAlphaFactor as ht,OneMinusSrcAlphaFactor as ct,SrcAlphaFactor as dt,OneMinusSrcColorFactor as ut,SrcColorFactor as pt,OneFactor as gt,ZeroFactor as mt,MaxEquation as ft,MinEquation as bt,ReverseSubtractEquation as yt,SubtractEquation as It,AddEquation as Ct,MultiplyBlending as Et,SubtractiveBlending as Bt,AdditiveBlending as wt,NormalBlending as vt,NoBlending as xt,CircleGeometry as Qt,Line3 as kt,Plane as Mt,Triangle as St,Box2 as Rt,Shape as Dt,Path as Tt,ShapePath as Ft,ShapeGeometry as Lt,CustomBlending as Pt,SkeletonHelper as _t,AnimationUtils as Gt,AdditiveAnimationBlendMode as Nt,NormalAnimationBlendMode as Ut,Raycaster as Ot,PMREMGenerator as zt,Scene as Ht,WebGLCubeRenderTarget as qt,CubeCamera as jt,IcosahedronGeometry as Vt,ShaderMaterial as Wt,NoToneMapping as Jt}from"three";const Kt=Math.PI,Yt=Kt/180,Xt=180/Kt,Zt=Number.EPSILON,$t=.5*Kt,es={luminousPowers:{"110000 lm (1000W)":11e4,"3500 lm (300W)":3500,"1700 lm (100W)":1700,"800 lm (60W)":800,"400 lm (40W)":400,"180 lm (25W)":180,"20 lm (4W)":20,Off:0},luminousIrradiances:{"0.0001 lx (Moonless Night)":1e-4,"0.002 lx (Night Airglow)":.002,"0.5 lx (Full Moon)":.5,"3.4 lx (City Twilight)":3.4,"50 lx (Living Room)":50,"100 lx (Very Overcast)":100,"350 lx (Office Room)":350,"400 lx (Sunrise/Sunset)":400,"1000 lx (Overcast)":1e3,"18000 lx (Daylight)":18e3,"50000 lx (Direct Sun)":5e4},exposure:e=>Math.pow(e,5),candelaToLumens:e=>4*e*Math.PI,lumensToCandela:e=>e/(4*Math.PI),todeg:Xt,torad:Yt,toFixed:(e,t=3)=>1*e.toFixed(t),toRound:(e,t=3)=>Math.trunc(e),clamp:(e,t=0,s=1)=>e=(e=e<t?t:e)>s?s:e,clampA:(e,t,s)=>Math.max(t,Math.min(s,e)),lerp:(e,t,s)=>(1-s)*e+s*t,damp:(e,t,s,i)=>es.lerp(e,t,1-Math.exp(-s*i)),nearAngle:(e,t,s=!1)=>t+Math.atan2(Math.sin(e-t),Math.cos(e-t))*(s?Xt:1),unwrapDeg:e=>e-360*Math.floor((e+180)/360),unwrapRad:e=>Math.atan2(Math.sin(e),Math.cos(e)),nearEquals:(e,t,s)=>Math.abs(e-t)<=s,autoSize:(e=[1,1,1],t="box")=>{1===e.length&&(e[1]=e[0]);let s=e[0],i=e[1];return"sphere"===t&&(e=[s,s,s]),"cylinder"!==t&&"wheel"!==t&&"capsule"!==t||(e=[s,i,s]),"cone"!==t&&"pyramid"!==t||(e=[s,i,s]),2===e.length&&(e[2]=e[0]),e},shuffle:e=>e.map((e=>({value:e,sort:Math.random()}))).sort(((e,t)=>e.sort-t.sort)).map((({value:e})=>e)),randomSign:()=>Math.random()<.5?-1:1,randSpread:e=>e*(.5-Math.random()),rand:(e=0,t=1)=>e+Math.random()*(t-e),randInt:(e,t)=>e+Math.floor(Math.random()*(t-e+1)),randIntUnic:(e,t,s)=>{for(var i=[];i.length<s;){var a=es.randInt(e,t);-1===i.indexOf(a)&&i.push(a)}return i},fromTransform:(e,t,s,i=[0,0,0,1],a=!1)=>{let r=es.composeMatrixArray(e,t),o=es.composeMatrixArray(s,i);return a&&(r=es.invertMatrixArray(r)),r=es.multiplyMatrixArray(r,o),[r[12],r[13],r[14]]},fromTransformToQ:(e,t,s=!1)=>{let i=es.composeMatrixArray(e,t),a=es.decomposeFullMatrixArray(i).q;return s&&(a=es.quatInvert(a)),a},lerpTransform:(e,t,s)=>{let i=e[0],a=e[1],r=t[0],o=t[1];return r=es.lerpArray(i,r,s),o=es.slerpQuatArray(a,o,s),[r,o]},composeMatrixArray:(e,t,s=[1,1,1])=>{const i=t[0],a=t[1],r=t[2],o=t[3],n=i+i,A=a+a,l=r+r,h=i*n,c=i*A,d=i*l,u=a*A,p=a*l,g=r*l,m=o*n,f=o*A,b=o*l,y=s[0],I=s[1],C=s[2];return[(1-(u+g))*y,(c+b)*y,(d-f)*y,0,(c-b)*I,(1-(h+g))*I,(p+m)*I,0,(d+f)*C,(p-m)*C,(1-(h+u))*C,0,e[0],e[1],e[2],1]},multiplyMatrixArray:(e,t)=>{const s=e,i=t,a=[],r=s[0],o=s[4],n=s[8],A=s[12],l=s[1],h=s[5],c=s[9],d=s[13],u=s[2],p=s[6],g=s[10],m=s[14],f=s[3],b=s[7],y=s[11],I=s[15],C=i[0],E=i[4],B=i[8],w=i[12],v=i[1],x=i[5],Q=i[9],k=i[13],M=i[2],S=i[6],R=i[10],D=i[14],T=i[3],F=i[7],L=i[11],P=i[15];return a[0]=r*C+o*v+n*M+A*T,a[4]=r*E+o*x+n*S+A*F,a[8]=r*B+o*Q+n*R+A*L,a[12]=r*w+o*k+n*D+A*P,a[1]=l*C+h*v+c*M+d*T,a[5]=l*E+h*x+c*S+d*F,a[9]=l*B+h*Q+c*R+d*L,a[13]=l*w+h*k+c*D+d*P,a[2]=u*C+p*v+g*M+m*T,a[6]=u*E+p*x+g*S+m*F,a[10]=u*B+p*Q+g*R+m*L,a[14]=u*w+p*k+g*D+m*P,a[3]=f*C+b*v+y*M+I*T,a[7]=f*E+b*x+y*S+I*F,a[11]=f*B+b*Q+y*R+I*L,a[15]=f*w+b*k+y*D+I*P,a},invertMatrixArray:e=>{const t=e,s=t[0],i=t[1],a=t[2],r=t[3],o=t[4],n=t[5],A=t[6],l=t[7],h=t[8],c=t[9],d=t[10],u=t[11],p=t[12],g=t[13],m=t[14],f=t[15],b=c*m*l-g*d*l+g*A*u-n*m*u-c*A*f+n*d*f,y=p*d*l-h*m*l-p*A*u+o*m*u+h*A*f-o*d*f,I=h*g*l-p*c*l+p*n*u-o*g*u-h*n*f+o*c*f,C=p*c*A-h*g*A-p*n*d+o*g*d+h*n*m-o*c*m,E=s*b+i*y+a*I+r*C;if(0===E)return[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];const B=1/E;return t[0]=b*B,t[1]=(g*d*r-c*m*r-g*a*u+i*m*u+c*a*f-i*d*f)*B,t[2]=(n*m*r-g*A*r+g*a*l-i*m*l-n*a*f+i*A*f)*B,t[3]=(c*A*r-n*d*r-c*a*l+i*d*l+n*a*u-i*A*u)*B,t[4]=y*B,t[5]=(h*m*r-p*d*r+p*a*u-s*m*u-h*a*f+s*d*f)*B,t[6]=(p*A*r-o*m*r-p*a*l+s*m*l+o*a*f-s*A*f)*B,t[7]=(o*d*r-h*A*r+h*a*l-s*d*l-o*a*u+s*A*u)*B,t[8]=I*B,t[9]=(p*c*r-h*g*r-p*i*u+s*g*u+h*i*f-s*c*f)*B,t[10]=(o*g*r-p*n*r+p*i*l-s*g*l-o*i*f+s*n*f)*B,t[11]=(h*n*r-o*c*r-h*i*l+s*c*l+o*i*u-s*n*u)*B,t[12]=C*B,t[13]=(h*g*a-p*c*a+p*i*d-s*g*d-h*i*m+s*c*m)*B,t[14]=(p*n*a-o*g*a-p*i*A+s*g*A+o*i*m-s*n*m)*B,t[15]=(o*c*a-h*n*a+h*i*A-s*c*A-o*i*d+s*n*d)*B,t},matrixArrayDeterminant:e=>{const t=e,s=t[0],i=t[4],a=t[8],r=t[12],o=t[1],n=t[5],A=t[9],l=t[13],h=t[2],c=t[6],d=t[10],u=t[14];return t[3]*(+r*A*c-a*l*c-r*n*d+i*l*d+a*n*u-i*A*u)+t[7]*(+s*A*u-s*l*d+r*o*d-a*o*u+a*l*h-r*A*h)+t[11]*(+s*l*c-s*n*u-r*o*c+i*o*u+r*n*h-i*l*h)+t[15]*(-a*n*h-s*A*c+s*n*d+a*o*c-i*o*d+i*A*h)},decomposeMatrixArray:e=>[e[12],e[13],e[14]],decomposeFullMatrixArray:e=>{const t=e;let s=es.lengthArray([t[0],t[1],t[2]]);const i=es.lengthArray([t[4],t[5],t[6]]),a=es.lengthArray([t[8],t[9],t[10]]);es.matrixArrayDeterminant(e)<0&&(s=-s);let r=[...e];const o=1/s,n=1/i,A=1/a;r[0]*=o,r[1]*=o,r[2]*=o,r[4]*=n,r[5]*=n,r[6]*=n,r[8]*=A,r[9]*=A,r[10]*=A;let l=es.quatFromRotationMatrix(r);return{p:[e[12],e[13],e[14]],q:l,s:[s,i,a]}},applyTransformArray:(e,t,s,i=[1,1,1])=>{const a=es.composeMatrixArray(t,s,i),r=e[0],o=e[1],n=e[2],A=1/(a[3]*r+a[7]*o+a[11]*n+a[15]);return[(a[0]*r+a[4]*o+a[8]*n+a[12])*A,(a[1]*r+a[5]*o+a[9]*n+a[13])*A,(a[2]*r+a[6]*o+a[10]*n+a[14])*A]},slerpQuatArray:(e,t,s)=>{if(0===s)return e;if(1===s)return t;let i=[...e];const a=e[0],r=e[1],o=e[2],n=e[3],A=t[0],l=t[1],h=t[2],c=t[3];let d=n*c+a*A+r*l+o*h;if(d<0?(i=[-A,-l,-h,-c],d=-d):i=[...t],d>=1)return e;const u=1-d*d;if(u<=Zt){const e=1-s;return i[3]=e*n+s*i[3],i[0]=e*a+s*i[0],i[1]=e*r+s*i[1],i[2]=e*o+s*i[2],es.quatNomalize(i)}const p=Math.sqrt(u),g=Math.atan2(p,d),m=Math.sin((1-s)*g)/p,f=Math.sin(s*g)/p;return i[3]=n*m+i[3]*f,i[0]=a*m+i[0]*f,i[1]=r*m+i[1]*f,i[2]=o*m+i[2]*f,i},toLocalQuatArray:(e=[0,0,0],t)=>{let s=es.quatFromEuler(e),i=es.quatInvert(t.quaternion.toArray());return es.quatMultiply(i,s)},quatFromRotationMatrix:e=>{let t=[0,0,0,1];const s=e,i=s[0],a=s[4],r=s[8],o=s[1],n=s[5],A=s[9],l=s[2],h=s[6],c=s[10],d=i+n+c;if(d>0){const e=.5/Math.sqrt(d+1);t[3]=.25/e,t[0]=(h-A)*e,t[1]=(r-l)*e,t[2]=(o-a)*e}else if(i>n&&i>c){const e=2*Math.sqrt(1+i-n-c);t[3]=(h-A)/e,t[0]=.25*e,t[1]=(a+o)/e,t[2]=(r+l)/e}else if(n>c){const e=2*Math.sqrt(1+n-i-c);t[3]=(r-l)/e,t[0]=(a+o)/e,t[1]=.25*e,t[2]=(A+h)/e}else{const e=2*Math.sqrt(1+c-i-n);t[3]=(o-a)/e,t[0]=(r+l)/e,t[1]=(A+h)/e,t[2]=.25*e}return t},quatFromEuler:(e=[0,0,0],t=!0)=>{const s=Math.cos,i=Math.sin,a=t?Yt:1,r=e[0]*a*.5,o=e[1]*a*.5,n=e[2]*a*.5,A=s(r),l=s(o),h=s(n),c=i(r),d=i(o),u=i(n);return[c*l*h+A*d*u,A*d*h-c*l*u,A*l*u+c*d*h,A*l*h-c*d*u]},quatFromAxis:(e=[0,0,0],t,s=!0)=>{const i=.5*t*(s?Yt:1),a=Math.sin(i);return[e[0]*a,e[1]*a,e[2]*a,Math.cos(i)]},quatNomalize:e=>{let t=es.lengthArray(e);return 0===t?[0,0,0,1]:(t=1/t,es.scaleArray(e,t,4))},quatInvert:e=>[-e[0],-e[1],-e[2],e[3]],quatMultiply:(e,t)=>{const s=e[0],i=e[1],a=e[2],r=e[3],o=t[0],n=t[1],A=t[2],l=t[3];return[s*l+r*o+i*A-a*n,i*l+r*n+a*o-s*A,a*l+r*A+s*n-i*o,r*l-s*o-i*n-a*A]},quatToAxis:e=>{let t=2*Math.acos(e[3]);const s=Math.sqrt(1-e[3]*e[3]);return s<1e-4?[1,0,0]:[e[0]/s,e[1]/s,e[2]/s,t]},eulerFromMatrix:e=>{const t=e[0],s=e[4],i=e[8];e[1];const a=e[5],r=e[9];e[2];const o=e[6],n=e[10];let A=[0,0,0];return A[1]=Math.asin(es.clamp(i,-1,1)),Math.abs(i)<.9999999?(A[0]=Math.atan2(-r,n),A[2]=Math.atan2(-s,t)):(A[0]=Math.atan2(o,a),A[2]=0),A},angleTo:(e,t)=>2*Math.acos(Math.abs(es.clamp(es.dotArray(e,t),-1,1))),getSize:e=>.001*e.byteLength+"kb",perpendicularArray:e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);let s=Math.acos(e[1]/t);const i=Math.atan2(e[2],e[0]);s>$t?s-=$t:s+=$t;return[t*Math.sin(s)*Math.cos(i),t*Math.cos(s),t*Math.sin(s)*Math.sin(i)]},crossArray:(e,t)=>{const s=e[0],i=e[1],a=e[2],r=t[0],o=t[1],n=t[2];return[i*n-a*o,a*r-s*n,s*o-i*r]},applyQuaternion:(e,t)=>{const s=e[0],i=e[1],a=e[2],r=t[0],o=t[1],n=t[2],A=t[3],l=2*(o*a-n*i),h=2*(n*s-r*a),c=2*(r*i-o*s);return[s+A*l+o*c-n*h,i+A*h+n*l-r*c,a+A*c+r*h-o*l]},nullArray:(e,t,s)=>{let i=0;for(;s--;)i+=e[t+s];return i},equalArray:(e,t)=>{let s=e.length;for(;s--;)if(e[s]!==t[s])return!1;return!0},lerpArray:(e,t,s)=>{if(0===s)return e;if(1===s)return t;let i=e.length,a=[];for(;i--;)a[i]=e[i],a[i]+=(t[i]-a[i])*s;return a},zeroArray:(e,t=0,s)=>{for(s=s??e.length;s--;)e[t+s]=0;return e},lengthArray:e=>{let t=e.length,s=0;for(;t--;)s+=e[t]*e[t];return Math.sqrt(s)},dotArray:(e,t)=>{let s=e.length,i=0;for(;s--;)i+=e[s]*t[s];return i},addArray:(e,t,s)=>{s=s??e.length;let i=[];for(;s--;)i[s]=e[s]+t[s];return i},subArray:(e,t,s)=>{s=s??e.length;let i=[];for(;s--;)i[s]=e[s]-t[s];return i},mulArray:(e,t,s)=>{if(t instanceof Array){let i=[];for(s=s??e.length;s--;)i[s]=e[s]*t[s];return i}return e.map((e=>e*t))},divArray:(e,t,s)=>es.mulArray(e,1/t,s),scaleArray:(e,t,s)=>es.mulArray(e,t,s),fillArray:(e,t,s=0,i)=>{for(i=i??e.length;i--;)t[s+i]=e[i]},copyArray:(e,t)=>{},cloneArray:e=>[...e],distanceArray:(e,t=[0,0,0])=>es.lengthArray(es.subArray(e,t)),normalizeArray:e=>es.divArray(e,es.lengthArray(e)||1),normalArray:(e,t=[0,0,0])=>es.normalizeArray(es.subArray(t,e)),getVolume:(e,t,s=null)=>{let i=1,a=t;switch(e){case"sphere":i=4*Math.PI*a[0]*a[0]*a[0]/3;break;case"cone":i=Math.PI*a[0]*(.5*a[1])*2;break;case"box":i=.5*a[0]*8*(.5*a[1])*(.5*a[2]);break;case"cylinder":i=Math.PI*a[0]*a[0]*(.5*a[1])*2;break;case"capsule":i=4*Math.PI*a[0]*a[0]*a[0]/3+Math.PI*a[0]*a[0]*(.5*a[1])*2;break;case"convex":case"mesh":i=es.getConvexVolume(s)}return i},getConvexVolume:e=>{let t,s=e.length/3,i=[0,0,0],a=[0,0,0];for(;s--;)t=3*s,e[t]<i[0]?i[0]=e[t]:e[t]>a[0]&&(a[0]=e[t]),e[t+1]<i[1]?i[1]=e[t+1]:e[t+1]>a[1]&&(a[1]=e[t+1]),e[t+2]<i[2]?i[2]=e[t+2]:e[t+2]>a[2]&&(a[2]=e[t+2]);let r=[a[0]-i[0],a[1]-i[1],a[2]-i[2]];return.5*r[0]*8*(.5*r[1])*(.5*r[2])},massFromDensity:(e,t)=>e*t,densityFromMass:(e,t)=>e/t,toNonIndexed:e=>e.index?e.clone().toNonIndexed():e,getIndex:(e,t)=>!e.index||t?null:e.index.array||null,getVertex:(e,t)=>{let s=e.attributes.position.array;return t&&e.index&&(s=(e=e.clone().toNonIndexed()).attributes.position.array),s},getNormal:e=>e.attributes.normal.array,getFaces:e=>{let t=[];if(e.index){let s=e.getIndex();for(let e=0;e<s.count;e+=3)t.push([s.getX(e),s.getX(e+1),s.getX(e+2)])}else{let s=e.getAttribute("position").count;for(let e=0;e<s;e+=3)t.push([e,e+1,e+2])}return t},reduce:e=>{},barycentric:(e,t)=>{},solve:(e,t)=>{}},ts=es;function ss(t,s=!1){const i=null!==t[0].index,a=new Set(Object.keys(t[0].attributes)),r=new Set(Object.keys(t[0].morphAttributes)),o={},n={},A=t[0].morphTargetsRelative,l=new e;let h=0;for(let e=0;e<t.length;++e){const c=t[e];let d=0;if(i!==(null!==c.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const t in c.attributes){if(!a.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+'. All geometries must have compatible attributes; make sure "'+t+'" attribute exists among all geometries, or in none of them.'),null;void 0===o[t]&&(o[t]=[]),o[t].push(c.attributes[t]),d++}if(d!==a.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+". Make sure all geometries have the same number of attributes."),null;if(A!==c.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const t in c.morphAttributes){if(!r.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+". .morphAttributes must be consistent throughout all geometries."),null;void 0===n[t]&&(n[t]=[]),n[t].push(c.morphAttributes[t])}if(s){let t;if(i)t=c.index.count;else{if(void 0===c.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+e+". The geometry must have either an index or a position attribute"),null;t=c.attributes.position.count}l.addGroup(h,t,e),h+=t}}if(i){let e=0;const s=[];for(let i=0;i<t.length;++i){const a=t[i].index;for(let t=0;t<a.count;++t)s.push(a.getX(t)+e);e+=t[i].attributes.position.count}l.setIndex(s)}for(const e in o){const t=is(o[e]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" attribute."),null;l.setAttribute(e,t)}for(const e in n){const t=n[e][0].length;if(0===t)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[e]=[];for(let s=0;s<t;++s){const t=[];for(let i=0;i<n[e].length;++i)t.push(n[e][i][s]);const i=is(t);if(!i)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" morphAttribute."),null;l.morphAttributes[e].push(i)}}return l}function is(e){let s,i,a,r=-1,o=0;for(let t=0;t<e.length;++t){const n=e[t];if(void 0===s&&(s=n.array.constructor),s!==n.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(void 0===i&&(i=n.itemSize),i!==n.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(void 0===a&&(a=n.normalized),a!==n.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(-1===r&&(r=n.gpuType),r!==n.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;o+=n.count*i}const n=new s(o),A=new t(n,i,a);let l=0;for(let t=0;t<e.length;++t){const s=e[t];if(s.isInterleavedBufferAttribute){const e=l/i;for(let t=0,a=s.count;t<a;t++)for(let a=0;a<i;a++){const i=s.getComponent(t,a);A.setComponent(t+e,a,i)}}else n.set(s.array,l);l+=s.count*i}return void 0!==r&&(A.gpuType=r),A}function as(e,s=1e-4){s=Math.max(s,Number.EPSILON);const i={},a=e.getIndex(),r=e.getAttribute("position"),o=a?a.count:r.count;let n=0;const A=Object.keys(e.attributes),l={},h={},c=[],d=["getX","getY","getZ","getW"],u=["setX","setY","setZ","setW"];for(let s=0,i=A.length;s<i;s++){const i=A[s],a=e.attributes[i];l[i]=new t(new a.array.constructor(a.count*a.itemSize),a.itemSize,a.normalized);const r=e.morphAttributes[i];r&&(h[i]=new t(new r.array.constructor(r.count*r.itemSize),r.itemSize,r.normalized))}const p=.5*s,g=Math.log10(1/s),m=Math.pow(10,g),f=p*m;for(let t=0;t<o;t++){const s=a?a.getX(t):t;let r="";for(let t=0,i=A.length;t<i;t++){const i=A[t],a=e.getAttribute(i),o=a.itemSize;for(let e=0;e<o;e++)r+=~~(a[d[e]](s)*m+f)+","}if(r in i)c.push(i[r]);else{for(let t=0,i=A.length;t<i;t++){const i=A[t],a=e.getAttribute(i),r=e.morphAttributes[i],o=a.itemSize,c=l[i],p=h[i];for(let e=0;e<o;e++){const t=d[e],i=u[e];if(c[i](n,a[t](s)),r)for(let e=0,a=r.length;e<a;e++)p[e][i](n,r[e][t](s))}}i[r]=n,c.push(n),n++}}const b=e.clone();for(const s in e.attributes){const e=l[s];if(b.setAttribute(s,new t(e.array.slice(0,n*e.itemSize),e.itemSize,e.normalized)),s in h)for(let e=0;e<h[s].length;e++){const i=h[s][e];b.morphAttributes[s][e]=new t(i.array.slice(0,n*i.itemSize),i.itemSize,i.normalized)}}return b.setIndex(c),b}function rs(e,t){if(t===s)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===i||t===a){let s=e.getIndex();if(null===s){const t=[],i=e.getAttribute("position");if(void 0===i)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<i.count;e++)t.push(e);e.setIndex(t),s=e.getIndex()}const a=s.count-2,r=[];if(t===i)for(let e=1;e<=a;e++)r.push(s.getX(0)),r.push(s.getX(e)),r.push(s.getX(e+1));else for(let e=0;e<a;e++)e%2==0?(r.push(s.getX(e)),r.push(s.getX(e+1)),r.push(s.getX(e+2))):(r.push(s.getX(e+2)),r.push(s.getX(e+1)),r.push(s.getX(e)));r.length/3!==a&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=e.clone();return o.setIndex(r),o.clearGroups(),o}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}class os extends n{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new ds(e)})),this.register((function(e){return new us(e)})),this.register((function(e){return new Es(e)})),this.register((function(e){return new Bs(e)})),this.register((function(e){return new ws(e)})),this.register((function(e){return new gs(e)})),this.register((function(e){return new ms(e)})),this.register((function(e){return new fs(e)})),this.register((function(e){return new bs(e)})),this.register((function(e){return new cs(e)})),this.register((function(e){return new ys(e)})),this.register((function(e){return new ps(e)})),this.register((function(e){return new Cs(e)})),this.register((function(e){return new Is(e)})),this.register((function(e){return new ls(e)})),this.register((function(e){return new vs(e)})),this.register((function(e){return new xs(e)}))}load(e,t,s,i){const a=this;let r;if(""!==this.resourcePath)r=this.resourcePath;else if(""!==this.path){const t=A.extractUrlBase(e);r=A.resolveURL(t,this.path)}else r=A.extractUrlBase(e);this.manager.itemStart(e);const o=function(t){i?i(t):console.error(t),a.manager.itemError(e),a.manager.itemEnd(e)},n=new l(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(function(s){try{a.parse(s,r,(function(s){t(s),a.manager.itemEnd(e)}),o)}catch(e){o(e)}}),s,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,i){let a;const r={},o={},n=new TextDecoder;if("string"==typeof e)a=JSON.parse(e);else if(e instanceof ArrayBuffer){if(n.decode(new Uint8Array(e,0,4))===Qs){try{r[As.KHR_BINARY_GLTF]=new Ss(e)}catch(e){return void(i&&i(e))}a=JSON.parse(r[As.KHR_BINARY_GLTF].content)}else a=JSON.parse(n.decode(e))}else a=e;if(void 0===a.asset||a.asset.version[0]<2)return void(i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const A=new ti(a,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});A.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](A);t.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),o[t.name]=t,r[t.name]=!0}if(a.extensionsUsed)for(let e=0;e<a.extensionsUsed.length;++e){const t=a.extensionsUsed[e],s=a.extensionsRequired||[];switch(t){case As.KHR_MATERIALS_UNLIT:r[t]=new hs;break;case As.KHR_DRACO_MESH_COMPRESSION:r[t]=new Rs(a,this.dracoLoader);break;case As.KHR_TEXTURE_TRANSFORM:r[t]=new Ds;break;case As.KHR_MESH_QUANTIZATION:r[t]=new Ts;break;default:s.indexOf(t)>=0&&void 0===o[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}A.setExtensions(r),A.setPlugins(o),A.parse(s,i)}parseAsync(e,t){const s=this;return new Promise((function(i,a){s.parse(e,t,i,a)}))}}function ns(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const As={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class ls{constructor(e){this.parser=e,this.name=As.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,i=t.length;s<i;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&void 0!==i.extensions[this.name].light&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let i=t.cache.get(s);if(i)return i;const a=t.json,r=((a.extensions&&a.extensions[this.name]||{}).lights||[])[e];let o;const n=new d(16777215);void 0!==r.color&&n.setRGB(r.color[0],r.color[1],r.color[2],u);const A=void 0!==r.range?r.range:0;switch(r.type){case"directional":o=new b(n),o.target.position.set(0,0,-1),o.add(o.target);break;case"point":o=new f(n),o.distance=A;break;case"spot":o=new g(n),o.distance=A,r.spot=r.spot||{},r.spot.innerConeAngle=void 0!==r.spot.innerConeAngle?r.spot.innerConeAngle:0,r.spot.outerConeAngle=void 0!==r.spot.outerConeAngle?r.spot.outerConeAngle:Math.PI/4,o.angle=r.spot.outerConeAngle,o.penumbra=1-r.spot.innerConeAngle/r.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+r.type)}return o.position.set(0,0,0),Ks(o,r),void 0!==r.intensity&&(o.intensity=r.intensity),o.name=t.createUniqueName(r.name||"light_"+e),i=Promise.resolve(o),t.cache.add(s,i),i}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],a=(i.extensions&&i.extensions[this.name]||{}).light;return void 0===a?null:this._loadLight(a).then((function(e){return s._getNodeRef(t.cache,a,e)}))}}class hs{constructor(){this.name=As.KHR_MATERIALS_UNLIT}getMaterialType(){return O}extendParams(e,t,s){const i=[];e.color=new d(1,1,1),e.opacity=1;const a=t.pbrMetallicRoughness;if(a){if(Array.isArray(a.baseColorFactor)){const t=a.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],u),e.opacity=t[3]}void 0!==a.baseColorTexture&&i.push(s.assignTexture(e,"map",a.baseColorTexture,p))}return Promise.all(i)}}class cs{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const i=s.extensions[this.name].emissiveStrength;return void 0!==i&&(t.emissiveIntensity=i),Promise.resolve()}}class ds{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];if(void 0!==r.clearcoatFactor&&(t.clearcoat=r.clearcoatFactor),void 0!==r.clearcoatTexture&&a.push(s.assignTexture(t,"clearcoatMap",r.clearcoatTexture)),void 0!==r.clearcoatRoughnessFactor&&(t.clearcoatRoughness=r.clearcoatRoughnessFactor),void 0!==r.clearcoatRoughnessTexture&&a.push(s.assignTexture(t,"clearcoatRoughnessMap",r.clearcoatRoughnessTexture)),void 0!==r.clearcoatNormalTexture&&(a.push(s.assignTexture(t,"clearcoatNormalMap",r.clearcoatNormalTexture)),void 0!==r.clearcoatNormalTexture.scale)){const e=r.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new c(e,e)}return Promise.all(a)}}class us{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_DISPERSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const i=s.extensions[this.name];return t.dispersion=void 0!==i.dispersion?i.dispersion:0,Promise.resolve()}}class ps{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];return void 0!==r.iridescenceFactor&&(t.iridescence=r.iridescenceFactor),void 0!==r.iridescenceTexture&&a.push(s.assignTexture(t,"iridescenceMap",r.iridescenceTexture)),void 0!==r.iridescenceIor&&(t.iridescenceIOR=r.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==r.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=r.iridescenceThicknessMinimum),void 0!==r.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=r.iridescenceThicknessMaximum),void 0!==r.iridescenceThicknessTexture&&a.push(s.assignTexture(t,"iridescenceThicknessMap",r.iridescenceThicknessTexture)),Promise.all(a)}}class gs{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_SHEEN}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[];t.sheenColor=new d(0,0,0),t.sheenRoughness=0,t.sheen=1;const r=i.extensions[this.name];if(void 0!==r.sheenColorFactor){const e=r.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],u)}return void 0!==r.sheenRoughnessFactor&&(t.sheenRoughness=r.sheenRoughnessFactor),void 0!==r.sheenColorTexture&&a.push(s.assignTexture(t,"sheenColorMap",r.sheenColorTexture,p)),void 0!==r.sheenRoughnessTexture&&a.push(s.assignTexture(t,"sheenRoughnessMap",r.sheenRoughnessTexture)),Promise.all(a)}}class ms{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];return void 0!==r.transmissionFactor&&(t.transmission=r.transmissionFactor),void 0!==r.transmissionTexture&&a.push(s.assignTexture(t,"transmissionMap",r.transmissionTexture)),Promise.all(a)}}class fs{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_VOLUME}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];t.thickness=void 0!==r.thicknessFactor?r.thicknessFactor:0,void 0!==r.thicknessTexture&&a.push(s.assignTexture(t,"thicknessMap",r.thicknessTexture)),t.attenuationDistance=r.attenuationDistance||1/0;const o=r.attenuationColor||[1,1,1];return t.attenuationColor=(new d).setRGB(o[0],o[1],o[2],u),Promise.all(a)}}class bs{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_IOR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const i=s.extensions[this.name];return t.ior=void 0!==i.ior?i.ior:1.5,Promise.resolve()}}class ys{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_SPECULAR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];t.specularIntensity=void 0!==r.specularFactor?r.specularFactor:1,void 0!==r.specularTexture&&a.push(s.assignTexture(t,"specularIntensityMap",r.specularTexture));const o=r.specularColorFactor||[1,1,1];return t.specularColor=(new d).setRGB(o[0],o[1],o[2],u),void 0!==r.specularColorTexture&&a.push(s.assignTexture(t,"specularColorMap",r.specularColorTexture,p)),Promise.all(a)}}class Is{constructor(e){this.parser=e,this.name=As.EXT_MATERIALS_BUMP}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];return t.bumpScale=void 0!==r.bumpFactor?r.bumpFactor:1,void 0!==r.bumpTexture&&a.push(s.assignTexture(t,"bumpMap",r.bumpTexture)),Promise.all(a)}}class Cs{constructor(e){this.parser=e,this.name=As.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?h:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const a=[],r=i.extensions[this.name];return void 0!==r.anisotropyStrength&&(t.anisotropy=r.anisotropyStrength),void 0!==r.anisotropyRotation&&(t.anisotropyRotation=r.anisotropyRotation),void 0!==r.anisotropyTexture&&a.push(s.assignTexture(t,"anisotropyMap",r.anisotropyTexture)),Promise.all(a)}}class Es{constructor(e){this.parser=e,this.name=As.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,i=s.textures[e];if(!i.extensions||!i.extensions[this.name])return null;const a=i.extensions[this.name],r=t.options.ktx2Loader;if(!r){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,a.source,r)}}class Bs{constructor(e){this.parser=e,this.name=As.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,i=s.json,a=i.textures[e];if(!a.extensions||!a.extensions[t])return null;const r=a.extensions[t],o=i.images[r.source];let n=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(n=e)}return this.detectSupport().then((function(a){if(a)return s.loadTextureImage(e,r.source,n);if(i.extensionsRequired&&i.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class ws{constructor(e){this.parser=e,this.name=As.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,i=s.json,a=i.textures[e];if(!a.extensions||!a.extensions[t])return null;const r=a.extensions[t],o=i.images[r.source];let n=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(n=e)}return this.detectSupport().then((function(a){if(a)return s.loadTextureImage(e,r.source,n);if(i.extensionsRequired&&i.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class vs{constructor(e){this.name=As.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],i=this.parser.getDependency("buffer",e.buffer),a=this.parser.options.meshoptDecoder;if(!a||!a.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then((function(t){const s=e.byteOffset||0,i=e.byteLength||0,r=e.count,o=e.byteStride,n=new Uint8Array(t,s,i);return a.decodeGltfBufferAsync?a.decodeGltfBufferAsync(r,o,n,e.mode,e.filter).then((function(e){return e.buffer})):a.ready.then((function(){const t=new ArrayBuffer(r*o);return a.decodeGltfBuffer(new Uint8Array(t),r,o,n,e.mode,e.filter),t}))}))}return null}}class xs{constructor(e){this.name=As.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||void 0===s.mesh)return null;const i=t.meshes[s.mesh];for(const e of i.primitives)if(e.mode!==_s.TRIANGLES&&e.mode!==_s.TRIANGLE_STRIP&&e.mode!==_s.TRIANGLE_FAN&&void 0!==e.mode)return null;const a=s.extensions[this.name].attributes,n=[],A={};for(const e in a)n.push(this.parser.getDependency("accessor",a[e]).then((t=>(A[e]=t,A[e]))));return n.length<1?null:(n.push(this.parser.createNodeMesh(e)),Promise.all(n).then((e=>{const t=e.pop(),s=t.isGroup?t.children:[t],i=e[0].count,a=[];for(const e of s){const t=new o,s=new y,n=new r,l=new y(1,1,1),h=new I(e.geometry,e.material,i);for(let e=0;e<i;e++)A.TRANSLATION&&s.fromBufferAttribute(A.TRANSLATION,e),A.ROTATION&&n.fromBufferAttribute(A.ROTATION,e),A.SCALE&&l.fromBufferAttribute(A.SCALE,e),h.setMatrixAt(e,t.compose(s,n,l));for(const t in A)if("_COLOR_0"===t){const e=A[t];h.instanceColor=new C(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,A[t]);E.prototype.copy.call(h,e),this.parser.assignFinalMaterial(h),a.push(h)}return t.isGroup?(t.clear(),t.add(...a),t):a[0]})))}}const Qs="glTF",ks=1313821514,Ms=5130562;class Ss{constructor(e){this.name=As.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Qs)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const i=this.header.length-12,a=new DataView(e,12);let r=0;for(;r<i;){const t=a.getUint32(r,!0);r+=4;const i=a.getUint32(r,!0);if(r+=4,i===ks){const i=new Uint8Array(e,12+r,t);this.content=s.decode(i)}else if(i===Ms){const s=12+r;this.body=e.slice(s,s+t)}r+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Rs{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=As.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,i=this.dracoLoader,a=e.extensions[this.name].bufferView,r=e.extensions[this.name].attributes,o={},n={},A={};for(const e in r){const t=zs[e]||e.toLowerCase();o[t]=r[e]}for(const t in e.attributes){const i=zs[t]||t.toLowerCase();if(void 0!==r[t]){const a=s.accessors[e.attributes[t]],r=Gs[a.componentType];A[i]=r.name,n[i]=!0===a.normalized}}return t.getDependency("bufferView",a).then((function(e){return new Promise((function(t,s){i.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],i=n[t];void 0!==i&&(s.normalized=i)}t(e)}),o,A,u,s)}))}))}}class Ds{constructor(){this.name=As.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&t.texCoord!==e.channel||void 0!==t.offset||void 0!==t.rotation||void 0!==t.scale?(e=e.clone(),void 0!==t.texCoord&&(e.channel=t.texCoord),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e):e}}class Ts{constructor(){this.name=As.KHR_MESH_QUANTIZATION}}class Fs extends he{constructor(e,t,s,i){super(e,t,s,i)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,i=this.valueSize,a=e*i*3+i;for(let e=0;e!==i;e++)t[e]=s[a+e];return t}interpolate_(e,t,s,i){const a=this.resultBuffer,r=this.sampleValues,o=this.valueSize,n=2*o,A=3*o,l=i-t,h=(s-t)/l,c=h*h,d=c*h,u=e*A,p=u-A,g=-2*d+3*c,m=d-c,f=1-g,b=m-c+h;for(let e=0;e!==o;e++){const t=r[p+e+o],s=r[p+e+n]*l,i=r[u+e+o],A=r[u+e]*l;a[e]=f*t+b*s+g*i+m*A}return a}}const Ls=new r;class Ps extends Fs{interpolate_(e,t,s,i){const a=super.interpolate_(e,t,s,i);return Ls.fromArray(a).normalize().toArray(a),a}}const _s={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Gs={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ns={9728:D,9729:R,9984:S,9985:M,9986:k,9987:Q},Us={33071:L,33648:F,10497:T},Os={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},zs={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Hs={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},qs={CUBICSPLINE:void 0,LINEAR:ie,STEP:se},js="OPAQUE",Vs="MASK",Ws="BLEND";function Js(e,t,s){for(const i in s.extensions)void 0===e[i]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[i]=s.extensions[i])}function Ks(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function Ys(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,i=t.weights.length;s<i;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,i=s.length;t<i;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Xs(e){let t;const s=e.extensions&&e.extensions[As.KHR_DRACO_MESH_COMPRESSION];if(t=s?"draco:"+s.bufferView+":"+s.indices+":"+Zs(s.attributes):e.indices+":"+Zs(e.attributes)+":"+e.mode,void 0!==e.targets)for(let s=0,i=e.targets.length;s<i;s++)t+=":"+Zs(e.targets[s]);return t}function Zs(e){let t="";const s=Object.keys(e).sort();for(let i=0,a=s.length;i<a;i++)t+=s[i]+":"+e[s[i]]+";";return t}function $s(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}const ei=new o;class ti{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new ns,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,i=-1,a=!1,r=-1;if("undefined"!=typeof navigator){const e=navigator.userAgent;s=!0===/^((?!chrome|android).)*safari/i.test(e);const t=e.match(/Version\/(\d+)/);i=s&&t?parseInt(t[1],10):-1,a=e.indexOf("Firefox")>-1,r=a?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||s&&i<17||a&&r<98?this.textureLoader=new B(this.options.manager):this.textureLoader=new w(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new l(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,i=this.json,a=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const r={scene:t[0][i.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:i.asset,parser:s,userData:{}};return Js(a,r,i),Ks(r,i),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(r)}))).then((function(){for(const e of r.scenes)e.updateMatrixWorld();e(r)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,i=t.length;s<i;s++){const i=t[s].joints;for(let t=0,s=i.length;t<s;t++)e[i[t]].isBone=!0}for(let t=0,i=e.length;t<i;t++){const i=e[t];void 0!==i.mesh&&(this._addNodeRef(this.meshCache,i.mesh),void 0!==i.skin&&(s[i.mesh].isSkinnedMesh=!0)),void 0!==i.camera&&this._addNodeRef(this.cameraCache,i.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const i=s.clone(),a=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,i]of e.children.entries())a(i,t.children[s])};return a(s,i),i.name+="_instance_"+e.uses[t]++,i}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const i=e(t[s]);if(i)return i}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let i=0;i<t.length;i++){const a=e(t[i]);a&&s.push(a)}return s}getDependency(e,t){const s=e+":"+t;let i=this.cache.get(s);if(!i){switch(e){case"scene":i=this.loadScene(t);break;case"node":i=this._invokeOne((function(e){return e.loadNode&&e.loadNode(t)}));break;case"mesh":i=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":i=this.loadAccessor(t);break;case"bufferView":i=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":i=this.loadBuffer(t);break;case"material":i=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":i=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":i=this.loadSkin(t);break;case"animation":i=this._invokeOne((function(e){return e.loadAnimation&&e.loadAnimation(t)}));break;case"camera":i=this.loadCamera(t);break;default:if(i=this._invokeOne((function(s){return s!=this&&s.getDependency&&s.getDependency(e,t)})),!i)throw new Error("Unknown type: "+e)}this.cache.add(s,i)}return i}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,i=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(i.map((function(t,i){return s.getDependency(e,i)}))),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&"arraybuffer"!==t.type)throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(void 0===t.uri&&0===e)return Promise.resolve(this.extensions[As.KHR_BINARY_GLTF].body);const i=this.options;return new Promise((function(e,a){s.load(A.resolveURL(t.uri,i.path),e,void 0,(function(){a(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,i=t.byteOffset||0;return e.slice(i,i+s)}))}loadAccessor(e){const s=this,i=this.json,a=this.json.accessors[e];if(void 0===a.bufferView&&void 0===a.sparse){const e=Os[a.type],s=Gs[a.componentType],i=!0===a.normalized,r=new s(a.count*e);return Promise.resolve(new t(r,e,i))}const r=[];return void 0!==a.bufferView?r.push(this.getDependency("bufferView",a.bufferView)):r.push(null),void 0!==a.sparse&&(r.push(this.getDependency("bufferView",a.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",a.sparse.values.bufferView))),Promise.all(r).then((function(e){const r=e[0],o=Os[a.type],n=Gs[a.componentType],A=n.BYTES_PER_ELEMENT,l=A*o,h=a.byteOffset||0,c=void 0!==a.bufferView?i.bufferViews[a.bufferView].byteStride:void 0,d=!0===a.normalized;let u,p;if(c&&c!==l){const e=Math.floor(h/c),t="InterleavedBuffer:"+a.bufferView+":"+a.componentType+":"+e+":"+a.count;let i=s.cache.get(t);i||(u=new n(r,e*c,a.count*c/A),i=new v(u,c/A),s.cache.add(t,i)),p=new x(i,o,h%c/A,d)}else u=null===r?new n(a.count*o):new n(r,h,a.count*o),p=new t(u,o,d);if(void 0!==a.sparse){const s=Os.SCALAR,i=Gs[a.sparse.indices.componentType],A=a.sparse.indices.byteOffset||0,l=a.sparse.values.byteOffset||0,h=new i(e[1],A,a.sparse.count*s),c=new n(e[2],l,a.sparse.count*o);null!==r&&(p=new t(p.array.slice(),p.itemSize,p.normalized)),p.normalized=!1;for(let e=0,t=h.length;e<t;e++){const t=h[e];if(p.setX(t,c[e*o]),o>=2&&p.setY(t,c[e*o+1]),o>=3&&p.setZ(t,c[e*o+2]),o>=4&&p.setW(t,c[e*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}p.normalized=d}return p}))}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,a=t.images[i];let r=this.textureLoader;if(a.uri){const e=s.manager.getHandler(a.uri);null!==e&&(r=e)}return this.loadTextureImage(e,i,r)}loadTextureImage(e,t,s){const i=this,a=this.json,r=a.textures[e],o=a.images[t],n=(o.uri||o.bufferView)+":"+r.sampler;if(this.textureCache[n])return this.textureCache[n];const A=this.loadImageSource(t,s).then((function(t){t.flipY=!1,t.name=r.name||o.name||"",""===t.name&&"string"==typeof o.uri&&!1===o.uri.startsWith("data:image/")&&(t.name=o.uri);const s=(a.samplers||{})[r.sampler]||{};return t.magFilter=Ns[s.magFilter]||R,t.minFilter=Ns[s.minFilter]||Q,t.wrapS=Us[s.wrapS]||T,t.wrapT=Us[s.wrapT]||T,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==D&&t.minFilter!==R,i.associations.set(t,{textures:e}),t})).catch((function(){return null}));return this.textureCache[n]=A,A}loadImageSource(e,t){const s=this,i=this.json,a=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then((e=>e.clone()));const r=i.images[e],o=self.URL||self.webkitURL;let n=r.uri||"",l=!1;if(void 0!==r.bufferView)n=s.getDependency("bufferView",r.bufferView).then((function(e){l=!0;const t=new Blob([e],{type:r.mimeType});return n=o.createObjectURL(t),n}));else if(void 0===r.uri)throw new Error("THREE.GLTFLoader: Image "+e