UNPKG

phy-engine

Version:

JavaScript 3D Physics for three.js

1 lines 513 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PHY={},e.THREE)}(this,(function(e,t){"use strict";var s="undefined"!=typeof document?document.currentScript:null;const i=Math.PI,a=i/180,r=180/i,o=Number.EPSILON,n=.5*i,A={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:r,torad:a,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)=>A.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?r: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=A.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=A.composeMatrixArray(e,t),o=A.composeMatrixArray(s,i);return a&&(r=A.invertMatrixArray(r)),r=A.multiplyMatrixArray(r,o),[r[12],r[13],r[14]]},fromTransformToQ:(e,t,s=!1)=>{let i=A.composeMatrixArray(e,t),a=A.decomposeFullMatrixArray(i).q;return s&&(a=A.quatInvert(a)),a},lerpTransform:(e,t,s)=>{let i=e[0],a=e[1],r=t[0],o=t[1];return r=A.lerpArray(i,r,s),o=A.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],B=i[4],E=i[8],w=i[12],x=i[1],v=i[5],Q=i[9],M=i[13],S=i[2],k=i[6],R=i[10],D=i[14],F=i[3],T=i[7],L=i[11],P=i[15];return a[0]=r*C+o*x+n*S+A*F,a[4]=r*B+o*v+n*k+A*T,a[8]=r*E+o*Q+n*R+A*L,a[12]=r*w+o*M+n*D+A*P,a[1]=l*C+h*x+c*S+d*F,a[5]=l*B+h*v+c*k+d*T,a[9]=l*E+h*Q+c*R+d*L,a[13]=l*w+h*M+c*D+d*P,a[2]=u*C+p*x+g*S+m*F,a[6]=u*B+p*v+g*k+m*T,a[10]=u*E+p*Q+g*R+m*L,a[14]=u*w+p*M+g*D+m*P,a[3]=f*C+b*x+y*S+I*F,a[7]=f*B+b*v+y*k+I*T,a[11]=f*E+b*Q+y*R+I*L,a[15]=f*w+b*M+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,B=s*b+i*y+a*I+r*C;if(0===B)return[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];const E=1/B;return t[0]=b*E,t[1]=(g*d*r-c*m*r-g*a*u+i*m*u+c*a*f-i*d*f)*E,t[2]=(n*m*r-g*A*r+g*a*l-i*m*l-n*a*f+i*A*f)*E,t[3]=(c*A*r-n*d*r-c*a*l+i*d*l+n*a*u-i*A*u)*E,t[4]=y*E,t[5]=(h*m*r-p*d*r+p*a*u-s*m*u-h*a*f+s*d*f)*E,t[6]=(p*A*r-o*m*r-p*a*l+s*m*l+o*a*f-s*A*f)*E,t[7]=(o*d*r-h*A*r+h*a*l-s*d*l-o*a*u+s*A*u)*E,t[8]=I*E,t[9]=(p*c*r-h*g*r-p*i*u+s*g*u+h*i*f-s*c*f)*E,t[10]=(o*g*r-p*n*r+p*i*l-s*g*l-o*i*f+s*n*f)*E,t[11]=(h*n*r-o*c*r-h*i*l+s*c*l+o*i*u-s*n*u)*E,t[12]=C*E,t[13]=(h*g*a-p*c*a+p*i*d-s*g*d-h*i*m+s*c*m)*E,t[14]=(p*n*a-o*g*a-p*i*A+s*g*A+o*i*m-s*n*m)*E,t[15]=(o*c*a-h*n*a+h*i*A-s*c*A-o*i*d+s*n*d)*E,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=A.lengthArray([t[0],t[1],t[2]]);const i=A.lengthArray([t[4],t[5],t[6]]),a=A.lengthArray([t[8],t[9],t[10]]);A.matrixArrayDeterminant(e)<0&&(s=-s);let r=[...e];const o=1/s,n=1/i,l=1/a;r[0]*=o,r[1]*=o,r[2]*=o,r[4]*=n,r[5]*=n,r[6]*=n,r[8]*=l,r[9]*=l,r[10]*=l;let h=A.quatFromRotationMatrix(r);return{p:[e[12],e[13],e[14]],q:h,s:[s,i,a]}},applyTransformArray:(e,t,s,i=[1,1,1])=>{const a=A.composeMatrixArray(t,s,i),r=e[0],o=e[1],n=e[2],l=1/(a[3]*r+a[7]*o+a[11]*n+a[15]);return[(a[0]*r+a[4]*o+a[8]*n+a[12])*l,(a[1]*r+a[5]*o+a[9]*n+a[13])*l,(a[2]*r+a[6]*o+a[10]*n+a[14])*l]},slerpQuatArray:(e,t,s)=>{if(0===s)return e;if(1===s)return t;let i=[...e];const a=e[0],r=e[1],n=e[2],l=e[3],h=t[0],c=t[1],d=t[2],u=t[3];let p=l*u+a*h+r*c+n*d;if(p<0?(i=[-h,-c,-d,-u],p=-p):i=[...t],p>=1)return e;const g=1-p*p;if(g<=o){const e=1-s;return i[3]=e*l+s*i[3],i[0]=e*a+s*i[0],i[1]=e*r+s*i[1],i[2]=e*n+s*i[2],A.quatNomalize(i)}const m=Math.sqrt(g),f=Math.atan2(m,p),b=Math.sin((1-s)*f)/m,y=Math.sin(s*f)/m;return i[3]=l*b+i[3]*y,i[0]=a*b+i[0]*y,i[1]=r*b+i[1]*y,i[2]=n*b+i[2]*y,i},toLocalQuatArray:(e=[0,0,0],t)=>{let s=A.quatFromEuler(e),i=A.quatInvert(t.quaternion.toArray());return A.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,r=t?a:1,o=e[0]*r*.5,n=e[1]*r*.5,A=e[2]*r*.5,l=s(o),h=s(n),c=s(A),d=i(o),u=i(n),p=i(A);return[d*h*c+l*u*p,l*u*c-d*h*p,l*h*p+d*u*c,l*h*c-d*u*p]},quatFromAxis:(e=[0,0,0],t,s=!0)=>{const i=.5*t*(s?a:1),r=Math.sin(i);return[e[0]*r,e[1]*r,e[2]*r,Math.cos(i)]},quatNomalize:e=>{let t=A.lengthArray(e);return 0===t?[0,0,0,1]:(t=1/t,A.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 l=[0,0,0];return l[1]=Math.asin(A.clamp(i,-1,1)),Math.abs(i)<.9999999?(l[0]=Math.atan2(-r,n),l[2]=Math.atan2(-s,t)):(l[0]=Math.atan2(o,a),l[2]=0),l},angleTo:(e,t)=>2*Math.acos(Math.abs(A.clamp(A.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>n?s-=n:s+=n;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)=>A.mulArray(e,1/t,s),scaleArray:(e,t,s)=>A.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])=>A.lengthArray(A.subArray(e,t)),normalizeArray:e=>A.divArray(e,A.lengthArray(e)||1),normalArray:(e,t=[0,0,0])=>A.normalizeArray(A.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=A.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)=>{}},l=A;function h(e,s=!1){const i=null!==e[0].index,a=new Set(Object.keys(e[0].attributes)),r=new Set(Object.keys(e[0].morphAttributes)),o={},n={},A=e[0].morphTargetsRelative,l=new t.BufferGeometry;let h=0;for(let t=0;t<e.length;++t){const c=e[t];let d=0;if(i!==(null!==c.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const e in c.attributes){if(!a.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+'. All geometries must have compatible attributes; make sure "'+e+'" attribute exists among all geometries, or in none of them.'),null;void 0===o[e]&&(o[e]=[]),o[e].push(c.attributes[e]),d++}if(d!==a.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". 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 "+t+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const e in c.morphAttributes){if(!r.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". .morphAttributes must be consistent throughout all geometries."),null;void 0===n[e]&&(n[e]=[]),n[e].push(c.morphAttributes[e])}if(s){let e;if(i)e=c.index.count;else{if(void 0===c.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". The geometry must have either an index or a position attribute"),null;e=c.attributes.position.count}l.addGroup(h,e,t),h+=e}}if(i){let t=0;const s=[];for(let i=0;i<e.length;++i){const a=e[i].index;for(let e=0;e<a.count;++e)s.push(a.getX(e)+t);t+=e[i].attributes.position.count}l.setIndex(s)}for(const e in o){const t=c(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=c(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 c(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.BufferAttribute(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 d(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.BufferAttribute(new a.array.constructor(a.count*a.itemSize),a.itemSize,a.normalized);const r=e.morphAttributes[i];r&&(h[i]=new t.BufferAttribute(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.BufferAttribute(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.BufferAttribute(i.array.slice(0,n*i.itemSize),i.itemSize,i.normalized)}}return b.setIndex(c),b}function u(e,s){if(s===t.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(s===t.TriangleFanDrawMode||s===t.TriangleStripDrawMode){let i=e.getIndex();if(null===i){const t=[],s=e.getAttribute("position");if(void 0===s)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<s.count;e++)t.push(e);e.setIndex(t),i=e.getIndex()}const a=i.count-2,r=[];if(s===t.TriangleFanDrawMode)for(let e=1;e<=a;e++)r.push(i.getX(0)),r.push(i.getX(e)),r.push(i.getX(e+1));else for(let e=0;e<a;e++)e%2==0?(r.push(i.getX(e)),r.push(i.getX(e+1)),r.push(i.getX(e+2))):(r.push(i.getX(e+2)),r.push(i.getX(e+1)),r.push(i.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:",s),e}class p extends t.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new C(e)})),this.register((function(e){return new B(e)})),this.register((function(e){return new R(e)})),this.register((function(e){return new D(e)})),this.register((function(e){return new F(e)})),this.register((function(e){return new w(e)})),this.register((function(e){return new x(e)})),this.register((function(e){return new v(e)})),this.register((function(e){return new Q(e)})),this.register((function(e){return new I(e)})),this.register((function(e){return new M(e)})),this.register((function(e){return new E(e)})),this.register((function(e){return new k(e)})),this.register((function(e){return new S(e)})),this.register((function(e){return new b(e)})),this.register((function(e){return new T(e)})),this.register((function(e){return new L(e)}))}load(e,s,i,a){const r=this;let o;if(""!==this.resourcePath)o=this.resourcePath;else if(""!==this.path){const s=t.LoaderUtils.extractUrlBase(e);o=t.LoaderUtils.resolveURL(s,this.path)}else o=t.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const n=function(t){a?a(t):console.error(t),r.manager.itemError(e),r.manager.itemEnd(e)},A=new t.FileLoader(this.manager);A.setPath(this.path),A.setResponseType("arraybuffer"),A.setRequestHeader(this.requestHeader),A.setWithCredentials(this.withCredentials),A.load(e,(function(t){try{r.parse(t,o,(function(t){s(t),r.manager.itemEnd(e)}),n)}catch(e){n(e)}}),i,n)}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))===P){try{r[f.KHR_BINARY_GLTF]=new U(e)}catch(e){return void(i&&i(e))}a=JSON.parse(r[f.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 he(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 f.KHR_MATERIALS_UNLIT:r[t]=new y;break;case f.KHR_DRACO_MESH_COMPRESSION:r[t]=new N(a,this.dracoLoader);break;case f.KHR_TEXTURE_TRANSFORM:r[t]=new O;break;case f.KHR_MESH_QUANTIZATION:r[t]=new z;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 g(){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 f={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 b{constructor(e){this.parser=e,this.name=f.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 s=this.parser,i="light:"+e;let a=s.cache.get(i);if(a)return a;const r=s.json,o=((r.extensions&&r.extensions[this.name]||{}).lights||[])[e];let n;const A=new t.Color(16777215);void 0!==o.color&&A.setRGB(o.color[0],o.color[1],o.color[2],t.LinearSRGBColorSpace);const l=void 0!==o.range?o.range:0;switch(o.type){case"directional":n=new t.DirectionalLight(A),n.target.position.set(0,0,-1),n.add(n.target);break;case"point":n=new t.PointLight(A),n.distance=l;break;case"spot":n=new t.SpotLight(A),n.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=void 0!==o.spot.innerConeAngle?o.spot.innerConeAngle:0,o.spot.outerConeAngle=void 0!==o.spot.outerConeAngle?o.spot.outerConeAngle:Math.PI/4,n.angle=o.spot.outerConeAngle,n.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,n.target.position.set(0,0,-1),n.add(n.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return n.position.set(0,0,0),ae(n,o),void 0!==o.intensity&&(n.intensity=o.intensity),n.name=s.createUniqueName(o.name||"light_"+e),a=Promise.resolve(n),s.cache.add(i,a),a}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 y{constructor(){this.name=f.KHR_MATERIALS_UNLIT}getMaterialType(){return t.MeshBasicMaterial}extendParams(e,s,i){const a=[];e.color=new t.Color(1,1,1),e.opacity=1;const r=s.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){const s=r.baseColorFactor;e.color.setRGB(s[0],s[1],s[2],t.LinearSRGBColorSpace),e.opacity=s[3]}void 0!==r.baseColorTexture&&a.push(i.assignTexture(e,"map",r.baseColorTexture,t.SRGBColorSpace))}return Promise.all(a)}}class I{constructor(e){this.parser=e,this.name=f.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 C{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const i=this.parser,a=i.json.materials[e];if(!a.extensions||!a.extensions[this.name])return Promise.resolve();const r=[],o=a.extensions[this.name];if(void 0!==o.clearcoatFactor&&(s.clearcoat=o.clearcoatFactor),void 0!==o.clearcoatTexture&&r.push(i.assignTexture(s,"clearcoatMap",o.clearcoatTexture)),void 0!==o.clearcoatRoughnessFactor&&(s.clearcoatRoughness=o.clearcoatRoughnessFactor),void 0!==o.clearcoatRoughnessTexture&&r.push(i.assignTexture(s,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),void 0!==o.clearcoatNormalTexture&&(r.push(i.assignTexture(s,"clearcoatNormalMap",o.clearcoatNormalTexture)),void 0!==o.clearcoatNormalTexture.scale)){const e=o.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new t.Vector2(e,e)}return Promise.all(r)}}class B{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 E{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 w{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const i=this.parser,a=i.json.materials[e];if(!a.extensions||!a.extensions[this.name])return Promise.resolve();const r=[];s.sheenColor=new t.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const o=a.extensions[this.name];if(void 0!==o.sheenColorFactor){const e=o.sheenColorFactor;s.sheenColor.setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace)}return void 0!==o.sheenRoughnessFactor&&(s.sheenRoughness=o.sheenRoughnessFactor),void 0!==o.sheenColorTexture&&r.push(i.assignTexture(s,"sheenColorMap",o.sheenColorTexture,t.SRGBColorSpace)),void 0!==o.sheenRoughnessTexture&&r.push(i.assignTexture(s,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(r)}}class x{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 v{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const i=this.parser,a=i.json.materials[e];if(!a.extensions||!a.extensions[this.name])return Promise.resolve();const r=[],o=a.extensions[this.name];s.thickness=void 0!==o.thicknessFactor?o.thicknessFactor:0,void 0!==o.thicknessTexture&&r.push(i.assignTexture(s,"thicknessMap",o.thicknessTexture)),s.attenuationDistance=o.attenuationDistance||1/0;const n=o.attenuationColor||[1,1,1];return s.attenuationColor=(new t.Color).setRGB(n[0],n[1],n[2],t.LinearSRGBColorSpace),Promise.all(r)}}class Q{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 M{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const i=this.parser,a=i.json.materials[e];if(!a.extensions||!a.extensions[this.name])return Promise.resolve();const r=[],o=a.extensions[this.name];s.specularIntensity=void 0!==o.specularFactor?o.specularFactor:1,void 0!==o.specularTexture&&r.push(i.assignTexture(s,"specularIntensityMap",o.specularTexture));const n=o.specularColorFactor||[1,1,1];return s.specularColor=(new t.Color).setRGB(n[0],n[1],n[2],t.LinearSRGBColorSpace),void 0!==o.specularColorTexture&&r.push(i.assignTexture(s,"specularColorMap",o.specularColorTexture,t.SRGBColorSpace)),Promise.all(r)}}class S{constructor(e){this.parser=e,this.name=f.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 k{constructor(e){this.parser=e,this.name=f.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial: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 R{constructor(e){this.parser=e,this.name=f.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 D{constructor(e){this.parser=e,this.name=f.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 F{constructor(e){this.parser=e,this.name=f.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 T{constructor(e){this.name=f.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 L{constructor(e){this.name=f.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const s=this.parser.json,i=s.nodes[e];if(!i.extensions||!i.extensions[this.name]||void 0===i.mesh)return null;const a=s.meshes[i.mesh];for(const e of a.primitives)if(e.mode!==j.TRIANGLES&&e.mode!==j.TRIANGLE_STRIP&&e.mode!==j.TRIANGLE_FAN&&void 0!==e.mode)return null;const r=i.extensions[this.name].attributes,o=[],n={};for(const e in r)o.push(this.parser.getDependency("accessor",r[e]).then((t=>(n[e]=t,n[e]))));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then((e=>{const s=e.pop(),i=s.isGroup?s.children:[s],a=e[0].count,r=[];for(const e of i){const s=new t.Matrix4,i=new t.Vector3,o=new t.Quaternion,A=new t.Vector3(1,1,1),l=new t.InstancedMesh(e.geometry,e.material,a);for(let e=0;e<a;e++)n.TRANSLATION&&i.fromBufferAttribute(n.TRANSLATION,e),n.ROTATION&&o.fromBufferAttribute(n.ROTATION,e),n.SCALE&&A.fromBufferAttribute(n.SCALE,e),l.setMatrixAt(e,s.compose(i,o,A));for(const s in n)if("_COLOR_0"===s){const e=n[s];l.instanceColor=new t.InstancedBufferAttribute(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==s&&"ROTATION"!==s&&"SCALE"!==s&&e.geometry.setAttribute(s,n[s]);t.Object3D.prototype.copy.call(l,e),this.parser.assignFinalMaterial(l),r.push(l)}return s.isGroup?(s.clear(),s.add(...r),s):r[0]})))}}const P="glTF",G=1313821514,_=5130562;class U{constructor(e){this.name=f.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!==P)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===G){const i=new Uint8Array(e,12+r,t);this.content=s.decode(i)}else if(i===_){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 N{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=f.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,s){const i=this.json,a=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,n={},A={},l={};for(const e in o){const t=X[e]||e.toLowerCase();n[t]=o[e]}for(const t in e.attributes){const s=X[t]||t.toLowerCase();if(void 0!==o[t]){const a=i.accessors[e.attributes[t]],r=W[a.componentType];l[s]=r.name,A[s]=!0===a.normalized}}return s.getDependency("bufferView",r).then((function(e){return new Promise((function(s,i){a.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],i=A[t];void 0!==i&&(s.normalized=i)}s(e)}),n,l,t.LinearSRGBColorSpace,i)}))}))}}class O{constructor(){this.name=f.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 z{constructor(){this.name=f.KHR_MESH_QUANTIZATION}}class V extends t.Interpolant{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 H=new t.Quaternion;class q extends V{interpolate_(e,t,s,i){const a=super.interpolate_(e,t,s,i);return H.fromArray(a).normalize().toArray(a),a}}const j={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},K={9728:t.NearestFilter,9729:t.LinearFilter,9984:t.NearestMipmapNearestFilter,9985:t.LinearMipmapNearestFilter,9986:t.NearestMipmapLinearFilter,9987:t.LinearMipmapLinearFilter},J={33071:t.ClampToEdgeWrapping,33648:t.MirroredRepeatWrapping,10497:t.RepeatWrapping},Y={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},X={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"},Z={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},$={CUBICSPLINE:void 0,LINEAR:t.InterpolateLinear,STEP:t.InterpolateDiscrete},ee="OPAQUE",te="MASK",se="BLEND";function ie(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 ae(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 re(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 oe(e){let t;const s=e.extensions&&e.extensions[f.KHR_DRACO_MESH_COMPRESSION];if(t=s?"draco:"+s.bufferView+":"+s.indices+":"+ne(s.attributes):e.indices+":"+ne(e.attributes)+":"+e.mode,void 0!==e.targets)for(let s=0,i=e.targets.length;s<i;s++)t+=":"+ne(e.targets[s]);return t}function ne(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 Ae(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 le=new t.Matrix4;class he{constructor(e={},s={}){this.json=e,this.extensions={},this.plugins={},this.options=s,this.cache=new g,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 i=!1,a=-1,r=!1,o=-1;if("undefined"!=typeof navigator){const e=navigator.userAgent;i=!0===/^((?!chrome|android).)*safari/i.test(e);const t=e.match(/Version\/(\d+)/);a=i&&t?parseInt(t[1],10):-1,r=e.indexOf("Firefox")>-1,o=r?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||i&&a<17||r&&o<98?this.textureLoader=new t.TextureLoader(this.options.manager):this.textureLoader=new t.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new t.FileLoader(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 ie(a,r,i),ae(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 s=this.json.buffers[e],i=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===e)return Promise.resolve(this.extensions[f.KHR_BINARY_GLTF].body);const a=this.options;return new Promise((function(e,r){i.load(t.LoaderUtils.resolveURL(s.uri,a.path),e,void 0,(function(){r(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.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=Y[a.type],s=W[a.componentType],i=!0===a.normalized,r=new s(a.count*e);return Promise.resolve(new t.BufferAttribute(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=Y[a.type],n=W[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),i="InterleavedBuffer:"+a.bufferView+":"+a.componentType+":"+e+":"+a.count;let l=s.cache.get(i);l||(u=new n(r,e*c,a.count*c/A),l=new t.InterleavedBuffer(u,c/A),s.cache.add(i,l)),p=new t.InterleavedBufferAttribute(l,o,h%c/A,d)}else u=null===r?new n(a.count*o):new n(r,h,a.count*o),p=new t.BufferAttribute(u,o,d);if(void 0!==a.sparse){const s=Y.SCALAR,i=W[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.BufferAttribute(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,s,i){const a=this,r=this.json,o=r.textures[e],n=r.images[s],A=(n.uri||n.bufferView)+":"+o.sampler;if(this.textureCache[A])return this.textureCache[A];const l=this.loadImageSource(s,i).then((function(s){s.flipY=!1,s.name=o.name||n.name||"",""===s.name&&"string"==typeof n.uri&&!1===n.uri.startsWith("data:image/")&&(s.name=n.uri);const i=(r.samplers||{})[o.sampler]||{};return s.magFilter=K[i.magFilter]||t.LinearFilter,s.minFilter=K[i.minFilter]||t.LinearMipmapLinearFilter,s.wrapS=J[i.wrapS]||t.RepeatWrapping,s.wrapT=J[i.wrapT]||t.RepeatWrapping,s.generateMipmaps=!s.isCompressedTexture&&s.minFilter!==t.NearestFilter&&s.minFilter!==t.LinearFilter,a.associations.set(s,{textures:e}),s})).catch((function(){return null}));return this.textureCache[A]=l,l}loadImageSource(e,s){const i=this,a=this.json,r=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then((e=>e.clone()));const o=a.images[e],n=self.URL||self.webkitURL;let A=o.uri||"",l=!1;if(void 0!==o.bufferView)A=i.getDependency("bufferView",o.bufferView).then((function(e){l=!0;const t=new Blob([e],{type:o.mimeType});return A=n.createObjectURL(t),A}));else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const h=Promise.resolve(A).then((function(e){return new Promise((function(i,a){let o=i;!0===s.isImageBitmapLoader&&(o=function(e){const s=new t.Texture(e);s.needsUpdate=!0,i(s)}),s.load(t.LoaderUtils.resolveURL(e,r.path),o,void 0,a)}))})).then((function(e){var t;return!0===l&&n.revokeObjectURL(A),ae(e,o),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":t.search(/\.ktx2($|\?)/i)>0||0===t.search(/^data\:image\/ktx2/)?"image/ktx2":"image/png"),e})).catch((function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",A),e}));return this.sourceCache[e]=h,h}assignTexture(e,t,s,i){const a=this;return this.getDependency("texture",s.index).then((function(r){if(!r)return null;if(void 0!==s.texCoord&&s.texCoord>0&&((r=r.clone()).channel=s.texCoord),a.extensions[f.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[f.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=a.associations.get(r);r=a.extensions[f.KHR_TEXTURE_TRANSFORM].extendTexture(r,e),a.associations.set(r,t)}}return void 0!==i&&(r.colorSpace=i),e[t]=r,r}))}assignFinalMaterial(e){const s=e.geometry;let i=e.material;const a=void 0===s.attributes.tangent,r=void 0!==s.attributes.color,o=void 0===s.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+i.uuid;let s=this.cache.get(e);s||(s=new t.PointsMaterial,t.Material.prototype.copy.call(s,i),s.color.copy(i.color),s.map=i.map,s.sizeAttenuation=!1,this.cache.add(e,s)),i=s}else if(e.isLine){const e="LineBasicMaterial:"+i.uuid;let s=this.cache.get(e);s||(s=new t.LineBasicMaterial,t.Material.prototype.copy.call(s,i),s.color.copy(i.color),s.map=i.map,this.cache.add(e,s)),i=s}if(a||r||o){let e="ClonedMateria