three-stdlib 2.7.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/{Nodes-ec4e1143.js → Nodes-894ac9dc.js} +0 -0
  2. package/{Nodes-427f68b0.js → Nodes-af575af7.js} +0 -0
  3. package/cameras/CinematicCamera.cjs.js +1 -1
  4. package/cameras/CinematicCamera.js +3 -8
  5. package/controls/ArcballControls.cjs.js +1 -1
  6. package/controls/ArcballControls.d.ts +6 -9
  7. package/controls/ArcballControls.js +188 -234
  8. package/controls/FirstPersonControls.cjs.js +1 -1
  9. package/controls/FirstPersonControls.d.ts +4 -5
  10. package/controls/FirstPersonControls.js +36 -45
  11. package/controls/TransformControls.cjs.js +1 -1
  12. package/controls/TransformControls.d.ts +2 -1
  13. package/controls/TransformControls.js +25 -26
  14. package/exporters/GLTFExporter.cjs.js +1 -1
  15. package/exporters/GLTFExporter.js +9 -18
  16. package/geometries/TeapotGeometry.js +2 -2
  17. package/index.cjs.js +1 -1
  18. package/loaders/EXRLoader.cjs.js +1 -1
  19. package/loaders/EXRLoader.js +21 -10
  20. package/loaders/GLTFLoader.cjs.js +1 -1
  21. package/loaders/GLTFLoader.js +5 -6
  22. package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
  23. package/loaders/HDRCubeTextureLoader.js +1 -3
  24. package/loaders/LDrawLoader.cjs.js +1 -1
  25. package/loaders/LDrawLoader.js +1450 -1105
  26. package/loaders/LUT3dlLoader.cjs.js +1 -1
  27. package/loaders/LUT3dlLoader.js +18 -11
  28. package/loaders/LUTCubeLoader.cjs.js +1 -1
  29. package/loaders/LUTCubeLoader.js +4 -5
  30. package/loaders/NodeMaterialLoader.cjs.js +1 -1
  31. package/loaders/PCDLoader.cjs.js +1 -1
  32. package/loaders/PCDLoader.js +2 -2
  33. package/loaders/RGBELoader.cjs.js +1 -1
  34. package/loaders/RGBELoader.js +6 -6
  35. package/loaders/STLLoader.js +7 -7
  36. package/loaders/VRMLLoader.cjs.js +1 -1
  37. package/loaders/VRMLLoader.js +10 -18
  38. package/modifiers/CurveModifier.cjs.js +1 -1
  39. package/modifiers/CurveModifier.js +9 -8
  40. package/nodes/accessors/CameraNode.js +12 -12
  41. package/nodes/accessors/PositionNode.js +3 -3
  42. package/nodes/accessors/ReflectNode.js +3 -3
  43. package/nodes/core/FunctionNode.js +3 -3
  44. package/nodes/core/InputNode.js +3 -3
  45. package/nodes/core/Node.js +6 -6
  46. package/nodes/core/TempNode.js +6 -6
  47. package/nodes/effects/BlurNode.js +3 -3
  48. package/nodes/math/MathNode.js +3 -3
  49. package/nodes/utils/VelocityNode.js +6 -6
  50. package/objects/Lensflare.cjs.js +1 -1
  51. package/objects/Lensflare.js +3 -11
  52. package/objects/Reflector.cjs.js +1 -1
  53. package/objects/Reflector.js +16 -12
  54. package/objects/ReflectorForSSRPass.cjs.js +1 -1
  55. package/objects/ReflectorForSSRPass.js +1 -9
  56. package/objects/Refractor.cjs.js +1 -1
  57. package/objects/Refractor.js +7 -12
  58. package/objects/Water.cjs.js +1 -1
  59. package/objects/Water.js +5 -16
  60. package/package.json +2 -2
  61. package/postprocessing/GlitchPass.cjs.js +1 -1
  62. package/postprocessing/GlitchPass.js +36 -33
  63. package/postprocessing/SMAAPass.cjs.js +1 -1
  64. package/postprocessing/SMAAPass.js +93 -96
  65. package/postprocessing/SSAOPass.cjs.js +1 -1
  66. package/postprocessing/SSAOPass.js +151 -152
  67. package/postprocessing/SavePass.cjs.js +1 -1
  68. package/postprocessing/SavePass.js +27 -28
  69. package/renderers/nodes/accessors/UVNode.js +1 -3
  70. package/renderers/nodes/core/AttributeNode.js +1 -3
  71. package/renderers/nodes/core/Node.js +4 -12
  72. package/renderers/nodes/core/NodeBuilder.js +6 -18
  73. package/renderers/webgpu/WebGPUTextures.cjs.js +1 -1
  74. package/renderers/webgpu/WebGPUTextures.js +1 -2
  75. package/utils/LDrawUtils.cjs.js +1 -0
  76. package/utils/LDrawUtils.js +144 -0
  77. package/webxr/ARButton.js +6 -6
  78. package/webxr/VRButton.js +6 -6
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("fflate");class n extends e.DataTextureLoader{constructor(r){super(r),this.type=e.HalfFloatType}parse(n){const t=65536,a=14,i=65537,o=16384,l=Math.pow(2.7182818,2.2);const s={l:0,c:0,lc:0};function u(e,r,n,t,a){for(;n<e;)r=r<<8|V(t,a),n+=8;n-=e,s.l=r>>n&(1<<e)-1,s.c=r,s.lc=n}const c=new Array(59);function f(e,r,n,t,a,o,l){for(var f=n,v=0,h=0;a<=o;a++){if(f.value-n.value>t)return!1;u(6,v,h,e,f);var p=s.l;if(v=s.c,h=s.lc,l[a]=p,63==p){if(f.value-n.value>t)throw"Something wrong with hufUnpackEncTable";u(8,v,h,e,f);var w=s.l+6;if(v=s.c,h=s.lc,a+w>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}else if(p>=59){if(a+(w=p-59+2)>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}}!function(e){for(var r=0;r<=58;++r)c[r]=0;for(r=0;r<i;++r)c[e[r]]+=1;var n=0;for(r=58;r>0;--r){var t=n+c[r]>>1;c[r]=n,n=t}for(r=0;r<i;++r){var a=e[r];a>0&&(e[r]=a|c[a]++<<6)}}(l)}function v(e){return 63&e}function h(e){return e>>6}const p={c:0,lc:0};function w(e,r,n,t){e=e<<8|V(n,t),r+=8,p.c=e,p.lc=r}const d={c:0,lc:0};function y(e,r,n,t,a,i,o,l,s,u){if(e==r){t<8&&(w(n,t,a,o),n=p.c,t=p.lc);var c=n>>(t-=8);c=new Uint8Array([c])[0];if(s.value+c>u)return!1;for(var f=l[s.value-1];c-- >0;)l[s.value++]=f}else{if(!(s.value<u))return!1;l[s.value++]=e}d.c=n,d.lc=t}function S(e){return 65535&e}function g(e){var r=S(e);return r>32767?r-65536:r}const b={a:0,b:0};function m(e,r){var n=g(e),t=g(r),a=n+(1&t)+(t>>1),i=a,o=a-t;b.a=i,b.b=o}function A(e,r){var n=S(e),t=S(r),a=n-(t>>1)&65535,i=t+a-32768&65535;b.a=i,b.b=a}function U(e,r,n,t,a,i,o){for(var l,s=o<16384,u=n>a?a:n,c=1;c<=u;)c<<=1;for(l=c>>=1,c>>=1;c>=1;){for(var f,v,h,p,w=0,d=w+i*(a-l),y=i*c,S=i*l,g=t*c,U=t*l;w<=d;w+=S){for(var M=w,z=w+t*(n-l);M<=z;M+=U){var C=M+g,E=(O=M+y)+g;s?(m(e[M+r],e[O+r]),f=b.a,h=b.b,m(e[C+r],e[E+r]),v=b.a,p=b.b,m(f,v),e[M+r]=b.a,e[C+r]=b.b,m(h,p),e[O+r]=b.a,e[E+r]=b.b):(A(e[M+r],e[O+r]),f=b.a,h=b.b,A(e[C+r],e[E+r]),v=b.a,p=b.b,A(f,v),e[M+r]=b.a,e[C+r]=b.b,A(h,p),e[O+r]=b.a,e[E+r]=b.b)}if(n&c){var O=M+y;s?m(e[M+r],e[O+r]):A(e[M+r],e[O+r]),f=b.a,e[O+r]=b.b,e[M+r]=f}}if(a&c)for(M=w,z=w+t*(n-l);M<=z;M+=U){C=M+g;s?m(e[M+r],e[C+r]):A(e[M+r],e[C+r]),f=b.a,e[C+r]=b.b,e[M+r]=f}l=c,c>>=1}return w}function M(e,r,n,t,l,s){var u=n.value,c=H(r,n),S=H(r,n);n.value+=4;var g=H(r,n);if(n.value+=4,c<0||c>=i||S<0||S>=i)throw"Something wrong with HUF_ENCSIZE";var b=new Array(i),m=new Array(o);if(function(e){for(var r=0;r<o;r++)e[r]={},e[r].len=0,e[r].lit=0,e[r].p=null}(m),f(e,0,n,t-(n.value-u),c,S,b),g>8*(t-(n.value-u)))throw"Something wrong with hufUncompress";!function(e,r,n,t){for(;r<=n;r++){var i=h(e[r]),o=v(e[r]);if(i>>o)throw"Invalid table entry";if(o>a){if((c=t[i>>o-a]).len)throw"Invalid table entry";if(c.lit++,c.p){var l=c.p;c.p=new Array(c.lit);for(var s=0;s<c.lit-1;++s)c.p[s]=l[s]}else c.p=new Array(1);c.p[c.lit-1]=r}else if(o){var u=0;for(s=1<<a-o;s>0;s--){var c;if((c=t[(i<<a-o)+u]).len||c.p)throw"Invalid table entry";c.len=o,c.lit=r,u++}}}}(b,c,S,m),function(e,r,n,t,i,o,l,s,u,c){for(var f=0,S=0,g=s,b=Math.trunc(i.value+(o+7)/8);i.value<b;)for(w(f,S,n,i),f=p.c,S=p.lc;S>=a;)if((M=r[f>>S-a&16383]).len)S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;else{if(!M.p)throw"hufDecode issues";var m;for(m=0;m<M.lit;m++){for(var A=v(e[M.p[m]]);S<A&&i.value<b;)w(f,S,n,i),f=p.c,S=p.lc;if(S>=A&&h(e[M.p[m]])==(f>>S-A&(1<<A)-1)){S-=A,y(M.p[m],l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;break}}if(m==M.lit)throw"hufDecode issues"}var U=8-o&7;for(f>>=U,S-=U;S>0;){var M;if(!(M=r[f<<a-S&16383]).len)throw"hufDecode issues";S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc}}(b,m,e,0,n,g,S,s,l,{value:0})}function z(e){for(var r=1;r<e.length;r++){var n=e[r-1]+e[r]-128;e[r]=n}}function C(e,r){for(var n=0,t=Math.floor((e.length+1)/2),a=0,i=e.length-1;!(a>i||(r[a++]=e[n++],a>i));)r[a++]=e[t++]}function E(e){for(var r=e.byteLength,n=new Array,t=0,a=new DataView(e);r>0;){var i=a.getInt8(t++);if(i<0){r-=(l=-i)+1;for(var o=0;o<l;o++)n.push(a.getUint8(t++))}else{var l=i;r-=2;var s=a.getUint8(t++);for(o=0;o<l+1;o++)n.push(s)}}return n}function O(e,r,n){for(var t,a=1;a<64;)65280==(t=r[e.value])?a=64:t>>8==255?a+=255&t:(n[a]=t,a++),e.value++}function R(e,r){r[0]=q(e[0]),r[1]=q(e[1]),r[2]=q(e[5]),r[3]=q(e[6]),r[4]=q(e[14]),r[5]=q(e[15]),r[6]=q(e[27]),r[7]=q(e[28]),r[8]=q(e[2]),r[9]=q(e[4]),r[10]=q(e[7]),r[11]=q(e[13]),r[12]=q(e[16]),r[13]=q(e[26]),r[14]=q(e[29]),r[15]=q(e[42]),r[16]=q(e[3]),r[17]=q(e[8]),r[18]=q(e[12]),r[19]=q(e[17]),r[20]=q(e[25]),r[21]=q(e[30]),r[22]=q(e[41]),r[23]=q(e[43]),r[24]=q(e[9]),r[25]=q(e[11]),r[26]=q(e[18]),r[27]=q(e[24]),r[28]=q(e[31]),r[29]=q(e[40]),r[30]=q(e[44]),r[31]=q(e[53]),r[32]=q(e[10]),r[33]=q(e[19]),r[34]=q(e[23]),r[35]=q(e[32]),r[36]=q(e[39]),r[37]=q(e[45]),r[38]=q(e[52]),r[39]=q(e[54]),r[40]=q(e[20]),r[41]=q(e[22]),r[42]=q(e[33]),r[43]=q(e[38]),r[44]=q(e[46]),r[45]=q(e[51]),r[46]=q(e[55]),r[47]=q(e[60]),r[48]=q(e[21]),r[49]=q(e[34]),r[50]=q(e[37]),r[51]=q(e[47]),r[52]=q(e[50]),r[53]=q(e[56]),r[54]=q(e[59]),r[55]=q(e[61]),r[56]=q(e[35]),r[57]=q(e[36]),r[58]=q(e[48]),r[59]=q(e[49]),r[60]=q(e[57]),r[61]=q(e[58]),r[62]=q(e[62]),r[63]=q(e[63])}function I(e){const r=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),t=.5*Math.cos(3.14159/8),a=.5*Math.cos(3*3.14159/16),i=.5*Math.cos(.981746875),o=.5*Math.cos(3*3.14159/8),l=.5*Math.cos(1.374445625);for(var s=new Array(4),u=new Array(4),c=new Array(4),f=new Array(4),v=0;v<8;++v){var h=8*v;s[0]=t*e[h+2],s[1]=o*e[h+2],s[2]=t*e[h+6],s[3]=o*e[h+6],u[0]=n*e[h+1]+a*e[h+3]+i*e[h+5]+l*e[h+7],u[1]=a*e[h+1]-l*e[h+3]-n*e[h+5]-i*e[h+7],u[2]=i*e[h+1]-n*e[h+3]+l*e[h+5]+a*e[h+7],u[3]=l*e[h+1]-i*e[h+3]+a*e[h+5]-n*e[h+7],c[0]=r*(e[h+0]+e[h+4]),c[3]=r*(e[h+0]-e[h+4]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[h+0]=f[0]+u[0],e[h+1]=f[1]+u[1],e[h+2]=f[2]+u[2],e[h+3]=f[3]+u[3],e[h+4]=f[3]-u[3],e[h+5]=f[2]-u[2],e[h+6]=f[1]-u[1],e[h+7]=f[0]-u[0]}for(var p=0;p<8;++p)s[0]=t*e[16+p],s[1]=o*e[16+p],s[2]=t*e[48+p],s[3]=o*e[48+p],u[0]=n*e[8+p]+a*e[24+p]+i*e[40+p]+l*e[56+p],u[1]=a*e[8+p]-l*e[24+p]-n*e[40+p]-i*e[56+p],u[2]=i*e[8+p]-n*e[24+p]+l*e[40+p]+a*e[56+p],u[3]=l*e[8+p]-i*e[24+p]+a*e[40+p]-n*e[56+p],c[0]=r*(e[p]+e[32+p]),c[3]=r*(e[p]-e[32+p]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[0+p]=f[0]+u[0],e[8+p]=f[1]+u[1],e[16+p]=f[2]+u[2],e[24+p]=f[3]+u[3],e[32+p]=f[3]-u[3],e[40+p]=f[2]-u[2],e[48+p]=f[1]-u[1],e[56+p]=f[0]-u[0]}function x(e){for(var r=0;r<64;++r){var n=e[0][r],t=e[1][r],a=e[2][r];e[0][r]=n+1.5747*a,e[1][r]=n-.1873*t-.4682*a,e[2][r]=n+1.8556*t}}function k(r,n,t){for(var a=0;a<64;++a)n[t+a]=e.DataUtils.toHalfFloat(P(r[a]))}function P(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(l,Math.abs(e)-1)}function N(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function D(e){var r=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(E(r)),t=new Uint8Array(n.length);return z(n),C(n,t),new DataView(t.buffer)}function L(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n),a=new Uint8Array(t.length);return z(t),C(t,a),new DataView(a.buffer)}function _(e){for(var r=e.viewer,n={value:e.offset.value},a=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),i=new Uint8Array(8192),o=0,l=new Array(e.channels),s=0;s<e.channels;s++)l[s]={},l[s].start=o,l[s].end=l[s].start,l[s].nx=e.width,l[s].ny=e.lines,l[s].size=e.type,o+=l[s].nx*l[s].ny*l[s].size;var u=j(r,n),c=j(r,n);if(c>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(u<=c)for(s=0;s<c-u+1;s++)i[s+u]=W(r,n);var f=new Uint16Array(t),v=function(e,r){for(var n=0,a=0;a<t;++a)(0==a||e[a>>3]&1<<(7&a))&&(r[n++]=a);for(var i=n-1;n<t;)r[n++]=0;return i}(i,f),h=H(r,n);M(e.array,r,n,h,a,o);for(s=0;s<e.channels;++s)for(var p=l[s],w=0;w<l[s].size;++w)U(a,p.start+w,p.nx,p.size,p.ny,p.nx*p.size,v);!function(e,r,n){for(var t=0;t<n;++t)r[t]=e[r[t]]}(f,a,o);for(var d=0,y=new Uint8Array(a.buffer.byteLength),S=0;S<e.lines;S++)for(var g=0;g<e.channels;g++){var b=(p=l[g]).nx*p.size,m=new Uint8Array(a.buffer,2*p.end,2*b);y.set(m,d),d+=2*b,p.end+=b}return new DataView(y.buffer)}function T(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n);const a=e.lines*e.channels*e.width,i=1==e.type?new Uint16Array(a):new Uint32Array(a);let o=0,l=0;const s=new Array(4);for(let r=0;r<e.lines;r++)for(let r=0;r<e.channels;r++){let r=0;switch(e.type){case 1:s[0]=o,s[1]=s[0]+e.width,o=s[1]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<8|t[s[1]++],i[l]=r,l++}break;case 2:s[0]=o,s[1]=s[0]+e.width,s[2]=s[1]+e.width,o=s[2]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<24|t[s[1]++]<<16|t[s[2]++]<<8,i[l]=r,l++}}}return new DataView(i.buffer)}function F(e){var n=e.viewer,t={value:e.offset.value},a=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Z(n,t),unknownUncompressedSize:Z(n,t),unknownCompressedSize:Z(n,t),acCompressedSize:Z(n,t),dcCompressedSize:Z(n,t),rleCompressedSize:Z(n,t),rleUncompressedSize:Z(n,t),rleRawSize:Z(n,t),totalAcUncompressedCount:Z(n,t),totalDcUncompressedCount:Z(n,t),acCompression:Z(n,t)};if(i.version<2)throw"EXRLoader.parse: "+re.compression+" version "+i.version+" is unsupported";for(var o=new Array,l=j(n,t)-2;l>0;){var s=X(n.buffer,t),u=W(n,t),c=u>>2&3,f=new Int8Array([(u>>4)-1])[0],v=W(n,t);o.push({name:s,index:f,type:v,compression:c}),l-=s.length+3}for(var h=re.channels,p=new Array(e.channels),w=0;w<e.channels;++w){var d=p[w]={},y=h[w];d.name=y.name,d.compression=0,d.decoded=!1,d.type=y.pixelType,d.pLinear=y.pLinear,d.width=e.width,d.height=e.lines}for(var S={idx:new Array(3)},g=0;g<e.channels;++g)for(d=p[g],w=0;w<o.length;++w){var b=o[w];d.name==b.name&&(d.compression=b.compression,b.index>=0&&(S.idx[b.index]=g),d.offset=g)}if(i.acCompressedSize>0)switch(i.acCompression){case 0:var m=new Uint16Array(i.totalAcUncompressedCount);M(e.array,n,t,i.acCompressedSize,m,i.totalAcUncompressedCount);break;case 1:var A=e.array.slice(t.value,t.value+i.totalAcUncompressedCount),U=r.unzlibSync(A);m=new Uint16Array(U.buffer);t.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){var z={array:e.array,offset:t,size:i.dcCompressedSize},C=new Uint16Array(L(z).buffer);t.value+=i.dcCompressedSize}if(i.rleRawSize>0){A=e.array.slice(t.value,t.value+i.rleCompressedSize);var P=E((U=r.unzlibSync(A)).buffer);t.value+=i.rleCompressedSize}var N=0,D=new Array(p.length);for(w=0;w<D.length;++w)D[w]=new Array;for(var _=0;_<e.lines;++_)for(var T=0;T<p.length;++T)D[T].push(N),N+=p[T].width*e.type*2;!function(e,r,n,t,a,i){var o=new DataView(i.buffer),l=n[e.idx[0]].width,s=n[e.idx[0]].height,u=Math.floor(l/8),c=Math.ceil(l/8),f=Math.ceil(s/8),v=l-8*(c-1),h=s-8*(f-1),p={value:0},w=new Array(3),d=new Array(3),y=new Array(3),S=new Array(3),g=new Array(3);for(let n=0;n<3;++n)g[n]=r[e.idx[n]],w[n]=n<1?0:w[n-1]+c*f,d[n]=new Float32Array(64),y[n]=new Uint16Array(64),S[n]=new Uint16Array(64*c);for(let r=0;r<f;++r){var b=8;r==f-1&&(b=h);var m=8;for(let e=0;e<c;++e){e==c-1&&(m=v);for(let e=0;e<3;++e)y[e].fill(0),y[e][0]=a[w[e]++],O(p,t,y[e]),R(y[e],d[e]),I(d[e]);x(d);for(let r=0;r<3;++r)k(d[r],S[r],64*e)}let i=0;for(let t=0;t<3;++t){const a=n[e.idx[t]].type;for(let e=8*r;e<8*r+b;++e){i=g[t][e];for(let r=0;r<u;++r){const n=64*r+8*(7&e);o.setUint16(i+0*a,S[t][n+0],!0),o.setUint16(i+2*a,S[t][n+1],!0),o.setUint16(i+4*a,S[t][n+2],!0),o.setUint16(i+6*a,S[t][n+3],!0),o.setUint16(i+8*a,S[t][n+4],!0),o.setUint16(i+10*a,S[t][n+5],!0),o.setUint16(i+12*a,S[t][n+6],!0),o.setUint16(i+14*a,S[t][n+7],!0),i+=16*a}}if(u!=c)for(let e=8*r;e<8*r+b;++e){const r=g[t][e]+8*u*2*a,n=64*u+8*(7&e);for(let e=0;e<m;++e)o.setUint16(r+2*e*a,S[t][n+e],!0)}}}for(var A=new Uint16Array(l),U=(o=new DataView(i.buffer),0);U<3;++U){n[e.idx[U]].decoded=!0;var M=n[e.idx[U]].type;if(2==n[U].type)for(var z=0;z<s;++z){const e=g[U][z];for(var C=0;C<l;++C)A[C]=o.getUint16(e+2*C*M,!0);for(C=0;C<l;++C)o.setFloat32(e+2*C*M,q(A[C]),!0)}}}(S,D,p,m,C,a);for(w=0;w<p.length;++w){if(!(d=p[w]).decoded)switch(d.compression){case 2:var F=0,B=0;for(_=0;_<e.lines;++_){for(var H=D[w][F],V=0;V<d.width;++V){for(var Y=0;Y<2*d.type;++Y)a[H++]=P[B+Y*d.width*d.height];B++}F++}break;case 1:default:throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(a.buffer)}function X(e,r){for(var n=new Uint8Array(e),t=0;0!=n[r.value+t];)t+=1;var a=(new TextDecoder).decode(n.slice(r.value,r.value+t));return r.value=r.value+t+1,a}function B(e,r){var n=e.getInt32(r.value,!0);return r.value=r.value+4,n}function H(e,r){var n=e.getUint32(r.value,!0);return r.value=r.value+4,n}function V(e,r){var n=e[r.value];return r.value=r.value+1,n}function W(e,r){var n=e.getUint8(r.value);return r.value=r.value+1,n}function Z(e,r){var n=Number(e.getBigInt64(r.value,!0));return r.value+=8,n}function Y(e,r){var n=e.getFloat32(r.value,!0);return r.value+=4,n}function G(r,n){return e.DataUtils.toHalfFloat(Y(r,n))}function q(e){var r=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(r?31===r?n?NaN:1/0:Math.pow(2,r-15)*(1+n/1024):n/1024*6103515625e-14)}function j(e,r){var n=e.getUint16(r.value,!0);return r.value+=2,n}function $(e,r){return q(j(e,r))}function J(e,r,n,t,a){return"string"===t||"stringvector"===t||"iccProfile"===t?function(e,r,n){var t=(new TextDecoder).decode(new Uint8Array(e).slice(r.value,r.value+n));return r.value=r.value+n,t}(r,n,a):"chlist"===t?function(e,r,n,t){for(var a=n.value,i=[];n.value<a+t-1;){var o=X(r,n),l=B(e,n),s=W(e,n);n.value+=3;var u=B(e,n),c=B(e,n);i.push({name:o,pixelType:l,pLinear:s,xSampling:u,ySampling:c})}return n.value+=1,i}(e,r,n,a):"chromaticities"===t?function(e,r){return{redX:Y(e,r),redY:Y(e,r),greenX:Y(e,r),greenY:Y(e,r),blueX:Y(e,r),blueY:Y(e,r),whiteX:Y(e,r),whiteY:Y(e,r)}}(e,n):"compression"===t?function(e,r){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][W(e,r)]}(e,n):"box2i"===t?function(e,r){return{xMin:H(e,r),yMin:H(e,r),xMax:H(e,r),yMax:H(e,r)}}(e,n):"lineOrder"===t?function(e,r){return["INCREASING_Y"][W(e,r)]}(e,n):"float"===t?Y(e,n):"v2f"===t?function(e,r){return[Y(e,r),Y(e,r)]}(e,n):"v3f"===t?function(e,r){return[Y(e,r),Y(e,r),Y(e,r)]}(e,n):"int"===t?B(e,n):"rational"===t?function(e,r){return[B(e,r),H(e,r)]}(e,n):"timecode"===t?function(e,r){return[H(e,r),H(e,r)]}(e,n):"preview"===t?(n.value+=a,"skipped"):void(n.value+=a)}const K=new DataView(n),Q=new Uint8Array(n),ee={value:0},re=function(e,r,n){const t={};if(20000630!=e.getUint32(0,!0))throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";t.version=e.getUint8(4,!0);const a=e.getUint8(5,!0);t.spec={singleTile:!!(1&a),longName:!!(2&a),deepFormat:!!(4&a),multiPart:!!(8&a)},n.value=8;for(var i=!0;i;){var o=X(r,n);if(0==o)i=!1;else{var l=X(r,n),s=J(e,r,n,l,H(e,n));void 0===s?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${l}'.`):t[o]=s}}if(0!=a)throw console.error("EXRHeader:",t),"THREE.EXRLoader: provided file is currently unsupported.";return t}(K,n,ee),ne=function(r,n,t,a,i){const o={size:0,viewer:n,array:t,offset:a,width:r.dataWindow.xMax-r.dataWindow.xMin+1,height:r.dataWindow.yMax-r.dataWindow.yMin+1,channels:r.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:r.channels[0].pixelType,uncompress:null,getter:null,format:null,encoding:null};switch(r.compression){case"NO_COMPRESSION":o.lines=1,o.uncompress=N;break;case"RLE_COMPRESSION":o.lines=1,o.uncompress=D;break;case"ZIPS_COMPRESSION":o.lines=1,o.uncompress=L;break;case"ZIP_COMPRESSION":o.lines=16,o.uncompress=L;break;case"PIZ_COMPRESSION":o.lines=32,o.uncompress=_;break;case"PXR24_COMPRESSION":o.lines=16,o.uncompress=T;break;case"DWAA_COMPRESSION":o.lines=32,o.uncompress=F;break;case"DWAB_COMPRESSION":o.lines=256,o.uncompress=F;break;default:throw"EXRLoader.parse: "+r.compression+" is unsupported"}if(o.scanlineBlockSize=o.lines,1==o.type)switch(i){case e.FloatType:o.getter=$,o.inputSize=2;break;case e.HalfFloatType:o.getter=j,o.inputSize=2}else{if(2!=o.type)throw"EXRLoader.parse: unsupported pixelType "+o.type+" for "+r.compression+".";switch(i){case e.FloatType:o.getter=Y,o.inputSize=4;break;case e.HalfFloatType:o.getter=G,o.inputSize=4}}o.blockCount=(r.dataWindow.yMax+1)/o.scanlineBlockSize;for(var l=0;l<o.blockCount;l++)Z(n,a);o.outputChannels=3==o.channels?4:o.channels;const s=o.width*o.height*o.outputChannels;switch(i){case e.FloatType:o.byteArray=new Float32Array(s),o.channels<o.outputChannels&&o.byteArray.fill(1,0,s);break;case e.HalfFloatType:o.byteArray=new Uint16Array(s),o.channels<o.outputChannels&&o.byteArray.fill(15360,0,s);break;default:console.error("THREE.EXRLoader: unsupported type: ",i)}return o.bytesPerLine=o.width*o.inputSize*o.channels,4==o.outputChannels?(o.format=e.RGBAFormat,o.encoding=e.LinearEncoding):(o.format=e.RedFormat,o.encoding=e.LinearEncoding),o}(re,K,Q,ee,this.type),te={value:0},ae={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<ne.height/ne.scanlineBlockSize;e++){const r=H(K,ee);ne.size=H(K,ee),ne.lines=r+ne.scanlineBlockSize>ne.height?ne.height-r:ne.scanlineBlockSize;const n=ne.size<ne.lines*ne.bytesPerLine?ne.uncompress(ne):N(ne);ee.value+=ne.size;for(let r=0;r<ne.scanlineBlockSize;r++){const t=r+e*ne.scanlineBlockSize;if(t>=ne.height)break;for(let e=0;e<ne.channels;e++){const a=ae[re.channels[e].name];for(let i=0;i<ne.width;i++){te.value=(r*(ne.channels*ne.width)+e*ne.width+i)*ne.inputSize;const o=(ne.height-1-t)*(ne.width*ne.outputChannels)+i*ne.outputChannels+a;ne.byteArray[o]=ne.getter(n,te)}}}}return{header:re,width:ne.width,height:ne.height,data:ne.byteArray,format:ne.format,encoding:ne.encoding,type:this.type}}setDataType(e){return this.type=e,this}load(r,n,t,a){return super.load(r,(function(r,t){r.encoding=t.encoding,r.minFilter=e.LinearFilter,r.magFilter=e.LinearFilter,r.generateMipmaps=!1,r.flipY=!1,n&&n(r,t)}),t,a)}}exports.EXRLoader=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("fflate");class n extends e.DataTextureLoader{constructor(r){super(r),this.type=e.HalfFloatType}parse(n){const t=65536,a=14,i=65537,o=16384,l=Math.pow(2.7182818,2.2);const s={l:0,c:0,lc:0};function u(e,r,n,t,a){for(;n<e;)r=r<<8|V(t,a),n+=8;n-=e,s.l=r>>n&(1<<e)-1,s.c=r,s.lc=n}const c=new Array(59);function f(e,r,n,t,a,o,l){for(var f=n,v=0,h=0;a<=o;a++){if(f.value-n.value>t)return!1;u(6,v,h,e,f);var p=s.l;if(v=s.c,h=s.lc,l[a]=p,63==p){if(f.value-n.value>t)throw"Something wrong with hufUnpackEncTable";u(8,v,h,e,f);var w=s.l+6;if(v=s.c,h=s.lc,a+w>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}else if(p>=59){if(a+(w=p-59+2)>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}}!function(e){for(var r=0;r<=58;++r)c[r]=0;for(r=0;r<i;++r)c[e[r]]+=1;var n=0;for(r=58;r>0;--r){var t=n+c[r]>>1;c[r]=n,n=t}for(r=0;r<i;++r){var a=e[r];a>0&&(e[r]=a|c[a]++<<6)}}(l)}function v(e){return 63&e}function h(e){return e>>6}const p={c:0,lc:0};function w(e,r,n,t){e=e<<8|V(n,t),r+=8,p.c=e,p.lc=r}const d={c:0,lc:0};function y(e,r,n,t,a,i,o,l,s,u){if(e==r){t<8&&(w(n,t,a,o),n=p.c,t=p.lc);var c=n>>(t-=8);c=new Uint8Array([c])[0];if(s.value+c>u)return!1;for(var f=l[s.value-1];c-- >0;)l[s.value++]=f}else{if(!(s.value<u))return!1;l[s.value++]=e}d.c=n,d.lc=t}function S(e){return 65535&e}function g(e){var r=S(e);return r>32767?r-65536:r}const b={a:0,b:0};function m(e,r){var n=g(e),t=g(r),a=n+(1&t)+(t>>1),i=a,o=a-t;b.a=i,b.b=o}function A(e,r){var n=S(e),t=S(r),a=n-(t>>1)&65535,i=t+a-32768&65535;b.a=i,b.b=a}function U(e,r,n,t,a,i,o){for(var l,s=o<16384,u=n>a?a:n,c=1;c<=u;)c<<=1;for(l=c>>=1,c>>=1;c>=1;){for(var f,v,h,p,w=0,d=w+i*(a-l),y=i*c,S=i*l,g=t*c,U=t*l;w<=d;w+=S){for(var M=w,z=w+t*(n-l);M<=z;M+=U){var C=M+g,E=(O=M+y)+g;s?(m(e[M+r],e[O+r]),f=b.a,h=b.b,m(e[C+r],e[E+r]),v=b.a,p=b.b,m(f,v),e[M+r]=b.a,e[C+r]=b.b,m(h,p),e[O+r]=b.a,e[E+r]=b.b):(A(e[M+r],e[O+r]),f=b.a,h=b.b,A(e[C+r],e[E+r]),v=b.a,p=b.b,A(f,v),e[M+r]=b.a,e[C+r]=b.b,A(h,p),e[O+r]=b.a,e[E+r]=b.b)}if(n&c){var O=M+y;s?m(e[M+r],e[O+r]):A(e[M+r],e[O+r]),f=b.a,e[O+r]=b.b,e[M+r]=f}}if(a&c)for(M=w,z=w+t*(n-l);M<=z;M+=U){C=M+g;s?m(e[M+r],e[C+r]):A(e[M+r],e[C+r]),f=b.a,e[C+r]=b.b,e[M+r]=f}l=c,c>>=1}return w}function M(e,r,n,t,l,s){var u=n.value,c=H(r,n),S=H(r,n);n.value+=4;var g=H(r,n);if(n.value+=4,c<0||c>=i||S<0||S>=i)throw"Something wrong with HUF_ENCSIZE";var b=new Array(i),m=new Array(o);if(function(e){for(var r=0;r<o;r++)e[r]={},e[r].len=0,e[r].lit=0,e[r].p=null}(m),f(e,0,n,t-(n.value-u),c,S,b),g>8*(t-(n.value-u)))throw"Something wrong with hufUncompress";!function(e,r,n,t){for(;r<=n;r++){var i=h(e[r]),o=v(e[r]);if(i>>o)throw"Invalid table entry";if(o>a){if((c=t[i>>o-a]).len)throw"Invalid table entry";if(c.lit++,c.p){var l=c.p;c.p=new Array(c.lit);for(var s=0;s<c.lit-1;++s)c.p[s]=l[s]}else c.p=new Array(1);c.p[c.lit-1]=r}else if(o){var u=0;for(s=1<<a-o;s>0;s--){var c;if((c=t[(i<<a-o)+u]).len||c.p)throw"Invalid table entry";c.len=o,c.lit=r,u++}}}}(b,c,S,m),function(e,r,n,t,i,o,l,s,u,c){for(var f=0,S=0,g=s,b=Math.trunc(i.value+(o+7)/8);i.value<b;)for(w(f,S,n,i),f=p.c,S=p.lc;S>=a;)if((M=r[f>>S-a&16383]).len)S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;else{if(!M.p)throw"hufDecode issues";var m;for(m=0;m<M.lit;m++){for(var A=v(e[M.p[m]]);S<A&&i.value<b;)w(f,S,n,i),f=p.c,S=p.lc;if(S>=A&&h(e[M.p[m]])==(f>>S-A&(1<<A)-1)){S-=A,y(M.p[m],l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;break}}if(m==M.lit)throw"hufDecode issues"}var U=8-o&7;for(f>>=U,S-=U;S>0;){var M;if(!(M=r[f<<a-S&16383]).len)throw"hufDecode issues";S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc}}(b,m,e,0,n,g,S,s,l,{value:0})}function z(e){for(var r=1;r<e.length;r++){var n=e[r-1]+e[r]-128;e[r]=n}}function C(e,r){for(var n=0,t=Math.floor((e.length+1)/2),a=0,i=e.length-1;!(a>i||(r[a++]=e[n++],a>i));)r[a++]=e[t++]}function E(e){for(var r=e.byteLength,n=new Array,t=0,a=new DataView(e);r>0;){var i=a.getInt8(t++);if(i<0){r-=(l=-i)+1;for(var o=0;o<l;o++)n.push(a.getUint8(t++))}else{var l=i;r-=2;var s=a.getUint8(t++);for(o=0;o<l+1;o++)n.push(s)}}return n}function O(e,r,n){for(var t,a=1;a<64;)65280==(t=r[e.value])?a=64:t>>8==255?a+=255&t:(n[a]=t,a++),e.value++}function R(e,r){r[0]=q(e[0]),r[1]=q(e[1]),r[2]=q(e[5]),r[3]=q(e[6]),r[4]=q(e[14]),r[5]=q(e[15]),r[6]=q(e[27]),r[7]=q(e[28]),r[8]=q(e[2]),r[9]=q(e[4]),r[10]=q(e[7]),r[11]=q(e[13]),r[12]=q(e[16]),r[13]=q(e[26]),r[14]=q(e[29]),r[15]=q(e[42]),r[16]=q(e[3]),r[17]=q(e[8]),r[18]=q(e[12]),r[19]=q(e[17]),r[20]=q(e[25]),r[21]=q(e[30]),r[22]=q(e[41]),r[23]=q(e[43]),r[24]=q(e[9]),r[25]=q(e[11]),r[26]=q(e[18]),r[27]=q(e[24]),r[28]=q(e[31]),r[29]=q(e[40]),r[30]=q(e[44]),r[31]=q(e[53]),r[32]=q(e[10]),r[33]=q(e[19]),r[34]=q(e[23]),r[35]=q(e[32]),r[36]=q(e[39]),r[37]=q(e[45]),r[38]=q(e[52]),r[39]=q(e[54]),r[40]=q(e[20]),r[41]=q(e[22]),r[42]=q(e[33]),r[43]=q(e[38]),r[44]=q(e[46]),r[45]=q(e[51]),r[46]=q(e[55]),r[47]=q(e[60]),r[48]=q(e[21]),r[49]=q(e[34]),r[50]=q(e[37]),r[51]=q(e[47]),r[52]=q(e[50]),r[53]=q(e[56]),r[54]=q(e[59]),r[55]=q(e[61]),r[56]=q(e[35]),r[57]=q(e[36]),r[58]=q(e[48]),r[59]=q(e[49]),r[60]=q(e[57]),r[61]=q(e[58]),r[62]=q(e[62]),r[63]=q(e[63])}function I(e){const r=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),t=.5*Math.cos(3.14159/8),a=.5*Math.cos(3*3.14159/16),i=.5*Math.cos(.981746875),o=.5*Math.cos(3*3.14159/8),l=.5*Math.cos(1.374445625);for(var s=new Array(4),u=new Array(4),c=new Array(4),f=new Array(4),v=0;v<8;++v){var h=8*v;s[0]=t*e[h+2],s[1]=o*e[h+2],s[2]=t*e[h+6],s[3]=o*e[h+6],u[0]=n*e[h+1]+a*e[h+3]+i*e[h+5]+l*e[h+7],u[1]=a*e[h+1]-l*e[h+3]-n*e[h+5]-i*e[h+7],u[2]=i*e[h+1]-n*e[h+3]+l*e[h+5]+a*e[h+7],u[3]=l*e[h+1]-i*e[h+3]+a*e[h+5]-n*e[h+7],c[0]=r*(e[h+0]+e[h+4]),c[3]=r*(e[h+0]-e[h+4]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[h+0]=f[0]+u[0],e[h+1]=f[1]+u[1],e[h+2]=f[2]+u[2],e[h+3]=f[3]+u[3],e[h+4]=f[3]-u[3],e[h+5]=f[2]-u[2],e[h+6]=f[1]-u[1],e[h+7]=f[0]-u[0]}for(var p=0;p<8;++p)s[0]=t*e[16+p],s[1]=o*e[16+p],s[2]=t*e[48+p],s[3]=o*e[48+p],u[0]=n*e[8+p]+a*e[24+p]+i*e[40+p]+l*e[56+p],u[1]=a*e[8+p]-l*e[24+p]-n*e[40+p]-i*e[56+p],u[2]=i*e[8+p]-n*e[24+p]+l*e[40+p]+a*e[56+p],u[3]=l*e[8+p]-i*e[24+p]+a*e[40+p]-n*e[56+p],c[0]=r*(e[p]+e[32+p]),c[3]=r*(e[p]-e[32+p]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[0+p]=f[0]+u[0],e[8+p]=f[1]+u[1],e[16+p]=f[2]+u[2],e[24+p]=f[3]+u[3],e[32+p]=f[3]-u[3],e[40+p]=f[2]-u[2],e[48+p]=f[1]-u[1],e[56+p]=f[0]-u[0]}function x(e){for(var r=0;r<64;++r){var n=e[0][r],t=e[1][r],a=e[2][r];e[0][r]=n+1.5747*a,e[1][r]=n-.1873*t-.4682*a,e[2][r]=n+1.8556*t}}function k(r,n,t){for(var a=0;a<64;++a)n[t+a]=e.DataUtils.toHalfFloat(P(r[a]))}function P(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(l,Math.abs(e)-1)}function N(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function D(e){var r=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(E(r)),t=new Uint8Array(n.length);return z(n),C(n,t),new DataView(t.buffer)}function L(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n),a=new Uint8Array(t.length);return z(t),C(t,a),new DataView(a.buffer)}function _(e){for(var r=e.viewer,n={value:e.offset.value},a=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),i=new Uint8Array(8192),o=0,l=new Array(e.channels),s=0;s<e.channels;s++)l[s]={},l[s].start=o,l[s].end=l[s].start,l[s].nx=e.width,l[s].ny=e.lines,l[s].size=e.type,o+=l[s].nx*l[s].ny*l[s].size;var u=j(r,n),c=j(r,n);if(c>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(u<=c)for(s=0;s<c-u+1;s++)i[s+u]=W(r,n);var f=new Uint16Array(t),v=function(e,r){for(var n=0,a=0;a<t;++a)(0==a||e[a>>3]&1<<(7&a))&&(r[n++]=a);for(var i=n-1;n<t;)r[n++]=0;return i}(i,f),h=H(r,n);M(e.array,r,n,h,a,o);for(s=0;s<e.channels;++s)for(var p=l[s],w=0;w<l[s].size;++w)U(a,p.start+w,p.nx,p.size,p.ny,p.nx*p.size,v);!function(e,r,n){for(var t=0;t<n;++t)r[t]=e[r[t]]}(f,a,o);for(var d=0,y=new Uint8Array(a.buffer.byteLength),S=0;S<e.lines;S++)for(var g=0;g<e.channels;g++){var b=(p=l[g]).nx*p.size,m=new Uint8Array(a.buffer,2*p.end,2*b);y.set(m,d),d+=2*b,p.end+=b}return new DataView(y.buffer)}function T(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n);const a=e.lines*e.channels*e.width,i=1==e.type?new Uint16Array(a):new Uint32Array(a);let o=0,l=0;const s=new Array(4);for(let r=0;r<e.lines;r++)for(let r=0;r<e.channels;r++){let r=0;switch(e.type){case 1:s[0]=o,s[1]=s[0]+e.width,o=s[1]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<8|t[s[1]++],i[l]=r,l++}break;case 2:s[0]=o,s[1]=s[0]+e.width,s[2]=s[1]+e.width,o=s[2]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<24|t[s[1]++]<<16|t[s[2]++]<<8,i[l]=r,l++}}}return new DataView(i.buffer)}function F(e){var n=e.viewer,t={value:e.offset.value},a=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Z(n,t),unknownUncompressedSize:Z(n,t),unknownCompressedSize:Z(n,t),acCompressedSize:Z(n,t),dcCompressedSize:Z(n,t),rleCompressedSize:Z(n,t),rleUncompressedSize:Z(n,t),rleRawSize:Z(n,t),totalAcUncompressedCount:Z(n,t),totalDcUncompressedCount:Z(n,t),acCompression:Z(n,t)};if(i.version<2)throw"EXRLoader.parse: "+re.compression+" version "+i.version+" is unsupported";for(var o=new Array,l=j(n,t)-2;l>0;){var s=B(n.buffer,t),u=W(n,t),c=u>>2&3,f=new Int8Array([(u>>4)-1])[0],v=W(n,t);o.push({name:s,index:f,type:v,compression:c}),l-=s.length+3}for(var h=re.channels,p=new Array(e.channels),w=0;w<e.channels;++w){var d=p[w]={},y=h[w];d.name=y.name,d.compression=0,d.decoded=!1,d.type=y.pixelType,d.pLinear=y.pLinear,d.width=e.width,d.height=e.lines}for(var S={idx:new Array(3)},g=0;g<e.channels;++g)for(d=p[g],w=0;w<o.length;++w){var b=o[w];d.name==b.name&&(d.compression=b.compression,b.index>=0&&(S.idx[b.index]=g),d.offset=g)}if(i.acCompressedSize>0)switch(i.acCompression){case 0:var m=new Uint16Array(i.totalAcUncompressedCount);M(e.array,n,t,i.acCompressedSize,m,i.totalAcUncompressedCount);break;case 1:var A=e.array.slice(t.value,t.value+i.totalAcUncompressedCount),U=r.unzlibSync(A);m=new Uint16Array(U.buffer);t.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){var z={array:e.array,offset:t,size:i.dcCompressedSize},C=new Uint16Array(L(z).buffer);t.value+=i.dcCompressedSize}if(i.rleRawSize>0){A=e.array.slice(t.value,t.value+i.rleCompressedSize);var P=E((U=r.unzlibSync(A)).buffer);t.value+=i.rleCompressedSize}var N=0,D=new Array(p.length);for(w=0;w<D.length;++w)D[w]=new Array;for(var _=0;_<e.lines;++_)for(var T=0;T<p.length;++T)D[T].push(N),N+=p[T].width*e.type*2;!function(e,r,n,t,a,i){var o=new DataView(i.buffer),l=n[e.idx[0]].width,s=n[e.idx[0]].height,u=Math.floor(l/8),c=Math.ceil(l/8),f=Math.ceil(s/8),v=l-8*(c-1),h=s-8*(f-1),p={value:0},w=new Array(3),d=new Array(3),y=new Array(3),S=new Array(3),g=new Array(3);for(let n=0;n<3;++n)g[n]=r[e.idx[n]],w[n]=n<1?0:w[n-1]+c*f,d[n]=new Float32Array(64),y[n]=new Uint16Array(64),S[n]=new Uint16Array(64*c);for(let r=0;r<f;++r){var b=8;r==f-1&&(b=h);var m=8;for(let e=0;e<c;++e){e==c-1&&(m=v);for(let e=0;e<3;++e)y[e].fill(0),y[e][0]=a[w[e]++],O(p,t,y[e]),R(y[e],d[e]),I(d[e]);x(d);for(let r=0;r<3;++r)k(d[r],S[r],64*e)}let i=0;for(let t=0;t<3;++t){const a=n[e.idx[t]].type;for(let e=8*r;e<8*r+b;++e){i=g[t][e];for(let r=0;r<u;++r){const n=64*r+8*(7&e);o.setUint16(i+0*a,S[t][n+0],!0),o.setUint16(i+2*a,S[t][n+1],!0),o.setUint16(i+4*a,S[t][n+2],!0),o.setUint16(i+6*a,S[t][n+3],!0),o.setUint16(i+8*a,S[t][n+4],!0),o.setUint16(i+10*a,S[t][n+5],!0),o.setUint16(i+12*a,S[t][n+6],!0),o.setUint16(i+14*a,S[t][n+7],!0),i+=16*a}}if(u!=c)for(let e=8*r;e<8*r+b;++e){const r=g[t][e]+8*u*2*a,n=64*u+8*(7&e);for(let e=0;e<m;++e)o.setUint16(r+2*e*a,S[t][n+e],!0)}}}for(var A=new Uint16Array(l),U=(o=new DataView(i.buffer),0);U<3;++U){n[e.idx[U]].decoded=!0;var M=n[e.idx[U]].type;if(2==n[U].type)for(var z=0;z<s;++z){const e=g[U][z];for(var C=0;C<l;++C)A[C]=o.getUint16(e+2*C*M,!0);for(C=0;C<l;++C)o.setFloat32(e+2*C*M,q(A[C]),!0)}}}(S,D,p,m,C,a);for(w=0;w<p.length;++w){if(!(d=p[w]).decoded)switch(d.compression){case 2:var F=0,X=0;for(_=0;_<e.lines;++_){for(var H=D[w][F],V=0;V<d.width;++V){for(var Y=0;Y<2*d.type;++Y)a[H++]=P[X+Y*d.width*d.height];X++}F++}break;case 1:default:throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(a.buffer)}function B(e,r){for(var n=new Uint8Array(e),t=0;0!=n[r.value+t];)t+=1;var a=(new TextDecoder).decode(n.slice(r.value,r.value+t));return r.value=r.value+t+1,a}function X(e,r){var n=e.getInt32(r.value,!0);return r.value=r.value+4,n}function H(e,r){var n=e.getUint32(r.value,!0);return r.value=r.value+4,n}function V(e,r){var n=e[r.value];return r.value=r.value+1,n}function W(e,r){var n=e.getUint8(r.value);return r.value=r.value+1,n}const Z=function(e,r){let n;return n="getBigInt64"in DataView.prototype?Number(e.getBigInt64(r.value,!0)):e.getUint32(r.value+4,!0)+Number(e.getUint32(r.value,!0)<<32),r.value+=8,n};function Y(e,r){var n=e.getFloat32(r.value,!0);return r.value+=4,n}function G(r,n){return e.DataUtils.toHalfFloat(Y(r,n))}function q(e){var r=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(r?31===r?n?NaN:1/0:Math.pow(2,r-15)*(1+n/1024):n/1024*6103515625e-14)}function j(e,r){var n=e.getUint16(r.value,!0);return r.value+=2,n}function $(e,r){return q(j(e,r))}function J(e,r,n,t,a){return"string"===t||"stringvector"===t||"iccProfile"===t?function(e,r,n){var t=(new TextDecoder).decode(new Uint8Array(e).slice(r.value,r.value+n));return r.value=r.value+n,t}(r,n,a):"chlist"===t?function(e,r,n,t){for(var a=n.value,i=[];n.value<a+t-1;){var o=B(r,n),l=X(e,n),s=W(e,n);n.value+=3;var u=X(e,n),c=X(e,n);i.push({name:o,pixelType:l,pLinear:s,xSampling:u,ySampling:c})}return n.value+=1,i}(e,r,n,a):"chromaticities"===t?function(e,r){return{redX:Y(e,r),redY:Y(e,r),greenX:Y(e,r),greenY:Y(e,r),blueX:Y(e,r),blueY:Y(e,r),whiteX:Y(e,r),whiteY:Y(e,r)}}(e,n):"compression"===t?function(e,r){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][W(e,r)]}(e,n):"box2i"===t?function(e,r){return{xMin:H(e,r),yMin:H(e,r),xMax:H(e,r),yMax:H(e,r)}}(e,n):"lineOrder"===t?function(e,r){return["INCREASING_Y"][W(e,r)]}(e,n):"float"===t?Y(e,n):"v2f"===t?function(e,r){return[Y(e,r),Y(e,r)]}(e,n):"v3f"===t?function(e,r){return[Y(e,r),Y(e,r),Y(e,r)]}(e,n):"int"===t?X(e,n):"rational"===t?function(e,r){return[X(e,r),H(e,r)]}(e,n):"timecode"===t?function(e,r){return[H(e,r),H(e,r)]}(e,n):"preview"===t?(n.value+=a,"skipped"):void(n.value+=a)}const K=new DataView(n),Q=new Uint8Array(n),ee={value:0},re=function(e,r,n){const t={};if(20000630!=e.getUint32(0,!0))throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";t.version=e.getUint8(4);const a=e.getUint8(5);t.spec={singleTile:!!(2&a),longName:!!(4&a),deepFormat:!!(8&a),multiPart:!!(16&a)},n.value=8;for(var i=!0;i;){var o=B(r,n);if(0==o)i=!1;else{var l=B(r,n),s=J(e,r,n,l,H(e,n));void 0===s?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${l}'.`):t[o]=s}}if(0!=a)throw console.error("EXRHeader:",t),"THREE.EXRLoader: provided file is currently unsupported.";return t}(K,n,ee),ne=function(r,n,t,a,i){const o={size:0,viewer:n,array:t,offset:a,width:r.dataWindow.xMax-r.dataWindow.xMin+1,height:r.dataWindow.yMax-r.dataWindow.yMin+1,channels:r.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:r.channels[0].pixelType,uncompress:null,getter:null,format:null,encoding:null};switch(r.compression){case"NO_COMPRESSION":o.lines=1,o.uncompress=N;break;case"RLE_COMPRESSION":o.lines=1,o.uncompress=D;break;case"ZIPS_COMPRESSION":o.lines=1,o.uncompress=L;break;case"ZIP_COMPRESSION":o.lines=16,o.uncompress=L;break;case"PIZ_COMPRESSION":o.lines=32,o.uncompress=_;break;case"PXR24_COMPRESSION":o.lines=16,o.uncompress=T;break;case"DWAA_COMPRESSION":o.lines=32,o.uncompress=F;break;case"DWAB_COMPRESSION":o.lines=256,o.uncompress=F;break;default:throw"EXRLoader.parse: "+r.compression+" is unsupported"}if(o.scanlineBlockSize=o.lines,1==o.type)switch(i){case e.FloatType:o.getter=$,o.inputSize=2;break;case e.HalfFloatType:o.getter=j,o.inputSize=2}else{if(2!=o.type)throw"EXRLoader.parse: unsupported pixelType "+o.type+" for "+r.compression+".";switch(i){case e.FloatType:o.getter=Y,o.inputSize=4;break;case e.HalfFloatType:o.getter=G,o.inputSize=4}}o.blockCount=(r.dataWindow.yMax+1)/o.scanlineBlockSize;for(var l=0;l<o.blockCount;l++)Z(n,a);o.outputChannels=3==o.channels?4:o.channels;const s=o.width*o.height*o.outputChannels;switch(i){case e.FloatType:o.byteArray=new Float32Array(s),o.channels<o.outputChannels&&o.byteArray.fill(1,0,s);break;case e.HalfFloatType:o.byteArray=new Uint16Array(s),o.channels<o.outputChannels&&o.byteArray.fill(15360,0,s);break;default:console.error("THREE.EXRLoader: unsupported type: ",i)}return o.bytesPerLine=o.width*o.inputSize*o.channels,4==o.outputChannels?(o.format=e.RGBAFormat,o.encoding=e.LinearEncoding):(o.format=e.RedFormat,o.encoding=e.LinearEncoding),o}(re,K,Q,ee,this.type),te={value:0},ae={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<ne.height/ne.scanlineBlockSize;e++){const r=H(K,ee);ne.size=H(K,ee),ne.lines=r+ne.scanlineBlockSize>ne.height?ne.height-r:ne.scanlineBlockSize;const n=ne.size<ne.lines*ne.bytesPerLine?ne.uncompress(ne):N(ne);ee.value+=ne.size;for(let r=0;r<ne.scanlineBlockSize;r++){const t=r+e*ne.scanlineBlockSize;if(t>=ne.height)break;for(let e=0;e<ne.channels;e++){const a=ae[re.channels[e].name];for(let i=0;i<ne.width;i++){te.value=(r*(ne.channels*ne.width)+e*ne.width+i)*ne.inputSize;const o=(ne.height-1-t)*(ne.width*ne.outputChannels)+i*ne.outputChannels+a;ne.byteArray[o]=ne.getter(n,te)}}}}return{header:re,width:ne.width,height:ne.height,data:ne.byteArray,format:ne.format,encoding:ne.encoding,type:this.type}}setDataType(e){return this.type=e,this}load(r,n,t,a){return super.load(r,(function(r,t){r.encoding=t.encoding,r.minFilter=e.LinearFilter,r.magFilter=e.LinearFilter,r.generateMipmaps=!1,r.flipY=!1,n&&n(r,t)}),t,a)}}exports.EXRLoader=n;
@@ -1272,11 +1272,18 @@ class EXRLoader extends DataTextureLoader {
1272
1272
  return Uint8;
1273
1273
  }
1274
1274
 
1275
- function parseInt64(dataView, offset) {
1276
- var int = Number(dataView.getBigInt64(offset.value, true));
1275
+ const parseInt64 = function (dataView, offset) {
1276
+ let int;
1277
+
1278
+ if ('getBigInt64' in DataView.prototype) {
1279
+ int = Number(dataView.getBigInt64(offset.value, true));
1280
+ } else {
1281
+ int = dataView.getUint32(offset.value + 4, true) + Number(dataView.getUint32(offset.value, true) << 32);
1282
+ }
1283
+
1277
1284
  offset.value += ULONG_SIZE;
1278
1285
  return int;
1279
- }
1286
+ };
1280
1287
 
1281
1288
  function parseFloat32(dataView, offset) {
1282
1289
  var float = dataView.getFloat32(offset.value, true);
@@ -1425,16 +1432,20 @@ class EXRLoader extends DataTextureLoader {
1425
1432
 
1426
1433
  function parseHeader(dataView, buffer, offset) {
1427
1434
  const EXRHeader = {};
1428
- if (dataView.getUint32(0, true) != 20000630) // magic
1435
+
1436
+ if (dataView.getUint32(0, true) != 20000630) {
1437
+ // magic
1429
1438
  throw "THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";
1430
- EXRHeader.version = dataView.getUint8(4, true);
1431
- const spec = dataView.getUint8(5, true); // fullMask
1439
+ }
1440
+
1441
+ EXRHeader.version = dataView.getUint8(4);
1442
+ const spec = dataView.getUint8(5); // fullMask
1432
1443
 
1433
1444
  EXRHeader.spec = {
1434
- singleTile: !!(spec & 1),
1435
- longName: !!(spec & 2),
1436
- deepFormat: !!(spec & 4),
1437
- multiPart: !!(spec & 8)
1445
+ singleTile: !!(spec & 2),
1446
+ longName: !!(spec & 4),
1447
+ deepFormat: !!(spec & 8),
1448
+ multiPart: !!(spec & 16)
1438
1449
  }; // start of header
1439
1450
 
1440
1451
  offset.value = 8; // start at 8 - after pre-amble
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new a(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new i(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new m(e)}))}load(t,s,n,r){const o=this;let a;a=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const i=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,a,(function(e){s(e),o.manager.itemEnd(t)}),i)}catch(e){i(e)}}),n,i)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}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(t,s,r,a){let i;const l={},c={};if("string"==typeof t)i=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===f){try{l[n.KHR_BINARY_GLTF]=new x(t)}catch(e){return void(a&&a(e))}i=l[n.KHR_BINARY_GLTF].content}else i=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(i);if(void 0===u.asset||u.asset.version[0]<2)return void(a&&a(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new Y(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new S;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new R;break;case n.KHR_MESH_QUANTIZATION:l[t]=new _;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,a)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function s(){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 n={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_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,a=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let i;const l=new e.Color(16777215);void 0!==a.color&&l.fromArray(a.color);const c=void 0!==a.range?a.range:0;switch(a.type){case"directional":i=new e.DirectionalLight(l),i.target.position.set(0,0,-1),i.add(i.target);break;case"point":i=new e.PointLight(l),i.distance=c;break;case"spot":i=new e.SpotLight(l),i.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=void 0!==a.spot.innerConeAngle?a.spot.innerConeAngle:0,a.spot.outerConeAngle=void 0!==a.spot.outerConeAngle?a.spot.outerConeAngle:Math.PI/4,i.angle=a.spot.outerConeAngle,i.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,i.target.position.set(0,0,-1),i.add(i.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return i.position.set(0,0,0),i.decay=2,void 0!==a.intensity&&(i.intensity=a.intensity),i.name=s.createUniqueName(a.name||"light_"+t),r=Promise.resolve(i),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];if(void 0!==a.clearcoatFactor&&(s.clearcoat=a.clearcoatFactor),void 0!==a.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",a.clearcoatTexture)),void 0!==a.clearcoatRoughnessFactor&&(s.clearcoatRoughness=a.clearcoatRoughnessFactor),void 0!==a.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",a.clearcoatRoughnessTexture)),void 0!==a.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",a.clearcoatNormalTexture)),void 0!==a.clearcoatNormalTexture.scale)){const t=a.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(o)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const a=r.extensions[this.name];return void 0!==a.sheenColorFactor&&s.sheenColor.fromArray(a.sheenColorFactor),void 0!==a.sheenRoughnessFactor&&(s.sheenRoughness=a.sheenRoughnessFactor),void 0!==a.sheenColorTexture&&o.push(n.assignTexture(s,"sheenColorMap",a.sheenColorTexture)),void 0!==a.sheenRoughnessTexture&&o.push(n.assignTexture(s,"sheenRoughnessMap",a.sheenRoughnessTexture)),Promise.all(o)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.thickness=void 0!==a.thicknessFactor?a.thicknessFactor:0,void 0!==a.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",a.thicknessTexture)),s.attenuationDistance=a.attenuationDistance||0;const i=a.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(i[0],i[1],i[2]),Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class h{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.specularIntensity=void 0!==a.specularFactor?a.specularFactor:1,void 0!==a.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",a.specularTexture));const i=a.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(i[0],i[1],i[2]),void 0!==a.specularColorTexture&&o.push(n.assignTexture(s,"specularColorMap",a.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class p{constructor(e){this.parser=e,this.name=n.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],o=s.images[r.source],a=t.options.ktx2Loader;if(!a){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,o,a)}}class d{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],a=n.images[o.source];let i=s.textureLoader;if(a.uri){const e=s.options.manager.getHandler(a.uri);null!==e&&(i=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,a,i);if(n.extensionsRequired&&n.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 m{constructor(e){this.name=n.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],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,a=e.byteStride,i=new ArrayBuffer(o*a),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(i),o,a,l,e.mode,e.filter),i}))}return null}}const f="glTF",g=1313821514,T=5130562;class x{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==f)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,o=new DataView(t,12);let a=0;for(;a<r;){const s=o.getUint32(a,!0);a+=4;const n=o.getUint32(a,!0);if(a+=4,n===g){const n=new Uint8Array(t,12+a,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===T){const e=12+a;this.body=t.slice(e,e+s)}a+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},i={},l={};for(const e in o){const t=k[e]||e.toLowerCase();a[t]=o[e]}for(const t in e.attributes){const n=k[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=N[r.componentType];l[n]=o,i[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=i[t];void 0!==n&&(s.normalized=n)}t(e)}),a,l)}))}))}}class R{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),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}}class v extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\ttexelSpecular = sRGBToLinear( texelSpecular );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),a=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),i={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=i,this.onBeforeCompile=function(e){for(const t in i)e.uniforms[t]=i[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",a)},Object.defineProperties(this,{specular:{get:function(){return i.specular.value},set:function(e){i.specular.value=e}},specularMap:{get:function(){return i.specularMap.value},set:function(e){i.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return i.glossiness.value},set:function(e){i.glossiness.value=e}},glossinessMap:{get:function(){return i.glossinessMap.value},set:function(e){i.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class S{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return v}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new v(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class _{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class y extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}y.prototype.beforeStart_=y.prototype.copySampleValue_,y.prototype.afterEnd_=y.prototype.copySampleValue_,y.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,a=this.valueSize,i=2*a,l=3*a,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==a;e++){const t=o[m+e+a],s=o[m+e+i]*c,n=o[d+e+a],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const A=new e.Quaternion;class E extends y{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return A.fromArray(r).normalize().toArray(r),r}}const L=0,w=1,b=2,P=3,I=4,C=5,O=6,N={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},F={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},H={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},k={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},G={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},B="OPAQUE",K="MASK",j="BLEND";function V(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}function X(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 q(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,n=t.weights.length;s<n;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,n=s.length;t<n;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function z(e){const t=e.extensions&&e.extensions[n.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+W(t.attributes):e.indices+":"+W(e.attributes)+":"+e.mode,s}function W(e){let t="";const s=Object.keys(e).sort();for(let n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";return t}function Q(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.")}}class Y{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox|Safari/.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.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,n=this.json,r=this.extensions;this.cache.removeAll(),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 o={scene:t[0][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};V(r,o,n),X(o,n),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(o)}))).then((function(){e(o)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.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 n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],r=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===t)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const o=this.options;return new Promise((function(t,n){r.load(e.LoaderUtils.resolveURL(s.uri,o.path),t,void 0,(function(){n(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,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],a=U[r.type],i=N[r.componentType],l=i.BYTES_PER_ELEMENT,c=l*a,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new i(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,a,u%h/l,p)}else d=null===o?new i(r.count*a):new i(o,u,r.count*a),m=new e.BufferAttribute(d,a,p);if(void 0!==r.sparse){const s=U.SCALAR,n=N[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new i(t[2],c,r.sparse.count*a);null!==o&&(m=new e.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*a]),a>=2&&m.setY(t,h[e*a+1]),a>=3&&m.setZ(t,h[e*a+2]),a>=4&&m.setW(t,h[e*a+3]),a>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,a=this.options,i=o.textures[t],l=(s.uri||s.bufferView)+":"+i.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1;if(void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const p=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(e.LoaderUtils.resolveURL(t,a.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,i.name&&(s.name=i.name);const n=(o.samplers||{})[i.sampler]||{};return s.magFilter=F[n.magFilter]||e.LinearFilter,s.minFilter=F[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=H[n.wrapS]||e.RepeatWrapping,s.wrapT=H[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{textures:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=p,p}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,a=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||a){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),a&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,a=r.materials[t];let i;const l={},c=a.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else{const n=a.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),i=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===a.doubleSided&&(l.side=e.DoubleSide);const h=a.alphaMode||B;if(h===j?(l.transparent=!0,l.depthWrite=!1):(l.format=e.RGBFormat,l.transparent=!1,h===K&&(l.alphaTest=void 0!==a.alphaCutoff?a.alphaCutoff:.5)),void 0!==a.normalTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",a.normalTexture)),l.normalScale=new e.Vector2(1,1),void 0!==a.normalTexture.scale)){const e=a.normalTexture.scale;l.normalScale.set(e,e)}return void 0!==a.occlusionTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",a.occlusionTexture)),void 0!==a.occlusionTexture.strength&&(l.aoMapIntensity=a.occlusionTexture.strength)),void 0!==a.emissiveFactor&&i!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(a.emissiveFactor)),void 0!==a.emissiveTexture&&i!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",a.emissiveTexture)),Promise.all(u).then((function(){let r;return r=i===v?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new i(l),a.name&&(r.name=a.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),X(r,a),s.associations.set(r,{materials:t}),a.extensions&&V(o,r,a),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function a(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Z(t,e,s)}))}const i=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=z(l),u=o[c];if(u)i.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?a(l):Z(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},i.push(t)}}return Promise.all(i)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],a=o.primitives,i=[];for(let t=0,s=a.length;t<s;t++){const s=void 0===a[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",a[t].material);i.push(s)}var l;return i.push(s.loadGeometries(a)),Promise.all(i).then((function(n){const i=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=a[n];let p;const d=i[n];if(h.mode===I||h.mode===C||h.mode===O||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===C?p.geometry=$(p.geometry,e.TriangleStripDrawMode):h.mode===O&&(p.geometry=$(p.geometry,e.TriangleFanDrawMode));else if(h.mode===w)p=new e.LineSegments(u,d);else if(h.mode===P)p=new e.Line(u,d);else if(h.mode===b)p=new e.LineLoop(u,d);else{if(h.mode!==L)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&q(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),X(p,o),h.extensions&&V(r,p,h),s.assignFinalMaterial(p),c.push(p)}for(let e=0,n=c.length;e<n;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const u=new e.Group;s.associations.set(u,{meshes:t});for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),X(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],a=[],i=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),a.push(l),i.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(a),Promise.all(i)]).then((function(n){const r=n[0],o=n[1],a=n[2],i=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=a[t],h=i[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,D[p.path]){case D.weights:d=e.NumberKeyframeTrack;break;case D.rotation:d=e.QuaternionKeyframeTrack;break;case D.position:case D.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?G[h.interpolation]:e.InterpolateLinear,g=[];D[p.path]===D.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=Q(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new d(g[t]+"."+D[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?E:y)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],a=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let i;if(i=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,i!==s[0])for(let e=0,t=s.length;e<t;e++)i.add(s[e]);if(o.name&&(i.userData.name=o.name,i.name=a),X(i,o),o.extensions&&V(n,i,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),i.applyMatrix4(t)}else void 0!==o.translation&&i.position.fromArray(o.translation),void 0!==o.rotation&&i.quaternion.fromArray(o.rotation),void 0!==o.scale&&i.scale.fromArray(o.scale);return r.associations.has(i)||r.associations.set(i,{}),r.associations.get(i).nodes=t,i}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,a=new e.Group;r.name&&(a.name=o.createUniqueName(r.name)),X(a,r),r.extensions&&V(n,a,r);const i=r.nodes||[],l=[];for(let e=0,t=i.length;e<t;e++)l.push(J(i[e],a,s,o));return Promise.all(l).then((function(){return o.associations=(t=>{const s=new Map;for(const[t,n]of o.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,n);return t.traverse((e=>{const t=o.associations.get(e);null!=t&&s.set(e,t)})),s})(a),a}))}}function J(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,a=n.length;t<a;t++){const a=n[t];if(a){r.push(a);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,a=s.length;o<a;o++){const a=s[o];t.push(J(a,e,n,r))}}return Promise.all(t)}))}function Z(t,s,n){const r=s.attributes,o=[];function a(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=k[e]||e.toLowerCase();s in t.attributes||o.push(a(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return X(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,a=t.max;if(void 0===s||void 0===a)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(a[0],a[1],a[2])),t.normalized){const e=Q(N[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const a=s.targets;if(void 0!==a){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=a.length;e<r;e++){const r=a[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,a=e.max;if(void 0!==o&&void 0!==a){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(a[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(a[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(a[2]))),e.normalized){const t=Q(N[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const i=new e.Sphere;o.getCenter(i.center),i.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=i}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],a=[];for(let i=0,l=t.length;i<l;i++){const l=t[i];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;a.push(t)}}return Promise.all([Promise.all(o),Promise.all(a)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function $(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const a=t.clone();return a.setIndex(o),a}exports.GLTFLoader=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new a(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new i(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new m(e)}))}load(t,s,n,r){const o=this;let a;a=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const i=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,a,(function(e){s(e),o.manager.itemEnd(t)}),i)}catch(e){i(e)}}),n,i)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}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(t,s,r,a){let i;const l={},c={};if("string"==typeof t)i=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===f){try{l[n.KHR_BINARY_GLTF]=new x(t)}catch(e){return void(a&&a(e))}i=l[n.KHR_BINARY_GLTF].content}else i=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(i);if(void 0===u.asset||u.asset.version[0]<2)return void(a&&a(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new Y(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new S;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new R;break;case n.KHR_MESH_QUANTIZATION:l[t]=new _;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,a)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function s(){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 n={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_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,a=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let i;const l=new e.Color(16777215);void 0!==a.color&&l.fromArray(a.color);const c=void 0!==a.range?a.range:0;switch(a.type){case"directional":i=new e.DirectionalLight(l),i.target.position.set(0,0,-1),i.add(i.target);break;case"point":i=new e.PointLight(l),i.distance=c;break;case"spot":i=new e.SpotLight(l),i.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=void 0!==a.spot.innerConeAngle?a.spot.innerConeAngle:0,a.spot.outerConeAngle=void 0!==a.spot.outerConeAngle?a.spot.outerConeAngle:Math.PI/4,i.angle=a.spot.outerConeAngle,i.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,i.target.position.set(0,0,-1),i.add(i.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return i.position.set(0,0,0),i.decay=2,void 0!==a.intensity&&(i.intensity=a.intensity),i.name=s.createUniqueName(a.name||"light_"+t),r=Promise.resolve(i),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];if(void 0!==a.clearcoatFactor&&(s.clearcoat=a.clearcoatFactor),void 0!==a.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",a.clearcoatTexture)),void 0!==a.clearcoatRoughnessFactor&&(s.clearcoatRoughness=a.clearcoatRoughnessFactor),void 0!==a.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",a.clearcoatRoughnessTexture)),void 0!==a.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",a.clearcoatNormalTexture)),void 0!==a.clearcoatNormalTexture.scale)){const t=a.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(o)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const a=r.extensions[this.name];return void 0!==a.sheenColorFactor&&s.sheenColor.fromArray(a.sheenColorFactor),void 0!==a.sheenRoughnessFactor&&(s.sheenRoughness=a.sheenRoughnessFactor),void 0!==a.sheenColorTexture&&o.push(n.assignTexture(s,"sheenColorMap",a.sheenColorTexture)),void 0!==a.sheenRoughnessTexture&&o.push(n.assignTexture(s,"sheenRoughnessMap",a.sheenRoughnessTexture)),Promise.all(o)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.thickness=void 0!==a.thicknessFactor?a.thicknessFactor:0,void 0!==a.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",a.thicknessTexture)),s.attenuationDistance=a.attenuationDistance||0;const i=a.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(i[0],i[1],i[2]),Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class h{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.specularIntensity=void 0!==a.specularFactor?a.specularFactor:1,void 0!==a.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",a.specularTexture));const i=a.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(i[0],i[1],i[2]),void 0!==a.specularColorTexture&&o.push(n.assignTexture(s,"specularColorMap",a.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class p{constructor(e){this.parser=e,this.name=n.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],o=s.images[r.source],a=t.options.ktx2Loader;if(!a){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,o,a)}}class d{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],a=n.images[o.source];let i=s.textureLoader;if(a.uri){const e=s.options.manager.getHandler(a.uri);null!==e&&(i=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,a,i);if(n.extensionsRequired&&n.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 m{constructor(e){this.name=n.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],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,a=e.byteStride,i=new ArrayBuffer(o*a),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(i),o,a,l,e.mode,e.filter),i}))}return null}}const f="glTF",g=1313821514,T=5130562;class x{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==f)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,o=new DataView(t,12);let a=0;for(;a<r;){const s=o.getUint32(a,!0);a+=4;const n=o.getUint32(a,!0);if(a+=4,n===g){const n=new Uint8Array(t,12+a,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===T){const e=12+a;this.body=t.slice(e,e+s)}a+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},i={},l={};for(const e in o){const t=k[e]||e.toLowerCase();a[t]=o[e]}for(const t in e.attributes){const n=k[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=N[r.componentType];l[n]=o,i[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=i[t];void 0!==n&&(s.normalized=n)}t(e)}),a,l)}))}))}}class R{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),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}}class v extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),a=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),i={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=i,this.onBeforeCompile=function(e){for(const t in i)e.uniforms[t]=i[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",a)},Object.defineProperties(this,{specular:{get:function(){return i.specular.value},set:function(e){i.specular.value=e}},specularMap:{get:function(){return i.specularMap.value},set:function(e){i.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return i.glossiness.value},set:function(e){i.glossiness.value=e}},glossinessMap:{get:function(){return i.glossinessMap.value},set:function(e){i.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class S{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return v}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new v(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class _{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class y extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}y.prototype.beforeStart_=y.prototype.copySampleValue_,y.prototype.afterEnd_=y.prototype.copySampleValue_,y.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,a=this.valueSize,i=2*a,l=3*a,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==a;e++){const t=o[m+e+a],s=o[m+e+i]*c,n=o[d+e+a],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const A=new e.Quaternion;class E extends y{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return A.fromArray(r).normalize().toArray(r),r}}const L=0,w=1,b=2,P=3,I=4,C=5,O=6,N={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},F={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},H={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},k={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},G={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},B="OPAQUE",K="MASK",j="BLEND";function V(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}function X(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 q(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,n=t.weights.length;s<n;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,n=s.length;t<n;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function z(e){const t=e.extensions&&e.extensions[n.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+W(t.attributes):e.indices+":"+W(e.attributes)+":"+e.mode,s}function W(e){let t="";const s=Object.keys(e).sort();for(let n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";return t}function Q(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.")}}class Y{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.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,n=this.json,r=this.extensions;this.cache.removeAll(),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 o={scene:t[0][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};V(r,o,n),X(o,n),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(o)}))).then((function(){e(o)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.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 n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],r=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===t)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const o=this.options;return new Promise((function(t,n){r.load(e.LoaderUtils.resolveURL(s.uri,o.path),t,void 0,(function(){n(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,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],a=U[r.type],i=N[r.componentType],l=i.BYTES_PER_ELEMENT,c=l*a,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new i(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,a,u%h/l,p)}else d=null===o?new i(r.count*a):new i(o,u,r.count*a),m=new e.BufferAttribute(d,a,p);if(void 0!==r.sparse){const s=U.SCALAR,n=N[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new i(t[2],c,r.sparse.count*a);null!==o&&(m=new e.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*a]),a>=2&&m.setY(t,h[e*a+1]),a>=3&&m.setZ(t,h[e*a+2]),a>=4&&m.setW(t,h[e*a+3]),a>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,a=this.options,i=o.textures[t],l=(s.uri||s.bufferView)+":"+i.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1;if(void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const p=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(e.LoaderUtils.resolveURL(t,a.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,i.name&&(s.name=i.name);const n=(o.samplers||{})[i.sampler]||{};return s.magFilter=F[n.magFilter]||e.LinearFilter,s.minFilter=F[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=H[n.wrapS]||e.RepeatWrapping,s.wrapT=H[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{textures:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=p,p}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,a=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||a){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),a&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,a=r.materials[t];let i;const l={},c=a.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else{const n=a.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),i=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===a.doubleSided&&(l.side=e.DoubleSide);const h=a.alphaMode||B;if(h===j?(l.transparent=!0,l.depthWrite=!1):(l.format=RGBFormat,l.transparent=!1,l.alphaWrite=!1,h===K&&(l.alphaTest=void 0!==a.alphaCutoff?a.alphaCutoff:.5)),void 0!==a.normalTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",a.normalTexture)),l.normalScale=new e.Vector2(1,1),void 0!==a.normalTexture.scale)){const e=a.normalTexture.scale;l.normalScale.set(e,e)}return void 0!==a.occlusionTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",a.occlusionTexture)),void 0!==a.occlusionTexture.strength&&(l.aoMapIntensity=a.occlusionTexture.strength)),void 0!==a.emissiveFactor&&i!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(a.emissiveFactor)),void 0!==a.emissiveTexture&&i!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",a.emissiveTexture)),Promise.all(u).then((function(){let r;return r=i===v?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new i(l),a.name&&(r.name=a.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),X(r,a),s.associations.set(r,{materials:t}),a.extensions&&V(o,r,a),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function a(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Z(t,e,s)}))}const i=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=z(l),u=o[c];if(u)i.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?a(l):Z(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},i.push(t)}}return Promise.all(i)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],a=o.primitives,i=[];for(let t=0,s=a.length;t<s;t++){const s=void 0===a[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",a[t].material);i.push(s)}var l;return i.push(s.loadGeometries(a)),Promise.all(i).then((function(n){const i=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=a[n];let p;const d=i[n];if(h.mode===I||h.mode===C||h.mode===O||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===C?p.geometry=$(p.geometry,e.TriangleStripDrawMode):h.mode===O&&(p.geometry=$(p.geometry,e.TriangleFanDrawMode));else if(h.mode===w)p=new e.LineSegments(u,d);else if(h.mode===P)p=new e.Line(u,d);else if(h.mode===b)p=new e.LineLoop(u,d);else{if(h.mode!==L)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&q(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),X(p,o),h.extensions&&V(r,p,h),s.assignFinalMaterial(p),c.push(p)}for(let e=0,n=c.length;e<n;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const u=new e.Group;s.associations.set(u,{meshes:t});for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),X(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],a=[],i=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),a.push(l),i.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(a),Promise.all(i)]).then((function(n){const r=n[0],o=n[1],a=n[2],i=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=a[t],h=i[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,D[p.path]){case D.weights:d=e.NumberKeyframeTrack;break;case D.rotation:d=e.QuaternionKeyframeTrack;break;case D.position:case D.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?G[h.interpolation]:e.InterpolateLinear,g=[];D[p.path]===D.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=Q(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new d(g[t]+"."+D[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?E:y)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],a=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let i;if(i=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,i!==s[0])for(let e=0,t=s.length;e<t;e++)i.add(s[e]);if(o.name&&(i.userData.name=o.name,i.name=a),X(i,o),o.extensions&&V(n,i,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),i.applyMatrix4(t)}else void 0!==o.translation&&i.position.fromArray(o.translation),void 0!==o.rotation&&i.quaternion.fromArray(o.rotation),void 0!==o.scale&&i.scale.fromArray(o.scale);return r.associations.has(i)||r.associations.set(i,{}),r.associations.get(i).nodes=t,i}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,a=new e.Group;r.name&&(a.name=o.createUniqueName(r.name)),X(a,r),r.extensions&&V(n,a,r);const i=r.nodes||[],l=[];for(let e=0,t=i.length;e<t;e++)l.push(J(i[e],a,s,o));return Promise.all(l).then((function(){return o.associations=(t=>{const s=new Map;for(const[t,n]of o.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,n);return t.traverse((e=>{const t=o.associations.get(e);null!=t&&s.set(e,t)})),s})(a),a}))}}function J(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,a=n.length;t<a;t++){const a=n[t];if(a){r.push(a);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,a=s.length;o<a;o++){const a=s[o];t.push(J(a,e,n,r))}}return Promise.all(t)}))}function Z(t,s,n){const r=s.attributes,o=[];function a(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=k[e]||e.toLowerCase();s in t.attributes||o.push(a(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return X(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,a=t.max;if(void 0===s||void 0===a)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(a[0],a[1],a[2])),t.normalized){const e=Q(N[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const a=s.targets;if(void 0!==a){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=a.length;e<r;e++){const r=a[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,a=e.max;if(void 0!==o&&void 0!==a){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(a[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(a[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(a[2]))),e.normalized){const t=Q(N[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const i=new e.Sphere;o.getCenter(i.center),i.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=i}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],a=[];for(let i=0,l=t.length;i<l;i++){const l=t[i];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;a.push(t)}}return Promise.all([Promise.all(o),Promise.all(a)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function $(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const a=t.clone();return a.setIndex(o),a}exports.GLTFLoader=t;
@@ -1,4 +1,4 @@
1
- import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2, sRGBEncoding, TangentSpaceNormalMap, Quaternion, ImageBitmapLoader, TextureLoader, InterleavedBuffer, InterleavedBufferAttribute, BufferAttribute, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, PointsMaterial, Material, LineBasicMaterial, MeshStandardMaterial, DoubleSide, RGBFormat, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, InterpolateLinear, AnimationClip, Bone, Object3D, Matrix4, Skeleton, TriangleFanDrawMode, NearestFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, InterpolateDiscrete, FrontSide, Texture, TriangleStripDrawMode, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, Box3, Vector3, Sphere, Interpolant } from 'three';
1
+ import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2, sRGBEncoding, TangentSpaceNormalMap, Quaternion, ImageBitmapLoader, TextureLoader, InterleavedBuffer, InterleavedBufferAttribute, BufferAttribute, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, PointsMaterial, Material, LineBasicMaterial, MeshStandardMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, InterpolateLinear, AnimationClip, Bone, Object3D, Matrix4, Skeleton, TriangleFanDrawMode, NearestFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, InterpolateDiscrete, FrontSide, Texture, TriangleStripDrawMode, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, Box3, Vector3, Sphere, Interpolant } from 'three';
2
2
 
3
3
  class GLTFLoader extends Loader {
4
4
  constructor(manager) {
@@ -1009,7 +1009,7 @@ class GLTFMeshStandardSGMaterial extends MeshStandardMaterial {
1009
1009
 
1010
1010
  const specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
1011
1011
  const glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
1012
- const specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' texelSpecular = sRGBToLinear( texelSpecular );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
1012
+ const specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
1013
1013
  const glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
1014
1014
  const lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
1015
1015
  const uniforms = {
@@ -1561,7 +1561,7 @@ class GLTFParser {
1561
1561
  this.nodeNamesUsed = {}; // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
1562
1562
  // expensive work of uploading a texture to the GPU off the main thread.
1563
1563
 
1564
- if (typeof createImageBitmap !== 'undefined' && /Firefox|Safari/.test(navigator.userAgent) === false) {
1564
+ if (typeof createImageBitmap !== 'undefined' && /Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent) === false) {
1565
1565
  this.textureLoader = new ImageBitmapLoader(this.options.manager);
1566
1566
  } else {
1567
1567
  this.textureLoader = new TextureLoader(this.options.manager);
@@ -2166,9 +2166,7 @@ class GLTFParser {
2166
2166
  mesh.material = material;
2167
2167
  }
2168
2168
 
2169
- getMaterialType()
2170
- /* materialIndex */
2171
- {
2169
+ getMaterialType() {
2172
2170
  return MeshStandardMaterial;
2173
2171
  }
2174
2172
  /**
@@ -2242,6 +2240,7 @@ class GLTFParser {
2242
2240
  } else {
2243
2241
  materialParams.format = RGBFormat;
2244
2242
  materialParams.transparent = false;
2243
+ materialParams.alphaWrite = false;
2245
2244
 
2246
2245
  if (alphaMode === ALPHA_MODES.MASK) {
2247
2246
  materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./RGBELoader.cjs.js");class a extends e.Loader{constructor(a){super(a),this.hdrLoader=new t.RGBELoader,this.type=e.HalfFloatType}load(t,a,r,i){Array.isArray(t)||(console.warn("THREE.HDRCubeTextureLoader signature has changed. Use .setDataType() instead."),this.setDataType(t),t=a,a=r,r=i,i=arguments[4]);const s=new e.CubeTexture;switch(s.type=this.type,s.type){case e.FloatType:case e.HalfFloatType:s.encoding=e.LinearEncoding,s.format=e.RGBFormat,s.minFilter=e.LinearFilter,s.magFilter=e.LinearFilter,s.generateMipmaps=!1}const n=this;let o=0;function d(a,r,i,d){new e.FileLoader(n.manager).setPath(n.path).setResponseType("arraybuffer").setWithCredentials(n.withCredentials).load(t[a],(function(t){o++;const i=n.hdrLoader.parse(t);if(i){if(void 0!==i.data){const t=new e.DataTexture(i.data,i.width,i.height);t.type=s.type,t.encoding=s.encoding,t.format=s.format,t.minFilter=s.minFilter,t.magFilter=s.magFilter,t.generateMipmaps=s.generateMipmaps,s.images[a]=t}6===o&&(s.needsUpdate=!0,r&&r(s))}}),i,d)}for(let e=0;e<t.length;e++)d(e,a,r,i);return s}setDataType(e){return this.type=e,this.hdrLoader.setDataType(e),this}}exports.HDRCubeTextureLoader=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./RGBELoader.cjs.js");class a extends e.Loader{constructor(a){super(a),this.hdrLoader=new t.RGBELoader,this.type=e.HalfFloatType}load(t,a,r,i){Array.isArray(t)||(console.warn("THREE.HDRCubeTextureLoader signature has changed. Use .setDataType() instead."),this.setDataType(t),t=a,a=r,r=i,i=arguments[4]);const s=new e.CubeTexture;switch(s.type=this.type,s.type){case e.FloatType:case e.HalfFloatType:s.encoding=e.LinearEncoding,s.minFilter=e.LinearFilter,s.magFilter=e.LinearFilter,s.generateMipmaps=!1}const n=this;let o=0;function d(a,r,i,d){new e.FileLoader(n.manager).setPath(n.path).setResponseType("arraybuffer").setWithCredentials(n.withCredentials).load(t[a],(function(t){o++;const i=n.hdrLoader.parse(t);if(i){if(void 0!==i.data){const t=new e.DataTexture(i.data,i.width,i.height);t.type=s.type,t.encoding=s.encoding,t.format=s.format,t.minFilter=s.minFilter,t.magFilter=s.magFilter,t.generateMipmaps=s.generateMipmaps,s.images[a]=t}6===o&&(s.needsUpdate=!0,r&&r(s))}}),i,d)}for(let e=0;e<t.length;e++)d(e,a,r,i);return s}setDataType(e){return this.type=e,this.hdrLoader.setDataType(e),this}}exports.HDRCubeTextureLoader=a;
@@ -1,4 +1,4 @@
1
- import { Loader, HalfFloatType, CubeTexture, LinearEncoding, RGBFormat, LinearFilter, FloatType, FileLoader, DataTexture } from 'three';
1
+ import { Loader, HalfFloatType, CubeTexture, LinearEncoding, LinearFilter, FloatType, FileLoader, DataTexture } from 'three';
2
2
  import { RGBELoader } from './RGBELoader.js';
3
3
 
4
4
  class HDRCubeTextureLoader extends Loader {
@@ -24,7 +24,6 @@ class HDRCubeTextureLoader extends Loader {
24
24
  switch (texture.type) {
25
25
  case FloatType:
26
26
  texture.encoding = LinearEncoding;
27
- texture.format = RGBFormat;
28
27
  texture.minFilter = LinearFilter;
29
28
  texture.magFilter = LinearFilter;
30
29
  texture.generateMipmaps = false;
@@ -32,7 +31,6 @@ class HDRCubeTextureLoader extends Loader {
32
31
 
33
32
  case HalfFloatType:
34
33
  texture.encoding = LinearEncoding;
35
- texture.format = RGBFormat;
36
34
  texture.minFilter = LinearFilter;
37
35
  texture.magFilter = LinearFilter;
38
36
  texture.generateMipmaps = false;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");const t=new e.Vector3,n=new e.Vector3;function r(e){return/primitive/i.test(e)||"Subpart"===e}class a{constructor(e,t){this.line=e,this.lineLength=e.length,this.currentCharIndex=0,this.currentChar=" ",this.lineNumber=t}seekNonSpace(){for(;this.currentCharIndex<this.lineLength;){if(this.currentChar=this.line.charAt(this.currentCharIndex)," "!==this.currentChar&&"\t"!==this.currentChar)return;this.currentCharIndex++}}getToken(){const e=this.currentCharIndex++;for(;this.currentCharIndex<this.lineLength&&(this.currentChar=this.line.charAt(this.currentCharIndex)," "!==this.currentChar&&"\t"!==this.currentChar);)this.currentCharIndex++;const t=this.currentCharIndex;return this.seekNonSpace(),this.line.substring(e,t)}getRemainingString(){return this.line.substring(this.currentCharIndex,this.lineLength)}isAtTheEnd(){return this.currentCharIndex>=this.lineLength}setToEnd(){this.currentCharIndex=this.lineLength}getLineNumberString(){return this.lineNumber>=0?" at line "+this.lineNumber:""}}function o(e,t){return e.colourCode===t.colourCode?0:e.colourCode<t.colourCode?-1:1}function i(t,n,r){t.sort(o);const a=[],i=[],s=[],l=new e.BufferGeometry;let c=null,u=0,d=0;for(let e=0,r=t.length;e<r;e++){const r=t[e],o=r.v0,h=r.v1;if(a.push(o.x,o.y,o.z,h.x,h.y,h.z),3===n){a.push(r.v2.x,r.v2.y,r.v2.z);const e=r.n0||r.faceNormal,t=r.n1||r.faceNormal,n=r.n2||r.faceNormal;i.push(e.x,e.y,e.z),i.push(t.x,t.y,t.z),i.push(n.x,n.y,n.z)}c!==r.material?(null!==c&&l.addGroup(u,d,s.length-1),s.push(r.material),c=r.material,u=e*n,d=n):d+=n}d>0&&l.addGroup(u,1/0,s.length-1),l.setAttribute("position",new e.Float32BufferAttribute(a,3)),3===n&&l.setAttribute("normal",new e.Float32BufferAttribute(i,3));let h=null;if(2===n?h=new e.LineSegments(l,s):3===n&&(h=new e.Mesh(l,s)),r){h.isConditionalLine=!0;const n=new Float32Array(3*t.length*2),r=new Float32Array(3*t.length*2),a=new Float32Array(3*t.length*2);for(let e=0,o=t.length;e<o;e++){const o=t[e],i=o.c0,s=o.c1,l=o.v0,c=o.v1,u=3*e*2;n[u+0]=i.x,n[u+1]=i.y,n[u+2]=i.z,n[u+3]=i.x,n[u+4]=i.y,n[u+5]=i.z,r[u+0]=s.x,r[u+1]=s.y,r[u+2]=s.z,r[u+3]=s.x,r[u+4]=s.y,r[u+5]=s.z,a[u+0]=c.x-l.x,a[u+1]=c.y-l.y,a[u+2]=c.z-l.z,a[u+3]=c.x-l.x,a[u+4]=c.y-l.y,a[u+5]=c.z-l.z}l.setAttribute("control0",new e.BufferAttribute(n,3,!1)),l.setAttribute("control1",new e.BufferAttribute(r,3,!1)),l.setAttribute("direction",new e.BufferAttribute(a,3,!1))}return h}class s extends e.Loader{constructor(e){super(e),this.parseScopesStack=null,this.materials=[],this.subobjectCache={},this.fileMap=null,this.setMaterials([this.parseColourMetaDirective(new a("Main_Colour CODE 16 VALUE #FF8080 EDGE #333333")),this.parseColourMetaDirective(new a("Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333"))]),this.separateObjects=!1,this.smoothNormals=!0}load(t,n,r,a){this.fileMap||(this.fileMap={});const o=this,i=new e.FileLoader(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(t,(function(e){o.processObject(e,n,null,t)}),r,a)}parse(e,t,n){this.processObject(e,n,null,t)}setMaterials(e){return this.parseScopesStack=[],this.newParseScopeLevel(e),this.getCurrentParseScope().isFromParse=!1,this.materials=e,this}setFileMap(e){return this.fileMap=e,this}newParseScopeLevel(t){const n={};if(t)for(let e=0,r=t.length;e<r;e++){const r=t[e];n[r.userData.code]=r}const r=this.getCurrentParseScope(),a={lib:n,url:null,subobjects:null,numSubobjects:0,subobjectIndex:0,inverted:!1,category:null,keywords:null,currentFileName:null,mainColourCode:r?r.mainColourCode:"16",mainEdgeColourCode:r?r.mainEdgeColourCode:"24",currentMatrix:new e.Matrix4,matrix:new e.Matrix4,isFromParse:!0,triangles:null,lineSegments:null,conditionalSegments:null,startingConstructionStep:!1};return this.parseScopesStack.push(a),a}removeScopeLevel(){return this.parseScopesStack.pop(),this}addMaterial(e){const t=this.getCurrentParseScope().lib;return t[e.userData.code]||this.materials.push(e),t[e.userData.code]=e,this}getMaterial(e){if(e.startsWith("0x2")){const t=e.substring(3);return this.parseColourMetaDirective(new a("Direct_Color_"+t+" CODE -1 VALUE #"+t+" EDGE #"+t))}for(let t=this.parseScopesStack.length-1;t>=0;t--){const n=this.parseScopesStack[t].lib[e];if(n)return n}return null}getParentParseScope(){return this.parseScopesStack.length>1?this.parseScopesStack[this.parseScopesStack.length-2]:null}getCurrentParseScope(){return this.parseScopesStack.length>0?this.parseScopesStack[this.parseScopesStack.length-1]:null}parseColourMetaDirective(t){let n=null,r=16711935,o=16711935,i=1,s=!1,l=0,c=0,u=!0,d=null;const h=t.getToken();if(!h)throw'LDrawLoader: Material name was expected after "!COLOUR tag'+t.getLineNumberString()+".";let p=null;for(;p=t.getToken(),p;)switch(p.toUpperCase()){case"CODE":n=t.getToken();break;case"VALUE":if(r=t.getToken(),r.startsWith("0x"))r="#"+r.substring(2);else if(!r.startsWith("#"))throw"LDrawLoader: Invalid colour while parsing material"+t.getLineNumberString()+".";break;case"EDGE":if(o=t.getToken(),o.startsWith("0x"))o="#"+o.substring(2);else if(!o.startsWith("#")){if(d=this.getMaterial(o),!d)throw"LDrawLoader: Invalid edge colour while parsing material"+t.getLineNumberString()+".";d=d.userData.edgeMaterial}break;case"ALPHA":if(i=parseInt(t.getToken()),isNaN(i))throw"LDrawLoader: Invalid alpha value in material definition"+t.getLineNumberString()+".";i=Math.max(0,Math.min(1,i/255)),i<1&&(s=!0);break;case"LUMINANCE":if(l=parseInt(t.getToken()),isNaN(l))throw"LDrawLoader: Invalid luminance value in material definition"+a.getLineNumberString()+".";l=Math.max(0,Math.min(1,l/255));break;case"CHROME":c=1;break;case"PEARLESCENT":c=2;break;case"RUBBER":c=3;break;case"MATTE_METALLIC":c=4;break;case"METAL":c=5;break;case"MATERIAL":t.setToEnd();break;default:throw'LDrawLoader: Unknown token "'+p+'" while parsing material'+t.getLineNumberString()+"."}let g=null;switch(c){case 0:g=new e.MeshStandardMaterial({color:r,roughness:.3,envMapIntensity:.3,metalness:0});break;case 2:const t=new e.Color(r),n=t.getHSL({h:0,s:0,l:0});n.h=(n.h+.5)%1,n.l=Math.min(1,n.l+.7*(1-n.l)),t.setHSL(n.h,n.s,n.l),g=new e.MeshPhongMaterial({color:r,specular:t,shininess:10,reflectivity:.3});break;case 1:g=new e.MeshStandardMaterial({color:r,roughness:0,metalness:1});break;case 3:g=new e.MeshStandardMaterial({color:r,roughness:.9,metalness:0}),u=!1;break;case 4:g=new e.MeshStandardMaterial({color:r,roughness:.8,metalness:.4});break;case 5:g=new e.MeshStandardMaterial({color:r,roughness:.2,metalness:.85})}return g.transparent=s,g.premultipliedAlpha=!0,g.opacity=i,g.depthWrite=!s,g.polygonOffset=!0,g.polygonOffsetFactor=1,g.userData.canHaveEnvMap=u,0!==l&&g.emissive.set(g.color).multiplyScalar(l),d||(d=new e.LineBasicMaterial({color:o,transparent:s,opacity:i,depthWrite:!s}),d.userData.code=n,d.name=h+" - Edge",d.userData.canHaveEnvMap=!1,d.userData.conditionalEdgeMaterial=new e.ShaderMaterial({vertexShader:"\n\tattribute vec3 control0;\n\tattribute vec3 control1;\n\tattribute vec3 direction;\n\tvarying float discardFlag;\n\n\t#include <common>\n\t#include <color_pars_vertex>\n\t#include <fog_pars_vertex>\n\t#include <logdepthbuf_pars_vertex>\n\t#include <clipping_planes_pars_vertex>\n\tvoid main() {\n\t\t#include <color_vertex>\n\n\t\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\tgl_Position = projectionMatrix * mvPosition;\n\n\t\t// Transform the line segment ends and control points into camera clip space\n\t\tvec4 c0 = projectionMatrix * modelViewMatrix * vec4( control0, 1.0 );\n\t\tvec4 c1 = projectionMatrix * modelViewMatrix * vec4( control1, 1.0 );\n\t\tvec4 p0 = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\tvec4 p1 = projectionMatrix * modelViewMatrix * vec4( position + direction, 1.0 );\n\n\t\tc0.xy /= c0.w;\n\t\tc1.xy /= c1.w;\n\t\tp0.xy /= p0.w;\n\t\tp1.xy /= p1.w;\n\n\t\t// Get the direction of the segment and an orthogonal vector\n\t\tvec2 dir = p1.xy - p0.xy;\n\t\tvec2 norm = vec2( -dir.y, dir.x );\n\n\t\t// Get control point directions from the line\n\t\tvec2 c0dir = c0.xy - p1.xy;\n\t\tvec2 c1dir = c1.xy - p1.xy;\n\n\t\t// If the vectors to the controls points are pointed in different directions away\n\t\t// from the line segment then the line should not be drawn.\n\t\tfloat d0 = dot( normalize( norm ), normalize( c0dir ) );\n\t\tfloat d1 = dot( normalize( norm ), normalize( c1dir ) );\n\t\tdiscardFlag = float( sign( d0 ) != sign( d1 ) );\n\n\t\t#include <logdepthbuf_vertex>\n\t\t#include <clipping_planes_vertex>\n\t\t#include <fog_vertex>\n\t}\n\t",fragmentShader:"\n\tuniform vec3 diffuse;\n\tuniform float opacity;\n\tvarying float discardFlag;\n\n\t#include <common>\n\t#include <color_pars_fragment>\n\t#include <fog_pars_fragment>\n\t#include <logdepthbuf_pars_fragment>\n\t#include <clipping_planes_pars_fragment>\n\tvoid main() {\n\n\t\tif ( discardFlag > 0.5 ) discard;\n\n\t\t#include <clipping_planes_fragment>\n\t\tvec3 outgoingLight = vec3( 0.0 );\n\t\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t\t#include <logdepthbuf_fragment>\n\t\t#include <color_fragment>\n\t\toutgoingLight = diffuseColor.rgb; // simple shader\n\t\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t\t#include <tonemapping_fragment>\n\t\t#include <encodings_fragment>\n\t\t#include <fog_fragment>\n\t\t#include <premultiplied_alpha_fragment>\n\t}\n\t",uniforms:e.UniformsUtils.merge([e.UniformsLib.fog,{diffuse:{value:new e.Color(o)},opacity:{value:i}}]),fog:!0,transparent:s,depthWrite:!s}),d.userData.conditionalEdgeMaterial.userData.canHaveEnvMap=!1),g.userData.code=n,g.name=h,g.userData.edgeMaterial=d,g}objectParse(o){const i=this.getParentParseScope(),s=i.mainColourCode,l=i.mainEdgeColourCode,c=this.getCurrentParseScope();let u,d,h;const p=[];let g=null,m=null;-1!==o.indexOf("\r\n")&&(o=o.replace(/\r\n/g,"\n"));const f=o.split("\n"),b=f.length;let v=!1,C=null,S=null,x=!1,w=!0,k=!1,M=!0,L="",y=!1;const D=this;function N(e,t){let n=e.getToken();t||"16"!==n||(n=s),t&&"24"===n&&(n=l);const r=D.getMaterial(n);if(!r)throw'LDrawLoader: Unknown colour code "'+n+'" is used'+e.getLineNumberString()+" but it was not defined previously.";return r}function E(t){const n=new e.Vector3(parseFloat(t.getToken()),parseFloat(t.getToken()),parseFloat(t.getToken()));return D.separateObjects||n.applyMatrix4(c.currentMatrix),n}for(let o=0;o<b;o++){const s=f[o];if(0===s.length)continue;if(v){s.startsWith("0 FILE ")?(this.subobjectCache[C.toLowerCase()]=S,C=s.substring(7),S=""):S+=s+"\n";continue}const l=new a(s,o+1);if(l.seekNonSpace(),l.isAtTheEnd())continue;const b=l.getToken();let F,T,j,_,O,A,I,P,V,z;switch(b){case"0":const a=l.getToken();if(a)switch(a){case"!LDRAW_ORG":L=l.getToken(),c.triangles=[],c.lineSegments=[],c.conditionalSegments=[],c.type=L;(!i.isFromParse||D.separateObjects&&!r(L))&&(c.groupObject=new e.Group,c.groupObject.userData.startingConstructionStep=c.startingConstructionStep),c.matrix.determinant()<0&&(D.separateObjects&&r(L)||!D.separateObjects)&&(c.inverted=!c.inverted),u=c.triangles,d=c.lineSegments,h=c.conditionalSegments;break;case"!COLOUR":F=this.parseColourMetaDirective(l),F?this.addMaterial(F):console.warn("LDrawLoader: Error parsing material"+l.getLineNumberString());break;case"!CATEGORY":g=l.getToken();break;case"!KEYWORDS":const t=l.getRemainingString().split(",");t.length>0&&(m||(m=[]),t.forEach((function(e){m.push(e.trim())})));break;case"FILE":o>0&&(v=!0,C=l.getRemainingString(),S="",x=!1,w=!0);break;case"BFC":for(;!l.isAtTheEnd();){const e=l.getToken();switch(e){case"CERTIFY":case"NOCERTIFY":x="CERTIFY"===e,w=!0;break;case"CW":case"CCW":w="CCW"===e;break;case"INVERTNEXT":k=!0;break;case"CLIP":case"NOCLIP":M="CLIP"===e;break;default:console.warn('THREE.LDrawLoader: BFC directive "'+e+'" is unknown.')}}break;case"STEP":y=!0}break;case"1":F=N(l);const s=parseFloat(l.getToken()),f=parseFloat(l.getToken()),R=parseFloat(l.getToken()),W=parseFloat(l.getToken()),$=parseFloat(l.getToken()),U=parseFloat(l.getToken()),G=parseFloat(l.getToken()),H=parseFloat(l.getToken()),B=parseFloat(l.getToken()),q=parseFloat(l.getToken()),Y=parseFloat(l.getToken()),K=parseFloat(l.getToken()),X=(new e.Matrix4).set(W,$,U,s,G,H,B,f,q,Y,K,R,0,0,0,1);let J=l.getRemainingString().trim().replace(/\\/g,"/");D.fileMap[J]?J=D.fileMap[J]:J.startsWith("s/")?J="parts/"+J:J.startsWith("48/")&&(J="p/"+J),p.push({material:F,matrix:X,fileName:J,originalFileName:J,locationState:0,url:null,triedLowerCase:!1,inverted:k!==c.inverted,startingConstructionStep:y}),k=!1;break;case"2":F=N(l,!0),T={material:F.userData.edgeMaterial,colourCode:F.userData.code,v0:E(l),v1:E(l)},d.push(T);break;case"5":F=N(l,!0),T={material:F.userData.edgeMaterial.userData.conditionalEdgeMaterial,colourCode:F.userData.code,v0:E(l),v1:E(l),c0:E(l),c1:E(l)},h.push(T);break;case"3":F=N(l),j=c.inverted,_=w!==j,O=!x||!M,!0===_?(A=E(l),I=E(l),P=E(l)):(P=E(l),I=E(l),A=E(l)),t.subVectors(I,A),n.subVectors(P,I),z=(new e.Vector3).crossVectors(t,n).normalize(),u.push({material:F,colourCode:F.userData.code,v0:A,v1:I,v2:P,faceNormal:z,n0:null,n1:null,n2:null}),!0===O&&u.push({material:F,colourCode:F.userData.code,v0:A,v1:P,v2:I,faceNormal:z,n0:null,n1:null,n2:null});break;case"4":F=N(l),j=c.inverted,_=w!==j,O=!x||!M,!0===_?(A=E(l),I=E(l),P=E(l),V=E(l)):(V=E(l),P=E(l),I=E(l),A=E(l)),t.subVectors(I,A),n.subVectors(P,I),z=(new e.Vector3).crossVectors(t,n).normalize(),u.push({material:F,colourCode:F.userData.code,v0:A,v1:I,v2:P,faceNormal:z,n0:null,n1:null,n2:null}),u.push({material:F,colourCode:F.userData.code,v0:A,v1:P,v2:V,faceNormal:z,n0:null,n1:null,n2:null}),!0===O&&(u.push({material:F,colourCode:F.userData.code,v0:A,v1:P,v2:I,faceNormal:z,n0:null,n1:null,n2:null}),u.push({material:F,colourCode:F.userData.code,v0:A,v1:V,v2:P,faceNormal:z,n0:null,n1:null,n2:null}));break;default:throw'LDrawLoader: Unknown line type "'+b+'"'+l.getLineNumberString()+"."}}v&&(this.subobjectCache[C.toLowerCase()]=S),c.category=g,c.keywords=m,c.subobjects=p,c.numSubobjects=p.length,c.subobjectIndex=0}computeConstructionSteps(e){let t=0;e.traverse((e=>{e.isGroup&&(e.userData.startingConstructionStep&&t++,e.userData.constructionStep=t)})),e.userData.numConstructionSteps=t+1}processObject(a,o,s,l){const c=this,u=c.newParseScopeLevel();u.url=l;const d=c.getParentParseScope();s&&(u.currentMatrix.multiplyMatrices(d.currentMatrix,s.matrix),u.matrix.copy(s.matrix),u.inverted=s.inverted,u.startingConstructionStep=s.startingConstructionStep);let h=d.currentFileName;null!==h&&(h=d.currentFileName.toLowerCase()),void 0===c.subobjectCache[h]&&(c.subobjectCache[h]=a),c.objectParse(a);let p=0;function g(){if(p++,p===u.subobjects.length+1)!function(){c.smoothNormals&&"Part"===u.type&&function(e,t){function n(e){return`${~~(100*e.x)},${~~(100*e.y)},${~~(100*e.z)}`}function r(e,t){return`${n(e)}_${n(t)}`}const a=new Set,o={},i={},s=[];for(let e=0,n=t.length;e<n;e++){const n=t[e],o=n.v0,i=n.v1;a.add(r(o,i)),a.add(r(i,o))}for(let t=0,n=e.length;t<n;t++){const n=e[t];for(let e=0,t=3;e<t;e++){const t=(e+1)%3,s=r(n[`v${e}`],n[`v${t}`]);a.has(s)||(o[s]=n,i[s]=n)}}for(;;){const e=Object.keys(o);if(0===e.length)break;let t=0;const n=[i[e[0]]];for(;t<n.length;){const e=n[t];t++;const a=e.faceNormal;null===e.n0&&(e.n0=a.clone(),s.push(e.n0)),null===e.n1&&(e.n1=a.clone(),s.push(e.n1)),null===e.n2&&(e.n2=a.clone(),s.push(e.n2));for(let t=0,a=3;t<a;t++){const a=t,s=(t+1)%3,l=e[`v${a}`],c=e[`v${s}`];delete o[r(l,c)];const u=r(c,l),d=i[u];if(d){if(Math.abs(d.faceNormal.dot(e.faceNormal))<.25)continue;u in o&&(n.push(d),delete o[u]);for(let t=0,n=3;t<n;t++){const n=t,o=(t+1)%3;if(r(d[`v${n}`],d[`v${o}`])===u){if(null===d[`n${n}`]){const t=e[`n${s}`];d[`n${n}`]=t,t.add(d.faceNormal)}if(null===d[`n${o}`]){const t=e[`n${a}`];d[`n${o}`]=t,t.add(d.faceNormal)}break}}}}}}for(let e=0,t=s.length;e<t;e++)s[e].normalize()}(u.triangles,u.lineSegments);const e=!d.isFromParse;if(c.separateObjects&&!r(u.type)||e){const e=u.groupObject;u.triangles.length>0&&e.add(i(u.triangles,3)),u.lineSegments.length>0&&e.add(i(u.lineSegments,2)),u.conditionalSegments.length>0&&e.add(i(u.conditionalSegments,2,!0)),d.groupObject&&(e.name=u.fileName,e.userData.category=u.category,e.userData.keywords=u.keywords,u.matrix.decompose(e.position,e.quaternion,e.scale),d.groupObject.add(e))}else{const e=c.separateObjects,r=d.lineSegments,a=d.conditionalSegments,o=d.triangles,i=u.lineSegments,s=u.conditionalSegments,l=u.triangles;for(let t=0,n=i.length;t<n;t++){const n=i[t];e&&(n.v0.applyMatrix4(u.matrix),n.v1.applyMatrix4(u.matrix)),r.push(n)}for(let t=0,n=s.length;t<n;t++){const n=s[t];e&&(n.v0.applyMatrix4(u.matrix),n.v1.applyMatrix4(u.matrix),n.c0.applyMatrix4(u.matrix),n.c1.applyMatrix4(u.matrix)),a.push(n)}for(let r=0,a=l.length;r<a;r++){const a=l[r];e&&(a.v0=a.v0.clone().applyMatrix4(u.matrix),a.v1=a.v1.clone().applyMatrix4(u.matrix),a.v2=a.v2.clone().applyMatrix4(u.matrix),t.subVectors(a.v1,a.v0),n.subVectors(a.v2,a.v1),a.faceNormal.crossVectors(t,n).normalize()),o.push(a)}}c.removeScopeLevel(),d.isFromParse||c.computeConstructionSteps(u.groupObject);o&&o(u.groupObject)}();else{const e=u.subobjects[u.subobjectIndex];Promise.resolve().then((function(){m(e)})),u.subobjectIndex++}}function m(t){u.mainColourCode=t.material.userData.code,u.mainEdgeColourCode=t.material.userData.edgeMaterial.userData.code,u.currentFileName=t.originalFileName;const n=c.subobjectCache[t.originalFileName.toLowerCase()];if(n)return void c.processObject(n,(function(e){f(e,t),g()}),t,l);let r=t.fileName,a=6;switch(t.locationState){case 0:a=t.locationState+1;break;case 1:r="parts/"+r,a=t.locationState+1;break;case 2:r="p/"+r,a=t.locationState+1;break;case 3:r="models/"+r,a=t.locationState+1;break;case 4:r=l.substring(0,l.lastIndexOf("/")+1)+r,a=t.locationState+1;break;case 5:t.triedLowerCase?a=6:(t.fileName=t.fileName.toLowerCase(),r=t.fileName,t.triedLowerCase=!0,a=0);break;case 6:return void console.warn('LDrawLoader: Subobject "'+t.originalFileName+'" could not be found.')}t.locationState=a,t.url=r;const o=new e.FileLoader(c.manager);o.setPath(c.path),o.setRequestHeader(c.requestHeader),o.setWithCredentials(c.withCredentials),o.load(r,(function(e){c.processObject(e,(function(e){f(e,t),g()}),t,l)}),void 0,(function(e){!function(e,t){m(t)}(0,t)}),t)}function f(e,t){null!==e?c.fileMap[t.originalFileName]=t.url:m(t)}g()}}exports.LDrawLoader=s;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");const t=new e.Vector3,r=new e.Vector3;class a extends e.ShaderMaterial{constructor(t){super({uniforms:e.UniformsUtils.merge([e.UniformsLib.fog,{diffuse:{value:new e.Color},opacity:{value:1}}]),vertexShader:"\n attribute vec3 control0;\n attribute vec3 control1;\n attribute vec3 direction;\n varying float discardFlag;\n\n #include <common>\n #include <color_pars_vertex>\n #include <fog_pars_vertex>\n #include <logdepthbuf_pars_vertex>\n #include <clipping_planes_pars_vertex>\n\n void main() {\n #include <color_vertex>\n\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n gl_Position = projectionMatrix * mvPosition;\n\n // Transform the line segment ends and control points into camera clip space\n vec4 c0 = projectionMatrix * modelViewMatrix * vec4(control0, 1.0);\n vec4 c1 = projectionMatrix * modelViewMatrix * vec4(control1, 1.0);\n vec4 p0 = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n vec4 p1 = projectionMatrix * modelViewMatrix * vec4(position + direction, 1.0);\n\n c0.xy /= c0.w;\n c1.xy /= c1.w;\n p0.xy /= p0.w;\n p1.xy /= p1.w;\n\n // Get the direction of the segment and an orthogonal vector\n vec2 dir = p1.xy - p0.xy;\n vec2 norm = vec2(-dir.y, dir.x);\n\n // Get control point directions from the line\n vec2 c0dir = c0.xy - p1.xy;\n vec2 c1dir = c1.xy - p1.xy;\n\n // If the vectors to the controls points are pointed in different directions away\n // from the line segment then the line should not be drawn.\n float d0 = dot(normalize(norm), normalize(c0dir));\n float d1 = dot(normalize(norm), normalize(c1dir));\n discardFlag = float(sign(d0) != sign(d1));\n\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <fog_vertex>\n }\n ",fragmentShader:"\n uniform vec3 diffuse;\n uniform float opacity;\n varying float discardFlag;\n\n #include <common>\n #include <color_pars_fragment>\n #include <fog_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n #include <clipping_planes_pars_fragment>\n\n void main() {\n if (discardFlag > 0.5) discard;\n\n #include <clipping_planes_fragment>\n vec3 outgoingLight = vec3(0.0);\n vec4 diffuseColor = vec4(diffuse, opacity);\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb; // simple shader\n gl_FragColor = vec4(outgoingLight, diffuseColor.a);\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n }\n "}),Object.defineProperties(this,{opacity:{get:function(){return this.uniforms.opacity.value},set:function(e){this.uniforms.opacity.value=e}},color:{get:function(){return this.uniforms.diffuse.value}}}),this.setValues(t),this.isLDrawConditionalLineMaterial=!0}}class n extends e.LineSegments{constructor(e,t){super(e,t),this.isConditionalLine=!0}}const o=new e.Ray;function i(e){return"Part"===e||"Unofficial_Part"===e}class s{constructor(e,t){this.line=e,this.lineLength=e.length,this.currentCharIndex=0,this.currentChar=" ",this.lineNumber=t}seekNonSpace(){for(;this.currentCharIndex<this.lineLength;){if(this.currentChar=this.line.charAt(this.currentCharIndex)," "!==this.currentChar&&"\t"!==this.currentChar)return;this.currentCharIndex++}}getToken(){const e=this.currentCharIndex++;for(;this.currentCharIndex<this.lineLength&&(this.currentChar=this.line.charAt(this.currentCharIndex)," "!==this.currentChar&&"\t"!==this.currentChar);)this.currentCharIndex++;const t=this.currentCharIndex;return this.seekNonSpace(),this.line.substring(e,t)}getVector(){return new e.Vector3(parseFloat(this.getToken()),parseFloat(this.getToken()),parseFloat(this.getToken()))}getRemainingString(){return this.line.substring(this.currentCharIndex,this.lineLength)}isAtTheEnd(){return this.currentCharIndex>=this.lineLength}setToEnd(){this.currentCharIndex=this.lineLength}getLineNumberString(){return this.lineNumber>=0?" at line "+this.lineNumber:""}}class l{constructor(e){this.loader=e,this._cache={}}cloneResult(e){const t={};return t.faces=e.faces.map((e=>({colorCode:e.colorCode,material:e.material,vertices:e.vertices.map((e=>e.clone())),normals:e.normals.map((()=>null)),faceNormal:null}))),t.conditionalSegments=e.conditionalSegments.map((e=>({colorCode:e.colorCode,material:e.material,vertices:e.vertices.map((e=>e.clone())),controlPoints:e.controlPoints.map((e=>e.clone()))}))),t.lineSegments=e.lineSegments.map((e=>({colorCode:e.colorCode,material:e.material,vertices:e.vertices.map((e=>e.clone()))}))),t.type=e.type,t.category=e.category,t.keywords=e.keywords,t.subobjects=e.subobjects,t.totalFaces=e.totalFaces,t.startingConstructionStep=e.startingConstructionStep,t.materials=e.materials,t.group=null,t}async fetchData(t){let r=!1,a=0;for(;6!==a;){let n=t;switch(a){case 0:a+=1;break;case 1:n="parts/"+n,a+=1;break;case 2:n="p/"+n,a+=1;break;case 3:n="models/"+n,a+=1;break;case 4:n=t.substring(0,t.lastIndexOf("/")+1)+n,a+=1;break;case 5:r?a=6:(n=t=t.toLowerCase(),r=!0,a=0)}const o=this.loader,i=new e.FileLoader(o.manager);i.setPath(o.partsLibraryPath),i.setRequestHeader(o.requestHeader),i.setWithCredentials(o.withCredentials);try{return await i.loadAsync(n)}catch{continue}}throw new Error('LDrawLoader: Subobject "'+t+'" could not be loaded.')}parse(t,r=null){const a=this.loader,n=[],o=[],i=[],l=[],c={},h=e=>c[e]||null;let u="Model",d=null,g=null,p=0;-1!==t.indexOf("\r\n")&&(t=t.replace(/\r\n/g,"\n"));const m=t.split("\n"),f=m.length;let C=!1,w=null,M=null,b=!1,y=!0,L=!1,v=!0,k=!1;for(let t=0;t<f;t++){const r=m[t];if(0===r.length)continue;if(C){r.startsWith("0 FILE ")?(this.setData(w,M),w=r.substring(7),M=""):M+=r+"\n";continue}const f=new s(r,t+1);if(f.seekNonSpace(),f.isAtTheEnd())continue;const x=f.getToken();let S,D,E,T,_,N,V,F,A,I,P;switch(x){case"0":const r=f.getToken();if(r)switch(r){case"!LDRAW_ORG":u=f.getToken();break;case"!COLOUR":S=a.parseColorMetaDirective(f),S?c[S.userData.code]=S:console.warn("LDrawLoader: Error parsing material"+f.getLineNumberString());break;case"!CATEGORY":d=f.getToken();break;case"!KEYWORDS":const e=f.getRemainingString().split(",");e.length>0&&(g||(g=[]),e.forEach((function(e){g.push(e.trim())})));break;case"FILE":t>0&&(C=!0,w=f.getRemainingString(),M="",b=!1,y=!0);break;case"BFC":for(;!f.isAtTheEnd();){const e=f.getToken();switch(e){case"CERTIFY":case"NOCERTIFY":b="CERTIFY"===e,y=!0;break;case"CW":case"CCW":y="CCW"===e;break;case"INVERTNEXT":L=!0;break;case"CLIP":case"NOCLIP":v="CLIP"===e;break;default:console.warn('THREE.LDrawLoader: BFC directive "'+e+'" is unknown.')}}break;case"STEP":k=!0}break;case"1":D=f.getToken(),S=h(D);const s=parseFloat(f.getToken()),m=parseFloat(f.getToken()),R=parseFloat(f.getToken()),O=parseFloat(f.getToken()),z=parseFloat(f.getToken()),W=parseFloat(f.getToken()),U=parseFloat(f.getToken()),G=parseFloat(f.getToken()),j=parseFloat(f.getToken()),B=parseFloat(f.getToken()),H=parseFloat(f.getToken()),q=parseFloat(f.getToken()),$=(new e.Matrix4).set(O,z,W,s,U,G,j,m,B,H,q,R,0,0,0,1);let Y=f.getRemainingString().trim().replace(/\\/g,"/");a.fileMap[Y]?Y=a.fileMap[Y]:Y.startsWith("s/")?Y="parts/"+Y:Y.startsWith("48/")&&(Y="p/"+Y),l.push({material:S,colorCode:D,matrix:$,fileName:Y,inverted:L,startingConstructionStep:k}),L=!1;break;case"2":D=f.getToken(),S=h(D),N=f.getVector(),V=f.getVector(),E={material:S,colorCode:D,vertices:[N,V]},o.push(E);break;case"5":D=f.getToken(),S=h(D),N=f.getVector(),V=f.getVector(),I=f.getVector(),P=f.getVector(),E={material:S,colorCode:D,vertices:[N,V],controlPoints:[I,P]},i.push(E);break;case"3":D=f.getToken(),S=h(D),T=y,_=!b||!v,!0===T?(N=f.getVector(),V=f.getVector(),F=f.getVector()):(F=f.getVector(),V=f.getVector(),N=f.getVector()),n.push({material:S,colorCode:D,faceNormal:null,vertices:[N,V,F],normals:[null,null,null]}),p++,!0===_&&(n.push({material:S,colorCode:D,faceNormal:null,vertices:[F,V,N],normals:[null,null,null]}),p++);break;case"4":D=f.getToken(),S=h(D),T=y,_=!b||!v,!0===T?(N=f.getVector(),V=f.getVector(),F=f.getVector(),A=f.getVector()):(A=f.getVector(),F=f.getVector(),V=f.getVector(),N=f.getVector()),n.push({material:S,colorCode:D,faceNormal:null,vertices:[N,V,F,A],normals:[null,null,null,null]}),p+=2,!0===_&&(n.push({material:S,colorCode:D,faceNormal:null,vertices:[A,F,V,N],normals:[null,null,null,null]}),p+=2);break;default:throw new Error('LDrawLoader: Unknown line type "'+x+'"'+f.getLineNumberString()+".")}}return C&&this.setData(w,M),{faces:n,conditionalSegments:i,lineSegments:o,type:u,category:d,keywords:g,subobjects:l,totalFaces:p,startingConstructionStep:k,materials:c,fileName:r,group:null}}getData(e,t=!0){const r=e.toLowerCase(),a=this._cache[r];return null===a||a instanceof Promise?null:t?this.cloneResult(a):a}async ensureDataLoaded(e){const t=e.toLowerCase();t in this._cache||(this._cache[t]=this.fetchData(e).then((r=>{const a=this.parse(r,e);return this._cache[t]=a,a}))),await this._cache[t]}setData(e,t){const r=e.toLowerCase();this._cache[r]=this.parse(t,e)}}function c(e,t,r,a){return(!a&&"16"===e||a&&"24"===e)&&(e=t),r[e]||null}class h{constructor(e){this.loader=e,this.parseCache=new l(e),this._cache={}}async processIntoMesh(a){const n=this.loader,i=this.parseCache,s=new Set,l=async(t,r=null)=>{const a=t.subobjects,o=[];for(let e=0,t=a.length;e<t;e++){const t=a[e],r=i.ensureDataLoaded(t.fileName).then((()=>{const e=i.getData(t.fileName,!1);return r=e.type,/primitive/i.test(r)||"Subpart"===r?l(i.getData(t.fileName),t):this.loadModel(t.fileName).catch((e=>(console.warn(e),null)));var r}));o.push(r)}const h=new e.Group;h.userData.category=t.category,h.userData.keywords=t.keywords,t.group=h;const u=await Promise.all(o);for(let e=0,r=u.length;e<r;e++){const r=t.subobjects[e],a=u[e];if(null===a)continue;if(a.isGroup){const e=a;r.matrix.decompose(e.position,e.quaternion,e.scale),e.userData.startingConstructionStep=r.startingConstructionStep,e.name=r.fileName,n.applyMaterialsToMesh(e,r.colorCode,t.materials),h.add(e);continue}a.group.children.length&&h.add(a.group);const o=t.lineSegments,i=t.conditionalSegments,l=t.faces,d=a.lineSegments,g=a.conditionalSegments,p=a.faces,m=r.matrix,f=r.inverted,C=m.determinant()<0,w=r.colorCode,M="16"===w?"24":w;for(let e=0,r=d.length;e<r;e++){const r=d[e],a=r.vertices;a[0].applyMatrix4(m),a[1].applyMatrix4(m),r.colorCode="24"===r.colorCode?M:r.colorCode,r.material=r.material||c(r.colorCode,r.colorCode,t.materials,!0),o.push(r)}for(let e=0,r=g.length;e<r;e++){const r=g[e],a=r.vertices,n=r.controlPoints;a[0].applyMatrix4(m),a[1].applyMatrix4(m),n[0].applyMatrix4(m),n[1].applyMatrix4(m),r.colorCode="24"===r.colorCode?M:r.colorCode,r.material=r.material||c(r.colorCode,r.colorCode,t.materials,!0),i.push(r)}for(let e=0,r=p.length;e<r;e++){const r=p[e],a=r.vertices;for(let e=0,t=a.length;e<t;e++)a[e].applyMatrix4(m);r.colorCode="16"===r.colorCode?w:r.colorCode,r.material=r.material||c(r.colorCode,w,t.materials,!1),s.add(r.colorCode),C!==f&&a.reverse(),l.push(r)}t.totalFaces+=a.totalFaces}return r&&n.applyMaterialsToMesh(h,r.colorCode,t.materials),t};for(let e=0,t=a.faces;e<t;e++)s.add(a.faces[e].colorCode);if(await l(a),n.smoothNormals){const n=s.size>1;!function(a){for(let n=0,o=a.length;n<o;n++){const o=a[n],i=o.vertices,s=i[0],l=i[1],c=i[2];t.subVectors(l,s),r.subVectors(c,l),o.faceNormal=(new e.Vector3).crossVectors(t,r).normalize()}}(a.faces),function(t,r,a=!1){const n=100*(1+1e-10);function i(e){return`${~~(e.x*n)},${~~(e.y*n)},${~~(e.z*n)}`}function s(e,t){return`${i(e)}_${i(t)}`}function l(e,t,r){r.direction.subVectors(t,e).normalize();const a=e.dot(r.direction);return r.origin.copy(e).addScaledVector(r.direction,-a),r}function c(e){return s(e.origin,e.direction)}const h=new Set,u=new Map,d={},g=[];for(let t=0,n=r.length;t<n;t++){const n=r[t].vertices,o=n[0],i=n[1];if(h.add(s(o,i)),h.add(s(i,o)),a){const t=l(o,i,new e.Ray),r=c(t);if(!u.has(r)){l(i,o,t);const e=c(t),a={ray:t,distances:[]};u.set(r,a),u.set(e,a)}const a=u.get(r);let n=a.ray.direction.dot(o),s=a.ray.direction.dot(i);n>s&&([n,s]=[s,n]),a.distances.push(n,s)}}for(let e=0,r=t.length;e<r;e++){const r=t[e],n=r.vertices,i=n.length;for(let e=0;e<i;e++){const t=e,g=(e+1)%i,p=n[t],m=n[g],f=s(p,m);if(h.has(f))continue;if(a){l(p,m,o);const e=c(o);if(u.has(e)){const t=u.get(e),{ray:r,distances:a}=t;let n=r.direction.dot(p),o=r.direction.dot(m);n>o&&([n,o]=[o,n]);let i=!1;for(let e=0,t=a.length;e<t;e+=2)if(n>=a[e]&&o<=a[e+1]){i=!0;break}if(i)continue}}const C={index:t,tri:r};d[f]=C}}for(;;){let t=null;for(const e in d){t=d[e];break}if(null===t)break;const r=[t];for(;r.length>0;){const t=r.pop().tri,a=t.vertices,n=t.normals,o=t.faceNormal,i=a.length;for(let l=0;l<i;l++){const c=l,h=(l+1)%i,u=a[c],p=a[h];delete d[s(u,p)];const m=s(p,u),f=d[m];if(f){const a=f.tri,i=f.index,s=a.normals,l=s.length,u=a.faceNormal;if(Math.abs(a.faceNormal.dot(t.faceNormal))<.25)continue;m in d&&(r.push(f),delete d[m]);const p=(i+1)%l;n[c]&&s[p]&&n[c]!==s[p]&&(s[p].norm.add(n[c].norm),n[c].norm=s[p].norm);let C=n[c]||s[p];null===C&&(C={norm:new e.Vector3},g.push(C.norm)),null===n[c]&&(n[c]=C,C.norm.add(o)),null===s[p]&&(s[p]=C,C.norm.add(u)),n[h]&&s[i]&&n[h]!==s[i]&&(s[i].norm.add(n[h].norm),n[h].norm=s[i].norm);let w=n[h]||s[i];null===w&&(w={norm:new e.Vector3},g.push(w.norm)),null===n[h]&&(n[h]=w,w.norm.add(o)),null===s[i]&&(s[i]=w,w.norm.add(u))}}}}for(let e=0,t=g.length;e<t;e++)g[e].normalize()}(a.faces,a.lineSegments,n)}const h=a.group;return a.faces.length>0&&h.add(d(a.faces,3,!1,a.totalFaces)),a.lineSegments.length>0&&h.add(d(a.lineSegments,2)),a.conditionalSegments.length>0&&h.add(d(a.conditionalSegments,2,!0)),h}hasCachedModel(e){return null!==e&&e.toLowerCase()in this._cache}async getCachedModel(e){if(null!==e&&this.hasCachedModel(e)){const t=e.toLowerCase();return(await this._cache[t]).clone()}return null}async loadModel(e){const t=this.parseCache,r=e.toLowerCase();if(this.hasCachedModel(e))return this.getCachedModel(e);{await t.ensureDataLoaded(e);const a=t.getData(e),n=this.processIntoMesh(a);if(this.hasCachedModel(e))return this.getCachedModel(e);i(a.type)&&(this._cache[r]=n);return(await n).clone()}}async parseModel(e){const t=this.parseCache.parse(e);return i(t.type)&&this.hasCachedModel(t.fileName)?this.getCachedModel(t.fileName):this.processIntoMesh(t)}}function u(e,t){return e.colorCode===t.colorCode?0:e.colorCode<t.colorCode?-1:1}function d(a,o,i=!1,s=null){a.sort(u),null===s&&(s=a.length);const l=new Float32Array(o*s*3),c=3===o?new Float32Array(o*s*3):null,h=[],d=new Array(6),g=new e.BufferGeometry;let p=null,m=0,f=0,C=0;for(let n=0,s=a.length;n<s;n++){const s=a[n];let u=s.vertices;4===u.length&&(d[0]=u[0],d[1]=u[1],d[2]=u[2],d[3]=u[0],d[4]=u[2],d[5]=u[3],u=d);for(let e=0,t=u.length;e<t;e++){const t=u[e],r=C+3*e;l[r+0]=t.x,l[r+1]=t.y,l[r+2]=t.z}if(3===o){if(!s.faceNormal){const a=u[0],n=u[1],o=u[2];t.subVectors(n,a),r.subVectors(o,n),s.faceNormal=(new e.Vector3).crossVectors(t,r).normalize()}let a=s.normals;4===a.length&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[0],d[4]=a[2],d[5]=a[3],a=d);for(let e=0,t=a.length;e<t;e++){let t=s.faceNormal;a[e]&&(t=a[e].norm);const r=C+3*e;c[r+0]=t.x,c[r+1]=t.y,c[r+2]=t.z}}if(p!==s.colorCode){null!==p&&g.addGroup(m,f,h.length-1);const e=s.material;null!==e?3===o?h.push(e):2===o&&(null!==e?i?h.push(e.userData.edgeMaterial.userData.conditionalEdgeMaterial):h.push(e.userData.edgeMaterial):h.push(null)):h.push(s.colorCode),p=s.colorCode,m=C/3,f=u.length}else f+=u.length;C+=3*u.length}f>0&&g.addGroup(m,1/0,h.length-1),g.setAttribute("position",new e.BufferAttribute(l,3)),null!==c&&g.setAttribute("normal",new e.BufferAttribute(c,3));let w=null;if(2===o?w=i?new n(g,1===h.length?h[0]:h):new e.LineSegments(g,1===h.length?h[0]:h):3===o&&(w=new e.Mesh(g,1===h.length?h[0]:h)),i){w.isConditionalLine=!0;const t=new Float32Array(3*a.length*2),r=new Float32Array(3*a.length*2),n=new Float32Array(3*a.length*2);for(let e=0,o=a.length;e<o;e++){const o=a[e],i=o.vertices,s=o.controlPoints,l=s[0],c=s[1],h=i[0],u=i[1],d=3*e*2;t[d+0]=l.x,t[d+1]=l.y,t[d+2]=l.z,t[d+3]=l.x,t[d+4]=l.y,t[d+5]=l.z,r[d+0]=c.x,r[d+1]=c.y,r[d+2]=c.z,r[d+3]=c.x,r[d+4]=c.y,r[d+5]=c.z,n[d+0]=u.x-h.x,n[d+1]=u.y-h.y,n[d+2]=u.z-h.z,n[d+3]=u.x-h.x,n[d+4]=u.y-h.y,n[d+5]=u.z-h.z}g.setAttribute("control0",new e.BufferAttribute(t,3,!1)),g.setAttribute("control1",new e.BufferAttribute(r,3,!1)),g.setAttribute("direction",new e.BufferAttribute(n,3,!1))}return w}class g extends e.Loader{constructor(e){super(e),this.materials=[],this.materialLibrary={},this.partsCache=new h(this),this.fileMap={},this.setMaterials([]),this.smoothNormals=!0,this.partsLibraryPath=""}setPartsLibraryPath(e){return this.partsLibraryPath=e,this}async preloadMaterials(t){const r=new e.FileLoader(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials);const a=/^0 !COLOUR/,n=(await r.loadAsync(t)).split(/[\n\r]/g),o=[];for(let e=0,t=n.length;e<t;e++){const t=n[e];if(a.test(t)){const e=t.replace(a,""),r=this.parseColorMetaDirective(new s(e));o.push(r)}}this.setMaterials(o)}load(t,r,a,n){const o=new e.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,(e=>{this.partsCache.parseModel(e,this.materialLibrary).then((e=>{this.applyMaterialsToMesh(e,"16",this.materialLibrary,!0),this.computeConstructionSteps(e),r(e)})).catch(n)}),a,n)}parse(e,t){this.partsCache.parseModel(e,this.materialLibrary).then((e=>{this.computeConstructionSteps(e),t(e)}))}setMaterials(e){this.materialLibrary={},this.materials=[];for(let t=0,r=e.length;t<r;t++)this.addMaterial(e[t]);return this.addMaterial(this.parseColorMetaDirective(new s("Main_Colour CODE 16 VALUE #FF8080 EDGE #333333"))),this.addMaterial(this.parseColorMetaDirective(new s("Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333"))),this}setFileMap(e){return this.fileMap=e,this}addMaterial(e){const t=this.materialLibrary;return t[e.userData.code]||(this.materials.push(e),t[e.userData.code]=e),this}getMaterial(e){if(e.startsWith("0x2")){const t=e.substring(3);return this.parseColorMetaDirective(new s("Direct_Color_"+t+" CODE -1 VALUE #"+t+" EDGE #"+t))}return this.materialLibrary[e]||null}applyMaterialsToMesh(e,t,r,a=!1){const n=this,o="16"===t;function i(e,i){if(o&&!(i in r)&&!a)return i;const s=e.isLineSegments||e.isConditionalLine;(!s&&"16"===i||s&&"24"===i)&&(i=t);let l=null;if(i in r)l=r[i];else{if(!a)return i;if(l=n.getMaterial(i),null===l)throw new Error(`LDrawLoader: Material properties for code ${i} not available.`)}return e.isLineSegments&&(l=l.userData.edgeMaterial,e.isConditionalLine&&(l=l.userData.conditionalEdgeMaterial)),l}e.traverse((e=>{if(e.isMesh||e.isLineSegments)if(Array.isArray(e.material))for(let t=0,r=e.material.length;t<r;t++)e.material[t].isMaterial||(e.material[t]=i(e,e.material[t]));else e.material.isMaterial||(e.material=i(e,e.material))}))}getMainMaterial(){return this.getMaterial("16")}getMainEdgeMaterial(){return this.getMaterial("24")}parseColorMetaDirective(t){let r=null,n=16711935,o=16711935,i=1,l=!1,c=0,h=0,u=null;const d=t.getToken();if(!d)throw new Error('LDrawLoader: Material name was expected after "!COLOUR tag'+t.getLineNumberString()+".");let g=null;for(;g=t.getToken(),g;)switch(g.toUpperCase()){case"CODE":r=t.getToken();break;case"VALUE":if(n=t.getToken(),n.startsWith("0x"))n="#"+n.substring(2);else if(!n.startsWith("#"))throw new Error("LDrawLoader: Invalid color while parsing material"+t.getLineNumberString()+".");break;case"EDGE":if(o=t.getToken(),o.startsWith("0x"))o="#"+o.substring(2);else if(!o.startsWith("#")){if(u=this.getMaterial(o),!u)throw new Error("LDrawLoader: Invalid edge color while parsing material"+t.getLineNumberString()+".");u=u.userData.edgeMaterial}break;case"ALPHA":if(i=parseInt(t.getToken()),isNaN(i))throw new Error("LDrawLoader: Invalid alpha value in material definition"+t.getLineNumberString()+".");i=Math.max(0,Math.min(1,i/255)),i<1&&(l=!0);break;case"LUMINANCE":if(c=parseInt(t.getToken()),isNaN(c))throw new Error("LDrawLoader: Invalid luminance value in material definition"+s.getLineNumberString()+".");c=Math.max(0,Math.min(1,c/255));break;case"CHROME":h=1;break;case"PEARLESCENT":h=2;break;case"RUBBER":h=3;break;case"MATTE_METALLIC":h=4;break;case"METAL":h=5;break;case"MATERIAL":t.setToEnd();break;default:throw new Error('LDrawLoader: Unknown token "'+g+'" while parsing material'+t.getLineNumberString()+".")}let p=null;switch(h){case 0:p=new e.MeshStandardMaterial({color:n,roughness:.3,metalness:0});break;case 2:p=new e.MeshStandardMaterial({color:n,roughness:.3,metalness:.25});break;case 1:p=new e.MeshStandardMaterial({color:n,roughness:0,metalness:1});break;case 3:p=new e.MeshStandardMaterial({color:n,roughness:.9,metalness:0});break;case 4:p=new e.MeshStandardMaterial({color:n,roughness:.8,metalness:.4});break;case 5:p=new e.MeshStandardMaterial({color:n,roughness:.2,metalness:.85})}return p.transparent=l,p.premultipliedAlpha=!0,p.opacity=i,p.depthWrite=!l,p.polygonOffset=!0,p.polygonOffsetFactor=1,0!==c&&p.emissive.set(p.color).multiplyScalar(c),u||(u=new e.LineBasicMaterial({color:o,transparent:l,opacity:i,depthWrite:!l}),u.userData.code=r,u.name=d+" - Edge",u.userData.conditionalEdgeMaterial=new a({fog:!0,transparent:l,depthWrite:!l,color:o,opacity:i})),p.userData.code=r,p.name=d,p.userData.edgeMaterial=u,this.addMaterial(p),p}computeConstructionSteps(e){let t=0;e.traverse((e=>{e.isGroup&&(e.userData.startingConstructionStep&&t++,e.userData.constructionStep=t)})),e.userData.numConstructionSteps=t+1}}exports.LDrawLoader=g;