@vctrl/hooks 0.17.0 → 0.22.0

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 (47) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +9 -9
  3. package/chunk-CMqjfN_6.cjs +1 -0
  4. package/index.cjs.js +1 -1
  5. package/index.es.js +3 -3
  6. package/package.json +67 -67
  7. package/use-export-model-8JbUalyf.cjs +1 -0
  8. package/{use-export-model-DzVKdqnY.js → use-export-model-BXg6L_W5.js} +5 -5
  9. package/use-export-model.cjs.js +1 -1
  10. package/use-export-model.es.js +1 -1
  11. package/use-load-model/error-helpers.d.ts +5 -0
  12. package/use-load-model/file-loaders.d.ts +12 -0
  13. package/use-load-model/index.d.ts +1 -1
  14. package/use-load-model/optimizer-integration.d.ts +16 -0
  15. package/use-load-model/scene-data-builder.d.ts +3 -0
  16. package/use-load-model/types.d.ts +13 -4
  17. package/use-load-model/use-load-model.d.ts +5 -16
  18. package/use-load-model-B9M4cF4B.cjs +1 -0
  19. package/use-load-model-BDCy9n2U.js +504 -0
  20. package/use-load-model.cjs.js +1 -1
  21. package/use-load-model.es.js +1 -1
  22. package/use-optimize-model/use-optimize-model.d.ts +14 -12
  23. package/use-optimize-model/utils/browser-texture-encoder.d.ts +41 -0
  24. package/use-optimize-model/utils/index.d.ts +2 -2
  25. package/use-optimize-model/utils/texture-optimization.d.ts +3 -13
  26. package/use-optimize-model-CPGezwrM.cjs +1 -0
  27. package/use-optimize-model-KAGxtv_k.js +296 -0
  28. package/use-optimize-model.cjs.js +1 -1
  29. package/use-optimize-model.es.js +1 -1
  30. package/GLTFLoader-CygFefRr.cjs +0 -1
  31. package/GLTFLoader-NiJ7qzh1.js +0 -1381
  32. package/__vite-browser-external-Bn_csQuM.js +0 -7
  33. package/__vite-browser-external-CVmj8TrW.cjs +0 -1
  34. package/chunk-foFoljWS.js +0 -23
  35. package/chunk-gGpyby2o.cjs +0 -1
  36. package/lib-DKn2MJ9X.js +0 -4111
  37. package/lib-DZ-MihdJ.cjs +0 -2
  38. package/model-exporter-SMSAY90N.cjs +0 -1
  39. package/model-exporter-cvguDGnn.js +0 -6512
  40. package/server-communication-Bj6ZxFw2.js +0 -4659
  41. package/server-communication-yXZR8eso.cjs +0 -18
  42. package/use-export-model-CaijtW1c.cjs +0 -1
  43. package/use-load-model-B6UXiFWh.js +0 -517
  44. package/use-load-model-CH-WPQ_s.cjs +0 -1
  45. package/use-optimize-model/utils/validation.d.ts +0 -8
  46. package/use-optimize-model-C-fzzKh6.cjs +0 -1
  47. package/use-optimize-model-Cb3WMvDZ.js +0 -299
