Socket
Socket
Sign inDemoInstall

@gltf-transform/core

Package Overview
Dependencies
Maintainers
1
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/core - npm Package Compare versions

Comparing version 0.7.0-alpha.1 to 0.7.0-alpha.2

2

dist/core.d.ts

@@ -7,2 +7,2 @@ export { Document, Transform } from './document';

export { BufferUtils, ColorUtils, FileUtils, ImageUtils, MathUtils, Logger, uuid } from './utils/';
export { PropertyType, vec2, vec3, vec4, mat3, mat4 } from './constants';
export { TypedArray, PropertyType, vec2, vec3, vec4, mat3, mat4, GLB_BUFFER } from './constants';

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

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

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

readonly provideTypes: PropertyType[];
/** Dependency IDs needed by this extension, to be installed before I/O. */
readonly dependencies: string[];
protected required: boolean;

@@ -75,2 +77,4 @@ protected properties: Set<ExtensionProperty>;

*/
/** Installs dependencies required by the extension. */
install(key: string, dependency: unknown): this;
/**

@@ -77,0 +81,0 @@ * Used by the {@link PlatformIO} utilities when reading a glTF asset. This method may

@@ -22,2 +22,5 @@ import { Document } from '../document';

protected _extensions: typeof Extension[];
protected _dependencies: {
[key: string]: unknown;
};
/** Sets the {@link Logger} used by this I/O instance. Defaults to Logger.DEFAULT_INSTANCE. */

@@ -27,2 +30,6 @@ setLogger(logger: Logger): this;

registerExtensions(extensions: typeof Extension[]): this;
/** Registers dependencies used (e.g. by extensions) in the I/O process. */
registerDependencies(dependencies: {
[key: string]: unknown;
}): this;
/**********************************************************************************************

@@ -29,0 +36,0 @@ * JSON.

@@ -7,3 +7,6 @@ import { Document } from '../document';

logger?: Logger;
extensions?: (typeof Extension)[];
extensions: (typeof Extension)[];
dependencies: {
[key: string]: unknown;
};
}

@@ -10,0 +13,0 @@ /** @hidden */

{
"name": "@gltf-transform/core",
"version": "0.7.0-alpha.1",
"version": "0.7.0-alpha.2",
"repository": "github:donmccurdy/glTF-Transform",

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

},
"gitHead": "86d19f38214db00d61d1da70fc3c18fc4cb34ff3"
"gitHead": "c13e71257c34aaf7a05114d4740e5a2aec375807"
}

@@ -7,3 +7,3 @@ export { Document, Transform } from './document';

export { BufferUtils, ColorUtils, FileUtils, ImageUtils, MathUtils, Logger, uuid } from './utils/';
export { PropertyType, vec2, vec3, vec4, mat3, mat4 } from './constants';
export { TypedArray, PropertyType, vec2, vec3, vec4, mat3, mat4, GLB_BUFFER } from './constants';

@@ -10,0 +10,0 @@ /** [[include:CONCEPTS.md]] */

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

/** Dependency IDs needed by this extension, to be installed before I/O. */
public readonly dependencies: string[] = [];
protected required = false;

@@ -101,2 +104,8 @@ protected properties: Set<ExtensionProperty> = new Set();

/** Installs dependencies required by the extension. */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public install(key: string, dependency: unknown): this {
return this;
}
/**

@@ -103,0 +112,0 @@ * Used by the {@link PlatformIO} utilities when reading a glTF asset. This method may

@@ -57,3 +57,7 @@ import { Document } from '../document';

const jsonDoc = this.readAsJSON(uri);
return GLTFReader.read(jsonDoc, {extensions: this._extensions, logger: this._logger});
return GLTFReader.read(jsonDoc, {
extensions: this._extensions,
dependencies: this._dependencies,
logger: this._logger
});
}

@@ -60,0 +64,0 @@

@@ -25,4 +25,4 @@ import { GLB_BUFFER } from '../constants';

protected _logger = Logger.DEFAULT_INSTANCE;
protected _extensions: typeof Extension[] = [];
protected _dependencies: {[key: string]: unknown} = {};

@@ -41,2 +41,8 @@ /** Sets the {@link Logger} used by this I/O instance. Defaults to Logger.DEFAULT_INSTANCE. */

/** Registers dependencies used (e.g. by extensions) in the I/O process. */
public registerDependencies(dependencies: {[key: string]: unknown}): this {
Object.assign(this._dependencies, dependencies);
return this;
}
/**********************************************************************************************

@@ -48,3 +54,7 @@ * JSON.

public readJSON (jsonDoc: JSONDocument): Document {
return GLTFReader.read(jsonDoc, {extensions: this._extensions, logger: this._logger});
return GLTFReader.read(jsonDoc, {
extensions: this._extensions,
dependencies: this._dependencies,
logger: this._logger
});
}

@@ -51,0 +61,0 @@

@@ -21,3 +21,4 @@ import { getRotation, getScaling, getTranslation } from 'gl-matrix/mat4'

logger?: Logger;
extensions?: (typeof Extension)[];
extensions: (typeof Extension)[];
dependencies: {[key: string]: unknown};
}

@@ -28,2 +29,3 @@

extensions: [],
dependencies: {},
};

@@ -59,4 +61,8 @@

if (extensionsUsed.includes(Extension.EXTENSION_NAME)) {
doc.createExtension(Extension as ExtensionConstructor)
const extension = doc.createExtension(Extension as ExtensionConstructor)
.setRequired(extensionsRequired.includes(Extension.EXTENSION_NAME));
for (const key of extension.dependencies) {
extension.install(key, options.dependencies[key]);
}
}

@@ -97,2 +103,9 @@ }

if (accessorDef.normalized !== undefined) {
accessor.setNormalized(accessorDef.normalized);
}
// KHR_draco_mesh_compression.
if (accessorDef.bufferView === undefined && !accessorDef.sparse) return accessor;
let array: TypedArray;

@@ -107,6 +120,2 @@

if (accessorDef.normalized !== undefined) {
accessor.setNormalized(accessorDef.normalized);
}
accessor.setArray(array);

@@ -255,2 +264,5 @@ return accessor;

const meshDefs = json.meshes || [];
doc.getRoot().listExtensionsUsed()
.filter((extension) => extension.provideTypes.includes(PropertyType.PRIMITIVE))
.forEach((extension) => extension.provide(context, PropertyType.PRIMITIVE));
context.meshes = meshDefs.map((meshDef) => {

@@ -257,0 +269,0 @@ const mesh = doc.createMesh(meshDef.name);

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