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.5.3 to 0.5.4

2

dist/core.modern.js

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

import{getTranslation as t,getRotation as s,getScaling as e}from"gl-matrix/mat4";function r(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}var i;!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",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{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 h{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 n(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 o(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 u(t,s){}class c{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 a{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 l{static getSizeJPEG(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),d(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"===c.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 d(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 f{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 p{constructor(t){this.verbosity=t}debug(t){this.verbosity<=p.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=p.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=p.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=p.Verbosity.ERROR&&console.error(t)}}p.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const g="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",m=new Set,w=function(){let t="";for(let s=0;s<6;s++)t+=g.charAt(Math.floor(Math.random()*g.length));return t},v=function(){for(let t=0;t<999;t++){const t=w();if(!m.has(t))return m.add(t),t}},y=t=>t;class x 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,y)}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()}}class T extends x{constructor(){super(...arguments),this.extensions=[]}copy(t,s=y){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.constructor,s(e))}),this}getExtension(t){const s=t.EXTENSION_NAME,e=this.extensions.find(t=>t.getChild().extensionName===s);return e?e.getChild():null}setExtension(t,s){const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.p(this),this.addGraphChild(this.extensions,this.graph.link(s.extensionName,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],T.prototype,"extensions",void 0);class A extends T{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.T=!1,this.A=f.identity,this.M=f.identity,this.buffer=null}copy(t,s=y){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 A.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=>f.denormalize(t,this.v),this.A=t=>f.normalize(t,this.v)):(this.M=f.identity,this.A=f.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.getChild()}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}}A.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},A.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},r([o],A.prototype,"buffer",void 0);class E extends T{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=y){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())}}r([u],E.prototype,"channels",void 0),r([u],E.prototype,"samplers",void 0);class b extends x{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=y){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}}r([o],b.prototype,"targetNode",void 0),r([o],b.prototype,"sampler",void 0);class M extends x{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,this.N="LINEAR",this.input=null,this.output=null}copy(t,s=y){return super.copy(t,s),this.N=t.N,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],M.prototype,"input",void 0),r([o],M.prototype,"output",void 0);class S extends T{constructor(){super(...arguments),this.propertyType=i.BUFFER}copy(t,s=y){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class N extends T{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}copy(t,s=y){return super.copy(t,s),this.m=t.m,this.I=t.I,this.C=t.C,this._=t._,this.k=t.k,this.B=t.B,this.L=t.L,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=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.k}setYFov(t){return this.k=t,this}getXMag(){return this.B}setXMag(t){return this.B=t,this}getYMag(){return this.L}setYMag(t){return this.L=t,this}}class R extends x{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 I{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}copy(t){return this.texCoord=t.texCoord,this}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class C{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.D=10497}copy(t){return this.P=t.P,this.O=t.O,this.F=t.F,this.D=t.D,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.O}setMinFilter(t){return this.O=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.D}setWrapT(t){return this.D=t,this}}C.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},C.TextureMagFilter={NEAREST:9728,LINEAR:9729},C.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class _ extends n{constructor(){super(...arguments),this.textureInfo=new I,this.sampler=new C}copy(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this}}class k extends n{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class B extends n{copy(t){return this}}class L extends h{linkTexture(t,s,e){if(!e)return null;const r=new _(t,s,e);return this.registerLink(r),r}linkAttribute(t,s,e){if(!e)return null;const r=new k(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new B(t,s,e);return this.registerLink(r),r}}class U extends T{constructor(){super(...arguments),this.propertyType=i.MATERIAL,this.G="OPAQUE",this.j=.5,this.$=!1,this.V=[1,1,1,1],this.J=[0,0,0],this.W=1,this.Y=1,this.q=1,this.Z=1,this.baseColorTexture=null,this.emissiveTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.metallicRoughnessTexture=null}copy(t,s=y){return super.copy(t,s),this.G=t.G,this.j=t.j,this.$=t.$,this.V=[...t.V],this.J=[...t.J],this.W=t.W,this.Y=t.Y,this.q=t.q,this.Z=t.Z,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.baseColorTexture.copy(t.baseColorTexture)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.emissiveTexture.copy(t.emissiveTexture)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.normalTexture.copy(t.normalTexture)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.occlusionTexture.copy(t.occlusionTexture)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(t.metallicRoughnessTexture)),this}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=t,this}getAlphaMode(){return this.G}setAlphaMode(t){return this.G=t,this}getAlphaCutoff(){return this.j}setAlphaCutoff(t){return this.j=t,this}getBaseColorFactor(){return this.V}setBaseColorFactor(t){return this.V=t,this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null}getBaseColorTextureSampler(){return this.baseColorTexture?this.baseColorTexture.sampler:null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",this,t),this}getEmissiveFactor(){return this.J}setEmissiveFactor(t){return this.J=t,this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null}getEmissiveTextureSampler(){return this.emissiveTexture?this.emissiveTexture.sampler:null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",this,t),this}getNormalScale(){return this.W}setNormalScale(t){return this.W=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTexture.textureInfo:null}getNormalTextureSampler(){return this.normalTexture?this.normalTexture.sampler:null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.q}setRoughnessFactor(t){return this.q=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.metallicRoughnessTexture.textureInfo:null}getMetallicRoughnessTextureSampler(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this}}r([o],U.prototype,"baseColorTexture",void 0),r([o],U.prototype,"emissiveTexture",void 0),r([o],U.prototype,"normalTexture",void 0),r([o],U.prototype,"occlusionTexture",void 0),r([o],U.prototype,"metallicRoughnessTexture",void 0);class P extends T{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}copy(t,s=y){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}}r([u],P.prototype,"primitives",void 0);class O extends T{constructor(){super(...arguments),this.propertyType=i.NODE,this.H=[0,0,0],this.K=[0,0,0,1],this.tt=[1,1,1],this.X=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=y){return super.copy(t,s),this.H=[...t.H],this.K=[...t.K],this.tt=[...t.tt],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())),this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild()))),this}getTranslation(){return this.H}getRotation(){return this.K}getScale(){return this.tt}setTranslation(t){return this.H=t,this}setRotation(t){return this.K=t,this}setScale(t){return this.tt=t,this}addChild(t){const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}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}}r([o],O.prototype,"camera",void 0),r([o],O.prototype,"mesh",void 0),r([o],O.prototype,"skin",void 0),r([u],O.prototype,"children",void 0);class F extends x{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE,this.st=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=y){return super.copy(t,s),this.st=t.st,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.st}setMode(t){return this.st=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)}}r([o],F.prototype,"material",void 0),r([o],F.prototype,"indices",void 0),r([u],F.prototype,"attributes",void 0),r([u],F.prototype,"targets",void 0);class D extends x{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=y){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)}}r([u],D.prototype,"attributes",void 0);class G extends x{constructor(){super(...arguments),this.propertyType=i.ROOT,this.et={generator:"glTF-Transform v0.5.3",version:"2.0"},this.rt=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=y){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.et,t.et),t.accessors.forEach(t=>this.it(s(t.getChild()))),t.animations.forEach(t=>this.nt(s(t.getChild()))),t.buffers.forEach(t=>this.ht(s(t.getChild()))),t.cameras.forEach(t=>this.ot(s(t.getChild()))),t.materials.forEach(t=>this.ut(s(t.getChild()))),t.meshes.forEach(t=>this.ct(s(t.getChild()))),t.nodes.forEach(t=>this.at(s(t.getChild()))),t.scenes.forEach(t=>this.lt(s(t.getChild()))),t.skins.forEach(t=>this.dt(s(t.getChild()))),t.textures.forEach(t=>this.ft(s(t.getChild()))),this}getAsset(){return this.et}listExtensionsUsed(){return Array.from(this.rt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}pt(t){if(this.rt.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.rt.add(t),this}gt(t){return this.rt.delete(t),this}lt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ot(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())}ct(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}it(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],G.prototype,"accessors",void 0),r([u],G.prototype,"animations",void 0),r([u],G.prototype,"buffers",void 0),r([u],G.prototype,"cameras",void 0),r([u],G.prototype,"materials",void 0),r([u],G.prototype,"meshes",void 0),r([u],G.prototype,"nodes",void 0),r([u],G.prototype,"scenes",void 0),r([u],G.prototype,"skins",void 0),r([u],G.prototype,"textures",void 0);class j extends T{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}copy(t,s=y){return super.copy(t,s),this.clearGraphChildList(this.nodes),t.nodes.forEach(t=>this.addNode(s(t.getChild()))),this}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],j.prototype,"nodes",void 0);class $ extends T{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=y){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())}}r([o],$.prototype,"skeleton",void 0),r([o],$.prototype,"inverseBindMatrices",void 0),r([u],$.prototype,"joints",void 0);class z extends T{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}copy(t,s=y){return super.copy(t,s),this.mimeType=t.mimeType,this.uri=t.uri,t.image&&(this.image=t.image.slice(0)),this}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?l.getSizePNG(this.image):l.getSizeJPEG(this.image)}}class V{constructor(){this.graph=new L,this.root=new G(this.graph),this.logger=new p(p.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){return(new V).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.root),r.set(t.root,this.root);for(const i of t.graph.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof R?new i(this.graph,s[t.extensionName]):new i(this.graph);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 j(this.graph,t);return this.root.lt(s),s}createNode(t=""){const s=new O(this.graph,t);return this.root.at(s),s}createCamera(t=""){const s=new N(this.graph,t);return this.root.ot(s),s}createSkin(t=""){const s=new $(this.graph,t);return this.root.dt(s),s}createMesh(t=""){const s=new P(this.graph,t);return this.root.ct(s),s}createPrimitive(){return new F(this.graph)}createPrimitiveTarget(t=""){return new D(this.graph,t)}createMaterial(t=""){const s=new U(this.graph,t);return this.root.ut(s),s}createTexture(t=""){const s=new z(this.graph,t);return this.root.ft(s),s}createAnimation(t=""){const s=new E(this.graph,t);return this.root.nt(s),s}createAnimationChannel(){return new b(this.graph)}createAnimationSampler(){return new M(this.graph)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new A(this.graph,t).setBuffer(s);return this.root.it(e),e}createBuffer(t=""){const s=new S(this.graph,t);return this.root.ht(s),s}}class J{constructor(t){this.doc=t,this.provideTypes=[],this.wt=!1,this.vt=new Set,t.getRoot().pt(this)}dispose(){this.doc.getRoot().gt(this);for(const t of this.vt)t.dispose()}isRequired(){return this.wt}setRequired(t){return this.wt=t,this}addExtensionProperty(t){return this.vt.add(t),this}removeExtensionProperty(t){return this.vt.delete(t),this}provide(t,s){return this}}class W{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){void 0!==s.texCoord&&t.setTexCoord(s.texCoord)}setTextureSampler(t,s){const e=this.nativeDocument.json.textures[s.index];if(void 0===e.sampler)return;const r=this.nativeDocument.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 Y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class q{static read(r,n){const{json:h}=r,o=new V;if("2.0"!==h.asset.version)throw new Error(`Unsupported glTF version, "${h.asset.version}".`);if(h.extensionsRequired)for(const t of h.extensionsRequired)if(!n.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);o.getRoot().getAsset().generator=r.json.asset.generator;const u=new W(r),c=h.extensionsUsed||[],d=h.extensionsRequired||[];for(const t of n.extensions)c.includes(t.EXTENSION_NAME)&&o.createExtension(t).setRequired(d.includes(t.EXTENSION_NAME));u.buffers=(h.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(h.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(h.accessors||[]).map(t=>{const s=o.createAccessor(t.name,u.bufferViewBuffers[t.bufferView]);let e;return s.setType(t.type),e=void 0!==t.sparse?function(t,s){const e=Y[t.componentType],r=A.getElementSize(t.type);let i;i=void 0!==t.bufferView?Z(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=Z(h,s),c=Z(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}(t,r):Z(t,r).slice(),void 0!==t.normalized&&s.setNormalized(t.normalized),s.setArray(e),s});const f=h.images||[],p=h.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(i.TEXTURE)).forEach(t=>t.provide(u,i.TEXTURE)),u.textures=f.map(t=>{const s=o.createTexture(t.name);if(void 0!==t.bufferView){const e=h.bufferViews[t.bufferView],i=r.json.buffers[e.buffer],n=e.byteOffset||0,o=(i.uri?r.resources[i.uri]:r.resources["yt"]).slice(n,n+e.byteLength);s.setImage(o)}else void 0!==t.uri&&(s.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&s.setURI(t.uri));if(void 0!==t.mimeType)s.setMimeType(t.mimeType);else if(t.uri){const e=a.extension(t.uri);s.setMimeType(l.extensionToMimeType(e))}return s}),u.materials=(h.materials||[]).map(t=>{const s=o.createMaterial(t.name);void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t),u.setTextureSampler(s.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e),u.setTextureSampler(s.getEmissiveTextureSampler(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),u.setTextureSampler(s.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),u.setTextureSampler(s.getOcclusionTextureSampler(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t),u.setTextureSampler(s.getMetallicRoughnessTextureSampler(),t)}return s}),u.meshes=(h.meshes||[]).map(t=>{const s=o.createMesh(t.name);return void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(h.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return"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 g=h.nodes||[];return u.nodes=g.map(r=>{const i=o.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(s([],r.matrix)),i.setScale(e([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),u.skins=(h.skins||[]).map(t=>{const s=o.createSkin(t.name);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}),g.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=(h.animations||[]).map(t=>{const s=o.createAnimation(t.name),e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);s.addChannel(r)}),s}),u.scenes=(h.scenes||[]).map(t=>{const s=o.createScene(t.name);return(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addNode(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}}function Z(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["yt"],n=Y[t.componentType],h=A.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["yt"],n=Y[t.componentType],h=A.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 X{constructor(t,s){this.nativeDocument=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.samplerDefIndexMap=new Map,this.imageData=[]}createTextureInfoDef(t,s,e){const r={magFilter:e.getMagFilter()||void 0,minFilter:e.getMinFilter()||void 0,wrapS:e.getWrapS(),wrapT:e.getWrapT()},i=JSON.stringify(r);this.samplerDefIndexMap.has(i)||(this.samplerDefIndexMap.set(i,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(r));const n={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(i)},h=JSON.stringify(n);return this.textureDefIndexMap.has(h)||(this.textureDefIndexMap.set(h,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(n)),{index:this.textureDefIndexMap.get(h),texCoord:s.getTexCoord()}}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.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=l.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.nativeDocument.resources[t.uri]=s}}}class H{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}`}}class K{static write(t,s){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=r.json;i.asset.generator="glTF-Transform v0.5.3";const n=new X(r,s),h=e.listBuffers().length,o=e.listTextures().length;function u(t,s,e,r){const h=[];let o=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length;const e=c.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,h.push(e),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:c.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function a(t,s,e){const r=t[0].getCount();let h=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length,t.byteOffset=h;const e=s.getElementSize(),r=s.getComponentSize();h+=c.padNumber(e*r),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),a=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*h+e+r*i,c=o[s*t+r];switch(n){case 5126:a.setFloat32(u,c,!0);break;case 5120:a.setInt8(u,c);break;case 5122:a.setInt16(u,c,!0);break;case 5121:a.setUint8(u,c);break;case 5123:a.setUint16(u,c,!0);break;case 5125:a.setUint32(u,c,!0);break;default:throw new Error("Unexpected component type: "+n)}}e+=c.padNumber(t*i)}}return i.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new H(h>1,s.basename),n.imageURIGenerator=new H(o>1,s.basename),n.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 A){const e=l.get(t)||[];e.push(s),l.set(t,e)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=e.listTextures().map((t,s)=>{const e=n.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(e,t.getImage(),t),n.imageIndexMap.set(t,s),e}),i.buffers=[],e.listBuffers().forEach(t=>{const e=n.createPropertyDef(t),h=new Map,o=new Set,d=new Set,f=t.listParents().filter(t=>!(t instanceof G));for(const t of f){if(!(t instanceof A))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1;const i=l.get(t)||[];for(const t of i)t instanceof k?s=!0:t instanceof B?e=!0:r=!0;if(s||e||r||(r=!0),!s||e||r)if(!e||s||r){if(!r||s||e)throw new Error("Attribute or index accessors must be used only for that purpose.");d.add(t)}else o.add(t);else{const s=i[0].getParent(),e=h.get(s)||new Set;e.add(t),h.set(s,e)}}const p=[],g=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),g,w,34963);w+=t.byteLength,p.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const s=a(Array.from(t),g,w);w+=s.byteLength,p.push(...s.buffers)}if(d.size){const t=u(Array.from(d),g,w);w+=t.byteLength,p.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,p.push(n.imageData[t]);w?(s.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=w,r.resources[m]=c.concat(p),i.buffers.push(e)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=e.listMaterials().map((t,s)=>{const e=n.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(),i=t.getBaseColorTextureSampler();e.pbrMetallicRoughness.baseColorTexture=n.createTextureInfoDef(s,r,i)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();e.emissiveTexture=n.createTextureInfoDef(s,r,i)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),e.normalTexture=h}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),e.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();e.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(s,r,i)}return n.materialIndexMap.set(t,s),e}),i.meshes=e.listMeshes().map((t,s)=>{const e=n.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=n.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),t.getIndices()&&(s.indices=n.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=n.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=n.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),n.meshIndexMap.set(t,s),e}),i.cameras=e.listCameras().map((t,s)=>{const e=n.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()},n.cameraIndexMap.set(t,s),e}),i.nodes=e.listNodes().map((t,s)=>{const e=n.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),n.nodeIndexMap.set(t,s),e}),i.skins=e.listSkins().map((t,s)=>{const e=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=n.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=i.nodes[s];t.getMesh()&&(e.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=e.listAnimations().map(t=>{const s=n.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=n.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),i.scenes=e.listScenes().map(t=>{const s=n.createPropertyDef(t);return s.nodes=t.listNodes().map(t=>n.nodeIndexMap.get(t)),s}),i.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),i.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(n)),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]}(i),r}}class Q{constructor(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return q.read(t,{extensions:this.rt})}createNativeDocument(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return K.write(t,s)}unpackGLBToNativeDocument(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=c.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{yt:t.slice(h,h+i[0])}}}unpackGLB(t){return this.createDocument(this.unpackGLBToNativeDocument(t))}packGLB(t){const{json:s,resources:e}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(s),i=c.pad(c.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=c.concat([n,i]),o=c.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,a=c.concat([u,o]),l=new Uint32Array([1179937895,2,12+h.byteLength+a.byteLength]).buffer;return c.concat([l,h,a])}}class tt extends Q{constructor(t,s){super(),this.fs=t,this.path=s}readNativeDocument(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.readGLB(t):this.readGLTF(t)}read(t){const s=this.readNativeDocument(t);return q.read(s,{extensions:this.rt})}write(t,s){t.match(/\.glb$/)?this.writeGLB(t,s):this.writeGLTF(t,s)}readGLB(t){const s=this.fs.readFileSync(t),e=c.trim(s);return this.unpackGLBToNativeDocument(e)}readGLTF(t){const s=this.path.dirname(t),e={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri)if(t.uri.match(/data:/)){const s=`__${v()}.${a.extension(t.uri)}`;e.resources[s]=c.createBufferFromDataURI(t.uri),t.uri=s}else{const r=this.path.resolve(s,t.uri);e.resources[t.uri]=c.trim(this.fs.readFileSync(r))}}),e}writeGLTF(t,s){const e={basename:a.basename(t),isGLB:!1},{json:r,resources:i}=K.write(s,e),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const s=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),s)})}writeGLB(t,s){const e=Buffer.from(this.packGLB(s));this.fs.writeFileSync(t,e)}}class st extends Q{constructor(t){super(),this.fetchConfig=t}readNativeDocument(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.readGLB(t):this.readGLTF(t)}read(t){return this.readNativeDocument(t).then(t=>this.createDocument(t))}readGLTF(t){const s={json:{},resources:{}};return fetch(t,this.fetchConfig).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.fetchConfig).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLBToNativeDocument(t))}}export{A as Accessor,E as Animation,b as AnimationChannel,M as AnimationSampler,S as Buffer,c as BufferUtils,y as COPY_IDENTITY,N as Camera,V as Document,J as Extension,R as ExtensionProperty,a as FileUtils,h as Graph,o as GraphChild,l as ImageUtils,p as Logger,U as Material,f as MathUtils,P as Mesh,O as Node,tt as NodeIO,F as Primitive,D as PrimitiveTarget,x as Property,i as PropertyType,W as ReaderContext,G as Root,j as Scene,$ as Skin,z as Texture,I as TextureInfo,_ as TextureLink,C as TextureSampler,st as WebIO,X as WriterContext,v as uuid};
import{getTranslation as t,getRotation as s,getScaling as e}from"gl-matrix/mat4";function r(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}var i;!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",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{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 h{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 n(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 o(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 u(t,s){}class c{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 a{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 l{static getSizeJPEG(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),d(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"===c.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 d(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 f{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 p{constructor(t){this.verbosity=t}debug(t){this.verbosity<=p.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=p.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=p.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=p.Verbosity.ERROR&&console.error(t)}}p.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const g="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",m=new Set,w=function(){let t="";for(let s=0;s<6;s++)t+=g.charAt(Math.floor(Math.random()*g.length));return t},v=function(){for(let t=0;t<999;t++){const t=w();if(!m.has(t))return m.add(t),t}},y=t=>t;class x 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,y)}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()}}class T extends x{constructor(){super(...arguments),this.extensions=[]}copy(t,s=y){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.constructor,s(e))}),this}getExtension(t){const s=t.EXTENSION_NAME,e=this.extensions.find(t=>t.getChild().extensionName===s);return e?e.getChild():null}setExtension(t,s){const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.p(this),this.addGraphChild(this.extensions,this.graph.link(s.extensionName,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],T.prototype,"extensions",void 0);class A extends T{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.T=!1,this.A=f.identity,this.M=f.identity,this.buffer=null}copy(t,s=y){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 A.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=>f.denormalize(t,this.v),this.A=t=>f.normalize(t,this.v)):(this.M=f.identity,this.A=f.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.getChild()}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}}A.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},A.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},r([o],A.prototype,"buffer",void 0);class E extends T{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=y){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())}}r([u],E.prototype,"channels",void 0),r([u],E.prototype,"samplers",void 0);class b extends x{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=y){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}}r([o],b.prototype,"targetNode",void 0),r([o],b.prototype,"sampler",void 0);class M extends x{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,this.N="LINEAR",this.input=null,this.output=null}copy(t,s=y){return super.copy(t,s),this.N=t.N,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],M.prototype,"input",void 0),r([o],M.prototype,"output",void 0);class S extends T{constructor(){super(...arguments),this.propertyType=i.BUFFER}copy(t,s=y){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class N extends T{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}copy(t,s=y){return super.copy(t,s),this.m=t.m,this.I=t.I,this.C=t.C,this._=t._,this.k=t.k,this.B=t.B,this.L=t.L,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=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.k}setYFov(t){return this.k=t,this}getXMag(){return this.B}setXMag(t){return this.B=t,this}getYMag(){return this.L}setYMag(t){return this.L=t,this}}class R extends x{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 I{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}copy(t){return this.texCoord=t.texCoord,this}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class C{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.D=10497}copy(t){return this.P=t.P,this.O=t.O,this.F=t.F,this.D=t.D,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.O}setMinFilter(t){return this.O=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.D}setWrapT(t){return this.D=t,this}}C.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},C.TextureMagFilter={NEAREST:9728,LINEAR:9729},C.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class _ extends n{constructor(){super(...arguments),this.textureInfo=new I,this.sampler=new C}copy(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this}}class k extends n{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class B extends n{copy(t){return this}}class L extends h{linkTexture(t,s,e){if(!e)return null;const r=new _(t,s,e);return this.registerLink(r),r}linkAttribute(t,s,e){if(!e)return null;const r=new k(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new B(t,s,e);return this.registerLink(r),r}}class U extends T{constructor(){super(...arguments),this.propertyType=i.MATERIAL,this.G="OPAQUE",this.j=.5,this.$=!1,this.V=[1,1,1,1],this.J=[0,0,0],this.W=1,this.Y=1,this.q=1,this.Z=1,this.baseColorTexture=null,this.emissiveTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.metallicRoughnessTexture=null}copy(t,s=y){return super.copy(t,s),this.G=t.G,this.j=t.j,this.$=t.$,this.V=[...t.V],this.J=[...t.J],this.W=t.W,this.Y=t.Y,this.q=t.q,this.Z=t.Z,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.baseColorTexture.copy(t.baseColorTexture)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.emissiveTexture.copy(t.emissiveTexture)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.normalTexture.copy(t.normalTexture)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.occlusionTexture.copy(t.occlusionTexture)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(t.metallicRoughnessTexture)),this}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=t,this}getAlphaMode(){return this.G}setAlphaMode(t){return this.G=t,this}getAlphaCutoff(){return this.j}setAlphaCutoff(t){return this.j=t,this}getBaseColorFactor(){return this.V}setBaseColorFactor(t){return this.V=t,this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null}getBaseColorTextureSampler(){return this.baseColorTexture?this.baseColorTexture.sampler:null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",this,t),this}getEmissiveFactor(){return this.J}setEmissiveFactor(t){return this.J=t,this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null}getEmissiveTextureSampler(){return this.emissiveTexture?this.emissiveTexture.sampler:null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",this,t),this}getNormalScale(){return this.W}setNormalScale(t){return this.W=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTexture.textureInfo:null}getNormalTextureSampler(){return this.normalTexture?this.normalTexture.sampler:null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.q}setRoughnessFactor(t){return this.q=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.metallicRoughnessTexture.textureInfo:null}getMetallicRoughnessTextureSampler(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this}}r([o],U.prototype,"baseColorTexture",void 0),r([o],U.prototype,"emissiveTexture",void 0),r([o],U.prototype,"normalTexture",void 0),r([o],U.prototype,"occlusionTexture",void 0),r([o],U.prototype,"metallicRoughnessTexture",void 0);class P extends T{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}copy(t,s=y){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}}r([u],P.prototype,"primitives",void 0);class O extends T{constructor(){super(...arguments),this.propertyType=i.NODE,this.H=[0,0,0],this.K=[0,0,0,1],this.tt=[1,1,1],this.X=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=y){return super.copy(t,s),this.H=[...t.H],this.K=[...t.K],this.tt=[...t.tt],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())),this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild()))),this}getTranslation(){return this.H}getRotation(){return this.K}getScale(){return this.tt}setTranslation(t){return this.H=t,this}setRotation(t){return this.K=t,this}setScale(t){return this.tt=t,this}addChild(t){const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}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}}r([o],O.prototype,"camera",void 0),r([o],O.prototype,"mesh",void 0),r([o],O.prototype,"skin",void 0),r([u],O.prototype,"children",void 0);class F extends x{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE,this.st=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=y){return super.copy(t,s),this.st=t.st,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.st}setMode(t){return this.st=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)}}r([o],F.prototype,"material",void 0),r([o],F.prototype,"indices",void 0),r([u],F.prototype,"attributes",void 0),r([u],F.prototype,"targets",void 0);class D extends x{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=y){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)}}r([u],D.prototype,"attributes",void 0);class G extends x{constructor(){super(...arguments),this.propertyType=i.ROOT,this.et={generator:"glTF-Transform v0.5.4",version:"2.0"},this.rt=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=y){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.et,t.et),t.accessors.forEach(t=>this.it(s(t.getChild()))),t.animations.forEach(t=>this.nt(s(t.getChild()))),t.buffers.forEach(t=>this.ht(s(t.getChild()))),t.cameras.forEach(t=>this.ot(s(t.getChild()))),t.materials.forEach(t=>this.ut(s(t.getChild()))),t.meshes.forEach(t=>this.ct(s(t.getChild()))),t.nodes.forEach(t=>this.at(s(t.getChild()))),t.scenes.forEach(t=>this.lt(s(t.getChild()))),t.skins.forEach(t=>this.dt(s(t.getChild()))),t.textures.forEach(t=>this.ft(s(t.getChild()))),this}getAsset(){return this.et}listExtensionsUsed(){return Array.from(this.rt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}pt(t){if(this.rt.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.rt.add(t),this}gt(t){return this.rt.delete(t),this}lt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ot(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())}ct(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}it(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],G.prototype,"accessors",void 0),r([u],G.prototype,"animations",void 0),r([u],G.prototype,"buffers",void 0),r([u],G.prototype,"cameras",void 0),r([u],G.prototype,"materials",void 0),r([u],G.prototype,"meshes",void 0),r([u],G.prototype,"nodes",void 0),r([u],G.prototype,"scenes",void 0),r([u],G.prototype,"skins",void 0),r([u],G.prototype,"textures",void 0);class j extends T{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}copy(t,s=y){return super.copy(t,s),this.clearGraphChildList(this.nodes),t.nodes.forEach(t=>this.addNode(s(t.getChild()))),this}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],j.prototype,"nodes",void 0);class $ extends T{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=y){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())}}r([o],$.prototype,"skeleton",void 0),r([o],$.prototype,"inverseBindMatrices",void 0),r([u],$.prototype,"joints",void 0);class z extends T{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}copy(t,s=y){return super.copy(t,s),this.mimeType=t.mimeType,this.uri=t.uri,t.image&&(this.image=t.image.slice(0)),this}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?l.getSizePNG(this.image):l.getSizeJPEG(this.image)}}class V{constructor(){this.graph=new L,this.root=new G(this.graph),this.logger=new p(p.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){return(new V).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.root),r.set(t.root,this.root);for(const i of t.graph.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof R?new i(this.graph,s[t.extensionName]):new i(this.graph);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 j(this.graph,t);return this.root.lt(s),s}createNode(t=""){const s=new O(this.graph,t);return this.root.at(s),s}createCamera(t=""){const s=new N(this.graph,t);return this.root.ot(s),s}createSkin(t=""){const s=new $(this.graph,t);return this.root.dt(s),s}createMesh(t=""){const s=new P(this.graph,t);return this.root.ct(s),s}createPrimitive(){return new F(this.graph)}createPrimitiveTarget(t=""){return new D(this.graph,t)}createMaterial(t=""){const s=new U(this.graph,t);return this.root.ut(s),s}createTexture(t=""){const s=new z(this.graph,t);return this.root.ft(s),s}createAnimation(t=""){const s=new E(this.graph,t);return this.root.nt(s),s}createAnimationChannel(){return new b(this.graph)}createAnimationSampler(){return new M(this.graph)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new A(this.graph,t).setBuffer(s);return this.root.it(e),e}createBuffer(t=""){const s=new S(this.graph,t);return this.root.ht(s),s}}class J{constructor(t){this.doc=t,this.provideTypes=[],this.required=!1,this.properties=new Set,t.getRoot().pt(this)}dispose(){this.doc.getRoot().gt(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}provide(t,s){return this}}class W{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){void 0!==s.texCoord&&t.setTexCoord(s.texCoord)}setTextureSampler(t,s){const e=this.nativeDocument.json.textures[s.index];if(void 0===e.sampler)return;const r=this.nativeDocument.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 Y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class q{static read(r,n){const{json:h}=r,o=new V;if("2.0"!==h.asset.version)throw new Error(`Unsupported glTF version, "${h.asset.version}".`);if(h.extensionsRequired)for(const t of h.extensionsRequired)if(!n.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);o.getRoot().getAsset().generator=r.json.asset.generator;const u=new W(r),c=h.extensionsUsed||[],d=h.extensionsRequired||[];for(const t of n.extensions)c.includes(t.EXTENSION_NAME)&&o.createExtension(t).setRequired(d.includes(t.EXTENSION_NAME));u.buffers=(h.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(h.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(h.accessors||[]).map(t=>{const s=o.createAccessor(t.name,u.bufferViewBuffers[t.bufferView]);let e;return s.setType(t.type),e=void 0!==t.sparse?function(t,s){const e=Y[t.componentType],r=A.getElementSize(t.type);let i;i=void 0!==t.bufferView?Z(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=Z(h,s),c=Z(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}(t,r):Z(t,r).slice(),void 0!==t.normalized&&s.setNormalized(t.normalized),s.setArray(e),s});const f=h.images||[],p=h.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(i.TEXTURE)).forEach(t=>t.provide(u,i.TEXTURE)),u.textures=f.map(t=>{const s=o.createTexture(t.name);if(void 0!==t.bufferView){const e=h.bufferViews[t.bufferView],i=r.json.buffers[e.buffer],n=e.byteOffset||0,o=(i.uri?r.resources[i.uri]:r.resources["wt"]).slice(n,n+e.byteLength);s.setImage(o)}else void 0!==t.uri&&(s.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&s.setURI(t.uri));if(void 0!==t.mimeType)s.setMimeType(t.mimeType);else if(t.uri){const e=a.extension(t.uri);s.setMimeType(l.extensionToMimeType(e))}return s}),u.materials=(h.materials||[]).map(t=>{const s=o.createMaterial(t.name);void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t),u.setTextureSampler(s.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e),u.setTextureSampler(s.getEmissiveTextureSampler(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),u.setTextureSampler(s.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[p[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),u.setTextureSampler(s.getOcclusionTextureSampler(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[p[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t),u.setTextureSampler(s.getMetallicRoughnessTextureSampler(),t)}return s}),u.meshes=(h.meshes||[]).map(t=>{const s=o.createMesh(t.name);return void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(h.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return"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 g=h.nodes||[];return u.nodes=g.map(r=>{const i=o.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(s([],r.matrix)),i.setScale(e([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),u.skins=(h.skins||[]).map(t=>{const s=o.createSkin(t.name);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}),g.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=(h.animations||[]).map(t=>{const s=o.createAnimation(t.name),e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);s.addChannel(r)}),s}),u.scenes=(h.scenes||[]).map(t=>{const s=o.createScene(t.name);return(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addNode(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}}function Z(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["wt"],n=Y[t.componentType],h=A.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["wt"],n=Y[t.componentType],h=A.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 X{constructor(t,s){this.nativeDocument=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.samplerDefIndexMap=new Map,this.imageData=[]}createTextureInfoDef(t,s,e){const r={magFilter:e.getMagFilter()||void 0,minFilter:e.getMinFilter()||void 0,wrapS:e.getWrapS(),wrapT:e.getWrapT()},i=JSON.stringify(r);this.samplerDefIndexMap.has(i)||(this.samplerDefIndexMap.set(i,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(r));const n={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(i)},h=JSON.stringify(n);return this.textureDefIndexMap.has(h)||(this.textureDefIndexMap.set(h,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(n)),{index:this.textureDefIndexMap.get(h),texCoord:s.getTexCoord()}}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.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=l.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.nativeDocument.resources[t.uri]=s}}}class H{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}`}}class K{static write(t,s){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=r.json;i.asset.generator="glTF-Transform v0.5.4";const n=new X(r,s),h=e.listBuffers().length,o=e.listTextures().length;function u(t,s,e,r){const h=[];let o=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length;const e=c.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,h.push(e),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:c.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function a(t,s,e){const r=t[0].getCount();let h=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length,t.byteOffset=h;const e=s.getElementSize(),r=s.getComponentSize();h+=c.padNumber(e*r),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),a=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*h+e+r*i,c=o[s*t+r];switch(n){case 5126:a.setFloat32(u,c,!0);break;case 5120:a.setInt8(u,c);break;case 5122:a.setInt16(u,c,!0);break;case 5121:a.setUint8(u,c);break;case 5123:a.setUint16(u,c,!0);break;case 5125:a.setUint32(u,c,!0);break;default:throw new Error("Unexpected component type: "+n)}}e+=c.padNumber(t*i)}}return i.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new H(h>1,s.basename),n.imageURIGenerator=new H(o>1,s.basename),n.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 A){const e=l.get(t)||[];e.push(s),l.set(t,e)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=e.listTextures().map((t,s)=>{const e=n.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(e,t.getImage(),t),n.imageIndexMap.set(t,s),e}),i.buffers=[],e.listBuffers().forEach(t=>{const e=n.createPropertyDef(t),h=new Map,o=new Set,d=new Set,f=t.listParents().filter(t=>!(t instanceof G));for(const t of f){if(!(t instanceof A))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1;const i=l.get(t)||[];for(const t of i)t instanceof k?s=!0:t instanceof B?e=!0:r=!0;if(s||e||r||(r=!0),!s||e||r)if(!e||s||r){if(!r||s||e)throw new Error("Attribute or index accessors must be used only for that purpose.");d.add(t)}else o.add(t);else{const s=i[0].getParent(),e=h.get(s)||new Set;e.add(t),h.set(s,e)}}const p=[],g=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),g,w,34963);w+=t.byteLength,p.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const s=a(Array.from(t),g,w);w+=s.byteLength,p.push(...s.buffers)}if(d.size){const t=u(Array.from(d),g,w);w+=t.byteLength,p.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,p.push(n.imageData[t]);w?(s.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=w,r.resources[m]=c.concat(p),i.buffers.push(e)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=e.listMaterials().map((t,s)=>{const e=n.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(),i=t.getBaseColorTextureSampler();e.pbrMetallicRoughness.baseColorTexture=n.createTextureInfoDef(s,r,i)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();e.emissiveTexture=n.createTextureInfoDef(s,r,i)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),e.normalTexture=h}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),e.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();e.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(s,r,i)}return n.materialIndexMap.set(t,s),e}),i.meshes=e.listMeshes().map((t,s)=>{const e=n.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=n.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),t.getIndices()&&(s.indices=n.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=n.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=n.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),n.meshIndexMap.set(t,s),e}),i.cameras=e.listCameras().map((t,s)=>{const e=n.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()},n.cameraIndexMap.set(t,s),e}),i.nodes=e.listNodes().map((t,s)=>{const e=n.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),n.nodeIndexMap.set(t,s),e}),i.skins=e.listSkins().map((t,s)=>{const e=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=n.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=i.nodes[s];t.getMesh()&&(e.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=e.listAnimations().map(t=>{const s=n.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=n.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),i.scenes=e.listScenes().map(t=>{const s=n.createPropertyDef(t);return s.nodes=t.listNodes().map(t=>n.nodeIndexMap.get(t)),s}),i.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),i.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(n)),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]}(i),r}}class Q{constructor(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return q.read(t,{extensions:this.rt})}createNativeDocument(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return K.write(t,s)}unpackGLBToNativeDocument(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=c.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{wt:t.slice(h,h+i[0])}}}unpackGLB(t){return this.createDocument(this.unpackGLBToNativeDocument(t))}packGLB(t){const{json:s,resources:e}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(s),i=c.pad(c.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=c.concat([n,i]),o=c.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,a=c.concat([u,o]),l=new Uint32Array([1179937895,2,12+h.byteLength+a.byteLength]).buffer;return c.concat([l,h,a])}}class tt extends Q{constructor(t,s){super(),this.fs=t,this.path=s}readNativeDocument(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.readGLB(t):this.readGLTF(t)}read(t){const s=this.readNativeDocument(t);return q.read(s,{extensions:this.rt})}write(t,s){t.match(/\.glb$/)?this.writeGLB(t,s):this.writeGLTF(t,s)}readGLB(t){const s=this.fs.readFileSync(t),e=c.trim(s);return this.unpackGLBToNativeDocument(e)}readGLTF(t){const s=this.path.dirname(t),e={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri)if(t.uri.match(/data:/)){const s=`__${v()}.${a.extension(t.uri)}`;e.resources[s]=c.createBufferFromDataURI(t.uri),t.uri=s}else{const r=this.path.resolve(s,t.uri);e.resources[t.uri]=c.trim(this.fs.readFileSync(r))}}),e}writeGLTF(t,s){const e={basename:a.basename(t),isGLB:!1},{json:r,resources:i}=K.write(s,e),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const s=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),s)})}writeGLB(t,s){const e=Buffer.from(this.packGLB(s));this.fs.writeFileSync(t,e)}}class st extends Q{constructor(t){super(),this.fetchConfig=t}readNativeDocument(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.readGLB(t):this.readGLTF(t)}read(t){return this.readNativeDocument(t).then(t=>this.createDocument(t))}readGLTF(t){const s={json:{},resources:{}};return fetch(t,this.fetchConfig).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.fetchConfig).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>s)})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLBToNativeDocument(t))}}export{A as Accessor,E as Animation,b as AnimationChannel,M as AnimationSampler,S as Buffer,c as BufferUtils,y as COPY_IDENTITY,N as Camera,V as Document,J as Extension,R as ExtensionProperty,a as FileUtils,h as Graph,o as GraphChild,l as ImageUtils,p as Logger,U as Material,f as MathUtils,P as Mesh,O as Node,tt as NodeIO,F as Primitive,D as PrimitiveTarget,x as Property,i as PropertyType,W as ReaderContext,G as Root,j as Scene,$ as Skin,z as Texture,I as TextureInfo,_ as TextureLink,C as TextureSampler,st as WebIO,X as WriterContext,v as uuid};
//# sourceMappingURL=core.modern.js.map

@@ -46,4 +46,4 @@ import { PropertyType } from './constants';

readonly provideTypes: PropertyType[];
private _required;
private _properties;
protected required: boolean;
protected properties: Set<ExtensionProperty>;
/** @hidden */

@@ -50,0 +50,0 @@ constructor(doc: Document);

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

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

},
"gitHead": "6cfc741a055c508e9adb823169574b9a08599472"
"gitHead": "9122dbc2f611621270aadd9759876faddc0b689f"
}

@@ -45,4 +45,4 @@ import { PropertyType } from './constants';

private _required = false;
private _properties: Set<ExtensionProperty> = new Set();
protected required = false;
protected properties: Set<ExtensionProperty> = new Set();

@@ -57,3 +57,3 @@ /** @hidden */

this.doc.getRoot()._disableExtension(this);
for (const property of this._properties) {
for (const property of this.properties) {
property.dispose();

@@ -69,3 +69,3 @@ }

public isRequired(): boolean {
return this._required;
return this.required;
}

@@ -79,3 +79,3 @@

public setRequired(required: boolean): this {
this._required = required;
this.required = required;
return this;

@@ -90,3 +90,3 @@ }

public addExtensionProperty(property: ExtensionProperty): this {
this._properties.add(property);
this.properties.add(property);
return this;

@@ -97,3 +97,3 @@ }

public removeExtensionProperty(property: ExtensionProperty): this {
this._properties.delete(property);
this.properties.delete(property);
return this;

@@ -100,0 +100,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