Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gltf-transform/core

Package Overview
Dependencies
Maintainers
1
Versions
208
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.0 to 0.7.1

2

dist/constants.d.ts

@@ -47,3 +47,3 @@ /**

/** @hidden */
export declare const GLB_BUFFER = "__glb.bin";
export declare const GLB_BUFFER = "@glb.bin";
/**

@@ -50,0 +50,0 @@ * Abstraction representing any one of the typed array classes supported by glTF and JavaScript.

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

import{fromRotationTranslationScale as t,getTranslation as s,getRotation as e,getScaling as r,multiply as i}from"gl-matrix/mat4";function n(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}const h="__glb.bin";var o;!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"}(o||(o={}));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=[]}getLinks(){return this.u}listParents(t){return this.u.filter(s=>s.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(s=>s.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(s=>s.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=this.u.filter(s=>s.getChild()===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){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(s=>s!==t),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",T=new Set,y=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=y();if(!T.has(t))return T.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.l={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,E)}copy(t,s){return this.t=t.t,this.l=JSON.parse(JSON.stringify(t.l)),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.p(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}n([l],S.prototype,"extensions",void 0);class I extends S{constructor(){super(...arguments),this.propertyType=o.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.T=!1,this.A=m.identity,this.M=m.identity,this.buffer=null}copy(t,s=E){return super.copy(t,s),this.g=t.g.slice(),this.m=t.m,this.v=t.v,this.T=t.T,this.A=t.A,this.M=t.M,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.M(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.g[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.M(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.g[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.g.length/this.getElementSize()}getType(){return this.m}setType(t){return this.m=t,this}getElementSize(){return I.getElementSize(this.m)}getComponentSize(){return this.g.BYTES_PER_ELEMENT}getComponentType(){return this.v}getNormalized(){return this.T}setNormalized(t){return this.T=t,t?(this.M=t=>m.denormalize(t,this.v),this.A=t=>m.normalize(t,this.v)):(this.M=m.identity,this.A=m.identity),this}getScalar(t){const s=this.getElementSize();return this.M(this.g[t*s])}setScalar(t,s){return this.g[t*this.getElementSize()]=this.A(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.M(this.g[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.g[t*e+r]=this.A(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.g}setArray(t){return this.v=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.g=t,this}getByteLength(){return this.g.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},n([a],I.prototype,"buffer",void 0);class R extends S{constructor(){super(...arguments),this.propertyType=o.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())}}n([l],R.prototype,"channels",void 0),n([l],R.prototype,"samplers",void 0);class N extends b{constructor(){super(...arguments),this.propertyType=o.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=E){return super.copy(t,s),this.S=t.S,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.S}setTargetPath(t){return this.S=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}}n([a],N.prototype,"targetNode",void 0),n([a],N.prototype,"sampler",void 0);class C extends b{constructor(){super(...arguments),this.propertyType=o.ANIMATION_SAMPLER,this.I="LINEAR",this.input=null,this.output=null}copy(t,s=E){return super.copy(t,s),this.I=t.I,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.I}setInterpolation(t){return this.I=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}}n([a],C.prototype,"input",void 0),n([a],C.prototype,"output",void 0);class _ extends S{constructor(){super(...arguments),this.propertyType=o.BUFFER}copy(t,s=E){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class B extends S{constructor(){super(...arguments),this.propertyType=o.CAMERA,this.m="perspective"}copy(t,s=E){return super.copy(t,s),this.m=t.m,this.N=t.N,this.C=t.C,this._=t._,this.B=t.B,this.L=t.L,this.O=t.O,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.N}setZNear(t){return this.N=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.B}setYFov(t){return this.B=t,this}getXMag(){return this.L}setXMag(t){return this.L=t,this}getYMag(){return this.O}setYMag(t){return this.O=t,this}}class L extends b{constructor(t,s){super(t),this.U=s,this.U.addExtensionProperty(this)}dispose(){this.U.removeExtensionProperty(this),super.dispose()}p(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=o.TEXTURE_INFO,this.k=0,this.P=null,this.F=null,this.G=10497,this.j=10497}copy(t){return this.k=t.k,this.P=t.P,this.F=t.F,this.G=t.G,this.j=t.j,this}getTexCoord(){return this.k}setTexCoord(t){return this.k=t,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.F}setMinFilter(t){return this.F=t,this}getWrapS(){return this.G}setWrapS(t){return this.G=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=o.MATERIAL,this.D="OPAQUE",this.J=.5,this.$=!1,this.V=[1,1,1,1],this.W=[0,0,0],this.q=1,this.H=1,this.Y=1,this.Z=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.D=t.D,this.J=t.J,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,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()))),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()))),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()))),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()))),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()))),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.$}setDoubleSided(t){return this.$=t,this}getAlpha(){return this.V[3]}setAlpha(t){return this.V[3]=t,this}getAlphaMode(){return this.D}setAlphaMode(t){return this.D=t,this}getAlphaCutoff(){return this.J}setAlphaCutoff(t){return this.J=t,this}getBaseColorFactor(){return this.V}setBaseColorFactor(t){return this.V=t,this}getBaseColorHex(){return d.factorToHex(this.V)}setBaseColorHex(t){return d.hexToFactor(t,this.V),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.W}setEmissiveFactor(t){return this.W=t,this}getEmissiveHex(){return d.factorToHex(this.W)}setEmissiveHex(t){return d.hexToFactor(t,this.W),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.q}setNormalScale(t){return this.q=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.H}setOcclusionStrength(t){return this.H=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.Y}setRoughnessFactor(t){return this.Y=t,this}getMetallicFactor(){return this.Z}setMetallicFactor(t){return this.Z=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}}n([a],F.prototype,"baseColorTexture",void 0),n([a],F.prototype,"baseColorTextureInfo",void 0),n([a],F.prototype,"emissiveTexture",void 0),n([a],F.prototype,"emissiveTextureInfo",void 0),n([a],F.prototype,"normalTexture",void 0),n([a],F.prototype,"normalTextureInfo",void 0),n([a],F.prototype,"occlusionTexture",void 0),n([a],F.prototype,"occlusionTextureInfo",void 0),n([a],F.prototype,"metallicRoughnessTexture",void 0),n([a],F.prototype,"metallicRoughnessTextureInfo",void 0);class G extends S{constructor(){super(...arguments),this.propertyType=o.MESH,this.X=[],this.primitives=[]}copy(t,s=E){return super.copy(t,s),this.X=[...t.X],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.X}setWeights(t){return this.X=t,this}}n([l],G.prototype,"primitives",void 0);class j extends S{constructor(){super(...arguments),this.propertyType=o.NODE,this.K=[0,0,0],this.tt=[0,0,0,1],this.st=[1,1,1],this.X=[],this.s=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=E){return super.copy(t,s),this.K=[...t.K],this.tt=[...t.tt],this.st=[...t.st],this.X=[...t.X],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.K}getRotation(){return this.tt}getScale(){return this.st}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.st=t,this}getMatrix(){return t([],this.tt,this.K,this.st)}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.X}setWeights(t){return this.X=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}n([a],j.prototype,"camera",void 0),n([a],j.prototype,"mesh",void 0),n([a],j.prototype,"skin",void 0),n([l],j.prototype,"children",void 0);class D extends b{constructor(){super(...arguments),this.propertyType=o.PRIMITIVE,this.et=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=E){return super.copy(t,s),this.et=t.et,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.et}setMode(t){return this.et=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)}}n([a],D.prototype,"material",void 0),n([a],D.prototype,"indices",void 0),n([l],D.prototype,"attributes",void 0),n([l],D.prototype,"targets",void 0);class J extends b{constructor(){super(...arguments),this.propertyType=o.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)}}n([l],J.prototype,"attributes",void 0);class $ extends b{constructor(){super(...arguments),this.propertyType=o.ROOT,this.rt={generator:"glTF-Transform v0.7.0",version:"2.0"},this.it=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.rt,t.rt),t.accessors.forEach(t=>this.nt(s(t.getChild()))),t.animations.forEach(t=>this.ht(s(t.getChild()))),t.buffers.forEach(t=>this.ot(s(t.getChild()))),t.cameras.forEach(t=>this.ut(s(t.getChild()))),t.materials.forEach(t=>this.ct(s(t.getChild()))),t.meshes.forEach(t=>this.at(s(t.getChild()))),t.nodes.forEach(t=>this.lt(s(t.getChild()))),t.scenes.forEach(t=>this.ft(s(t.getChild()))),t.skins.forEach(t=>this.dt(s(t.getChild()))),t.textures.forEach(t=>this.pt(s(t.getChild()))),this}getAsset(){return this.rt}listExtensionsUsed(){return Array.from(this.it)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}gt(t){if(this.it.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.it.add(t),this}wt(t){return this.it.delete(t),this}ft(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}at(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}pt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}n([l],$.prototype,"accessors",void 0),n([l],$.prototype,"animations",void 0),n([l],$.prototype,"buffers",void 0),n([l],$.prototype,"cameras",void 0),n([l],$.prototype,"materials",void 0),n([l],$.prototype,"meshes",void 0),n([l],$.prototype,"nodes",void 0),n([l],$.prototype,"scenes",void 0),n([l],$.prototype,"skins",void 0),n([l],$.prototype,"textures",void 0);class z extends S{constructor(){super(...arguments),this.propertyType=o.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}}n([l],z.prototype,"children",void 0);class V extends S{constructor(){super(...arguments),this.propertyType=o.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())}}n([a],V.prototype,"skeleton",void 0),n([a],V.prototype,"inverseBindMatrices",void 0),n([l],V.prototype,"joints",void 0);class W extends S{constructor(){super(...arguments),this.propertyType=o.TEXTURE,this.vt=null,this.xt="",this.R=""}copy(t,s=E){return super.copy(t,s),this.xt=t.xt,this.R=t.R,t.vt&&(this.vt=t.vt.slice(0)),this}getMimeType(){return this.xt}setMimeType(t){return this.xt=t,this}getURI(){return this.R}setURI(t){return this.R=t,this}getImage(){return this.vt}setImage(t){return this.vt=t,this}getSize(){let t;return t=this.xt?"image/png"===this.xt:this.R.match(/\.png$/),t?g.getSizePNG(this.vt):g.getSizeJPEG(this.vt)}}class q{constructor(){this.Tt=new k,this.yt=new $(this.Tt),this.At=v.DEFAULT_INSTANCE}getRoot(){return this.yt}getGraph(){return this.Tt}getLogger(){return this.At}setLogger(t){return this.At=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.yt),r.set(t.yt,this.yt);for(const i of t.Tt.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof L?new i(this.Tt,s[t.extensionName]):new i(this.Tt);r.set(t,n),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.Tt,t);return this.yt.ft(s),s}createNode(t=""){const s=new j(this.Tt,t);return this.yt.lt(s),s}createCamera(t=""){const s=new B(this.Tt,t);return this.yt.ut(s),s}createSkin(t=""){const s=new V(this.Tt,t);return this.yt.dt(s),s}createMesh(t=""){const s=new G(this.Tt,t);return this.yt.at(s),s}createPrimitive(){return new D(this.Tt)}createPrimitiveTarget(t=""){return new J(this.Tt,t)}createMaterial(t=""){const s=new F(this.Tt,t);return this.yt.ct(s),s}createTexture(t=""){const s=new W(this.Tt,t);return this.yt.pt(s),s}createAnimation(t=""){const s=new R(this.Tt,t);return this.yt.ht(s),s}createAnimationChannel(t=""){return new N(this.Tt,t)}createAnimationSampler(t=""){return new C(this.Tt,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new I(this.Tt,t).setBuffer(s);return this.yt.nt(e),e}createBuffer(t=""){const s=new _(this.Tt,t);return this.yt.ot(s),s}}class H{constructor(t){this.doc=t,this.provideTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().gt(this)}dispose(){this.doc.getRoot().wt(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,h=new q;this.validate(t,i);const u=new Y(t),c=t.json.asset,a=h.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=h.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=h.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=h.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||[];h.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(o.TEXTURE)).forEach(t=>t.provide(u,o.TEXTURE)),u.textures=d.map(s=>{const e=h.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["Et"]).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=h.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||[];h.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(o.PRIMITIVE)).forEach(t=>t.provide(u,o.PRIMITIVE)),u.meshes=m.map(t=>{const s=h.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=h.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=h.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=h.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=h.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=h.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=h.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=h.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=h.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=h.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addChild(t)),s}),h.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),h}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["Et"],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["Et"],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.0";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.At=v.DEFAULT_INSTANCE,this.it=[],this.bt={}}setLogger(t){return this.At=t,this}registerExtensions(t){return this.it.push(...t),this}registerDependencies(t){return Object.assign(this.bt,t),this}readJSON(t){return K.read(t,{extensions:this.it,dependencies:this.bt,logger:this.At})}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:{Et: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.At}),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.Mt=require("fs"),this.St=require("path")}read(t){const s=this.readAsJSON(t);return K.read(s,{extensions:this.it,dependencies:this.bt,logger:this.At})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.It(t):this.Rt(t)}write(t,s){t.match(/\.glb$/)?this.Nt(t,s):this.Ct(t,s)}It(t){const s=this.Mt.readFileSync(t),e=f.trim(s);return this.binaryToJSON(e)}Rt(t){const s=this.St.dirname(t),e={json:JSON.parse(this.Mt.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.St.resolve(s,t.uri);e.resources[t.uri]=f.trim(this.Mt.readFileSync(r))}}),e}Ct(t,s){const{json:e,resources:r}=rt.write(s,{basename:p.basename(t),isGLB:!1,logger:this.At}),{Mt:i,St: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.Mt.writeFileSync(t,e)}}const ht={};class ot extends it{constructor(t=ht){super(),this._t=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.It(t):this.Rt(t)}Rt(t){const s={json:{},resources:{}};return fetch(t,this._t).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._t).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}It(t){return fetch(t,this._t).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,h 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,o 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";function n(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}const h="@glb.bin";var o;!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"}(o||(o={}));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=[]}getLinks(){return this.u}listParents(t){return this.u.filter(s=>s.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(s=>s.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(s=>s.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=this.u.filter(s=>s.getChild()===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){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(s=>s!==t),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",T=new Set,y=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=y();if(!T.has(t))return T.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.l={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,E)}copy(t,s){return this.t=t.t,this.l=JSON.parse(JSON.stringify(t.l)),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.p(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}n([l],S.prototype,"extensions",void 0);class I extends S{constructor(){super(...arguments),this.propertyType=o.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.T=!1,this.A=m.identity,this.M=m.identity,this.buffer=null}copy(t,s=E){return super.copy(t,s),this.g=t.g.slice(),this.m=t.m,this.v=t.v,this.T=t.T,this.A=t.A,this.M=t.M,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.M(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.g[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.M(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.g[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.g.length/this.getElementSize()}getType(){return this.m}setType(t){return this.m=t,this}getElementSize(){return I.getElementSize(this.m)}getComponentSize(){return this.g.BYTES_PER_ELEMENT}getComponentType(){return this.v}getNormalized(){return this.T}setNormalized(t){return this.T=t,t?(this.M=t=>m.denormalize(t,this.v),this.A=t=>m.normalize(t,this.v)):(this.M=m.identity,this.A=m.identity),this}getScalar(t){const s=this.getElementSize();return this.M(this.g[t*s])}setScalar(t,s){return this.g[t*this.getElementSize()]=this.A(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.M(this.g[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.g[t*e+r]=this.A(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.g}setArray(t){return this.v=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.g=t,this}getByteLength(){return this.g.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},n([a],I.prototype,"buffer",void 0);class R extends S{constructor(){super(...arguments),this.propertyType=o.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())}}n([l],R.prototype,"channels",void 0),n([l],R.prototype,"samplers",void 0);class N extends b{constructor(){super(...arguments),this.propertyType=o.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=E){return super.copy(t,s),this.S=t.S,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.S}setTargetPath(t){return this.S=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}}n([a],N.prototype,"targetNode",void 0),n([a],N.prototype,"sampler",void 0);class C extends b{constructor(){super(...arguments),this.propertyType=o.ANIMATION_SAMPLER,this.I="LINEAR",this.input=null,this.output=null}copy(t,s=E){return super.copy(t,s),this.I=t.I,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.I}setInterpolation(t){return this.I=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}}n([a],C.prototype,"input",void 0),n([a],C.prototype,"output",void 0);class _ extends S{constructor(){super(...arguments),this.propertyType=o.BUFFER}copy(t,s=E){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class B extends S{constructor(){super(...arguments),this.propertyType=o.CAMERA,this.m="perspective"}copy(t,s=E){return super.copy(t,s),this.m=t.m,this.N=t.N,this.C=t.C,this._=t._,this.B=t.B,this.L=t.L,this.O=t.O,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.N}setZNear(t){return this.N=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.B}setYFov(t){return this.B=t,this}getXMag(){return this.L}setXMag(t){return this.L=t,this}getYMag(){return this.O}setYMag(t){return this.O=t,this}}class L extends b{constructor(t,s){super(t),this.U=s,this.U.addExtensionProperty(this)}dispose(){this.U.removeExtensionProperty(this),super.dispose()}p(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=o.TEXTURE_INFO,this.k=0,this.P=null,this.F=null,this.G=10497,this.j=10497}copy(t){return this.k=t.k,this.P=t.P,this.F=t.F,this.G=t.G,this.j=t.j,this}getTexCoord(){return this.k}setTexCoord(t){return this.k=t,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.F}setMinFilter(t){return this.F=t,this}getWrapS(){return this.G}setWrapS(t){return this.G=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=o.MATERIAL,this.D="OPAQUE",this.J=.5,this.$=!1,this.V=[1,1,1,1],this.W=[0,0,0],this.q=1,this.H=1,this.Y=1,this.Z=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.D=t.D,this.J=t.J,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,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()))),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()))),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()))),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()))),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()))),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.$}setDoubleSided(t){return this.$=t,this}getAlpha(){return this.V[3]}setAlpha(t){return this.V[3]=t,this}getAlphaMode(){return this.D}setAlphaMode(t){return this.D=t,this}getAlphaCutoff(){return this.J}setAlphaCutoff(t){return this.J=t,this}getBaseColorFactor(){return this.V}setBaseColorFactor(t){return this.V=t,this}getBaseColorHex(){return d.factorToHex(this.V)}setBaseColorHex(t){return d.hexToFactor(t,this.V),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.W}setEmissiveFactor(t){return this.W=t,this}getEmissiveHex(){return d.factorToHex(this.W)}setEmissiveHex(t){return d.hexToFactor(t,this.W),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.q}setNormalScale(t){return this.q=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.H}setOcclusionStrength(t){return this.H=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.Y}setRoughnessFactor(t){return this.Y=t,this}getMetallicFactor(){return this.Z}setMetallicFactor(t){return this.Z=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}}n([a],F.prototype,"baseColorTexture",void 0),n([a],F.prototype,"baseColorTextureInfo",void 0),n([a],F.prototype,"emissiveTexture",void 0),n([a],F.prototype,"emissiveTextureInfo",void 0),n([a],F.prototype,"normalTexture",void 0),n([a],F.prototype,"normalTextureInfo",void 0),n([a],F.prototype,"occlusionTexture",void 0),n([a],F.prototype,"occlusionTextureInfo",void 0),n([a],F.prototype,"metallicRoughnessTexture",void 0),n([a],F.prototype,"metallicRoughnessTextureInfo",void 0);class G extends S{constructor(){super(...arguments),this.propertyType=o.MESH,this.X=[],this.primitives=[]}copy(t,s=E){return super.copy(t,s),this.X=[...t.X],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.X}setWeights(t){return this.X=t,this}}n([l],G.prototype,"primitives",void 0);class j extends S{constructor(){super(...arguments),this.propertyType=o.NODE,this.K=[0,0,0],this.tt=[0,0,0,1],this.st=[1,1,1],this.X=[],this.s=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=E){return super.copy(t,s),this.K=[...t.K],this.tt=[...t.tt],this.st=[...t.st],this.X=[...t.X],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.K}getRotation(){return this.tt}getScale(){return this.st}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.st=t,this}getMatrix(){return t([],this.tt,this.K,this.st)}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.X}setWeights(t){return this.X=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}n([a],j.prototype,"camera",void 0),n([a],j.prototype,"mesh",void 0),n([a],j.prototype,"skin",void 0),n([l],j.prototype,"children",void 0);class D extends b{constructor(){super(...arguments),this.propertyType=o.PRIMITIVE,this.et=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=E){return super.copy(t,s),this.et=t.et,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.et}setMode(t){return this.et=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)}}n([a],D.prototype,"material",void 0),n([a],D.prototype,"indices",void 0),n([l],D.prototype,"attributes",void 0),n([l],D.prototype,"targets",void 0);class J extends b{constructor(){super(...arguments),this.propertyType=o.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)}}n([l],J.prototype,"attributes",void 0);class $ extends b{constructor(){super(...arguments),this.propertyType=o.ROOT,this.rt={generator:"glTF-Transform v0.7.1",version:"2.0"},this.it=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.rt,t.rt),t.accessors.forEach(t=>this.nt(s(t.getChild()))),t.animations.forEach(t=>this.ht(s(t.getChild()))),t.buffers.forEach(t=>this.ot(s(t.getChild()))),t.cameras.forEach(t=>this.ut(s(t.getChild()))),t.materials.forEach(t=>this.ct(s(t.getChild()))),t.meshes.forEach(t=>this.at(s(t.getChild()))),t.nodes.forEach(t=>this.lt(s(t.getChild()))),t.scenes.forEach(t=>this.ft(s(t.getChild()))),t.skins.forEach(t=>this.dt(s(t.getChild()))),t.textures.forEach(t=>this.pt(s(t.getChild()))),this}getAsset(){return this.rt}listExtensionsUsed(){return Array.from(this.it)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}gt(t){if(this.it.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.it.add(t),this}wt(t){return this.it.delete(t),this}ft(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}at(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}pt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}n([l],$.prototype,"accessors",void 0),n([l],$.prototype,"animations",void 0),n([l],$.prototype,"buffers",void 0),n([l],$.prototype,"cameras",void 0),n([l],$.prototype,"materials",void 0),n([l],$.prototype,"meshes",void 0),n([l],$.prototype,"nodes",void 0),n([l],$.prototype,"scenes",void 0),n([l],$.prototype,"skins",void 0),n([l],$.prototype,"textures",void 0);class z extends S{constructor(){super(...arguments),this.propertyType=o.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}}n([l],z.prototype,"children",void 0);class V extends S{constructor(){super(...arguments),this.propertyType=o.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())}}n([a],V.prototype,"skeleton",void 0),n([a],V.prototype,"inverseBindMatrices",void 0),n([l],V.prototype,"joints",void 0);class W extends S{constructor(){super(...arguments),this.propertyType=o.TEXTURE,this.vt=null,this.xt="",this.R=""}copy(t,s=E){return super.copy(t,s),this.xt=t.xt,this.R=t.R,t.vt&&(this.vt=t.vt.slice(0)),this}getMimeType(){return this.xt}setMimeType(t){return this.xt=t,this}getURI(){return this.R}setURI(t){return this.R=t,this}getImage(){return this.vt}setImage(t){return this.vt=t,this}getSize(){let t;return t=this.xt?"image/png"===this.xt:this.R.match(/\.png$/),t?g.getSizePNG(this.vt):g.getSizeJPEG(this.vt)}}class q{constructor(){this.Tt=new k,this.yt=new $(this.Tt),this.At=v.DEFAULT_INSTANCE}getRoot(){return this.yt}getGraph(){return this.Tt}getLogger(){return this.At}setLogger(t){return this.At=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.yt),r.set(t.yt,this.yt);for(const i of t.Tt.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof L?new i(this.Tt,s[t.extensionName]):new i(this.Tt);r.set(t,n),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.Tt,t);return this.yt.ft(s),s}createNode(t=""){const s=new j(this.Tt,t);return this.yt.lt(s),s}createCamera(t=""){const s=new B(this.Tt,t);return this.yt.ut(s),s}createSkin(t=""){const s=new V(this.Tt,t);return this.yt.dt(s),s}createMesh(t=""){const s=new G(this.Tt,t);return this.yt.at(s),s}createPrimitive(){return new D(this.Tt)}createPrimitiveTarget(t=""){return new J(this.Tt,t)}createMaterial(t=""){const s=new F(this.Tt,t);return this.yt.ct(s),s}createTexture(t=""){const s=new W(this.Tt,t);return this.yt.pt(s),s}createAnimation(t=""){const s=new R(this.Tt,t);return this.yt.ht(s),s}createAnimationChannel(t=""){return new N(this.Tt,t)}createAnimationSampler(t=""){return new C(this.Tt,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new I(this.Tt,t).setBuffer(s);return this.yt.nt(e),e}createBuffer(t=""){const s=new _(this.Tt,t);return this.yt.ot(s),s}}class H{constructor(t){this.doc=t,this.provideTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().gt(this)}dispose(){this.doc.getRoot().wt(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,h=new q;this.validate(t,i);const u=new Y(t),c=t.json.asset,a=h.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=h.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=h.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=h.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||[];h.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(o.TEXTURE)).forEach(t=>t.provide(u,o.TEXTURE)),u.textures=d.map(s=>{const e=h.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=h.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||[];h.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(o.PRIMITIVE)).forEach(t=>t.provide(u,o.PRIMITIVE)),u.meshes=m.map(t=>{const s=h.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=h.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=h.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=h.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=h.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=h.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=h.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=h.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=h.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=h.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addChild(t)),s}),h.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),h}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.1";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.At=v.DEFAULT_INSTANCE,this.it=[],this.Et={}}setLogger(t){return this.At=t,this}registerExtensions(t){return this.it.push(...t),this}registerDependencies(t){return Object.assign(this.Et,t),this}readJSON(t){return K.read(t,{extensions:this.it,dependencies:this.Et,logger:this.At})}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.At}),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.bt=require("fs"),this.Mt=require("path")}read(t){const s=this.readAsJSON(t);return K.read(s,{extensions:this.it,dependencies:this.Et,logger:this.At})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.St(t):this.It(t)}write(t,s){t.match(/\.glb$/)?this.Rt(t,s):this.Nt(t,s)}St(t){const s=this.bt.readFileSync(t),e=f.trim(s);return this.binaryToJSON(e)}It(t){const s=this.Mt.dirname(t),e={json:JSON.parse(this.bt.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.Mt.resolve(s,t.uri);e.resources[t.uri]=f.trim(this.bt.readFileSync(r))}}),e}Nt(t,s){const{json:e,resources:r}=rt.write(s,{basename:p.basename(t),isGLB:!1,logger:this.At}),{bt:i,Mt: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)})}Rt(t,s){const e=Buffer.from(this.writeBinary(s));this.bt.writeFileSync(t,e)}}const ht={};class ot extends it{constructor(t=ht){super(),this.Ct=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.St(t):this.It(t)}It(t){const s={json:{},resources:{}};return fetch(t,this.Ct).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.Ct).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}St(t){return fetch(t,this.Ct).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,h 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,o 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};
//# sourceMappingURL=core.modern.js.map
{
"name": "@gltf-transform/core",
"version": "0.7.0",
"version": "0.7.1",
"repository": "github:donmccurdy/glTF-Transform",

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

},
"gitHead": "99398201271e9a8007c89c1981a1be3a71681979"
"gitHead": "6d8429266bc58b1956a0b010c13f490562d164ba"
}

@@ -67,3 +67,3 @@ // Injected at compile time, from $npm_package_version.

/** @hidden */
export const GLB_BUFFER = '__glb.bin';
export const GLB_BUFFER = '@glb.bin';

@@ -70,0 +70,0 @@ /**

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