@@ -1 +0,0 @@
1
- const e=require(`./chunk-gGpyby2o.cjs`);let t=require(`three`),n=require(`jszip`);n=e.a(n,1);var r=class{_listeners={};addEventListener(e,t){let n=this._listeners;return n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t),this}removeEventListener(e,t){let n=this._listeners[e];if(n!==void 0){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}return this}dispatchEvent(e){let t=this._listeners[e.type];if(t!==void 0){let n=t.slice(0);for(let t=0,r=n.length;t<r;t++)n[t].call(this,e)}return this}dispose(){for(let e in this._listeners)delete this._listeners[e]}},i=class{_disposed=!1;_name;_parent;_child;_attributes;constructor(e,t,n,r={}){if(this._name=e,this._parent=t,this._child=n,this._attributes=r,!t.isOnGraph(n))throw Error(`Cannot connect disconnected graphs.`)}getName(){return this._name}getParent(){return this._parent}getChild(){return this._child}setChild(e){return this._child=e,this}getAttributes(){return this._attributes}dispose(){this._disposed||=(this._parent._destroyRef(this),!0)}isDisposed(){return this._disposed}},a=class extends r{_emptySet=new Set;_edges=new Set;_parentEdges=new Map;_childEdges=new Map;listEdges(){return Array.from(this._edges)}listParentEdges(e){return Array.from(this._childEdges.get(e)||this._emptySet)}listParents(e){let t=new Set;for(let n of this.listParentEdges(e))t.add(n.getParent());return Array.from(t)}listChildEdges(e){return Array.from(this._parentEdges.get(e)||this._emptySet)}listChildren(e){let t=new Set;for(let n of this.listChildEdges(e))t.add(n.getChild());return Array.from(t)}disconnectParents(e,t){for(let n of this.listParentEdges(e))(!t||t(n.getParent()))&&n.dispose();return this}_createEdge(e,t,n,r){let a=new i(e,t,n,r);this._edges.add(a);let o=a.getParent();this._parentEdges.has(o)||this._parentEdges.set(o,new Set),this._parentEdges.get(o).add(a);let s=a.getChild();return this._childEdges.has(s)||this._childEdges.set(s,new Set),this._childEdges.get(s).add(a),a}_destroyEdge(e){return this._edges.delete(e),this._parentEdges.get(e.getParent()).delete(e),this._childEdges.get(e.getChild()).delete(e),this}},o=class{list=[];constructor(e){if(e)for(let t of e)this.list.push(t)}add(e){this.list.push(e)}remove(e){let t=this.list.indexOf(e);t>=0&&this.list.splice(t,1)}removeChild(e){let t=[];for(let n of this.list)n.getChild()===e&&t.push(n);for(let e of t)this.remove(e);return t}listRefsByChild(e){let t=[];for(let n of this.list)n.getChild()===e&&t.push(n);return t}values(){return this.list}},s=class{set=new Set;map=new Map;constructor(e){if(e)for(let t of e)this.add(t)}add(e){let t=e.getChild();this.removeChild(t),this.set.add(e),this.map.set(t,e)}remove(e){this.set.delete(e),this.map.delete(e.getChild())}removeChild(e){let t=this.map.get(e)||null;return t&&this.remove(t),t}getRefByChild(e){return this.map.get(e)||null}values(){return Array.from(this.set)}},c=class{map={};constructor(e){e&&Object.assign(this.map,e)}set(e,t){this.map[e]=t}delete(e){delete this.map[e]}get(e){return this.map[e]||null}keys(){return Object.keys(this.map)}values(){return Object.values(this.map)}},l=Symbol(`attributes`),u=Symbol(`immutableKeys`),d=class e extends r{_disposed=!1;graph;[l];[u];constructor(e){super(),this.graph=e,this[u]=new Set,this[l]=this._createAttributes()}getDefaults(){return{}}_createAttributes(){let t=this.getDefaults(),n={};for(let r in t){let i=t[r];if(i instanceof e){let e=this.graph._createEdge(r,this,i);this[u].add(r),n[r]=e}else n[r]=i}return n}isOnGraph(e){return this.graph===e.graph}isDisposed(){return this._disposed}dispose(){this._disposed||(this.graph.listChildEdges(this).forEach(e=>e.dispose()),this.graph.disconnectParents(this),this._disposed=!0,this.dispatchEvent({type:`dispose`}))}detach(){return this.graph.disconnectParents(this),this}swap(e,t){for(let n in this[l]){let r=this[l][n];if(r instanceof i){let i=r;i.getChild()===e&&this.setRef(n,t,i.getAttributes())}else if(r instanceof o)for(let i of r.listRefsByChild(e)){let r=i.getAttributes();this.removeRef(n,e),this.addRef(n,t,r)}else if(r instanceof s){let i=r.getRefByChild(e);if(i){let r=i.getAttributes();this.removeRef(n,e),this.addRef(n,t,r)}}else if(r instanceof c)for(let i of r.keys()){let a=r.get(i);a.getChild()===e&&this.setRefMap(n,i,t,a.getAttributes())}}return this}get(e){return this[l][e]}set(e,t){return this[l][e]=t,this.dispatchEvent({type:`change`,attribute:e})}getRef(e){let t=this[l][e];return t?t.getChild():null}setRef(e,t,n){if(this[u].has(e))throw Error(`Cannot overwrite immutable attribute, "${e}".`);let r=this[l][e];if(r&&r.dispose(),!t)return this;let i=this.graph._createEdge(e,this,t,n);return this[l][e]=i,this.dispatchEvent({type:`change`,attribute:e})}listRefs(e){return this.assertRefList(e).values().map(e=>e.getChild())}addRef(e,t,n){let r=this.graph._createEdge(e,this,t,n);return this.assertRefList(e).add(r),this.dispatchEvent({type:`change`,attribute:e})}removeRef(e,t){let n=this.assertRefList(e);if(n instanceof o)for(let e of n.listRefsByChild(t))e.dispose();else{let e=n.getRefByChild(t);e&&e.dispose()}return this}assertRefList(e){let t=this[l][e];if(t instanceof o||t instanceof s)return t;throw Error(`Expected RefList or RefSet for attribute "${e}"`)}listRefMapKeys(e){return this.assertRefMap(e).keys()}listRefMapValues(e){return this.assertRefMap(e).values().map(e=>e.getChild())}getRefMap(e,t){let n=this.assertRefMap(e).get(t);return n?n.getChild():null}setRefMap(e,t,n,r){let i=this.assertRefMap(e),a=i.get(t);if(a&&a.dispose(),!n)return this;r=Object.assign(r||{},{key:t});let o=this.graph._createEdge(e,this,n,{...r,key:t});return i.set(t,o),this.dispatchEvent({type:`change`,attribute:e,key:t})}assertRefMap(e){let t=this[l][e];if(t instanceof c)return t;throw Error(`Expected RefMap for attribute "${e}"`)}dispatchEvent(e){return super.dispatchEvent({...e,target:this}),this.graph.dispatchEvent({...e,target:this,type:`node:${e.type}`}),this}_destroyRef(e){let t=e.getName();if(this[l][t]===e)this[l][t]=null,this[u].has(t)&&e.getChild().dispose();else if(this[l][t]instanceof o)this[l][t].remove(e);else if(this[l][t]instanceof s)this[l][t].remove(e);else if(this[l][t]instanceof c){let n=this[l][t];for(let t of n.keys())n.get(t)===e&&n.delete(t)}else return;this.graph._destroyEdge(e),this.dispatchEvent({type:`change`,attribute:t})}},f=`v4.3.0`,p=`@glb.bin`,m;(function(e){e.ACCESSOR=`Accessor`,e.ANIMATION=`Animation`,e.ANIMATION_CHANNEL=`AnimationChannel`,e.ANIMATION_SAMPLER=`AnimationSampler`,e.BUFFER=`Buffer`,e.CAMERA=`Camera`,e.MATERIAL=`Material`,e.MESH=`Mesh`,e.PRIMITIVE=`Primitive`,e.PRIMITIVE_TARGET=`PrimitiveTarget`,e.NODE=`Node`,e.ROOT=`Root`,e.SCENE=`Scene`,e.SKIN=`Skin`,e.TEXTURE=`Texture`,e.TEXTURE_INFO=`TextureInfo`})(m||={});var h;(function(e){e.INTERLEAVED=`interleaved`,e.SEPARATE=`separate`})(h||={});var g;(function(e){e.ARRAY_BUFFER=`ARRAY_BUFFER`,e.ELEMENT_ARRAY_BUFFER=`ELEMENT_ARRAY_BUFFER`,e.INVERSE_BIND_MATRICES=`INVERSE_BIND_MATRICES`,e.OTHER=`OTHER`,e.SPARSE=`SPARSE`})(g||={});var _;(function(e){e[e.R=4096]=`R`,e[e.G=256]=`G`,e[e.B=16]=`B`,e[e.A=1]=`A`})(_||={});var v;(function(e){e.GLTF=`GLTF`,e.GLB=`GLB`})(v||={});var y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},b=class{static createBufferFromDataURI(e){if(typeof Buffer>`u`){let t=atob(e.split(`,`)[1]),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}else{let t=e.split(`,`)[1],n=e.indexOf(`base64`)>=0;return Buffer.from(t,n?`base64`:`utf8`)}}static encodeText(e){return new TextEncoder().encode(e)}static decodeText(e){return new TextDecoder().decode(e)}static concat(e){let t=0;for(let n of e)t+=n.byteLength;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}static pad(e,t=0){let n=this.padNumber(e.byteLength);if(n===e.byteLength)return e;let r=new Uint8Array(n);if(r.set(e),t!==0)for(let i=e.byteLength;i<n;i++)r[i]=t;return r}static padNumber(e){return Math.ceil(e/4)*4}static equals(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;let n=e.byteLength;for(;n--;)if(e[n]!==t[n])return!1;return!0}static toView(e,t=0,n=1/0){return new Uint8Array(e.buffer,e.byteOffset+t,Math.min(e.byteLength,n))}static assertView(e){if(e&&!ArrayBuffer.isView(e))throw Error(`Method requires Uint8Array parameter; received "${typeof e}".`);return e}},x=class{static hexToFactor(e,t){e=Math.floor(e);let n=t;return n[0]=(e>>16&255)/255,n[1]=(e>>8&255)/255,n[2]=(e&255)/255,this.convertSRGBToLinear(t,t)}static factorToHex(e){let t=[...e],[n,r,i]=this.convertLinearToSRGB(e,t);return n*255<<16^r*255<<8^i*255<<0}static convertSRGBToLinear(e,t){let n=e,r=t;for(let e=0;e<3;e++)r[e]=n[e]<.04045?n[e]*.0773993808:(n[e]*.9478672986+.0521327014)**2.4;return t}static convertLinearToSRGB(e,t){let n=e,r=t;for(let e=0;e<3;e++)r[e]=n[e]<.0031308?n[e]*12.92:1.055*n[e]**.41666-.055;return t}},S=class{match(e){return e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255}getSize(e){let t=new DataView(e.buffer,e.byteOffset+4),n,r;for(;t.byteLength;){if(n=t.getUint16(0,!1),te(t,n),r=t.getUint8(n+1),r===192||r===193||r===194)return[t.getUint16(n+7,!1),t.getUint16(n+5,!1)];t=new DataView(e.buffer,t.byteOffset+n+2)}throw TypeError(`Invalid JPG, no size found`)}getChannels(e){return 3}},ee=class e{match(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10}getSize(t){let n=new DataView(t.buffer,t.byteOffset);return b.decodeText(t.slice(12,16))===e.PNG_FRIED_CHUNK_NAME?[n.getUint32(32,!1),n.getUint32(36,!1)]:[n.getUint32(16,!1),n.getUint32(20,!1)]}getChannels(e){return 4}};ee.PNG_FRIED_CHUNK_NAME=`CgBI`;var C=class{static registerFormat(e,t){this.impls[e]=t}static getMimeType(e){for(let t in this.impls)if(this.impls[t].match(e))return t;return null}static getSize(e,t){return this.impls[t]?this.impls[t].getSize(e):null}static getChannels(e,t){return this.impls[t]?this.impls[t].getChannels(e):null}static getVRAMByteLength(e,t){if(!this.impls[t])return null;if(this.impls[t].getVRAMByteLength)return this.impls[t].getVRAMByteLength(e);let n=0,r=this.getSize(e,t);if(!r)return null;for(;r[0]>1||r[1]>1;)n+=r[0]*r[1]*4,r[0]=Math.max(Math.floor(r[0]/2),1),r[1]=Math.max(Math.floor(r[1]/2),1);return n+=4,n}static mimeTypeToExtension(e){return e===`image/jpeg`?`jpg`:e.split(`/`).pop()}static extensionToMimeType(e){return e===`jpg`?`image/jpeg`:e?`image/${e}`:``}};C.impls={"image/jpeg":new S,"image/png":new ee};function te(e,t){if(t>e.byteLength)throw TypeError(`Corrupt JPG, exceeded buffer limits`);if(e.getUint8(t)!==255)throw TypeError(`Invalid JPG, marker table corrupted`);return e}var w=class{static basename(e){let t=e.split(/[\\/]/).pop();return t.substring(0,t.lastIndexOf(`.`))}static extension(e){if(e.startsWith(`data:image/`)){let t=e.match(/data:(image\/\w+)/)[1];return C.mimeTypeToExtension(t)}else if(e.startsWith(`data:model/gltf+json`))return`gltf`;else if(e.startsWith(`data:model/gltf-binary`))return`glb`;else if(e.startsWith(`data:application/`))return`bin`;return e.split(/[\\/]/).pop().split(/[.]/).pop()}},ne=typeof Float32Array<`u`?Float32Array:Array;function re(){var e=new ne(3);return ne!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function ie(e){var t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)}function ae(e,t,n){var r=t[0],i=t[1],a=t[2],o=n[3]*r+n[7]*i+n[11]*a+n[15];return o||=1,e[0]=(n[0]*r+n[4]*i+n[8]*a+n[12])/o,e[1]=(n[1]*r+n[5]*i+n[9]*a+n[13])/o,e[2]=(n[2]*r+n[6]*i+n[10]*a+n[14])/o,e}(function(){var e=re();return function(t,n,r,i,a,o){var s,c;for(n||=3,r||=0,c=i?Math.min(i*n+r,t.length):t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],a(e,e,o),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}})();function oe(e){let t=le(),n=e.propertyType===m.NODE?[e]:e.listChildren();for(let e of n)e.traverse(e=>{let n=e.getMesh();if(!n)return;let r=se(n,e.getWorldMatrix());r.min.every(isFinite)&&r.max.every(isFinite)&&(ce(r.min,t),ce(r.max,t))});return t}function se(e,t){let n=le();for(let r of e.listPrimitives()){let e=r.getAttribute(`POSITION`),i=r.getIndices();if(!e)continue;let a=[0,0,0],o=[0,0,0];for(let r=0,s=i?i.getCount():e.getCount();r<s;r++){let s=i?i.getScalar(r):r;a=e.getElement(s,a),o=ae(o,a,t),ce(o,n)}}return n}function ce(e,t){for(let n=0;n<3;n++)t.min[n]=Math.min(e[n],t.min[n]),t.max[n]=Math.max(e[n],t.max[n])}function le(){return{min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}}var ue=`https://null.example`,de=class{static dirname(e){let t=e.lastIndexOf(`/`);return t===-1?`./`:e.substring(0,t+1)}static basename(e){return w.basename(new URL(e,ue).pathname)}static extension(e){return w.extension(new URL(e,ue).pathname)}static resolve(e,t){if(!this.isRelativePath(t))return t;let n=e.split(`/`),r=t.split(`/`);n.pop();for(let e=0;e<r.length;e++)r[e]!==`.`&&(r[e]===`..`?n.pop():n.push(r[e]));return n.join(`/`)}static isAbsoluteURL(e){return this.PROTOCOL_REGEXP.test(e)}static isRelativePath(e){return!/^(?:[a-zA-Z]+:)?\//.test(e)}};de.DEFAULT_INIT={},de.PROTOCOL_REGEXP=/^[a-zA-Z]+:\/\//;function fe(e){return Object.prototype.toString.call(e)===`[object Object]`}function pe(e){if(fe(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(fe(n)===!1||Object.hasOwn(n,`isPrototypeOf`)===!1)}var me,he;(function(e){e[e.SILENT=4]=`SILENT`,e[e.ERROR=3]=`ERROR`,e[e.WARN=2]=`WARN`,e[e.INFO=1]=`INFO`,e[e.DEBUG=0]=`DEBUG`})(he||={});var ge=class e{constructor(e){this.verbosity=void 0,this.verbosity=e}debug(t){this.verbosity<=e.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=e.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=e.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=e.Verbosity.ERROR&&console.error(t)}};me=ge,ge.Verbosity=he,ge.DEFAULT_INSTANCE=new me(me.Verbosity.INFO);function _e(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=t*o-n*a,v=t*s-r*a,y=n*s-r*o,b=l*m-u*p,x=l*h-d*p,S=u*h-d*m,ee=t*S-n*x+r*b,C=a*S-o*x+s*b,te=l*y-u*v+d*_,w=p*y-m*v+h*_;return c*ee-i*C+g*te-f*w}function ve(e,t,n){var r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12],g=t[13],_=t[14],v=t[15],y=n[0],b=n[1],x=n[2],S=n[3];return e[0]=y*r+b*s+x*d+S*h,e[1]=y*i+b*c+x*f+S*g,e[2]=y*a+b*l+x*p+S*_,e[3]=y*o+b*u+x*m+S*v,y=n[4],b=n[5],x=n[6],S=n[7],e[4]=y*r+b*s+x*d+S*h,e[5]=y*i+b*c+x*f+S*g,e[6]=y*a+b*l+x*p+S*_,e[7]=y*o+b*u+x*m+S*v,y=n[8],b=n[9],x=n[10],S=n[11],e[8]=y*r+b*s+x*d+S*h,e[9]=y*i+b*c+x*f+S*g,e[10]=y*a+b*l+x*p+S*_,e[11]=y*o+b*u+x*m+S*v,y=n[12],b=n[13],x=n[14],S=n[15],e[12]=y*r+b*s+x*d+S*h,e[13]=y*i+b*c+x*f+S*g,e[14]=y*a+b*l+x*p+S*_,e[15]=y*o+b*u+x*m+S*v,e}function ye(e,t){var n=t[0],r=t[1],i=t[2],a=t[4],o=t[5],s=t[6],c=t[8],l=t[9],u=t[10];return e[0]=Math.sqrt(n*n+r*r+i*i),e[1]=Math.sqrt(a*a+o*o+s*s),e[2]=Math.sqrt(c*c+l*l+u*u),e}function be(e,t){var n=new ne(3);ye(n,t);var r=1/n[0],i=1/n[1],a=1/n[2],o=t[0]*r,s=t[1]*i,c=t[2]*a,l=t[4]*r,u=t[5]*i,d=t[6]*a,f=t[8]*r,p=t[9]*i,m=t[10]*a,h=o+u+m,g=0;return h>0?(g=Math.sqrt(h+1)*2,e[3]=.25*g,e[0]=(d-p)/g,e[1]=(f-c)/g,e[2]=(s-l)/g):o>u&&o>m?(g=Math.sqrt(1+o-u-m)*2,e[3]=(d-p)/g,e[0]=.25*g,e[1]=(s+l)/g,e[2]=(f+c)/g):u>m?(g=Math.sqrt(1+u-o-m)*2,e[3]=(f-c)/g,e[0]=(s+l)/g,e[1]=.25*g,e[2]=(d+p)/g):(g=Math.sqrt(1+m-o-u)*2,e[3]=(s-l)/g,e[0]=(f+c)/g,e[1]=(d+p)/g,e[2]=.25*g),e}var T=class e{static identity(e){return e}static eq(e,t,n=1e-5){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(Math.abs(e[r]-t[r])>n)return!1;return!0}static clamp(e,t,n){return e<t?t:e>n?n:e}static decodeNormalizedInt(e,t){switch(t){case 5126:return e;case 5123:return e/65535;case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5120:return Math.max(e/127,-1);default:throw Error(`Invalid component type.`)}}static encodeNormalizedInt(t,n){switch(n){case 5126:return t;case 5123:return Math.round(e.clamp(t,0,1)*65535);case 5121:return Math.round(e.clamp(t,0,1)*255);case 5122:return Math.round(e.clamp(t,-1,1)*32767);case 5120:return Math.round(e.clamp(t,-1,1)*127);default:throw Error(`Invalid component type.`)}}static decompose(e,t,n,r){let i=ie([e[0],e[1],e[2]]),a=ie([e[4],e[5],e[6]]),o=ie([e[8],e[9],e[10]]);_e(e)<0&&(i=-i),t[0]=e[12],t[1]=e[13],t[2]=e[14];let s=e.slice(),c=1/i,l=1/a,u=1/o;s[0]*=c,s[1]*=c,s[2]*=c,s[4]*=l,s[5]*=l,s[6]*=l,s[8]*=u,s[9]*=u,s[10]*=u,be(n,s),r[0]=i,r[1]=a,r[2]=o}static compose(e,t,n,r){let i=r,a=t[0],o=t[1],s=t[2],c=t[3],l=a+a,u=o+o,d=s+s,f=a*l,p=a*u,m=a*d,h=o*u,g=o*d,_=s*d,v=c*l,y=c*u,b=c*d,x=n[0],S=n[1],ee=n[2];return i[0]=(1-(h+_))*x,i[1]=(p+b)*x,i[2]=(m-y)*x,i[3]=0,i[4]=(p-b)*S,i[5]=(1-(f+_))*S,i[6]=(g+v)*S,i[7]=0,i[8]=(m+y)*ee,i[9]=(g-v)*ee,i[10]=(1-(f+h))*ee,i[11]=0,i[12]=e[0],i[13]=e[1],i[14]=e[2],i[15]=1,i}};function xe(e,t){if(!!e!=!!t)return!1;let n=e.getChild(),r=t.getChild();return n===r||n.equals(r)}function Se(e,t){if(!!e!=!!t)return!1;let n=e.values(),r=t.values();if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(t.getChild()!==i.getChild()&&!t.getChild().equals(i.getChild()))return!1}return!0}function Ce(e,t){if(!!e!=!!t)return!1;let n=e.keys(),r=t.keys();if(n.length!==r.length)return!1;for(let r of n){let n=e.get(r),i=t.get(r);if(!!n!=!!i)return!1;let a=n.getChild(),o=i.getChild();if(a!==o&&!a.equals(o))return!1}return!0}function we(e,t){if(e===t)return!0;if(!!e!=!!t||!e||!t||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Te(e,t){if(e===t)return!0;if(!!e!=!!t)return!1;if(!pe(e)||!pe(t))return e===t;let n=e,r=t,i=0,a=0,o;for(o in n)i++;for(o in r)a++;if(i!==a)return!1;for(o in n){let e=n[o],t=r[o];if(Ee(e)&&Ee(t)){if(!we(e,t))return!1}else if(pe(e)&&pe(t)){if(!Te(e,t))return!1}else if(e!==t)return!1}return!0}function Ee(e){return Array.isArray(e)||ArrayBuffer.isView(e)}var De=`23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ`,Oe=999,ke=6,Ae=new Set,je=function(){let e=``;for(let t=0;t<ke;t++)e+=De.charAt(Math.floor(Math.random()*42));return e},Me=function(){for(let e=0;e<Oe;e++){let e=je();if(!Ae.has(e))return Ae.add(e),e}return``},Ne=e=>e,Pe=new Set,Fe=class extends d{constructor(e,t=``){super(e),this[l].name=t,this.init(),this.dispatchEvent({type:`create`})}getGraph(){return this.graph}getDefaults(){return Object.assign(super.getDefaults(),{name:``,extras:{}})}set(e,t){return Array.isArray(t)&&(t=t.slice()),super.set(e,t)}getName(){return this.get(`name`)}setName(e){return this.set(`name`,e)}getExtras(){return this.get(`extras`)}setExtras(e){return this.set(`extras`,e)}clone(){let e=this.constructor;return new e(this.graph).copy(this,Ne)}copy(e,t=Ne){for(let e in this[l]){let t=this[l][e];if(t instanceof i)this[u].has(e)||t.dispose();else if(t instanceof o||t instanceof s)for(let e of t.values())e.dispose();else if(t instanceof c)for(let e of t.values())e.dispose()}for(let n in e[l]){let r=this[l][n],a=e[l][n];if(a instanceof i)this[u].has(n)?r.getChild().copy(t(a.getChild()),t):this.setRef(n,t(a.getChild()),a.getAttributes());else if(a instanceof s||a instanceof o)for(let e of a.values())this.addRef(n,t(e.getChild()),e.getAttributes());else if(a instanceof c)for(let e of a.keys()){let r=a.get(e);this.setRefMap(n,e,t(r.getChild()),r.getAttributes())}else pe(a)?this[l][n]=JSON.parse(JSON.stringify(a)):Array.isArray(a)||a instanceof ArrayBuffer||ArrayBuffer.isView(a)?this[l][n]=a.slice():this[l][n]=a}return this}equals(e,t=Pe){if(this===e)return!0;if(this.propertyType!==e.propertyType)return!1;for(let n in this[l]){if(t.has(n))continue;let r=this[l][n],a=e[l][n];if(r instanceof i||a instanceof i){if(!xe(r,a))return!1}else if(r instanceof s||a instanceof s||r instanceof o||a instanceof o){if(!Se(r,a))return!1}else if(r instanceof c||a instanceof c){if(!Ce(r,a))return!1}else if(pe(r)||pe(a)){if(!Te(r,a))return!1}else if(Ee(r)||Ee(a)){if(!we(r,a))return!1}else if(r!==a)return!1}return!0}detach(){return this.graph.disconnectParents(this,e=>e.propertyType!==`Root`),this}listParents(){return this.graph.listParents(this)}},E=class extends Fe{getDefaults(){return Object.assign(super.getDefaults(),{extensions:new c})}getExtension(e){return this.getRefMap(`extensions`,e)}setExtension(e,t){return t&&t._validateParent(this),this.setRefMap(`extensions`,e,t)}listExtensions(){return this.listRefMapValues(`extensions`)}},D=class e extends E{init(){this.propertyType=m.ACCESSOR}getDefaults(){return Object.assign(super.getDefaults(),{array:null,type:e.Type.SCALAR,componentType:e.ComponentType.FLOAT,normalized:!1,sparse:!1,buffer:null})}static getElementSize(t){switch(t){case e.Type.SCALAR:return 1;case e.Type.VEC2:return 2;case e.Type.VEC3:return 3;case e.Type.VEC4:return 4;case e.Type.MAT2:return 4;case e.Type.MAT3:return 9;case e.Type.MAT4:return 16;default:throw Error(`Unexpected type: `+t)}}static getComponentSize(t){switch(t){case e.ComponentType.BYTE:return 1;case e.ComponentType.UNSIGNED_BYTE:return 1;case e.ComponentType.SHORT:return 2;case e.ComponentType.UNSIGNED_SHORT:return 2;case e.ComponentType.UNSIGNED_INT:return 4;case e.ComponentType.FLOAT:return 4;default:throw Error(`Unexpected component type: `+t)}}getMinNormalized(e){let t=this.getNormalized(),n=this.getElementSize(),r=this.getComponentType();if(this.getMin(e),t)for(let t=0;t<n;t++)e[t]=T.decodeNormalizedInt(e[t],r);return e}getMin(e){let t=this.getArray(),n=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=1/0;for(let i=0;i<n*r;i+=r)for(let n=0;n<r;n++){let r=t[i+n];Number.isFinite(r)&&(e[n]=Math.min(e[n],r))}return e}getMaxNormalized(e){let t=this.getNormalized(),n=this.getElementSize(),r=this.getComponentType();if(this.getMax(e),t)for(let t=0;t<n;t++)e[t]=T.decodeNormalizedInt(e[t],r);return e}getMax(e){let t=this.get(`array`),n=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=-1/0;for(let i=0;i<n*r;i+=r)for(let n=0;n<r;n++){let r=t[i+n];Number.isFinite(r)&&(e[n]=Math.max(e[n],r))}return e}getCount(){let e=this.get(`array`);return e?e.length/this.getElementSize():0}getType(){return this.get(`type`)}setType(e){return this.set(`type`,e)}getElementSize(){return e.getElementSize(this.get(`type`))}getComponentSize(){return this.get(`array`).BYTES_PER_ELEMENT}getComponentType(){return this.get(`componentType`)}getNormalized(){return this.get(`normalized`)}setNormalized(e){return this.set(`normalized`,e)}getScalar(e){let t=this.getElementSize(),n=this.getComponentType(),r=this.getArray();return this.getNormalized()?T.decodeNormalizedInt(r[e*t],n):r[e*t]}setScalar(e,t){let n=this.getElementSize(),r=this.getComponentType(),i=this.getArray();return this.getNormalized()?i[e*n]=T.encodeNormalizedInt(t,r):i[e*n]=t,this}getElement(e,t){let n=this.getNormalized(),r=this.getElementSize(),i=this.getComponentType(),a=this.getArray();for(let o=0;o<r;o++)n?t[o]=T.decodeNormalizedInt(a[e*r+o],i):t[o]=a[e*r+o];return t}setElement(e,t){let n=this.getNormalized(),r=this.getElementSize(),i=this.getComponentType(),a=this.getArray();for(let o=0;o<r;o++)n?a[e*r+o]=T.encodeNormalizedInt(t[o],i):a[e*r+o]=t[o];return this}getSparse(){return this.get(`sparse`)}setSparse(e){return this.set(`sparse`,e)}getBuffer(){return this.getRef(`buffer`)}setBuffer(e){return this.setRef(`buffer`,e)}getArray(){return this.get(`array`)}setArray(t){return this.set(`componentType`,t?Ie(t):e.ComponentType.FLOAT),this.set(`array`,t),this}getByteLength(){let e=this.get(`array`);return e?e.byteLength:0}};D.Type={SCALAR:`SCALAR`,VEC2:`VEC2`,VEC3:`VEC3`,VEC4:`VEC4`,MAT2:`MAT2`,MAT3:`MAT3`,MAT4:`MAT4`},D.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126};function Ie(e){switch(e.constructor){case Float32Array:return D.ComponentType.FLOAT;case Uint32Array:return D.ComponentType.UNSIGNED_INT;case Uint16Array:return D.ComponentType.UNSIGNED_SHORT;case Uint8Array:return D.ComponentType.UNSIGNED_BYTE;case Int16Array:return D.ComponentType.SHORT;case Int8Array:return D.ComponentType.BYTE;default:throw Error(`Unknown accessor componentType.`)}}var Le=class extends E{init(){this.propertyType=m.ANIMATION}getDefaults(){return Object.assign(super.getDefaults(),{channels:new s,samplers:new s})}addChannel(e){return this.addRef(`channels`,e)}removeChannel(e){return this.removeRef(`channels`,e)}listChannels(){return this.listRefs(`channels`)}addSampler(e){return this.addRef(`samplers`,e)}removeSampler(e){return this.removeRef(`samplers`,e)}listSamplers(){return this.listRefs(`samplers`)}},Re=class extends E{init(){this.propertyType=m.ANIMATION_CHANNEL}getDefaults(){return Object.assign(super.getDefaults(),{targetPath:null,targetNode:null,sampler:null})}getTargetPath(){return this.get(`targetPath`)}setTargetPath(e){return this.set(`targetPath`,e)}getTargetNode(){return this.getRef(`targetNode`)}setTargetNode(e){return this.setRef(`targetNode`,e)}getSampler(){return this.getRef(`sampler`)}setSampler(e){return this.setRef(`sampler`,e)}};Re.TargetPath={TRANSLATION:`translation`,ROTATION:`rotation`,SCALE:`scale`,WEIGHTS:`weights`};var ze=class e extends E{init(){this.propertyType=m.ANIMATION_SAMPLER}getDefaultAttributes(){return Object.assign(super.getDefaults(),{interpolation:e.Interpolation.LINEAR,input:null,output:null})}getInterpolation(){return this.get(`interpolation`)}setInterpolation(e){return this.set(`interpolation`,e)}getInput(){return this.getRef(`input`)}setInput(e){return this.setRef(`input`,e,{usage:g.OTHER})}getOutput(){return this.getRef(`output`)}setOutput(e){return this.setRef(`output`,e,{usage:g.OTHER})}};ze.Interpolation={LINEAR:`LINEAR`,STEP:`STEP`,CUBICSPLINE:`CUBICSPLINE`};var Be=class extends E{init(){this.propertyType=m.BUFFER}getDefaults(){return Object.assign(super.getDefaults(),{uri:``})}getURI(){return this.get(`uri`)}setURI(e){return this.set(`uri`,e)}},Ve=class e extends E{init(){this.propertyType=m.CAMERA}getDefaults(){return Object.assign(super.getDefaults(),{type:e.Type.PERSPECTIVE,znear:.1,zfar:100,aspectRatio:null,yfov:Math.PI*2*50/360,xmag:1,ymag:1})}getType(){return this.get(`type`)}setType(e){return this.set(`type`,e)}getZNear(){return this.get(`znear`)}setZNear(e){return this.set(`znear`,e)}getZFar(){return this.get(`zfar`)}setZFar(e){return this.set(`zfar`,e)}getAspectRatio(){return this.get(`aspectRatio`)}setAspectRatio(e){return this.set(`aspectRatio`,e)}getYFov(){return this.get(`yfov`)}setYFov(e){return this.set(`yfov`,e)}getXMag(){return this.get(`xmag`)}setXMag(e){return this.set(`xmag`,e)}getYMag(){return this.get(`ymag`)}setYMag(e){return this.set(`ymag`,e)}};Ve.Type={PERSPECTIVE:`perspective`,ORTHOGRAPHIC:`orthographic`};var O=class extends Fe{_validateParent(e){if(!this.parentTypes.includes(e.propertyType))throw Error(`Parent "${e.propertyType}" invalid for child "${this.propertyType}".`)}};O.EXTENSION_NAME=void 0;var k=class e extends E{init(){this.propertyType=m.TEXTURE_INFO}getDefaults(){return Object.assign(super.getDefaults(),{texCoord:0,magFilter:null,minFilter:null,wrapS:e.WrapMode.REPEAT,wrapT:e.WrapMode.REPEAT})}getTexCoord(){return this.get(`texCoord`)}setTexCoord(e){return this.set(`texCoord`,e)}getMagFilter(){return this.get(`magFilter`)}setMagFilter(e){return this.set(`magFilter`,e)}getMinFilter(){return this.get(`minFilter`)}setMinFilter(e){return this.set(`minFilter`,e)}getWrapS(){return this.get(`wrapS`)}setWrapS(e){return this.set(`wrapS`,e)}getWrapT(){return this.get(`wrapT`)}setWrapT(e){return this.set(`wrapT`,e)}};k.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},k.MagFilter={NEAREST:9728,LINEAR:9729},k.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var{R:He,G:Ue,B:We,A:Ge}=_,Ke=class e extends E{init(){this.propertyType=m.MATERIAL}getDefaults(){return Object.assign(super.getDefaults(),{alphaMode:e.AlphaMode.OPAQUE,alphaCutoff:.5,doubleSided:!1,baseColorFactor:[1,1,1,1],baseColorTexture:null,baseColorTextureInfo:new k(this.graph,`baseColorTextureInfo`),emissiveFactor:[0,0,0],emissiveTexture:null,emissiveTextureInfo:new k(this.graph,`emissiveTextureInfo`),normalScale:1,normalTexture:null,normalTextureInfo:new k(this.graph,`normalTextureInfo`),occlusionStrength:1,occlusionTexture:null,occlusionTextureInfo:new k(this.graph,`occlusionTextureInfo`),roughnessFactor:1,metallicFactor:1,metallicRoughnessTexture:null,metallicRoughnessTextureInfo:new k(this.graph,`metallicRoughnessTextureInfo`)})}getDoubleSided(){return this.get(`doubleSided`)}setDoubleSided(e){return this.set(`doubleSided`,e)}getAlpha(){return this.get(`baseColorFactor`)[3]}setAlpha(e){let t=this.get(`baseColorFactor`).slice();return t[3]=e,this.set(`baseColorFactor`,t)}getAlphaMode(){return this.get(`alphaMode`)}setAlphaMode(e){return this.set(`alphaMode`,e)}getAlphaCutoff(){return this.get(`alphaCutoff`)}setAlphaCutoff(e){return this.set(`alphaCutoff`,e)}getBaseColorFactor(){return this.get(`baseColorFactor`)}setBaseColorFactor(e){return this.set(`baseColorFactor`,e)}getBaseColorTexture(){return this.getRef(`baseColorTexture`)}getBaseColorTextureInfo(){return this.getRef(`baseColorTexture`)?this.getRef(`baseColorTextureInfo`):null}setBaseColorTexture(e){return this.setRef(`baseColorTexture`,e,{channels:He|Ue|We|Ge,isColor:!0})}getEmissiveFactor(){return this.get(`emissiveFactor`)}setEmissiveFactor(e){return this.set(`emissiveFactor`,e)}getEmissiveTexture(){return this.getRef(`emissiveTexture`)}getEmissiveTextureInfo(){return this.getRef(`emissiveTexture`)?this.getRef(`emissiveTextureInfo`):null}setEmissiveTexture(e){return this.setRef(`emissiveTexture`,e,{channels:He|Ue|We,isColor:!0})}getNormalScale(){return this.get(`normalScale`)}setNormalScale(e){return this.set(`normalScale`,e)}getNormalTexture(){return this.getRef(`normalTexture`)}getNormalTextureInfo(){return this.getRef(`normalTexture`)?this.getRef(`normalTextureInfo`):null}setNormalTexture(e){return this.setRef(`normalTexture`,e,{channels:He|Ue|We})}getOcclusionStrength(){return this.get(`occlusionStrength`)}setOcclusionStrength(e){return this.set(`occlusionStrength`,e)}getOcclusionTexture(){return this.getRef(`occlusionTexture`)}getOcclusionTextureInfo(){return this.getRef(`occlusionTexture`)?this.getRef(`occlusionTextureInfo`):null}setOcclusionTexture(e){return this.setRef(`occlusionTexture`,e,{channels:He})}getRoughnessFactor(){return this.get(`roughnessFactor`)}setRoughnessFactor(e){return this.set(`roughnessFactor`,e)}getMetallicFactor(){return this.get(`metallicFactor`)}setMetallicFactor(e){return this.set(`metallicFactor`,e)}getMetallicRoughnessTexture(){return this.getRef(`metallicRoughnessTexture`)}getMetallicRoughnessTextureInfo(){return this.getRef(`metallicRoughnessTexture`)?this.getRef(`metallicRoughnessTextureInfo`):null}setMetallicRoughnessTexture(e){return this.setRef(`metallicRoughnessTexture`,e,{channels:Ue|We})}};Ke.AlphaMode={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};var qe=class extends E{init(){this.propertyType=m.MESH}getDefaults(){return Object.assign(super.getDefaults(),{weights:[],primitives:new s})}addPrimitive(e){return this.addRef(`primitives`,e)}removePrimitive(e){return this.removeRef(`primitives`,e)}listPrimitives(){return this.listRefs(`primitives`)}getWeights(){return this.get(`weights`)}setWeights(e){return this.set(`weights`,e)}},Je=class extends E{init(){this.propertyType=m.NODE}getDefaults(){return Object.assign(super.getDefaults(),{translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1],weights:[],camera:null,mesh:null,skin:null,children:new s})}copy(e,t=Ne){if(t===Ne)throw Error(`Node cannot be copied.`);return super.copy(e,t)}getTranslation(){return this.get(`translation`)}getRotation(){return this.get(`rotation`)}getScale(){return this.get(`scale`)}setTranslation(e){return this.set(`translation`,e)}setRotation(e){return this.set(`rotation`,e)}setScale(e){return this.set(`scale`,e)}getMatrix(){return T.compose(this.get(`translation`),this.get(`rotation`),this.get(`scale`),[])}setMatrix(e){let t=this.get(`translation`).slice(),n=this.get(`rotation`).slice(),r=this.get(`scale`).slice();return T.decompose(e,t,n,r),this.set(`translation`,t).set(`rotation`,n).set(`scale`,r)}getWorldTranslation(){let e=[0,0,0];return T.decompose(this.getWorldMatrix(),e,[0,0,0,1],[1,1,1]),e}getWorldRotation(){let e=[0,0,0,1];return T.decompose(this.getWorldMatrix(),[0,0,0],e,[1,1,1]),e}getWorldScale(){let e=[1,1,1];return T.decompose(this.getWorldMatrix(),[0,0,0],[0,0,0,1],e),e}getWorldMatrix(){let e=[];for(let t=this;t!=null;t=t.getParentNode())e.push(t);let t,n=e.pop().getMatrix();for(;t=e.pop();)ve(n,n,t.getMatrix());return n}addChild(e){let t=e.getParentNode();t&&t.removeChild(e);for(let t of e.listParents())t.propertyType===m.SCENE&&t.removeChild(e);return this.addRef(`children`,e)}removeChild(e){return this.removeRef(`children`,e)}listChildren(){return this.listRefs(`children`)}getParentNode(){for(let e of this.listParents())if(e.propertyType===m.NODE)return e;return null}getMesh(){return this.getRef(`mesh`)}setMesh(e){return this.setRef(`mesh`,e)}getCamera(){return this.getRef(`camera`)}setCamera(e){return this.setRef(`camera`,e)}getSkin(){return this.getRef(`skin`)}setSkin(e){return this.setRef(`skin`,e)}getWeights(){return this.get(`weights`)}setWeights(e){return this.set(`weights`,e)}traverse(e){e(this);for(let t of this.listChildren())t.traverse(e);return this}},Ye=class e extends E{init(){this.propertyType=m.PRIMITIVE}getDefaults(){return Object.assign(super.getDefaults(),{mode:e.Mode.TRIANGLES,material:null,indices:null,attributes:new c,targets:new s})}getIndices(){return this.getRef(`indices`)}setIndices(e){return this.setRef(`indices`,e,{usage:g.ELEMENT_ARRAY_BUFFER})}getAttribute(e){return this.getRefMap(`attributes`,e)}setAttribute(e,t){return this.setRefMap(`attributes`,e,t,{usage:g.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues(`attributes`)}listSemantics(){return this.listRefMapKeys(`attributes`)}getMaterial(){return this.getRef(`material`)}setMaterial(e){return this.setRef(`material`,e)}getMode(){return this.get(`mode`)}setMode(e){return this.set(`mode`,e)}listTargets(){return this.listRefs(`targets`)}addTarget(e){return this.addRef(`targets`,e)}removeTarget(e){return this.removeRef(`targets`,e)}};Ye.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6};var Xe=class extends Fe{init(){this.propertyType=m.PRIMITIVE_TARGET}getDefaults(){return Object.assign(super.getDefaults(),{attributes:new c})}getAttribute(e){return this.getRefMap(`attributes`,e)}setAttribute(e,t){return this.setRefMap(`attributes`,e,t,{usage:g.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues(`attributes`)}listSemantics(){return this.listRefMapKeys(`attributes`)}};function A(){return A=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},A.apply(null,arguments)}var Ze=class extends E{init(){this.propertyType=m.SCENE}getDefaults(){return Object.assign(super.getDefaults(),{children:new s})}copy(e,t=Ne){if(t===Ne)throw Error(`Scene cannot be copied.`);return super.copy(e,t)}addChild(e){let t=e.getParentNode();return t&&t.removeChild(e),this.addRef(`children`,e)}removeChild(e){return this.removeRef(`children`,e)}listChildren(){return this.listRefs(`children`)}traverse(e){for(let t of this.listChildren())t.traverse(e);return this}},Qe=class extends E{init(){this.propertyType=m.SKIN}getDefaults(){return Object.assign(super.getDefaults(),{skeleton:null,inverseBindMatrices:null,joints:new s})}getSkeleton(){return this.getRef(`skeleton`)}setSkeleton(e){return this.setRef(`skeleton`,e)}getInverseBindMatrices(){return this.getRef(`inverseBindMatrices`)}setInverseBindMatrices(e){return this.setRef(`inverseBindMatrices`,e,{usage:g.INVERSE_BIND_MATRICES})}addJoint(e){return this.addRef(`joints`,e)}removeJoint(e){return this.removeRef(`joints`,e)}listJoints(){return this.listRefs(`joints`)}},$e=class extends E{init(){this.propertyType=m.TEXTURE}getDefaults(){return Object.assign(super.getDefaults(),{image:null,mimeType:``,uri:``})}getMimeType(){return this.get(`mimeType`)||C.extensionToMimeType(w.extension(this.get(`uri`)))}setMimeType(e){return this.set(`mimeType`,e)}getURI(){return this.get(`uri`)}setURI(e){this.set(`uri`,e);let t=C.extensionToMimeType(w.extension(e));return t&&this.set(`mimeType`,t),this}getImage(){return this.get(`image`)}setImage(e){return this.set(`image`,b.assertView(e))}getSize(){let e=this.get(`image`);return e?C.getSize(e,this.getMimeType()):null}},et=class extends E{init(){this.propertyType=m.ROOT}getDefaults(){return Object.assign(super.getDefaults(),{asset:{generator:`glTF-Transform ${f}`,version:`2.0`},defaultScene:null,accessors:new s,animations:new s,buffers:new s,cameras:new s,materials:new s,meshes:new s,nodes:new s,scenes:new s,skins:new s,textures:new s})}constructor(e){super(e),this._extensions=new Set,e.addEventListener(`node:create`,e=>{this._addChildOfRoot(e.target)})}clone(){throw Error(`Root cannot be cloned.`)}copy(e,t=Ne){if(t===Ne)throw Error(`Root cannot be copied.`);this.set(`asset`,A({},e.get(`asset`))),this.setName(e.getName()),this.setExtras(A({},e.getExtras())),this.setDefaultScene(e.getDefaultScene()?t(e.getDefaultScene()):null);for(let n of e.listRefMapKeys(`extensions`)){let r=e.getExtension(n);this.setExtension(n,t(r))}return this}_addChildOfRoot(e){return e instanceof Ze?this.addRef(`scenes`,e):e instanceof Je?this.addRef(`nodes`,e):e instanceof Ve?this.addRef(`cameras`,e):e instanceof Qe?this.addRef(`skins`,e):e instanceof qe?this.addRef(`meshes`,e):e instanceof Ke?this.addRef(`materials`,e):e instanceof $e?this.addRef(`textures`,e):e instanceof Le?this.addRef(`animations`,e):e instanceof D?this.addRef(`accessors`,e):e instanceof Be&&this.addRef(`buffers`,e),this}getAsset(){return this.get(`asset`)}listExtensionsUsed(){return Array.from(this._extensions)}listExtensionsRequired(){return this.listExtensionsUsed().filter(e=>e.isRequired())}_enableExtension(e){return this._extensions.add(e),this}_disableExtension(e){return this._extensions.delete(e),this}listScenes(){return this.listRefs(`scenes`)}setDefaultScene(e){return this.setRef(`defaultScene`,e)}getDefaultScene(){return this.getRef(`defaultScene`)}listNodes(){return this.listRefs(`nodes`)}listCameras(){return this.listRefs(`cameras`)}listSkins(){return this.listRefs(`skins`)}listMeshes(){return this.listRefs(`meshes`)}listMaterials(){return this.listRefs(`materials`)}listTextures(){return this.listRefs(`textures`)}listAnimations(){return this.listRefs(`animations`)}listAccessors(){return this.listRefs(`accessors`)}listBuffers(){return this.listRefs(`buffers`)}},tt=class e{static fromGraph(t){return e._GRAPH_DOCUMENTS.get(t)||null}constructor(){this._graph=new a,this._root=new et(this._graph),this._logger=ge.DEFAULT_INSTANCE,e._GRAPH_DOCUMENTS.set(this._graph,this)}getRoot(){return this._root}getGraph(){return this._graph}getLogger(){return this._logger}setLogger(e){return this._logger=e,this}clone(){throw Error(`Use 'cloneDocument(source)' from '@gltf-transform/functions'.`)}merge(e){throw Error(`Use 'mergeDocuments(target, source)' from '@gltf-transform/functions'.`)}async transform(...e){let t=e.map(e=>e.name);for(let n of e)await n(this,{stack:t});return this}createExtension(e){let t=e.EXTENSION_NAME;return this.getRoot().listExtensionsUsed().find(e=>e.extensionName===t)||new e(this)}disposeExtension(e){let t=this.getRoot().listExtensionsUsed().find(t=>t.extensionName===e);t&&t.dispose()}createScene(e=``){return new Ze(this._graph,e)}createNode(e=``){return new Je(this._graph,e)}createCamera(e=``){return new Ve(this._graph,e)}createSkin(e=``){return new Qe(this._graph,e)}createMesh(e=``){return new qe(this._graph,e)}createPrimitive(){return new Ye(this._graph)}createPrimitiveTarget(e=``){return new Xe(this._graph,e)}createMaterial(e=``){return new Ke(this._graph,e)}createTexture(e=``){return new $e(this._graph,e)}createAnimation(e=``){return new Le(this._graph,e)}createAnimationChannel(e=``){return new Re(this._graph,e)}createAnimationSampler(e=``){return new ze(this._graph,e)}createAccessor(e=``,t=null){return t||=this.getRoot().listBuffers()[0],new D(this._graph,e).setBuffer(t)}createBuffer(e=``){return new Be(this._graph,e)}};tt._GRAPH_DOCUMENTS=new WeakMap;var j=class{constructor(e){this.extensionName=``,this.prereadTypes=[],this.prewriteTypes=[],this.readDependencies=[],this.writeDependencies=[],this.document=void 0,this.required=!1,this.properties=new Set,this._listener=void 0,this.document=e,e.getRoot()._enableExtension(this),this._listener=e=>{let t=e,n=t.target;n instanceof O&&n.extensionName===this.extensionName&&(t.type===`node:create`&&this._addExtensionProperty(n),t.type===`node:dispose`&&this._removeExtensionProperty(n))};let t=e.getGraph();t.addEventListener(`node:create`,this._listener),t.addEventListener(`node:dispose`,this._listener)}dispose(){this.document.getRoot()._disableExtension(this);let e=this.document.getGraph();e.removeEventListener(`node:create`,this._listener),e.removeEventListener(`node:dispose`,this._listener);for(let e of this.properties)e.dispose()}static register(){}isRequired(){return this.required}setRequired(e){return this.required=e,this}listProperties(){return Array.from(this.properties)}_addExtensionProperty(e){return this.properties.add(e),this}_removeExtensionProperty(e){return this.properties.delete(e),this}install(e,t){return this}preread(e,t){return this}prewrite(e,t){return this}};j.EXTENSION_NAME=void 0;var nt=class{constructor(e){this.jsonDoc=void 0,this.buffers=[],this.bufferViews=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[],this.jsonDoc=e}setTextureInfo(e,t){this.textureInfos.set(e,t),t.texCoord!==void 0&&e.setTexCoord(t.texCoord),t.extras!==void 0&&e.setExtras(t.extras);let n=this.jsonDoc.json.textures[t.index];if(n.sampler===void 0)return;let r=this.jsonDoc.json.samplers[n.sampler];r.magFilter!==void 0&&e.setMagFilter(r.magFilter),r.minFilter!==void 0&&e.setMinFilter(r.minFilter),r.wrapS!==void 0&&e.setWrapS(r.wrapS),r.wrapT!==void 0&&e.setWrapT(r.wrapT)}},rt={logger:ge.DEFAULT_INSTANCE,extensions:[],dependencies:{}},it=new Set([m.BUFFER,m.TEXTURE,m.MATERIAL,m.MESH,m.PRIMITIVE,m.NODE,m.SCENE]),at=class{static read(e,t=rt){let n=A({},rt,t),{json:r}=e,i=new tt().setLogger(n.logger);this.validate(e,n);let a=new nt(e),o=r.asset,s=i.getRoot().getAsset();o.copyright&&(s.copyright=o.copyright),o.extras&&(s.extras=o.extras),r.extras!==void 0&&i.getRoot().setExtras(A({},r.extras));let c=r.extensionsUsed||[],l=r.extensionsRequired||[];n.extensions.sort((e,t)=>e.EXTENSION_NAME>t.EXTENSION_NAME?1:-1);for(let e of n.extensions)if(c.includes(e.EXTENSION_NAME)){let t=i.createExtension(e).setRequired(l.includes(e.EXTENSION_NAME)),r=t.prereadTypes.filter(e=>!it.has(e));r.length&&n.logger.warn(`Preread hooks for some types (${r.join()}), requested by extension ${t.extensionName}, are unsupported. Please file an issue or a PR.`);for(let e of t.readDependencies)t.install(e,n.dependencies[e])}let u=r.buffers||[];i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.BUFFER)).forEach(e=>e.preread(a,m.BUFFER)),a.buffers=u.map(e=>{let t=i.createBuffer(e.name);return e.extras&&t.setExtras(e.extras),e.uri&&e.uri.indexOf(`__`)!==0&&t.setURI(e.uri),t}),a.bufferViewBuffers=(r.bufferViews||[]).map((t,n)=>{if(!a.bufferViews[n]){let r=e.json.buffers[t.buffer],i=r.uri?e.resources[r.uri]:e.resources[p],o=t.byteOffset||0;a.bufferViews[n]=b.toView(i,o,t.byteLength)}return a.buffers[t.buffer]});let d=r.accessors||[];a.accessors=d.map(e=>{let t=a.bufferViewBuffers[e.bufferView],n=i.createAccessor(e.name,t).setType(e.type);return e.extras&&n.setExtras(e.extras),e.normalized!==void 0&&n.setNormalized(e.normalized),e.bufferView===void 0||n.setArray(st(e,a)),n});let f=r.images||[],h=r.textures||[];i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.TEXTURE)).forEach(e=>e.preread(a,m.TEXTURE)),a.textures=f.map(t=>{let n=i.createTexture(t.name);if(t.extras&&n.setExtras(t.extras),t.bufferView!==void 0){let i=r.bufferViews[t.bufferView],a=e.json.buffers[i.buffer],o=a.uri?e.resources[a.uri]:e.resources[p],s=i.byteOffset||0,c=i.byteLength,l=o.slice(s,s+c);n.setImage(l)}else t.uri!==void 0&&(n.setImage(e.resources[t.uri]),t.uri.indexOf(`__`)!==0&&n.setURI(t.uri));if(t.mimeType!==void 0)n.setMimeType(t.mimeType);else if(t.uri){let e=w.extension(t.uri);n.setMimeType(C.extensionToMimeType(e))}return n}),i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.MATERIAL)).forEach(e=>e.preread(a,m.MATERIAL)),a.materials=(r.materials||[]).map(e=>{let t=i.createMaterial(e.name);e.extras&&t.setExtras(e.extras),e.alphaMode!==void 0&&t.setAlphaMode(e.alphaMode),e.alphaCutoff!==void 0&&t.setAlphaCutoff(e.alphaCutoff),e.doubleSided!==void 0&&t.setDoubleSided(e.doubleSided);let n=e.pbrMetallicRoughness||{};if(n.baseColorFactor!==void 0&&t.setBaseColorFactor(n.baseColorFactor),e.emissiveFactor!==void 0&&t.setEmissiveFactor(e.emissiveFactor),n.metallicFactor!==void 0&&t.setMetallicFactor(n.metallicFactor),n.roughnessFactor!==void 0&&t.setRoughnessFactor(n.roughnessFactor),n.baseColorTexture!==void 0){let e=n.baseColorTexture,r=a.textures[h[e.index].source];t.setBaseColorTexture(r),a.setTextureInfo(t.getBaseColorTextureInfo(),e)}if(e.emissiveTexture!==void 0){let n=e.emissiveTexture,r=a.textures[h[n.index].source];t.setEmissiveTexture(r),a.setTextureInfo(t.getEmissiveTextureInfo(),n)}if(e.normalTexture!==void 0){let n=e.normalTexture,r=a.textures[h[n.index].source];t.setNormalTexture(r),a.setTextureInfo(t.getNormalTextureInfo(),n),e.normalTexture.scale!==void 0&&t.setNormalScale(e.normalTexture.scale)}if(e.occlusionTexture!==void 0){let n=e.occlusionTexture,r=a.textures[h[n.index].source];t.setOcclusionTexture(r),a.setTextureInfo(t.getOcclusionTextureInfo(),n),e.occlusionTexture.strength!==void 0&&t.setOcclusionStrength(e.occlusionTexture.strength)}if(n.metallicRoughnessTexture!==void 0){let e=n.metallicRoughnessTexture,r=a.textures[h[e.index].source];t.setMetallicRoughnessTexture(r),a.setTextureInfo(t.getMetallicRoughnessTextureInfo(),e)}return t}),i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.MESH)).forEach(e=>e.preread(a,m.MESH));let g=r.meshes||[];i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.PRIMITIVE)).forEach(e=>e.preread(a,m.PRIMITIVE)),a.meshes=g.map(e=>{let t=i.createMesh(e.name);return e.extras&&t.setExtras(e.extras),e.weights!==void 0&&t.setWeights(e.weights),(e.primitives||[]).forEach(n=>{let r=i.createPrimitive();n.extras&&r.setExtras(n.extras),n.material!==void 0&&r.setMaterial(a.materials[n.material]),n.mode!==void 0&&r.setMode(n.mode);for(let[e,t]of Object.entries(n.attributes||{}))r.setAttribute(e,a.accessors[t]);n.indices!==void 0&&r.setIndices(a.accessors[n.indices]);let o=e.extras&&e.extras.targetNames||[];(n.targets||[]).forEach((e,t)=>{let n=o[t]||t.toString(),s=i.createPrimitiveTarget(n);for(let[t,n]of Object.entries(e))s.setAttribute(t,a.accessors[n]);r.addTarget(s)}),t.addPrimitive(r)}),t}),a.cameras=(r.cameras||[]).map(e=>{let t=i.createCamera(e.name).setType(e.type);if(e.extras&&t.setExtras(e.extras),e.type===Ve.Type.PERSPECTIVE){let n=e.perspective;t.setYFov(n.yfov),t.setZNear(n.znear),n.zfar!==void 0&&t.setZFar(n.zfar),n.aspectRatio!==void 0&&t.setAspectRatio(n.aspectRatio)}else{let n=e.orthographic;t.setZNear(n.znear).setZFar(n.zfar).setXMag(n.xmag).setYMag(n.ymag)}return t});let _=r.nodes||[];i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.NODE)).forEach(e=>e.preread(a,m.NODE)),a.nodes=_.map(e=>{let t=i.createNode(e.name);if(e.extras&&t.setExtras(e.extras),e.translation!==void 0&&t.setTranslation(e.translation),e.rotation!==void 0&&t.setRotation(e.rotation),e.scale!==void 0&&t.setScale(e.scale),e.matrix!==void 0){let n=[0,0,0],r=[0,0,0,1],i=[1,1,1];T.decompose(e.matrix,n,r,i),t.setTranslation(n),t.setRotation(r),t.setScale(i)}return e.weights!==void 0&&t.setWeights(e.weights),t}),a.skins=(r.skins||[]).map(e=>{let t=i.createSkin(e.name);e.extras&&t.setExtras(e.extras),e.inverseBindMatrices!==void 0&&t.setInverseBindMatrices(a.accessors[e.inverseBindMatrices]),e.skeleton!==void 0&&t.setSkeleton(a.nodes[e.skeleton]);for(let n of e.joints)t.addJoint(a.nodes[n]);return t}),_.map((e,t)=>{let n=a.nodes[t];(e.children||[]).forEach(e=>n.addChild(a.nodes[e])),e.mesh!==void 0&&n.setMesh(a.meshes[e.mesh]),e.camera!==void 0&&n.setCamera(a.cameras[e.camera]),e.skin!==void 0&&n.setSkin(a.skins[e.skin])}),a.animations=(r.animations||[]).map(e=>{let t=i.createAnimation(e.name);e.extras&&t.setExtras(e.extras);let n=(e.samplers||[]).map(e=>{let n=i.createAnimationSampler().setInput(a.accessors[e.input]).setOutput(a.accessors[e.output]).setInterpolation(e.interpolation||ze.Interpolation.LINEAR);return e.extras&&n.setExtras(e.extras),t.addSampler(n),n});return(e.channels||[]).forEach(e=>{let r=i.createAnimationChannel().setSampler(n[e.sampler]).setTargetPath(e.target.path);e.target.node!==void 0&&r.setTargetNode(a.nodes[e.target.node]),e.extras&&r.setExtras(e.extras),t.addChannel(r)}),t});let v=r.scenes||[];return i.getRoot().listExtensionsUsed().filter(e=>e.prereadTypes.includes(m.SCENE)).forEach(e=>e.preread(a,m.SCENE)),a.scenes=v.map(e=>{let t=i.createScene(e.name);return e.extras&&t.setExtras(e.extras),(e.nodes||[]).map(e=>a.nodes[e]).forEach(e=>t.addChild(e)),t}),r.scene!==void 0&&i.getRoot().setDefaultScene(a.scenes[r.scene]),i.getRoot().listExtensionsUsed().forEach(e=>e.read(a)),d.forEach((e,t)=>{let n=a.accessors[t],r=!!e.sparse,i=!e.bufferView&&!n.getArray();(r||i)&&n.setSparse(!0).setArray(ct(e,a))}),i}static validate(e,t){let n=e.json;if(n.asset.version!==`2.0`)throw Error(`Unsupported glTF version, "${n.asset.version}".`);if(n.extensionsRequired){for(let e of n.extensionsRequired)if(!t.extensions.find(t=>t.EXTENSION_NAME===e))throw Error(`Missing required extension, "${e}".`)}if(n.extensionsUsed)for(let e of n.extensionsUsed)t.extensions.find(t=>t.EXTENSION_NAME===e)||t.logger.warn(`Missing optional extension, "${e}".`)}};function ot(e,t){let n=t.jsonDoc,r=t.bufferViews[e.bufferView],i=n.json.bufferViews[e.bufferView],a=y[e.componentType],o=D.getElementSize(e.type),s=a.BYTES_PER_ELEMENT,c=e.byteOffset||0,l=new a(e.count*o),u=new DataView(r.buffer,r.byteOffset,r.byteLength),d=i.byteStride;for(let t=0;t<e.count;t++)for(let n=0;n<o;n++){let r=c+t*d+n*s,i;switch(e.componentType){case D.ComponentType.FLOAT:i=u.getFloat32(r,!0);break;case D.ComponentType.UNSIGNED_INT:i=u.getUint32(r,!0);break;case D.ComponentType.UNSIGNED_SHORT:i=u.getUint16(r,!0);break;case D.ComponentType.UNSIGNED_BYTE:i=u.getUint8(r);break;case D.ComponentType.SHORT:i=u.getInt16(r,!0);break;case D.ComponentType.BYTE:i=u.getInt8(r);break;default:throw Error(`Unexpected componentType "${e.componentType}".`)}l[t*o+n]=i}return l}function st(e,t){let n=t.jsonDoc,r=t.bufferViews[e.bufferView],i=n.json.bufferViews[e.bufferView],a=y[e.componentType],o=D.getElementSize(e.type),s=a.BYTES_PER_ELEMENT,c=o*s;if(i.byteStride!==void 0&&i.byteStride!==c)return ot(e,t);let l=r.byteOffset+(e.byteOffset||0),u=e.count*o*s;return new a(r.buffer.slice(l,l+u))}function ct(e,t){let n=y[e.componentType],r=D.getElementSize(e.type),i;i=e.bufferView===void 0?new n(e.count*r):st(e,t);let a=e.sparse;if(!a)return i;let o=a.count,s=A({},e,a.indices,{count:o,type:`SCALAR`}),c=A({},e,a.values,{count:o}),l=st(s,t),u=st(c,t);for(let e=0;e<s.count;e++)for(let t=0;t<r;t++)i[l[e]*r+t]=u[e*r+t];return i}var lt;(function(e){e[e.ARRAY_BUFFER=34962]=`ARRAY_BUFFER`,e[e.ELEMENT_ARRAY_BUFFER=34963]=`ELEMENT_ARRAY_BUFFER`})(lt||={});var M=class{constructor(e,t,n){this._doc=void 0,this.jsonDoc=void 0,this.options=void 0,this.accessorIndexMap=new Map,this.animationIndexMap=new Map,this.bufferIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.textureInfoDefMap=new Map,this.samplerDefIndexMap=new Map,this.sceneIndexMap=new Map,this.imageBufferViews=[],this.otherBufferViews=new Map,this.otherBufferViewsIndexMap=new Map,this.extensionData={},this.bufferURIGenerator=void 0,this.imageURIGenerator=void 0,this.logger=void 0,this._accessorUsageMap=new Map,this.accessorUsageGroupedByParent=new Set([`ARRAY_BUFFER`]),this.accessorParents=new Map,this._doc=e,this.jsonDoc=t,this.options=n;let r=e.getRoot(),i=r.listBuffers().length,a=r.listTextures().length;this.bufferURIGenerator=new ut(i>1,()=>n.basename||`buffer`),this.imageURIGenerator=new ut(a>1,t=>dt(e,t)||n.basename||`texture`),this.logger=e.getLogger()}createTextureInfoDef(e,t){let n={magFilter:t.getMagFilter()||void 0,minFilter:t.getMinFilter()||void 0,wrapS:t.getWrapS(),wrapT:t.getWrapT()},r=JSON.stringify(n);this.samplerDefIndexMap.has(r)||(this.samplerDefIndexMap.set(r,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(n));let i={source:this.imageIndexMap.get(e),sampler:this.samplerDefIndexMap.get(r)},a=JSON.stringify(i);this.textureDefIndexMap.has(a)||(this.textureDefIndexMap.set(a,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(i));let o={index:this.textureDefIndexMap.get(a)};return t.getTexCoord()!==0&&(o.texCoord=t.getTexCoord()),Object.keys(t.getExtras()).length>0&&(o.extras=t.getExtras()),this.textureInfoDefMap.set(t,o),o}createPropertyDef(e){let t={};return e.getName()&&(t.name=e.getName()),Object.keys(e.getExtras()).length>0&&(t.extras=e.getExtras()),t}createAccessorDef(e){let t=this.createPropertyDef(e);return t.type=e.getType(),t.componentType=e.getComponentType(),t.count=e.getCount(),this._doc.getGraph().listParentEdges(e).some(e=>e.getName()===`attributes`&&e.getAttributes().key===`POSITION`||e.getName()===`input`)&&(t.max=e.getMax([]).map(Math.fround),t.min=e.getMin([]).map(Math.fround)),e.getNormalized()&&(t.normalized=e.getNormalized()),t}createImageData(e,t,n){if(this.options.format===v.GLB)this.imageBufferViews.push(t),e.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.byteLength});else{let r=C.mimeTypeToExtension(n.getMimeType());e.uri=this.imageURIGenerator.createURI(n,r),this.assignResourceURI(e.uri,t,!1)}}assignResourceURI(e,t,n){let r=this.jsonDoc.resources;if(!(e in r)){r[e]=t;return}if(t===r[e]){this.logger.warn(`Duplicate resource URI, "${e}".`);return}let i=`Resource URI "${e}" already assigned to different data.`;if(!n){this.logger.warn(i);return}throw Error(i)}getAccessorUsage(e){let t=this._accessorUsageMap.get(e);if(t)return t;if(e.getSparse())return g.SPARSE;for(let t of this._doc.getGraph().listParentEdges(e)){let{usage:e}=t.getAttributes();if(e)return e;t.getParent().propertyType!==m.ROOT&&this.logger.warn(`Missing attribute ".usage" on edge, "${t.getName()}".`)}return g.OTHER}addAccessorToUsageGroup(e,t){let n=this._accessorUsageMap.get(e);if(n&&n!==t)throw Error(`Accessor with usage "${n}" cannot be reused as "${t}".`);return this._accessorUsageMap.set(e,t),this}};M.BufferViewTarget=lt,M.BufferViewUsage=g,M.USAGE_TO_TARGET={[g.ARRAY_BUFFER]:lt.ARRAY_BUFFER,[g.ELEMENT_ARRAY_BUFFER]:lt.ELEMENT_ARRAY_BUFFER};var ut=class{constructor(e,t){this.multiple=void 0,this.basename=void 0,this.counter={},this.multiple=e,this.basename=t}createURI(e,t){if(e.getURI())return e.getURI();if(this.multiple){let n=this.basename(e);return this.counter[n]=this.counter[n]||1,`${n}_${this.counter[n]++}.${t}`}else return`${this.basename(e)}.${t}`}};function dt(e,t){let n=e.getGraph().listParentEdges(t).find(t=>t.getParent()!==e.getRoot());return n?n.getName().replace(/texture$/i,``):``}var{BufferViewUsage:ft}=M,{UNSIGNED_INT:pt,UNSIGNED_SHORT:mt,UNSIGNED_BYTE:ht}=D.ComponentType,gt=new Set([m.ACCESSOR,m.BUFFER,m.MATERIAL,m.MESH]),_t=class{static write(e,t){let n=e.getGraph(),r=e.getRoot(),i={asset:A({generator:`glTF-Transform ${f}`},r.getAsset()),extras:A({},r.getExtras())},a={json:i,resources:{}},o=new M(e,a,t),s=t.logger||ge.DEFAULT_INSTANCE,c=new Set(t.extensions.map(e=>e.EXTENSION_NAME)),l=e.getRoot().listExtensionsUsed().filter(e=>c.has(e.extensionName)).sort((e,t)=>e.extensionName>t.extensionName?1:-1),u=e.getRoot().listExtensionsRequired().filter(e=>c.has(e.extensionName)).sort((e,t)=>e.extensionName>t.extensionName?1:-1);l.length<e.getRoot().listExtensionsUsed().length&&s.warn(`Some extensions were not registered for I/O, and will not be written.`);for(let e of l){let n=e.prewriteTypes.filter(e=>!gt.has(e));n.length&&s.warn(`Prewrite hooks for some types (${n.join()}), requested by extension ${e.extensionName}, are unsupported. Please file an issue or a PR.`);for(let n of e.writeDependencies)e.install(n,t.dependencies[n])}function d(e,t,n,r){let a=[],s=0;for(let t of e){let e=o.createAccessorDef(t);e.bufferView=i.bufferViews.length;let n=t.getArray(),r=b.pad(b.toView(n));e.byteOffset=s,s+=r.byteLength,a.push(r),o.accessorIndexMap.set(t,i.accessors.length),i.accessors.push(e)}let c={buffer:t,byteOffset:n,byteLength:b.concat(a).byteLength};return r&&(c.target=r),i.bufferViews.push(c),{buffers:a,byteLength:s}}function g(e,t,n){let r=e[0].getCount(),a=0;for(let t of e){let e=o.createAccessorDef(t);e.bufferView=i.bufferViews.length,e.byteOffset=a;let n=t.getElementSize(),r=t.getComponentSize();a+=b.padNumber(n*r),o.accessorIndexMap.set(t,i.accessors.length),i.accessors.push(e)}let s=r*a,c=new ArrayBuffer(s),l=new DataView(c);for(let t=0;t<r;t++){let n=0;for(let r of e){let e=r.getElementSize(),i=r.getComponentSize(),o=r.getComponentType(),s=r.getArray();for(let r=0;r<e;r++){let c=t*a+n+r*i,u=s[t*e+r];switch(o){case D.ComponentType.FLOAT:l.setFloat32(c,u,!0);break;case D.ComponentType.BYTE:l.setInt8(c,u);break;case D.ComponentType.SHORT:l.setInt16(c,u,!0);break;case D.ComponentType.UNSIGNED_BYTE:l.setUint8(c,u);break;case D.ComponentType.UNSIGNED_SHORT:l.setUint16(c,u,!0);break;case D.ComponentType.UNSIGNED_INT:l.setUint32(c,u,!0);break;default:throw Error(`Unexpected component type: `+o)}}n+=b.padNumber(e*i)}}let u={buffer:t,byteOffset:n,byteLength:s,byteStride:a,target:M.BufferViewTarget.ARRAY_BUFFER};return i.bufferViews.push(u),{byteLength:s,buffers:[new Uint8Array(c)]}}function _(e,t,n){let r=[],a=0,c=new Map,l=-1/0,u=!1;for(let t of e){let e=o.createAccessorDef(t);i.accessors.push(e),o.accessorIndexMap.set(t,i.accessors.length-1);let n=[],r=[],a=[],s=Array(t.getElementSize()).fill(0);for(let e=0,i=t.getCount();e<i;e++)if(t.getElement(e,a),!T.eq(a,s,0)){l=Math.max(e,l),n.push(e);for(let e=0;e<a.length;e++)r.push(a[e])}let d=n.length,f={accessorDef:e,count:d};if(c.set(t,f),d===0)continue;d>t.getCount()/2&&(u=!0);let p=y[t.getComponentType()];f.indices=n,f.values=new p(r)}if(!Number.isFinite(l))return{buffers:r,byteLength:a};u&&s.warn(`Some sparse accessors have >50% non-zero elements, which may increase file size.`);let d=l<255?Uint8Array:l<65535?Uint16Array:Uint32Array,f=l<255?ht:l<65535?mt:pt,p={buffer:t,byteOffset:n+a,byteLength:0};for(let t of e){let e=c.get(t);if(e.count===0)continue;e.indicesByteOffset=p.byteLength;let n=b.pad(b.toView(new d(e.indices)));r.push(n),a+=n.byteLength,p.byteLength+=n.byteLength}i.bufferViews.push(p);let m=i.bufferViews.length-1,h={buffer:t,byteOffset:n+a,byteLength:0};for(let t of e){let e=c.get(t);if(e.count===0)continue;e.valuesByteOffset=h.byteLength;let n=b.pad(b.toView(e.values));r.push(n),a+=n.byteLength,h.byteLength+=n.byteLength}i.bufferViews.push(h);let g=i.bufferViews.length-1;for(let t of e){let e=c.get(t);e.count!==0&&(e.accessorDef.sparse={count:e.count,indices:{bufferView:m,byteOffset:e.indicesByteOffset,componentType:f},values:{bufferView:g,byteOffset:e.valuesByteOffset}})}return{buffers:r,byteLength:a}}if(i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=r.listTextures().map((e,t)=>{let n=o.createPropertyDef(e);e.getMimeType()&&(n.mimeType=e.getMimeType());let r=e.getImage();return r&&o.createImageData(n,r,e),o.imageIndexMap.set(e,t),n}),l.filter(e=>e.prewriteTypes.includes(m.ACCESSOR)).forEach(e=>e.prewrite(o,m.ACCESSOR)),r.listAccessors().forEach(e=>{let t=o.accessorUsageGroupedByParent,r=o.accessorParents;if(o.accessorIndexMap.has(e))return;let i=o.getAccessorUsage(e);if(o.addAccessorToUsageGroup(e,i),t.has(i)){let t=n.listParents(e).find(e=>e.propertyType!==m.ROOT);r.set(e,t)}}),l.filter(e=>e.prewriteTypes.includes(m.BUFFER)).forEach(e=>e.prewrite(o,m.BUFFER)),(r.listAccessors().length>0||o.otherBufferViews.size>0||r.listTextures().length>0&&t.format===v.GLB)&&r.listBuffers().length===0)throw Error(`Buffer required for Document resources, but none was found.`);i.buffers=[],r.listBuffers().forEach((e,n)=>{let r=o.createPropertyDef(e),a=o.accessorUsageGroupedByParent,s=e.listParents().filter(e=>e instanceof D),c=new Set(s.map(e=>o.accessorParents.get(e))),l=new Map(Array.from(c).map((e,t)=>[e,t])),u={};for(let e of s){var f;if(o.accessorIndexMap.has(e))continue;let t=o.getAccessorUsage(e),n=t;if(a.has(t)){let t=o.accessorParents.get(e);n+=`:${l.get(t)}`}u[f=n]||(u[f]={usage:t,accessors:[]}),u[n].accessors.push(e)}let m=[],y=i.buffers.length,x=0;for(let{usage:e,accessors:n}of Object.values(u))if(e===ft.ARRAY_BUFFER&&t.vertexLayout===h.INTERLEAVED){let e=g(n,y,x);x+=e.byteLength;for(let t of e.buffers)m.push(t)}else if(e===ft.ARRAY_BUFFER)for(let e of n){let t=g([e],y,x);x+=t.byteLength;for(let e of t.buffers)m.push(e)}else if(e===ft.SPARSE){let e=_(n,y,x);x+=e.byteLength;for(let t of e.buffers)m.push(t)}else if(e===ft.ELEMENT_ARRAY_BUFFER){let e=M.BufferViewTarget.ELEMENT_ARRAY_BUFFER,t=d(n,y,x,e);x+=t.byteLength;for(let e of t.buffers)m.push(e)}else{let e=d(n,y,x);x+=e.byteLength;for(let t of e.buffers)m.push(t)}if(o.imageBufferViews.length&&n===0){for(let e=0;e<o.imageBufferViews.length;e++)if(i.bufferViews[i.images[e].bufferView].byteOffset=x,x+=o.imageBufferViews[e].byteLength,m.push(o.imageBufferViews[e]),x%8){let e=8-x%8;x+=e,m.push(new Uint8Array(e))}}if(o.otherBufferViews.has(e))for(let t of o.otherBufferViews.get(e))i.bufferViews.push({buffer:y,byteOffset:x,byteLength:t.byteLength}),o.otherBufferViewsIndexMap.set(t,i.bufferViews.length-1),x+=t.byteLength,m.push(t);if(x){let n;t.format===v.GLB?n=p:(n=o.bufferURIGenerator.createURI(e,`bin`),r.uri=n),r.byteLength=x,o.assignResourceURI(n,b.concat(m),!0)}i.buffers.push(r),o.bufferIndexMap.set(e,n)}),r.listAccessors().find(e=>!e.getBuffer())&&s.warn(`Skipped writing one or more Accessors: no Buffer assigned.`),l.filter(e=>e.prewriteTypes.includes(m.MATERIAL)).forEach(e=>e.prewrite(o,m.MATERIAL)),i.materials=r.listMaterials().map((e,t)=>{let n=o.createPropertyDef(e);if(e.getAlphaMode()!==Ke.AlphaMode.OPAQUE&&(n.alphaMode=e.getAlphaMode()),e.getAlphaMode()===Ke.AlphaMode.MASK&&(n.alphaCutoff=e.getAlphaCutoff()),e.getDoubleSided()&&(n.doubleSided=!0),n.pbrMetallicRoughness={},T.eq(e.getBaseColorFactor(),[1,1,1,1])||(n.pbrMetallicRoughness.baseColorFactor=e.getBaseColorFactor()),T.eq(e.getEmissiveFactor(),[0,0,0])||(n.emissiveFactor=e.getEmissiveFactor()),e.getRoughnessFactor()!==1&&(n.pbrMetallicRoughness.roughnessFactor=e.getRoughnessFactor()),e.getMetallicFactor()!==1&&(n.pbrMetallicRoughness.metallicFactor=e.getMetallicFactor()),e.getBaseColorTexture()){let t=e.getBaseColorTexture(),r=e.getBaseColorTextureInfo();n.pbrMetallicRoughness.baseColorTexture=o.createTextureInfoDef(t,r)}if(e.getEmissiveTexture()){let t=e.getEmissiveTexture(),r=e.getEmissiveTextureInfo();n.emissiveTexture=o.createTextureInfoDef(t,r)}if(e.getNormalTexture()){let t=e.getNormalTexture(),r=e.getNormalTextureInfo(),i=o.createTextureInfoDef(t,r);e.getNormalScale()!==1&&(i.scale=e.getNormalScale()),n.normalTexture=i}if(e.getOcclusionTexture()){let t=e.getOcclusionTexture(),r=e.getOcclusionTextureInfo(),i=o.createTextureInfoDef(t,r);e.getOcclusionStrength()!==1&&(i.strength=e.getOcclusionStrength()),n.occlusionTexture=i}if(e.getMetallicRoughnessTexture()){let t=e.getMetallicRoughnessTexture(),r=e.getMetallicRoughnessTextureInfo();n.pbrMetallicRoughness.metallicRoughnessTexture=o.createTextureInfoDef(t,r)}return o.materialIndexMap.set(e,t),n}),l.filter(e=>e.prewriteTypes.includes(m.MESH)).forEach(e=>e.prewrite(o,m.MESH)),i.meshes=r.listMeshes().map((e,t)=>{let n=o.createPropertyDef(e),r=null;return n.primitives=e.listPrimitives().map(e=>{let t={attributes:{}};t.mode=e.getMode();let n=e.getMaterial();n&&(t.material=o.materialIndexMap.get(n)),Object.keys(e.getExtras()).length&&(t.extras=e.getExtras());let i=e.getIndices();i&&(t.indices=o.accessorIndexMap.get(i));for(let n of e.listSemantics())t.attributes[n]=o.accessorIndexMap.get(e.getAttribute(n));for(let n of e.listTargets()){let e={};for(let t of n.listSemantics())e[t]=o.accessorIndexMap.get(n.getAttribute(t));t.targets=t.targets||[],t.targets.push(e)}return e.listTargets().length&&!r&&(r=e.listTargets().map(e=>e.getName())),t}),e.getWeights().length&&(n.weights=e.getWeights()),r&&(n.extras=n.extras||{},n.extras.targetNames=r),o.meshIndexMap.set(e,t),n}),i.cameras=r.listCameras().map((e,t)=>{let n=o.createPropertyDef(e);if(n.type=e.getType(),n.type===Ve.Type.PERSPECTIVE){n.perspective={znear:e.getZNear(),zfar:e.getZFar(),yfov:e.getYFov()};let t=e.getAspectRatio();t!==null&&(n.perspective.aspectRatio=t)}else n.orthographic={znear:e.getZNear(),zfar:e.getZFar(),xmag:e.getXMag(),ymag:e.getYMag()};return o.cameraIndexMap.set(e,t),n}),i.nodes=r.listNodes().map((e,t)=>{let n=o.createPropertyDef(e);return T.eq(e.getTranslation(),[0,0,0])||(n.translation=e.getTranslation()),T.eq(e.getRotation(),[0,0,0,1])||(n.rotation=e.getRotation()),T.eq(e.getScale(),[1,1,1])||(n.scale=e.getScale()),e.getWeights().length&&(n.weights=e.getWeights()),o.nodeIndexMap.set(e,t),n}),i.skins=r.listSkins().map((e,t)=>{let n=o.createPropertyDef(e),r=e.getInverseBindMatrices();r&&(n.inverseBindMatrices=o.accessorIndexMap.get(r));let i=e.getSkeleton();return i&&(n.skeleton=o.nodeIndexMap.get(i)),n.joints=e.listJoints().map(e=>o.nodeIndexMap.get(e)),o.skinIndexMap.set(e,t),n}),r.listNodes().forEach((e,t)=>{let n=i.nodes[t],r=e.getMesh();r&&(n.mesh=o.meshIndexMap.get(r));let a=e.getCamera();a&&(n.camera=o.cameraIndexMap.get(a));let s=e.getSkin();s&&(n.skin=o.skinIndexMap.get(s)),e.listChildren().length>0&&(n.children=e.listChildren().map(e=>o.nodeIndexMap.get(e)))}),i.animations=r.listAnimations().map((e,t)=>{let n=o.createPropertyDef(e),r=new Map;return n.samplers=e.listSamplers().map((e,t)=>{let n=o.createPropertyDef(e);return n.input=o.accessorIndexMap.get(e.getInput()),n.output=o.accessorIndexMap.get(e.getOutput()),n.interpolation=e.getInterpolation(),r.set(e,t),n}),n.channels=e.listChannels().map(e=>{let t=o.createPropertyDef(e);return t.sampler=r.get(e.getSampler()),t.target={node:o.nodeIndexMap.get(e.getTargetNode()),path:e.getTargetPath()},t}),o.animationIndexMap.set(e,t),n}),i.scenes=r.listScenes().map((e,t)=>{let n=o.createPropertyDef(e);return n.nodes=e.listChildren().map(e=>o.nodeIndexMap.get(e)),o.sceneIndexMap.set(e,t),n});let x=r.getDefaultScene();return x&&(i.scene=r.listScenes().indexOf(x)),i.extensionsUsed=l.map(e=>e.extensionName),i.extensionsRequired=u.map(e=>e.extensionName),l.forEach(e=>e.write(o)),vt(i),a}};function vt(e){let t=[];for(let n in e){let r=e[n];(Array.isArray(r)&&r.length===0||r===null||r===``||r&&typeof r==`object`&&Object.keys(r).length===0)&&t.push(n)}for(let n of t)delete e[n]}var yt;(function(e){e[e.JSON=1313821514]=`JSON`,e[e.BIN=5130562]=`BIN`})(yt||={});var bt=class{constructor(){this._logger=ge.DEFAULT_INSTANCE,this._extensions=new Set,this._dependencies={},this._vertexLayout=h.INTERLEAVED,this._strictResources=!0,this.lastReadBytes=0,this.lastWriteBytes=0}setLogger(e){return this._logger=e,this}registerExtensions(e){for(let t of e)this._extensions.add(t),t.register();return this}registerDependencies(e){return Object.assign(this._dependencies,e),this}setVertexLayout(e){return this._vertexLayout=e,this}setStrictResources(e){return this._strictResources=e,this}async read(e){return await this.readJSON(await this.readAsJSON(e))}async readAsJSON(e){let t=await this.readURI(e,`view`);this.lastReadBytes=t.byteLength;let n=Ct(t)?this._binaryToJSON(t):{json:JSON.parse(b.decodeText(t)),resources:{}};return await this._readResourcesExternal(n,this.dirname(e)),this._readResourcesInternal(n),n}async readJSON(e){return e=this._copyJSON(e),this._readResourcesInternal(e),at.read(e,{extensions:Array.from(this._extensions),dependencies:this._dependencies,logger:this._logger})}async binaryToJSON(e){let t=this._binaryToJSON(b.assertView(e));this._readResourcesInternal(t);let n=t.json;if(n.buffers&&n.buffers.some(e=>xt(t,e)))throw Error(`Cannot resolve external buffers with binaryToJSON().`);if(n.images&&n.images.some(e=>St(t,e)))throw Error(`Cannot resolve external images with binaryToJSON().`);return t}async readBinary(e){return this.readJSON(await this.binaryToJSON(b.assertView(e)))}async writeJSON(e,t={}){if(t.format===v.GLB&&e.getRoot().listBuffers().length>1)throw Error(`GLB must have 0–1 buffers.`);return _t.write(e,{format:t.format||v.GLTF,basename:t.basename||``,logger:this._logger,vertexLayout:this._vertexLayout,dependencies:A({},this._dependencies),extensions:Array.from(this._extensions)})}async writeBinary(e){let{json:t,resources:n}=await this.writeJSON(e,{format:v.GLB}),r=new Uint32Array([1179937895,2,12]),i=JSON.stringify(t),a=b.pad(b.encodeText(i),32),o=b.toView(new Uint32Array([a.byteLength,1313821514])),s=b.concat([o,a]);r[r.length-1]+=s.byteLength;let c=Object.values(n)[0];if(!c||!c.byteLength)return b.concat([b.toView(r),s]);let l=b.pad(c,0),u=b.toView(new Uint32Array([l.byteLength,5130562])),d=b.concat([u,l]);return r[r.length-1]+=d.byteLength,b.concat([b.toView(r),s,d])}async _readResourcesExternal(e,t){var n=this;let r=e.json.images||[],i=e.json.buffers||[],a=[...r,...i].map(async function(i){let a=i.uri;if(!a||a.match(/data:/))return Promise.resolve();try{e.resources[a]=await n.readURI(n.resolve(t,a),`view`),n.lastReadBytes+=e.resources[a].byteLength}catch(t){if(!n._strictResources&&r.includes(i))n._logger.warn(`Failed to load image URI, "${a}". ${t}`),e.resources[a]=null;else throw t}});await Promise.all(a)}_readResourcesInternal(e){function t(t){if(t.uri){if(t.uri in e.resources){b.assertView(e.resources[t.uri]);return}if(t.uri.match(/data:/)){let n=`__${Me()}.${w.extension(t.uri)}`;e.resources[n]=b.createBufferFromDataURI(t.uri),t.uri=n}}}(e.json.images||[]).forEach(e=>{if(e.bufferView===void 0&&e.uri===void 0)throw Error(`Missing resource URI or buffer view.`);t(e)}),(e.json.buffers||[]).forEach(t)}_copyJSON(e){let{images:t,buffers:n}=e.json;return e={json:A({},e.json),resources:A({},e.resources)},t&&(e.json.images=t.map(e=>A({},e))),n&&(e.json.buffers=n.map(e=>A({},e))),e}_binaryToJSON(e){if(!Ct(e))throw Error(`Invalid glTF 2.0 binary.`);let t=new Uint32Array(e.buffer,e.byteOffset+12,2);if(t[1]!==yt.JSON)throw Error(`Missing required GLB JSON chunk.`);let n=t[0],r=b.decodeText(b.toView(e,20,n)),i=JSON.parse(r),a=20+n;if(e.byteLength<=a)return{json:i,resources:{}};let o=new Uint32Array(e.buffer,e.byteOffset+a,2);if(o[1]!==yt.BIN)return{json:i,resources:{}};let s=o[0],c=b.toView(e,a+8,s);return{json:i,resources:{[p]:c}}}};function xt(e,t){return t.uri!==void 0&&!(t.uri in e.resources)}function St(e,t){return t.uri!==void 0&&!(t.uri in e.resources)&&t.bufferView===void 0}function Ct(e){if(e.byteLength<3*Uint32Array.BYTES_PER_ELEMENT)return!1;let t=new Uint32Array(e.buffer,e.byteOffset,3);return t[0]===1179937895&&t[1]===2}var wt=class extends bt{constructor(e=de.DEFAULT_INIT){super(),this._fetchConfig=void 0,this._fetchConfig=e}async readURI(e,t){let n=await fetch(e,this._fetchConfig);switch(t){case`view`:return new Uint8Array(await n.arrayBuffer());case`text`:return n.text()}}resolve(e,t){return de.resolve(e,t)}dirname(e){return de.dirname(e)}};function Tt(){return{vkFormat:0,typeSize:1,pixelWidth:0,pixelHeight:0,pixelDepth:0,layerCount:0,faceCount:1,levelCount:0,supercompressionScheme:0,levels:[],dataFormatDescriptor:[{vendorId:0,descriptorType:0,versionNumber:2,colorModel:0,colorPrimaries:1,transferFunction:2,flags:0,texelBlockDimension:[0,0,0,0],bytesPlane:[0,0,0,0,0,0,0,0],samples:[]}],keyValue:{},globalData:null}}var Et=class{constructor(e,t,n,r){this._dataView=void 0,this._littleEndian=void 0,this._offset=void 0,this._dataView=new DataView(e.buffer,e.byteOffset+t,n),this._littleEndian=r,this._offset=0}_nextUint8(){let e=this._dataView.getUint8(this._offset);return this._offset+=1,e}_nextUint16(){let e=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,e}_nextUint32(){let e=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,e}_nextUint64(){let e=this._dataView.getUint32(this._offset,this._littleEndian)+2**32*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,e}_nextInt32(){let e=this._dataView.getInt32(this._offset,this._littleEndian);return this._offset+=4,e}_nextUint8Array(e){let t=new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+this._offset,e);return this._offset+=e,t}_skip(e){return this._offset+=e,this}_scan(e,t=0){let n=this._offset,r=0;for(;this._dataView.getUint8(this._offset)!==t&&r<e;)r++,this._offset++;return r<e&&this._offset++,new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+n,r)}};new Uint8Array([0]);var N=[171,75,84,88,32,50,48,187,13,10,26,10];function Dt(e){return new TextDecoder().decode(e)}function Ot(e){let t=new Uint8Array(e.buffer,e.byteOffset,N.length);if(t[0]!==N[0]||t[1]!==N[1]||t[2]!==N[2]||t[3]!==N[3]||t[4]!==N[4]||t[5]!==N[5]||t[6]!==N[6]||t[7]!==N[7]||t[8]!==N[8]||t[9]!==N[9]||t[10]!==N[10]||t[11]!==N[11])throw Error(`Missing KTX 2.0 identifier.`);let n=Tt(),r=17*Uint32Array.BYTES_PER_ELEMENT,i=new Et(e,N.length,r,!0);n.vkFormat=i._nextUint32(),n.typeSize=i._nextUint32(),n.pixelWidth=i._nextUint32(),n.pixelHeight=i._nextUint32(),n.pixelDepth=i._nextUint32(),n.layerCount=i._nextUint32(),n.faceCount=i._nextUint32(),n.levelCount=i._nextUint32(),n.supercompressionScheme=i._nextUint32();let a=i._nextUint32(),o=i._nextUint32(),s=i._nextUint32(),c=i._nextUint32(),l=i._nextUint64(),u=i._nextUint64(),d=Math.max(n.levelCount,1)*3*8,f=new Et(e,N.length+r,d,!0);for(let t=0,r=Math.max(n.levelCount,1);t<r;t++)n.levels.push({levelData:new Uint8Array(e.buffer,e.byteOffset+f._nextUint64(),f._nextUint64()),uncompressedByteLength:f._nextUint64()});let p=new Et(e,a,o,!0);p._skip(4);let m=p._nextUint16(),h=p._nextUint16(),g=p._nextUint16(),_=p._nextUint16(),v={vendorId:m,descriptorType:h,versionNumber:g,colorModel:p._nextUint8(),colorPrimaries:p._nextUint8(),transferFunction:p._nextUint8(),flags:p._nextUint8(),texelBlockDimension:[p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8()],bytesPlane:[p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8()],samples:[]},y=(_/4-6)/4;for(let e=0;e<y;e++){let t={bitOffset:p._nextUint16(),bitLength:p._nextUint8(),channelType:p._nextUint8(),samplePosition:[p._nextUint8(),p._nextUint8(),p._nextUint8(),p._nextUint8()],sampleLower:-1/0,sampleUpper:1/0};t.channelType&64?(t.sampleLower=p._nextInt32(),t.sampleUpper=p._nextInt32()):(t.sampleLower=p._nextUint32(),t.sampleUpper=p._nextUint32()),v.samples[e]=t}n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(v);let b=new Et(e,s,c,!0);for(;b._offset<c;){let e=b._nextUint32(),t=b._scan(e),r=Dt(t);if(n.keyValue[r]=b._nextUint8Array(e-t.byteLength-1),r.match(/^ktx/i)){let e=Dt(n.keyValue[r]);n.keyValue[r]=e.substring(0,e.lastIndexOf(`\0`))}let i=e%4?4-e%4:0;b._skip(i)}if(u<=0)return n;let x=new Et(e,l,u,!0),S=x._nextUint16(),ee=x._nextUint16(),C=x._nextUint32(),te=x._nextUint32(),w=x._nextUint32(),ne=x._nextUint32(),re=[];for(let e=0,t=Math.max(n.levelCount,1);e<t;e++)re.push({imageFlags:x._nextUint32(),rgbSliceByteOffset:x._nextUint32(),rgbSliceByteLength:x._nextUint32(),alphaSliceByteOffset:x._nextUint32(),alphaSliceByteLength:x._nextUint32()});let ie=l+x._offset,ae=ie+C,oe=ae+te,se=oe+w;return n.globalData={endpointCount:S,selectorCount:ee,imageDescs:re,endpointsData:new Uint8Array(e.buffer,e.byteOffset+ie,C),selectorsData:new Uint8Array(e.buffer,e.byteOffset+ae,te),tablesData:new Uint8Array(e.buffer,e.byteOffset+oe,w),extendedData:new Uint8Array(e.buffer,e.byteOffset+se,ne)},n}var P=`EXT_mesh_gpu_instancing`,F=`EXT_meshopt_compression`,kt=`EXT_texture_webp`,At=`EXT_texture_avif`,I=`KHR_draco_mesh_compression`,L=`KHR_lights_punctual`,R=`KHR_materials_anisotropy`,z=`KHR_materials_clearcoat`,B=`KHR_materials_diffuse_transmission`,V=`KHR_materials_dispersion`,H=`KHR_materials_emissive_strength`,U=`KHR_materials_ior`,W=`KHR_materials_iridescence`,G=`KHR_materials_pbrSpecularGlossiness`,jt=`KHR_materials_sheen`,Mt=`KHR_materials_specular`,Nt=`KHR_materials_transmission`,Pt=`KHR_materials_unlit`,Ft=`KHR_materials_volume`,K=`KHR_materials_variants`,It=`KHR_mesh_quantization`,Lt=`KHR_node_visibility`,Rt=`KHR_texture_basisu`,zt=`KHR_texture_transform`,q=`KHR_xmp_json_ld`,Bt=`INSTANCE_ATTRIBUTE`,Vt=class extends O{init(){this.extensionName=P,this.propertyType=`InstancedMesh`,this.parentTypes=[m.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{attributes:new c})}getAttribute(e){return this.getRefMap(`attributes`,e)}setAttribute(e,t){return this.setRefMap(`attributes`,e,t,{usage:Bt})}listAttributes(){return this.listRefMapValues(`attributes`)}listSemantics(){return this.listRefMapKeys(`attributes`)}};Vt.EXTENSION_NAME=P;var Ht=class extends j{constructor(...e){super(...e),this.extensionName=P,this.provideTypes=[m.NODE],this.prewriteTypes=[m.ACCESSOR]}createInstancedMesh(){return new Vt(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,n)=>{if(!t.extensions||!t.extensions[P])return;let r=t.extensions[P],i=this.createInstancedMesh();for(let t in r.attributes)i.setAttribute(t,e.accessors[r.attributes[t]]);e.nodes[n].setExtension(P,i)}),this}prewrite(e){e.accessorUsageGroupedByParent.add(Bt);for(let t of this.properties)for(let n of t.listAttributes())e.addAccessorToUsageGroup(n,Bt);return this}write(e){let t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(n=>{let r=n.getExtension(P);if(r){let i=e.nodeIndexMap.get(n),a=t.json.nodes[i],o={attributes:{}};r.listSemantics().forEach(t=>{let n=r.getAttribute(t);o.attributes[t]=e.accessorIndexMap.get(n)}),a.extensions=a.extensions||{},a.extensions[P]=o}}),this}};Ht.EXTENSION_NAME=P;function Ut(){return Ut=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ut.apply(null,arguments)}var Wt;(function(e){e.QUANTIZE=`quantize`,e.FILTER=`filter`})(Wt||={});var Gt;(function(e){e.ATTRIBUTES=`ATTRIBUTES`,e.TRIANGLES=`TRIANGLES`,e.INDICES=`INDICES`})(Gt||={});var J;(function(e){e.NONE=`NONE`,e.OCTAHEDRAL=`OCTAHEDRAL`,e.QUATERNION=`QUATERNION`,e.EXPONENTIAL=`EXPONENTIAL`})(J||={});function Kt(e){return!e.extensions||!e.extensions[F]?!1:!!e.extensions[F].fallback}var{BYTE:qt,SHORT:Jt,FLOAT:Yt}=D.ComponentType,{encodeNormalizedInt:Xt,decodeNormalizedInt:Zt}=T;function Qt(e,t,n,r){let{filter:i,bits:a}=r,o={array:e.getArray(),byteStride:e.getElementSize()*e.getComponentSize(),componentType:e.getComponentType(),normalized:e.getNormalized()};if(n!==Gt.ATTRIBUTES)return o;if(i!==J.NONE){let n=e.getNormalized()?$t(e):new Float32Array(o.array);switch(i){case J.EXPONENTIAL:o.byteStride=e.getElementSize()*4,o.componentType=Yt,o.normalized=!1,o.array=t.encodeFilterExp(n,e.getCount(),o.byteStride,a);break;case J.OCTAHEDRAL:o.byteStride=a>8?8:4,o.componentType=a>8?Jt:qt,o.normalized=!0,n=e.getElementSize()===3?tn(n):n,o.array=t.encodeFilterOct(n,e.getCount(),o.byteStride,a);break;case J.QUATERNION:o.byteStride=8,o.componentType=Jt,o.normalized=!0,o.array=t.encodeFilterQuat(n,e.getCount(),o.byteStride,a);break;default:throw Error(`Invalid filter.`)}o.min=e.getMin([]),o.max=e.getMax([]),e.getNormalized()&&(o.min=o.min.map(t=>Zt(t,e.getComponentType())),o.max=o.max.map(t=>Zt(t,e.getComponentType()))),o.normalized&&(o.min=o.min.map(e=>Xt(e,o.componentType)),o.max=o.max.map(e=>Xt(e,o.componentType)))}else o.byteStride%4&&(o.array=en(o.array,e.getElementSize()),o.byteStride=o.array.byteLength/e.getCount());return o}function $t(e){let t=e.getComponentType(),n=e.getArray(),r=new Float32Array(n.length);for(let e=0;e<n.length;e++)r[e]=Zt(n[e],t);return r}function en(e,t){let n=b.padNumber(e.BYTES_PER_ELEMENT*t)/e.BYTES_PER_ELEMENT,r=e.length/t,i=new e.constructor(r*n);for(let r=0;r*t<e.length;r++)for(let a=0;a<t;a++)i[r*n+a]=e[r*t+a];return i}function tn(e){let t=new Float32Array(e.length*4/3);for(let n=0,r=e.length/3;n<r;n++)t[n*4]=e[n*3],t[n*4+1]=e[n*3+1],t[n*4+2]=e[n*3+2];return t}function nn(e,t){return t===M.BufferViewUsage.ELEMENT_ARRAY_BUFFER?e.listParents().some(e=>e instanceof Ye&&e.getMode()===Ye.Mode.TRIANGLES)?Gt.TRIANGLES:Gt.INDICES:Gt.ATTRIBUTES}function rn(e,t){let n=t.getGraph().listParentEdges(e).filter(e=>!(e.getParent()instanceof et));for(let t of n){let n=t.getName(),r=t.getAttributes().key||``,i=t.getParent().propertyType===m.PRIMITIVE_TARGET;if(n===`indices`)return{filter:J.NONE};if(n===`attributes`){if(r===`POSITION`||r===`TEXCOORD_0`||r.startsWith(`JOINTS_`)||r.startsWith(`WEIGHTS_`))return{filter:J.NONE};if(r===`NORMAL`||r===`TANGENT`)return i?{filter:J.NONE}:{filter:J.OCTAHEDRAL,bits:8}}if(n===`output`){let t=an(e);return t===`rotation`?{filter:J.QUATERNION,bits:16}:t===`translation`||t===`scale`?{filter:J.EXPONENTIAL,bits:12}:{filter:J.NONE}}if(n===`input`||n===`inverseBindMatrices`)return{filter:J.NONE}}return{filter:J.NONE}}function an(e){for(let t of e.listParents())if(t instanceof ze){for(let e of t.listParents())if(e instanceof Re)return e.getTargetPath()}return null}var on={method:Wt.QUANTIZE},sn=class extends j{constructor(...e){super(...e),this.extensionName=F,this.prereadTypes=[m.BUFFER,m.PRIMITIVE],this.prewriteTypes=[m.BUFFER,m.ACCESSOR],this.readDependencies=[`meshopt.decoder`],this.writeDependencies=[`meshopt.encoder`],this._decoder=null,this._decoderFallbackBufferMap=new Map,this._encoder=null,this._encoderOptions=on,this._encoderFallbackBuffer=null,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={}}install(e,t){return e===`meshopt.decoder`&&(this._decoder=t),e===`meshopt.encoder`&&(this._encoder=t),this}setEncoderOptions(e){return this._encoderOptions=Ut({},on,e),this}preread(e,t){if(!this._decoder){if(!this.isRequired())return this;throw Error(`[${F}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw Error(`[${F}]: Missing WASM support.`)}return t===m.BUFFER?this._prereadBuffers(e):t===m.PRIMITIVE&&this._prereadPrimitives(e),this}_prereadBuffers(e){let t=e.jsonDoc;(t.json.bufferViews||[]).forEach((n,r)=>{if(!n.extensions||!n.extensions[F])return;let i=n.extensions[F],a=i.byteOffset||0,o=i.byteLength||0,s=i.count,c=i.byteStride,l=new Uint8Array(s*c),u=t.json.buffers[i.buffer],d=u.uri?t.resources[u.uri]:t.resources[p],f=b.toView(d,a,o);this._decoder.decodeGltfBuffer(l,s,c,f,i.mode,i.filter),e.bufferViews[r]=l})}_prereadPrimitives(e){let t=e.jsonDoc;(t.json.bufferViews||[]).forEach(n=>{if(!n.extensions||!n.extensions[F])return;let r=n.extensions[F],i=e.buffers[r.buffer],a=e.buffers[n.buffer],o=t.json.buffers[n.buffer];Kt(o)&&this._decoderFallbackBufferMap.set(a,i)})}read(e){if(!this.isRequired())return this;for(let[e,t]of this._decoderFallbackBufferMap){for(let n of e.listParents())n instanceof D&&n.swap(e,t);e.dispose()}return this}prewrite(e,t){return t===m.ACCESSOR?this._prewriteAccessors(e):t===m.BUFFER&&this._prewriteBuffers(e),this}_prewriteAccessors(e){let t=e.jsonDoc.json,n=this._encoder,r=this._encoderOptions,i=this.document.getGraph(),a=this.document.createBuffer(),o=this.document.getRoot().listBuffers().indexOf(a),s=1,c=new Map,l=e=>{for(let t of i.listParents(e)){if(t.propertyType===m.ROOT)continue;let n=c.get(e);return n===void 0&&c.set(e,n=s++),n}return-1};this._encoderFallbackBuffer=a,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={};for(let i of this.document.getRoot().listAccessors()){if(an(i)===`weights`||i.getSparse())continue;let a=e.getAccessorUsage(i),s=e.accessorUsageGroupedByParent.has(a)?l(i):null,c=nn(i,a),u=r.method===Wt.FILTER?rn(i,this.document):{filter:J.NONE},d=Qt(i,n,c,u),{array:f,byteStride:p}=d,m=i.getBuffer();if(!m)throw Error(`${F}: Missing buffer for accessor.`);let h=this.document.getRoot().listBuffers().indexOf(m),g=[a,s,c,u.filter,p,h].join(`:`),_=this._encoderBufferViews[g],v=this._encoderBufferViewData[g],y=this._encoderBufferViewAccessors[g];(!_||!v)&&(y=this._encoderBufferViewAccessors[g]=[],v=this._encoderBufferViewData[g]=[],_=this._encoderBufferViews[g]={buffer:o,target:M.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===M.BufferViewUsage.ARRAY_BUFFER?p:void 0,extensions:{[F]:{buffer:h,byteOffset:0,byteLength:0,mode:c,filter:u.filter===J.NONE?void 0:u.filter,byteStride:p,count:0}}});let b=e.createAccessorDef(i);b.componentType=d.componentType,b.normalized=d.normalized,b.byteOffset=_.byteLength,b.min&&d.min&&(b.min=d.min),b.max&&d.max&&(b.max=d.max),e.accessorIndexMap.set(i,t.accessors.length),t.accessors.push(b),y.push(b),v.push(new Uint8Array(f.buffer,f.byteOffset,f.byteLength)),_.byteLength+=f.byteLength,_.extensions.EXT_meshopt_compression.count+=i.getCount()}}_prewriteBuffers(e){let t=this._encoder;for(let n in this._encoderBufferViews){let r=this._encoderBufferViews[n],i=this._encoderBufferViewData[n],a=this.document.getRoot().listBuffers()[r.extensions[F].buffer],o=e.otherBufferViews.get(a)||[],{count:s,byteStride:c,mode:l}=r.extensions[F],u=b.concat(i),d=t.encodeGltfBuffer(u,s,c,l),f=b.pad(d);r.extensions[F].byteLength=d.byteLength,i.length=0,i.push(f),o.push(f),e.otherBufferViews.set(a,o)}}write(e){let t=0;for(let n in this._encoderBufferViews){let r=this._encoderBufferViews[n],i=this._encoderBufferViewData[n][0],a=e.otherBufferViewsIndexMap.get(i),o=this._encoderBufferViewAccessors[n];for(let e of o)e.bufferView=a;let s=e.jsonDoc.json.bufferViews[a],c=s.byteOffset||0;Object.assign(s,r),s.byteOffset=t;let l=s.extensions[F];l.byteOffset=c,t+=b.padNumber(r.byteLength)}let n=this._encoderFallbackBuffer,r=e.bufferIndexMap.get(n),i=e.jsonDoc.json.buffers[r];return i.byteLength=t,i.extensions={[F]:{fallback:!0}},n.dispose(),this}};sn.EXTENSION_NAME=F,sn.EncoderMethod=Wt;var cn=class{match(e){return e.length>=12&&b.decodeText(e.slice(4,12))===`ftypavif`}getSize(e){if(!this.match(e))return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=un(t,0);if(!n)return null;let r=n.end;for(;n=un(t,r);)if(n.type===`meta`)r=n.start+4;else if(n.type===`iprp`||n.type===`ipco`)r=n.start;else if(n.type===`ispe`)return[t.getUint32(n.start+4),t.getUint32(n.start+8)];else if(n.type===`mdat`)break;else r=n.end;return null}getChannels(e){return 4}},ln=class extends j{constructor(...e){super(...e),this.extensionName=At,this.prereadTypes=[m.TEXTURE]}static register(){C.registerFormat(`image/avif`,new cn)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[At]&&(e.source=e.extensions[At].source)}),this}read(e){return this}write(e){let t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(n=>{if(n.getMimeType()===`image/avif`){let r=e.imageIndexMap.get(n);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[At]={source:e.source},delete e.source)})}}),this}};ln.EXTENSION_NAME=At;function un(e,t){if(e.byteLength<4+t)return null;let n=e.getUint32(t);return e.byteLength<n+t||n<8?null:{type:b.decodeText(new Uint8Array(e.buffer,e.byteOffset+t+4,4)),start:t+8,end:t+n}}var dn=class{match(e){return e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}getSize(e){let t=b.decodeText(e.slice(0,4)),n=b.decodeText(e.slice(8,12));if(t!==`RIFF`||n!==`WEBP`)return null;let r=new DataView(e.buffer,e.byteOffset),i=12;for(;i<r.byteLength;){let e=b.decodeText(new Uint8Array([r.getUint8(i),r.getUint8(i+1),r.getUint8(i+2),r.getUint8(i+3)])),t=r.getUint32(i+4,!0);if(e===`VP8 `)return[r.getInt16(i+14,!0)&16383,r.getInt16(i+16,!0)&16383];if(e===`VP8L`){let e=r.getUint8(i+9),t=r.getUint8(i+10),n=r.getUint8(i+11),a=r.getUint8(i+12);return[1+((t&63)<<8|e),1+((a&15)<<10|n<<2|(t&192)>>6)]}i+=8+t+t%2}return null}getChannels(e){return 4}},fn=class extends j{constructor(...e){super(...e),this.extensionName=kt,this.prereadTypes=[m.TEXTURE]}static register(){C.registerFormat(`image/webp`,new dn)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[kt]&&(e.source=e.extensions[kt].source)}),this}read(e){return this}write(e){let t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(n=>{if(n.getMimeType()===`image/webp`){let r=e.imageIndexMap.get(n);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[kt]={source:e.source},delete e.source)})}}),this}};fn.EXTENSION_NAME=kt;var Y,pn,mn;function hn(e,t){let n=new Y.DecoderBuffer;try{if(n.Init(t,t.length),e.GetEncodedGeometryType(n)!==Y.TRIANGULAR_MESH)throw Error(`[${I}] Unknown geometry type.`);let r=new Y.Mesh;if(!e.DecodeBufferToMesh(n,r).ok()||r.ptr===0)throw Error(`[${I}] Decoding failure.`);return r}finally{Y.destroy(n)}}function gn(e,t){let n=t.num_faces()*3,r,i;if(t.num_points()<=65534){let a=n*Uint16Array.BYTES_PER_ELEMENT;r=Y._malloc(a),e.GetTrianglesUInt16Array(t,a,r),i=new Uint16Array(Y.HEAPU16.buffer,r,n).slice()}else{let a=n*Uint32Array.BYTES_PER_ELEMENT;r=Y._malloc(a),e.GetTrianglesUInt32Array(t,a,r),i=new Uint32Array(Y.HEAPU32.buffer,r,n).slice()}return Y._free(r),i}function _n(e,t,n,r){let i=mn[r.componentType],a=pn[r.componentType],o=n.num_components(),s=t.num_points()*o,c=s*a.BYTES_PER_ELEMENT,l=Y._malloc(c);e.GetAttributeDataArrayForAllPoints(t,n,i,c,l);let u=new a(Y.HEAPF32.buffer,l,s).slice();return Y._free(l),u}function vn(e){Y=e,pn={[D.ComponentType.FLOAT]:Float32Array,[D.ComponentType.UNSIGNED_INT]:Uint32Array,[D.ComponentType.UNSIGNED_SHORT]:Uint16Array,[D.ComponentType.UNSIGNED_BYTE]:Uint8Array,[D.ComponentType.SHORT]:Int16Array,[D.ComponentType.BYTE]:Int8Array},mn={[D.ComponentType.FLOAT]:Y.DT_FLOAT32,[D.ComponentType.UNSIGNED_INT]:Y.DT_UINT32,[D.ComponentType.UNSIGNED_SHORT]:Y.DT_UINT16,[D.ComponentType.UNSIGNED_BYTE]:Y.DT_UINT8,[D.ComponentType.SHORT]:Y.DT_INT16,[D.ComponentType.BYTE]:Y.DT_INT8}}var X,yn;(function(e){e[e.EDGEBREAKER=1]=`EDGEBREAKER`,e[e.SEQUENTIAL=0]=`SEQUENTIAL`})(yn||={});var Z;(function(e){e.POSITION=`POSITION`,e.NORMAL=`NORMAL`,e.COLOR=`COLOR`,e.TEX_COORD=`TEX_COORD`,e.GENERIC=`GENERIC`})(Z||={});var bn={[Z.POSITION]:14,[Z.NORMAL]:10,[Z.COLOR]:8,[Z.TEX_COORD]:12,[Z.GENERIC]:12},xn={decodeSpeed:5,encodeSpeed:5,method:yn.EDGEBREAKER,quantizationBits:bn,quantizationVolume:`mesh`};function Sn(e){X=e}function Cn(e,t=xn){let n=Ut({},xn,t);n.quantizationBits=Ut({},bn,t.quantizationBits);let r=new X.MeshBuilder,i=new X.Mesh,a=new X.ExpertEncoder(i),o={},s=new X.DracoInt8Array,c=e.listTargets().length>0,l=!1;for(let t of e.listSemantics()){let s=e.getAttribute(t);if(s.getSparse()){l=!0;continue}let c=wn(t),u=Tn(r,s.getComponentType(),i,X[c],s.getCount(),s.getElementSize(),s.getArray());if(u===-1)throw Error(`Error compressing "${t}" attribute.`);if(o[t]=u,n.quantizationVolume===`mesh`||t!==`POSITION`)a.SetAttributeQuantization(u,n.quantizationBits[c]);else if(typeof n.quantizationVolume==`object`){let{quantizationVolume:e}=n,t=Math.max(e.max[0]-e.min[0],e.max[1]-e.min[1],e.max[2]-e.min[2]);a.SetAttributeExplicitQuantization(u,n.quantizationBits[c],s.getElementSize(),e.min,t)}else throw Error(`Invalid quantization volume state.`)}let u=e.getIndices();if(!u)throw new En(`Primitive must have indices.`);r.AddFacesToMesh(i,u.getCount()/3,u.getArray()),a.SetSpeedOptions(n.encodeSpeed,n.decodeSpeed),a.SetTrackEncodedProperties(!0),n.method===yn.SEQUENTIAL||c||l?a.SetEncodingMethod(X.MESH_SEQUENTIAL_ENCODING):a.SetEncodingMethod(X.MESH_EDGEBREAKER_ENCODING);let d=a.EncodeToDracoBuffer(!(c||l),s);if(d<=0)throw new En(`Error applying Draco compression.`);let f=new Uint8Array(d);for(let e=0;e<d;++e)f[e]=s.GetValue(e);let p=a.GetNumberOfEncodedPoints(),m=a.GetNumberOfEncodedFaces()*3;return X.destroy(s),X.destroy(i),X.destroy(r),X.destroy(a),{numVertices:p,numIndices:m,data:f,attributeIDs:o}}function wn(e){return e===`POSITION`?Z.POSITION:e===`NORMAL`?Z.NORMAL:e.startsWith(`COLOR_`)?Z.COLOR:e.startsWith(`TEXCOORD_`)?Z.TEX_COORD:Z.GENERIC}function Tn(e,t,n,r,i,a,o){switch(t){case D.ComponentType.UNSIGNED_BYTE:return e.AddUInt8Attribute(n,r,i,a,o);case D.ComponentType.BYTE:return e.AddInt8Attribute(n,r,i,a,o);case D.ComponentType.UNSIGNED_SHORT:return e.AddUInt16Attribute(n,r,i,a,o);case D.ComponentType.SHORT:return e.AddInt16Attribute(n,r,i,a,o);case D.ComponentType.UNSIGNED_INT:return e.AddUInt32Attribute(n,r,i,a,o);case D.ComponentType.FLOAT:return e.AddFloatAttribute(n,r,i,a,o);default:throw Error(`Unexpected component type, "${t}".`)}}var En=class extends Error{},Dn=class extends j{constructor(...e){super(...e),this.extensionName=I,this.prereadTypes=[m.PRIMITIVE],this.prewriteTypes=[m.ACCESSOR],this.readDependencies=[`draco3d.decoder`],this.writeDependencies=[`draco3d.encoder`],this._decoderModule=null,this._encoderModule=null,this._encoderOptions={}}install(e,t){return e===`draco3d.decoder`&&(this._decoderModule=t,vn(this._decoderModule)),e===`draco3d.encoder`&&(this._encoderModule=t,Sn(this._encoderModule)),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(e){if(!this._decoderModule)throw Error(`[${I}] Please install extension dependency, "draco3d.decoder".`);let t=this.document.getLogger(),n=e.jsonDoc,r=new Map;try{let i=n.json.meshes||[];for(let a of i)for(let i of a.primitives){if(!i.extensions||!i.extensions[I])continue;let a=i.extensions[I],[o,s]=r.get(a.bufferView)||[];if(!s||!o){let e=n.json.bufferViews[a.bufferView],i=n.json.buffers[e.buffer],c=i.uri?n.resources[i.uri]:n.resources[p],l=e.byteOffset||0,u=e.byteLength,d=b.toView(c,l,u);o=new this._decoderModule.Decoder,s=hn(o,d),r.set(a.bufferView,[o,s]),t.debug(`[${I}] Decompressed ${d.byteLength} bytes.`)}for(let t in a.attributes){let n=e.jsonDoc.json.accessors[i.attributes[t]],r=o.GetAttributeByUniqueId(s,a.attributes[t]),c=_n(o,s,r,n);e.accessors[i.attributes[t]].setArray(c)}i.indices!==void 0&&e.accessors[i.indices].setArray(gn(o,s))}}finally{for(let[e,t]of Array.from(r.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(e,t){if(!this._encoderModule)throw Error(`[${I}] Please install extension dependency, "draco3d.encoder".`);let n=this.document.getLogger();n.debug(`[${I}] Compression options: ${JSON.stringify(this._encoderOptions)}`);let r=On(this.document),i=new Map,a=`mesh`;this._encoderOptions.quantizationVolume===`scene`&&(this.document.getRoot().listScenes().length===1?a=oe(this.document.getRoot().listScenes().pop()):n.warn(`[${I}]: quantizationVolume=scene requires exactly 1 scene.`));for(let t of Array.from(r.keys())){let o=r.get(t);if(!o)throw Error(`Unexpected primitive.`);if(i.has(o)){i.set(o,i.get(o));continue}let s=t.getIndices(),c=e.jsonDoc.json.accessors,l;try{l=Cn(t,Ut({},this._encoderOptions,{quantizationVolume:a}))}catch(e){if(e instanceof En){n.warn(`[${I}]: ${e.message} Skipping primitive compression.`);continue}throw e}i.set(o,l);let u=e.createAccessorDef(s);u.count=l.numIndices,e.accessorIndexMap.set(s,c.length),c.push(u),l.numVertices>65534&&D.getComponentSize(u.componentType)<=2?u.componentType=D.ComponentType.UNSIGNED_INT:l.numVertices>254&&D.getComponentSize(u.componentType)<=1&&(u.componentType=D.ComponentType.UNSIGNED_SHORT);for(let n of t.listSemantics()){let r=t.getAttribute(n);if(l.attributeIDs[n]===void 0)continue;let i=e.createAccessorDef(r);i.count=l.numVertices,e.accessorIndexMap.set(r,c.length),c.push(i)}let d=t.getAttribute(`POSITION`).getBuffer()||this.document.getRoot().listBuffers()[0];e.otherBufferViews.has(d)||e.otherBufferViews.set(d,[]),e.otherBufferViews.get(d).push(l.data)}return n.debug(`[${I}] Compressed ${r.size} primitives.`),e.extensionData[I]={primitiveHashMap:r,primitiveEncodingMap:i},this}write(e){let t=e.extensionData[I];for(let n of this.document.getRoot().listMeshes()){let r=e.jsonDoc.json.meshes[e.meshIndexMap.get(n)];for(let i=0;i<n.listPrimitives().length;i++){let a=n.listPrimitives()[i],o=r.primitives[i],s=t.primitiveHashMap.get(a);if(!s)continue;let c=t.primitiveEncodingMap.get(s);c&&(o.extensions=o.extensions||{},o.extensions[I]={bufferView:e.otherBufferViewsIndexMap.get(c.data),attributes:c.attributeIDs})}}if(!t.primitiveHashMap.size){let t=e.jsonDoc.json;t.extensionsUsed=(t.extensionsUsed||[]).filter(e=>e!==I),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==I)}return this}};Dn.EXTENSION_NAME=I,Dn.EncoderMethod=yn;function On(e){let t=e.getLogger(),n=new Set,r=new Set,i=0,a=0;for(let t of e.getRoot().listMeshes())for(let e of t.listPrimitives())e.getIndices()?e.getMode()===Ye.Mode.TRIANGLES?n.add(e):(r.add(e),a++):(r.add(e),i++);i>0&&t.warn(`[${I}] Skipping Draco compression of ${i} non-indexed primitives.`),a>0&&t.warn(`[${I}] Skipping Draco compression of ${a} non-TRIANGLES primitives.`);let o=e.getRoot().listAccessors(),s=new Map;for(let e=0;e<o.length;e++)s.set(o[e],e);let c=new Map,l=new Set,u=new Map;for(let t of Array.from(n)){let n=kn(t,s);if(l.has(n)){u.set(t,n);continue}if(c.has(t.getIndices())){let n=t.getIndices(),r=n.clone();s.set(r,e.getRoot().listAccessors().length-1),t.swap(n,r)}for(let n of t.listAttributes())if(c.has(n)){let r=n.clone();s.set(r,e.getRoot().listAccessors().length-1),t.swap(n,r)}n=kn(t,s),l.add(n),u.set(t,n),c.set(t.getIndices(),n);for(let e of t.listAttributes())c.set(e,n)}for(let e of Array.from(c.keys())){let t=new Set(e.listParents().map(e=>e.propertyType));if(t.size!==2||!t.has(m.PRIMITIVE)||!t.has(m.ROOT))throw Error(`[${I}] Compressed accessors must only be used as indices or vertex attributes.`)}for(let e of Array.from(n)){let t=u.get(e),n=e.getIndices();if(c.get(n)!==t||e.listAttributes().some(e=>c.get(e)!==t))throw Error(`[${I}] Draco primitives must share all, or no, accessors.`)}for(let e of Array.from(r)){let t=e.getIndices();if(c.has(t)||e.listAttributes().some(e=>c.has(e)))throw Error(`[${I}] Accessor cannot be shared by compressed and uncompressed primitives.`)}return u}function kn(e,t){let n=[],r=e.getIndices();n.push(t.get(r));for(let r of e.listAttributes())n.push(t.get(r));return n.sort().join(`|`)}var An=class e extends O{init(){this.extensionName=L,this.propertyType=`Light`,this.parentTypes=[m.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:e.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get(`color`)}setColor(e){return this.set(`color`,e)}getIntensity(){return this.get(`intensity`)}setIntensity(e){return this.set(`intensity`,e)}getType(){return this.get(`type`)}setType(e){return this.set(`type`,e)}getRange(){return this.get(`range`)}setRange(e){return this.set(`range`,e)}getInnerConeAngle(){return this.get(`innerConeAngle`)}setInnerConeAngle(e){return this.set(`innerConeAngle`,e)}getOuterConeAngle(){return this.get(`outerConeAngle`)}setOuterConeAngle(e){return this.set(`outerConeAngle`,e)}};An.EXTENSION_NAME=L,An.Type={POINT:`point`,SPOT:`spot`,DIRECTIONAL:`directional`};var jn=class extends j{constructor(...e){super(...e),this.extensionName=L}createLight(e=``){return new An(this.document.getGraph(),e)}read(e){let t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[L])return this;let n=(t.json.extensions[L].lights||[]).map(e=>{let t=this.createLight().setName(e.name||``).setType(e.type);return e.color!==void 0&&t.setColor(e.color),e.intensity!==void 0&&t.setIntensity(e.intensity),e.range!==void 0&&t.setRange(e.range),e.spot?.innerConeAngle!==void 0&&t.setInnerConeAngle(e.spot.innerConeAngle),e.spot?.outerConeAngle!==void 0&&t.setOuterConeAngle(e.spot.outerConeAngle),t});return t.json.nodes.forEach((t,r)=>{if(!t.extensions||!t.extensions[L])return;let i=t.extensions[L];e.nodes[r].setExtension(L,n[i.light])}),this}write(e){let t=e.jsonDoc;if(this.properties.size===0)return this;let n=[],r=new Map;for(let e of this.properties){let t=e,i={type:t.getType()};T.eq(t.getColor(),[1,1,1])||(i.color=t.getColor()),t.getIntensity()!==1&&(i.intensity=t.getIntensity()),t.getRange()!=null&&(i.range=t.getRange()),t.getName()&&(i.name=t.getName()),t.getType()===An.Type.SPOT&&(i.spot={innerConeAngle:t.getInnerConeAngle(),outerConeAngle:t.getOuterConeAngle()}),n.push(i),r.set(t,n.length-1)}return this.document.getRoot().listNodes().forEach(n=>{let i=n.getExtension(L);if(i){let a=e.nodeIndexMap.get(n),o=t.json.nodes[a];o.extensions=o.extensions||{},o.extensions[L]={light:r.get(i)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[L]={lights:n},this}};jn.EXTENSION_NAME=L;var{R:Mn,G:Nn,B:Pn}=_,Fn=class extends O{init(){this.extensionName=R,this.propertyType=`Anisotropy`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{anisotropyStrength:0,anisotropyRotation:0,anisotropyTexture:null,anisotropyTextureInfo:new k(this.graph,`anisotropyTextureInfo`)})}getAnisotropyStrength(){return this.get(`anisotropyStrength`)}setAnisotropyStrength(e){return this.set(`anisotropyStrength`,e)}getAnisotropyRotation(){return this.get(`anisotropyRotation`)}setAnisotropyRotation(e){return this.set(`anisotropyRotation`,e)}getAnisotropyTexture(){return this.getRef(`anisotropyTexture`)}getAnisotropyTextureInfo(){return this.getRef(`anisotropyTexture`)?this.getRef(`anisotropyTextureInfo`):null}setAnisotropyTexture(e){return this.setRef(`anisotropyTexture`,e,{channels:Mn|Nn|Pn})}};Fn.EXTENSION_NAME=R;var In=class extends j{constructor(...e){super(...e),this.extensionName=R,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createAnisotropy(){return new Fn(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[R]){let i=this.createAnisotropy();e.materials[n].setExtension(R,i);let a=t.extensions[R];if(a.anisotropyStrength!==void 0&&i.setAnisotropyStrength(a.anisotropyStrength),a.anisotropyRotation!==void 0&&i.setAnisotropyRotation(a.anisotropyRotation),a.anisotropyTexture!==void 0){let t=a.anisotropyTexture,n=e.textures[r[t.index].source];i.setAnisotropyTexture(n),e.setTextureInfo(i.getAnisotropyTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(R);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[R]={};if(r.getAnisotropyStrength()>0&&(o.anisotropyStrength=r.getAnisotropyStrength()),r.getAnisotropyRotation()!==0&&(o.anisotropyRotation=r.getAnisotropyRotation()),r.getAnisotropyTexture()){let t=r.getAnisotropyTexture(),n=r.getAnisotropyTextureInfo();o.anisotropyTexture=e.createTextureInfoDef(t,n)}}}),this}};In.EXTENSION_NAME=R;var{R:Ln,G:Rn,B:zn}=_,Bn=class extends O{init(){this.extensionName=z,this.propertyType=`Clearcoat`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new k(this.graph,`clearcoatTextureInfo`),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new k(this.graph,`clearcoatRoughnessTextureInfo`),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new k(this.graph,`clearcoatNormalTextureInfo`)})}getClearcoatFactor(){return this.get(`clearcoatFactor`)}setClearcoatFactor(e){return this.set(`clearcoatFactor`,e)}getClearcoatTexture(){return this.getRef(`clearcoatTexture`)}getClearcoatTextureInfo(){return this.getRef(`clearcoatTexture`)?this.getRef(`clearcoatTextureInfo`):null}setClearcoatTexture(e){return this.setRef(`clearcoatTexture`,e,{channels:Ln})}getClearcoatRoughnessFactor(){return this.get(`clearcoatRoughnessFactor`)}setClearcoatRoughnessFactor(e){return this.set(`clearcoatRoughnessFactor`,e)}getClearcoatRoughnessTexture(){return this.getRef(`clearcoatRoughnessTexture`)}getClearcoatRoughnessTextureInfo(){return this.getRef(`clearcoatRoughnessTexture`)?this.getRef(`clearcoatRoughnessTextureInfo`):null}setClearcoatRoughnessTexture(e){return this.setRef(`clearcoatRoughnessTexture`,e,{channels:Rn})}getClearcoatNormalScale(){return this.get(`clearcoatNormalScale`)}setClearcoatNormalScale(e){return this.set(`clearcoatNormalScale`,e)}getClearcoatNormalTexture(){return this.getRef(`clearcoatNormalTexture`)}getClearcoatNormalTextureInfo(){return this.getRef(`clearcoatNormalTexture`)?this.getRef(`clearcoatNormalTextureInfo`):null}setClearcoatNormalTexture(e){return this.setRef(`clearcoatNormalTexture`,e,{channels:Ln|Rn|zn})}};Bn.EXTENSION_NAME=z;var Vn=class extends j{constructor(...e){super(...e),this.extensionName=z,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createClearcoat(){return new Bn(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[z]){let i=this.createClearcoat();e.materials[n].setExtension(z,i);let a=t.extensions[z];if(a.clearcoatFactor!==void 0&&i.setClearcoatFactor(a.clearcoatFactor),a.clearcoatRoughnessFactor!==void 0&&i.setClearcoatRoughnessFactor(a.clearcoatRoughnessFactor),a.clearcoatTexture!==void 0){let t=a.clearcoatTexture,n=e.textures[r[t.index].source];i.setClearcoatTexture(n),e.setTextureInfo(i.getClearcoatTextureInfo(),t)}if(a.clearcoatRoughnessTexture!==void 0){let t=a.clearcoatRoughnessTexture,n=e.textures[r[t.index].source];i.setClearcoatRoughnessTexture(n),e.setTextureInfo(i.getClearcoatRoughnessTextureInfo(),t)}if(a.clearcoatNormalTexture!==void 0){let t=a.clearcoatNormalTexture,n=e.textures[r[t.index].source];i.setClearcoatNormalTexture(n),e.setTextureInfo(i.getClearcoatNormalTextureInfo(),t),t.scale!==void 0&&i.setClearcoatNormalScale(t.scale)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(z);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[z]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()};if(r.getClearcoatTexture()){let t=r.getClearcoatTexture(),n=r.getClearcoatTextureInfo();o.clearcoatTexture=e.createTextureInfoDef(t,n)}if(r.getClearcoatRoughnessTexture()){let t=r.getClearcoatRoughnessTexture(),n=r.getClearcoatRoughnessTextureInfo();o.clearcoatRoughnessTexture=e.createTextureInfoDef(t,n)}if(r.getClearcoatNormalTexture()){let t=r.getClearcoatNormalTexture(),n=r.getClearcoatNormalTextureInfo();o.clearcoatNormalTexture=e.createTextureInfoDef(t,n),r.getClearcoatNormalScale()!==1&&(o.clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}};Vn.EXTENSION_NAME=z;var{R:Hn,G:Un,B:Wn,A:Gn}=_,Kn=class extends O{init(){this.extensionName=B,this.propertyType=`DiffuseTransmission`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseTransmissionFactor:0,diffuseTransmissionTexture:null,diffuseTransmissionTextureInfo:new k(this.graph,`diffuseTransmissionTextureInfo`),diffuseTransmissionColorFactor:[1,1,1],diffuseTransmissionColorTexture:null,diffuseTransmissionColorTextureInfo:new k(this.graph,`diffuseTransmissionColorTextureInfo`)})}getDiffuseTransmissionFactor(){return this.get(`diffuseTransmissionFactor`)}setDiffuseTransmissionFactor(e){return this.set(`diffuseTransmissionFactor`,e)}getDiffuseTransmissionTexture(){return this.getRef(`diffuseTransmissionTexture`)}getDiffuseTransmissionTextureInfo(){return this.getRef(`diffuseTransmissionTexture`)?this.getRef(`diffuseTransmissionTextureInfo`):null}setDiffuseTransmissionTexture(e){return this.setRef(`diffuseTransmissionTexture`,e,{channels:Gn})}getDiffuseTransmissionColorFactor(){return this.get(`diffuseTransmissionColorFactor`)}setDiffuseTransmissionColorFactor(e){return this.set(`diffuseTransmissionColorFactor`,e)}getDiffuseTransmissionColorTexture(){return this.getRef(`diffuseTransmissionColorTexture`)}getDiffuseTransmissionColorTextureInfo(){return this.getRef(`diffuseTransmissionColorTexture`)?this.getRef(`diffuseTransmissionColorTextureInfo`):null}setDiffuseTransmissionColorTexture(e){return this.setRef(`diffuseTransmissionColorTexture`,e,{channels:Hn|Un|Wn})}};Kn.EXTENSION_NAME=B;var qn=class extends j{constructor(...e){super(...e),this.extensionName=B}createDiffuseTransmission(){return new Kn(this.document.getGraph())}read(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[B]){let i=this.createDiffuseTransmission();e.materials[n].setExtension(B,i);let a=t.extensions[B];if(a.diffuseTransmissionFactor!==void 0&&i.setDiffuseTransmissionFactor(a.diffuseTransmissionFactor),a.diffuseTransmissionColorFactor!==void 0&&i.setDiffuseTransmissionColorFactor(a.diffuseTransmissionColorFactor),a.diffuseTransmissionTexture!==void 0){let t=a.diffuseTransmissionTexture,n=e.textures[r[t.index].source];i.setDiffuseTransmissionTexture(n),e.setTextureInfo(i.getDiffuseTransmissionTextureInfo(),t)}if(a.diffuseTransmissionColorTexture!==void 0){let t=a.diffuseTransmissionColorTexture,n=e.textures[r[t.index].source];i.setDiffuseTransmissionColorTexture(n),e.setTextureInfo(i.getDiffuseTransmissionColorTextureInfo(),t)}}}),this}write(e){let t=e.jsonDoc;for(let n of this.document.getRoot().listMaterials()){let r=n.getExtension(B);if(!r)continue;let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[B]={diffuseTransmissionFactor:r.getDiffuseTransmissionFactor(),diffuseTransmissionColorFactor:r.getDiffuseTransmissionColorFactor()};if(r.getDiffuseTransmissionTexture()){let t=r.getDiffuseTransmissionTexture(),n=r.getDiffuseTransmissionTextureInfo();o.diffuseTransmissionTexture=e.createTextureInfoDef(t,n)}if(r.getDiffuseTransmissionColorTexture()){let t=r.getDiffuseTransmissionColorTexture(),n=r.getDiffuseTransmissionColorTextureInfo();o.diffuseTransmissionColorTexture=e.createTextureInfoDef(t,n)}}return this}};qn.EXTENSION_NAME=B;var Jn=class extends O{init(){this.extensionName=V,this.propertyType=`Dispersion`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{dispersion:0})}getDispersion(){return this.get(`dispersion`)}setDispersion(e){return this.set(`dispersion`,e)}};Jn.EXTENSION_NAME=V;var Yn=class extends j{constructor(...e){super(...e),this.extensionName=V,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createDispersion(){return new Jn(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){return(e.jsonDoc.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[V]){let r=this.createDispersion();e.materials[n].setExtension(V,r);let i=t.extensions[V];i.dispersion!==void 0&&r.setDispersion(i.dispersion)}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(V);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{},a.extensions[V]={dispersion:r.getDispersion()}}}),this}};Yn.EXTENSION_NAME=V;var Xn=class extends O{init(){this.extensionName=H,this.propertyType=`EmissiveStrength`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{emissiveStrength:1})}getEmissiveStrength(){return this.get(`emissiveStrength`)}setEmissiveStrength(e){return this.set(`emissiveStrength`,e)}};Xn.EXTENSION_NAME=H;var Zn=class extends j{constructor(...e){super(...e),this.extensionName=H,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createEmissiveStrength(){return new Xn(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){return(e.jsonDoc.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[H]){let r=this.createEmissiveStrength();e.materials[n].setExtension(H,r);let i=t.extensions[H];i.emissiveStrength!==void 0&&r.setEmissiveStrength(i.emissiveStrength)}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(H);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{},a.extensions[H]={emissiveStrength:r.getEmissiveStrength()}}}),this}};Zn.EXTENSION_NAME=H;var Qn=class extends O{init(){this.extensionName=U,this.propertyType=`IOR`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:1.5})}getIOR(){return this.get(`ior`)}setIOR(e){return this.set(`ior`,e)}};Qn.EXTENSION_NAME=U;var $n=class extends j{constructor(...e){super(...e),this.extensionName=U,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createIOR(){return new Qn(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){return(e.jsonDoc.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[U]){let r=this.createIOR();e.materials[n].setExtension(U,r);let i=t.extensions[U];i.ior!==void 0&&r.setIOR(i.ior)}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(U);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{},a.extensions[U]={ior:r.getIOR()}}}),this}};$n.EXTENSION_NAME=U;var{R:er,G:tr}=_,nr=class extends O{init(){this.extensionName=W,this.propertyType=`Iridescence`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{iridescenceFactor:0,iridescenceTexture:null,iridescenceTextureInfo:new k(this.graph,`iridescenceTextureInfo`),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new k(this.graph,`iridescenceThicknessTextureInfo`)})}getIridescenceFactor(){return this.get(`iridescenceFactor`)}setIridescenceFactor(e){return this.set(`iridescenceFactor`,e)}getIridescenceTexture(){return this.getRef(`iridescenceTexture`)}getIridescenceTextureInfo(){return this.getRef(`iridescenceTexture`)?this.getRef(`iridescenceTextureInfo`):null}setIridescenceTexture(e){return this.setRef(`iridescenceTexture`,e,{channels:er})}getIridescenceIOR(){return this.get(`iridescenceIOR`)}setIridescenceIOR(e){return this.set(`iridescenceIOR`,e)}getIridescenceThicknessMinimum(){return this.get(`iridescenceThicknessMinimum`)}setIridescenceThicknessMinimum(e){return this.set(`iridescenceThicknessMinimum`,e)}getIridescenceThicknessMaximum(){return this.get(`iridescenceThicknessMaximum`)}setIridescenceThicknessMaximum(e){return this.set(`iridescenceThicknessMaximum`,e)}getIridescenceThicknessTexture(){return this.getRef(`iridescenceThicknessTexture`)}getIridescenceThicknessTextureInfo(){return this.getRef(`iridescenceThicknessTexture`)?this.getRef(`iridescenceThicknessTextureInfo`):null}setIridescenceThicknessTexture(e){return this.setRef(`iridescenceThicknessTexture`,e,{channels:tr})}};nr.EXTENSION_NAME=W;var rr=class extends j{constructor(...e){super(...e),this.extensionName=W,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createIridescence(){return new nr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[W]){let i=this.createIridescence();e.materials[n].setExtension(W,i);let a=t.extensions[W];if(a.iridescenceFactor!==void 0&&i.setIridescenceFactor(a.iridescenceFactor),a.iridescenceIor!==void 0&&i.setIridescenceIOR(a.iridescenceIor),a.iridescenceThicknessMinimum!==void 0&&i.setIridescenceThicknessMinimum(a.iridescenceThicknessMinimum),a.iridescenceThicknessMaximum!==void 0&&i.setIridescenceThicknessMaximum(a.iridescenceThicknessMaximum),a.iridescenceTexture!==void 0){let t=a.iridescenceTexture,n=e.textures[r[t.index].source];i.setIridescenceTexture(n),e.setTextureInfo(i.getIridescenceTextureInfo(),t)}if(a.iridescenceThicknessTexture!==void 0){let t=a.iridescenceThicknessTexture,n=e.textures[r[t.index].source];i.setIridescenceThicknessTexture(n),e.setTextureInfo(i.getIridescenceThicknessTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(W);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[W]={};if(r.getIridescenceFactor()>0&&(o.iridescenceFactor=r.getIridescenceFactor()),r.getIridescenceIOR()!==1.3&&(o.iridescenceIor=r.getIridescenceIOR()),r.getIridescenceThicknessMinimum()!==100&&(o.iridescenceThicknessMinimum=r.getIridescenceThicknessMinimum()),r.getIridescenceThicknessMaximum()!==400&&(o.iridescenceThicknessMaximum=r.getIridescenceThicknessMaximum()),r.getIridescenceTexture()){let t=r.getIridescenceTexture(),n=r.getIridescenceTextureInfo();o.iridescenceTexture=e.createTextureInfoDef(t,n)}if(r.getIridescenceThicknessTexture()){let t=r.getIridescenceThicknessTexture(),n=r.getIridescenceThicknessTextureInfo();o.iridescenceThicknessTexture=e.createTextureInfoDef(t,n)}}}),this}};rr.EXTENSION_NAME=W;var{R:ir,G:ar,B:or,A:sr}=_,cr=class extends O{init(){this.extensionName=G,this.propertyType=`PBRSpecularGlossiness`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseFactor:[1,1,1,1],diffuseTexture:null,diffuseTextureInfo:new k(this.graph,`diffuseTextureInfo`),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new k(this.graph,`specularGlossinessTextureInfo`)})}getDiffuseFactor(){return this.get(`diffuseFactor`)}setDiffuseFactor(e){return this.set(`diffuseFactor`,e)}getDiffuseTexture(){return this.getRef(`diffuseTexture`)}getDiffuseTextureInfo(){return this.getRef(`diffuseTexture`)?this.getRef(`diffuseTextureInfo`):null}setDiffuseTexture(e){return this.setRef(`diffuseTexture`,e,{channels:ir|ar|or|sr,isColor:!0})}getSpecularFactor(){return this.get(`specularFactor`)}setSpecularFactor(e){return this.set(`specularFactor`,e)}getGlossinessFactor(){return this.get(`glossinessFactor`)}setGlossinessFactor(e){return this.set(`glossinessFactor`,e)}getSpecularGlossinessTexture(){return this.getRef(`specularGlossinessTexture`)}getSpecularGlossinessTextureInfo(){return this.getRef(`specularGlossinessTexture`)?this.getRef(`specularGlossinessTextureInfo`):null}setSpecularGlossinessTexture(e){return this.setRef(`specularGlossinessTexture`,e,{channels:ir|ar|or|sr})}};cr.EXTENSION_NAME=G;var lr=class extends j{constructor(...e){super(...e),this.extensionName=G,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createPBRSpecularGlossiness(){return new cr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[G]){let i=this.createPBRSpecularGlossiness();e.materials[n].setExtension(G,i);let a=t.extensions[G];if(a.diffuseFactor!==void 0&&i.setDiffuseFactor(a.diffuseFactor),a.specularFactor!==void 0&&i.setSpecularFactor(a.specularFactor),a.glossinessFactor!==void 0&&i.setGlossinessFactor(a.glossinessFactor),a.diffuseTexture!==void 0){let t=a.diffuseTexture,n=e.textures[r[t.index].source];i.setDiffuseTexture(n),e.setTextureInfo(i.getDiffuseTextureInfo(),t)}if(a.specularGlossinessTexture!==void 0){let t=a.specularGlossinessTexture,n=e.textures[r[t.index].source];i.setSpecularGlossinessTexture(n),e.setTextureInfo(i.getSpecularGlossinessTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(G);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[G]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()};if(r.getDiffuseTexture()){let t=r.getDiffuseTexture(),n=r.getDiffuseTextureInfo();o.diffuseTexture=e.createTextureInfoDef(t,n)}if(r.getSpecularGlossinessTexture()){let t=r.getSpecularGlossinessTexture(),n=r.getSpecularGlossinessTextureInfo();o.specularGlossinessTexture=e.createTextureInfoDef(t,n)}}}),this}};lr.EXTENSION_NAME=G;var{R:ur,G:dr,B:fr,A:pr}=_,mr=class extends O{init(){this.extensionName=jt,this.propertyType=`Sheen`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{sheenColorFactor:[0,0,0],sheenColorTexture:null,sheenColorTextureInfo:new k(this.graph,`sheenColorTextureInfo`),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new k(this.graph,`sheenRoughnessTextureInfo`)})}getSheenColorFactor(){return this.get(`sheenColorFactor`)}setSheenColorFactor(e){return this.set(`sheenColorFactor`,e)}getSheenColorTexture(){return this.getRef(`sheenColorTexture`)}getSheenColorTextureInfo(){return this.getRef(`sheenColorTexture`)?this.getRef(`sheenColorTextureInfo`):null}setSheenColorTexture(e){return this.setRef(`sheenColorTexture`,e,{channels:ur|dr|fr,isColor:!0})}getSheenRoughnessFactor(){return this.get(`sheenRoughnessFactor`)}setSheenRoughnessFactor(e){return this.set(`sheenRoughnessFactor`,e)}getSheenRoughnessTexture(){return this.getRef(`sheenRoughnessTexture`)}getSheenRoughnessTextureInfo(){return this.getRef(`sheenRoughnessTexture`)?this.getRef(`sheenRoughnessTextureInfo`):null}setSheenRoughnessTexture(e){return this.setRef(`sheenRoughnessTexture`,e,{channels:pr})}};mr.EXTENSION_NAME=jt;var hr=class extends j{constructor(...e){super(...e),this.extensionName=jt,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createSheen(){return new mr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[jt]){let i=this.createSheen();e.materials[n].setExtension(jt,i);let a=t.extensions[jt];if(a.sheenColorFactor!==void 0&&i.setSheenColorFactor(a.sheenColorFactor),a.sheenRoughnessFactor!==void 0&&i.setSheenRoughnessFactor(a.sheenRoughnessFactor),a.sheenColorTexture!==void 0){let t=a.sheenColorTexture,n=e.textures[r[t.index].source];i.setSheenColorTexture(n),e.setTextureInfo(i.getSheenColorTextureInfo(),t)}if(a.sheenRoughnessTexture!==void 0){let t=a.sheenRoughnessTexture,n=e.textures[r[t.index].source];i.setSheenRoughnessTexture(n),e.setTextureInfo(i.getSheenRoughnessTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(jt);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[jt]={sheenColorFactor:r.getSheenColorFactor(),sheenRoughnessFactor:r.getSheenRoughnessFactor()};if(r.getSheenColorTexture()){let t=r.getSheenColorTexture(),n=r.getSheenColorTextureInfo();o.sheenColorTexture=e.createTextureInfoDef(t,n)}if(r.getSheenRoughnessTexture()){let t=r.getSheenRoughnessTexture(),n=r.getSheenRoughnessTextureInfo();o.sheenRoughnessTexture=e.createTextureInfoDef(t,n)}}}),this}};hr.EXTENSION_NAME=jt;var{R:gr,G:_r,B:vr,A:yr}=_,br=class extends O{init(){this.extensionName=Mt,this.propertyType=`Specular`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{specularFactor:1,specularTexture:null,specularTextureInfo:new k(this.graph,`specularTextureInfo`),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new k(this.graph,`specularColorTextureInfo`)})}getSpecularFactor(){return this.get(`specularFactor`)}setSpecularFactor(e){return this.set(`specularFactor`,e)}getSpecularColorFactor(){return this.get(`specularColorFactor`)}setSpecularColorFactor(e){return this.set(`specularColorFactor`,e)}getSpecularTexture(){return this.getRef(`specularTexture`)}getSpecularTextureInfo(){return this.getRef(`specularTexture`)?this.getRef(`specularTextureInfo`):null}setSpecularTexture(e){return this.setRef(`specularTexture`,e,{channels:yr})}getSpecularColorTexture(){return this.getRef(`specularColorTexture`)}getSpecularColorTextureInfo(){return this.getRef(`specularColorTexture`)?this.getRef(`specularColorTextureInfo`):null}setSpecularColorTexture(e){return this.setRef(`specularColorTexture`,e,{channels:gr|_r|vr,isColor:!0})}};br.EXTENSION_NAME=Mt;var xr=class extends j{constructor(...e){super(...e),this.extensionName=Mt,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createSpecular(){return new br(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[Mt]){let i=this.createSpecular();e.materials[n].setExtension(Mt,i);let a=t.extensions[Mt];if(a.specularFactor!==void 0&&i.setSpecularFactor(a.specularFactor),a.specularColorFactor!==void 0&&i.setSpecularColorFactor(a.specularColorFactor),a.specularTexture!==void 0){let t=a.specularTexture,n=e.textures[r[t.index].source];i.setSpecularTexture(n),e.setTextureInfo(i.getSpecularTextureInfo(),t)}if(a.specularColorTexture!==void 0){let t=a.specularColorTexture,n=e.textures[r[t.index].source];i.setSpecularColorTexture(n),e.setTextureInfo(i.getSpecularColorTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(Mt);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[Mt]={};if(r.getSpecularFactor()!==1&&(o.specularFactor=r.getSpecularFactor()),T.eq(r.getSpecularColorFactor(),[1,1,1])||(o.specularColorFactor=r.getSpecularColorFactor()),r.getSpecularTexture()){let t=r.getSpecularTexture(),n=r.getSpecularTextureInfo();o.specularTexture=e.createTextureInfoDef(t,n)}if(r.getSpecularColorTexture()){let t=r.getSpecularColorTexture(),n=r.getSpecularColorTextureInfo();o.specularColorTexture=e.createTextureInfoDef(t,n)}}}),this}};xr.EXTENSION_NAME=Mt;var{R:Sr}=_,Cr=class extends O{init(){this.extensionName=Nt,this.propertyType=`Transmission`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{transmissionFactor:0,transmissionTexture:null,transmissionTextureInfo:new k(this.graph,`transmissionTextureInfo`)})}getTransmissionFactor(){return this.get(`transmissionFactor`)}setTransmissionFactor(e){return this.set(`transmissionFactor`,e)}getTransmissionTexture(){return this.getRef(`transmissionTexture`)}getTransmissionTextureInfo(){return this.getRef(`transmissionTexture`)?this.getRef(`transmissionTextureInfo`):null}setTransmissionTexture(e){return this.setRef(`transmissionTexture`,e,{channels:Sr})}};Cr.EXTENSION_NAME=Nt;var wr=class extends j{constructor(...e){super(...e),this.extensionName=Nt,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createTransmission(){return new Cr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[Nt]){let i=this.createTransmission();e.materials[n].setExtension(Nt,i);let a=t.extensions[Nt];if(a.transmissionFactor!==void 0&&i.setTransmissionFactor(a.transmissionFactor),a.transmissionTexture!==void 0){let t=a.transmissionTexture,n=e.textures[r[t.index].source];i.setTransmissionTexture(n),e.setTextureInfo(i.getTransmissionTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(Nt);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[Nt]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){let t=r.getTransmissionTexture(),n=r.getTransmissionTextureInfo();o.transmissionTexture=e.createTextureInfoDef(t,n)}}}),this}};wr.EXTENSION_NAME=Nt;var Tr=class extends O{init(){this.extensionName=Pt,this.propertyType=`Unlit`,this.parentTypes=[m.MATERIAL]}};Tr.EXTENSION_NAME=Pt;var Er=class extends j{constructor(...e){super(...e),this.extensionName=Pt,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createUnlit(){return new Tr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){return(e.jsonDoc.json.materials||[]).forEach((t,n)=>{t.extensions&&t.extensions[Pt]&&e.materials[n].setExtension(Pt,this.createUnlit())}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{if(n.getExtension(Pt)){let r=e.materialIndexMap.get(n),i=t.json.materials[r];i.extensions=i.extensions||{},i.extensions[Pt]={}}}),this}};Er.EXTENSION_NAME=Pt;var Dr=class extends O{init(){this.extensionName=K,this.propertyType=`Mapping`,this.parentTypes=[`MappingList`]}getDefaults(){return Object.assign(super.getDefaults(),{material:null,variants:new s})}getMaterial(){return this.getRef(`material`)}setMaterial(e){return this.setRef(`material`,e)}addVariant(e){return this.addRef(`variants`,e)}removeVariant(e){return this.removeRef(`variants`,e)}listVariants(){return this.listRefs(`variants`)}};Dr.EXTENSION_NAME=K;var Or=class extends O{init(){this.extensionName=K,this.propertyType=`MappingList`,this.parentTypes=[m.PRIMITIVE]}getDefaults(){return Object.assign(super.getDefaults(),{mappings:new s})}addMapping(e){return this.addRef(`mappings`,e)}removeMapping(e){return this.removeRef(`mappings`,e)}listMappings(){return this.listRefs(`mappings`)}};Or.EXTENSION_NAME=K;var kr=class extends O{init(){this.extensionName=K,this.propertyType=`Variant`,this.parentTypes=[`MappingList`]}};kr.EXTENSION_NAME=K;var Ar=class extends j{constructor(...e){super(...e),this.extensionName=K}createMappingList(){return new Or(this.document.getGraph())}createVariant(e=``){return new kr(this.document.getGraph(),e)}createMapping(){return new Dr(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof kr)}read(e){let t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[K])return this;let n=(t.json.extensions[K].variants||[]).map(e=>this.createVariant().setName(e.name||``));return(t.json.meshes||[]).forEach((t,r)=>{let i=e.meshes[r];(t.primitives||[]).forEach((t,r)=>{if(!t.extensions||!t.extensions[K])return;let a=this.createMappingList(),o=t.extensions[K];for(let t of o.mappings){let r=this.createMapping();t.material!==void 0&&r.setMaterial(e.materials[t.material]);for(let e of t.variants||[])r.addVariant(n[e]);a.addMapping(r)}i.listPrimitives()[r].setExtension(K,a)})}),this}write(e){let t=e.jsonDoc,n=this.listVariants();if(!n.length)return this;let r=[],i=new Map;for(let t of n)i.set(t,r.length),r.push(e.createPropertyDef(t));for(let t of this.document.getRoot().listMeshes()){let n=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,r)=>{let a=t.getExtension(K);if(!a)return;let o=e.jsonDoc.json.meshes[n].primitives[r],s=a.listMappings().map(t=>{let n=e.createPropertyDef(t),r=t.getMaterial();return r&&(n.material=e.materialIndexMap.get(r)),n.variants=t.listVariants().map(e=>i.get(e)),n});o.extensions=o.extensions||{},o.extensions[K]={mappings:s}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[K]={variants:r},this}};Ar.EXTENSION_NAME=K;var{G:jr}=_,Mr=class extends O{init(){this.extensionName=Ft,this.propertyType=`Volume`,this.parentTypes=[m.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{thicknessFactor:0,thicknessTexture:null,thicknessTextureInfo:new k(this.graph,`thicknessTexture`),attenuationDistance:1/0,attenuationColor:[1,1,1]})}getThicknessFactor(){return this.get(`thicknessFactor`)}setThicknessFactor(e){return this.set(`thicknessFactor`,e)}getThicknessTexture(){return this.getRef(`thicknessTexture`)}getThicknessTextureInfo(){return this.getRef(`thicknessTexture`)?this.getRef(`thicknessTextureInfo`):null}setThicknessTexture(e){return this.setRef(`thicknessTexture`,e,{channels:jr})}getAttenuationDistance(){return this.get(`attenuationDistance`)}setAttenuationDistance(e){return this.set(`attenuationDistance`,e)}getAttenuationColor(){return this.get(`attenuationColor`)}setAttenuationColor(e){return this.set(`attenuationColor`,e)}};Mr.EXTENSION_NAME=Ft;var Nr=class extends j{constructor(...e){super(...e),this.extensionName=Ft,this.prereadTypes=[m.MESH],this.prewriteTypes=[m.MESH]}createVolume(){return new Mr(this.document.getGraph())}read(e){return this}write(e){return this}preread(e){let t=e.jsonDoc,n=t.json.materials||[],r=t.json.textures||[];return n.forEach((t,n)=>{if(t.extensions&&t.extensions[Ft]){let i=this.createVolume();e.materials[n].setExtension(Ft,i);let a=t.extensions[Ft];if(a.thicknessFactor!==void 0&&i.setThicknessFactor(a.thicknessFactor),a.attenuationDistance!==void 0&&i.setAttenuationDistance(a.attenuationDistance),a.attenuationColor!==void 0&&i.setAttenuationColor(a.attenuationColor),a.thicknessTexture!==void 0){let t=a.thicknessTexture,n=e.textures[r[t.index].source];i.setThicknessTexture(n),e.setTextureInfo(i.getThicknessTextureInfo(),t)}}}),this}prewrite(e){let t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(n=>{let r=n.getExtension(Ft);if(r){let i=e.materialIndexMap.get(n),a=t.json.materials[i];a.extensions=a.extensions||{};let o=a.extensions[Ft]={};if(r.getThicknessFactor()>0&&(o.thicknessFactor=r.getThicknessFactor()),Number.isFinite(r.getAttenuationDistance())&&(o.attenuationDistance=r.getAttenuationDistance()),T.eq(r.getAttenuationColor(),[1,1,1])||(o.attenuationColor=r.getAttenuationColor()),r.getThicknessTexture()){let t=r.getThicknessTexture(),n=r.getThicknessTextureInfo();o.thicknessTexture=e.createTextureInfoDef(t,n)}}}),this}};Nr.EXTENSION_NAME=Ft;var Pr=class extends j{constructor(...e){super(...e),this.extensionName=It}read(e){return this}write(e){return this}};Pr.EXTENSION_NAME=It;var Fr=class extends O{init(){this.extensionName=Lt,this.propertyType=`Visibility`,this.parentTypes=[m.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{visible:!0})}getVisible(){return this.get(`visible`)}setVisible(e){return this.set(`visible`,e)}};Fr.EXTENSION_NAME=Lt;var Ir=class extends j{constructor(...e){super(...e),this.extensionName=Lt}createVisibility(){return new Fr(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Lt]){let r=this.createVisibility();e.nodes[n].setExtension(Lt,r);let i=t.extensions[Lt];i.visible!==void 0&&r.setVisible(i.visible)}}),this}write(e){let t=e.jsonDoc;for(let n of this.document.getRoot().listNodes()){let r=n.getExtension(Lt);if(!r)continue;let i=e.nodeIndexMap.get(n),a=t.json.nodes[i];a.extensions=a.extensions||{},a.extensions[Lt]={visible:r.getVisible()}}return this}};Ir.EXTENSION_NAME=Lt;var Lr=class{match(e){return e[0]===171&&e[1]===75&&e[2]===84&&e[3]===88&&e[4]===32&&e[5]===50&&e[6]===48&&e[7]===187&&e[8]===13&&e[9]===10&&e[10]===26&&e[11]===10}getSize(e){let t=Ot(e);return[t.pixelWidth,t.pixelHeight]}getChannels(e){let t=Ot(e).dataFormatDescriptor[0];if(t.colorModel===163)return t.samples.length===2&&(t.samples[1].channelType&15)==15?4:3;if(t.colorModel===166)return(t.samples[0].channelType&15)==3?4:3;throw Error(`Unexpected KTX2 colorModel, "${t.colorModel}".`)}getVRAMByteLength(e){let t=Ot(e),n=this.getChannels(e)>3,r=0;for(let e=0;e<t.levels.length;e++){let i=t.levels[e];if(i.uncompressedByteLength)r+=i.uncompressedByteLength;else{let i=Math.max(1,Math.floor(t.pixelWidth/2**e)),a=Math.max(1,Math.floor(t.pixelHeight/2**e)),o=n?16:8;r+=i/4*(a/4)*o}}return r}},Rr=class extends j{constructor(...e){super(...e),this.extensionName=Rt,this.prereadTypes=[m.TEXTURE]}static register(){C.registerFormat(`image/ktx2`,new Lr)}preread(e){return e.jsonDoc.json.textures&&e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[Rt]&&(e.source=e.extensions[Rt].source)}),this}read(e){return this}write(e){let t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(n=>{if(n.getMimeType()===`image/ktx2`){let r=e.imageIndexMap.get(n);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[Rt]={source:e.source},delete e.source)})}}),this}};Rr.EXTENSION_NAME=Rt;var zr=class extends O{init(){this.extensionName=zt,this.propertyType=`Transform`,this.parentTypes=[m.TEXTURE_INFO]}getDefaults(){return Object.assign(super.getDefaults(),{offset:[0,0],rotation:0,scale:[1,1],texCoord:null})}getOffset(){return this.get(`offset`)}setOffset(e){return this.set(`offset`,e)}getRotation(){return this.get(`rotation`)}setRotation(e){return this.set(`rotation`,e)}getScale(){return this.get(`scale`)}setScale(e){return this.set(`scale`,e)}getTexCoord(){return this.get(`texCoord`)}setTexCoord(e){return this.set(`texCoord`,e)}};zr.EXTENSION_NAME=zt;var Br=class extends j{constructor(...e){super(...e),this.extensionName=zt}createTransform(){return new zr(this.document.getGraph())}read(e){for(let[t,n]of Array.from(e.textureInfos.entries())){if(!n.extensions||!n.extensions[zt])continue;let e=this.createTransform(),r=n.extensions[zt];r.offset!==void 0&&e.setOffset(r.offset),r.rotation!==void 0&&e.setRotation(r.rotation),r.scale!==void 0&&e.setScale(r.scale),r.texCoord!==void 0&&e.setTexCoord(r.texCoord),t.setExtension(zt,e)}return this}write(e){let t=Array.from(e.textureInfoDefMap.entries());for(let[e,n]of t){let t=e.getExtension(zt);if(!t)continue;n.extensions=n.extensions||{};let r={},i=T.eq;i(t.getOffset(),[0,0])||(r.offset=t.getOffset()),t.getRotation()!==0&&(r.rotation=t.getRotation()),i(t.getScale(),[1,1])||(r.scale=t.getScale()),t.getTexCoord()!=null&&(r.texCoord=t.getTexCoord()),n.extensions[zt]=r}return this}};Br.EXTENSION_NAME=zt;var Vr=[m.ROOT,m.SCENE,m.NODE,m.MESH,m.MATERIAL,m.TEXTURE,m.ANIMATION],Hr=class extends O{init(){this.extensionName=q,this.propertyType=`Packet`,this.parentTypes=Vr}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get(`context`)}setContext(e){return this.set(`context`,Ut({},e))}listProperties(){return Object.keys(this.get(`properties`))}getProperty(e){let t=this.get(`properties`);return e in t?t[e]:null}setProperty(e,t){this._assertContext(e);let n=Ut({},this.get(`properties`));return t?n[e]=t:delete n[e],this.set(`properties`,n)}toJSONLD(){let e=Ur(this.get(`context`)),t=Ur(this.get(`properties`));return Ut({"@context":e},t)}fromJSONLD(e){e=Ur(e);let t=e[`@context`];return t&&this.set(`context`,t),delete e[`@context`],this.set(`properties`,e)}_assertContext(e){if(!(e.split(`:`)[0]in this.get(`context`)))throw Error(`${q}: Missing context for term, "${e}".`)}};Hr.EXTENSION_NAME=q;function Ur(e){return JSON.parse(JSON.stringify(e))}var Wr=class extends j{constructor(...e){super(...e),this.extensionName=q}createPacket(){return new Hr(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){let t=e.jsonDoc.json.extensions?.[q];if(!t||!t.packets)return this;let n=e.jsonDoc.json,r=this.document.getRoot(),i=t.packets.map(e=>this.createPacket().fromJSONLD(e)),a=[[n.asset],n.scenes,n.nodes,n.meshes,n.materials,n.images,n.animations],o=[[r],r.listScenes(),r.listNodes(),r.listMeshes(),r.listMaterials(),r.listTextures(),r.listAnimations()];for(let e=0;e<a.length;e++){let t=a[e]||[];for(let n=0;n<t.length;n++){let r=t[n];if(r.extensions&&r.extensions[q]){let t=r.extensions[q];o[e][n].setExtension(q,i[t.packet])}}}return this}write(e){let{json:t}=e.jsonDoc,n=[];for(let r of this.properties){n.push(r.toJSONLD());for(let i of r.listParents()){let r;switch(i.propertyType){case m.ROOT:r=t.asset;break;case m.SCENE:r=t.scenes[e.sceneIndexMap.get(i)];break;case m.NODE:r=t.nodes[e.nodeIndexMap.get(i)];break;case m.MESH:r=t.meshes[e.meshIndexMap.get(i)];break;case m.MATERIAL:r=t.materials[e.materialIndexMap.get(i)];break;case m.TEXTURE:r=t.images[e.imageIndexMap.get(i)];break;case m.ANIMATION:r=t.animations[e.animationIndexMap.get(i)];break;default:r=null,this.document.getLogger().warn(`[${q}]: Unsupported parent property, "${i.propertyType}"`);break}r&&(r.extensions=r.extensions||{},r.extensions[q]={packet:n.length-1})}}return n.length>0&&(t.extensions=t.extensions||{},t.extensions[q]={packets:n}),this}};Wr.EXTENSION_NAME=q;var Gr=[Ht,sn,ln,fn,...[Dn,jn,In,Vn,qn,Yn,Zn,$n,rr,lr,xr,hr,wr,Er,Ar,Nr,Pr,Ir,Rr,Br,Wr]],Kr={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`]},qr=class{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new fi(e)}),this.register(function(e){return new pi(e)}),this.register(function(e){return new _i(e)}),this.register(function(e){return new vi(e)}),this.register(function(e){return new yi(e)}),this.register(function(e){return new bi(e)}),this.register(function(e){return new mi(e)}),this.register(function(e){return new hi(e)}),this.register(function(e){return new gi(e)}),this.register(function(e){return new xi(e)}),this.register(function(e){return new Si(e)}),this.register(function(e){return new Ci(e)}),this.register(function(e){return new wi(e)}),this.register(function(e){return new Ti(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}setTextureUtils(e){return this.textureUtils=e,this}parse(e,t,n,r){let i=new di,a=[];for(let e=0,t=this.pluginCallbacks.length;e<t;e++)a.push(this.pluginCallbacks[e](i));i.setPlugins(a),i.setTextureUtils(this.textureUtils),i.writeAsync(e,t,r).catch(n)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,r,i,t)})}},Q={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,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},Jr=`KHR_mesh_quantization`,$={};$[t.NearestFilter]=Q.NEAREST,$[t.NearestMipmapNearestFilter]=Q.NEAREST_MIPMAP_NEAREST,$[t.NearestMipmapLinearFilter]=Q.NEAREST_MIPMAP_LINEAR,$[t.LinearFilter]=Q.LINEAR,$[t.LinearMipmapNearestFilter]=Q.LINEAR_MIPMAP_NEAREST,$[t.LinearMipmapLinearFilter]=Q.LINEAR_MIPMAP_LINEAR,$[t.ClampToEdgeWrapping]=Q.CLAMP_TO_EDGE,$[t.RepeatWrapping]=Q.REPEAT,$[t.MirroredRepeatWrapping]=Q.MIRRORED_REPEAT;var Yr={scale:`scale`,position:`translation`,quaternion:`rotation`,morphTargetInfluences:`weights`},Xr=new t.Color,Zr=12,Qr=1179937895,$r=2,ei=8,ti=1313821514,ni=5130562;function ri(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}function ii(e){return new TextEncoder().encode(e).buffer}function ai(e){return ri(e.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function oi(e,n,r){let i={min:Array(e.itemSize).fill(1/0),max:Array(e.itemSize).fill(-1/0)};for(let a=n;a<n+r;a++)for(let n=0;n<e.itemSize;n++){let r;e.itemSize>4?r=e.array[a*e.itemSize+n]:(n===0?r=e.getX(a):n===1?r=e.getY(a):n===2?r=e.getZ(a):n===3&&(r=e.getW(a)),e.normalized===!0&&(r=t.MathUtils.normalize(r,e.array))),i.min[n]=Math.min(i.min[n],r),i.max[n]=Math.max(i.max[n],r)}return i}function si(e){return Math.ceil(e/4)*4}function ci(e,t=0){let n=si(e.byteLength);if(n!==e.byteLength){let r=new Uint8Array(n);if(r.set(new Uint8Array(e)),t!==0)for(let i=e.byteLength;i<n;i++)r[i]=t;return r.buffer}return e}function li(){return typeof document>`u`&&typeof OffscreenCanvas<`u`?new OffscreenCanvas(1,1):document.createElement(`canvas`)}function ui(e,t){if(typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas){let n;return t===`image/jpeg`?n=.92:t===`image/webp`&&(n=.8),e.convertToBlob({type:t,quality:n})}else return new Promise(n=>e.toBlob(n,t))}var di=class{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 r`+t.REVISION}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},n),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);let r=this,i=r.buffers,a=r.json;n=r.options;let o=r.extensionsUsed,s=r.extensionsRequired,c=new Blob(i,{type:`application/octet-stream`}),l=Object.keys(o),u=Object.keys(s);if(l.length>0&&(a.extensionsUsed=l),u.length>0&&(a.extensionsRequired=u),a.buffers&&a.buffers.length>0&&(a.buffers[0].byteLength=c.size),n.binary===!0){let e=new FileReader;e.readAsArrayBuffer(c),e.onloadend=function(){let n=ci(e.result),r=new DataView(new ArrayBuffer(ei));r.setUint32(0,n.byteLength,!0),r.setUint32(4,ni,!0);let i=ci(ii(JSON.stringify(a)),32),o=new DataView(new ArrayBuffer(ei));o.setUint32(0,i.byteLength,!0),o.setUint32(4,ti,!0);let s=new ArrayBuffer(Zr),c=new DataView(s);c.setUint32(0,Qr,!0),c.setUint32(4,$r,!0);let l=Zr+o.byteLength+i.byteLength+r.byteLength+n.byteLength;c.setUint32(8,l,!0);let u=new Blob([s,o,i,r,n],{type:`application/octet-stream`}),d=new FileReader;d.readAsArrayBuffer(u),d.onloadend=function(){t(d.result)}}}else if(a.buffers&&a.buffers.length>0){let e=new FileReader;e.readAsDataURL(c),e.onloadend=function(){let n=e.result;a.buffers[0].uri=n,t(a)}}else t(a)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let e in i.gltfExtensions)t.extensions[e]=i.gltfExtensions[e],r[e]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(t){console.warn(`THREE.GLTFExporter: userData of '`+e.name+`' won't be serialized because of JSON.stringify error - `+t.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let n=new t.Vector3;for(let t=0,r=e.count;t<r;t++)if(Math.abs(n.fromBufferAttribute(e,t).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let n=this.cache;if(n.attributesNormalized.has(e))return n.attributesNormalized.get(e);let r=e.clone(),i=new t.Vector3;for(let e=0,t=r.count;e<t;e++)i.fromBufferAttribute(r,e),i.x===0&&i.y===0&&i.z===0?i.setX(1):i.normalize(),r.setXYZ(e,i.x,i.y,i.z);return n.attributesNormalized.set(e,r),r}applyTextureTransform(e,t){let n=!1,r={};(t.offset.x!==0||t.offset.y!==0)&&(r.offset=t.offset.toArray(),n=!0),t.rotation!==0&&(r.rotation=t.rotation,n=!0),(t.repeat.x!==1||t.repeat.y!==1)&&(r.scale=t.repeat.toArray(),n=!0),n&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=r,this.extensionsUsed.KHR_texture_transform=!0)}async buildMetalRoughTextureAsync(e,n){if(e===n)return e;function r(e){return e.colorSpace===t.SRGBColorSpace?function(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}:function(e){return e}}e instanceof t.CompressedTexture&&(e=await this.decompressTextureAsync(e)),n instanceof t.CompressedTexture&&(n=await this.decompressTextureAsync(n));let i=e?e.image:null,a=n?n.image:null,o=Math.max(i?i.width:0,a?a.width:0),s=Math.max(i?i.height:0,a?a.height:0),c=li();c.width=o,c.height=s;let l=c.getContext(`2d`,{willReadFrequently:!0});l.fillStyle=`#00ffff`,l.fillRect(0,0,o,s);let u=l.getImageData(0,0,o,s);if(i){l.drawImage(i,0,0,o,s);let t=r(e),n=l.getImageData(0,0,o,s).data;for(let e=2;e<n.length;e+=4)u.data[e]=t(n[e]/256)*256}if(a){l.drawImage(a,0,0,o,s);let e=r(n),t=l.getImageData(0,0,o,s).data;for(let n=1;n<t.length;n+=4)u.data[n]=e(t[n]/256)*256}l.putImageData(u,0,0);let d=(e||n).clone();return d.source=new t.Source(c),d.colorSpace=t.NoColorSpace,d.channel=(e||n).channel,e&&n&&e.channel!==n.channel&&console.warn(`THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.`),console.warn(`THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.`),d}async decompressTextureAsync(e,t=1/0){if(this.textureUtils===null)throw Error(`THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.`);return await this.textureUtils.decompress(e,t)}processBuffer(e){let t=this.json,n=this.buffers;return t.buffers||=[{byteLength:0}],n.push(e),0}processBufferView(e,n,r,i,a){let o=this.json;o.bufferViews||=[];let s;switch(n){case Q.BYTE:case Q.UNSIGNED_BYTE:s=1;break;case Q.SHORT:case Q.UNSIGNED_SHORT:s=2;break;default:s=4}let c=e.itemSize*s;a===Q.ARRAY_BUFFER&&(c=Math.ceil(c/4)*4);let l=si(i*c),u=new DataView(new ArrayBuffer(l)),d=0;for(let a=r;a<r+i;a++){for(let r=0;r<e.itemSize;r++){let i;e.itemSize>4?i=e.array[a*e.itemSize+r]:(r===0?i=e.getX(a):r===1?i=e.getY(a):r===2?i=e.getZ(a):r===3&&(i=e.getW(a)),e.normalized===!0&&(i=t.MathUtils.normalize(i,e.array))),n===Q.FLOAT?u.setFloat32(d,i,!0):n===Q.INT?u.setInt32(d,i,!0):n===Q.UNSIGNED_INT?u.setUint32(d,i,!0):n===Q.SHORT?u.setInt16(d,i,!0):n===Q.UNSIGNED_SHORT?u.setUint16(d,i,!0):n===Q.BYTE?u.setInt8(d,i):n===Q.UNSIGNED_BYTE&&u.setUint8(d,i),d+=s}d%c!==0&&(d+=c-d%c)}let f={buffer:this.processBuffer(u.buffer),byteOffset:this.byteOffset,byteLength:l};return a!==void 0&&(f.target=a),a===Q.ARRAY_BUFFER&&(f.byteStride=c),this.byteOffset+=l,o.bufferViews.push(f),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||=[],new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=ci(i.result),a={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let i=this.json,a={1:`SCALAR`,2:`VEC2`,3:`VEC3`,4:`VEC4`,9:`MAT3`,16:`MAT4`},o;if(e.array.constructor===Float32Array)o=Q.FLOAT;else if(e.array.constructor===Int32Array)o=Q.INT;else if(e.array.constructor===Uint32Array)o=Q.UNSIGNED_INT;else if(e.array.constructor===Int16Array)o=Q.SHORT;else if(e.array.constructor===Uint16Array)o=Q.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)o=Q.BYTE;else if(e.array.constructor===Uint8Array)o=Q.UNSIGNED_BYTE;else throw Error(`THREE.GLTFExporter: Unsupported bufferAttribute component type: `+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let s=oi(e,n,r),c;t!==void 0&&(c=e===t.index?Q.ELEMENT_ARRAY_BUFFER:Q.ARRAY_BUFFER);let l=this.processBufferView(e,o,n,r,c),u={bufferView:l.id,byteOffset:l.byteOffset,componentType:o,count:r,max:s.max,min:s.min,type:a[e.itemSize]};return e.normalized===!0&&(u.normalized=!0),i.accessors||=[],i.accessors.push(u)-1}processImage(e,n,r,i=`image/png`){if(e!==null){let a=this,o=a.cache,s=a.json,c=a.options,l=a.pending;o.images.has(e)||o.images.set(e,{});let u=o.images.get(e),d=i+`:flipY/`+r.toString();if(u[d]!==void 0)return u[d];s.images||=[];let f={mimeType:i},p=li();p.width=Math.min(e.width,c.maxTextureSize),p.height=Math.min(e.height,c.maxTextureSize);let m=p.getContext(`2d`,{willReadFrequently:!0});if(r===!0&&(m.translate(0,p.height),m.scale(1,-1)),e.data!==void 0){n!==t.RGBAFormat&&console.error(`GLTFExporter: Only RGBAFormat is supported.`,n),(e.width>c.maxTextureSize||e.height>c.maxTextureSize)&&console.warn(`GLTFExporter: Image size is bigger than maxTextureSize`,e);let r=new Uint8ClampedArray(e.height*e.width*4);for(let t=0;t<r.length;t+=4)r[t+0]=e.data[t+0],r[t+1]=e.data[t+1],r[t+2]=e.data[t+2],r[t+3]=e.data[t+3];m.putImageData(new ImageData(r,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)m.drawImage(e,0,0,p.width,p.height);else throw Error(`THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.`);c.binary===!0?l.push(ui(p,i).then(e=>a.processBufferViewImage(e)).then(e=>{f.bufferView=e})):f.uri=t.ImageUtils.getDataURL(p,i);let h=s.images.push(f)-1;return u[d]=h,h}else throw Error(`THREE.GLTFExporter: No valid image data found. Unable to process texture.`)}processSampler(e){let t=this.json;t.samplers||=[];let n={magFilter:$[e.magFilter],minFilter:$[e.minFilter],wrapS:$[e.wrapS],wrapT:$[e.wrapT]};return t.samplers.push(n)-1}async processTextureAsync(e){let n=this.options,r=this.cache,i=this.json;if(r.textures.has(e))return r.textures.get(e);i.textures||=[],e instanceof t.CompressedTexture&&(e=await this.decompressTextureAsync(e,n.maxTextureSize));let a=e.userData.mimeType,o=this.processImage(e.image,e.format,e.flipY,a),s={sampler:this.processSampler(e)};a===`image/webp`?(s.extensions=s.extensions||{},s.extensions.EXT_texture_webp={source:o},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):s.source=o,e.name&&(s.name=e.name),await this._invokeAllAsync(async function(t){t.writeTexture&&await t.writeTexture(e,s)});let c=i.textures.push(s)-1;return r.textures.set(e,c),c}async processMaterialAsync(e){let n=this.cache,r=this.json;if(n.materials.has(e))return n.materials.get(e);if(e.isShaderMaterial)return console.warn(`GLTFExporter: THREE.ShaderMaterial not supported.`),null;r.materials||=[];let i={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn(`GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.`);let a=e.color.toArray().concat([e.opacity]);if(ri(a,[1,1,1,1])||(i.pbrMetallicRoughness.baseColorFactor=a),e.isMeshStandardMaterial?(i.pbrMetallicRoughness.metallicFactor=e.metalness,i.pbrMetallicRoughness.roughnessFactor=e.roughness):(i.pbrMetallicRoughness.metallicFactor=0,i.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){let t=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),n={index:await this.processTextureAsync(t),texCoord:t.channel};this.applyTextureTransform(n,t),i.pbrMetallicRoughness.metallicRoughnessTexture=n}if(e.map){let t={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(t,e.map),i.pbrMetallicRoughness.baseColorTexture=t}if(e.emissive){let t=e.emissive;if(Math.max(t.r,t.g,t.b)>0&&(i.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),i.emissiveTexture=t}}if(e.normalMap){let t={index:await this.processTextureAsync(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),i.normalTexture=t}if(e.aoMap){let t={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(t.strength=e.aoMapIntensity),this.applyTextureTransform(t,e.aoMap),i.occlusionTexture=t}e.transparent?i.alphaMode=`BLEND`:e.alphaTest>0&&(i.alphaMode=`MASK`,i.alphaCutoff=e.alphaTest),e.side===t.DoubleSide&&(i.doubleSided=!0),e.name!==``&&(i.name=e.name),this.serializeUserData(e,i),await this._invokeAllAsync(async function(t){t.writeMaterialAsync&&await t.writeMaterialAsync(e,i)});let o=r.materials.push(i)-1;return n.materials.set(e,o),o}async processMeshAsync(e){let t=this.cache,n=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let t=0,n=e.material.length;t<n;t++)r.push(e.material[t].uuid);else r.push(e.material.uuid);let i=r.join(`:`);if(t.meshes.has(i))return t.meshes.get(i);let a=e.geometry,o;o=e.isLineSegments?Q.LINES:e.isLineLoop?Q.LINE_LOOP:e.isLine?Q.LINE_STRIP:e.isPoints?Q.POINTS:e.material.wireframe?Q.LINES:Q.TRIANGLES;let s={},c={},l=[],u=[],d={uv:`TEXCOORD_0`,uv1:`TEXCOORD_1`,uv2:`TEXCOORD_2`,uv3:`TEXCOORD_3`,color:`COLOR_0`,skinWeight:`WEIGHTS_0`,skinIndex:`JOINTS_0`},f=a.getAttribute(`normal`);f!==void 0&&!this.isNormalizedNormalAttribute(f)&&(console.warn(`THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.`),a.setAttribute(`normal`,this.createNormalizedNormalAttribute(f)));let p=null;for(let e in a.attributes){if(e.slice(0,5)===`morph`)continue;let n=a.attributes[e];if(e=d[e]||e.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(e)&&!e.startsWith(`_`)&&(e=`_`+e),t.attributes.has(this.getUID(n))){c[e]=t.attributes.get(this.getUID(n));continue}p=null;let r=n.array;e===`JOINTS_0`&&!(r instanceof Uint16Array)&&!(r instanceof Uint8Array)?(console.warn(`GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.`),p=qr.Utils.toTypedBufferAttribute(n,Uint16Array)):(r instanceof Uint32Array||r instanceof Int32Array)&&!e.startsWith(`_`)&&(console.warn(`GLTFExporter: Attribute "${e}" converted to type FLOAT.`),p=qr.Utils.toTypedBufferAttribute(n,Float32Array));let i=this.processAccessor(p||n,a);i!==null&&(e.startsWith(`_`)||this.detectMeshQuantization(e,n),c[e]=i,t.attributes.set(this.getUID(n),i))}if(f!==void 0&&a.setAttribute(`normal`,f),Object.keys(c).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){let n=[],r=[],i={};if(e.morphTargetDictionary!==void 0)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o<e.morphTargetInfluences.length;++o){let s={},c=!1;for(let e in a.morphAttributes){if(e!==`position`&&e!==`normal`){c||=(console.warn(`GLTFExporter: Only POSITION and NORMAL morph are supported.`),!0);continue}let n=a.morphAttributes[e][o],r=e.toUpperCase(),i=a.attributes[e];if(t.attributes.has(this.getUID(n,!0))){s[r]=t.attributes.get(this.getUID(n,!0));continue}let l=n.clone();if(!a.morphTargetsRelative)for(let e=0,t=n.count;e<t;e++)for(let t=0;t<n.itemSize;t++)t===0&&l.setX(e,n.getX(e)-i.getX(e)),t===1&&l.setY(e,n.getY(e)-i.getY(e)),t===2&&l.setZ(e,n.getZ(e)-i.getZ(e)),t===3&&l.setW(e,n.getW(e)-i.getW(e));s[r]=this.processAccessor(l,a),t.attributes.set(this.getUID(i,!0),s[r])}u.push(s),n.push(e.morphTargetInfluences[o]),e.morphTargetDictionary!==void 0&&r.push(i[o])}s.weights=n,r.length>0&&(s.extras={},s.extras.targetNames=r)}let m=Array.isArray(e.material);if(m&&a.groups.length===0)return null;let h=!1;if(m&&a.index===null){let e=[];for(let t=0,n=a.attributes.position.count;t<n;t++)e[t]=t;a.setIndex(e),h=!0}let g=m?e.material:[e.material],_=m?a.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,n=_.length;e<n;e++){let n={mode:o,attributes:c};if(this.serializeUserData(a,n),u.length>0&&(n.targets=u),a.index!==null){let r=this.getUID(a.index);(_[e].start!==void 0||_[e].count!==void 0)&&(r+=`:`+_[e].start+`:`+_[e].count),t.attributes.has(r)?n.indices=t.attributes.get(r):(n.indices=this.processAccessor(a.index,a,_[e].start,_[e].count),t.attributes.set(r,n.indices)),n.indices===null&&delete n.indices}let r=await this.processMaterialAsync(g[_[e].materialIndex]);r!==null&&(n.material=r),l.push(n)}h===!0&&a.setIndex(null),s.primitives=l,n.meshes||=[],await this._invokeAllAsync(function(t){t.writeMesh&&t.writeMesh(e,s)});let v=n.meshes.push(s)-1;return t.meshes.set(i,v),v}detectMeshQuantization(e,t){if(this.extensionsUsed[Jr])return;let n;switch(t.array.constructor){case Int8Array:n=`byte`;break;case Uint8Array:n=`unsigned byte`;break;case Int16Array:n=`short`;break;case Uint16Array:n=`unsigned short`;break;default:return}t.normalized&&(n+=` normalized`);let r=e.split(`_`,1)[0];Kr[r]&&Kr[r].includes(n)&&(this.extensionsUsed[Jr]=!0,this.extensionsRequired[Jr]=!0)}processCamera(e){let n=this.json;n.cameras||=[];let r=e.isOrthographicCamera,i={type:r?`orthographic`:`perspective`};return r?i.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:i.perspective={aspectRatio:e.aspect,yfov:t.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==``&&(i.name=e.type),n.cameras.push(i)-1}processAnimation(e,n){let r=this.json,i=this.nodeMap;r.animations||=[],e=qr.Utils.mergeMorphTargetTracks(e.clone(),n);let a=e.tracks,o=[],s=[];for(let e=0;e<a.length;++e){let r=a[e],c=t.PropertyBinding.parseTrackName(r.name),l=t.PropertyBinding.findNode(n,c.nodeName),u=Yr[c.propertyName];if(c.objectName===`bones`&&(l=l.isSkinnedMesh===!0?l.skeleton.getBoneByName(c.objectIndex):void 0),!l||!u){console.warn(`THREE.GLTFExporter: Could not export animation track "%s".`,r.name);continue}let d=r.values.length/r.times.length;u===Yr.morphTargetInfluences&&(d/=l.morphTargetInfluences.length);let f;r.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(f=`CUBICSPLINE`,d/=3):f=r.getInterpolation()===t.InterpolateDiscrete?`STEP`:`LINEAR`,s.push({input:this.processAccessor(new t.BufferAttribute(r.times,1)),output:this.processAccessor(new t.BufferAttribute(r.values,d)),interpolation:f}),o.push({sampler:s.length-1,target:{node:i.get(l),path:u}})}let c={name:e.name||`clip_`+r.animations.length,samplers:s,channels:o};return this.serializeUserData(e,c),r.animations.push(c),r.animations.length-1}processSkin(e){let n=this.json,r=this.nodeMap,i=n.nodes[r.get(e)],a=e.skeleton;if(a===void 0)return null;let o=e.skeleton.bones[0];if(o===void 0)return null;let s=[],c=new Float32Array(a.bones.length*16),l=new t.Matrix4;for(let t=0;t<a.bones.length;++t)s.push(r.get(a.bones[t])),l.copy(a.boneInverses[t]),l.multiply(e.bindMatrix).toArray(c,t*16);return n.skins===void 0&&(n.skins=[]),n.skins.push({inverseBindMatrices:this.processAccessor(new t.BufferAttribute(c,16)),joints:s,skeleton:r.get(o)}),i.skin=n.skins.length-1}async processNodeAsync(e){let t=this.json,n=this.options,r=this.nodeMap;if(t.nodes||=[],e.pivot!==null)return await this._processNodeWithPivotAsync(e);let i={};if(n.trs){let t=e.quaternion.toArray(),n=e.position.toArray(),r=e.scale.toArray();ri(t,[0,0,0,1])||(i.rotation=t),ri(n,[0,0,0])||(i.translation=n),ri(r,[1,1,1])||(i.scale=r)}else e.matrixAutoUpdate&&e.updateMatrix(),ai(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){let t=await this.processMeshAsync(e);t!==null&&(i.mesh=t)}else e.isCamera&&(i.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let a=t.nodes.push(i)-1;if(r.set(e,a),e.children.length>0){let t=[];for(let r=0,i=e.children.length;r<i;r++){let i=e.children[r];if(i.visible||n.onlyVisible===!1){let e=await this.processNodeAsync(i);e!==null&&t.push(e)}}t.length>0&&(i.children=t)}return await this._invokeAllAsync(function(t){t.writeNode&&t.writeNode(e,i)}),a}async _processNodeWithPivotAsync(e){let t=this.json,n=this.options,r=this.nodeMap,i=e.pivot,a={},o=e.quaternion.toArray(),s=[e.position.x+i.x,e.position.y+i.y,e.position.z+i.z],c=e.scale.toArray();ri(o,[0,0,0,1])||(a.rotation=o),ri(s,[0,0,0])||(a.translation=s),ri(c,[1,1,1])||(a.scale=c),a.extras={pivot:i.toArray()},e.name!==``&&(a.name=String(e.name)),this.serializeUserData(e,a);let l=t.nodes.push(a)-1;r.set(e,l);let u={},d=[-i.x,-i.y,-i.z];if(ri(d,[0,0,0])||(u.translation=d),e.isMesh||e.isLine||e.isPoints){let t=await this.processMeshAsync(e);t!==null&&(u.mesh=t)}else e.isCamera&&(u.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let f=[t.nodes.push(u)-1];if(e.children.length>0){let t=[];for(let r=0,i=e.children.length;r<i;r++){let i=e.children[r];if(i.visible||n.onlyVisible===!1){let e=await this.processNodeAsync(i);e!==null&&t.push(e)}}t.length>0&&(u.children=t)}return a.children=f,await this._invokeAllAsync(function(t){t.writeNode&&t.writeNode(e,a)}),l}async processSceneAsync(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==``&&(r.name=e.name),t.scenes.push(r);let i=[];for(let t=0,r=e.children.length;t<r;t++){let r=e.children[t];if(r.visible||n.onlyVisible===!1){let e=await this.processNodeAsync(r);e!==null&&i.push(e)}}i.length>0&&(r.nodes=i),this.serializeUserData(e,r)}async processObjectsAsync(e){let n=new t.Scene;n.name=`AuxScene`;for(let t=0;t<e.length;t++)n.children.push(e[t]);await this.processSceneAsync(n)}async processInputAsync(e){let n=this.options;e=e instanceof Array?e:[e],await this._invokeAllAsync(function(t){t.beforeParse&&t.beforeParse(e)});let r=[];for(let n=0;n<e.length;n++)e[n]instanceof t.Scene?await this.processSceneAsync(e[n]):r.push(e[n]);r.length>0&&await this.processObjectsAsync(r);for(let e=0;e<this.skins.length;++e)this.processSkin(this.skins[e]);for(let t=0;t<n.animations.length;++t)this.processAnimation(n.animations[t],e[0]);await this._invokeAllAsync(function(t){t.afterParse&&t.afterParse(e)})}async _invokeAllAsync(e){for(let t=0,n=this.plugins.length;t<n;t++)await e(this.plugins[t])}},fi=class{constructor(e){this.writer=e,this.name=`KHR_lights_punctual`}writeNode(e,t){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}let n=this.writer,r=n.json,i=n.extensionsUsed,a={};e.name&&(a.name=e.name),a.color=e.color.toArray(),a.intensity=e.intensity,e.isDirectionalLight?a.type=`directional`:e.isPointLight?(a.type=`point`,e.distance>0&&(a.range=e.distance)):e.isSpotLight&&(a.type=`spot`,e.distance>0&&(a.range=e.distance),a.spot={},a.spot.innerConeAngle=(1-e.penumbra)*e.angle,a.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);let o=r.extensions[this.name].lights;o.push(a),t.extensions=t.extensions||{},t.extensions[this.name]={light:o.length-1}}},pi=class{constructor(e){this.writer=e,this.name=`KHR_materials_unlit`}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},n[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},mi=class{constructor(e){this.writer=e,this.name=`KHR_materials_clearcoat`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){let t={index:await n.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(t,e.clearcoatMap),i.clearcoatTexture=t}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let t={index:await n.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(t,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=t}if(e.clearcoatNormalMap){let t={index:await n.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(t.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},hi=class{constructor(e){this.writer=e,this.name=`KHR_materials_dispersion`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let n=this.writer.extensionsUsed,r={};r.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},gi=class{constructor(e){this.writer=e,this.name=`KHR_materials_iridescence`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){let t={index:await n.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(t,e.iridescenceMap),i.iridescenceTexture=t}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){let t={index:await n.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(t,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},_i=class{constructor(e){this.writer=e,this.name=`KHR_materials_transmission`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){let t={index:await n.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(t,e.transmissionMap),i.transmissionTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},vi=class{constructor(e){this.writer=e,this.name=`KHR_materials_volume`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){let t={index:await n.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(t,e.thicknessMap),i.thicknessTexture=t}e.attenuationDistance!==1/0&&(i.attenuationDistance=e.attenuationDistance),i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},yi=class{constructor(e){this.writer=e,this.name=`KHR_materials_ior`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let n=this.writer.extensionsUsed,r={};r.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},bi=class{constructor(e){this.writer=e,this.name=`KHR_materials_specular`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(Xr)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.specularIntensityMap){let t={index:await n.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(t,e.specularIntensityMap),i.specularTexture=t}if(e.specularColorMap){let t={index:await n.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(t,e.specularColorMap),i.specularColorTexture=t}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},xi=class{constructor(e){this.writer=e,this.name=`KHR_materials_sheen`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.sheenRoughnessMap){let t={index:await n.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(t,e.sheenRoughnessMap),i.sheenRoughnessTexture=t}if(e.sheenColorMap){let t={index:await n.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(t,e.sheenColorMap),i.sheenColorTexture=t}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},Si=class{constructor(e){this.writer=e,this.name=`KHR_materials_anisotropy`}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.anisotropyMap){let t={index:await n.processTextureAsync(e.anisotropyMap)};n.applyTextureTransform(t,e.anisotropyMap),i.anisotropyTexture=t}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},Ci=class{constructor(e){this.writer=e,this.name=`KHR_materials_emissive_strength`}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let n=this.writer.extensionsUsed,r={};r.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},wi=class{constructor(e){this.writer=e,this.name=`EXT_materials_bump`}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.bumpMap){let t={index:await n.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(t,e.bumpMap),i.bumpTexture=t}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},Ti=class{constructor(e){this.writer=e,this.name=`EXT_mesh_gpu_instancing`}writeNode(e,n){if(!e.isInstancedMesh)return;let r=this.writer,i=e,a=new Float32Array(i.count*3),o=new Float32Array(i.count*4),s=new Float32Array(i.count*3),c=new t.Matrix4,l=new t.Vector3,u=new t.Quaternion,d=new t.Vector3;for(let e=0;e<i.count;e++)i.getMatrixAt(e,c),c.decompose(l,u,d),l.toArray(a,e*3),u.toArray(o,e*4),d.toArray(s,e*3);let f={TRANSLATION:r.processAccessor(new t.BufferAttribute(a,3)),ROTATION:r.processAccessor(new t.BufferAttribute(o,4)),SCALE:r.processAccessor(new t.BufferAttribute(s,3))};i.instanceColor&&(f._COLOR_0=r.processAccessor(i.instanceColor)),n.extensions=n.extensions||{},n.extensions[this.name]={attributes:f},r.extensionsUsed[this.name]=!0,r.extensionsRequired[this.name]=!0}};qr.Utils={insertKeyframe:function(e,t){let n=.001,r=e.getValueSize(),i=new e.TimeBufferType(e.times.length+1),a=new e.ValueBufferType(e.values.length+r),o=e.createInterpolant(new e.ValueBufferType(r)),s;if(e.times.length===0){i[0]=t;for(let e=0;e<r;e++)a[e]=0;s=0}else if(t<e.times[0]){if(Math.abs(e.times[0]-t)<n)return 0;i[0]=t,i.set(e.times,1),a.set(o.evaluate(t),0),a.set(e.values,r),s=0}else if(t>e.times[e.times.length-1]){if(Math.abs(e.times[e.times.length-1]-t)<n)return e.times.length-1;i[i.length-1]=t,i.set(e.times,0),a.set(e.values,0),a.set(o.evaluate(t),e.values.length),s=i.length-1}else for(let c=0;c<e.times.length;c++){if(Math.abs(e.times[c]-t)<n)return c;if(e.times[c]<t&&e.times[c+1]>t){i.set(e.times.slice(0,c+1),0),i[c+1]=t,i.set(e.times.slice(c+1),c+2),a.set(e.values.slice(0,(c+1)*r),0),a.set(o.evaluate(t),(c+1)*r),a.set(e.values.slice((c+1)*r),(c+2)*r),s=c+1;break}}return e.times=i,e.values=a,s},mergeMorphTargetTracks:function(e,n){let r=[],i={},a=e.tracks;for(let e=0;e<a.length;++e){let o=a[e],s=t.PropertyBinding.parseTrackName(o.name),c=t.PropertyBinding.findNode(n,s.nodeName);if(s.propertyName!==`morphTargetInfluences`||s.propertyIndex===void 0){r.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw 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(t.InterpolateLinear)}let l=c.morphTargetInfluences.length,u=c.morphTargetDictionary[s.propertyIndex];if(u===void 0)throw Error(`THREE.GLTFExporter: Morph target name not found: `+s.propertyIndex);let d;if(i[c.uuid]===void 0){d=o.clone();let e=new d.ValueBufferType(l*d.times.length);for(let t=0;t<d.times.length;t++)e[t*l+u]=d.values[t];d.name=(s.nodeName||``)+`.morphTargetInfluences`,d.values=e,i[c.uuid]=d,r.push(d);continue}let f=o.createInterpolant(new o.ValueBufferType(1));d=i[c.uuid];for(let e=0;e<d.times.length;e++)d.values[e*l+u]=f.evaluate(d.times[e]);for(let e=0;e<o.times.length;e++){let t=this.insertKeyframe(d,o.times[e]);d.values[t*l+u]=o.values[e]}}return e.tracks=r,e},toTypedBufferAttribute:function(e,n){let r=new t.BufferAttribute(new n(e.count*e.itemSize),e.itemSize,!1);if(!e.normalized&&!e.isInterleavedBufferAttribute)return r.array.set(e.array),r;for(let t=0,n=e.count;t<n;t++)for(let n=0;n<e.itemSize;n++)r.setComponent(t,n,e.getComponent(t,n));return r}};var Ei=class{constructor(){this.io=new wt().registerExtensions(Gr),this.threeExporter=new qr}onProgress(e){this.progressCallback=e}async exportDocumentGLB(e){let t=Date.now();this.emitProgress(`Exporting to GLB format`,0);try{this.emitProgress(`Serializing document`,50);let n=await this.io.writeBinary(e);this.emitProgress(`Finalizing export`,90);let r=n,i=Date.now()-t;return this.emitProgress(`Export completed`,100),{data:r,format:`glb`,size:r.byteLength,exportTime:i}}catch(e){throw Error(`Failed to export GLB: ${e}`,{cause:e})}}async exportDocumentGLTF(e){let t=Date.now();this.emitProgress(`Exporting to GLTF format`,0);try{this.emitProgress(`Serializing document`,25);let n=await this.io.writeJSON(e);this.emitProgress(`Processing assets`,75);let r=new Map;n.resources&&Object.entries(n.resources).forEach(([e,t])=>{e!==`model.gltf`&&(console.log(`Adding asset:`,e),r.set(e,t))});let i=new TextEncoder().encode(JSON.stringify(n.json)).byteLength,a=Array.from(r.values()).reduce((e,t)=>e+t.byteLength,0),o=Date.now()-t;return this.emitProgress(`Export completed`,100),{data:n.json,format:`gltf`,size:i+a,exportTime:o,assets:r}}catch(e){throw Error(`Failed to export GLTF: ${e}`,{cause:e})}}async exportThreeJSGLB(e,t){let n=Date.now();this.emitProgress(`Exporting Three.js object to GLB`,0);try{this.emitProgress(`Serializing Three.js scene`,40);let r=await this.threeExporter.parseAsync(e,{binary:!0});if(!(r instanceof ArrayBuffer))throw Error(`Expected binary GLB output from GLTFExporter`);this.emitProgress(`Finalizing GLB binary`,90);let i=new Uint8Array(r),a=Date.now()-n;return this.emitProgress(`Export completed`,100),t.modifiedTextureResources&&console.warn(`modifiedTextureResources is ignored for direct Three.js GLB export`),{data:i,format:`glb`,size:i.byteLength,exportTime:a}}catch(e){throw Error(`Failed to export Three.js object: ${e}`,{cause:e})}}async exportThreeJSGLTF(e){this.emitProgress(`Exporting Three.js object to GLTF`,0);try{let t=await this.threeExporter.parseAsync(e,{binary:!0});return await this.exportDocumentGLTF(await this.io.readBinary(new Uint8Array(t)))}catch(e){throw Error(`Failed to export Three.js object: ${e}`,{cause:e})}}async createZIPArchive(e,t=`model`){if(e.format!==`gltf`)throw Error(`ZIP archive can only be created from GLTF exports`);this.emitProgress(`Creating ZIP archive`,0);let r=new n.default;if(r.file(`${t}.gltf`,JSON.stringify(e.data,null,2)),e.assets){let t=0,n=e.assets.size;e.assets.forEach((e,i)=>{r.file(i,e),t++,this.emitProgress(`Adding assets to ZIP`,Math.round(t/n*80)+10)})}this.emitProgress(`Generating ZIP file`,90);let i=await r.generateAsync({type:`uint8array`});return this.emitProgress(`ZIP archive created`,100),i}async saveToFile(t,n){try{let r=await Promise.resolve().then(()=>require(`./__vite-browser-external-CVmj8TrW.cjs`)).then(t=>e.a(t.t(),1)),i=await Promise.resolve().then(()=>require(`./__vite-browser-external-CVmj8TrW.cjs`)).then(t=>e.a(t.t(),1));if(this.emitProgress(`Saving to file system`,0),t.format===`glb`)await r.writeFile(n,t.data);else{let e=i.dirname(n),a=i.basename(n,i.extname(n));if(await r.mkdir(e,{recursive:!0}),await r.writeFile(i.join(e,`${a}.gltf`),JSON.stringify(t.data,null,2)),t.assets){let n=0,a=t.assets.size;for(let[o,s]of t.assets)await r.writeFile(i.join(e,o),s),n++,this.emitProgress(`Saving assets`,Math.round(n/a*100))}}this.emitProgress(`File saved successfully`,100)}catch(e){throw Error(`Failed to save file: ${e}`,{cause:e})}}emitProgress(e,t,n){this.progressCallback&&this.progressCallback({operation:e,progress:t,details:n})}};Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return wt}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return Je}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return Ot}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Pr}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return qr}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Ei}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return Ye}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return Xe}});