Socket
Socket
Sign inDemoInstall

@gltf-transform/core

Package Overview
Dependencies
Maintainers
1
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/core - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

2

dist/core.modern.js

@@ -1,2 +0,2 @@

import{fromRotationTranslationScale as t,getTranslation as s,getRotation as e,getScaling as r,multiply as i}from"gl-matrix/mat4";const n="@glb.bin";var h;function o(t,s,e,r){var i,n=arguments.length,h=n<3?s:null===r?r=Object.getOwnPropertyDescriptor(s,e):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,s,e,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(s,e,h):i(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h}!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo"}(h||(h={}));class u{constructor(t,s,e){if(this.t=t,this.s=s,this.i=e,this.h=!1,this.o=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class c{constructor(){this.u=new Set,this.l=new Map,this.p=new Map}getLinks(){return Array.from(this.u)}listParents(t){return(this.p.get(t)||[]).map(t=>t.getParent())}listChildren(t){return(this.l.get(t)||[]).map(t=>t.getChild())}disconnectChildren(t){return(this.l.get(t)||[]).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=this.p.get(t)||[];return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}link(t,s,e){if(!e)return null;const r=new u(t,s,e);return this.registerLink(r),r}registerLink(t){this.u.add(t);const s=t.getParent();this.l.has(s)||this.l.set(s,[]),this.l.get(s).push(t);const e=t.getChild();return this.p.has(e)||this.p.set(e,[]),this.p.get(e).push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){this.u.delete(t);const s=this.l.get(t.getParent()).filter(s=>t!==s);this.l.set(t.getParent(),s);const e=this.p.get(t.getChild()).filter(s=>t!==s);return this.p.set(t.getChild(),e),this}}function a(t,s){Object.defineProperty(t,s,{get:function(){return this["__"+s]},set:function(t){const e=this["__"+s];e&&!Array.isArray(e)&&e.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+s]=null}),this["__"+s]=t},enumerable:!0})}function l(t,s){}class f{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const s=atob(t.split(",")[1]),e=new Uint8Array(s.length);for(let t=0;t<s.length;t++)e[t]=s.charCodeAt(t);return e.buffer}{const s=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(s,e?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:s,byteLength:e}=t;return t.buffer.slice(s,s+e)}static concat(t){let s=0;for(const e of t)s+=e.byteLength;const e=new Uint8Array(s);let r=0;for(const s of t)e.set(new Uint8Array(s),r),r+=s.byteLength;return e.buffer}static pad(t,s=0){const e=this.padNumber(t.byteLength);if(e!==t.byteLength){const r=new Uint8Array(e);if(r.set(new Uint8Array(t)),0!==s)for(let i=t.byteLength;i<e;i++)r[i]=s;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,s){if(t===s)return!0;if(t.byteLength!==s.byteLength)return!1;const e=new DataView(t),r=new DataView(s);let i=t.byteLength;for(;i--;)if(e.getUint8(i)!==r.getUint8(i))return!1;return!0}}class d{static hexToFactor(t,s){return t=Math.floor(t),s[0]=(t>>16&255)/255,s[1]=(t>>8&255)/255,s[2]=(255&t)/255,this.convertSRGBToLinear(s,s)}static factorToHex(t){const s=[...t],[e,r,i]=this.convertLinearToSRGB(t,s);return 255*e<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(t,s){for(let e=0;e<3;e++)s[e]=t[e]<.04045?.0773993808*t[e]:Math.pow(.9478672986*t[e]+.0521327014,2.4);return s}static convertLinearToSRGB(t,s){for(let e=0;e<3;e++)s[e]=t[e]<.0031308?12.92*t[e]:1.055*Math.pow(t[e],.41666)-.055;return s}}class p{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class g{static getSizeJPEG(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),w(r,s),e=r.getUint8(s+1),192===e||193===e||194===e)return[r.getUint16(s+7,!1),r.getUint16(s+5,!1)];r=new DataView(t,r.byteOffset+s+2)}throw new TypeError("Invalid JPG, no size found")}static getSizePNG(t){const s=new DataView(t);return"CgBI"===f.decodeText(t.slice(12,16))?[s.getUint32(32,!1),s.getUint32(36,!1)]:[s.getUint32(16,!1),s.getUint32(20,!1)]}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":"image/"+t}}function w(t,s){if(s>t.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t.getUint8(s))throw new TypeError("Invalid JPG, marker table corrupted")}class m{static identity(t){return t}static denormalize(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}static normalize(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}}class v{constructor(t){this.verbosity=t}debug(t){this.verbosity<=v.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=v.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=v.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=v.Verbosity.ERROR&&console.error(t)}}v.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0},v.DEFAULT_INSTANCE=new v(v.Verbosity.INFO);const x="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",y=new Set,T=function(){let t="";for(let s=0;s<6;s++)t+=x.charAt(Math.floor(Math.random()*x.length));return t},A=function(){for(let t=0;t<999;t++){const t=T();if(!y.has(t))return y.add(t),t}},E=t=>t;class b extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.getLinks().filter(s=>s.getParent()===this&&s.getChild()===t).forEach(t=>t.setChild(s)),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0,t.push(...e)}),this}removeGraphChild(t,s){return t.filter(t=>t.getChild()===s).forEach(t=>t.dispose()),this}clearGraphChildList(t){for(;t.length>0;)t[0].dispose();return this}listGraphParents(){return this.graph.listParents(this)}}{constructor(t,s=""){super(t),this.g={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.g}setExtras(t){return this.g=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,E)}copy(t,s){return this.t=t.t,this.g=JSON.parse(JSON.stringify(t.g)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}const M="Pass extension name (string) as lookup token, not a constructor.";class S extends b{constructor(){super(...arguments),this.extensions=[]}copy(t,s=E){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.extensionName,s(e))}),this}getExtension(t){if("string"!=typeof t)throw new Error(M);const s=this.extensions.find(s=>s.getChild().extensionName===t);return s?s.getChild():null}setExtension(t,s){if("string"!=typeof t)throw new Error(M);const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.m(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}o([l],S.prototype,"extensions",void 0);class I extends S{constructor(){super(...arguments),this.propertyType=h.ACCESSOR,this.v=null,this.T="SCALAR",this.A=null,this.M=!1,this.S=m.identity,this.I=m.identity,this.buffer=null}copy(t,s=E){return super.copy(t,s),this.v=t.v.slice(),this.T=t.T,this.A=t.A,this.M=t.M,this.S=t.S,this.I=t.I,t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}}getMinNormalized(t){const s=this.getElementSize();this.getMin(t);for(let e=0;e<s;e++)t[e]=this.I(t[e]);return t}getMin(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.v[r+s];Number.isFinite(e)&&(t[s]=Math.min(t[s],e))}return t}getMaxNormalized(t){const s=this.getElementSize();this.getMax(t);for(let e=0;e<s;e++)t[e]=this.I(t[e]);return t}getMax(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=-Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.v[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.v.length/this.getElementSize()}getType(){return this.T}setType(t){return this.T=t,this}getElementSize(){return I.getElementSize(this.T)}getComponentSize(){return this.v.BYTES_PER_ELEMENT}getComponentType(){return this.A}getNormalized(){return this.M}setNormalized(t){return this.M=t,t?(this.I=t=>m.denormalize(t,this.A),this.S=t=>m.normalize(t,this.A)):(this.I=m.identity,this.S=m.identity),this}getScalar(t){const s=this.getElementSize();return this.I(this.v[t*s])}setScalar(t,s){return this.v[t*this.getElementSize()]=this.S(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.I(this.v[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.v[t*e+r]=this.S(s[r]);return this}getBuffer(){return this.buffer?this.buffer.getChild():null}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.v}setArray(t){return this.A=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.v=t,this}getByteLength(){return this.v.byteLength}}I.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},I.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},o([a],I.prototype,"buffer",void 0);class R extends S{constructor(){super(...arguments),this.propertyType=h.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=E){return super.copy(t,s),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),t.channels.forEach(t=>this.addChannel(s(t.getChild()))),t.samplers.forEach(t=>this.addSampler(s(t.getChild()))),this}addChannel(t){const s=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,s)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const s=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,s)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}o([l],R.prototype,"channels",void 0),o([l],R.prototype,"samplers",void 0);class N extends b{constructor(){super(...arguments),this.propertyType=h.ANIMATION_CHANNEL,this.R=null,this.targetNode=null,this.sampler=null}copy(t,s=E){return super.copy(t,s),this.R=t.R,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.R}setTargetPath(t){return this.R=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}o([a],N.prototype,"targetNode",void 0),o([a],N.prototype,"sampler",void 0);class C extends b{constructor(){super(...arguments),this.propertyType=h.ANIMATION_SAMPLER,this.N="LINEAR",this.input=null,this.output=null}copy(t,s=E){return super.copy(t,s),this.N=t.N,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}o([a],C.prototype,"input",void 0),o([a],C.prototype,"output",void 0);class _ extends S{constructor(){super(...arguments),this.propertyType=h.BUFFER}copy(t,s=E){return super.copy(t,s),this.C=t.C,this}getURI(){return this.C}setURI(t){return this.C=t,this}}class B extends S{constructor(){super(...arguments),this.propertyType=h.CAMERA,this.T="perspective"}copy(t,s=E){return super.copy(t,s),this.T=t.T,this._=t._,this.B=t.B,this.L=t.L,this.O=t.O,this.U=t.U,this.k=t.k,this}getType(){return this.T}setType(t){return this.T=t,this}getZNear(){return this._}setZNear(t){return this._=t,this}getZFar(){return this.B}setZFar(t){return this.B=t,this}getAspectRatio(){return this.L}setAspectRatio(t){return this.L=t,this}getYFov(){return this.O}setYFov(t){return this.O=t,this}getXMag(){return this.U}setXMag(t){return this.U=t,this}getYMag(){return this.k}setYMag(t){return this.k=t,this}}class L extends b{constructor(t,s){super(t),this.P=s,this.P.addExtensionProperty(this)}dispose(){this.P.removeExtensionProperty(this),super.dispose()}m(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class O extends u{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class U extends u{copy(t){return this}}class k extends c{linkAttribute(t,s,e){if(!e)return null;const r=new O(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new U(t,s,e);return this.registerLink(r),r}}class P extends S{constructor(){super(...arguments),this.propertyType=h.TEXTURE_INFO,this.F=0,this.G=null,this.j=null,this.D=10497,this.J=10497}copy(t,s=E){return super.copy(t,s),this.F=t.F,this.G=t.G,this.j=t.j,this.D=t.D,this.J=t.J,this}getTexCoord(){return this.F}setTexCoord(t){return this.F=t,this}getMagFilter(){return this.G}setMagFilter(t){return this.G=t,this}getMinFilter(){return this.j}setMinFilter(t){return this.j=t,this}getWrapS(){return this.D}setWrapS(t){return this.D=t,this}getWrapT(){return this.J}setWrapT(t){return this.J=t,this}}P.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},P.TextureMagFilter={NEAREST:9728,LINEAR:9729},P.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class F extends S{constructor(){super(...arguments),this.propertyType=h.MATERIAL,this.$="OPAQUE",this.V=.5,this.W=!1,this.q=[1,1,1,1],this.H=[0,0,0],this.Y=1,this.Z=1,this.X=1,this.K=1,this.baseColorTexture=null,this.baseColorTextureInfo=this.graph.link("baseColorTextureInfo",this,new P(this.graph)),this.emissiveTexture=null,this.emissiveTextureInfo=this.graph.link("emissiveTextureInfo",this,new P(this.graph)),this.normalTexture=null,this.normalTextureInfo=this.graph.link("normalTextureInfo",this,new P(this.graph)),this.occlusionTexture=null,this.occlusionTextureInfo=this.graph.link("occlusionTextureInfo",this,new P(this.graph)),this.metallicRoughnessTexture=null,this.metallicRoughnessTextureInfo=this.graph.link("metallicRoughnessTextureInfo",this,new P(this.graph))}copy(t,s=E){return super.copy(t,s),this.$=t.$,this.V=t.V,this.W=t.W,this.q=[...t.q],this.H=[...t.H],this.Y=t.Y,this.Z=t.Z,this.X=t.X,this.K=t.K,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()),s)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()),s)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()),s)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()),s)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()),s)),this}dispose(){this.baseColorTextureInfo.getChild().dispose(),this.emissiveTextureInfo.getChild().dispose(),this.normalTextureInfo.getChild().dispose(),this.occlusionTextureInfo.getChild().dispose(),this.metallicRoughnessTextureInfo.getChild().dispose(),super.dispose()}getDoubleSided(){return this.W}setDoubleSided(t){return this.W=t,this}getAlpha(){return this.q[3]}setAlpha(t){return this.q[3]=t,this}getAlphaMode(){return this.$}setAlphaMode(t){return this.$=t,this}getAlphaCutoff(){return this.V}setAlphaCutoff(t){return this.V=t,this}getBaseColorFactor(){return this.q}setBaseColorFactor(t){return this.q=t,this}getBaseColorHex(){return d.factorToHex(this.q)}setBaseColorHex(t){return d.hexToFactor(t,this.q),this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTextureInfo.getChild():null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.link("baseColorTexture",this,t),this}getEmissiveFactor(){return this.H}setEmissiveFactor(t){return this.H=t,this}getEmissiveHex(){return d.factorToHex(this.H)}setEmissiveHex(t){return d.hexToFactor(t,this.H),this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTextureInfo.getChild():null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.link("emissiveTexture",this,t),this}getNormalScale(){return this.Y}setNormalScale(t){return this.Y=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTextureInfo.getChild():null}setNormalTexture(t){return this.normalTexture=this.graph.link("normalTexture",this,t),this}getOcclusionStrength(){return this.Z}setOcclusionStrength(t){return this.Z=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTextureInfo.getChild():null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.link("occlusionTexture",this,t),this}getRoughnessFactor(){return this.X}setRoughnessFactor(t){return this.X=t,this}getMetallicFactor(){return this.K}setMetallicFactor(t){return this.K=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTextureInfo.getChild():null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.link("metallicRoughnessTexture",this,t),this}}o([a],F.prototype,"baseColorTexture",void 0),o([a],F.prototype,"baseColorTextureInfo",void 0),o([a],F.prototype,"emissiveTexture",void 0),o([a],F.prototype,"emissiveTextureInfo",void 0),o([a],F.prototype,"normalTexture",void 0),o([a],F.prototype,"normalTextureInfo",void 0),o([a],F.prototype,"occlusionTexture",void 0),o([a],F.prototype,"occlusionTextureInfo",void 0),o([a],F.prototype,"metallicRoughnessTexture",void 0),o([a],F.prototype,"metallicRoughnessTextureInfo",void 0);class G extends S{constructor(){super(...arguments),this.propertyType=h.MESH,this.tt=[],this.primitives=[]}copy(t,s=E){return super.copy(t,s),this.tt=[...t.tt],this.clearGraphChildList(this.primitives),t.primitives.forEach(t=>this.addPrimitive(s(t.getChild()))),this}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.tt}setWeights(t){return this.tt=t,this}}o([l],G.prototype,"primitives",void 0);class j extends S{constructor(){super(...arguments),this.propertyType=h.NODE,this.st=[0,0,0],this.et=[0,0,0,1],this.rt=[1,1,1],this.tt=[],this.s=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=E){return super.copy(t,s),this.st=[...t.st],this.et=[...t.et],this.rt=[...t.rt],this.tt=[...t.tt],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),s!==E&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}getTranslation(){return this.st}getRotation(){return this.et}getScale(){return this.rt}setTranslation(t){return this.st=t,this}setRotation(t){return this.et=t,this}setScale(t){return this.rt=t,this}getMatrix(){return t([],this.et,this.st,this.rt)}getWorldTranslation(){return s([],this.getWorldMatrix())}getWorldRotation(){return e([],this.getWorldMatrix())}getWorldScale(){return r([],this.getWorldMatrix())}getWorldMatrix(){const t=[];for(let s=this;s instanceof j;s=s.s)t.push(s);let s;const e=t.pop().getMatrix();for(;s=t.pop();)i(e,e,s.getMatrix());return e}addChild(t){t.s&&t.s.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.s=this,s.onDispose(()=>t.s=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getParent(){return this.s}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.tt}setWeights(t){return this.tt=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}o([a],j.prototype,"camera",void 0),o([a],j.prototype,"mesh",void 0),o([a],j.prototype,"skin",void 0),o([l],j.prototype,"children",void 0);class D extends b{constructor(){super(...arguments),this.propertyType=h.PRIMITIVE,this.it=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=E){return super.copy(t,s),this.it=t.it,t.indices&&this.setIndices(s(t.indices.getChild())),t.material&&this.setMaterial(s(t.material.getChild())),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this.clearGraphChildList(this.targets),t.targets.forEach(t=>this.addTarget(s(t.getChild()))),this}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.graph.linkIndex("index",this,t),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}getMaterial(){return this.material?this.material.getChild():null}setMaterial(t){return this.material=this.graph.link("material",this,t),this}getMode(){return this.it}setMode(t){return this.it=t,this}listTargets(){return this.targets.map(t=>t.getChild())}addTarget(t){return this.addGraphChild(this.targets,this.graph.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}o([a],D.prototype,"material",void 0),o([a],D.prototype,"indices",void 0),o([l],D.prototype,"attributes",void 0),o([l],D.prototype,"targets",void 0);class J extends b{constructor(){super(...arguments),this.propertyType=h.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=E){return super.copy(t,s),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}}o([l],J.prototype,"attributes",void 0);class $ extends b{constructor(){super(...arguments),this.propertyType=h.ROOT,this.nt={generator:"glTF-Transform v0.7.2",version:"2.0"},this.ht=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[]}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=E){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.nt,t.nt),t.accessors.forEach(t=>this.ot(s(t.getChild()))),t.animations.forEach(t=>this.ut(s(t.getChild()))),t.buffers.forEach(t=>this.ct(s(t.getChild()))),t.cameras.forEach(t=>this.at(s(t.getChild()))),t.materials.forEach(t=>this.lt(s(t.getChild()))),t.meshes.forEach(t=>this.ft(s(t.getChild()))),t.nodes.forEach(t=>this.dt(s(t.getChild()))),t.scenes.forEach(t=>this.pt(s(t.getChild()))),t.skins.forEach(t=>this.gt(s(t.getChild()))),t.textures.forEach(t=>this.wt(s(t.getChild()))),this}getAsset(){return this.nt}listExtensionsUsed(){return Array.from(this.ht)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}vt(t){if(this.ht.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.ht.add(t),this}xt(t){return this.ht.delete(t),this}pt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}gt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}wt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}o([l],$.prototype,"accessors",void 0),o([l],$.prototype,"animations",void 0),o([l],$.prototype,"buffers",void 0),o([l],$.prototype,"cameras",void 0),o([l],$.prototype,"materials",void 0),o([l],$.prototype,"meshes",void 0),o([l],$.prototype,"nodes",void 0),o([l],$.prototype,"scenes",void 0),o([l],$.prototype,"skins",void 0),o([l],$.prototype,"textures",void 0);class z extends S{constructor(){super(...arguments),this.propertyType=h.SCENE,this.children=[]}copy(t,s=E){return super.copy(t,s),s!==E&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}addChild(t){t.s&&t.s.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.s=this,s.onDispose(()=>t.s=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}traverse(t){for(const s of this.listChildren())s.traverse(t);return this}}o([l],z.prototype,"children",void 0);class V extends S{constructor(){super(...arguments),this.propertyType=h.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=E){return super.copy(t,s),t.skeleton&&this.setSkeleton(s(t.skeleton.getChild())),t.inverseBindMatrices&&this.setInverseBindMatrices(s(t.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),t.joints.forEach(t=>this.addJoint(s(t.getChild()))),this}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const s=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,s)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}o([a],V.prototype,"skeleton",void 0),o([a],V.prototype,"inverseBindMatrices",void 0),o([l],V.prototype,"joints",void 0);class W extends S{constructor(){super(...arguments),this.propertyType=h.TEXTURE,this.yt=null,this.Tt="",this.C=""}copy(t,s=E){return super.copy(t,s),this.Tt=t.Tt,this.C=t.C,t.yt&&(this.yt=t.yt.slice(0)),this}getMimeType(){return this.Tt}setMimeType(t){return this.Tt=t,this}getURI(){return this.C}setURI(t){return this.C=t,this}getImage(){return this.yt}setImage(t){return this.yt=t,this}getSize(){let t;return t=this.Tt?"image/png"===this.Tt:this.C.match(/\.png$/),t?g.getSizePNG(this.yt):g.getSizeJPEG(this.yt)}}class q{constructor(){this.At=new k,this.Et=new $(this.At),this.bt=v.DEFAULT_INSTANCE}getRoot(){return this.Et}getGraph(){return this.At}getLogger(){return this.bt}setLogger(t){return this.bt=t,this}clone(){return(new q).merge(this)}merge(t){const s={};for(const e of t.getRoot().listExtensionsUsed()){const t=this.createExtension(e.constructor);e.isRequired()&&t.setRequired(!0),s[t.extensionName]=t}const e=new Set,r=new Map;e.add(t.Et),r.set(t.Et,this.Et);for(const i of t.At.getLinks())for(const t of[i.getParent(),i.getChild()]){if(e.has(t))continue;let i;if(t.propertyType===h.TEXTURE_INFO)i=t;else{const e=t.constructor;i=t instanceof L?new e(this.At,s[t.extensionName]):new e(this.At)}r.set(t,i),e.add(t)}const i=t=>r.get(t);for(const t of e)r.get(t).copy(t,i);return this}async transform(...t){for(const s of t)await s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t=""){const s=new z(this.At,t);return this.Et.pt(s),s}createNode(t=""){const s=new j(this.At,t);return this.Et.dt(s),s}createCamera(t=""){const s=new B(this.At,t);return this.Et.at(s),s}createSkin(t=""){const s=new V(this.At,t);return this.Et.gt(s),s}createMesh(t=""){const s=new G(this.At,t);return this.Et.ft(s),s}createPrimitive(){return new D(this.At)}createPrimitiveTarget(t=""){return new J(this.At,t)}createMaterial(t=""){const s=new F(this.At,t);return this.Et.lt(s),s}createTexture(t=""){const s=new W(this.At,t);return this.Et.wt(s),s}createAnimation(t=""){const s=new R(this.At,t);return this.Et.ut(s),s}createAnimationChannel(t=""){return new N(this.At,t)}createAnimationSampler(t=""){return new C(this.At,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new I(this.At,t).setBuffer(s);return this.Et.ot(e),e}createBuffer(t=""){const s=new _(this.At,t);return this.Et.ct(s),s}}class H{constructor(t){this.doc=t,this.provideTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().vt(this)}dispose(){this.doc.getRoot().xt(this);for(const t of this.properties)t.dispose()}isRequired(){return this.required}setRequired(t){return this.required=t,this}addExtensionProperty(t){return this.properties.add(t),this}removeExtensionProperty(t){return this.properties.delete(t),this}install(t,s){return this}provide(t,s){return this}}class Y{constructor(t){this.jsonDoc=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){this.textureInfos.set(t,s),void 0!==s.texCoord&&t.setTexCoord(s.texCoord);const e=this.jsonDoc.json.textures[s.index];if(void 0===e.sampler)return;const r=this.jsonDoc.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const Z={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},X={logger:v.DEFAULT_INSTANCE,extensions:[],dependencies:{}};class K{static read(t,i=X){const{json:n}=t,o=new q;this.validate(t,i);const u=new Y(t),c=t.json.asset,a=o.getRoot().getAsset();c.copyright&&(a.copyright=c.copyright),c.extras&&(a.extras=c.extras),c.generator&&(a.generator=c.generator),c.minVersion&&(a.minVersion=c.minVersion);const l=n.extensionsUsed||[],f=n.extensionsRequired||[];for(const t of i.extensions)if(l.includes(t.EXTENSION_NAME)){const s=o.createExtension(t).setRequired(f.includes(t.EXTENSION_NAME));for(const t of s.dependencies)s.install(t,i.dependencies[t])}u.buffers=(n.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.extras&&s.setExtras(t.extras),t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(n.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(n.accessors||[]).map(s=>{const e=o.createAccessor(s.name,u.bufferViewBuffers[s.bufferView]).setType(s.type);if(s.extras&&e.setExtras(s.extras),void 0!==s.normalized&&e.setNormalized(s.normalized),void 0===s.bufferView&&!s.sparse)return e;let r;return r=void 0!==s.sparse?function(t,s){const e=Z[t.componentType],r=I.getElementSize(t.type);let i;i=void 0!==t.bufferView?Q(t,s).slice():new e(t.count*r);const n=t.sparse.count,h={...t,...t.sparse.indices,count:n,type:"SCALAR"},o={...t,...t.sparse.values,count:n},u=Q(h,s),c=Q(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(s,t):Q(s,t).slice(),e.setArray(r),e});const d=n.images||[],w=n.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(h.TEXTURE)).forEach(t=>t.provide(u,h.TEXTURE)),u.textures=d.map(s=>{const e=o.createTexture(s.name);if(s.extras&&e.setExtras(s.extras),void 0!==s.bufferView){const r=n.bufferViews[s.bufferView],i=t.json.buffers[r.buffer],h=r.byteOffset||0,o=(i.uri?t.resources[i.uri]:t.resources["@glb.bin"]).slice(h,h+r.byteLength);e.setImage(o)}else void 0!==s.uri&&(e.setImage(t.resources[s.uri]),0!==s.uri.indexOf("__")&&e.setURI(s.uri));if(void 0!==s.mimeType)e.setMimeType(s.mimeType);else if(s.uri){const t=p.extension(s.uri);e.setMimeType(g.extensionToMimeType(t))}return e}),u.materials=(n.materials||[]).map(t=>{const s=o.createMaterial(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[w[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[w[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[w[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[w[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[w[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t)}return s});const m=n.meshes||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(h.PRIMITIVE)).forEach(t=>t.provide(u,h.PRIMITIVE)),u.meshes=m.map(t=>{const s=o.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();e.extras&&r.setExtras(e.extras),void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(n.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return t.extras&&s.setExtras(t.extras),"perspective"===t.type?s.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):s.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),s});const v=n.nodes||[];return u.nodes=v.map(t=>{const i=o.createNode(t.name);return t.extras&&i.setExtras(t.extras),void 0!==t.translation&&i.setTranslation(t.translation),void 0!==t.rotation&&i.setRotation(t.rotation),void 0!==t.scale&&i.setScale(t.scale),void 0!==t.matrix&&(i.setTranslation(s([],t.matrix)),i.setRotation(e([],t.matrix)),i.setScale(r([],t.matrix))),void 0!==t.weights&&i.setWeights(t.weights),i}),u.skins=(n.skins||[]).map(t=>{const s=o.createSkin(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(u.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(u.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(u.nodes[e]);return s}),v.map((t,s)=>{const e=u.nodes[s];(t.children||[]).forEach(t=>e.addChild(u.nodes[t])),void 0!==t.mesh&&e.setMesh(u.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(u.cameras[t.camera]),void 0!==t.skin&&e.setSkin(u.skins[t.skin])}),u.animations=(n.animations||[]).map(t=>{const s=o.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return t.extras&&e.setExtras(t.extras),s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);t.extras&&r.setExtras(t.extras),s.addChannel(r)}),s}),u.scenes=(n.scenes||[]).map(t=>{const s=o.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addChild(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}static validate(t,s){const e=t.json;if("2.0"!==e.asset.version)throw new Error(`Unsupported glTF version, "${e.asset.version}".`);if(e.extensionsRequired)for(const t of e.extensionsRequired)if(!s.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);if(e.extensionsUsed)for(const t of e.extensionsUsed)s.extensions.find(s=>s.EXTENSION_NAME===t)||s.logger.warn(`Missing optional extension, "${t}".`)}}function Q(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=Z[t.componentType],h=I.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=Z[t.componentType],h=I.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case 5126:i=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[s*h+e]=i}return c}(t,s);const o=(e.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class tt{constructor(t,s){this.jsonDoc=t,this.options=s,this.accessorIndexMap=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.imageData=[]}createTextureInfoDef(t,s){const e={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},r=JSON.stringify(e);this.samplerDefIndexMap.has(r)||(this.samplerDefIndexMap.set(r,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(e));const i={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(r)},n=JSON.stringify(i);this.textureDefIndexMap.has(n)||(this.textureDefIndexMap.set(n,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(i));const h={index:this.textureDefIndexMap.get(n),texCoord:s.getTexCoord()};return this.textureInfoDefMap.set(s,h),h}createPropertyDef(t){const s={};return t.getName()&&(s.name=t.getName()),Object.keys(t.getExtras()).length>0&&(s.extras=t.getExtras()),s}createAccessorDef(t){const s=this.createPropertyDef(t);return s.type=t.getType(),s.componentType=t.getComponentType(),s.count=t.getCount(),t.getMax(s.max=[]),t.getMin(s.min=[]),s.normalized=t.getNormalized(),s}createImageData(t,s,e){if(this.options.isGLB)this.imageData.push(s),t.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=g.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.jsonDoc.resources[t.uri]=s}}}class st{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}const et={logger:v.DEFAULT_INSTANCE,basename:"",isGLB:!0};class rt{static write(t,s=et){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=s.logger||v.DEFAULT_INSTANCE,n=r.json;n.asset.generator="glTF-Transform v0.7.2";const h=new tt(r,s),o=e.listBuffers().length,u=e.listTextures().length;function c(t,s,e,r){const i=[];let o=0;for(const s of t){const t=h.createAccessorDef(s);t.bufferView=n.bufferViews.length;const e=f.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,i.push(e),h.accessorIndexMap.set(s,n.accessors.length),n.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:f.concat(i).byteLength};return r&&(u.target=r),n.bufferViews.push(u),{buffers:i,byteLength:o}}function a(t,s,e){const r=t[0].getCount();let i=0;for(const s of t){const t=h.createAccessorDef(s);t.bufferView=n.bufferViews.length,t.byteOffset=i;const e=s.getElementSize(),r=s.getComponentSize();i+=f.padNumber(e*r),h.accessorIndexMap.set(s,n.accessors.length),n.accessors.push(t)}const o=r*i,u=new ArrayBuffer(o),c=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),n=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*i+e+r*n,a=o[s*t+r];switch(h){case 5126:c.setFloat32(u,a,!0);break;case 5120:c.setInt8(u,a);break;case 5122:c.setInt16(u,a,!0);break;case 5121:c.setUint8(u,a);break;case 5123:c.setUint16(u,a,!0);break;case 5125:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}e+=f.padNumber(t*n)}}return n.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:i,target:34962}),{byteLength:o,buffers:[u]}}h.bufferURIGenerator=new st(o>1,s.basename),h.imageURIGenerator=new st(u>1,s.basename),h.logger=t.getLogger();const l=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof I){const e=l.get(t)||[];e.push(s),l.set(t,e)}}return n.accessors=[],n.bufferViews=[],n.samplers=[],n.textures=[],n.images=e.listTextures().map((t,s)=>{const e=h.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&h.createImageData(e,t.getImage(),t),h.imageIndexMap.set(t,s),e}),n.buffers=[],e.listBuffers().forEach(t=>{const e=h.createPropertyDef(t),i=new Map,o=new Set,u=new Set,d=new Set,p=t.listParents().filter(t=>!(t instanceof $));for(const t of p){if(!(t instanceof I))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1,n=!1;const h=l.get(t)||[];for(const t of h)t instanceof O?s=!0:t instanceof U?e=!0:"inverseBindMatrices"===t.getName()?r=!0:n=!0;if(s||e||r||n||(n=!0),!s||e||r||n)if(!e||s||r||n)if(!r||s||e||n){if(!n||s||e||r)throw new Error("Attribute, index, or IBM accessors must be used only for that purpose.");d.add(t)}else u.add(t);else o.add(t);else{const s=h[0].getParent(),e=i.get(s)||new Set;e.add(t),i.set(s,e)}}const g=[],w=n.buffers.length;let m,v=0;if(o.size){const t=c(Array.from(o),w,v,34963);v+=t.byteLength,g.push(...t.buffers)}for(const t of Array.from(i.values()))if(t.size){const s=a(Array.from(t),w,v);v+=s.byteLength,g.push(...s.buffers)}if(u.size){const t=c(Array.from(u),w,v);v+=t.byteLength,g.push(...t.buffers)}if(d.size){const t=c(Array.from(d),w,v);v+=t.byteLength,g.push(...t.buffers)}if(h.imageData.length)for(let t=0;t<h.imageData.length;t++)n.bufferViews[n.images[t].bufferView].byteOffset=v,v+=h.imageData[t].byteLength,g.push(h.imageData[t]);v?(s.isGLB?m="@glb.bin":(m=h.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=v,r.resources[m]=f.concat(g),n.buffers.push(e)):h.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),e.listAccessors().find(t=>!t.getBuffer())&&i.warn("Skipped writing one or more Accessors: no Buffer assigned."),n.materials=e.listMaterials().map((t,s)=>{const e=h.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(e.alphaCutoff=t.getAlphaCutoff()),e.doubleSided=t.getDoubleSided(),e.pbrMetallicRoughness={},e.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),e.emissiveFactor=t.getEmissiveFactor(),e.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),e.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const s=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo();e.pbrMetallicRoughness.baseColorTexture=h.createTextureInfoDef(s,r)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo();e.emissiveTexture=h.createTextureInfoDef(s,r)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=h.createTextureInfoDef(s,r);1!==t.getNormalScale()&&(i.scale=t.getNormalScale()),e.normalTexture=i}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=h.createTextureInfoDef(s,r);1!==t.getOcclusionStrength()&&(i.strength=t.getOcclusionStrength()),e.occlusionTexture=i}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo();e.pbrMetallicRoughness.metallicRoughnessTexture=h.createTextureInfoDef(s,r)}return h.materialIndexMap.set(t,s),e}),n.meshes=e.listMeshes().map((t,s)=>{const e=h.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=h.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),Object.keys(t.getExtras()).length&&(s.extras=t.getExtras()),t.getIndices()&&(s.indices=h.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=h.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=h.accessorIndexMap.get(e.getAttribute(s));s.targets=s.targets||[],s.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),s}),t.getWeights().length&&(e.weights=t.getWeights()),r&&(e.extras=e.extras||{},e.extras.targetNames=r),h.meshIndexMap.set(t,s),e}),n.cameras=e.listCameras().map((t,s)=>{const e=h.createPropertyDef(t);return e.type=t.getType(),"perspective"===e.type?e.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:e.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},h.cameraIndexMap.set(t,s),e}),n.nodes=e.listNodes().map((t,s)=>{const e=h.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),h.nodeIndexMap.set(t,s),e}),n.skins=e.listSkins().map((t,s)=>{const e=h.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=h.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=h.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>h.nodeIndexMap.get(t)),h.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=n.nodes[s];t.getMesh()&&(e.mesh=h.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=h.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=h.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>h.nodeIndexMap.get(t)))}),n.animations=e.listAnimations().map(t=>{const s=h.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=h.createPropertyDef(t);return r.input=h.accessorIndexMap.get(t.getInput()),r.output=h.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=h.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:h.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),n.scenes=e.listScenes().map(t=>{const s=h.createPropertyDef(t);return s.nodes=t.listChildren().map(t=>h.nodeIndexMap.get(t)),s}),n.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),n.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(h)),function(t){const s=[];for(const e in t){const r=t[e];Array.isArray(r)&&0===r.length?s.push(e):null!==r&&""!==r||s.push(r)}for(const e of s)delete t[e]}(n),r}}class it{constructor(){this.bt=v.DEFAULT_INSTANCE,this.ht=[],this.Mt={}}setLogger(t){return this.bt=t,this}registerExtensions(t){return this.ht.push(...t),this}registerDependencies(t){return Object.assign(this.Mt,t),this}readJSON(t){return K.read(t,{extensions:this.ht,dependencies:this.Mt,logger:this.bt})}writeJSON(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return rt.write(t,s)}binaryToJSON(t){const s=new Uint32Array(t,0,3);if(1179937895!==s[0])throw new Error("Invalid glTF asset.");if(2!==s[1])throw new Error(`Unsupported glTF binary version, "${s[1]}".`);const e=new Uint32Array(t,12,2),r=e[0],i=new Uint32Array(t,20+r,2);if(1313821514!==e[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=f.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{"@glb.bin":t.slice(h,h+i[0])}}}readBinary(t){return this.readJSON(this.binaryToJSON(t))}writeBinary(t){const{json:s,resources:e}=this.writeJSON(t,{basename:"",isGLB:!0,logger:this.bt}),r=JSON.stringify(s),i=f.pad(f.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=f.concat([n,i]),o=f.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=f.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return f.concat([a,h,c])}}class nt extends it{constructor(){super(),this.St=require("fs"),this.It=require("path")}read(t){const s=this.readAsJSON(t);return K.read(s,{extensions:this.ht,dependencies:this.Mt,logger:this.bt})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Rt(t):this.Nt(t)}write(t,s){t.match(/\.glb$/)?this.Ct(t,s):this._t(t,s)}Rt(t){const s=this.St.readFileSync(t),e=f.trim(s);return this.binaryToJSON(e)}Nt(t){const s=this.It.dirname(t),e={json:JSON.parse(this.St.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri)if(t.uri.match(/data:/)){const s=`__${A()}.${p.extension(t.uri)}`;e.resources[s]=f.createBufferFromDataURI(t.uri),t.uri=s}else{const r=this.It.resolve(s,t.uri);e.resources[t.uri]=f.trim(this.St.readFileSync(r))}}),e}_t(t,s){const{json:e,resources:r}=rt.write(s,{basename:p.basename(t),isGLB:!1,logger:this.bt}),{St:i,It:n}=this,h=n.dirname(t);i.writeFileSync(t,JSON.stringify(e,null,2)),Object.keys(r).forEach(t=>{const s=Buffer.from(r[t]);i.writeFileSync(n.join(h,t),s)})}Ct(t,s){const e=Buffer.from(this.writeBinary(s));this.St.writeFileSync(t,e)}}const ht={};class ot extends it{constructor(t=ht){super(),this.Bt=t}read(t){return this.readAsJSON(t).then(t=>this.readJSON(t))}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Rt(t):this.Nt(t)}Nt(t){const s={json:{},resources:{}};return fetch(t,this.Bt).then(t=>t.json()).then(t=>{s.json=t;const e=[...t.images||[],...t.buffers||[]].map(t=>{if(t.uri)return fetch(t.uri,this.Bt).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}Rt(t){return fetch(t,this.Bt).then(t=>t.arrayBuffer()).then(t=>this.binaryToJSON(t))}}export{I as Accessor,R as Animation,N as AnimationChannel,C as AnimationSampler,_ as Buffer,f as BufferUtils,E as COPY_IDENTITY,B as Camera,d as ColorUtils,q as Document,H as Extension,L as ExtensionProperty,p as FileUtils,n as GLB_BUFFER,c as Graph,a as GraphChild,g as ImageUtils,u as Link,v as Logger,F as Material,m as MathUtils,G as Mesh,j as Node,nt as NodeIO,D as Primitive,J as PrimitiveTarget,b as Property,h as PropertyType,Y as ReaderContext,$ as Root,z as Scene,V as Skin,W as Texture,P as TextureInfo,ot as WebIO,tt as WriterContext,A as uuid};
import{fromRotationTranslationScale as t,getTranslation as s,getRotation as e,getScaling as r,multiply as i}from"gl-matrix/mat4";const n="@glb.bin";var h;function o(t,s,e,r){var i,n=arguments.length,h=n<3?s:null===r?r=Object.getOwnPropertyDescriptor(s,e):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,s,e,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(s,e,h):i(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h}!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo"}(h||(h={}));class u{constructor(t,s,e){if(this.t=t,this.s=s,this.i=e,this.h=!1,this.o=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}const c=new Set;class a{constructor(){this.u=new Set,this.l=new Map,this.p=new Map}getLinks(){return Array.from(this.u)}listParents(t){const s=this.p.get(t)||c;return Array.from(s).map(t=>t.getParent())}listChildren(t){const s=this.l.get(t)||c;return Array.from(s).map(t=>t.getChild())}disconnectChildren(t){return(this.l.get(t)||c).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=Array.from(this.p.get(t)||c);return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}swapChild(t,s,e){const r=this.l.get(t)||c;return Array.from(r).filter(t=>t.getChild()===s).forEach(t=>{this.p.get(s).delete(t),t.setChild(e),this.p.has(e)||this.p.set(e,new Set),this.p.get(e).add(t)}),this}link(t,s,e){if(!e)return null;const r=new u(t,s,e);return this.registerLink(r),r}registerLink(t){this.u.add(t);const s=t.getParent();this.l.has(s)||this.l.set(s,new Set),this.l.get(s).add(t);const e=t.getChild();return this.p.has(e)||this.p.set(e,new Set),this.p.get(e).add(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u.delete(t),this.l.get(t.getParent()).delete(t),this.p.get(t.getChild()).delete(t),this}}function l(t,s){Object.defineProperty(t,s,{get:function(){return this["__"+s]},set:function(t){const e=this["__"+s];e&&!Array.isArray(e)&&e.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+s]=null}),this["__"+s]=t},enumerable:!0})}function f(t,s){}class d{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const s=atob(t.split(",")[1]),e=new Uint8Array(s.length);for(let t=0;t<s.length;t++)e[t]=s.charCodeAt(t);return e.buffer}{const s=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(s,e?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:s,byteLength:e}=t;return t.buffer.slice(s,s+e)}static concat(t){let s=0;for(const e of t)s+=e.byteLength;const e=new Uint8Array(s);let r=0;for(const s of t)e.set(new Uint8Array(s),r),r+=s.byteLength;return e.buffer}static pad(t,s=0){const e=this.padNumber(t.byteLength);if(e!==t.byteLength){const r=new Uint8Array(e);if(r.set(new Uint8Array(t)),0!==s)for(let i=t.byteLength;i<e;i++)r[i]=s;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,s){if(t===s)return!0;if(t.byteLength!==s.byteLength)return!1;const e=new DataView(t),r=new DataView(s);let i=t.byteLength;for(;i--;)if(e.getUint8(i)!==r.getUint8(i))return!1;return!0}}class p{static hexToFactor(t,s){return t=Math.floor(t),s[0]=(t>>16&255)/255,s[1]=(t>>8&255)/255,s[2]=(255&t)/255,this.convertSRGBToLinear(s,s)}static factorToHex(t){const s=[...t],[e,r,i]=this.convertLinearToSRGB(t,s);return 255*e<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(t,s){for(let e=0;e<3;e++)s[e]=t[e]<.04045?.0773993808*t[e]:Math.pow(.9478672986*t[e]+.0521327014,2.4);return s}static convertLinearToSRGB(t,s){for(let e=0;e<3;e++)s[e]=t[e]<.0031308?12.92*t[e]:1.055*Math.pow(t[e],.41666)-.055;return s}}class g{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class w{static getSizeJPEG(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),m(r,s),e=r.getUint8(s+1),192===e||193===e||194===e)return[r.getUint16(s+7,!1),r.getUint16(s+5,!1)];r=new DataView(t,r.byteOffset+s+2)}throw new TypeError("Invalid JPG, no size found")}static getSizePNG(t){const s=new DataView(t);return"CgBI"===d.decodeText(t.slice(12,16))?[s.getUint32(32,!1),s.getUint32(36,!1)]:[s.getUint32(16,!1),s.getUint32(20,!1)]}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":"image/"+t}}function m(t,s){if(s>t.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t.getUint8(s))throw new TypeError("Invalid JPG, marker table corrupted")}class v{static identity(t){return t}static denormalize(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}static normalize(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}}class x{constructor(t){this.verbosity=t}debug(t){this.verbosity<=x.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=x.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=x.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=x.Verbosity.ERROR&&console.error(t)}}x.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0},x.DEFAULT_INSTANCE=new x(x.Verbosity.INFO);const y="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",A=new Set,T=function(){let t="";for(let s=0;s<6;s++)t+=y.charAt(Math.floor(Math.random()*y.length));return t},E=function(){for(let t=0;t<999;t++){const t=T();if(!A.has(t))return A.add(t),t}},b=t=>t;class M extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.swapChild(this,t,s),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0,t.push(...e)}),this}removeGraphChild(t,s){return t.filter(t=>t.getChild()===s).forEach(t=>t.dispose()),this}clearGraphChildList(t){for(;t.length>0;)t[0].dispose();return this}listGraphParents(){return this.graph.listParents(this)}}{constructor(t,s=""){super(t),this.g={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.g}setExtras(t){return this.g=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,b)}copy(t,s){return this.t=t.t,this.g=JSON.parse(JSON.stringify(t.g)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}const S="Pass extension name (string) as lookup token, not a constructor.";class I extends M{constructor(){super(...arguments),this.extensions=[]}copy(t,s=b){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.extensionName,s(e))}),this}getExtension(t){if("string"!=typeof t)throw new Error(S);const s=this.extensions.find(s=>s.getChild().extensionName===t);return s?s.getChild():null}setExtension(t,s){if("string"!=typeof t)throw new Error(S);const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.m(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}o([f],I.prototype,"extensions",void 0);class R extends I{constructor(){super(...arguments),this.propertyType=h.ACCESSOR,this.v=null,this.A="SCALAR",this.T=null,this.M=!1,this.S=v.identity,this.I=v.identity,this.buffer=null}copy(t,s=b){return super.copy(t,s),this.v=t.v.slice(),this.A=t.A,this.T=t.T,this.M=t.M,this.S=t.S,this.I=t.I,t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}}getMinNormalized(t){const s=this.getElementSize();this.getMin(t);for(let e=0;e<s;e++)t[e]=this.I(t[e]);return t}getMin(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.v[r+s];Number.isFinite(e)&&(t[s]=Math.min(t[s],e))}return t}getMaxNormalized(t){const s=this.getElementSize();this.getMax(t);for(let e=0;e<s;e++)t[e]=this.I(t[e]);return t}getMax(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=-Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.v[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.v.length/this.getElementSize()}getType(){return this.A}setType(t){return this.A=t,this}getElementSize(){return R.getElementSize(this.A)}getComponentSize(){return this.v.BYTES_PER_ELEMENT}getComponentType(){return this.T}getNormalized(){return this.M}setNormalized(t){return this.M=t,t?(this.I=t=>v.denormalize(t,this.T),this.S=t=>v.normalize(t,this.T)):(this.I=v.identity,this.S=v.identity),this}getScalar(t){const s=this.getElementSize();return this.I(this.v[t*s])}setScalar(t,s){return this.v[t*this.getElementSize()]=this.S(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.I(this.v[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.v[t*e+r]=this.S(s[r]);return this}getBuffer(){return this.buffer?this.buffer.getChild():null}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.v}setArray(t){return this.T=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.v=t,this}getByteLength(){return this.v.byteLength}}R.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},R.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},o([l],R.prototype,"buffer",void 0);class C extends I{constructor(){super(...arguments),this.propertyType=h.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=b){return super.copy(t,s),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),t.channels.forEach(t=>this.addChannel(s(t.getChild()))),t.samplers.forEach(t=>this.addSampler(s(t.getChild()))),this}addChannel(t){const s=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,s)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const s=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,s)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}o([f],C.prototype,"channels",void 0),o([f],C.prototype,"samplers",void 0);class N extends M{constructor(){super(...arguments),this.propertyType=h.ANIMATION_CHANNEL,this.R=null,this.targetNode=null,this.sampler=null}copy(t,s=b){return super.copy(t,s),this.R=t.R,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.R}setTargetPath(t){return this.R=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}o([l],N.prototype,"targetNode",void 0),o([l],N.prototype,"sampler",void 0);class _ extends M{constructor(){super(...arguments),this.propertyType=h.ANIMATION_SAMPLER,this.C="LINEAR",this.input=null,this.output=null}copy(t,s=b){return super.copy(t,s),this.C=t.C,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.C}setInterpolation(t){return this.C=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}o([l],_.prototype,"input",void 0),o([l],_.prototype,"output",void 0);class B extends I{constructor(){super(...arguments),this.propertyType=h.BUFFER}copy(t,s=b){return super.copy(t,s),this.N=t.N,this}getURI(){return this.N}setURI(t){return this.N=t,this}}class L extends I{constructor(){super(...arguments),this.propertyType=h.CAMERA,this.A="perspective"}copy(t,s=b){return super.copy(t,s),this.A=t.A,this._=t._,this.B=t.B,this.L=t.L,this.O=t.O,this.U=t.U,this.k=t.k,this}getType(){return this.A}setType(t){return this.A=t,this}getZNear(){return this._}setZNear(t){return this._=t,this}getZFar(){return this.B}setZFar(t){return this.B=t,this}getAspectRatio(){return this.L}setAspectRatio(t){return this.L=t,this}getYFov(){return this.O}setYFov(t){return this.O=t,this}getXMag(){return this.U}setXMag(t){return this.U=t,this}getYMag(){return this.k}setYMag(t){return this.k=t,this}}class O extends M{constructor(t,s){super(t),this.P=s,this.P.addExtensionProperty(this)}dispose(){this.P.removeExtensionProperty(this),super.dispose()}m(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class U extends u{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class k extends u{copy(t){return this}}class P extends a{linkAttribute(t,s,e){if(!e)return null;const r=new U(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new k(t,s,e);return this.registerLink(r),r}}class F extends I{constructor(){super(...arguments),this.propertyType=h.TEXTURE_INFO,this.F=0,this.G=null,this.j=null,this.D=10497,this.J=10497}copy(t,s=b){return super.copy(t,s),this.F=t.F,this.G=t.G,this.j=t.j,this.D=t.D,this.J=t.J,this}getTexCoord(){return this.F}setTexCoord(t){return this.F=t,this}getMagFilter(){return this.G}setMagFilter(t){return this.G=t,this}getMinFilter(){return this.j}setMinFilter(t){return this.j=t,this}getWrapS(){return this.D}setWrapS(t){return this.D=t,this}getWrapT(){return this.J}setWrapT(t){return this.J=t,this}}F.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},F.TextureMagFilter={NEAREST:9728,LINEAR:9729},F.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class G extends I{constructor(){super(...arguments),this.propertyType=h.MATERIAL,this.$="OPAQUE",this.V=.5,this.W=!1,this.q=[1,1,1,1],this.H=[0,0,0],this.Y=1,this.Z=1,this.X=1,this.K=1,this.baseColorTexture=null,this.baseColorTextureInfo=this.graph.link("baseColorTextureInfo",this,new F(this.graph)),this.emissiveTexture=null,this.emissiveTextureInfo=this.graph.link("emissiveTextureInfo",this,new F(this.graph)),this.normalTexture=null,this.normalTextureInfo=this.graph.link("normalTextureInfo",this,new F(this.graph)),this.occlusionTexture=null,this.occlusionTextureInfo=this.graph.link("occlusionTextureInfo",this,new F(this.graph)),this.metallicRoughnessTexture=null,this.metallicRoughnessTextureInfo=this.graph.link("metallicRoughnessTextureInfo",this,new F(this.graph))}copy(t,s=b){return super.copy(t,s),this.$=t.$,this.V=t.V,this.W=t.W,this.q=[...t.q],this.H=[...t.H],this.Y=t.Y,this.Z=t.Z,this.X=t.X,this.K=t.K,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()),s)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()),s)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()),s)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()),s)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()),s)),this}dispose(){this.baseColorTextureInfo.getChild().dispose(),this.emissiveTextureInfo.getChild().dispose(),this.normalTextureInfo.getChild().dispose(),this.occlusionTextureInfo.getChild().dispose(),this.metallicRoughnessTextureInfo.getChild().dispose(),super.dispose()}getDoubleSided(){return this.W}setDoubleSided(t){return this.W=t,this}getAlpha(){return this.q[3]}setAlpha(t){return this.q[3]=t,this}getAlphaMode(){return this.$}setAlphaMode(t){return this.$=t,this}getAlphaCutoff(){return this.V}setAlphaCutoff(t){return this.V=t,this}getBaseColorFactor(){return this.q}setBaseColorFactor(t){return this.q=t,this}getBaseColorHex(){return p.factorToHex(this.q)}setBaseColorHex(t){return p.hexToFactor(t,this.q),this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTextureInfo.getChild():null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.link("baseColorTexture",this,t),this}getEmissiveFactor(){return this.H}setEmissiveFactor(t){return this.H=t,this}getEmissiveHex(){return p.factorToHex(this.H)}setEmissiveHex(t){return p.hexToFactor(t,this.H),this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTextureInfo.getChild():null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.link("emissiveTexture",this,t),this}getNormalScale(){return this.Y}setNormalScale(t){return this.Y=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTextureInfo.getChild():null}setNormalTexture(t){return this.normalTexture=this.graph.link("normalTexture",this,t),this}getOcclusionStrength(){return this.Z}setOcclusionStrength(t){return this.Z=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTextureInfo.getChild():null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.link("occlusionTexture",this,t),this}getRoughnessFactor(){return this.X}setRoughnessFactor(t){return this.X=t,this}getMetallicFactor(){return this.K}setMetallicFactor(t){return this.K=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTextureInfo.getChild():null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.link("metallicRoughnessTexture",this,t),this}}o([l],G.prototype,"baseColorTexture",void 0),o([l],G.prototype,"baseColorTextureInfo",void 0),o([l],G.prototype,"emissiveTexture",void 0),o([l],G.prototype,"emissiveTextureInfo",void 0),o([l],G.prototype,"normalTexture",void 0),o([l],G.prototype,"normalTextureInfo",void 0),o([l],G.prototype,"occlusionTexture",void 0),o([l],G.prototype,"occlusionTextureInfo",void 0),o([l],G.prototype,"metallicRoughnessTexture",void 0),o([l],G.prototype,"metallicRoughnessTextureInfo",void 0);class j extends I{constructor(){super(...arguments),this.propertyType=h.MESH,this.tt=[],this.primitives=[]}copy(t,s=b){return super.copy(t,s),this.tt=[...t.tt],this.clearGraphChildList(this.primitives),t.primitives.forEach(t=>this.addPrimitive(s(t.getChild()))),this}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.tt}setWeights(t){return this.tt=t,this}}o([f],j.prototype,"primitives",void 0);class D extends I{constructor(){super(...arguments),this.propertyType=h.NODE,this.st=[0,0,0],this.et=[0,0,0,1],this.rt=[1,1,1],this.tt=[],this.s=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=b){return super.copy(t,s),this.st=[...t.st],this.et=[...t.et],this.rt=[...t.rt],this.tt=[...t.tt],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),s!==b&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}getTranslation(){return this.st}getRotation(){return this.et}getScale(){return this.rt}setTranslation(t){return this.st=t,this}setRotation(t){return this.et=t,this}setScale(t){return this.rt=t,this}getMatrix(){return t([],this.et,this.st,this.rt)}getWorldTranslation(){return s([],this.getWorldMatrix())}getWorldRotation(){return e([],this.getWorldMatrix())}getWorldScale(){return r([],this.getWorldMatrix())}getWorldMatrix(){const t=[];for(let s=this;s instanceof D;s=s.s)t.push(s);let s;const e=t.pop().getMatrix();for(;s=t.pop();)i(e,e,s.getMatrix());return e}addChild(t){t.s&&t.s.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.s=this,s.onDispose(()=>t.s=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getParent(){return this.s}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.tt}setWeights(t){return this.tt=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}o([l],D.prototype,"camera",void 0),o([l],D.prototype,"mesh",void 0),o([l],D.prototype,"skin",void 0),o([f],D.prototype,"children",void 0);class J extends M{constructor(){super(...arguments),this.propertyType=h.PRIMITIVE,this.it=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=b){return super.copy(t,s),this.it=t.it,t.indices&&this.setIndices(s(t.indices.getChild())),t.material&&this.setMaterial(s(t.material.getChild())),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this.clearGraphChildList(this.targets),t.targets.forEach(t=>this.addTarget(s(t.getChild()))),this}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.graph.linkIndex("index",this,t),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}getMaterial(){return this.material?this.material.getChild():null}setMaterial(t){return this.material=this.graph.link("material",this,t),this}getMode(){return this.it}setMode(t){return this.it=t,this}listTargets(){return this.targets.map(t=>t.getChild())}addTarget(t){return this.addGraphChild(this.targets,this.graph.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}o([l],J.prototype,"material",void 0),o([l],J.prototype,"indices",void 0),o([f],J.prototype,"attributes",void 0),o([f],J.prototype,"targets",void 0);class $ extends M{constructor(){super(...arguments),this.propertyType=h.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=b){return super.copy(t,s),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}}o([f],$.prototype,"attributes",void 0);class z extends M{constructor(){super(...arguments),this.propertyType=h.ROOT,this.nt={generator:"glTF-Transform v0.7.3",version:"2.0"},this.ht=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[]}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=b){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.nt,t.nt),t.accessors.forEach(t=>this.ot(s(t.getChild()))),t.animations.forEach(t=>this.ut(s(t.getChild()))),t.buffers.forEach(t=>this.ct(s(t.getChild()))),t.cameras.forEach(t=>this.at(s(t.getChild()))),t.materials.forEach(t=>this.lt(s(t.getChild()))),t.meshes.forEach(t=>this.ft(s(t.getChild()))),t.nodes.forEach(t=>this.dt(s(t.getChild()))),t.scenes.forEach(t=>this.pt(s(t.getChild()))),t.skins.forEach(t=>this.gt(s(t.getChild()))),t.textures.forEach(t=>this.wt(s(t.getChild()))),this}getAsset(){return this.nt}listExtensionsUsed(){return Array.from(this.ht)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}vt(t){if(this.ht.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.ht.add(t),this}xt(t){return this.ht.delete(t),this}pt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}gt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}wt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}o([f],z.prototype,"accessors",void 0),o([f],z.prototype,"animations",void 0),o([f],z.prototype,"buffers",void 0),o([f],z.prototype,"cameras",void 0),o([f],z.prototype,"materials",void 0),o([f],z.prototype,"meshes",void 0),o([f],z.prototype,"nodes",void 0),o([f],z.prototype,"scenes",void 0),o([f],z.prototype,"skins",void 0),o([f],z.prototype,"textures",void 0);class V extends I{constructor(){super(...arguments),this.propertyType=h.SCENE,this.children=[]}copy(t,s=b){return super.copy(t,s),s!==b&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}addChild(t){t.s&&t.s.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.s=this,s.onDispose(()=>t.s=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}traverse(t){for(const s of this.listChildren())s.traverse(t);return this}}o([f],V.prototype,"children",void 0);class W extends I{constructor(){super(...arguments),this.propertyType=h.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=b){return super.copy(t,s),t.skeleton&&this.setSkeleton(s(t.skeleton.getChild())),t.inverseBindMatrices&&this.setInverseBindMatrices(s(t.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),t.joints.forEach(t=>this.addJoint(s(t.getChild()))),this}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const s=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,s)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}o([l],W.prototype,"skeleton",void 0),o([l],W.prototype,"inverseBindMatrices",void 0),o([f],W.prototype,"joints",void 0);class q extends I{constructor(){super(...arguments),this.propertyType=h.TEXTURE,this.yt=null,this.At="",this.N=""}copy(t,s=b){return super.copy(t,s),this.At=t.At,this.N=t.N,t.yt&&(this.yt=t.yt.slice(0)),this}getMimeType(){return this.At}setMimeType(t){return this.At=t,this}getURI(){return this.N}setURI(t){return this.N=t,this}getImage(){return this.yt}setImage(t){return this.yt=t,this}getSize(){let t;return t=this.At?"image/png"===this.At:this.N.match(/\.png$/),t?w.getSizePNG(this.yt):w.getSizeJPEG(this.yt)}}class H{constructor(){this.Tt=new P,this.Et=new z(this.Tt),this.bt=x.DEFAULT_INSTANCE}getRoot(){return this.Et}getGraph(){return this.Tt}getLogger(){return this.bt}setLogger(t){return this.bt=t,this}clone(){return(new H).merge(this)}merge(t){const s={};for(const e of t.getRoot().listExtensionsUsed()){const t=this.createExtension(e.constructor);e.isRequired()&&t.setRequired(!0),s[t.extensionName]=t}const e=new Set,r=new Map;e.add(t.Et),r.set(t.Et,this.Et);for(const i of t.Tt.getLinks())for(const t of[i.getParent(),i.getChild()]){if(e.has(t))continue;let i;if(t.propertyType===h.TEXTURE_INFO)i=t;else{const e=t.constructor;i=t instanceof O?new e(this.Tt,s[t.extensionName]):new e(this.Tt)}r.set(t,i),e.add(t)}const i=t=>r.get(t);for(const t of e)r.get(t).copy(t,i);return this}async transform(...t){for(const s of t)await s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t=""){const s=new V(this.Tt,t);return this.Et.pt(s),s}createNode(t=""){const s=new D(this.Tt,t);return this.Et.dt(s),s}createCamera(t=""){const s=new L(this.Tt,t);return this.Et.at(s),s}createSkin(t=""){const s=new W(this.Tt,t);return this.Et.gt(s),s}createMesh(t=""){const s=new j(this.Tt,t);return this.Et.ft(s),s}createPrimitive(){return new J(this.Tt)}createPrimitiveTarget(t=""){return new $(this.Tt,t)}createMaterial(t=""){const s=new G(this.Tt,t);return this.Et.lt(s),s}createTexture(t=""){const s=new q(this.Tt,t);return this.Et.wt(s),s}createAnimation(t=""){const s=new C(this.Tt,t);return this.Et.ut(s),s}createAnimationChannel(t=""){return new N(this.Tt,t)}createAnimationSampler(t=""){return new _(this.Tt,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new R(this.Tt,t).setBuffer(s);return this.Et.ot(e),e}createBuffer(t=""){const s=new B(this.Tt,t);return this.Et.ct(s),s}}class Y{constructor(t){this.doc=t,this.provideTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().vt(this)}dispose(){this.doc.getRoot().xt(this);for(const t of this.properties)t.dispose()}isRequired(){return this.required}setRequired(t){return this.required=t,this}addExtensionProperty(t){return this.properties.add(t),this}removeExtensionProperty(t){return this.properties.delete(t),this}install(t,s){return this}provide(t,s){return this}}class Z{constructor(t){this.jsonDoc=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){this.textureInfos.set(t,s),void 0!==s.texCoord&&t.setTexCoord(s.texCoord);const e=this.jsonDoc.json.textures[s.index];if(void 0===e.sampler)return;const r=this.jsonDoc.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const X={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},K={logger:x.DEFAULT_INSTANCE,extensions:[],dependencies:{}};class Q{static read(t,i=K){const{json:n}=t,o=new H;this.validate(t,i);const u=new Z(t),c=t.json.asset,a=o.getRoot().getAsset();c.copyright&&(a.copyright=c.copyright),c.extras&&(a.extras=c.extras),c.generator&&(a.generator=c.generator),c.minVersion&&(a.minVersion=c.minVersion);const l=n.extensionsUsed||[],f=n.extensionsRequired||[];for(const t of i.extensions)if(l.includes(t.EXTENSION_NAME)){const s=o.createExtension(t).setRequired(f.includes(t.EXTENSION_NAME));for(const t of s.dependencies)s.install(t,i.dependencies[t])}u.buffers=(n.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.extras&&s.setExtras(t.extras),t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(n.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(n.accessors||[]).map(s=>{const e=o.createAccessor(s.name,u.bufferViewBuffers[s.bufferView]).setType(s.type);if(s.extras&&e.setExtras(s.extras),void 0!==s.normalized&&e.setNormalized(s.normalized),void 0===s.bufferView&&!s.sparse)return e;let r;return r=void 0!==s.sparse?function(t,s){const e=X[t.componentType],r=R.getElementSize(t.type);let i;i=void 0!==t.bufferView?tt(t,s).slice():new e(t.count*r);const n=t.sparse.count,h={...t,...t.sparse.indices,count:n,type:"SCALAR"},o={...t,...t.sparse.values,count:n},u=tt(h,s),c=tt(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(s,t):tt(s,t).slice(),e.setArray(r),e});const d=n.images||[],p=n.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(h.TEXTURE)).forEach(t=>t.provide(u,h.TEXTURE)),u.textures=d.map(s=>{const e=o.createTexture(s.name);if(s.extras&&e.setExtras(s.extras),void 0!==s.bufferView){const r=n.bufferViews[s.bufferView],i=t.json.buffers[r.buffer],h=r.byteOffset||0,o=(i.uri?t.resources[i.uri]:t.resources["@glb.bin"]).slice(h,h+r.byteLength);e.setImage(o)}else void 0!==s.uri&&(e.setImage(t.resources[s.uri]),0!==s.uri.indexOf("__")&&e.setURI(s.uri));if(void 0!==s.mimeType)e.setMimeType(s.mimeType);else if(s.uri){const t=g.extension(s.uri);e.setMimeType(w.extensionToMimeType(t))}return e}),u.materials=(n.materials||[]).map(t=>{const s=o.createMaterial(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t)}return s});const m=n.meshes||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(h.PRIMITIVE)).forEach(t=>t.provide(u,h.PRIMITIVE)),u.meshes=m.map(t=>{const s=o.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();e.extras&&r.setExtras(e.extras),void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(n.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return t.extras&&s.setExtras(t.extras),"perspective"===t.type?s.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):s.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),s});const v=n.nodes||[];return u.nodes=v.map(t=>{const i=o.createNode(t.name);return t.extras&&i.setExtras(t.extras),void 0!==t.translation&&i.setTranslation(t.translation),void 0!==t.rotation&&i.setRotation(t.rotation),void 0!==t.scale&&i.setScale(t.scale),void 0!==t.matrix&&(i.setTranslation(s([],t.matrix)),i.setRotation(e([],t.matrix)),i.setScale(r([],t.matrix))),void 0!==t.weights&&i.setWeights(t.weights),i}),u.skins=(n.skins||[]).map(t=>{const s=o.createSkin(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(u.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(u.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(u.nodes[e]);return s}),v.map((t,s)=>{const e=u.nodes[s];(t.children||[]).forEach(t=>e.addChild(u.nodes[t])),void 0!==t.mesh&&e.setMesh(u.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(u.cameras[t.camera]),void 0!==t.skin&&e.setSkin(u.skins[t.skin])}),u.animations=(n.animations||[]).map(t=>{const s=o.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return t.extras&&e.setExtras(t.extras),s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);t.extras&&r.setExtras(t.extras),s.addChannel(r)}),s}),u.scenes=(n.scenes||[]).map(t=>{const s=o.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addChild(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}static validate(t,s){const e=t.json;if("2.0"!==e.asset.version)throw new Error(`Unsupported glTF version, "${e.asset.version}".`);if(e.extensionsRequired)for(const t of e.extensionsRequired)if(!s.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);if(e.extensionsUsed)for(const t of e.extensionsUsed)s.extensions.find(s=>s.EXTENSION_NAME===t)||s.logger.warn(`Missing optional extension, "${t}".`)}}function tt(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=X[t.componentType],h=R.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=X[t.componentType],h=R.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case 5126:i=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[s*h+e]=i}return c}(t,s);const o=(e.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class st{constructor(t,s){this.jsonDoc=t,this.options=s,this.accessorIndexMap=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.imageData=[]}createTextureInfoDef(t,s){const e={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},r=JSON.stringify(e);this.samplerDefIndexMap.has(r)||(this.samplerDefIndexMap.set(r,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(e));const i={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(r)},n=JSON.stringify(i);this.textureDefIndexMap.has(n)||(this.textureDefIndexMap.set(n,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(i));const h={index:this.textureDefIndexMap.get(n),texCoord:s.getTexCoord()};return this.textureInfoDefMap.set(s,h),h}createPropertyDef(t){const s={};return t.getName()&&(s.name=t.getName()),Object.keys(t.getExtras()).length>0&&(s.extras=t.getExtras()),s}createAccessorDef(t){const s=this.createPropertyDef(t);return s.type=t.getType(),s.componentType=t.getComponentType(),s.count=t.getCount(),t.getMax(s.max=[]),t.getMin(s.min=[]),s.normalized=t.getNormalized(),s}createImageData(t,s,e){if(this.options.isGLB)this.imageData.push(s),t.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=w.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.jsonDoc.resources[t.uri]=s}}}class et{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}const rt={logger:x.DEFAULT_INSTANCE,basename:"",isGLB:!0};class it{static write(t,s=rt){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=s.logger||x.DEFAULT_INSTANCE,n=r.json;n.asset.generator="glTF-Transform v0.7.3";const h=new st(r,s),o=e.listBuffers().length,u=e.listTextures().length;function c(t,s,e,r){const i=[];let o=0;for(const s of t){const t=h.createAccessorDef(s);t.bufferView=n.bufferViews.length;const e=d.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,i.push(e),h.accessorIndexMap.set(s,n.accessors.length),n.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:d.concat(i).byteLength};return r&&(u.target=r),n.bufferViews.push(u),{buffers:i,byteLength:o}}function a(t,s,e){const r=t[0].getCount();let i=0;for(const s of t){const t=h.createAccessorDef(s);t.bufferView=n.bufferViews.length,t.byteOffset=i;const e=s.getElementSize(),r=s.getComponentSize();i+=d.padNumber(e*r),h.accessorIndexMap.set(s,n.accessors.length),n.accessors.push(t)}const o=r*i,u=new ArrayBuffer(o),c=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),n=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*i+e+r*n,a=o[s*t+r];switch(h){case 5126:c.setFloat32(u,a,!0);break;case 5120:c.setInt8(u,a);break;case 5122:c.setInt16(u,a,!0);break;case 5121:c.setUint8(u,a);break;case 5123:c.setUint16(u,a,!0);break;case 5125:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}e+=d.padNumber(t*n)}}return n.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:i,target:34962}),{byteLength:o,buffers:[u]}}h.bufferURIGenerator=new et(o>1,s.basename),h.imageURIGenerator=new et(u>1,s.basename),h.logger=t.getLogger();const l=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof R){const e=l.get(t)||[];e.push(s),l.set(t,e)}}return n.accessors=[],n.bufferViews=[],n.samplers=[],n.textures=[],n.images=e.listTextures().map((t,s)=>{const e=h.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&h.createImageData(e,t.getImage(),t),h.imageIndexMap.set(t,s),e}),n.buffers=[],e.listBuffers().forEach(t=>{const e=h.createPropertyDef(t),i=new Map,o=new Set,u=new Set,f=new Set,p=t.listParents().filter(t=>!(t instanceof z));for(const t of p){if(!(t instanceof R))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1,n=!1;const h=l.get(t)||[];for(const t of h)t instanceof U?s=!0:t instanceof k?e=!0:"inverseBindMatrices"===t.getName()?r=!0:n=!0;if(s||e||r||n||(n=!0),!s||e||r||n)if(!e||s||r||n)if(!r||s||e||n){if(!n||s||e||r)throw new Error("Attribute, index, or IBM accessors must be used only for that purpose.");f.add(t)}else u.add(t);else o.add(t);else{const s=h[0].getParent(),e=i.get(s)||new Set;e.add(t),i.set(s,e)}}const g=[],w=n.buffers.length;let m,v=0;if(o.size){const t=c(Array.from(o),w,v,34963);v+=t.byteLength,g.push(...t.buffers)}for(const t of Array.from(i.values()))if(t.size){const s=a(Array.from(t),w,v);v+=s.byteLength,g.push(...s.buffers)}if(u.size){const t=c(Array.from(u),w,v);v+=t.byteLength,g.push(...t.buffers)}if(f.size){const t=c(Array.from(f),w,v);v+=t.byteLength,g.push(...t.buffers)}if(h.imageData.length)for(let t=0;t<h.imageData.length;t++)n.bufferViews[n.images[t].bufferView].byteOffset=v,v+=h.imageData[t].byteLength,g.push(h.imageData[t]);v?(s.isGLB?m="@glb.bin":(m=h.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=v,r.resources[m]=d.concat(g),n.buffers.push(e)):h.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),e.listAccessors().find(t=>!t.getBuffer())&&i.warn("Skipped writing one or more Accessors: no Buffer assigned."),n.materials=e.listMaterials().map((t,s)=>{const e=h.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(e.alphaCutoff=t.getAlphaCutoff()),e.doubleSided=t.getDoubleSided(),e.pbrMetallicRoughness={},e.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),e.emissiveFactor=t.getEmissiveFactor(),e.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),e.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const s=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo();e.pbrMetallicRoughness.baseColorTexture=h.createTextureInfoDef(s,r)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo();e.emissiveTexture=h.createTextureInfoDef(s,r)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=h.createTextureInfoDef(s,r);1!==t.getNormalScale()&&(i.scale=t.getNormalScale()),e.normalTexture=i}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=h.createTextureInfoDef(s,r);1!==t.getOcclusionStrength()&&(i.strength=t.getOcclusionStrength()),e.occlusionTexture=i}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo();e.pbrMetallicRoughness.metallicRoughnessTexture=h.createTextureInfoDef(s,r)}return h.materialIndexMap.set(t,s),e}),n.meshes=e.listMeshes().map((t,s)=>{const e=h.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=h.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),Object.keys(t.getExtras()).length&&(s.extras=t.getExtras()),t.getIndices()&&(s.indices=h.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=h.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=h.accessorIndexMap.get(e.getAttribute(s));s.targets=s.targets||[],s.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),s}),t.getWeights().length&&(e.weights=t.getWeights()),r&&(e.extras=e.extras||{},e.extras.targetNames=r),h.meshIndexMap.set(t,s),e}),n.cameras=e.listCameras().map((t,s)=>{const e=h.createPropertyDef(t);return e.type=t.getType(),"perspective"===e.type?e.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:e.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},h.cameraIndexMap.set(t,s),e}),n.nodes=e.listNodes().map((t,s)=>{const e=h.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),h.nodeIndexMap.set(t,s),e}),n.skins=e.listSkins().map((t,s)=>{const e=h.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=h.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=h.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>h.nodeIndexMap.get(t)),h.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=n.nodes[s];t.getMesh()&&(e.mesh=h.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=h.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=h.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>h.nodeIndexMap.get(t)))}),n.animations=e.listAnimations().map(t=>{const s=h.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=h.createPropertyDef(t);return r.input=h.accessorIndexMap.get(t.getInput()),r.output=h.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=h.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:h.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),n.scenes=e.listScenes().map(t=>{const s=h.createPropertyDef(t);return s.nodes=t.listChildren().map(t=>h.nodeIndexMap.get(t)),s}),n.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),n.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(h)),function(t){const s=[];for(const e in t){const r=t[e];Array.isArray(r)&&0===r.length?s.push(e):null!==r&&""!==r||s.push(r)}for(const e of s)delete t[e]}(n),r}}class nt{constructor(){this.bt=x.DEFAULT_INSTANCE,this.ht=[],this.Mt={}}setLogger(t){return this.bt=t,this}registerExtensions(t){return this.ht.push(...t),this}registerDependencies(t){return Object.assign(this.Mt,t),this}readJSON(t){return Q.read(t,{extensions:this.ht,dependencies:this.Mt,logger:this.bt})}writeJSON(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return it.write(t,s)}binaryToJSON(t){const s=new Uint32Array(t,0,3);if(1179937895!==s[0])throw new Error("Invalid glTF asset.");if(2!==s[1])throw new Error(`Unsupported glTF binary version, "${s[1]}".`);const e=new Uint32Array(t,12,2),r=e[0],i=new Uint32Array(t,20+r,2);if(1313821514!==e[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=d.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{"@glb.bin":t.slice(h,h+i[0])}}}readBinary(t){return this.readJSON(this.binaryToJSON(t))}writeBinary(t){const{json:s,resources:e}=this.writeJSON(t,{basename:"",isGLB:!0,logger:this.bt}),r=JSON.stringify(s),i=d.pad(d.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=d.concat([n,i]),o=d.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=d.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return d.concat([a,h,c])}}class ht extends nt{constructor(){super(),this.St=require("fs"),this.It=require("path")}read(t){const s=this.readAsJSON(t);return Q.read(s,{extensions:this.ht,dependencies:this.Mt,logger:this.bt})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Rt(t):this.Ct(t)}write(t,s){t.match(/\.glb$/)?this.Nt(t,s):this._t(t,s)}Rt(t){const s=this.St.readFileSync(t),e=d.trim(s);return this.binaryToJSON(e)}Ct(t){const s=this.It.dirname(t),e={json:JSON.parse(this.St.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri)if(t.uri.match(/data:/)){const s=`__${E()}.${g.extension(t.uri)}`;e.resources[s]=d.createBufferFromDataURI(t.uri),t.uri=s}else{const r=this.It.resolve(s,t.uri);e.resources[t.uri]=d.trim(this.St.readFileSync(r))}}),e}_t(t,s){const{json:e,resources:r}=it.write(s,{basename:g.basename(t),isGLB:!1,logger:this.bt}),{St:i,It:n}=this,h=n.dirname(t);i.writeFileSync(t,JSON.stringify(e,null,2)),Object.keys(r).forEach(t=>{const s=Buffer.from(r[t]);i.writeFileSync(n.join(h,t),s)})}Nt(t,s){const e=Buffer.from(this.writeBinary(s));this.St.writeFileSync(t,e)}}const ot={};class ut extends nt{constructor(t=ot){super(),this.Bt=t}read(t){return this.readAsJSON(t).then(t=>this.readJSON(t))}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Rt(t):this.Ct(t)}Ct(t){const s={json:{},resources:{}};return fetch(t,this.Bt).then(t=>t.json()).then(t=>{s.json=t;const e=[...t.images||[],...t.buffers||[]].map(t=>{if(t.uri)return fetch(t.uri,this.Bt).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}Rt(t){return fetch(t,this.Bt).then(t=>t.arrayBuffer()).then(t=>this.binaryToJSON(t))}}export{R as Accessor,C as Animation,N as AnimationChannel,_ as AnimationSampler,B as Buffer,d as BufferUtils,b as COPY_IDENTITY,L as Camera,p as ColorUtils,H as Document,Y as Extension,O as ExtensionProperty,g as FileUtils,n as GLB_BUFFER,a as Graph,l as GraphChild,w as ImageUtils,u as Link,x as Logger,G as Material,v as MathUtils,j as Mesh,D as Node,ht as NodeIO,J as Primitive,$ as PrimitiveTarget,M as Property,h as PropertyType,Z as ReaderContext,z as Root,V as Scene,W as Skin,q as Texture,F as TextureInfo,ut as WebIO,st as WriterContext,E as uuid};
//# sourceMappingURL=core.modern.js.map

@@ -26,3 +26,9 @@ import { GraphNode } from './graph-node';

getChild(): Child;
/** Sets the child node. */
/**
* Sets the child node.
*
* @internal Only {@link Graph} implementations may safely call this method directly. Use
* {@link Property.swap} or {@link Graph.swapChild} instead.
* @hidden
*/
setChild(child: Child): this;

@@ -29,0 +35,0 @@ /** Destroys a (currently intact) link, updating both the graph and the owner. */

@@ -19,2 +19,3 @@ import { Link } from './graph-links';

disconnectParents(node: GraphNode, filter?: (n: GraphNode) => boolean): this;
swapChild(parent: GraphNode, prevChild: GraphNode, nextChild: GraphNode): this;
/**

@@ -21,0 +22,0 @@ * Creates a link between two {@link GraphNode} instances. Link is returned

{
"name": "@gltf-transform/core",
"version": "0.7.2",
"version": "0.7.3",
"repository": "github:donmccurdy/glTF-Transform",

@@ -42,3 +42,3 @@ "description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js",

},
"gitHead": "69fdd465707cb428d34dcc940a31c2cfebd54a32"
"gitHead": "4320ec99813721c975857fa9d25b13eaf3fb981f"
}

@@ -35,3 +35,9 @@ import { GraphNode } from './graph-node';

/** Sets the child node. */
/**
* Sets the child node.
*
* @internal Only {@link Graph} implementations may safely call this method directly. Use
* {@link Property.swap} or {@link Graph.swapChild} instead.
* @hidden
*/
setChild(child: Child): this {

@@ -38,0 +44,0 @@ this._child = child;

@@ -60,5 +60,3 @@ import { Graph } from './graph';

public swap(old: GraphNode, replacement: GraphNode): this {
this.graph.getLinks()
.filter((link) => link.getParent() === this && link.getChild() === old)
.forEach((link) => (link.setChild(replacement)));
this.graph.swapChild(this, old, replacement);
return this;

@@ -65,0 +63,0 @@ }

import { Link } from './graph-links';
import { GraphNode } from './graph-node';
const EMPTY_SET: Set<Link<GraphNode, GraphNode>> = new Set();
/**

@@ -13,4 +15,4 @@ * A graph manages a network of {@link GraphNode} nodes, connected

private _links: Set<Link<GraphNode, GraphNode>> = new Set();
private _parentRefs: Map<GraphNode, Link<GraphNode, GraphNode>[]> = new Map();
private _childRefs: Map<GraphNode, Link<GraphNode, GraphNode>[]> = new Map();
private _parentRefs: Map<GraphNode, Set<Link<GraphNode, GraphNode>>> = new Map();
private _childRefs: Map<GraphNode, Set<Link<GraphNode, GraphNode>>> = new Map();

@@ -22,13 +24,13 @@ public getLinks(): Link<GraphNode, GraphNode>[] {

public listParents(node: GraphNode): GraphNode[] {
const links = this._childRefs.get(node) || [];
return links.map((link) => link.getParent());
const links = this._childRefs.get(node) || EMPTY_SET;
return Array.from(links).map((link) => link.getParent());
}
public listChildren(node: GraphNode): GraphNode[] {
const links = this._parentRefs.get(node) || [];
return links.map((link) => link.getChild());
const links = this._parentRefs.get(node) || EMPTY_SET;
return Array.from(links).map((link) => link.getChild());
}
public disconnectChildren(node: GraphNode): this {
const links = this._parentRefs.get(node) || [];
const links = this._parentRefs.get(node) || EMPTY_SET;
links.forEach((link) => link.dispose());

@@ -39,3 +41,3 @@ return this;

public disconnectParents(node: GraphNode, filter?: (n: GraphNode) => boolean): this {
let links = this._childRefs.get(node) || [];
let links = Array.from(this._childRefs.get(node) || EMPTY_SET);
if (filter) {

@@ -48,2 +50,16 @@ links = links.filter((link) => filter(link.getParent()));

public swapChild(parent: GraphNode, prevChild: GraphNode, nextChild: GraphNode): this {
const links = this._parentRefs.get(parent) || EMPTY_SET;
Array.from(links)
.filter((link) => link.getChild() === prevChild)
.forEach((link) => {
this._childRefs.get(prevChild).delete(link);
link.setChild(nextChild);
if (!this._childRefs.has(nextChild)) this._childRefs.set(nextChild, new Set());
this._childRefs.get(nextChild).add(link);
});
return this;
}
/**

@@ -68,8 +84,8 @@ * Creates a link between two {@link GraphNode} instances. Link is returned

const parent = link.getParent();
if (!this._parentRefs.has(parent)) this._parentRefs.set(parent, []);
this._parentRefs.get(parent).push(link);
if (!this._parentRefs.has(parent)) this._parentRefs.set(parent, new Set());
this._parentRefs.get(parent).add(link);
const child = link.getChild();
if (!this._childRefs.has(child)) this._childRefs.set(child, []);
this._childRefs.get(child).push(link);
if (!this._childRefs.has(child)) this._childRefs.set(child, new Set());
this._childRefs.get(child).add(link);

@@ -88,13 +104,6 @@ link.onDispose(() => this.unlink(link));

this._links.delete(link);
const parentRefs = this._parentRefs.get(link.getParent())
.filter((_link) => link !== _link);
this._parentRefs.set(link.getParent(), parentRefs);
const childRefs = this._childRefs.get(link.getChild())
.filter((_link) => link !== _link);
this._childRefs.set(link.getChild(), childRefs);
this._parentRefs.get(link.getParent()).delete(link);
this._childRefs.get(link.getChild()).delete(link);
return this;
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc