@shopware-ag/dive 2.0.1-beta.7 → 2.0.1-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/build/chunks/AssetCache-CWeKL4PT.cjs +1 -0
  2. package/build/chunks/AssetCache-Y5G3mQU1.mjs +84 -0
  3. package/build/chunks/{AssetExporter-QnOue3VT.mjs → AssetExporter-CcSkkmZL.mjs} +4 -3
  4. package/build/chunks/{AssetExporter-TzKB2FHh.cjs → AssetExporter-Ds2dAfxL.cjs} +18 -18
  5. package/build/chunks/AssetLoader-CMKzMJ1u.cjs +4 -0
  6. package/build/chunks/{AssetLoader-Dqrg0Re8.mjs → AssetLoader-DjHz5xWK.mjs} +513 -516
  7. package/build/chunks/{FileTypes-Ca8pkRlQ.cjs → FileTypes-CKOjpHjz.cjs} +1 -1
  8. package/build/chunks/{FileTypes-CpKiTXEY.mjs → FileTypes-Cu4s3c_0.mjs} +1 -1
  9. package/build/chunks/{SelectTool-BizqI7_a.cjs → SelectTool-BD6Ccy_2.cjs} +1 -1
  10. package/build/chunks/{SelectTool-DVFL7BtX.mjs → SelectTool-w7sF1obN.mjs} +1 -1
  11. package/build/chunks/file-type-error-BsK7IJt7.cjs +1 -0
  12. package/build/chunks/file-type-error-aWHfMumr.mjs +8 -0
  13. package/build/chunks/isFileTypeSupported-BSpswPHU.mjs +12 -0
  14. package/build/chunks/isFileTypeSupported-CrEqYiv9.cjs +1 -0
  15. package/build/chunks/network-error-BONfHWQq.mjs +14 -0
  16. package/build/chunks/network-error-CdDXil5g.cjs +1 -0
  17. package/build/chunks/package-DXbIn_zz.mjs +39 -0
  18. package/build/chunks/package-DaKgG9tF.cjs +1 -0
  19. package/build/chunks/parse-error-IryNa_oq.mjs +8 -0
  20. package/build/chunks/parse-error-m5cNt1UV.cjs +1 -0
  21. package/build/dive.cjs +1 -1
  22. package/build/dive.mjs +27 -24
  23. package/build/plugins/ar/index.cjs +1 -1
  24. package/build/plugins/ar/index.mjs +59 -54
  25. package/build/plugins/assetcache/index.cjs +1 -0
  26. package/build/plugins/assetcache/index.d.ts +2 -0
  27. package/build/plugins/assetcache/index.mjs +5 -0
  28. package/build/plugins/assetexporter/index.cjs +1 -1
  29. package/build/plugins/assetexporter/index.mjs +1 -1
  30. package/build/plugins/assetloader/index.cjs +1 -1
  31. package/build/plugins/assetloader/index.mjs +1 -1
  32. package/build/plugins/axiscamera/index.cjs +1 -1
  33. package/build/plugins/axiscamera/index.mjs +1 -1
  34. package/build/plugins/state/index.cjs +1 -1
  35. package/build/plugins/state/index.mjs +2 -2
  36. package/build/plugins/systeminfo/index.mjs +1 -1
  37. package/build/plugins/toolbox/index.cjs +1 -1
  38. package/build/plugins/toolbox/index.mjs +2 -2
  39. package/build/src/error/file-content/file-content-error.d.ts +4 -0
  40. package/build/src/error/index.d.ts +4 -0
  41. package/build/src/error/network/network-error.d.ts +1 -1
  42. package/build/src/error/parse/parse-error.d.ts +2 -1
  43. package/build/src/events/dispatcher/EventDispatcher.d.ts +6 -0
  44. package/build/src/events/index.d.ts +1 -1
  45. package/build/src/index.d.ts +1 -3
  46. package/build/src/plugins/ar/src/error/ar-errors.d.ts +7 -1
  47. package/build/src/plugins/ar/src/webxr/raycaster/WebXRRaycaster.d.ts +1 -1
  48. package/build/src/plugins/ar/src/webxr/touchscreencontrols/WebXRTouchscreenControls.d.ts +1 -1
  49. package/build/src/plugins/assetcache/index.d.ts +1 -0
  50. package/build/src/plugins/assetcache/src/cache/AssetCache.d.ts +11 -0
  51. package/build/src/plugins/assetcache/src/chunk/Chunk.d.ts +19 -0
  52. package/build/src/plugins/assetcache/src/index.d.ts +2 -0
  53. package/build/src/plugins/assetloader/src/loader/AssetLoader.d.ts +0 -1
  54. package/build/src/plugins/systeminfo/src/SystemInfo.d.ts +1 -1
  55. package/package.json +11 -4
  56. package/build/chunks/AssetLoader-DCBiLwef.cjs +0 -4
  57. package/build/chunks/network-error-CHvryg-4.mjs +0 -18
  58. package/build/chunks/network-error-D_pq8VU6.cjs +0 -1
  59. package/build/chunks/package-CeZyVg2G.mjs +0 -39
  60. package/build/chunks/package-D_hIrGNz.cjs +0 -1
  61. package/build/chunks/parse-error-BFRJyIxM.mjs +0 -14
  62. package/build/chunks/parse-error-Bd09D_1L.cjs +0 -1
  63. package/build/src/events/EventExecutor.d.ts +0 -5
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.defineProperty;var c=(s,e,r)=>e in s?u(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>c(s,typeof e!="symbol"?e+"":e,r);require("./FileTypes-CKOjpHjz.cjs");require("three");const i=require("./network-error-CdDXil5g.cjs"),n=require("./parse-error-m5cNt1UV.cjs");class h{constructor(e,r){t(this,"_promise");t(this,"_resolve");t(this,"_arrayBuffer",null);t(this,"_result",null);t(this,"_size",-1);t(this,"_createdAt");t(this,"_updatedAt");this._uri=e,this._parse=r,this._promise=new Promise(a=>{this._resolve=a}),this._createdAt=new Date,this._updatedAt=new Date}get promise(){return this._promise}get result(){return this._result}get size(){return this._size}get createdAt(){return this._createdAt}get updatedAt(){return this._updatedAt}get arrayBuffer(){return this._arrayBuffer}async fetch(){const e=await fetch(this._uri);if(!e.ok)throw new i.NetworkError(this._uri);try{const r=await e.arrayBuffer();this._arrayBuffer=r,this._size=r.byteLength}catch{throw new i.FileContentError(this._uri)}try{const r=this._parse(this._arrayBuffer);this._result=await r}catch{throw new n.ParseError(this._uri)}return this._updatedAt=new Date,this._resolve(this._result),this._result}}class _{constructor(){t(this,"_cache",new Map)}create(e,r){const a=new h(e,r);return this._cache.set(e,a),a}write(e,r){this._cache.set(e,r)}read(e){return this._cache.get(e)??null}delete(e){this._cache.delete(e)}clear(){this._cache.clear()}}const o=new _;exports.AssetCache=o;exports.Chunk=h;
@@ -0,0 +1,84 @@
1
+ var i = Object.defineProperty;
2
+ var h = (s, t, e) => t in s ? i(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var r = (s, t, e) => h(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import "./FileTypes-Cu4s3c_0.mjs";
5
+ import "three";
6
+ import { N as u, F as c } from "./network-error-BONfHWQq.mjs";
7
+ import { P as _ } from "./parse-error-IryNa_oq.mjs";
8
+ class n {
9
+ constructor(t, e) {
10
+ r(this, "_promise");
11
+ r(this, "_resolve");
12
+ r(this, "_arrayBuffer", null);
13
+ r(this, "_result", null);
14
+ // metadata
15
+ r(this, "_size", -1);
16
+ r(this, "_createdAt");
17
+ r(this, "_updatedAt");
18
+ this._uri = t, this._parse = e, this._promise = new Promise((a) => {
19
+ this._resolve = a;
20
+ }), this._createdAt = /* @__PURE__ */ new Date(), this._updatedAt = /* @__PURE__ */ new Date();
21
+ }
22
+ get promise() {
23
+ return this._promise;
24
+ }
25
+ get result() {
26
+ return this._result;
27
+ }
28
+ get size() {
29
+ return this._size;
30
+ }
31
+ get createdAt() {
32
+ return this._createdAt;
33
+ }
34
+ get updatedAt() {
35
+ return this._updatedAt;
36
+ }
37
+ get arrayBuffer() {
38
+ return this._arrayBuffer;
39
+ }
40
+ async fetch() {
41
+ const t = await fetch(this._uri);
42
+ if (!t.ok)
43
+ throw new u(this._uri);
44
+ try {
45
+ const e = await t.arrayBuffer();
46
+ this._arrayBuffer = e, this._size = e.byteLength;
47
+ } catch {
48
+ throw new c(this._uri);
49
+ }
50
+ try {
51
+ const e = this._parse(this._arrayBuffer);
52
+ this._result = await e;
53
+ } catch {
54
+ throw new _(this._uri);
55
+ }
56
+ return this._updatedAt = /* @__PURE__ */ new Date(), this._resolve(this._result), this._result;
57
+ }
58
+ }
59
+ class o {
60
+ constructor() {
61
+ r(this, "_cache", /* @__PURE__ */ new Map());
62
+ }
63
+ create(t, e) {
64
+ const a = new n(t, e);
65
+ return this._cache.set(t, a), a;
66
+ }
67
+ write(t, e) {
68
+ this._cache.set(t, e);
69
+ }
70
+ read(t) {
71
+ return this._cache.get(t) ?? null;
72
+ }
73
+ delete(t) {
74
+ this._cache.delete(t);
75
+ }
76
+ clear() {
77
+ this._cache.clear();
78
+ }
79
+ }
80
+ const m = new o();
81
+ export {
82
+ m as A,
83
+ n as C
84
+ };
@@ -3,7 +3,8 @@ var Me = (n, e, s) => e in n ? Te(n, e, { enumerable: !0, configurable: !0, writ
3
3
  var Y = (n, e, s) => Me(n, typeof e != "symbol" ? e + "" : e, s);
4
4
  import { PlaneGeometry as ye, ShaderMaterial as we, Uniform as Ee, SRGBColorSpace as ue, Mesh as Ae, PerspectiveCamera as be, Scene as Z, WebGLRenderer as Ie, CanvasTexture as Re, Color as _e, Matrix4 as le, Vector3 as B, Quaternion as Se, BufferAttribute as L, CompressedTexture as j, Source as Ne, NoColorSpace as fe, MathUtils as q, RGBAFormat as Le, DoubleSide as pe, PropertyBinding as H, InterpolateDiscrete as ve, NearestFilter as Ce, NearestMipmapNearestFilter as Ue, NearestMipmapLinearFilter as Fe, LinearFilter as $e, LinearMipmapNearestFilter as Oe, LinearMipmapLinearFilter as Pe, ClampToEdgeWrapping as De, RepeatWrapping as Ge, MirroredRepeatWrapping as ke, InterpolateLinear as ze } from "three";
5
5
  import { s as he, z as Be } from "./fflate.module-xyO_T3Zm.mjs";
6
- import { F as He, P as N } from "./parse-error-BFRJyIxM.mjs";
6
+ import { F as He } from "./file-type-error-aWHfMumr.mjs";
7
+ import { P as N } from "./parse-error-IryNa_oq.mjs";
7
8
  let O, K, C, G;
8
9
  function z(n, e = 1 / 0, s = null) {
9
10
  K || (K = new ye(2, 2, 1, 1)), C || (C = new we({
@@ -1566,7 +1567,7 @@ function _t(n) {
1566
1567
 
1567
1568
  `;
1568
1569
  }
1569
- class Ct {
1570
+ class Ut {
1570
1571
  constructor() {
1571
1572
  Y(this, "_gltfExporter");
1572
1573
  Y(this, "_usdzExporter");
@@ -1617,5 +1618,5 @@ class Ct {
1617
1618
  }
1618
1619
  }
1619
1620
  export {
1620
- Ct as A
1621
+ Ut as A
1621
1622
  };
@@ -1,4 +1,4 @@
1
- "use strict";var ue=Object.defineProperty;var le=(n,e,s)=>e in n?ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var H=(n,e,s)=>le(n,typeof e!="symbol"?e+"":e,s);const d=require("three"),K=require("./fflate.module-DHdJvhNh.cjs"),L=require("./parse-error-Bd09D_1L.cjs");let O,V,C,D;function k(n,e=1/0,s=null){V||(V=new d.PlaneGeometry(2,2,1,1)),C||(C=new d.ShaderMaterial({uniforms:{blitTexture:new d.Uniform(n)},vertexShader:`
1
+ "use strict";var ue=Object.defineProperty;var le=(n,e,s)=>e in n?ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var H=(n,e,s)=>le(n,typeof e!="symbol"?e+"":e,s);const d=require("three"),K=require("./fflate.module-DHdJvhNh.cjs"),fe=require("./file-type-error-BsK7IJt7.cjs"),L=require("./parse-error-m5cNt1UV.cjs");let O,V,C,D;function k(n,e=1/0,s=null){V||(V=new d.PlaneGeometry(2,2,1,1)),C||(C=new d.ShaderMaterial({uniforms:{blitTexture:new d.Uniform(n)},vertexShader:`
2
2
  varying vec2 vUv;
3
3
  void main(){
4
4
  vUv = uv;
@@ -15,7 +15,7 @@
15
15
  #else
16
16
  gl_FragColor = texture2D( blitTexture, vUv);
17
17
  #endif
18
- }`})),C.uniforms.blitTexture.value=n,C.defines.IS_SRGB=n.colorSpace==d.SRGBColorSpace,C.needsUpdate=!0,D||(D=new d.Mesh(V,C),D.frustumCulled=!1);const t=new d.PerspectiveCamera,r=new d.Scene;r.add(D),s===null&&(s=O=new d.WebGLRenderer({antialias:!1}));const i=Math.min(n.image.width,e),o=Math.min(n.image.height,e);s.setSize(i,o),s.clear(),s.render(r,t);const a=document.createElement("canvas"),c=a.getContext("2d");a.width=i,a.height=o,c.drawImage(s.domElement,0,0,i,o);const u=new d.CanvasTexture(a);return u.minFilter=n.minFilter,u.magFilter=n.magFilter,u.wrapS=n.wrapS,u.wrapT=n.wrapT,u.name=n.name,O&&(O.forceContextLoss(),O.dispose(),O=null),u}const Z={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class X{constructor(){this.pluginCallbacks=[],this.register(function(e){return new ye(e)}),this.register(function(e){return new we(e)}),this.register(function(e){return new Ae(e)}),this.register(function(e){return new Ie(e)}),this.register(function(e){return new Re(e)}),this.register(function(e){return new Se(e)}),this.register(function(e){return new Ee(e)}),this.register(function(e){return new be(e)}),this.register(function(e){return new _e(e)}),this.register(function(e){return new Ne(e)}),this.register(function(e){return new Le(e)}),this.register(function(e){return new ve(e)}),this.register(function(e){return new Ce(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,s,t,r){const i=new Me,o=[];for(let a=0,c=this.pluginCallbacks.length;a<c;a++)o.push(this.pluginCallbacks[a](i));i.setPlugins(o),i.write(e,s,r).catch(t)}parseAsync(e,s){const t=this;return new Promise(function(r,i){t.parse(e,r,i,s)})}}const M={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},Y="KHR_mesh_quantization",S={};S[d.NearestFilter]=M.NEAREST;S[d.NearestMipmapNearestFilter]=M.NEAREST_MIPMAP_NEAREST;S[d.NearestMipmapLinearFilter]=M.NEAREST_MIPMAP_LINEAR;S[d.LinearFilter]=M.LINEAR;S[d.LinearMipmapNearestFilter]=M.LINEAR_MIPMAP_NEAREST;S[d.LinearMipmapLinearFilter]=M.LINEAR_MIPMAP_LINEAR;S[d.ClampToEdgeWrapping]=M.CLAMP_TO_EDGE;S[d.RepeatWrapping]=M.REPEAT;S[d.MirroredRepeatWrapping]=M.MIRRORED_REPEAT;const J={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},fe=new d.Color,Q=12,pe=1179937895,he=2,ee=8,de=1313821514,xe=5130562;function P(n,e){return n.length===e.length&&n.every(function(s,t){return s===e[t]})}function ge(n){return new TextEncoder().encode(n).buffer}function me(n){return P(n.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Te(n,e,s){const t={min:new Array(n.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(n.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let r=e;r<e+s;r++)for(let i=0;i<n.itemSize;i++){let o;n.itemSize>4?o=n.array[r*n.itemSize+i]:(i===0?o=n.getX(r):i===1?o=n.getY(r):i===2?o=n.getZ(r):i===3&&(o=n.getW(r)),n.normalized===!0&&(o=d.MathUtils.normalize(o,n.array))),t.min[i]=Math.min(t.min[i],o),t.max[i]=Math.max(t.max[i],o)}return t}function ie(n){return Math.ceil(n/4)*4}function j(n,e=0){const s=ie(n.byteLength);if(s!==n.byteLength){const t=new Uint8Array(s);if(t.set(new Uint8Array(n)),e!==0)for(let r=n.byteLength;r<s;r++)t[r]=e;return t.buffer}return n}function te(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function se(n,e){if(n.toBlob!==void 0)return new Promise(t=>n.toBlob(t,e));let s;return e==="image/jpeg"?s=.92:e==="image/webp"&&(s=.8),n.convertToBlob({type:e,quality:s})}class Me{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map}}setPlugins(e){this.plugins=e}async write(e,s,t={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},t),this.options.animations.length>0&&(this.options.trs=!0),this.processInput(e),await Promise.all(this.pending);const r=this,i=r.buffers,o=r.json;t=r.options;const a=r.extensionsUsed,c=r.extensionsRequired,u=new Blob(i,{type:"application/octet-stream"}),p=Object.keys(a),l=Object.keys(c);if(p.length>0&&(o.extensionsUsed=p),l.length>0&&(o.extensionsRequired=l),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=u.size),t.binary===!0){const g=new FileReader;g.readAsArrayBuffer(u),g.onloadend=function(){const f=j(g.result),h=new DataView(new ArrayBuffer(ee));h.setUint32(0,f.byteLength,!0),h.setUint32(4,xe,!0);const x=j(ge(JSON.stringify(o)),32),m=new DataView(new ArrayBuffer(ee));m.setUint32(0,x.byteLength,!0),m.setUint32(4,de,!0);const w=new ArrayBuffer(Q),_=new DataView(w);_.setUint32(0,pe,!0),_.setUint32(4,he,!0);const B=Q+m.byteLength+x.byteLength+h.byteLength+f.byteLength;_.setUint32(8,B,!0);const T=new Blob([w,m,x,h,f],{type:"application/octet-stream"}),y=new FileReader;y.readAsArrayBuffer(T),y.onloadend=function(){s(y.result)}}}else if(o.buffers&&o.buffers.length>0){const g=new FileReader;g.readAsDataURL(u),g.onloadend=function(){const f=g.result;o.buffers[0].uri=f,s(o)}}else s(o)}serializeUserData(e,s){if(Object.keys(e.userData).length===0)return;const t=this.options,r=this.extensionsUsed;try{const i=JSON.parse(JSON.stringify(e.userData));if(t.includeCustomExtensions&&i.gltfExtensions){s.extensions===void 0&&(s.extensions={});for(const o in i.gltfExtensions)s.extensions[o]=i.gltfExtensions[o],r[o]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(s.extras=i)}catch(i){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+i.message)}}getUID(e,s=!1){if(this.uids.has(e)===!1){const r=new Map;r.set(!0,this.uid++),r.set(!1,this.uid++),this.uids.set(e,r)}return this.uids.get(e).get(s)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;const t=new d.Vector3;for(let r=0,i=e.count;r<i;r++)if(Math.abs(t.fromBufferAttribute(e,r).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){const s=this.cache;if(s.attributesNormalized.has(e))return s.attributesNormalized.get(e);const t=e.clone(),r=new d.Vector3;for(let i=0,o=t.count;i<o;i++)r.fromBufferAttribute(t,i),r.x===0&&r.y===0&&r.z===0?r.setX(1):r.normalize(),t.setXYZ(i,r.x,r.y,r.z);return s.attributesNormalized.set(e,t),t}applyTextureTransform(e,s){let t=!1;const r={};(s.offset.x!==0||s.offset.y!==0)&&(r.offset=s.offset.toArray(),t=!0),s.rotation!==0&&(r.rotation=s.rotation,t=!0),(s.repeat.x!==1||s.repeat.y!==1)&&(r.scale=s.repeat.toArray(),t=!0),t&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=r,this.extensionsUsed.KHR_texture_transform=!0)}buildMetalRoughTexture(e,s){if(e===s)return e;function t(f){return f.colorSpace===d.SRGBColorSpace?function(x){return x<.04045?x*.0773993808:Math.pow(x*.9478672986+.0521327014,2.4)}:function(x){return x}}console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),e instanceof d.CompressedTexture&&(e=k(e)),s instanceof d.CompressedTexture&&(s=k(s));const r=e?e.image:null,i=s?s.image:null,o=Math.max(r?r.width:0,i?i.width:0),a=Math.max(r?r.height:0,i?i.height:0),c=te();c.width=o,c.height=a;const u=c.getContext("2d");u.fillStyle="#00ffff",u.fillRect(0,0,o,a);const p=u.getImageData(0,0,o,a);if(r){u.drawImage(r,0,0,o,a);const f=t(e),h=u.getImageData(0,0,o,a).data;for(let x=2;x<h.length;x+=4)p.data[x]=f(h[x]/256)*256}if(i){u.drawImage(i,0,0,o,a);const f=t(s),h=u.getImageData(0,0,o,a).data;for(let x=1;x<h.length;x+=4)p.data[x]=f(h[x]/256)*256}u.putImageData(p,0,0);const g=(e||s).clone();return g.source=new d.Source(c),g.colorSpace=d.NoColorSpace,g.channel=(e||s).channel,e&&s&&e.channel!==s.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),g}processBuffer(e){const s=this.json,t=this.buffers;return s.buffers||(s.buffers=[{byteLength:0}]),t.push(e),0}processBufferView(e,s,t,r,i){const o=this.json;o.bufferViews||(o.bufferViews=[]);let a;switch(s){case M.BYTE:case M.UNSIGNED_BYTE:a=1;break;case M.SHORT:case M.UNSIGNED_SHORT:a=2;break;default:a=4}let c=e.itemSize*a;i===M.ARRAY_BUFFER&&(c=Math.ceil(c/4)*4);const u=ie(r*c),p=new DataView(new ArrayBuffer(u));let l=0;for(let h=t;h<t+r;h++){for(let x=0;x<e.itemSize;x++){let m;e.itemSize>4?m=e.array[h*e.itemSize+x]:(x===0?m=e.getX(h):x===1?m=e.getY(h):x===2?m=e.getZ(h):x===3&&(m=e.getW(h)),e.normalized===!0&&(m=d.MathUtils.normalize(m,e.array))),s===M.FLOAT?p.setFloat32(l,m,!0):s===M.INT?p.setInt32(l,m,!0):s===M.UNSIGNED_INT?p.setUint32(l,m,!0):s===M.SHORT?p.setInt16(l,m,!0):s===M.UNSIGNED_SHORT?p.setUint16(l,m,!0):s===M.BYTE?p.setInt8(l,m):s===M.UNSIGNED_BYTE&&p.setUint8(l,m),l+=a}l%c!==0&&(l+=c-l%c)}const g={buffer:this.processBuffer(p.buffer),byteOffset:this.byteOffset,byteLength:u};return i!==void 0&&(g.target=i),i===M.ARRAY_BUFFER&&(g.byteStride=c),this.byteOffset+=u,o.bufferViews.push(g),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const s=this,t=s.json;return t.bufferViews||(t.bufferViews=[]),new Promise(function(r){const i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){const o=j(i.result),a={buffer:s.processBuffer(o),byteOffset:s.byteOffset,byteLength:o.byteLength};s.byteOffset+=o.byteLength,r(t.bufferViews.push(a)-1)}})}processAccessor(e,s,t,r){const i=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"};let a;if(e.array.constructor===Float32Array)a=M.FLOAT;else if(e.array.constructor===Int32Array)a=M.INT;else if(e.array.constructor===Uint32Array)a=M.UNSIGNED_INT;else if(e.array.constructor===Int16Array)a=M.SHORT;else if(e.array.constructor===Uint16Array)a=M.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)a=M.BYTE;else if(e.array.constructor===Uint8Array)a=M.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(t===void 0&&(t=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;const c=Te(e,t,r);let u;s!==void 0&&(u=e===s.index?M.ELEMENT_ARRAY_BUFFER:M.ARRAY_BUFFER);const p=this.processBufferView(e,a,t,r,u),l={bufferView:p.id,byteOffset:p.byteOffset,componentType:a,count:r,max:c.max,min:c.min,type:o[e.itemSize]};return e.normalized===!0&&(l.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(l)-1}processImage(e,s,t,r="image/png"){if(e!==null){const i=this,o=i.cache,a=i.json,c=i.options,u=i.pending;o.images.has(e)||o.images.set(e,{});const p=o.images.get(e),l=r+":flipY/"+t.toString();if(p[l]!==void 0)return p[l];a.images||(a.images=[]);const g={mimeType:r},f=te();f.width=Math.min(e.width,c.maxTextureSize),f.height=Math.min(e.height,c.maxTextureSize);const h=f.getContext("2d");if(t===!0&&(h.translate(0,f.height),h.scale(1,-1)),e.data!==void 0){s!==d.RGBAFormat&&console.error("GLTFExporter: Only RGBAFormat is supported.",s),(e.width>c.maxTextureSize||e.height>c.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);const m=new Uint8ClampedArray(e.height*e.width*4);for(let w=0;w<m.length;w+=4)m[w+0]=e.data[w+0],m[w+1]=e.data[w+1],m[w+2]=e.data[w+2],m[w+3]=e.data[w+3];h.putImageData(new ImageData(m,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)h.drawImage(e,0,0,f.width,f.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");c.binary===!0?u.push(se(f,r).then(m=>i.processBufferViewImage(m)).then(m=>{g.bufferView=m})):f.toDataURL!==void 0?g.uri=f.toDataURL(r):u.push(se(f,r).then(m=>new FileReader().readAsDataURL(m)).then(m=>{g.uri=m}));const x=a.images.push(g)-1;return p[l]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const s=this.json;s.samplers||(s.samplers=[]);const t={magFilter:S[e.magFilter],minFilter:S[e.minFilter],wrapS:S[e.wrapS],wrapT:S[e.wrapT]};return s.samplers.push(t)-1}processTexture(e){const t=this.options,r=this.cache,i=this.json;if(r.textures.has(e))return r.textures.get(e);i.textures||(i.textures=[]),e instanceof d.CompressedTexture&&(e=k(e,t.maxTextureSize));let o=e.userData.mimeType;o==="image/webp"&&(o="image/png");const a={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,o)};e.name&&(a.name=e.name),this._invokeAll(function(u){u.writeTexture&&u.writeTexture(e,a)});const c=i.textures.push(a)-1;return r.textures.set(e,c),c}processMaterial(e){const s=this.cache,t=this.json;if(s.materials.has(e))return s.materials.get(e);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;t.materials||(t.materials=[]);const r={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");const i=e.color.toArray().concat([e.opacity]);if(P(i,[1,1,1,1])||(r.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(r.pbrMetallicRoughness.metallicFactor=e.metalness,r.pbrMetallicRoughness.roughnessFactor=e.roughness):(r.pbrMetallicRoughness.metallicFactor=.5,r.pbrMetallicRoughness.roughnessFactor=.5),e.metalnessMap||e.roughnessMap){const a=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),c={index:this.processTexture(a),channel:a.channel};this.applyTextureTransform(c,a),r.pbrMetallicRoughness.metallicRoughnessTexture=c}if(e.map){const a={index:this.processTexture(e.map),texCoord:e.map.channel};this.applyTextureTransform(a,e.map),r.pbrMetallicRoughness.baseColorTexture=a}if(e.emissive){const a=e.emissive;if(Math.max(a.r,a.g,a.b)>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){const u={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(u,e.emissiveMap),r.emissiveTexture=u}}if(e.normalMap){const a={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(a.scale=e.normalScale.x),this.applyTextureTransform(a,e.normalMap),r.normalTexture=a}if(e.aoMap){const a={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(a.strength=e.aoMapIntensity),this.applyTextureTransform(a,e.aoMap),r.occlusionTexture=a}e.transparent?r.alphaMode="BLEND":e.alphaTest>0&&(r.alphaMode="MASK",r.alphaCutoff=e.alphaTest),e.side===d.DoubleSide&&(r.doubleSided=!0),e.name!==""&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(a){a.writeMaterial&&a.writeMaterial(e,r)});const o=t.materials.push(r)-1;return s.materials.set(e,o),o}processMesh(e){const s=this.cache,t=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let T=0,y=e.material.length;T<y;T++)r.push(e.material[T].uuid);else r.push(e.material.uuid);const i=r.join(":");if(s.meshes.has(i))return s.meshes.get(i);const o=e.geometry;let a;e.isLineSegments?a=M.LINES:e.isLineLoop?a=M.LINE_LOOP:e.isLine?a=M.LINE_STRIP:e.isPoints?a=M.POINTS:a=e.material.wireframe?M.LINES:M.TRIANGLES;const c={},u={},p=[],l=[],g={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},f=o.getAttribute("normal");f!==void 0&&!this.isNormalizedNormalAttribute(f)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(f)));let h=null;for(let T in o.attributes){if(T.slice(0,5)==="morph")continue;const y=o.attributes[T];if(T=g[T]||T.toUpperCase(),/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(T)||(T="_"+T),s.attributes.has(this.getUID(y))){u[T]=s.attributes.get(this.getUID(y));continue}h=null;const A=y.array;T==="JOINTS_0"&&!(A instanceof Uint16Array)&&!(A instanceof Uint8Array)&&(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),h=new d.BufferAttribute(new Uint16Array(A),y.itemSize,y.normalized));const R=this.processAccessor(h||y,o);R!==null&&(T.startsWith("_")||this.detectMeshQuantization(T,y),u[T]=R,s.attributes.set(this.getUID(y),R))}if(f!==void 0&&o.setAttribute("normal",f),Object.keys(u).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const T=[],y=[],b={};if(e.morphTargetDictionary!==void 0)for(const A in e.morphTargetDictionary)b[e.morphTargetDictionary[A]]=A;for(let A=0;A<e.morphTargetInfluences.length;++A){const R={};let q=!1;for(const U in o.morphAttributes){if(U!=="position"&&U!=="normal"){q||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),q=!0);continue}const N=o.morphAttributes[U][A],z=U.toUpperCase(),F=o.attributes[U];if(s.attributes.has(this.getUID(N,!0))){R[z]=s.attributes.get(this.getUID(N,!0));continue}const $=N.clone();if(!o.morphTargetsRelative)for(let I=0,ce=N.count;I<ce;I++)for(let v=0;v<N.itemSize;v++)v===0&&$.setX(I,N.getX(I)-F.getX(I)),v===1&&$.setY(I,N.getY(I)-F.getY(I)),v===2&&$.setZ(I,N.getZ(I)-F.getZ(I)),v===3&&$.setW(I,N.getW(I)-F.getW(I));R[z]=this.processAccessor($,o),s.attributes.set(this.getUID(F,!0),R[z])}l.push(R),T.push(e.morphTargetInfluences[A]),e.morphTargetDictionary!==void 0&&y.push(b[A])}c.weights=T,y.length>0&&(c.extras={},c.extras.targetNames=y)}const x=Array.isArray(e.material);if(x&&o.groups.length===0)return null;let m=!1;if(x&&o.index===null){const T=[];for(let y=0,b=o.attributes.position.count;y<b;y++)T[y]=y;o.setIndex(T),m=!0}const w=x?e.material:[e.material],_=x?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let T=0,y=_.length;T<y;T++){const b={mode:a,attributes:u};if(this.serializeUserData(o,b),l.length>0&&(b.targets=l),o.index!==null){let R=this.getUID(o.index);(_[T].start!==void 0||_[T].count!==void 0)&&(R+=":"+_[T].start+":"+_[T].count),s.attributes.has(R)?b.indices=s.attributes.get(R):(b.indices=this.processAccessor(o.index,o,_[T].start,_[T].count),s.attributes.set(R,b.indices)),b.indices===null&&delete b.indices}const A=this.processMaterial(w[_[T].materialIndex]);A!==null&&(b.material=A),p.push(b)}m===!0&&o.setIndex(null),c.primitives=p,t.meshes||(t.meshes=[]),this._invokeAll(function(T){T.writeMesh&&T.writeMesh(e,c)});const B=t.meshes.push(c)-1;return s.meshes.set(i,B),B}detectMeshQuantization(e,s){if(this.extensionsUsed[Y])return;let t;switch(s.array.constructor){case Int8Array:t="byte";break;case Uint8Array:t="unsigned byte";break;case Int16Array:t="short";break;case Uint16Array:t="unsigned short";break;default:return}s.normalized&&(t+=" normalized");const r=e.split("_",1)[0];Z[r]&&Z[r].includes(t)&&(this.extensionsUsed[Y]=!0,this.extensionsRequired[Y]=!0)}processCamera(e){const s=this.json;s.cameras||(s.cameras=[]);const t=e.isOrthographicCamera,r={type:t?"orthographic":"perspective"};return t?r.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(r.name=e.type),s.cameras.push(r)-1}processAnimation(e,s){const t=this.json,r=this.nodeMap;t.animations||(t.animations=[]),e=X.Utils.mergeMorphTargetTracks(e.clone(),s);const i=e.tracks,o=[],a=[];for(let c=0;c<i.length;++c){const u=i[c],p=d.PropertyBinding.parseTrackName(u.name);let l=d.PropertyBinding.findNode(s,p.nodeName);const g=J[p.propertyName];if(p.objectName==="bones"&&(l.isSkinnedMesh===!0?l=l.skeleton.getBoneByName(p.objectIndex):l=void 0),!l||!g)return console.warn('THREE.GLTFExporter: Could not export animation track "%s".',u.name),null;const f=1;let h=u.values.length/u.times.length;g===J.morphTargetInfluences&&(h/=l.morphTargetInfluences.length);let x;u.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(x="CUBICSPLINE",h/=3):u.getInterpolation()===d.InterpolateDiscrete?x="STEP":x="LINEAR",a.push({input:this.processAccessor(new d.BufferAttribute(u.times,f)),output:this.processAccessor(new d.BufferAttribute(u.values,h)),interpolation:x}),o.push({sampler:a.length-1,target:{node:r.get(l),path:g}})}return t.animations.push({name:e.name||"clip_"+t.animations.length,samplers:a,channels:o}),t.animations.length-1}processSkin(e){const s=this.json,t=this.nodeMap,r=s.nodes[t.get(e)],i=e.skeleton;if(i===void 0)return null;const o=e.skeleton.bones[0];if(o===void 0)return null;const a=[],c=new Float32Array(i.bones.length*16),u=new d.Matrix4;for(let l=0;l<i.bones.length;++l)a.push(t.get(i.bones[l])),u.copy(i.boneInverses[l]),u.multiply(e.bindMatrix).toArray(c,l*16);return s.skins===void 0&&(s.skins=[]),s.skins.push({inverseBindMatrices:this.processAccessor(new d.BufferAttribute(c,16)),joints:a,skeleton:t.get(o)}),r.skin=s.skins.length-1}processNode(e){const s=this.json,t=this.options,r=this.nodeMap;s.nodes||(s.nodes=[]);const i={};if(t.trs){const a=e.quaternion.toArray(),c=e.position.toArray(),u=e.scale.toArray();P(a,[0,0,0,1])||(i.rotation=a),P(c,[0,0,0])||(i.translation=c),P(u,[1,1,1])||(i.scale=u)}else e.matrixAutoUpdate&&e.updateMatrix(),me(e.matrix)===!1&&(i.matrix=e.matrix.elements);if(e.name!==""&&(i.name=String(e.name)),this.serializeUserData(e,i),e.isMesh||e.isLine||e.isPoints){const a=this.processMesh(e);a!==null&&(i.mesh=a)}else e.isCamera&&(i.camera=this.processCamera(e));if(e.isSkinnedMesh&&this.skins.push(e),e.children.length>0){const a=[];for(let c=0,u=e.children.length;c<u;c++){const p=e.children[c];if(p.visible||t.onlyVisible===!1){const l=this.processNode(p);l!==null&&a.push(l)}}a.length>0&&(i.children=a)}this._invokeAll(function(a){a.writeNode&&a.writeNode(e,i)});const o=s.nodes.push(i)-1;return r.set(e,o),o}processScene(e){const s=this.json,t=this.options;s.scenes||(s.scenes=[],s.scene=0);const r={};e.name!==""&&(r.name=e.name),s.scenes.push(r);const i=[];for(let o=0,a=e.children.length;o<a;o++){const c=e.children[o];if(c.visible||t.onlyVisible===!1){const u=this.processNode(c);u!==null&&i.push(u)}}i.length>0&&(r.nodes=i),this.serializeUserData(e,r)}processObjects(e){const s=new d.Scene;s.name="AuxScene";for(let t=0;t<e.length;t++)s.children.push(e[t]);this.processScene(s)}processInput(e){const s=this.options;e=e instanceof Array?e:[e],this._invokeAll(function(r){r.beforeParse&&r.beforeParse(e)});const t=[];for(let r=0;r<e.length;r++)e[r]instanceof d.Scene?this.processScene(e[r]):t.push(e[r]);t.length>0&&this.processObjects(t);for(let r=0;r<this.skins.length;++r)this.processSkin(this.skins[r]);for(let r=0;r<s.animations.length;++r)this.processAnimation(s.animations[r],e[0]);this._invokeAll(function(r){r.afterParse&&r.afterParse(e)})}_invokeAll(e){for(let s=0,t=this.plugins.length;s<t;s++)e(this.plugins[s])}}class ye{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,s){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}const t=this.writer,r=t.json,i=t.extensionsUsed,o={};e.name&&(o.name=e.name),o.color=e.color.toArray(),o.intensity=e.intensity,e.isDirectionalLight?o.type="directional":e.isPointLight?(o.type="point",e.distance>0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),i[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},i[this.name]=!0);const a=r.extensions[this.name].lights;a.push(o),s.extensions=s.extensions||{},s.extensions[this.name]={light:a.length-1}}}class we{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,s){if(!e.isMeshBasicMaterial)return;const r=this.writer.extensionsUsed;s.extensions=s.extensions||{},s.extensions[this.name]={},r[this.name]=!0,s.pbrMetallicRoughness.metallicFactor=0,s.pbrMetallicRoughness.roughnessFactor=.9}}class Ee{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){const o={index:t.processTexture(e.clearcoatMap),texCoord:e.clearcoatMap.channel};t.applyTextureTransform(o,e.clearcoatMap),i.clearcoatTexture=o}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const o={index:t.processTexture(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};t.applyTextureTransform(o,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){const o={index:t.processTexture(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};t.applyTextureTransform(o,e.clearcoatNormalMap),i.clearcoatNormalTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class be{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){const o={index:t.processTexture(e.iridescenceMap),texCoord:e.iridescenceMap.channel};t.applyTextureTransform(o,e.iridescenceMap),i.iridescenceTexture=o}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const o={index:t.processTexture(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};t.applyTextureTransform(o,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ae{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){const o={index:t.processTexture(e.transmissionMap),texCoord:e.transmissionMap.channel};t.applyTextureTransform(o,e.transmissionMap),i.transmissionTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ie{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){const o={index:t.processTexture(e.thicknessMap),texCoord:e.thicknessMap.channel};t.applyTextureTransform(o,e.thicknessMap),i.thicknessTexture=o}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Re{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;const r=this.writer.extensionsUsed,i={};i.ior=e.ior,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Se{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(fe)&&!e.specularIntensityMap&&!e.specularColorMap)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.specularIntensityMap){const o={index:t.processTexture(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};t.applyTextureTransform(o,e.specularIntensityMap),i.specularTexture=o}if(e.specularColorMap){const o={index:t.processTexture(e.specularColorMap),texCoord:e.specularColorMap.channel};t.applyTextureTransform(o,e.specularColorMap),i.specularColorTexture=o}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class _e{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.sheenRoughnessMap){const o={index:t.processTexture(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};t.applyTextureTransform(o,e.sheenRoughnessMap),i.sheenRoughnessTexture=o}if(e.sheenColorMap){const o={index:t.processTexture(e.sheenColorMap),texCoord:e.sheenColorMap.channel};t.applyTextureTransform(o,e.sheenColorMap),i.sheenColorTexture=o}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ne{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.anisotropyMap){const o={index:t.processTexture(e.anisotropyMap)};t.applyTextureTransform(o,e.anisotropyMap),i.anisotropyTexture=o}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Le{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,s){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;const r=this.writer.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class ve{constructor(e){this.writer=e,this.name="EXT_materials_bump"}writeMaterial(e,s){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.bumpMap){const o={index:t.processTexture(e.bumpMap),texCoord:e.bumpMap.channel};t.applyTextureTransform(o,e.bumpMap),i.bumpTexture=o}i.bumpFactor=e.bumpScale,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ce{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,s){if(!e.isInstancedMesh)return;const t=this.writer,r=e,i=new Float32Array(r.count*3),o=new Float32Array(r.count*4),a=new Float32Array(r.count*3),c=new d.Matrix4,u=new d.Vector3,p=new d.Quaternion,l=new d.Vector3;for(let f=0;f<r.count;f++)r.getMatrixAt(f,c),c.decompose(u,p,l),u.toArray(i,f*3),p.toArray(o,f*4),l.toArray(a,f*3);const g={TRANSLATION:t.processAccessor(new d.BufferAttribute(i,3)),ROTATION:t.processAccessor(new d.BufferAttribute(o,4)),SCALE:t.processAccessor(new d.BufferAttribute(a,3))};r.instanceColor&&(g._COLOR_0=t.processAccessor(r.instanceColor)),s.extensions=s.extensions||{},s.extensions[this.name]={attributes:g},t.extensionsUsed[this.name]=!0,t.extensionsRequired[this.name]=!0}}X.Utils={insertKeyframe:function(n,e){const t=n.getValueSize(),r=new n.TimeBufferType(n.times.length+1),i=new n.ValueBufferType(n.values.length+t),o=n.createInterpolant(new n.ValueBufferType(t));let a;if(n.times.length===0){r[0]=e;for(let c=0;c<t;c++)i[c]=0;a=0}else if(e<n.times[0]){if(Math.abs(n.times[0]-e)<.001)return 0;r[0]=e,r.set(n.times,1),i.set(o.evaluate(e),0),i.set(n.values,t),a=0}else if(e>n.times[n.times.length-1]){if(Math.abs(n.times[n.times.length-1]-e)<.001)return n.times.length-1;r[r.length-1]=e,r.set(n.times,0),i.set(n.values,0),i.set(o.evaluate(e),n.values.length),a=r.length-1}else for(let c=0;c<n.times.length;c++){if(Math.abs(n.times[c]-e)<.001)return c;if(n.times[c]<e&&n.times[c+1]>e){r.set(n.times.slice(0,c+1),0),r[c+1]=e,r.set(n.times.slice(c+1),c+2),i.set(n.values.slice(0,(c+1)*t),0),i.set(o.evaluate(e),(c+1)*t),i.set(n.values.slice((c+1)*t),(c+2)*t),a=c+1;break}}return n.times=r,n.values=i,a},mergeMorphTargetTracks:function(n,e){const s=[],t={},r=n.tracks;for(let i=0;i<r.length;++i){let o=r[i];const a=d.PropertyBinding.parseTrackName(o.name),c=d.PropertyBinding.findNode(e,a.nodeName);if(a.propertyName!=="morphTargetInfluences"||a.propertyIndex===void 0){s.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),o=o.clone(),o.setInterpolation(d.InterpolateLinear)}const u=c.morphTargetInfluences.length,p=c.morphTargetDictionary[a.propertyIndex];if(p===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+a.propertyIndex);let l;if(t[c.uuid]===void 0){l=o.clone();const f=new l.ValueBufferType(u*l.times.length);for(let h=0;h<l.times.length;h++)f[h*u+p]=l.values[h];l.name=(a.nodeName||"")+".morphTargetInfluences",l.values=f,t[c.uuid]=l,s.push(l);continue}const g=o.createInterpolant(new o.ValueBufferType(1));l=t[c.uuid];for(let f=0;f<l.times.length;f++)l.values[f*u+p]=g.evaluate(l.times[f]);for(let f=0;f<o.times.length;f++){const h=this.insertKeyframe(l,o.times[f]);l.values[h*u+p]=o.values[f]}}return n.tracks=s,n}};class Ue{async parse(e,s={}){s=Object.assign({ar:{anchoring:{type:"plane"},planeAnchoring:{alignment:"horizontal"}},quickLookCompatible:!1,maxTextureSize:1024},s);const t={},r="model.usda";t[r]=null;let i=oe();i+=$e(s);const o={},a={};e.traverseVisible(u=>{if(u.isMesh){const p=u.geometry,l=u.material;if(l.isMeshStandardMaterial){const g="geometries/Geometry_"+p.id+".usda";if(!(g in t)){const f=De(p);t[g]=Pe(f)}l.uuid in o||(o[l.uuid]=l),i+=Be(u,p,l)}else console.warn("THREE.USDZExporter: Unsupported material type (USDZ only supports MeshStandardMaterial)",u)}else u.isCamera&&(i+=We(u))}),i+=Oe(),i+=Ye(o,a,s.quickLookCompatible),t[r]=K.strToU8(i),i=null;for(const u in a){let p=a[u];p.isCompressedTexture===!0&&(p=k(p));const l=Fe(p.image,p.flipY,s.maxTextureSize),g=await new Promise(f=>l.toBlob(f,"image/png",1));t[`textures/Texture_${u}.png`]=new Uint8Array(await g.arrayBuffer())}let c=0;for(const u in t){const p=t[u],l=34+u.length;c+=l;const g=c&63;if(g!==4){const f=64-g,h=new Uint8Array(f);t[u]=[p,{extra:{12345:h}}]}c=p.length}return K.zipSync(t,{level:0})}}function Fe(n,e,s){if(typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas||typeof ImageBitmap<"u"&&n instanceof ImageBitmap){const t=s/Math.max(n.width,n.height),r=document.createElement("canvas");r.width=n.width*Math.min(1,t),r.height=n.height*Math.min(1,t);const i=r.getContext("2d");return e===!0&&(i.translate(0,r.height),i.scale(1,-1)),i.drawImage(n,0,0,r.width,r.height),r}else throw new Error("THREE.USDZExporter: No valid image data found. Unable to process texture.")}const E=7;function oe(){return`#usda 1.0
18
+ }`})),C.uniforms.blitTexture.value=n,C.defines.IS_SRGB=n.colorSpace==d.SRGBColorSpace,C.needsUpdate=!0,D||(D=new d.Mesh(V,C),D.frustumCulled=!1);const t=new d.PerspectiveCamera,r=new d.Scene;r.add(D),s===null&&(s=O=new d.WebGLRenderer({antialias:!1}));const i=Math.min(n.image.width,e),o=Math.min(n.image.height,e);s.setSize(i,o),s.clear(),s.render(r,t);const a=document.createElement("canvas"),c=a.getContext("2d");a.width=i,a.height=o,c.drawImage(s.domElement,0,0,i,o);const u=new d.CanvasTexture(a);return u.minFilter=n.minFilter,u.magFilter=n.magFilter,u.wrapS=n.wrapS,u.wrapT=n.wrapT,u.name=n.name,O&&(O.forceContextLoss(),O.dispose(),O=null),u}const Z={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class X{constructor(){this.pluginCallbacks=[],this.register(function(e){return new we(e)}),this.register(function(e){return new Ee(e)}),this.register(function(e){return new Ie(e)}),this.register(function(e){return new Re(e)}),this.register(function(e){return new Se(e)}),this.register(function(e){return new _e(e)}),this.register(function(e){return new be(e)}),this.register(function(e){return new Ae(e)}),this.register(function(e){return new Ne(e)}),this.register(function(e){return new Le(e)}),this.register(function(e){return new ve(e)}),this.register(function(e){return new Ce(e)}),this.register(function(e){return new Ue(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,s,t,r){const i=new ye,o=[];for(let a=0,c=this.pluginCallbacks.length;a<c;a++)o.push(this.pluginCallbacks[a](i));i.setPlugins(o),i.write(e,s,r).catch(t)}parseAsync(e,s){const t=this;return new Promise(function(r,i){t.parse(e,r,i,s)})}}const M={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},Y="KHR_mesh_quantization",S={};S[d.NearestFilter]=M.NEAREST;S[d.NearestMipmapNearestFilter]=M.NEAREST_MIPMAP_NEAREST;S[d.NearestMipmapLinearFilter]=M.NEAREST_MIPMAP_LINEAR;S[d.LinearFilter]=M.LINEAR;S[d.LinearMipmapNearestFilter]=M.LINEAR_MIPMAP_NEAREST;S[d.LinearMipmapLinearFilter]=M.LINEAR_MIPMAP_LINEAR;S[d.ClampToEdgeWrapping]=M.CLAMP_TO_EDGE;S[d.RepeatWrapping]=M.REPEAT;S[d.MirroredRepeatWrapping]=M.MIRRORED_REPEAT;const J={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},pe=new d.Color,Q=12,he=1179937895,de=2,ee=8,xe=1313821514,ge=5130562;function P(n,e){return n.length===e.length&&n.every(function(s,t){return s===e[t]})}function me(n){return new TextEncoder().encode(n).buffer}function Te(n){return P(n.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Me(n,e,s){const t={min:new Array(n.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(n.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let r=e;r<e+s;r++)for(let i=0;i<n.itemSize;i++){let o;n.itemSize>4?o=n.array[r*n.itemSize+i]:(i===0?o=n.getX(r):i===1?o=n.getY(r):i===2?o=n.getZ(r):i===3&&(o=n.getW(r)),n.normalized===!0&&(o=d.MathUtils.normalize(o,n.array))),t.min[i]=Math.min(t.min[i],o),t.max[i]=Math.max(t.max[i],o)}return t}function ie(n){return Math.ceil(n/4)*4}function j(n,e=0){const s=ie(n.byteLength);if(s!==n.byteLength){const t=new Uint8Array(s);if(t.set(new Uint8Array(n)),e!==0)for(let r=n.byteLength;r<s;r++)t[r]=e;return t.buffer}return n}function te(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function se(n,e){if(n.toBlob!==void 0)return new Promise(t=>n.toBlob(t,e));let s;return e==="image/jpeg"?s=.92:e==="image/webp"&&(s=.8),n.convertToBlob({type:e,quality:s})}class ye{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map}}setPlugins(e){this.plugins=e}async write(e,s,t={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},t),this.options.animations.length>0&&(this.options.trs=!0),this.processInput(e),await Promise.all(this.pending);const r=this,i=r.buffers,o=r.json;t=r.options;const a=r.extensionsUsed,c=r.extensionsRequired,u=new Blob(i,{type:"application/octet-stream"}),p=Object.keys(a),l=Object.keys(c);if(p.length>0&&(o.extensionsUsed=p),l.length>0&&(o.extensionsRequired=l),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=u.size),t.binary===!0){const g=new FileReader;g.readAsArrayBuffer(u),g.onloadend=function(){const f=j(g.result),h=new DataView(new ArrayBuffer(ee));h.setUint32(0,f.byteLength,!0),h.setUint32(4,ge,!0);const x=j(me(JSON.stringify(o)),32),m=new DataView(new ArrayBuffer(ee));m.setUint32(0,x.byteLength,!0),m.setUint32(4,xe,!0);const w=new ArrayBuffer(Q),_=new DataView(w);_.setUint32(0,he,!0),_.setUint32(4,de,!0);const B=Q+m.byteLength+x.byteLength+h.byteLength+f.byteLength;_.setUint32(8,B,!0);const T=new Blob([w,m,x,h,f],{type:"application/octet-stream"}),y=new FileReader;y.readAsArrayBuffer(T),y.onloadend=function(){s(y.result)}}}else if(o.buffers&&o.buffers.length>0){const g=new FileReader;g.readAsDataURL(u),g.onloadend=function(){const f=g.result;o.buffers[0].uri=f,s(o)}}else s(o)}serializeUserData(e,s){if(Object.keys(e.userData).length===0)return;const t=this.options,r=this.extensionsUsed;try{const i=JSON.parse(JSON.stringify(e.userData));if(t.includeCustomExtensions&&i.gltfExtensions){s.extensions===void 0&&(s.extensions={});for(const o in i.gltfExtensions)s.extensions[o]=i.gltfExtensions[o],r[o]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(s.extras=i)}catch(i){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+i.message)}}getUID(e,s=!1){if(this.uids.has(e)===!1){const r=new Map;r.set(!0,this.uid++),r.set(!1,this.uid++),this.uids.set(e,r)}return this.uids.get(e).get(s)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;const t=new d.Vector3;for(let r=0,i=e.count;r<i;r++)if(Math.abs(t.fromBufferAttribute(e,r).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){const s=this.cache;if(s.attributesNormalized.has(e))return s.attributesNormalized.get(e);const t=e.clone(),r=new d.Vector3;for(let i=0,o=t.count;i<o;i++)r.fromBufferAttribute(t,i),r.x===0&&r.y===0&&r.z===0?r.setX(1):r.normalize(),t.setXYZ(i,r.x,r.y,r.z);return s.attributesNormalized.set(e,t),t}applyTextureTransform(e,s){let t=!1;const r={};(s.offset.x!==0||s.offset.y!==0)&&(r.offset=s.offset.toArray(),t=!0),s.rotation!==0&&(r.rotation=s.rotation,t=!0),(s.repeat.x!==1||s.repeat.y!==1)&&(r.scale=s.repeat.toArray(),t=!0),t&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=r,this.extensionsUsed.KHR_texture_transform=!0)}buildMetalRoughTexture(e,s){if(e===s)return e;function t(f){return f.colorSpace===d.SRGBColorSpace?function(x){return x<.04045?x*.0773993808:Math.pow(x*.9478672986+.0521327014,2.4)}:function(x){return x}}console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),e instanceof d.CompressedTexture&&(e=k(e)),s instanceof d.CompressedTexture&&(s=k(s));const r=e?e.image:null,i=s?s.image:null,o=Math.max(r?r.width:0,i?i.width:0),a=Math.max(r?r.height:0,i?i.height:0),c=te();c.width=o,c.height=a;const u=c.getContext("2d");u.fillStyle="#00ffff",u.fillRect(0,0,o,a);const p=u.getImageData(0,0,o,a);if(r){u.drawImage(r,0,0,o,a);const f=t(e),h=u.getImageData(0,0,o,a).data;for(let x=2;x<h.length;x+=4)p.data[x]=f(h[x]/256)*256}if(i){u.drawImage(i,0,0,o,a);const f=t(s),h=u.getImageData(0,0,o,a).data;for(let x=1;x<h.length;x+=4)p.data[x]=f(h[x]/256)*256}u.putImageData(p,0,0);const g=(e||s).clone();return g.source=new d.Source(c),g.colorSpace=d.NoColorSpace,g.channel=(e||s).channel,e&&s&&e.channel!==s.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),g}processBuffer(e){const s=this.json,t=this.buffers;return s.buffers||(s.buffers=[{byteLength:0}]),t.push(e),0}processBufferView(e,s,t,r,i){const o=this.json;o.bufferViews||(o.bufferViews=[]);let a;switch(s){case M.BYTE:case M.UNSIGNED_BYTE:a=1;break;case M.SHORT:case M.UNSIGNED_SHORT:a=2;break;default:a=4}let c=e.itemSize*a;i===M.ARRAY_BUFFER&&(c=Math.ceil(c/4)*4);const u=ie(r*c),p=new DataView(new ArrayBuffer(u));let l=0;for(let h=t;h<t+r;h++){for(let x=0;x<e.itemSize;x++){let m;e.itemSize>4?m=e.array[h*e.itemSize+x]:(x===0?m=e.getX(h):x===1?m=e.getY(h):x===2?m=e.getZ(h):x===3&&(m=e.getW(h)),e.normalized===!0&&(m=d.MathUtils.normalize(m,e.array))),s===M.FLOAT?p.setFloat32(l,m,!0):s===M.INT?p.setInt32(l,m,!0):s===M.UNSIGNED_INT?p.setUint32(l,m,!0):s===M.SHORT?p.setInt16(l,m,!0):s===M.UNSIGNED_SHORT?p.setUint16(l,m,!0):s===M.BYTE?p.setInt8(l,m):s===M.UNSIGNED_BYTE&&p.setUint8(l,m),l+=a}l%c!==0&&(l+=c-l%c)}const g={buffer:this.processBuffer(p.buffer),byteOffset:this.byteOffset,byteLength:u};return i!==void 0&&(g.target=i),i===M.ARRAY_BUFFER&&(g.byteStride=c),this.byteOffset+=u,o.bufferViews.push(g),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const s=this,t=s.json;return t.bufferViews||(t.bufferViews=[]),new Promise(function(r){const i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){const o=j(i.result),a={buffer:s.processBuffer(o),byteOffset:s.byteOffset,byteLength:o.byteLength};s.byteOffset+=o.byteLength,r(t.bufferViews.push(a)-1)}})}processAccessor(e,s,t,r){const i=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"};let a;if(e.array.constructor===Float32Array)a=M.FLOAT;else if(e.array.constructor===Int32Array)a=M.INT;else if(e.array.constructor===Uint32Array)a=M.UNSIGNED_INT;else if(e.array.constructor===Int16Array)a=M.SHORT;else if(e.array.constructor===Uint16Array)a=M.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)a=M.BYTE;else if(e.array.constructor===Uint8Array)a=M.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(t===void 0&&(t=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;const c=Me(e,t,r);let u;s!==void 0&&(u=e===s.index?M.ELEMENT_ARRAY_BUFFER:M.ARRAY_BUFFER);const p=this.processBufferView(e,a,t,r,u),l={bufferView:p.id,byteOffset:p.byteOffset,componentType:a,count:r,max:c.max,min:c.min,type:o[e.itemSize]};return e.normalized===!0&&(l.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(l)-1}processImage(e,s,t,r="image/png"){if(e!==null){const i=this,o=i.cache,a=i.json,c=i.options,u=i.pending;o.images.has(e)||o.images.set(e,{});const p=o.images.get(e),l=r+":flipY/"+t.toString();if(p[l]!==void 0)return p[l];a.images||(a.images=[]);const g={mimeType:r},f=te();f.width=Math.min(e.width,c.maxTextureSize),f.height=Math.min(e.height,c.maxTextureSize);const h=f.getContext("2d");if(t===!0&&(h.translate(0,f.height),h.scale(1,-1)),e.data!==void 0){s!==d.RGBAFormat&&console.error("GLTFExporter: Only RGBAFormat is supported.",s),(e.width>c.maxTextureSize||e.height>c.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);const m=new Uint8ClampedArray(e.height*e.width*4);for(let w=0;w<m.length;w+=4)m[w+0]=e.data[w+0],m[w+1]=e.data[w+1],m[w+2]=e.data[w+2],m[w+3]=e.data[w+3];h.putImageData(new ImageData(m,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)h.drawImage(e,0,0,f.width,f.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");c.binary===!0?u.push(se(f,r).then(m=>i.processBufferViewImage(m)).then(m=>{g.bufferView=m})):f.toDataURL!==void 0?g.uri=f.toDataURL(r):u.push(se(f,r).then(m=>new FileReader().readAsDataURL(m)).then(m=>{g.uri=m}));const x=a.images.push(g)-1;return p[l]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const s=this.json;s.samplers||(s.samplers=[]);const t={magFilter:S[e.magFilter],minFilter:S[e.minFilter],wrapS:S[e.wrapS],wrapT:S[e.wrapT]};return s.samplers.push(t)-1}processTexture(e){const t=this.options,r=this.cache,i=this.json;if(r.textures.has(e))return r.textures.get(e);i.textures||(i.textures=[]),e instanceof d.CompressedTexture&&(e=k(e,t.maxTextureSize));let o=e.userData.mimeType;o==="image/webp"&&(o="image/png");const a={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,o)};e.name&&(a.name=e.name),this._invokeAll(function(u){u.writeTexture&&u.writeTexture(e,a)});const c=i.textures.push(a)-1;return r.textures.set(e,c),c}processMaterial(e){const s=this.cache,t=this.json;if(s.materials.has(e))return s.materials.get(e);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;t.materials||(t.materials=[]);const r={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");const i=e.color.toArray().concat([e.opacity]);if(P(i,[1,1,1,1])||(r.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(r.pbrMetallicRoughness.metallicFactor=e.metalness,r.pbrMetallicRoughness.roughnessFactor=e.roughness):(r.pbrMetallicRoughness.metallicFactor=.5,r.pbrMetallicRoughness.roughnessFactor=.5),e.metalnessMap||e.roughnessMap){const a=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),c={index:this.processTexture(a),channel:a.channel};this.applyTextureTransform(c,a),r.pbrMetallicRoughness.metallicRoughnessTexture=c}if(e.map){const a={index:this.processTexture(e.map),texCoord:e.map.channel};this.applyTextureTransform(a,e.map),r.pbrMetallicRoughness.baseColorTexture=a}if(e.emissive){const a=e.emissive;if(Math.max(a.r,a.g,a.b)>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){const u={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(u,e.emissiveMap),r.emissiveTexture=u}}if(e.normalMap){const a={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(a.scale=e.normalScale.x),this.applyTextureTransform(a,e.normalMap),r.normalTexture=a}if(e.aoMap){const a={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(a.strength=e.aoMapIntensity),this.applyTextureTransform(a,e.aoMap),r.occlusionTexture=a}e.transparent?r.alphaMode="BLEND":e.alphaTest>0&&(r.alphaMode="MASK",r.alphaCutoff=e.alphaTest),e.side===d.DoubleSide&&(r.doubleSided=!0),e.name!==""&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(a){a.writeMaterial&&a.writeMaterial(e,r)});const o=t.materials.push(r)-1;return s.materials.set(e,o),o}processMesh(e){const s=this.cache,t=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let T=0,y=e.material.length;T<y;T++)r.push(e.material[T].uuid);else r.push(e.material.uuid);const i=r.join(":");if(s.meshes.has(i))return s.meshes.get(i);const o=e.geometry;let a;e.isLineSegments?a=M.LINES:e.isLineLoop?a=M.LINE_LOOP:e.isLine?a=M.LINE_STRIP:e.isPoints?a=M.POINTS:a=e.material.wireframe?M.LINES:M.TRIANGLES;const c={},u={},p=[],l=[],g={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},f=o.getAttribute("normal");f!==void 0&&!this.isNormalizedNormalAttribute(f)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(f)));let h=null;for(let T in o.attributes){if(T.slice(0,5)==="morph")continue;const y=o.attributes[T];if(T=g[T]||T.toUpperCase(),/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(T)||(T="_"+T),s.attributes.has(this.getUID(y))){u[T]=s.attributes.get(this.getUID(y));continue}h=null;const A=y.array;T==="JOINTS_0"&&!(A instanceof Uint16Array)&&!(A instanceof Uint8Array)&&(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),h=new d.BufferAttribute(new Uint16Array(A),y.itemSize,y.normalized));const R=this.processAccessor(h||y,o);R!==null&&(T.startsWith("_")||this.detectMeshQuantization(T,y),u[T]=R,s.attributes.set(this.getUID(y),R))}if(f!==void 0&&o.setAttribute("normal",f),Object.keys(u).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const T=[],y=[],b={};if(e.morphTargetDictionary!==void 0)for(const A in e.morphTargetDictionary)b[e.morphTargetDictionary[A]]=A;for(let A=0;A<e.morphTargetInfluences.length;++A){const R={};let q=!1;for(const U in o.morphAttributes){if(U!=="position"&&U!=="normal"){q||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),q=!0);continue}const N=o.morphAttributes[U][A],z=U.toUpperCase(),F=o.attributes[U];if(s.attributes.has(this.getUID(N,!0))){R[z]=s.attributes.get(this.getUID(N,!0));continue}const $=N.clone();if(!o.morphTargetsRelative)for(let I=0,ce=N.count;I<ce;I++)for(let v=0;v<N.itemSize;v++)v===0&&$.setX(I,N.getX(I)-F.getX(I)),v===1&&$.setY(I,N.getY(I)-F.getY(I)),v===2&&$.setZ(I,N.getZ(I)-F.getZ(I)),v===3&&$.setW(I,N.getW(I)-F.getW(I));R[z]=this.processAccessor($,o),s.attributes.set(this.getUID(F,!0),R[z])}l.push(R),T.push(e.morphTargetInfluences[A]),e.morphTargetDictionary!==void 0&&y.push(b[A])}c.weights=T,y.length>0&&(c.extras={},c.extras.targetNames=y)}const x=Array.isArray(e.material);if(x&&o.groups.length===0)return null;let m=!1;if(x&&o.index===null){const T=[];for(let y=0,b=o.attributes.position.count;y<b;y++)T[y]=y;o.setIndex(T),m=!0}const w=x?e.material:[e.material],_=x?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let T=0,y=_.length;T<y;T++){const b={mode:a,attributes:u};if(this.serializeUserData(o,b),l.length>0&&(b.targets=l),o.index!==null){let R=this.getUID(o.index);(_[T].start!==void 0||_[T].count!==void 0)&&(R+=":"+_[T].start+":"+_[T].count),s.attributes.has(R)?b.indices=s.attributes.get(R):(b.indices=this.processAccessor(o.index,o,_[T].start,_[T].count),s.attributes.set(R,b.indices)),b.indices===null&&delete b.indices}const A=this.processMaterial(w[_[T].materialIndex]);A!==null&&(b.material=A),p.push(b)}m===!0&&o.setIndex(null),c.primitives=p,t.meshes||(t.meshes=[]),this._invokeAll(function(T){T.writeMesh&&T.writeMesh(e,c)});const B=t.meshes.push(c)-1;return s.meshes.set(i,B),B}detectMeshQuantization(e,s){if(this.extensionsUsed[Y])return;let t;switch(s.array.constructor){case Int8Array:t="byte";break;case Uint8Array:t="unsigned byte";break;case Int16Array:t="short";break;case Uint16Array:t="unsigned short";break;default:return}s.normalized&&(t+=" normalized");const r=e.split("_",1)[0];Z[r]&&Z[r].includes(t)&&(this.extensionsUsed[Y]=!0,this.extensionsRequired[Y]=!0)}processCamera(e){const s=this.json;s.cameras||(s.cameras=[]);const t=e.isOrthographicCamera,r={type:t?"orthographic":"perspective"};return t?r.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(r.name=e.type),s.cameras.push(r)-1}processAnimation(e,s){const t=this.json,r=this.nodeMap;t.animations||(t.animations=[]),e=X.Utils.mergeMorphTargetTracks(e.clone(),s);const i=e.tracks,o=[],a=[];for(let c=0;c<i.length;++c){const u=i[c],p=d.PropertyBinding.parseTrackName(u.name);let l=d.PropertyBinding.findNode(s,p.nodeName);const g=J[p.propertyName];if(p.objectName==="bones"&&(l.isSkinnedMesh===!0?l=l.skeleton.getBoneByName(p.objectIndex):l=void 0),!l||!g)return console.warn('THREE.GLTFExporter: Could not export animation track "%s".',u.name),null;const f=1;let h=u.values.length/u.times.length;g===J.morphTargetInfluences&&(h/=l.morphTargetInfluences.length);let x;u.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(x="CUBICSPLINE",h/=3):u.getInterpolation()===d.InterpolateDiscrete?x="STEP":x="LINEAR",a.push({input:this.processAccessor(new d.BufferAttribute(u.times,f)),output:this.processAccessor(new d.BufferAttribute(u.values,h)),interpolation:x}),o.push({sampler:a.length-1,target:{node:r.get(l),path:g}})}return t.animations.push({name:e.name||"clip_"+t.animations.length,samplers:a,channels:o}),t.animations.length-1}processSkin(e){const s=this.json,t=this.nodeMap,r=s.nodes[t.get(e)],i=e.skeleton;if(i===void 0)return null;const o=e.skeleton.bones[0];if(o===void 0)return null;const a=[],c=new Float32Array(i.bones.length*16),u=new d.Matrix4;for(let l=0;l<i.bones.length;++l)a.push(t.get(i.bones[l])),u.copy(i.boneInverses[l]),u.multiply(e.bindMatrix).toArray(c,l*16);return s.skins===void 0&&(s.skins=[]),s.skins.push({inverseBindMatrices:this.processAccessor(new d.BufferAttribute(c,16)),joints:a,skeleton:t.get(o)}),r.skin=s.skins.length-1}processNode(e){const s=this.json,t=this.options,r=this.nodeMap;s.nodes||(s.nodes=[]);const i={};if(t.trs){const a=e.quaternion.toArray(),c=e.position.toArray(),u=e.scale.toArray();P(a,[0,0,0,1])||(i.rotation=a),P(c,[0,0,0])||(i.translation=c),P(u,[1,1,1])||(i.scale=u)}else e.matrixAutoUpdate&&e.updateMatrix(),Te(e.matrix)===!1&&(i.matrix=e.matrix.elements);if(e.name!==""&&(i.name=String(e.name)),this.serializeUserData(e,i),e.isMesh||e.isLine||e.isPoints){const a=this.processMesh(e);a!==null&&(i.mesh=a)}else e.isCamera&&(i.camera=this.processCamera(e));if(e.isSkinnedMesh&&this.skins.push(e),e.children.length>0){const a=[];for(let c=0,u=e.children.length;c<u;c++){const p=e.children[c];if(p.visible||t.onlyVisible===!1){const l=this.processNode(p);l!==null&&a.push(l)}}a.length>0&&(i.children=a)}this._invokeAll(function(a){a.writeNode&&a.writeNode(e,i)});const o=s.nodes.push(i)-1;return r.set(e,o),o}processScene(e){const s=this.json,t=this.options;s.scenes||(s.scenes=[],s.scene=0);const r={};e.name!==""&&(r.name=e.name),s.scenes.push(r);const i=[];for(let o=0,a=e.children.length;o<a;o++){const c=e.children[o];if(c.visible||t.onlyVisible===!1){const u=this.processNode(c);u!==null&&i.push(u)}}i.length>0&&(r.nodes=i),this.serializeUserData(e,r)}processObjects(e){const s=new d.Scene;s.name="AuxScene";for(let t=0;t<e.length;t++)s.children.push(e[t]);this.processScene(s)}processInput(e){const s=this.options;e=e instanceof Array?e:[e],this._invokeAll(function(r){r.beforeParse&&r.beforeParse(e)});const t=[];for(let r=0;r<e.length;r++)e[r]instanceof d.Scene?this.processScene(e[r]):t.push(e[r]);t.length>0&&this.processObjects(t);for(let r=0;r<this.skins.length;++r)this.processSkin(this.skins[r]);for(let r=0;r<s.animations.length;++r)this.processAnimation(s.animations[r],e[0]);this._invokeAll(function(r){r.afterParse&&r.afterParse(e)})}_invokeAll(e){for(let s=0,t=this.plugins.length;s<t;s++)e(this.plugins[s])}}class we{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,s){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}const t=this.writer,r=t.json,i=t.extensionsUsed,o={};e.name&&(o.name=e.name),o.color=e.color.toArray(),o.intensity=e.intensity,e.isDirectionalLight?o.type="directional":e.isPointLight?(o.type="point",e.distance>0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),i[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},i[this.name]=!0);const a=r.extensions[this.name].lights;a.push(o),s.extensions=s.extensions||{},s.extensions[this.name]={light:a.length-1}}}class Ee{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,s){if(!e.isMeshBasicMaterial)return;const r=this.writer.extensionsUsed;s.extensions=s.extensions||{},s.extensions[this.name]={},r[this.name]=!0,s.pbrMetallicRoughness.metallicFactor=0,s.pbrMetallicRoughness.roughnessFactor=.9}}class be{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){const o={index:t.processTexture(e.clearcoatMap),texCoord:e.clearcoatMap.channel};t.applyTextureTransform(o,e.clearcoatMap),i.clearcoatTexture=o}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const o={index:t.processTexture(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};t.applyTextureTransform(o,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){const o={index:t.processTexture(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};t.applyTextureTransform(o,e.clearcoatNormalMap),i.clearcoatNormalTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ae{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){const o={index:t.processTexture(e.iridescenceMap),texCoord:e.iridescenceMap.channel};t.applyTextureTransform(o,e.iridescenceMap),i.iridescenceTexture=o}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const o={index:t.processTexture(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};t.applyTextureTransform(o,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ie{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){const o={index:t.processTexture(e.transmissionMap),texCoord:e.transmissionMap.channel};t.applyTextureTransform(o,e.transmissionMap),i.transmissionTexture=o}s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Re{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const t=this.writer,r=t.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){const o={index:t.processTexture(e.thicknessMap),texCoord:e.thicknessMap.channel};t.applyTextureTransform(o,e.thicknessMap),i.thicknessTexture=o}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Se{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;const r=this.writer.extensionsUsed,i={};i.ior=e.ior,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class _e{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(pe)&&!e.specularIntensityMap&&!e.specularColorMap)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.specularIntensityMap){const o={index:t.processTexture(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};t.applyTextureTransform(o,e.specularIntensityMap),i.specularTexture=o}if(e.specularColorMap){const o={index:t.processTexture(e.specularColorMap),texCoord:e.specularColorMap.channel};t.applyTextureTransform(o,e.specularColorMap),i.specularColorTexture=o}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ne{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.sheenRoughnessMap){const o={index:t.processTexture(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};t.applyTextureTransform(o,e.sheenRoughnessMap),i.sheenRoughnessTexture=o}if(e.sheenColorMap){const o={index:t.processTexture(e.sheenColorMap),texCoord:e.sheenColorMap.channel};t.applyTextureTransform(o,e.sheenColorMap),i.sheenColorTexture=o}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Le{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,s){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.anisotropyMap){const o={index:t.processTexture(e.anisotropyMap)};t.applyTextureTransform(o,e.anisotropyMap),i.anisotropyTexture=o}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class ve{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,s){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;const r=this.writer.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ce{constructor(e){this.writer=e,this.name="EXT_materials_bump"}writeMaterial(e,s){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;const t=this.writer,r=t.extensionsUsed,i={};if(e.bumpMap){const o={index:t.processTexture(e.bumpMap),texCoord:e.bumpMap.channel};t.applyTextureTransform(o,e.bumpMap),i.bumpTexture=o}i.bumpFactor=e.bumpScale,s.extensions=s.extensions||{},s.extensions[this.name]=i,r[this.name]=!0}}class Ue{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,s){if(!e.isInstancedMesh)return;const t=this.writer,r=e,i=new Float32Array(r.count*3),o=new Float32Array(r.count*4),a=new Float32Array(r.count*3),c=new d.Matrix4,u=new d.Vector3,p=new d.Quaternion,l=new d.Vector3;for(let f=0;f<r.count;f++)r.getMatrixAt(f,c),c.decompose(u,p,l),u.toArray(i,f*3),p.toArray(o,f*4),l.toArray(a,f*3);const g={TRANSLATION:t.processAccessor(new d.BufferAttribute(i,3)),ROTATION:t.processAccessor(new d.BufferAttribute(o,4)),SCALE:t.processAccessor(new d.BufferAttribute(a,3))};r.instanceColor&&(g._COLOR_0=t.processAccessor(r.instanceColor)),s.extensions=s.extensions||{},s.extensions[this.name]={attributes:g},t.extensionsUsed[this.name]=!0,t.extensionsRequired[this.name]=!0}}X.Utils={insertKeyframe:function(n,e){const t=n.getValueSize(),r=new n.TimeBufferType(n.times.length+1),i=new n.ValueBufferType(n.values.length+t),o=n.createInterpolant(new n.ValueBufferType(t));let a;if(n.times.length===0){r[0]=e;for(let c=0;c<t;c++)i[c]=0;a=0}else if(e<n.times[0]){if(Math.abs(n.times[0]-e)<.001)return 0;r[0]=e,r.set(n.times,1),i.set(o.evaluate(e),0),i.set(n.values,t),a=0}else if(e>n.times[n.times.length-1]){if(Math.abs(n.times[n.times.length-1]-e)<.001)return n.times.length-1;r[r.length-1]=e,r.set(n.times,0),i.set(n.values,0),i.set(o.evaluate(e),n.values.length),a=r.length-1}else for(let c=0;c<n.times.length;c++){if(Math.abs(n.times[c]-e)<.001)return c;if(n.times[c]<e&&n.times[c+1]>e){r.set(n.times.slice(0,c+1),0),r[c+1]=e,r.set(n.times.slice(c+1),c+2),i.set(n.values.slice(0,(c+1)*t),0),i.set(o.evaluate(e),(c+1)*t),i.set(n.values.slice((c+1)*t),(c+2)*t),a=c+1;break}}return n.times=r,n.values=i,a},mergeMorphTargetTracks:function(n,e){const s=[],t={},r=n.tracks;for(let i=0;i<r.length;++i){let o=r[i];const a=d.PropertyBinding.parseTrackName(o.name),c=d.PropertyBinding.findNode(e,a.nodeName);if(a.propertyName!=="morphTargetInfluences"||a.propertyIndex===void 0){s.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),o=o.clone(),o.setInterpolation(d.InterpolateLinear)}const u=c.morphTargetInfluences.length,p=c.morphTargetDictionary[a.propertyIndex];if(p===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+a.propertyIndex);let l;if(t[c.uuid]===void 0){l=o.clone();const f=new l.ValueBufferType(u*l.times.length);for(let h=0;h<l.times.length;h++)f[h*u+p]=l.values[h];l.name=(a.nodeName||"")+".morphTargetInfluences",l.values=f,t[c.uuid]=l,s.push(l);continue}const g=o.createInterpolant(new o.ValueBufferType(1));l=t[c.uuid];for(let f=0;f<l.times.length;f++)l.values[f*u+p]=g.evaluate(l.times[f]);for(let f=0;f<o.times.length;f++){const h=this.insertKeyframe(l,o.times[f]);l.values[h*u+p]=o.values[f]}}return n.tracks=s,n}};class Fe{async parse(e,s={}){s=Object.assign({ar:{anchoring:{type:"plane"},planeAnchoring:{alignment:"horizontal"}},quickLookCompatible:!1,maxTextureSize:1024},s);const t={},r="model.usda";t[r]=null;let i=oe();i+=Oe(s);const o={},a={};e.traverseVisible(u=>{if(u.isMesh){const p=u.geometry,l=u.material;if(l.isMeshStandardMaterial){const g="geometries/Geometry_"+p.id+".usda";if(!(g in t)){const f=Ge(p);t[g]=Be(f)}l.uuid in o||(o[l.uuid]=l),i+=De(u,p,l)}else console.warn("THREE.USDZExporter: Unsupported material type (USDZ only supports MeshStandardMaterial)",u)}else u.isCamera&&(i+=Xe(u))}),i+=Pe(),i+=je(o,a,s.quickLookCompatible),t[r]=K.strToU8(i),i=null;for(const u in a){let p=a[u];p.isCompressedTexture===!0&&(p=k(p));const l=$e(p.image,p.flipY,s.maxTextureSize),g=await new Promise(f=>l.toBlob(f,"image/png",1));t[`textures/Texture_${u}.png`]=new Uint8Array(await g.arrayBuffer())}let c=0;for(const u in t){const p=t[u],l=34+u.length;c+=l;const g=c&63;if(g!==4){const f=64-g,h=new Uint8Array(f);t[u]=[p,{extra:{12345:h}}]}c=p.length}return K.zipSync(t,{level:0})}}function $e(n,e,s){if(typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas||typeof ImageBitmap<"u"&&n instanceof ImageBitmap){const t=s/Math.max(n.width,n.height),r=document.createElement("canvas");r.width=n.width*Math.min(1,t),r.height=n.height*Math.min(1,t);const i=r.getContext("2d");return e===!0&&(i.translate(0,r.height),i.scale(1,-1)),i.drawImage(n,0,0,r.width,r.height),r}else throw new Error("THREE.USDZExporter: No valid image data found. Unable to process texture.")}const E=7;function oe(){return`#usda 1.0
19
19
  (
20
20
  customLayerData = {
21
21
  string creator = "Three.js USDZExporter"
@@ -25,7 +25,7 @@
25
25
  upAxis = "Y"
26
26
  )
27
27
 
28
- `}function $e(n){return`def Xform "Root"
28
+ `}function Oe(n){return`def Xform "Root"
29
29
  {
30
30
  def Scope "Scenes" (
31
31
  kind = "sceneLibrary"
@@ -42,12 +42,12 @@
42
42
  token preliminary:anchoring:type = "${n.ar.anchoring.type}"
43
43
  token preliminary:planeAnchoring:alignment = "${n.ar.planeAnchoring.alignment}"
44
44
 
45
- `}function Oe(){return`
45
+ `}function Pe(){return`
46
46
  }
47
47
  }
48
48
  }
49
49
 
50
- `}function Pe(n){let e=oe();return e+=n,K.strToU8(e)}function Be(n,e,s){const t="Object_"+n.id,r=ae(n.matrixWorld);return n.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",n),`def Xform "${t}" (
50
+ `}function Be(n){let e=oe();return e+=n,K.strToU8(e)}function De(n,e,s){const t="Object_"+n.id,r=ae(n.matrixWorld);return n.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",n),`def Xform "${t}" (
51
51
  prepend references = @./geometries/Geometry_${e.id}.usda@</Geometry>
52
52
  prepend apiSchemas = ["MaterialBindingAPI"]
53
53
  )
@@ -58,35 +58,35 @@
58
58
  rel material:binding = </Materials/Material_${s.id}>
59
59
  }
60
60
 
61
- `}function ae(n){const e=n.elements;return`( ${G(e,0)}, ${G(e,4)}, ${G(e,8)}, ${G(e,12)} )`}function G(n,e){return`(${n[e+0]}, ${n[e+1]}, ${n[e+2]}, ${n[e+3]})`}function De(n){return`
61
+ `}function ae(n){const e=n.elements;return`( ${G(e,0)}, ${G(e,4)}, ${G(e,8)}, ${G(e,12)} )`}function G(n,e){return`(${n[e+0]}, ${n[e+1]}, ${n[e+2]}, ${n[e+3]})`}function Ge(n){return`
62
62
  def "Geometry"
63
63
  {
64
- ${Ge(n)}
64
+ ${ke(n)}
65
65
  }
66
- `}function Ge(n){const e="Geometry",s=n.attributes,t=s.position.count;return`
66
+ `}function ke(n){const e="Geometry",s=n.attributes,t=s.position.count;return`
67
67
  def Mesh "${e}"
68
68
  {
69
- int[] faceVertexCounts = [${ke(n)}]
70
- int[] faceVertexIndices = [${ze(n)}]
69
+ int[] faceVertexCounts = [${ze(n)}]
70
+ int[] faceVertexIndices = [${He(n)}]
71
71
  normal3f[] normals = [${W(s.normal,t)}] (
72
72
  interpolation = "vertex"
73
73
  )
74
74
  point3f[] points = [${W(s.position,t)}]
75
- ${Ve(s)}
75
+ ${Ye(s)}
76
76
  uniform token subdivisionScheme = "none"
77
77
  }
78
- `}function ke(n){const e=n.index!==null?n.index.count:n.attributes.position.count;return Array(e/3).fill(3).join(", ")}function ze(n){const e=n.index,s=[];if(e!==null)for(let t=0;t<e.count;t++)s.push(e.getX(t));else{const t=n.attributes.position.count;for(let r=0;r<t;r++)s.push(r)}return s.join(", ")}function W(n,e){if(n===void 0)return console.warn("USDZExporter: Normals missing."),Array(e).fill("(0, 0, 0)").join(", ");const s=[];for(let t=0;t<n.count;t++){const r=n.getX(t),i=n.getY(t),o=n.getZ(t);s.push(`(${r.toPrecision(E)}, ${i.toPrecision(E)}, ${o.toPrecision(E)})`)}return s.join(", ")}function He(n){const e=[];for(let s=0;s<n.count;s++){const t=n.getX(s),r=n.getY(s);e.push(`(${t.toPrecision(E)}, ${1-r.toPrecision(E)})`)}return e.join(", ")}function Ve(n){let e="";for(let t=0;t<4;t++){const r=t>0?t:"",i=n["uv"+r];i!==void 0&&(e+=`
79
- texCoord2f[] primvars:st${r} = [${He(i)}] (
78
+ `}function ze(n){const e=n.index!==null?n.index.count:n.attributes.position.count;return Array(e/3).fill(3).join(", ")}function He(n){const e=n.index,s=[];if(e!==null)for(let t=0;t<e.count;t++)s.push(e.getX(t));else{const t=n.attributes.position.count;for(let r=0;r<t;r++)s.push(r)}return s.join(", ")}function W(n,e){if(n===void 0)return console.warn("USDZExporter: Normals missing."),Array(e).fill("(0, 0, 0)").join(", ");const s=[];for(let t=0;t<n.count;t++){const r=n.getX(t),i=n.getY(t),o=n.getZ(t);s.push(`(${r.toPrecision(E)}, ${i.toPrecision(E)}, ${o.toPrecision(E)})`)}return s.join(", ")}function Ve(n){const e=[];for(let s=0;s<n.count;s++){const t=n.getX(s),r=n.getY(s);e.push(`(${t.toPrecision(E)}, ${1-r.toPrecision(E)})`)}return e.join(", ")}function Ye(n){let e="";for(let t=0;t<4;t++){const r=t>0?t:"",i=n["uv"+r];i!==void 0&&(e+=`
79
+ texCoord2f[] primvars:st${r} = [${Ve(i)}] (
80
80
  interpolation = "vertex"
81
81
  )`)}const s=n.color;if(s!==void 0){const t=s.count;e+=`
82
82
  color3f[] primvars:displayColor = [${W(s,t)}] (
83
83
  interpolation = "vertex"
84
- )`}return e}function Ye(n,e,s=!1){const t=[];for(const r in n){const i=n[r];t.push(je(i,e,s))}return`def "Materials"
84
+ )`}return e}function je(n,e,s=!1){const t=[];for(const r in n){const i=n[r];t.push(Ke(i,e,s))}return`def "Materials"
85
85
  {
86
86
  ${t.join("")}
87
87
  }
88
88
 
89
- `}function je(n,e,s=!1){const t=" ",r=[],i=[];function o(a,c,u){const p=a.source.id+"_"+a.flipY;e[p]=a;const l=a.channel>0?"st"+a.channel:"st",g={1e3:"repeat",1001:"clamp",1002:"mirror"},f=a.repeat.clone(),h=a.offset.clone(),x=a.rotation,m=Math.sin(x),w=Math.cos(x);return h.y=1-h.y-f.y,s?(h.x=h.x/f.x,h.y=h.y/f.y,h.x+=m/f.x,h.y+=w-1):(h.x+=m*f.x,h.y+=(1-w)*f.y),`
89
+ `}function Ke(n,e,s=!1){const t=" ",r=[],i=[];function o(a,c,u){const p=a.source.id+"_"+a.flipY;e[p]=a;const l=a.channel>0?"st"+a.channel:"st",g={1e3:"repeat",1001:"clamp",1002:"mirror"},f=a.repeat.clone(),h=a.offset.clone(),x=a.rotation,m=Math.sin(x),w=Math.cos(x);return h.y=1-h.y-f.y,s?(h.x=h.x/f.x,h.y=h.y/f.y,h.x+=m/f.x,h.y+=w-1):(h.x+=m*f.x,h.y+=(1-w)*f.y),`
90
90
  def Shader "PrimvarReader_${c}"
91
91
  {
92
92
  uniform token info:id = "UsdPrimvarReader_float2"
@@ -110,7 +110,7 @@ ${t.join("")}
110
110
  uniform token info:id = "UsdUVTexture"
111
111
  asset inputs:file = @textures/Texture_${p}.png@
112
112
  float2 inputs:st.connect = </Materials/Material_${n.id}/Transform2d_${c}.outputs:result>
113
- ${u!==void 0?"float4 inputs:scale = "+Ke(u):""}
113
+ ${u!==void 0?"float4 inputs:scale = "+We(u):""}
114
114
  token inputs:sourceColorSpace = "${a.colorSpace===d.NoColorSpace?"raw":"sRGB"}"
115
115
  token inputs:wrapS = "${g[a.wrapS]}"
116
116
  token inputs:wrapT = "${g[a.wrapT]}"
@@ -137,7 +137,7 @@ ${i.join(`
137
137
  `)}
138
138
 
139
139
  }
140
- `}function ne(n){return`(${n.r}, ${n.g}, ${n.b})`}function Ke(n){return`(${n.r}, ${n.g}, ${n.b}, 1.0)`}function re(n){return`(${n.x}, ${n.y})`}function We(n){const e=n.name?n.name:"Camera_"+n.id,s=ae(n.matrixWorld);return n.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",n),n.isOrthographicCamera?`def Camera "${e}"
140
+ `}function ne(n){return`(${n.r}, ${n.g}, ${n.b})`}function We(n){return`(${n.r}, ${n.g}, ${n.b}, 1.0)`}function re(n){return`(${n.x}, ${n.y})`}function Xe(n){const e=n.name?n.name:"Camera_"+n.id,s=ae(n.matrixWorld);return n.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",n),n.isOrthographicCamera?`def Camera "${e}"
141
141
  {
142
142
  matrix4d xformOp:transform = ${s}
143
143
  uniform token[] xformOpOrder = ["xformOp:transform"]
@@ -161,4 +161,4 @@ ${i.join(`
161
161
  float verticalAperture = ${n.getFilmHeight().toPrecision(E)}
162
162
  }
163
163
 
164
- `}class Xe{constructor(){H(this,"_gltfExporter");H(this,"_usdzExporter");this._gltfExporter=new X,this._usdzExporter=new Ue}async export(e,s,t){switch(s){case"glb":return this._exportGlb(e,t);case"gltf":return this._exportGltf(e,t);case"usdz":return this._exportUsdz(e,t);default:throw new L.FileTypeError(`Unsupported file type: ${s}`,s)}}async _exportGlb(e,s){try{const t=await this._gltfExporter.parseAsync(e,{...s,binary:!0});if(t instanceof ArrayBuffer)return t;throw new L.ParseError("Failed to export GLB: expected ArrayBuffer")}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export GLB",t)}}async _exportGltf(e,s){try{const t=await this._gltfExporter.parseAsync(e,{...s,binary:!1}),r=JSON.stringify(t);return new TextEncoder().encode(r).buffer}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export GLTF",t)}}async _exportUsdz(e,s){try{return(await this._usdzExporter.parse(e,s)).buffer}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export USDZ",t)}}}exports.AssetExporter=Xe;
164
+ `}class qe{constructor(){H(this,"_gltfExporter");H(this,"_usdzExporter");this._gltfExporter=new X,this._usdzExporter=new Fe}async export(e,s,t){switch(s){case"glb":return this._exportGlb(e,t);case"gltf":return this._exportGltf(e,t);case"usdz":return this._exportUsdz(e,t);default:throw new fe.FileTypeError(`Unsupported file type: ${s}`,s)}}async _exportGlb(e,s){try{const t=await this._gltfExporter.parseAsync(e,{...s,binary:!0});if(t instanceof ArrayBuffer)return t;throw new L.ParseError("Failed to export GLB: expected ArrayBuffer")}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export GLB",t)}}async _exportGltf(e,s){try{const t=await this._gltfExporter.parseAsync(e,{...s,binary:!1}),r=JSON.stringify(t);return new TextEncoder().encode(r).buffer}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export GLTF",t)}}async _exportUsdz(e,s){try{return(await this._usdzExporter.parse(e,s)).buffer}catch(t){throw t instanceof L.ParseError?t:new L.ParseError("Failed to export USDZ",t)}}}exports.AssetExporter=qe;
@@ -0,0 +1,4 @@
1
+ "use strict";var ue=Object.defineProperty;var fe=(h,e,t)=>e in h?ue(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var k=(h,e,t)=>fe(h,typeof e!="symbol"?e+"":e,t);const f=require("three"),B=require("./fflate.module-DHdJvhNh.cjs"),de=require("./FileTypes-CKOjpHjz.cjs"),Y=require("./isFileTypeSupported-CrEqYiv9.cjs"),J=require("./file-type-error-BsK7IJt7.cjs"),Q=require("./parse-error-m5cNt1UV.cjs"),Z=require("./AssetCache-CWeKL4PT.cjs");function $(h,e){if(e===f.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),h;if(e===f.TriangleFanDrawMode||e===f.TriangleStripDrawMode){let t=h.getIndex();if(t===null){const n=[],a=h.getAttribute("position");if(a!==void 0){for(let i=0;i<a.count;i++)n.push(i);h.setIndex(n),t=h.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),h}const o=t.count-2,s=[];if(e===f.TriangleFanDrawMode)for(let n=1;n<=o;n++)s.push(t.getX(0)),s.push(t.getX(n)),s.push(t.getX(n+1));else for(let n=0;n<o;n++)n%2===0?(s.push(t.getX(n)),s.push(t.getX(n+1)),s.push(t.getX(n+2))):(s.push(t.getX(n+2)),s.push(t.getX(n+1)),s.push(t.getX(n)));s.length/3!==o&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const r=h.clone();return r.setIndex(s),r.clearGroups(),r}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),h}class he extends f.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Te(t)}),this.register(function(t){return new be(t)}),this.register(function(t){return new Me(t)}),this.register(function(t){return new Ce(t)}),this.register(function(t){return new Re(t)}),this.register(function(t){return new xe(t)}),this.register(function(t){return new Se(t)}),this.register(function(t){return new _e(t)}),this.register(function(t){return new Ae(t)}),this.register(function(t){return new we(t)}),this.register(function(t){return new ye(t)}),this.register(function(t){return new Ee(t)}),this.register(function(t){return new Le(t)}),this.register(function(t){return new me(t)}),this.register(function(t){return new Ie(t)}),this.register(function(t){return new Ne(t)})}load(e,t,o,s){const r=this;let n;if(this.resourcePath!=="")n=this.resourcePath;else if(this.path!==""){const c=f.LoaderUtils.extractUrlBase(e);n=f.LoaderUtils.resolveURL(c,this.path)}else n=f.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(c){s?s(c):console.error(c),r.manager.itemError(e),r.manager.itemEnd(e)},i=new f.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,function(c){try{r.parse(c,n,function(l){t(l),r.manager.itemEnd(e)},a)}catch(l){a(l)}},o,a)}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 this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,o,s){let r;const n={},a={},i=new TextDecoder;if(typeof e=="string")r=JSON.parse(e);else if(e instanceof ArrayBuffer)if(i.decode(new Uint8Array(e,0,4))===re){try{n[b.KHR_BINARY_GLTF]=new De(e)}catch(u){s&&s(u);return}r=JSON.parse(n[b.KHR_BINARY_GLTF].content)}else r=JSON.parse(i.decode(e));else r=e;if(r.asset===void 0||r.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new We(r,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let l=0;l<this.pluginCallbacks.length;l++){const u=this.pluginCallbacks[l](c);u.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[u.name]=u,n[u.name]=!0}if(r.extensionsUsed)for(let l=0;l<r.extensionsUsed.length;++l){const u=r.extensionsUsed[l],d=r.extensionsRequired||[];switch(u){case b.KHR_MATERIALS_UNLIT:n[u]=new ge;break;case b.KHR_DRACO_MESH_COMPRESSION:n[u]=new Oe(r,this.dracoLoader);break;case b.KHR_TEXTURE_TRANSFORM:n[u]=new Pe;break;case b.KHR_MESH_QUANTIZATION:n[u]=new ke;break;default:d.indexOf(u)>=0&&a[u]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+u+'".')}}c.setExtensions(n),c.setPlugins(a),c.parse(o,s)}parseAsync(e,t){const o=this;return new Promise(function(s,r){o.parse(e,t,s,r)})}}function pe(){let h={};return{get:function(e){return h[e]},add:function(e,t){h[e]=t},remove:function(e){delete h[e]},removeAll:function(){h={}}}}const b={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_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class me{constructor(e){this.parser=e,this.name=b.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let o=0,s=t.length;o<s;o++){const r=t[o];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const t=this.parser,o="light:"+e;let s=t.cache.get(o);if(s)return s;const r=t.json,i=((r.extensions&&r.extensions[this.name]||{}).lights||[])[e];let c;const l=new f.Color(16777215);i.color!==void 0&&l.setRGB(i.color[0],i.color[1],i.color[2],f.LinearSRGBColorSpace);const u=i.range!==void 0?i.range:0;switch(i.type){case"directional":c=new f.DirectionalLight(l),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new f.PointLight(l),c.distance=u;break;case"spot":c=new f.SpotLight(l),c.distance=u,i.spot=i.spot||{},i.spot.innerConeAngle=i.spot.innerConeAngle!==void 0?i.spot.innerConeAngle:0,i.spot.outerConeAngle=i.spot.outerConeAngle!==void 0?i.spot.outerConeAngle:Math.PI/4,c.angle=i.spot.outerConeAngle,c.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return c.position.set(0,0,0),c.decay=2,O(c,i),i.intensity!==void 0&&(c.intensity=i.intensity),c.name=t.createUniqueName(i.name||"light_"+e),s=Promise.resolve(c),t.cache.add(o,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,o=this.parser,r=o.json.nodes[e],a=(r.extensions&&r.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(i){return o._getNodeRef(t.cache,a,i)})}}class ge{constructor(){this.name=b.KHR_MATERIALS_UNLIT}getMaterialType(){return f.MeshBasicMaterial}extendParams(e,t,o){const s=[];e.color=new f.Color(1,1,1),e.opacity=1;const r=t.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){const n=r.baseColorFactor;e.color.setRGB(n[0],n[1],n[2],f.LinearSRGBColorSpace),e.opacity=n[3]}r.baseColorTexture!==void 0&&s.push(o.assignTexture(e,"map",r.baseColorTexture,f.SRGBColorSpace))}return Promise.all(s)}}class Ae{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name].emissiveStrength;return r!==void 0&&(t.emissiveIntensity=r),Promise.resolve()}}class Te{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(o.assignTexture(t,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(o.assignTexture(t,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(o.assignTexture(t,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const a=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new f.Vector2(a,a)}return Promise.all(r)}}class ye{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(o.assignTexture(t,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(o.assignTexture(t,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(r)}}class Re{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SHEEN}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[];t.sheenColor=new f.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const n=s.extensions[this.name];if(n.sheenColorFactor!==void 0){const a=n.sheenColorFactor;t.sheenColor.setRGB(a[0],a[1],a[2],f.LinearSRGBColorSpace)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(o.assignTexture(t,"sheenColorMap",n.sheenColorTexture,f.SRGBColorSpace)),n.sheenRoughnessTexture!==void 0&&r.push(o.assignTexture(t,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(r)}}class xe{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(o.assignTexture(t,"transmissionMap",n.transmissionTexture)),Promise.all(r)}}class Se{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_VOLUME}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];t.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&r.push(o.assignTexture(t,"thicknessMap",n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;const a=n.attenuationColor||[1,1,1];return t.attenuationColor=new f.Color().setRGB(a[0],a[1],a[2],f.LinearSRGBColorSpace),Promise.all(r)}}class _e{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_IOR}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name];return t.ior=r.ior!==void 0?r.ior:1.5,Promise.resolve()}}class we{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SPECULAR}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];t.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&r.push(o.assignTexture(t,"specularIntensityMap",n.specularTexture));const a=n.specularColorFactor||[1,1,1];return t.specularColor=new f.Color().setRGB(a[0],a[1],a[2],f.LinearSRGBColorSpace),n.specularColorTexture!==void 0&&r.push(o.assignTexture(t,"specularColorMap",n.specularColorTexture,f.SRGBColorSpace)),Promise.all(r)}}class Le{constructor(e){this.parser=e,this.name=b.EXT_MATERIALS_BUMP}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];return t.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&r.push(o.assignTexture(t,"bumpMap",n.bumpTexture)),Promise.all(r)}}class Ee{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const o=this.parser.json.materials[e];return!o.extensions||!o.extensions[this.name]?null:f.MeshPhysicalMaterial}extendMaterialParams(e,t){const o=this.parser,s=o.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=[],n=s.extensions[this.name];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(o.assignTexture(t,"anisotropyMap",n.anisotropyTexture)),Promise.all(r)}}class be{constructor(e){this.parser=e,this.name=b.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,o=t.json,s=o.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const r=s.extensions[this.name],n=t.options.ktx2Loader;if(!n){if(o.extensionsRequired&&o.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,r.source,n)}}class Me{constructor(e){this.parser=e,this.name=b.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,o=this.parser,s=o.json,r=s.textures[e];if(!r.extensions||!r.extensions[t])return null;const n=r.extensions[t],a=s.images[n.source];let i=o.textureLoader;if(a.uri){const c=o.options.manager.getHandler(a.uri);c!==null&&(i=c)}return this.detectSupport().then(function(c){if(c)return o.loadTextureImage(e,n.source,i);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return o.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(t.height===1)}})),this.isSupported}}class Ce{constructor(e){this.parser=e,this.name=b.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,o=this.parser,s=o.json,r=s.textures[e];if(!r.extensions||!r.extensions[t])return null;const n=r.extensions[t],a=s.images[n.source];let i=o.textureLoader;if(a.uri){const c=o.options.manager.getHandler(a.uri);c!==null&&(i=c)}return this.detectSupport().then(function(c){if(c)return o.loadTextureImage(e,n.source,i);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return o.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class Ie{constructor(e){this.name=b.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,o=t.bufferViews[e];if(o.extensions&&o.extensions[this.name]){const s=o.extensions[this.name],r=this.parser.getDependency("buffer",s.buffer),n=this.parser.options.meshoptDecoder;if(!n||!n.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 r.then(function(a){const i=s.byteOffset||0,c=s.byteLength||0,l=s.count,u=s.byteStride,d=new Uint8Array(a,i,c);return n.decodeGltfBufferAsync?n.decodeGltfBufferAsync(l,u,d,s.mode,s.filter).then(function(g){return g.buffer}):n.ready.then(function(){const g=new ArrayBuffer(l*u);return n.decodeGltfBuffer(new Uint8Array(g),l,u,d,s.mode,s.filter),g})})}else return null}}class Ne{constructor(e){this.name=b.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,o=t.nodes[e];if(!o.extensions||!o.extensions[this.name]||o.mesh===void 0)return null;const s=t.meshes[o.mesh];for(const c of s.primitives)if(c.mode!==N.TRIANGLES&&c.mode!==N.TRIANGLE_STRIP&&c.mode!==N.TRIANGLE_FAN&&c.mode!==void 0)return null;const n=o.extensions[this.name].attributes,a=[],i={};for(const c in n)a.push(this.parser.getDependency("accessor",n[c]).then(l=>(i[c]=l,i[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(c=>{const l=c.pop(),u=l.isGroup?l.children:[l],d=c[0].count,g=[];for(const y of u){const S=new f.Matrix4,R=new f.Vector3,x=new f.Quaternion,L=new f.Vector3(1,1,1),E=new f.InstancedMesh(y.geometry,y.material,d);for(let _=0;_<d;_++)i.TRANSLATION&&R.fromBufferAttribute(i.TRANSLATION,_),i.ROTATION&&x.fromBufferAttribute(i.ROTATION,_),i.SCALE&&L.fromBufferAttribute(i.SCALE,_),E.setMatrixAt(_,S.compose(R,x,L));for(const _ in i)if(_==="_COLOR_0"){const C=i[_];E.instanceColor=new f.InstancedBufferAttribute(C.array,C.itemSize,C.normalized)}else _!=="TRANSLATION"&&_!=="ROTATION"&&_!=="SCALE"&&y.geometry.setAttribute(_,i[_]);f.Object3D.prototype.copy.call(E,y),this.parser.assignFinalMaterial(E),g.push(E)}return l.isGroup?(l.clear(),l.add(...g),l):g[0]}))}}const re="glTF",G=12,ee={JSON:1313821514,BIN:5130562};class De{constructor(e){this.name=b.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,G),o=new TextDecoder;if(this.header={magic:o.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==re)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const s=this.header.length-G,r=new DataView(e,G);let n=0;for(;n<s;){const a=r.getUint32(n,!0);n+=4;const i=r.getUint32(n,!0);if(n+=4,i===ee.JSON){const c=new Uint8Array(e,G+n,a);this.content=o.decode(c)}else if(i===ee.BIN){const c=G+n;this.body=e.slice(c,c+a)}n+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Oe{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=b.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const o=this.json,s=this.dracoLoader,r=e.extensions[this.name].bufferView,n=e.extensions[this.name].attributes,a={},i={},c={};for(const l in n){const u=W[l]||l.toLowerCase();a[u]=n[l]}for(const l in e.attributes){const u=W[l]||l.toLowerCase();if(n[l]!==void 0){const d=o.accessors[e.attributes[l]],g=F[d.componentType];c[u]=g.name,i[u]=d.normalized===!0}}return t.getDependency("bufferView",r).then(function(l){return new Promise(function(u,d){s.decodeDracoFile(l,function(g){for(const y in g.attributes){const S=g.attributes[y],R=i[y];R!==void 0&&(S.normalized=R)}u(g)},a,c,f.LinearSRGBColorSpace,d)})})}}class Pe{constructor(){this.name=b.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class ke{constructor(){this.name=b.KHR_MESH_QUANTIZATION}}class oe extends f.Interpolant{constructor(e,t,o,s){super(e,t,o,s)}copySampleValue_(e){const t=this.resultBuffer,o=this.sampleValues,s=this.valueSize,r=e*s*3+s;for(let n=0;n!==s;n++)t[n]=o[r+n];return t}interpolate_(e,t,o,s){const r=this.resultBuffer,n=this.sampleValues,a=this.valueSize,i=a*2,c=a*3,l=s-t,u=(o-t)/l,d=u*u,g=d*u,y=e*c,S=y-c,R=-2*g+3*d,x=g-d,L=1-R,E=x-d+u;for(let _=0;_!==a;_++){const C=n[S+_+a],I=n[S+_+i]*l,M=n[y+_+a],p=n[y+_]*l;r[_]=L*C+E*I+R*M+x*p}return r}}const Fe=new f.Quaternion;class Ge extends oe{interpolate_(e,t,o,s){const r=super.interpolate_(e,t,o,s);return Fe.fromArray(r).normalize().toArray(r),r}}const N={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},F={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},te={9728:f.NearestFilter,9729:f.LinearFilter,9984:f.NearestMipmapNearestFilter,9985:f.LinearMipmapNearestFilter,9986:f.NearestMipmapLinearFilter,9987:f.LinearMipmapLinearFilter},ne={33071:f.ClampToEdgeWrapping,33648:f.MirroredRepeatWrapping,10497:f.RepeatWrapping},H={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},W={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Ue={CUBICSPLINE:void 0,LINEAR:f.InterpolateLinear,STEP:f.InterpolateDiscrete},v={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Be(h){return h.DefaultMaterial===void 0&&(h.DefaultMaterial=new f.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:f.FrontSide})),h.DefaultMaterial}function P(h,e,t){for(const o in t.extensions)h[o]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[o]=t.extensions[o])}function O(h,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(h.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function He(h,e,t){let o=!1,s=!1,r=!1;for(let c=0,l=e.length;c<l;c++){const u=e[c];if(u.POSITION!==void 0&&(o=!0),u.NORMAL!==void 0&&(s=!0),u.COLOR_0!==void 0&&(r=!0),o&&s&&r)break}if(!o&&!s&&!r)return Promise.resolve(h);const n=[],a=[],i=[];for(let c=0,l=e.length;c<l;c++){const u=e[c];if(o){const d=u.POSITION!==void 0?t.getDependency("accessor",u.POSITION):h.attributes.position;n.push(d)}if(s){const d=u.NORMAL!==void 0?t.getDependency("accessor",u.NORMAL):h.attributes.normal;a.push(d)}if(r){const d=u.COLOR_0!==void 0?t.getDependency("accessor",u.COLOR_0):h.attributes.color;i.push(d)}}return Promise.all([Promise.all(n),Promise.all(a),Promise.all(i)]).then(function(c){const l=c[0],u=c[1],d=c[2];return o&&(h.morphAttributes.position=l),s&&(h.morphAttributes.normal=u),r&&(h.morphAttributes.color=d),h.morphTargetsRelative=!0,h})}function ve(h,e){if(h.updateMorphTargets(),e.weights!==void 0)for(let t=0,o=e.weights.length;t<o;t++)h.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(h.morphTargetInfluences.length===t.length){h.morphTargetDictionary={};for(let o=0,s=t.length;o<s;o++)h.morphTargetDictionary[t[o]]=o}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function je(h){let e;const t=h.extensions&&h.extensions[b.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+j(t.attributes):e=h.indices+":"+j(h.attributes)+":"+h.mode,h.targets!==void 0)for(let o=0,s=h.targets.length;o<s;o++)e+=":"+j(h.targets[o]);return e}function j(h){let e="";const t=Object.keys(h).sort();for(let o=0,s=t.length;o<s;o++)e+=t[o]+":"+h[t[o]]+";";return e}function X(h){switch(h){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.")}}function Ke(h){return h.search(/\.jpe?g($|\?)/i)>0||h.search(/^data\:image\/jpeg/)===0?"image/jpeg":h.search(/\.webp($|\?)/i)>0||h.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const Ve=new f.Matrix4;class We{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new pe,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let o=!1,s=!1,r=-1;typeof navigator<"u"&&(o=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)===!0,s=navigator.userAgent.indexOf("Firefox")>-1,r=s?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),typeof createImageBitmap>"u"||o||s&&r<98?this.textureLoader=new f.TextureLoader(this.options.manager):this.textureLoader=new f.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new f.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const o=this,s=this.json,r=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(n){return n._markDefs&&n._markDefs()}),Promise.all(this._invokeAll(function(n){return n.beforeRoot&&n.beforeRoot()})).then(function(){return Promise.all([o.getDependencies("scene"),o.getDependencies("animation"),o.getDependencies("camera")])}).then(function(n){const a={scene:n[0][s.scene||0],scenes:n[0],animations:n[1],cameras:n[2],asset:s.asset,parser:o,userData:{}};return P(r,a,s),O(a,s),Promise.all(o._invokeAll(function(i){return i.afterRoot&&i.afterRoot(a)})).then(function(){for(const i of a.scenes)i.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],o=this.json.meshes||[];for(let s=0,r=t.length;s<r;s++){const n=t[s].joints;for(let a=0,i=n.length;a<i;a++)e[n[a]].isBone=!0}for(let s=0,r=e.length;s<r;s++){const n=e[s];n.mesh!==void 0&&(this._addNodeRef(this.meshCache,n.mesh),n.skin!==void 0&&(o[n.mesh].isSkinnedMesh=!0)),n.camera!==void 0&&this._addNodeRef(this.cameraCache,n.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,o){if(e.refs[t]<=1)return o;const s=o.clone(),r=(n,a)=>{const i=this.associations.get(n);i!=null&&this.associations.set(a,i);for(const[c,l]of n.children.entries())r(l,a.children[c])};return r(o,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let o=0;o<t.length;o++){const s=e(t[o]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const o=[];for(let s=0;s<t.length;s++){const r=e(t[s]);r&&o.push(r)}return o}getDependency(e,t){const o=e+":"+t;let s=this.cache.get(o);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(r){return r.loadNode&&r.loadNode(t)});break;case"mesh":s=this._invokeOne(function(r){return r.loadMesh&&r.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(r){return r.loadBufferView&&r.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(r){return r.loadMaterial&&r.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(r){return r.loadTexture&&r.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(r){return r.loadAnimation&&r.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(o,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const o=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(r,n){return o.getDependency(e,n)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],o=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[b.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(r,n){o.load(f.LoaderUtils.resolveURL(t.uri,s.path),r,void 0,function(){n(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(o){const s=t.byteLength||0,r=t.byteOffset||0;return o.slice(r,r+s)})}loadAccessor(e){const t=this,o=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const n=H[s.type],a=F[s.componentType],i=s.normalized===!0,c=new a(s.count*n);return Promise.resolve(new f.BufferAttribute(c,n,i))}const r=[];return s.bufferView!==void 0?r.push(this.getDependency("bufferView",s.bufferView)):r.push(null),s.sparse!==void 0&&(r.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(r).then(function(n){const a=n[0],i=H[s.type],c=F[s.componentType],l=c.BYTES_PER_ELEMENT,u=l*i,d=s.byteOffset||0,g=s.bufferView!==void 0?o.bufferViews[s.bufferView].byteStride:void 0,y=s.normalized===!0;let S,R;if(g&&g!==u){const x=Math.floor(d/g),L="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+x+":"+s.count;let E=t.cache.get(L);E||(S=new c(a,x*g,s.count*g/l),E=new f.InterleavedBuffer(S,g/l),t.cache.add(L,E)),R=new f.InterleavedBufferAttribute(E,i,d%g/l,y)}else a===null?S=new c(s.count*i):S=new c(a,d,s.count*i),R=new f.BufferAttribute(S,i,y);if(s.sparse!==void 0){const x=H.SCALAR,L=F[s.sparse.indices.componentType],E=s.sparse.indices.byteOffset||0,_=s.sparse.values.byteOffset||0,C=new L(n[1],E,s.sparse.count*x),I=new c(n[2],_,s.sparse.count*i);a!==null&&(R=new f.BufferAttribute(R.array.slice(),R.itemSize,R.normalized));for(let M=0,p=C.length;M<p;M++){const m=C[M];if(R.setX(m,I[M*i]),i>=2&&R.setY(m,I[M*i+1]),i>=3&&R.setZ(m,I[M*i+2]),i>=4&&R.setW(m,I[M*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return R})}loadTexture(e){const t=this.json,o=this.options,r=t.textures[e].source,n=t.images[r];let a=this.textureLoader;if(n.uri){const i=o.manager.getHandler(n.uri);i!==null&&(a=i)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,o){const s=this,r=this.json,n=r.textures[e],a=r.images[t],i=(a.uri||a.bufferView)+":"+n.sampler;if(this.textureCache[i])return this.textureCache[i];const c=this.loadImageSource(t,o).then(function(l){l.flipY=!1,l.name=n.name||a.name||"",l.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(l.name=a.uri);const d=(r.samplers||{})[n.sampler]||{};return l.magFilter=te[d.magFilter]||f.LinearFilter,l.minFilter=te[d.minFilter]||f.LinearMipmapLinearFilter,l.wrapS=ne[d.wrapS]||f.RepeatWrapping,l.wrapT=ne[d.wrapT]||f.RepeatWrapping,s.associations.set(l,{textures:e}),l}).catch(function(){return null});return this.textureCache[i]=c,c}loadImageSource(e,t){const o=this,s=this.json,r=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(u=>u.clone());const n=s.images[e],a=self.URL||self.webkitURL;let i=n.uri||"",c=!1;if(n.bufferView!==void 0)i=o.getDependency("bufferView",n.bufferView).then(function(u){c=!0;const d=new Blob([u],{type:n.mimeType});return i=a.createObjectURL(d),i});else if(n.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const l=Promise.resolve(i).then(function(u){return new Promise(function(d,g){let y=d;t.isImageBitmapLoader===!0&&(y=function(S){const R=new f.Texture(S);R.needsUpdate=!0,d(R)}),t.load(f.LoaderUtils.resolveURL(u,r.path),y,void 0,g)})}).then(function(u){return c===!0&&a.revokeObjectURL(i),u.userData.mimeType=n.mimeType||Ke(n.uri),u}).catch(function(u){throw console.error("THREE.GLTFLoader: Couldn't load texture",i),u});return this.sourceCache[e]=l,l}assignTexture(e,t,o,s){const r=this;return this.getDependency("texture",o.index).then(function(n){if(!n)return null;if(o.texCoord!==void 0&&o.texCoord>0&&(n=n.clone(),n.channel=o.texCoord),r.extensions[b.KHR_TEXTURE_TRANSFORM]){const a=o.extensions!==void 0?o.extensions[b.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const i=r.associations.get(n);n=r.extensions[b.KHR_TEXTURE_TRANSFORM].extendTexture(n,a),r.associations.set(n,i)}}return s!==void 0&&(n.colorSpace=s),e[t]=n,n})}assignFinalMaterial(e){const t=e.geometry;let o=e.material;const s=t.attributes.tangent===void 0,r=t.attributes.color!==void 0,n=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+o.uuid;let i=this.cache.get(a);i||(i=new f.PointsMaterial,f.Material.prototype.copy.call(i,o),i.color.copy(o.color),i.map=o.map,i.sizeAttenuation=!1,this.cache.add(a,i)),o=i}else if(e.isLine){const a="LineBasicMaterial:"+o.uuid;let i=this.cache.get(a);i||(i=new f.LineBasicMaterial,f.Material.prototype.copy.call(i,o),i.color.copy(o.color),i.map=o.map,this.cache.add(a,i)),o=i}if(s||r||n){let a="ClonedMaterial:"+o.uuid+":";s&&(a+="derivative-tangents:"),r&&(a+="vertex-colors:"),n&&(a+="flat-shading:");let i=this.cache.get(a);i||(i=o.clone(),r&&(i.vertexColors=!0),n&&(i.flatShading=!0),s&&(i.normalScale&&(i.normalScale.y*=-1),i.clearcoatNormalScale&&(i.clearcoatNormalScale.y*=-1)),this.cache.add(a,i),this.associations.set(i,this.associations.get(o))),o=i}e.material=o}getMaterialType(){return f.MeshStandardMaterial}loadMaterial(e){const t=this,o=this.json,s=this.extensions,r=o.materials[e];let n;const a={},i=r.extensions||{},c=[];if(i[b.KHR_MATERIALS_UNLIT]){const u=s[b.KHR_MATERIALS_UNLIT];n=u.getMaterialType(),c.push(u.extendParams(a,r,t))}else{const u=r.pbrMetallicRoughness||{};if(a.color=new f.Color(1,1,1),a.opacity=1,Array.isArray(u.baseColorFactor)){const d=u.baseColorFactor;a.color.setRGB(d[0],d[1],d[2],f.LinearSRGBColorSpace),a.opacity=d[3]}u.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",u.baseColorTexture,f.SRGBColorSpace)),a.metalness=u.metallicFactor!==void 0?u.metallicFactor:1,a.roughness=u.roughnessFactor!==void 0?u.roughnessFactor:1,u.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",u.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",u.metallicRoughnessTexture))),n=this._invokeOne(function(d){return d.getMaterialType&&d.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(d){return d.extendMaterialParams&&d.extendMaterialParams(e,a)})))}r.doubleSided===!0&&(a.side=f.DoubleSide);const l=r.alphaMode||v.OPAQUE;if(l===v.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,l===v.MASK&&(a.alphaTest=r.alphaCutoff!==void 0?r.alphaCutoff:.5)),r.normalTexture!==void 0&&n!==f.MeshBasicMaterial&&(c.push(t.assignTexture(a,"normalMap",r.normalTexture)),a.normalScale=new f.Vector2(1,1),r.normalTexture.scale!==void 0)){const u=r.normalTexture.scale;a.normalScale.set(u,u)}if(r.occlusionTexture!==void 0&&n!==f.MeshBasicMaterial&&(c.push(t.assignTexture(a,"aoMap",r.occlusionTexture)),r.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=r.occlusionTexture.strength)),r.emissiveFactor!==void 0&&n!==f.MeshBasicMaterial){const u=r.emissiveFactor;a.emissive=new f.Color().setRGB(u[0],u[1],u[2],f.LinearSRGBColorSpace)}return r.emissiveTexture!==void 0&&n!==f.MeshBasicMaterial&&c.push(t.assignTexture(a,"emissiveMap",r.emissiveTexture,f.SRGBColorSpace)),Promise.all(c).then(function(){const u=new n(a);return r.name&&(u.name=r.name),O(u,r),t.associations.set(u,{materials:e}),r.extensions&&P(s,u,r),u})}createUniqueName(e){const t=f.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,o=this.extensions,s=this.primitiveCache;function r(a){return o[b.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(i){return se(i,a,t)})}const n=[];for(let a=0,i=e.length;a<i;a++){const c=e[a],l=je(c),u=s[l];if(u)n.push(u.promise);else{let d;c.extensions&&c.extensions[b.KHR_DRACO_MESH_COMPRESSION]?d=r(c):d=se(new f.BufferGeometry,c,t),s[l]={primitive:c,promise:d},n.push(d)}}return Promise.all(n)}loadMesh(e){const t=this,o=this.json,s=this.extensions,r=o.meshes[e],n=r.primitives,a=[];for(let i=0,c=n.length;i<c;i++){const l=n[i].material===void 0?Be(this.cache):this.getDependency("material",n[i].material);a.push(l)}return a.push(t.loadGeometries(n)),Promise.all(a).then(function(i){const c=i.slice(0,i.length-1),l=i[i.length-1],u=[];for(let g=0,y=l.length;g<y;g++){const S=l[g],R=n[g];let x;const L=c[g];if(R.mode===N.TRIANGLES||R.mode===N.TRIANGLE_STRIP||R.mode===N.TRIANGLE_FAN||R.mode===void 0)x=r.isSkinnedMesh===!0?new f.SkinnedMesh(S,L):new f.Mesh(S,L),x.isSkinnedMesh===!0&&x.normalizeSkinWeights(),R.mode===N.TRIANGLE_STRIP?x.geometry=$(x.geometry,f.TriangleStripDrawMode):R.mode===N.TRIANGLE_FAN&&(x.geometry=$(x.geometry,f.TriangleFanDrawMode));else if(R.mode===N.LINES)x=new f.LineSegments(S,L);else if(R.mode===N.LINE_STRIP)x=new f.Line(S,L);else if(R.mode===N.LINE_LOOP)x=new f.LineLoop(S,L);else if(R.mode===N.POINTS)x=new f.Points(S,L);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+R.mode);Object.keys(x.geometry.morphAttributes).length>0&&ve(x,r),x.name=t.createUniqueName(r.name||"mesh_"+e),O(x,r),R.extensions&&P(s,x,R),t.assignFinalMaterial(x),u.push(x)}for(let g=0,y=u.length;g<y;g++)t.associations.set(u[g],{meshes:e,primitives:g});if(u.length===1)return r.extensions&&P(s,u[0],r),u[0];const d=new f.Group;r.extensions&&P(s,d,r),t.associations.set(d,{meshes:e});for(let g=0,y=u.length;g<y;g++)d.add(u[g]);return d})}loadCamera(e){let t;const o=this.json.cameras[e],s=o[o.type];if(!s){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return o.type==="perspective"?t=new f.PerspectiveCamera(f.MathUtils.radToDeg(s.yfov),s.aspectRatio||1,s.znear||1,s.zfar||2e6):o.type==="orthographic"&&(t=new f.OrthographicCamera(-s.xmag,s.xmag,s.ymag,-s.ymag,s.znear,s.zfar)),o.name&&(t.name=this.createUniqueName(o.name)),O(t,o),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],o=[];for(let s=0,r=t.joints.length;s<r;s++)o.push(this._loadNodeShallow(t.joints[s]));return t.inverseBindMatrices!==void 0?o.push(this.getDependency("accessor",t.inverseBindMatrices)):o.push(null),Promise.all(o).then(function(s){const r=s.pop(),n=s,a=[],i=[];for(let c=0,l=n.length;c<l;c++){const u=n[c];if(u){a.push(u);const d=new f.Matrix4;r!==null&&d.fromArray(r.array,c*16),i.push(d)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[c])}return new f.Skeleton(a,i)})}loadAnimation(e){const t=this.json,o=this,s=t.animations[e],r=s.name?s.name:"animation_"+e,n=[],a=[],i=[],c=[],l=[];for(let u=0,d=s.channels.length;u<d;u++){const g=s.channels[u],y=s.samplers[g.sampler],S=g.target,R=S.node,x=s.parameters!==void 0?s.parameters[y.input]:y.input,L=s.parameters!==void 0?s.parameters[y.output]:y.output;S.node!==void 0&&(n.push(this.getDependency("node",R)),a.push(this.getDependency("accessor",x)),i.push(this.getDependency("accessor",L)),c.push(y),l.push(S))}return Promise.all([Promise.all(n),Promise.all(a),Promise.all(i),Promise.all(c),Promise.all(l)]).then(function(u){const d=u[0],g=u[1],y=u[2],S=u[3],R=u[4],x=[];for(let L=0,E=d.length;L<E;L++){const _=d[L],C=g[L],I=y[L],M=S[L],p=R[L];if(_===void 0)continue;_.updateMatrix&&_.updateMatrix();const m=o._createAnimationTracks(_,C,I,M,p);if(m)for(let A=0;A<m.length;A++)x.push(m[A])}return new f.AnimationClip(r,void 0,x)})}createNodeMesh(e){const t=this.json,o=this,s=t.nodes[e];return s.mesh===void 0?null:o.getDependency("mesh",s.mesh).then(function(r){const n=o._getNodeRef(o.meshCache,s.mesh,r);return s.weights!==void 0&&n.traverse(function(a){if(a.isMesh)for(let i=0,c=s.weights.length;i<c;i++)a.morphTargetInfluences[i]=s.weights[i]}),n})}loadNode(e){const t=this.json,o=this,s=t.nodes[e],r=o._loadNodeShallow(e),n=[],a=s.children||[];for(let c=0,l=a.length;c<l;c++)n.push(o.getDependency("node",a[c]));const i=s.skin===void 0?Promise.resolve(null):o.getDependency("skin",s.skin);return Promise.all([r,Promise.all(n),i]).then(function(c){const l=c[0],u=c[1],d=c[2];d!==null&&l.traverse(function(g){g.isSkinnedMesh&&g.bind(d,Ve)});for(let g=0,y=u.length;g<y;g++)l.add(u[g]);return l})}_loadNodeShallow(e){const t=this.json,o=this.extensions,s=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const r=t.nodes[e],n=r.name?s.createUniqueName(r.name):"",a=[],i=s._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return i&&a.push(i),r.camera!==void 0&&a.push(s.getDependency("camera",r.camera).then(function(c){return s._getNodeRef(s.cameraCache,r.camera,c)})),s._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let l;if(r.isBone===!0?l=new f.Bone:c.length>1?l=new f.Group:c.length===1?l=c[0]:l=new f.Object3D,l!==c[0])for(let u=0,d=c.length;u<d;u++)l.add(c[u]);if(r.name&&(l.userData.name=r.name,l.name=n),O(l,r),r.extensions&&P(o,l,r),r.matrix!==void 0){const u=new f.Matrix4;u.fromArray(r.matrix),l.applyMatrix4(u)}else r.translation!==void 0&&l.position.fromArray(r.translation),r.rotation!==void 0&&l.quaternion.fromArray(r.rotation),r.scale!==void 0&&l.scale.fromArray(r.scale);return s.associations.has(l)||s.associations.set(l,{}),s.associations.get(l).nodes=e,l}),this.nodeCache[e]}loadScene(e){const t=this.extensions,o=this.json.scenes[e],s=this,r=new f.Group;o.name&&(r.name=s.createUniqueName(o.name)),O(r,o),o.extensions&&P(t,r,o);const n=o.nodes||[],a=[];for(let i=0,c=n.length;i<c;i++)a.push(s.getDependency("node",n[i]));return Promise.all(a).then(function(i){for(let l=0,u=i.length;l<u;l++)r.add(i[l]);const c=l=>{const u=new Map;for(const[d,g]of s.associations)(d instanceof f.Material||d instanceof f.Texture)&&u.set(d,g);return l.traverse(d=>{const g=s.associations.get(d);g!=null&&u.set(d,g)}),u};return s.associations=c(r),r})}_createAnimationTracks(e,t,o,s,r){const n=[],a=e.name?e.name:e.uuid,i=[];D[r.path]===D.weights?e.traverse(function(d){d.morphTargetInfluences&&i.push(d.name?d.name:d.uuid)}):i.push(a);let c;switch(D[r.path]){case D.weights:c=f.NumberKeyframeTrack;break;case D.rotation:c=f.QuaternionKeyframeTrack;break;case D.position:case D.scale:c=f.VectorKeyframeTrack;break;default:switch(o.itemSize){case 1:c=f.NumberKeyframeTrack;break;case 2:case 3:default:c=f.VectorKeyframeTrack;break}break}const l=s.interpolation!==void 0?Ue[s.interpolation]:f.InterpolateLinear,u=this._getArrayFromAccessor(o);for(let d=0,g=i.length;d<g;d++){const y=new c(i[d]+"."+D[r.path],t.array,u,l);s.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(y),n.push(y)}return n}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const o=X(t.constructor),s=new Float32Array(t.length);for(let r=0,n=t.length;r<n;r++)s[r]=t[r]*o;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(o){const s=this instanceof f.QuaternionKeyframeTrack?Ge:oe;return new s(this.times,this.values,this.getValueSize()/3,o)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Xe(h,e,t){const o=e.attributes,s=new f.Box3;if(o.POSITION!==void 0){const a=t.json.accessors[o.POSITION],i=a.min,c=a.max;if(i!==void 0&&c!==void 0){if(s.set(new f.Vector3(i[0],i[1],i[2]),new f.Vector3(c[0],c[1],c[2])),a.normalized){const l=X(F[a.componentType]);s.min.multiplyScalar(l),s.max.multiplyScalar(l)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const r=e.targets;if(r!==void 0){const a=new f.Vector3,i=new f.Vector3;for(let c=0,l=r.length;c<l;c++){const u=r[c];if(u.POSITION!==void 0){const d=t.json.accessors[u.POSITION],g=d.min,y=d.max;if(g!==void 0&&y!==void 0){if(i.setX(Math.max(Math.abs(g[0]),Math.abs(y[0]))),i.setY(Math.max(Math.abs(g[1]),Math.abs(y[1]))),i.setZ(Math.max(Math.abs(g[2]),Math.abs(y[2]))),d.normalized){const S=X(F[d.componentType]);i.multiplyScalar(S)}a.max(i)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}s.expandByVector(a)}h.boundingBox=s;const n=new f.Sphere;s.getCenter(n.center),n.radius=s.min.distanceTo(s.max)/2,h.boundingSphere=n}function se(h,e,t){const o=e.attributes,s=[];function r(n,a){return t.getDependency("accessor",n).then(function(i){h.setAttribute(a,i)})}for(const n in o){const a=W[n]||n.toLowerCase();a in h.attributes||s.push(r(o[n],a))}if(e.indices!==void 0&&!h.index){const n=t.getDependency("accessor",e.indices).then(function(a){h.setIndex(a)});s.push(n)}return f.ColorManagement.workingColorSpace!==f.LinearSRGBColorSpace&&"COLOR_0"in o&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${f.ColorManagement.workingColorSpace}" not supported.`),O(h,e),Xe(h,e,t),Promise.all(s).then(function(){return e.targets!==void 0?He(h,e.targets,t):h})}class qe{parse(e){const t={},o=e.split(`
2
+ `);let s=null,r=t;const n=[t];for(const a of o)if(a.includes("=")){const i=a.split("="),c=i[0].trim(),l=i[1].trim();if(l.endsWith("{")){const u={};n.push(u),r[c]=u,r=u}else r[c]=l}else if(a.endsWith("{")){const i=r[s]||{};n.push(i),r[s]=i,r=i}else if(a.endsWith("}")){if(n.pop(),n.length===0)continue;r=n[n.length-1]}else if(a.endsWith("(")){const i={};n.push(i),s=a.split("(")[0].trim()||s,r[s]=i,r=i}else a.endsWith(")")?(n.pop(),r=n[n.length-1]):s=a.trim();return t}}class ze extends f.Loader{constructor(e){super(e)}load(e,t,o,s){const r=this,n=new f.FileLoader(r.manager);n.setPath(r.path),n.setResponseType("arraybuffer"),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(e,function(a){try{t(r.parse(a))}catch(i){s?s(i):console.error(i),r.manager.itemError(e)}},o,s)}parse(e){const t=new qe;function o(p){const m={};new f.FileLoader().setResponseType("arraybuffer");for(const T in p){if(T.endsWith("png")){const w=new Blob([p[T]],{type:{type:"image/png"}});m[T]=URL.createObjectURL(w)}if(T.endsWith("usd")||T.endsWith("usda")){if(s(p[T])){console.warn("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.");continue}const w=B.strFromU8(p[T]);m[T]=t.parse(w)}}return m}function s(p){const m=p.slice(0,7),A=new Uint8Array([80,88,82,45,85,83,68,67]);return m.every((T,w)=>T===A[w])}function r(p){if(p.length<1)return;const m=Object.keys(p)[0];let A=!1;if(m.endsWith("usda"))return p[m];if(m.endsWith("usdc"))A=!0;else if(m.endsWith("usd"))if(s(p[m]))A=!0;else return p[m];A&&console.warn("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.")}const n=B.unzipSync(new Uint8Array(e)),a=o(n),i=r(n);if(i===void 0)return console.warn("THREE.USDZLoader: No usda file found."),new f.Group;const c=B.strFromU8(i),l=t.parse(c);function u(p){if(p){if("prepend references"in p){const A=p["prepend references"].split("@"),T=A[1].replace(/^.\//,""),w=A[2].replace(/^<\//,"").replace(/>$/,"");return d(a[T],w)}return d(p)}}function d(p,m){if(p){if(m!==void 0){const A=`def Mesh "${m}"`;if(A in p)return p[A]}for(const A in p){const T=p[A];if(A.startsWith("def Mesh"))return"point3f[] points"in p&&(T["point3f[] points"]=p["point3f[] points"]),"texCoord2f[] primvars:st"in p&&(T["texCoord2f[] primvars:st"]=p["texCoord2f[] primvars:st"]),"int[] primvars:st:indices"in p&&(T["int[] primvars:st:indices"]=p["int[] primvars:st:indices"]),T;if(typeof T=="object"){const w=d(T);if(w)return w}}}}function g(p){if(!p)return;let m=new f.BufferGeometry;if("int[] faceVertexIndices"in p){const A=JSON.parse(p["int[] faceVertexIndices"]);m.setIndex(A)}if("point3f[] points"in p){const A=JSON.parse(p["point3f[] points"].replace(/[()]*/g,"")),T=new f.BufferAttribute(new Float32Array(A),3);m.setAttribute("position",T)}if("normal3f[] normals"in p){const A=JSON.parse(p["normal3f[] normals"].replace(/[()]*/g,"")),T=new f.BufferAttribute(new Float32Array(A),3);m.setAttribute("normal",T)}else m.computeVertexNormals();if("float2[] primvars:st"in p&&(p["texCoord2f[] primvars:st"]=p["float2[] primvars:st"]),"texCoord2f[] primvars:st"in p){const A=JSON.parse(p["texCoord2f[] primvars:st"].replace(/[()]*/g,"")),T=new f.BufferAttribute(new Float32Array(A),2);if("int[] primvars:st:indices"in p){m=m.toNonIndexed();const w=JSON.parse(p["int[] primvars:st:indices"]);m.setAttribute("uv",y(T,w))}else m.setAttribute("uv",T)}return m}function y(p,m){const A=p.array,T=p.itemSize,w=new A.constructor(m.length*T);let q=0,ce=0;for(let U=0,le=m.length;U<le;U++){q=m[U]*T;for(let z=0;z<T;z++)w[ce++]=A[q++]}return new f.BufferAttribute(w,T)}function S(p){if(p){if("rel material:binding"in p){const T=p["rel material:binding"].replace(/^<\//,"").replace(/>$/,"").split("/");return R(l,` "${T[1]}"`)}return R(p)}}function R(p,m=""){for(const A in p){const T=p[A];if(A.startsWith("def Material"+m))return T;if(typeof T=="object"){const w=R(T,m);if(w)return w}}}function x(p,m){m["float inputs:rotation"]&&(p.rotation=parseFloat(m["float inputs:rotation"])),m["float2 inputs:scale"]&&(p.repeat=new f.Vector2().fromArray(JSON.parse("["+m["float2 inputs:scale"].replace(/[()]*/g,"")+"]"))),m["float2 inputs:translation"]&&(p.offset=new f.Vector2().fromArray(JSON.parse("["+m["float2 inputs:translation"].replace(/[()]*/g,"")+"]")))}function L(p){const m=new f.MeshPhysicalMaterial;if(p!==void 0){if('def Shader "PreviewSurface"'in p){const A=p['def Shader "PreviewSurface"'];if("color3f inputs:diffuseColor.connect"in A){const T=A["color3f inputs:diffuseColor.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.map=_(w),m.map.colorSpace=f.SRGBColorSpace,'def Shader "Transform2d_diffuse"'in p&&x(m.map,p['def Shader "Transform2d_diffuse"'])}else if("color3f inputs:diffuseColor"in A){const T=A["color3f inputs:diffuseColor"].replace(/[()]*/g,"");m.color.fromArray(JSON.parse("["+T+"]"))}if("color3f inputs:emissiveColor.connect"in A){const T=A["color3f inputs:emissiveColor.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.emissiveMap=_(w),m.emissiveMap.colorSpace=f.SRGBColorSpace,m.emissive.set(16777215),'def Shader "Transform2d_emissive"'in p&&x(m.emissiveMap,p['def Shader "Transform2d_emissive"'])}else if("color3f inputs:emissiveColor"in A){const T=A["color3f inputs:emissiveColor"].replace(/[()]*/g,"");m.emissive.fromArray(JSON.parse("["+T+"]"))}if("normal3f inputs:normal.connect"in A){const T=A["normal3f inputs:normal.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.normalMap=_(w),m.normalMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_normal"'in p&&x(m.normalMap,p['def Shader "Transform2d_normal"'])}if("float inputs:roughness.connect"in A){const T=A["float inputs:roughness.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.roughness=1,m.roughnessMap=_(w),m.roughnessMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_roughness"'in p&&x(m.roughnessMap,p['def Shader "Transform2d_roughness"'])}else"float inputs:roughness"in A&&(m.roughness=parseFloat(A["float inputs:roughness"]));if("float inputs:metallic.connect"in A){const T=A["float inputs:metallic.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.metalness=1,m.metalnessMap=_(w),m.metalnessMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_metallic"'in p&&x(m.metalnessMap,p['def Shader "Transform2d_metallic"'])}else"float inputs:metallic"in A&&(m.metalness=parseFloat(A["float inputs:metallic"]));if("float inputs:clearcoat.connect"in A){const T=A["float inputs:clearcoat.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.clearcoat=1,m.clearcoatMap=_(w),m.clearcoatMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_clearcoat"'in p&&x(m.clearcoatMap,p['def Shader "Transform2d_clearcoat"'])}else"float inputs:clearcoat"in A&&(m.clearcoat=parseFloat(A["float inputs:clearcoat"]));if("float inputs:clearcoatRoughness.connect"in A){const T=A["float inputs:clearcoatRoughness.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.clearcoatRoughness=1,m.clearcoatRoughnessMap=_(w),m.clearcoatRoughnessMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_clearcoatRoughness"'in p&&x(m.clearcoatRoughnessMap,p['def Shader "Transform2d_clearcoatRoughness"'])}else"float inputs:clearcoatRoughness"in A&&(m.clearcoatRoughness=parseFloat(A["float inputs:clearcoatRoughness"]));if("float inputs:ior"in A&&(m.ior=parseFloat(A["float inputs:ior"])),"float inputs:occlusion.connect"in A){const T=A["float inputs:occlusion.connect"],w=E(l,/(\w+).output/.exec(T)[1]);m.aoMap=_(w),m.aoMap.colorSpace=f.NoColorSpace,'def Shader "Transform2d_occlusion"'in p&&x(m.aoMap,p['def Shader "Transform2d_occlusion"'])}}if('def Shader "diffuseColor_texture"'in p){const A=p['def Shader "diffuseColor_texture"'];m.map=_(A),m.map.colorSpace=f.SRGBColorSpace}if('def Shader "normal_texture"'in p){const A=p['def Shader "normal_texture"'];m.normalMap=_(A),m.normalMap.colorSpace=f.NoColorSpace}}return m}function E(p,m){for(const A in p){const T=p[A];if(A.startsWith(`def Shader "${m}"`))return T;if(typeof T=="object"){const w=E(T,m);if(w)return w}}}function _(p){if("asset inputs:file"in p){const m=p["asset inputs:file"].replace(/@*/g,""),T=new f.TextureLoader().load(a[m]),w={'"clamp"':f.ClampToEdgeWrapping,'"mirror"':f.MirroredRepeatWrapping,'"repeat"':f.RepeatWrapping};return"token inputs:wrapS"in p&&(T.wrapS=w[p["token inputs:wrapS"]]),"token inputs:wrapT"in p&&(T.wrapT=w[p["token inputs:wrapT"]]),T}return null}function C(p){const m=g(u(p)),A=L(S(p)),T=m?new f.Mesh(m,A):new f.Object3D;if("matrix4d xformOp:transform"in p){const w=JSON.parse("["+p["matrix4d xformOp:transform"].replace(/[()]*/g,"")+"]");T.matrix.fromArray(w),T.matrix.decompose(T.position,T.quaternion,T.scale)}return T}function I(p,m){for(const A in p)if(A.startsWith("def Scope"))I(p[A],m);else if(A.startsWith("def Xform")){const T=C(p[A]);/def Xform "(\w+)"/.test(A)&&(T.name=/def Xform "(\w+)"/.exec(A)[1]),m.add(T),I(p[A],T)}}const M=new f.Group;return I(l,M),M}}const K=new WeakMap;class Ye extends f.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,o,s){const r=new f.FileLoader(this.manager);r.setPath(this.path),r.setResponseType("arraybuffer"),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,n=>{this.parse(n,t,s)},o,s)}parse(e,t,o=()=>{}){this.decodeDracoFile(e,t,null,null,f.SRGBColorSpace).catch(o)}decodeDracoFile(e,t,o,s,r=f.LinearSRGBColorSpace,n=()=>{}){const a={attributeIDs:o||this.defaultAttributeIDs,attributeTypes:s||this.defaultAttributeTypes,useUniqueIDs:!!o,vertexColorSpace:r};return this.decodeGeometry(e,a).then(t).catch(n)}decodeGeometry(e,t){const o=JSON.stringify(t);if(K.has(e)){const i=K.get(e);if(i.key===o)return i.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let s;const r=this.workerNextTaskID++,n=e.byteLength,a=this._getWorker(r,n).then(i=>(s=i,new Promise((c,l)=>{s._callbacks[r]={resolve:c,reject:l},s.postMessage({type:"decode",id:r,taskConfig:t,buffer:e},[e])}))).then(i=>this._createGeometry(i.geometry));return a.catch(()=>!0).then(()=>{s&&r&&this._releaseTask(s,r)}),K.set(e,{key:o,promise:a}),a}_createGeometry(e){const t=new f.BufferGeometry;e.index&&t.setIndex(new f.BufferAttribute(e.index.array,1));for(let o=0;o<e.attributes.length;o++){const s=e.attributes[o],r=s.name,n=s.array,a=s.itemSize,i=new f.BufferAttribute(n,a);r==="color"&&(this._assignVertexColorSpace(i,s.vertexColorSpace),i.normalized=!(n instanceof Float32Array)),t.setAttribute(r,i)}return t}_assignVertexColorSpace(e,t){if(t!==f.SRGBColorSpace)return;const o=new f.Color;for(let s=0,r=e.count;s<r;s++)o.fromBufferAttribute(e,s).convertSRGBToLinear(),e.setXYZ(s,o.r,o.g,o.b)}_loadLibrary(e,t){const o=new f.FileLoader(this.manager);return o.setPath(this.decoderPath),o.setResponseType(t),o.setWithCredentials(this.withCredentials),new Promise((s,r)=>{o.load(e,s,void 0,r)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(o=>{const s=o[0];e||(this.decoderConfig.wasmBinary=o[1]);const r=Je.toString(),n=["/* draco decoder */",s,"","/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join(`
3
+ `);this.workerSourceURL=URL.createObjectURL(new Blob([n]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const s=new Worker(this.workerSourceURL);s._callbacks={},s._taskCosts={},s._taskLoad=0,s.postMessage({type:"init",decoderConfig:this.decoderConfig}),s.onmessage=function(r){const n=r.data;switch(n.type){case"decode":s._callbacks[n.id].resolve(n);break;case"error":s._callbacks[n.id].reject(n);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+n.type+'"')}},this.workerPool.push(s)}else this.workerPool.sort(function(s,r){return s._taskLoad>r._taskLoad?-1:1});const o=this.workerPool[this.workerPool.length-1];return o._taskCosts[e]=t,o._taskLoad+=t,o})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this.workerSourceURL!==""&&URL.revokeObjectURL(this.workerSourceURL),this}}function Je(){let h,e;onmessage=function(n){const a=n.data;switch(a.type){case"init":h=a.decoderConfig,e=new Promise(function(l){h.onModuleLoaded=function(u){l({draco:u})},DracoDecoderModule(h)});break;case"decode":const i=a.buffer,c=a.taskConfig;e.then(l=>{const u=l.draco,d=new u.Decoder;try{const g=t(u,d,new Int8Array(i),c),y=g.attributes.map(S=>S.array.buffer);g.index&&y.push(g.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:g},y)}catch(g){console.error(g),self.postMessage({type:"error",id:a.id,error:g.message})}finally{u.destroy(d)}});break}};function t(n,a,i,c){const l=c.attributeIDs,u=c.attributeTypes;let d,g;const y=a.GetEncodedGeometryType(i);if(y===n.TRIANGULAR_MESH)d=new n.Mesh,g=a.DecodeArrayToMesh(i,i.byteLength,d);else if(y===n.POINT_CLOUD)d=new n.PointCloud,g=a.DecodeArrayToPointCloud(i,i.byteLength,d);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!g.ok()||d.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+g.error_msg());const S={index:null,attributes:[]};for(const R in l){const x=self[u[R]];let L,E;if(c.useUniqueIDs)E=l[R],L=a.GetAttributeByUniqueId(d,E);else{if(E=a.GetAttributeId(d,n[l[R]]),E===-1)continue;L=a.GetAttribute(d,E)}const _=s(n,a,d,R,x,L);R==="color"&&(_.vertexColorSpace=c.vertexColorSpace),S.attributes.push(_)}return y===n.TRIANGULAR_MESH&&(S.index=o(n,a,d)),n.destroy(d),S}function o(n,a,i){const l=i.num_faces()*3,u=l*4,d=n._malloc(u);a.GetTrianglesUInt32Array(i,u,d);const g=new Uint32Array(n.HEAPF32.buffer,d,l).slice();return n._free(d),{array:g,itemSize:1}}function s(n,a,i,c,l,u){const d=u.num_components(),y=i.num_points()*d,S=y*l.BYTES_PER_ELEMENT,R=r(n,l),x=n._malloc(S);a.GetAttributeDataArrayForAllPoints(i,u,R,S,x);const L=new l(n.HEAPF32.buffer,x,y).slice();return n._free(x),{name:c,array:L,itemSize:d}}function r(n,a){switch(a){case Float32Array:return n.DT_FLOAT32;case Int8Array:return n.DT_INT8;case Int16Array:return n.DT_INT16;case Int32Array:return n.DT_INT32;case Uint8Array:return n.DT_UINT8;case Uint16Array:return n.DT_UINT16;case Uint32Array:return n.DT_UINT32}}}function ie(){let h,e;onmessage=function(n){const a=n.data;switch(a.type){case"init":h=a.decoderConfig,e=new Promise(function(l){h.onModuleLoaded=function(u){l({draco:u})},DracoDecoderModule(h)});break;case"decode":const i=a.buffer,c=a.taskConfig;e.then(l=>{const u=l.draco,d=new u.Decoder;try{const g=t(u,d,new Int8Array(i),c),y=g.attributes.map(S=>S.array.buffer);g.index&&y.push(g.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:g},y)}catch(g){console.error(g),self.postMessage({type:"error",id:a.id,error:g.message})}finally{u.destroy(d)}});break}};function t(n,a,i,c){const l=c.attributeIDs,u=c.attributeTypes;let d,g;const y=a.GetEncodedGeometryType(i);if(y===n.TRIANGULAR_MESH)d=new n.Mesh,g=a.DecodeArrayToMesh(i,i.byteLength,d);else if(y===n.POINT_CLOUD)d=new n.PointCloud,g=a.DecodeArrayToPointCloud(i,i.byteLength,d);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!g.ok()||d.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+g.error_msg());const S={index:null,attributes:[]};for(const R in l){const x=self[u[R]];let L,E;if(c.useUniqueIDs)E=l[R],L=a.GetAttributeByUniqueId(d,E);else{if(E=a.GetAttributeId(d,n[l[R]]),E===-1)continue;L=a.GetAttribute(d,E)}const _=s(n,a,d,R,x,L);R==="color"&&(_.vertexColorSpace=c.vertexColorSpace),S.attributes.push(_)}return y===n.TRIANGULAR_MESH&&(S.index=o(n,a,d)),n.destroy(d),S}function o(n,a,i){const l=i.num_faces()*3,u=l*4,d=n._malloc(u);a.GetTrianglesUInt32Array(i,u,d);const g=new Uint32Array(n.HEAPF32.buffer,d,l).slice();return n._free(d),{array:g,itemSize:1}}function s(n,a,i,c,l,u){const d=u.num_components(),y=i.num_points()*d,S=y*l.BYTES_PER_ELEMENT,R=r(n,l),x=n._malloc(S);a.GetAttributeDataArrayForAllPoints(i,u,R,S,x);const L=new l(n.HEAPF32.buffer,x,y).slice();return n._free(x),{name:c,array:L,itemSize:d}}function r(n,a){switch(a){case Float32Array:return n.DT_FLOAT32;case Int8Array:return n.DT_INT8;case Int16Array:return n.DT_INT16;case Int32Array:return n.DT_INT32;case Uint8Array:return n.DT_UINT8;case Uint16Array:return n.DT_UINT16;case Uint32Array:return n.DT_UINT32}}}const V={LOAD_DRACO_JS_DECODER:async()=>(await Promise.resolve().then(()=>require("./draco_decoder-DvYjcLz_.cjs"))).default,LOAD_DRACO_WASM_WRAPPER:async()=>(await Promise.resolve().then(()=>require("./draco_wasm_wrapper-FoEVV9af.cjs"))).default,LOAD_DRACO_WASM_DECODER:async()=>{const h=(await Promise.resolve().then(()=>require("./draco_decoder-Bh9flJPu.cjs"))).default;return await(await fetch(h)).arrayBuffer()}};class ae extends Ye{constructor(){super(...arguments);k(this,"decoderPending",null);k(this,"decoderConfig",{type:"js",wasmBinary:null});k(this,"workerSourceURL","")}async _initDecoder(){if(this.decoderPending)return this.decoderPending;const t=typeof WebAssembly!="object"||this.decoderConfig.type==="js",o=[];return t?o.push(V.LOAD_DRACO_JS_DECODER()):(o.push(V.LOAD_DRACO_WASM_WRAPPER()),o.push(V.LOAD_DRACO_WASM_DECODER())),this.decoderPending=Promise.all(o).then(s=>{const r=s[0];t||(this.decoderConfig.wasmBinary=s[1]);const n=ie.toString(),a=["/* draco decoder */",r,"","/* worker */",n.substring(n.indexOf("{")+1,n.lastIndexOf("}"))].join(`
4
+ `);this.workerSourceURL=URL.createObjectURL(new Blob([a]))}),this.decoderPending}}class Qe{constructor(){k(this,"_gltfLoader");k(this,"_usdzLoader");const e=new ae;e.setDecoderConfig({type:"wasm"}),this._gltfLoader=new he,this._gltfLoader.setDRACOLoader(e),this._usdzLoader=new ze}async load(e){const t=Y.getFileTypeFromUri(e);if(t.length===0)throw new J.FileTypeError("No file extension found in URI","");if(!Y.isFileTypeSupported(t))throw new J.FileTypeError(`Unsupported file type: ${t}. Supported types: ${de.SUPPORTED_FILE_TYPES.join(", ")}`,t);const o=Z.AssetCache.read(e);if(o)return o.result?o.result:o.promise;const s=async n=>{try{switch(t){case"glb":case"gltf":return(await this._gltfLoader.parseAsync(n,"")).scene;case"usdz":return await this._usdzLoader.parse(n)}}catch(a){throw a instanceof Error?new Q.ParseError(`Failed to parse ${t} file: ${a.message}`,a):new Q.ParseError(`Failed to parse ${t} file`)}};return Z.AssetCache.create(e,s).fetch()}}exports.AssetLoader=Qe;exports.DRACOWorker=ie;exports.DracoLoader=ae;