@gltf-transform/core
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -5,3 +5,3 @@ /** | ||
*/ | ||
export declare const VERSION = "v0.3"; | ||
export declare const VERSION: string; | ||
/** @hidden */ | ||
@@ -8,0 +8,0 @@ export declare const NAME = "@gltf-transform/core"; |
@@ -1,2 +0,2 @@ | ||
import{getTranslation as t,getRotation as e,getScaling as s}from"gl-matrix/mat4";import{glMatrix as r}from"gl-matrix";function i(t,e,s,r){var i,n=arguments.length,h=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,s,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(e,s,h):i(e,s))||h);return n>3&&h&&Object.defineProperty(e,s,h),h}class n{constructor(t,e,s){if(this.t=t,this.s=e,this.i=s,this.h=!1,this.o=[],!e.canLink(s))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class h{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(e=>e.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(e=>e.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(e=>e.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,e){let s=this.u.filter(e=>e.getChild()===t);return e&&(s=s.filter(t=>e(t.getParent()))),s.forEach(t=>t.dispose()),this}link(t,e,s){if(!s)return null;const r=new n(t,e,s);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(e=>e!==t),this}}function o(t,e){Object.defineProperty(t,e,{get:function(){return this["__"+e]},set:function(t){const s=this["__"+e];s&&!Array.isArray(s)&&s.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+e]=null}),this["__"+e]=t},enumerable:!0})}function u(t,e){}class c extends Error{constructor(){super("@gltf-transform/core: Not implemented.")}}class a extends class{constructor(t){this.h=!1,this.l=t}canLink(t){return this.l===t.l}isDisposed(){return this.h}dispose(){this.l.disconnectChildren(this),this.l.disconnectParents(this),this.h=!0}detach(){return this.l.disconnectParents(this),this}swap(t,e){return this.l.getLinks().filter(e=>e.getParent()===this&&e.getChild()===t).forEach(t=>t.setChild(e)),this}addGraphChild(t,e){return t.push(e),e.onDispose(()=>{const s=t.filter(t=>t!==e);t.length=0,t.push(...s)}),this}removeGraphChild(t,e){return t.filter(t=>t.getChild()===e).forEach(t=>t.dispose()),this}listGraphParents(){return this.l.listParents(this)}}{constructor(t,e=""){super(t),this.t="",this.g={},this.p={},this.t=e}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.g}setExtras(t){return this.g=t,this}getExtensions(){return this.p}setExtensions(t){return this.p=t,this}clone(){throw new c}detach(){return this.l.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class l extends a{constructor(){super(...arguments),this.propertyType="Accessor",this.m=null,this.v="SCALAR",this.A=null,this.T=!1,this.M=f,this.S=f,this.buffer=null}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 e=this.getElementSize();this.getMin(t);for(let s=0;s<e;s++)t[s]=this.S(t[s]);return t}getMin(t){const e=this.getCount(),s=this.getElementSize();for(let e=0;e<s;e++)t[e]=Infinity;for(let r=0;r<e*s;r+=s)for(let e=0;e<s;e++)t[e]=Math.min(t[e],this.m[r+e]);return t}getMaxNormalized(t){const e=this.getElementSize();this.getMax(t);for(let s=0;s<e;s++)t[s]=this.S(t[s]);return t}getMax(t){const e=this.getCount(),s=this.getElementSize();for(let e=0;e<s;e++)t[e]=-Infinity;for(let r=0;r<e*s;r+=s)for(let e=0;e<s;e++)t[e]=Math.max(t[e],this.m[r+e]);return t}getCount(){return this.m.length/this.getElementSize()}getType(){return this.v}setType(t){return this.v=t,this}getElementSize(){return l.getElementSize(this.v)}getComponentSize(){return this.m.BYTES_PER_ELEMENT}getComponentType(){return this.A}getNormalized(){return this.T}setNormalized(t){return this.T=t,t?(this.S=t=>function(t,e){switch(e){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)}}(t,this.A),this.M=t=>function(t,e){switch(e){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)}}(t,this.A)):(this.S=f,this.M=f),this}getScalar(t){const e=this.getElementSize();return this.S(this.m[t*e])}setScalar(t,e){return this.m[t*this.getElementSize()]=this.M(e),this}getElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)e[r]=this.S(this.m[t*s+r]);return e}setElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)this.m[t*s+r]=this.M(e[r]);return this}getBuffer(){return this.buffer.getChild()}setBuffer(t){return this.buffer=this.l.link("buffer",this,t),this}getArray(){return this.m}setArray(t){return this.A=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.m=t,this}getByteLength(){return this.m.byteLength}}function f(t){return t}l.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},l.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},i([o],l.prototype,"buffer",void 0);class d extends a{constructor(){super(...arguments),this.propertyType="Animation",this.channels=[],this.samplers=[]}addChannel(t){const e=this.l.link("channel",this,t);return this.addGraphChild(this.channels,e)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const e=this.l.link("sampler",this,t);return this.addGraphChild(this.samplers,e)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}i([u],d.prototype,"channels",void 0),i([u],d.prototype,"samplers",void 0);class g extends a{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.N=null,this.targetNode=null,this.sampler=null}getTargetPath(){return this.N}setTargetPath(t){return this.N=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.l.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.l.link("sampler",this,t),this}}i([o],g.prototype,"targetNode",void 0),i([o],g.prototype,"sampler",void 0);class p extends a{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.C="LINEAR",this.input=null,this.output=null}getInterpolation(){return this.C}setInterpolation(t){return this.C=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.l.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.l.link("output",this,t),this}}i([o],p.prototype,"input",void 0),i([o],p.prototype,"output",void 0);class m extends a{constructor(){super(...arguments),this.propertyType="Buffer"}getURI(){return this.R}setURI(t){return this.R=t,this}}class v extends a{constructor(){super(...arguments),this.propertyType="Camera",this.v="perspective"}getType(){return this.v}setType(t){return this.v=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.B}setZFar(t){return this.B=t,this}getAspectRatio(){return this.k}setAspectRatio(t){return this.k=t,this}getYFov(){return this.U}setYFov(t){return this.U=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 w{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const e=atob(t.split(",")[1]),s=new Uint8Array(e.length);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s.buffer}{const e=t.split(",")[1],s=t.indexOf("base64")>=0;return this.trim(Buffer.from(e,s?"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:e,byteLength:s}=t;return t.buffer.slice(e,e+s)}static concat(t){let e=0;for(const s of t)e+=s.byteLength;const s=new Uint8Array(e);let r=0;for(const e of t)s.set(new Uint8Array(e),r),r+=e.byteLength;return s.buffer}static pad(t,e=0){const s=this.padNumber(t.byteLength);if(s!==t.byteLength){const r=new Uint8Array(s);if(r.set(new Uint8Array(t)),0!==e)for(let i=t.byteLength;i<s;i++)r[i]=e;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const s=new DataView(t),r=new DataView(e);let i=t.byteLength;for(;i--;)if(s.getUint8(i)!==r.getUint8(i))return!1;return!0}}class A{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class T{static getSizeJPEG(t){let e,s;for(t=t.slice(4);t.length;){if(e=t.readUInt16BE(0),x(t,e),s=t[e+1],192===s||193===s||194===s)return[t.readUInt16BE(e+7),t.readUInt16BE(e+5)];t=t.slice(e+2)}throw new TypeError("Invalid JPG, no size found")}static getSizePNG(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]}}function x(t,e){if(e>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[e])throw new TypeError("Invalid JPG, marker table corrupted")}class y{constructor(t){this.verbosity=t}debug(t){this.verbosity<=y.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=y.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=y.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=y.Verbosity.ERROR&&console.error(t)}}y.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const M="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",b=new Set,E=function(){let t="";for(let e=0;e<6;e++)t+=M.charAt(Math.floor(Math.random()*M.length));return t},S=function(){for(let t=0;t<999;t++){const t=E();if(!b.has(t))return t}return""};class N extends a{constructor(){super(...arguments),this.propertyType="Texture",this.image=null,this.mimeType="",this.uri=""}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?T.getSizePNG(Buffer.from(this.image)):T.getSizeJPEG(Buffer.from(this.image))}}class C{constructor(){this.propertyType="TextureInfo",this.texCoord=0}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class R{constructor(){this.propertyType="TextureSampler",this.P=null,this._=null,this.F=10497,this.G=10497}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this._}setMinFilter(t){return this._=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.G}setWrapT(t){return this.G=t,this}}R.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},R.TextureMagFilter={NEAREST:9728,LINEAR:9729},R.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class I extends n{constructor(){super(...arguments),this.textureInfo=new C,this.sampler=new R}}class B extends n{constructor(){super(...arguments),this.semantic=""}}class k extends n{}class U extends h{linkTexture(t,e,s){if(!s)return null;const r=new I(t,e,s);return this.registerLink(r),r}linkAttribute(t,e,s){if(!s)return null;const r=new B(t,e,s);return this.registerLink(r),r}linkIndex(t,e,s){if(!s)return null;const r=new k(t,e,s);return this.registerLink(r),r}}class L extends a{constructor(){super(...arguments),this.propertyType="Material",this.j="OPAQUE",this.D=.5,this.$=!1,this.J=[1,1,1,1],this.V=[0,0,0],this.W=1,this.Y=1,this.Z=1,this.X=1,this.baseColorTexture=null,this.emissiveTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.metallicRoughnessTexture=null}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=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.J}setBaseColorFactor(t){return this.J=t,this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null}getBaseColorTextureSampler(){return this.baseColorTexture?this.baseColorTexture.sampler:null}setBaseColorTexture(t){return this.baseColorTexture=this.l.linkTexture("baseColorTexture",this,t),this}getEmissiveFactor(){return this.V}setEmissiveFactor(t){return this.V=t,this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null}getEmissiveTextureSampler(){return this.emissiveTexture?this.emissiveTexture.sampler:null}setEmissiveTexture(t){return this.emissiveTexture=this.l.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.l.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.l.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.Z}setRoughnessFactor(t){return this.Z=t,this}getMetallicFactor(){return this.X}setMetallicFactor(t){return this.X=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.l.linkTexture("metallicRoughnessTexture",this,t),this}}i([o],L.prototype,"baseColorTexture",void 0),i([o],L.prototype,"emissiveTexture",void 0),i([o],L.prototype,"normalTexture",void 0),i([o],L.prototype,"occlusionTexture",void 0),i([o],L.prototype,"metallicRoughnessTexture",void 0);class O extends a{constructor(){super(...arguments),this.propertyType="Mesh",this.q=[],this.primitives=[]}addPrimitive(t){return this.addGraphChild(this.primitives,this.l.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.q}setWeights(t){return this.q=t,this}}i([u],O.prototype,"primitives",void 0);class P extends a{constructor(){super(...arguments),this.propertyType="Primitive",this.H=4,this.indices=null,this.attributes=[],this.targets=[],this.material=null}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.l.linkIndex("index",this,t),this}getAttribute(t){const e=this.attributes.find(e=>e.semantic===t);return e?e.getChild():null}setAttribute(t,e){const s=this.getAttribute(t);if(s&&this.removeGraphChild(this.attributes,s),!e)return this;const r=this.l.linkAttribute(t.toLowerCase(),this,e);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.l.link("material",this,t),this}getMode(){return this.H}setMode(t){return this.H=t,this}listTargets(){return this.targets.map(t=>t.getChild())}addTarget(t){return this.addGraphChild(this.targets,this.l.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}i([o],P.prototype,"indices",void 0),i([u],P.prototype,"attributes",void 0),i([u],P.prototype,"targets",void 0),i([o],P.prototype,"material",void 0);class _ extends a{constructor(){super(...arguments),this.propertyType="PrimitiveTarget",this.attributes=[]}getAttribute(t){const e=this.attributes.find(e=>e.semantic===t);return e?e.getChild():null}setAttribute(t,e){const s=this.getAttribute(t);if(s&&this.removeGraphChild(this.attributes,s),!e)return this;const r=this.l.linkAttribute(t.toLowerCase(),this,e);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)}}i([u],_.prototype,"attributes",void 0);class F extends a{constructor(){super(...arguments),this.propertyType="Node",this.K=[0,0,0],this.tt=[0,0,0,1],this.et=[1,1,1],this.q=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}getTranslation(){return this.K}getRotation(){return this.tt}getScale(){return this.et}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.et=t,this}addChild(t){const e=this.l.link("child",this,t);return this.addGraphChild(this.children,e)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.l.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.l.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.l.link("skin",this,t),this}getWeights(){return this.q}setWeights(t){return this.q=t,this}}i([o],F.prototype,"camera",void 0),i([o],F.prototype,"mesh",void 0),i([o],F.prototype,"skin",void 0),i([u],F.prototype,"children",void 0);class G extends a{constructor(){super(...arguments),this.propertyType="Root",this.st={generator:"glTF-Transform v0.3",version:"2.0"},this.scenes=[],this.nodes=[],this.cameras=[],this.skins=[],this.meshes=[],this.materials=[],this.textures=[],this.animations=[],this.accessors=[],this.buffers=[]}getAsset(){return this.st}addScene(t){return this.addGraphChild(this.scenes,this.l.link("scene",this,t))}removeScene(t){return this.removeGraphChild(this.scenes,t)}listScenes(){return this.scenes.map(t=>t.getChild())}addNode(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}addCamera(t){return this.addGraphChild(this.cameras,this.l.link("camera",this,t))}removeCamera(t){return this.removeGraphChild(this.cameras,t)}listCameras(){return this.cameras.map(t=>t.getChild())}addSkin(t){return this.addGraphChild(this.skins,this.l.link("skin",this,t))}removeSkin(t){return this.removeGraphChild(this.skins,t)}listSkins(){return this.skins.map(t=>t.getChild())}addMesh(t){return this.addGraphChild(this.meshes,this.l.link("mesh",this,t))}removeMesh(t){return this.removeGraphChild(this.meshes,t)}listMeshes(){return this.meshes.map(t=>t.getChild())}addMaterial(t){return this.addGraphChild(this.materials,this.l.link("material",this,t))}removeMaterial(t){return this.removeGraphChild(this.materials,t)}listMaterials(){return this.materials.map(t=>t.getChild())}addTexture(t){return this.addGraphChild(this.textures,this.l.link("texture",this,t))}removeTexture(t){return this.removeGraphChild(this.textures,t)}listTextures(){return this.textures.map(t=>t.getChild())}addAnimation(t){return this.addGraphChild(this.animations,this.l.link("animation",this,t))}removeAnimation(t){return this.removeGraphChild(this.animations,t)}listAnimations(){return this.animations.map(t=>t.getChild())}addAccessor(t){return this.addGraphChild(this.accessors,this.l.link("accessor",this,t))}removeAccessor(t){return this.removeGraphChild(this.accessors,t)}listAccessors(){return this.accessors.map(t=>t.getChild())}addBuffer(t){return this.addGraphChild(this.buffers,this.l.link("buffer",this,t))}removeBuffer(t){return this.removeGraphChild(this.buffers,t)}listBuffers(){return this.buffers.map(t=>t.getChild())}}i([u],G.prototype,"scenes",void 0),i([u],G.prototype,"nodes",void 0),i([u],G.prototype,"cameras",void 0),i([u],G.prototype,"skins",void 0),i([u],G.prototype,"meshes",void 0),i([u],G.prototype,"materials",void 0),i([u],G.prototype,"textures",void 0),i([u],G.prototype,"animations",void 0),i([u],G.prototype,"accessors",void 0),i([u],G.prototype,"buffers",void 0);class j extends a{constructor(){super(...arguments),this.propertyType="Scene",this.nodes=[]}addNode(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}i([u],j.prototype,"nodes",void 0);class D extends a{constructor(){super(...arguments),this.propertyType="Skin",this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.l.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.l.link("inverseBindMatrices",this,t),this}addJoint(t){const e=this.l.link("joint",this,t);return this.addGraphChild(this.joints,e)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}i([o],D.prototype,"skeleton",void 0),i([o],D.prototype,"inverseBindMatrices",void 0),i([u],D.prototype,"joints",void 0);class z{constructor(){this.graph=new U,this.root=new G(this.graph),this.logger=new y(y.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){throw new Error("Not implemented.")}transform(...t){for(const e of t)e(this);return this}createScene(t){const e=new j(this.graph,t);return this.root.addScene(e),e}createNode(t){const e=new F(this.graph,t);return this.root.addNode(e),e}createCamera(t){const e=new v(this.graph,t);return this.root.addCamera(e),e}createSkin(t){const e=new D(this.graph,t);return this.root.addSkin(e),e}createMesh(t){const e=new O(this.graph,t);return this.root.addMesh(e),e}createPrimitive(){return new P(this.graph)}createPrimitiveTarget(t){return new _(this.graph,t)}createMaterial(t){const e=new L(this.graph,t);return this.root.addMaterial(e),e}createTexture(t){const e=new N(this.graph,t);return this.root.addTexture(e),e}createAnimation(t){const e=new d(this.graph,t);return this.root.addAnimation(e),e}createAnimationChannel(){return new g(this.graph)}createAnimationSampler(){return new p(this.graph)}createAccessor(t,e=null){e||(e=this.getRoot().listBuffers()[0]);const s=new l(this.graph,t).setBuffer(e);return this.root.addAccessor(s),s}createBuffer(t){const e=new m(this.graph,t);return this.root.addBuffer(e),e}}const $={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class J{static read(r){const{json:i}=r,n=new z;if("2.0"!==i.asset.version)throw new Error(`Unsupported glTF version: "${i.asset.version}".`);const h=(i.buffers||[]).map(t=>{const e=n.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&e.setURI(t.uri),e}),o=(i.bufferViews||[]).map(t=>h[t.buffer]),u=(i.accessors||[]).map(t=>{const e=n.createAccessor(t.name,o[t.bufferView]);let s;return e.setType(t.type),s=void 0!==t.sparse?function(t,e){const s=$[t.componentType],r=l.getElementSize(t.type);let i;i=void 0!==t.bufferView?Y(t,e).slice():new s(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=Y(h,e),c=Y(o,e);for(let t=0;t<h.count;t++)for(let e=0;e<r;e++)i[u[t]*r+e]=c[t*r+e];return i}(t,r):Y(t,r).slice(),void 0!==t.normalized&&e.setNormalized(t.normalized),e.setArray(s),e}),c=i.textures||[],a=(i.images||[]).map(t=>{const e=n.createTexture(t.name);if(void 0!==t.bufferView){const s=i.bufferViews[t.bufferView],n=r.json.buffers[s.buffer],h=s.byteOffset||0,o=(n.uri?r.resources[n.uri]:r.resources["rt"]).slice(h,h+s.byteLength);e.setImage(o)}else void 0!==t.uri&&(e.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&e.setURI(t.uri));if(void 0!==t.mimeType)e.setMimeType(t.mimeType);else if(t.uri){const s=A.extension(t.uri);e.setMimeType("png"===s?"image/png":"image/jpeg")}return e}),f=(i.materials||[]).map(t=>{const e=n.createMaterial(t.name);void 0!==t.alphaMode&&e.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&e.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&e.setDoubleSided(t.doubleSided);const s=t.pbrMetallicRoughness||{};if(void 0!==s.baseColorFactor&&e.setBaseColorFactor(s.baseColorFactor),void 0!==t.emissiveFactor&&e.setEmissiveFactor(t.emissiveFactor),void 0!==s.metallicFactor&&e.setMetallicFactor(s.metallicFactor),void 0!==s.roughnessFactor&&e.setRoughnessFactor(s.roughnessFactor),void 0!==s.baseColorTexture){const t=s.baseColorTexture;e.setBaseColorTexture(a[c[t.index].source]),V(e.getBaseColorTextureInfo(),t),W(e.getBaseColorTextureSampler(),t,r)}if(void 0!==t.emissiveTexture){const s=t.emissiveTexture;e.setEmissiveTexture(a[c[s.index].source]),V(e.getEmissiveTextureInfo(),s),W(e.getEmissiveTextureSampler(),s,r)}if(void 0!==t.normalTexture){const s=t.normalTexture;e.setNormalTexture(a[c[s.index].source]),V(e.getNormalTextureInfo(),s),W(e.getNormalTextureSampler(),s,r),void 0!==t.normalTexture.scale&&e.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const s=t.occlusionTexture;e.setOcclusionTexture(a[c[s.index].source]),V(e.getOcclusionTextureInfo(),s),W(e.getOcclusionTextureSampler(),s,r),void 0!==t.occlusionTexture.strength&&e.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==s.metallicRoughnessTexture){const t=s.metallicRoughnessTexture;e.setMetallicRoughnessTexture(a[c[t.index].source]),V(e.getMetallicRoughnessTextureInfo(),t),W(e.getMetallicRoughnessTextureSampler(),t,r)}return e}),d=(i.meshes||[]).map(t=>{const e=n.createMesh(t.name);return void 0!==t.weights&&e.setWeights(t.weights),t.primitives.forEach(s=>{const r=n.createPrimitive();void 0!==s.material&&r.setMaterial(f[s.material]),void 0!==s.mode&&r.setMode(s.mode);for(const[t,e]of Object.entries(s.attributes||{}))r.setAttribute(t,u[e]);void 0!==s.indices&&r.setIndices(u[s.indices]);const i=t.extras&&t.extras.targetNames||[];(s.targets||[]).forEach((t,e)=>{const s=i[e]||e.toString(),h=n.createPrimitiveTarget(s);for(const[e,s]of Object.entries(t))h.setAttribute(e,u[s]);r.addTarget(h)}),e.addPrimitive(r)}),e}),g=(i.cameras||[]).map(t=>{const e=n.createCamera(t.name).setType(t.type);return"perspective"===t.type?e.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):e.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),e}),p=i.nodes||[],m=p.map(r=>{const i=n.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(e([],r.matrix)),i.setScale(s([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),v=(i.skins||[]).map(t=>{const e=n.createSkin(t.name);void 0!==t.inverseBindMatrices&&e.setInverseBindMatrices(u[t.inverseBindMatrices]),void 0!==t.skeleton&&e.setSkeleton(m[t.skeleton]);for(const s of t.joints)e.addJoint(m[s]);return e});return p.map((t,e)=>{const s=m[e];(t.children||[]).forEach(t=>s.addChild(m[t])),void 0!==t.mesh&&s.setMesh(d[t.mesh]),void 0!==t.camera&&s.setCamera(g[t.camera]),void 0!==t.skin&&s.setSkin(v[t.skin])}),(i.animations||[]).map(t=>{const e=n.createAnimation(t.name),s=(t.samplers||[]).map(t=>{const s=n.createAnimationSampler().setInput(u[t.input]).setOutput(u[t.output]).setInterpolation(t.interpolation||"LINEAR");return e.addSampler(s),s});return(t.channels||[]).forEach(t=>{const r=n.createAnimationChannel().setSampler(s[t.sampler]).setTargetNode(m[t.target.node]).setTargetPath(t.target.path);e.addChannel(r)}),e}),(i.scenes||[]).map(t=>{const e=n.createScene(t.name);return(t.nodes||[]).map(t=>m[t]).forEach(t=>e.addNode(t)),e}),n}}function V(t,e){void 0!==e.texCoord&&t.setTexCoord(e.texCoord)}function W(t,e,s){const r=s.json.textures[e.index];if(void 0===r.sampler)return;const i=s.json.samplers[r.sampler];void 0!==i.magFilter&&t.setMagFilter(i.magFilter),void 0!==i.minFilter&&t.setMinFilter(i.minFilter),void 0!==i.wrapS&&t.setWrapS(i.wrapS),void 0!==i.wrapT&&t.setWrapT(i.wrapT)}function Y(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["rt"],n=$[t.componentType],h=l.getElementSize(t.type);if(void 0!==s.byteStride&&s.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["rt"],n=$[t.componentType],h=l.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,s.byteOffset,s.byteLength),f=s.byteStride;for(let e=0;e<t.count;e++)for(let s=0;s<h;s++){const r=u+e*f+s*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[e*h+s]=i}return c}(t,e);const o=(s.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 Z{static write(t,e){const s=t.getRoot(),r={json:{asset:s.getAsset()},resources:{}},i=r.json,n=t.getLogger(),h=s.listBuffers().length,o=s.listTextures().length,u=new H(h>1,e.basename),c=new H(o>1,e.basename),a=new Map,f=new Map,d=new Map,g=new Map,p=new Map,m=new Map,v=new Map,A=new Map,T=new Map,x=[];function y(t,e,s,r){const n=[];let h=0;for(const e of t){const t=q(e);t.bufferView=i.bufferViews.length;const s=w.pad(e.getArray().buffer);t.byteOffset=h,h+=s.byteLength,n.push(s),a.set(e,i.accessors.length),i.accessors.push(t)}const o={buffer:e,byteOffset:s,byteLength:w.concat(n).byteLength};return r&&(o.target=r),i.bufferViews.push(o),{buffers:n,byteLength:h}}function M(t,e,s){const r=t[0].getCount();let n=0;for(const e of t){const t=q(e);t.bufferView=i.bufferViews.length,t.byteOffset=n;const s=e.getElementSize(),r=e.getComponentSize();n+=w.padNumber(s*r),a.set(e,i.accessors.length),i.accessors.push(t)}const h=r*n,o=new ArrayBuffer(h),u=new DataView(o);for(let e=0;e<r;e++){let s=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const c=e*n+s+r*i,a=o[e*t+r];switch(h){case 5126:u.setFloat32(c,a,!0);break;case 5120:u.setInt8(c,a);break;case 5122:u.setInt16(c,a,!0);break;case 5121:u.setUint8(c,a);break;case 5123:u.setUint16(c,a,!0);break;case 5125:u.setUint32(c,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}s+=w.padNumber(t*i)}}return i.bufferViews.push({buffer:e,byteOffset:s,byteLength:h,byteStride:n,target:34962}),{byteLength:h,buffers:[o]}}function b(t,e,s){const r={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},n=JSON.stringify(r);T.has(n)||(T.set(n,i.samplers.length),i.samplers.push(r));const h={source:v.get(t),sampler:T.get(n)},o=JSON.stringify(h);return A.has(o)||(A.set(o,i.textures.length),i.textures.push(h)),{index:A.get(o),texCoord:e.getTexCoord()}}const E=new Map;for(const e of t.getGraph().getLinks()){if(e.getParent()===s)continue;const t=e.getChild();if(t instanceof l){const s=E.get(t)||[];s.push(e),E.set(t,s)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=s.listTextures().map((t,s)=>{const n=X(t);if(t.getMimeType()&&(n.mimeType=t.getMimeType()),e.isGLB)x.push(t.getImage()),n.bufferView=i.bufferViews.length,i.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.getImage().byteLength});else{const e="image/png"===t.getMimeType()?"png":"jpeg";n.uri=c.createURI(t,e),r.resources[n.uri]=t.getImage()}return v.set(t,s),n}),i.buffers=[],s.listBuffers().forEach(t=>{const s=X(t),h=new Map,o=new Set,c=new Set,a=t.listParents().filter(t=>!(t instanceof G));for(const t of a){if(!(t instanceof l))throw new Error("Unimplemented buffer reference: "+t);let e=!1,s=!1,r=!1;const i=E.get(t)||[];for(const t of i)t instanceof B?e=!0:t instanceof k?s=!0:r=!0;if(e||s||r||(r=!0),!e||s||r)if(!s||e||r){if(!r||e||s)throw new Error("Attribute or index accessors must be used only for that purpose.");c.add(t)}else o.add(t);else{const e=i[0].getParent(),s=h.get(e)||new Set;s.add(t),h.set(e,s)}}const f=[],d=i.buffers.length;let g,p=0;if(o.size){const t=y(Array.from(o),d,p,34963);p+=t.byteLength,f.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const e=M(Array.from(t),d,p);p+=e.byteLength,f.push(...e.buffers)}if(c.size){const t=y(Array.from(c),d,p);p+=t.byteLength,f.push(...t.buffers)}if(x.length)for(let t=0;t<x.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=p,p+=x[t].byteLength,f.push(x[t]);p?(e.isGLB?g="__glb.bin":(g=u.createURI(t,"bin"),s.uri=g),s.byteLength=p,r.resources[g]=w.concat(f),i.buffers.push(s)):n.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=s.listMaterials().map((t,e)=>{const s=X(t);if(s.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(s.alphaCutoff=t.getAlphaCutoff()),s.doubleSided=t.getDoubleSided(),s.pbrMetallicRoughness={},s.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),s.emissiveFactor=t.getEmissiveFactor(),s.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),s.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const e=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo(),i=t.getBaseColorTextureSampler();s.pbrMetallicRoughness.baseColorTexture=b(e,r,i)}if(t.getEmissiveTexture()){const e=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();s.emissiveTexture=b(e,r,i)}if(t.getNormalTexture()){const e=b(t.getNormalTexture(),t.getNormalTextureInfo(),t.getNormalTextureSampler());1!==t.getNormalScale()&&(e.scale=t.getNormalScale()),s.normalTexture=e}if(t.getOcclusionTexture()){const e=b(t.getOcclusionTexture(),t.getOcclusionTextureInfo(),t.getOcclusionTextureSampler());1!==t.getOcclusionStrength()&&(e.strength=t.getOcclusionStrength()),s.occlusionTexture=e}if(t.getMetallicRoughnessTexture()){const e=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();s.pbrMetallicRoughness.metallicRoughnessTexture=b(e,r,i)}return g.set(t,e),s}),i.meshes=s.listMeshes().map((t,e)=>{const s=X(t);let r;return s.primitives=t.listPrimitives().map(t=>{const e={attributes:{}};e.material=g.get(t.getMaterial()),e.mode=t.getMode(),t.getIndices()&&(e.indices=a.get(t.getIndices()));for(const s of t.listSemantics())e.attributes[s]=a.get(t.getAttribute(s));for(const s of t.listTargets()){const t={};for(const e of s.listSemantics())t[e]=a.get(s.getAttribute(e));e.targets=e.targets||[],e.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),e}),t.getWeights().length&&(s.weights=t.getWeights()),r&&(s.extras=s.extras||{},s.extras.targetNames=r),p.set(t,e),s}),i.cameras=s.listCameras().map((t,e)=>{const s=X(t);return s.type=t.getType(),"perspective"===s.type?s.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:s.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},f.set(t,e),s}),i.nodes=s.listNodes().map((t,e)=>{const s=X(t);return s.translation=t.getTranslation(),s.rotation=t.getRotation(),s.scale=t.getScale(),t.getWeights().length&&(s.weights=t.getWeights()),m.set(t,e),s}),i.skins=s.listSkins().map((t,e)=>{const s=X(t);return t.getInverseBindMatrices()&&(s.inverseBindMatrices=a.get(t.getInverseBindMatrices())),t.getSkeleton()&&(s.skeleton=m.get(t.getSkeleton())),s.joints=t.listJoints().map(t=>m.get(t)),d.set(t,e),s}),s.listNodes().forEach((t,e)=>{const s=i.nodes[e];t.getMesh()&&(s.mesh=p.get(t.getMesh())),t.getCamera()&&(s.camera=f.get(t.getCamera())),t.getSkin()&&(s.skin=d.get(t.getSkin())),t.listChildren().length>0&&(s.children=t.listChildren().map(t=>m.get(t)))}),i.animations=s.listAnimations().map(t=>{const e=X(t),s=new Map;return e.samplers=t.listSamplers().map((t,e)=>{const r=X(t);return r.input=a.get(t.getInput()),r.output=a.get(t.getOutput()),r.interpolation=t.getInterpolation(),s.set(t,e),r}),e.channels=t.listChannels().map(t=>{const e=X(t);return e.sampler=s.get(t.getSampler()),e.target={node:m.get(t.getTargetNode()),path:t.getTargetPath()},e}),e}),i.scenes=s.listScenes().map(t=>{const e=X(t);return e.nodes=t.listNodes().map(t=>m.get(t)),e}),function(t){const e=[];for(const s in t){const r=t[s];Array.isArray(r)&&0===r.length?e.push(s):null!==r&&""!==r||e.push(r)}for(const s of e)delete t[s]}(i),r}}function X(t){const e={};return t.getName()&&(e.name=t.getName()),Object.keys(t.getExtras()).length>0&&(e.extras=t.getExtras()),Object.keys(t.getExtensions()).length>0&&(e.extras=t.getExtensions()),e}function q(t){const e=X(t);return e.type=t.getType(),e.componentType=t.getComponentType(),e.count=t.getCount(),t.getMax(e.max=[]),t.getMin(e.min=[]),e.normalized=t.getNormalized(),e}class H{constructor(t,e){this.multiple=t,this.basename=e,this.counter=1}createURI(t,e){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${e}`:`${this.basename}.${e}`}}class K{createDocument(t){return J.read(t)}createNativeDocument(t,e){if(e.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return Z.write(t,e)}unpackGLB(t){const e=new Uint32Array(t,0,3);if(1179937895!==e[0])throw new Error("Invalid glTF asset.");if(2!==e[1])throw new Error(`Unsupported glTF binary version, "${e[1]}".`);const s=new Uint32Array(t,12,2),r=s[0],i=new Uint32Array(t,20+r,2);if(1313821514!==s[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=w.decodeText(t.slice(20,20+r)),h=JSON.parse(n),o=20+r+8,u=t.slice(o,o+i[0]);return this.createDocument({json:h,resources:{rt:u}})}packGLB(t){const{json:e,resources:s}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(e),i=w.pad(w.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=w.concat([n,i]),o=w.pad(Object.values(s)[0],0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=w.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return w.concat([a,h,c])}}class Q extends K{constructor(t,e){super(),this.fs=t,this.path=e}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,e){t.match(/\.glb$/)?this.writeGLB(t,e):this.writeGLTF(t,e)}readGLB(t){const e=this.fs.readFileSync(t),s=w.trim(e);return this.unpackGLB(s)}readGLTF(t){const e=this.path.dirname(t),s={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...s.json.images||[],...s.json.buffers||[]].forEach(t=>{if(t.uri&&!t.uri.match(/data:/)){const r=this.path.resolve(e,t.uri);s.resources[t.uri]=w.trim(this.fs.readFileSync(r))}else{const e=`__${S()}.${A.extension(t.uri)}`;s.resources[e]=w.createBufferFromDataURI(t.uri),t.uri=e}}),J.read(s)}writeGLTF(t,e){const s={basename:A.basename(t),isGLB:!1},{json:r,resources:i}=Z.write(e,s),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const e=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),e)})}writeGLB(t,e){const s=Buffer.from(this.packGLB(e));this.fs.writeFileSync(t,s)}}class tt extends K{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const e={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{e.json=t;const s=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(s=>{e.resources[t.uri]=s})});return Promise.all(s).then(()=>this.createDocument(e))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}r.setMatrixArrayType(Array);export{l as Accessor,d as Animation,g as AnimationChannel,p as AnimationSampler,m as Buffer,w as BufferUtils,v as Camera,z as Document,A as FileUtils,h as Graph,T as ImageUtils,y as Logger,L as Material,O as Mesh,F as Node,Q as NodeIO,P as Primitive,_ as PrimitiveTarget,a as Property,G as Root,j as Scene,D as Skin,N as Texture,C as TextureInfo,R as TextureSampler,tt as WebIO,S as uuid}; | ||
import{getTranslation as t,getRotation as e,getScaling as s}from"gl-matrix/mat4";function r(t,e,s,r){var i,n=arguments.length,h=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,s,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(e,s,h):i(e,s))||h);return n>3&&h&&Object.defineProperty(e,s,h),h}class i{constructor(t,e,s){if(this.t=t,this.s=e,this.i=s,this.h=!1,this.o=[],!e.canLink(s))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 n{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(e=>e.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(e=>e.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(e=>e.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,e){let s=this.u.filter(e=>e.getChild()===t);return e&&(s=s.filter(t=>e(t.getParent()))),s.forEach(t=>t.dispose()),this}link(t,e,s){if(!s)return null;const r=new i(t,e,s);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(e=>e!==t),this}}function h(t,e){Object.defineProperty(t,e,{get:function(){return this["__"+e]},set:function(t){const s=this["__"+e];s&&!Array.isArray(s)&&s.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+e]=null}),this["__"+e]=t},enumerable:!0})}function o(t,e){}class u extends Error{constructor(){super("@gltf-transform/core: Not implemented.")}}class c extends class{constructor(t){this.h=!1,this.l=t}canLink(t){return this.l===t.l}isDisposed(){return this.h}dispose(){this.l.disconnectChildren(this),this.l.disconnectParents(this),this.h=!0}detach(){return this.l.disconnectParents(this),this}swap(t,e){return this.l.getLinks().filter(e=>e.getParent()===this&&e.getChild()===t).forEach(t=>t.setChild(e)),this}addGraphChild(t,e){return t.push(e),e.onDispose(()=>{const s=t.filter(t=>t!==e);t.length=0,t.push(...s)}),this}removeGraphChild(t,e){return t.filter(t=>t.getChild()===e).forEach(t=>t.dispose()),this}listGraphParents(){return this.l.listParents(this)}}{constructor(t,e=""){super(t),this.t="",this.g={},this.p={},this.t=e}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.g}setExtras(t){return this.g=t,this}getExtensions(){return this.p}setExtensions(t){return this.p=t,this}clone(){throw new u}detach(){return this.l.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class a extends c{constructor(){super(...arguments),this.propertyType="Accessor",this.m=null,this.v="SCALAR",this.A=null,this.T=!1,this.M=l,this.S=l,this.buffer=null}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 e=this.getElementSize();this.getMin(t);for(let s=0;s<e;s++)t[s]=this.S(t[s]);return t}getMin(t){const e=this.getCount(),s=this.getElementSize();for(let e=0;e<s;e++)t[e]=Infinity;for(let r=0;r<e*s;r+=s)for(let e=0;e<s;e++){const s=this.m[r+e];Number.isFinite(s)&&(t[e]=Math.min(t[e],s))}return t}getMaxNormalized(t){const e=this.getElementSize();this.getMax(t);for(let s=0;s<e;s++)t[s]=this.S(t[s]);return t}getMax(t){const e=this.getCount(),s=this.getElementSize();for(let e=0;e<s;e++)t[e]=-Infinity;for(let r=0;r<e*s;r+=s)for(let e=0;e<s;e++){const s=this.m[r+e];Number.isFinite(s)&&(t[e]=Math.max(t[e],s))}return t}getCount(){return this.m.length/this.getElementSize()}getType(){return this.v}setType(t){return this.v=t,this}getElementSize(){return a.getElementSize(this.v)}getComponentSize(){return this.m.BYTES_PER_ELEMENT}getComponentType(){return this.A}getNormalized(){return this.T}setNormalized(t){return this.T=t,t?(this.S=t=>function(t,e){switch(e){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)}}(t,this.A),this.M=t=>function(t,e){switch(e){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)}}(t,this.A)):(this.S=l,this.M=l),this}getScalar(t){const e=this.getElementSize();return this.S(this.m[t*e])}setScalar(t,e){return this.m[t*this.getElementSize()]=this.M(e),this}getElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)e[r]=this.S(this.m[t*s+r]);return e}setElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)this.m[t*s+r]=this.M(e[r]);return this}getBuffer(){return this.buffer.getChild()}setBuffer(t){return this.buffer=this.l.link("buffer",this,t),this}getArray(){return this.m}setArray(t){return this.A=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.m=t,this}getByteLength(){return this.m.byteLength}}function l(t){return t}a.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},a.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},r([h],a.prototype,"buffer",void 0);class f extends c{constructor(){super(...arguments),this.propertyType="Animation",this.channels=[],this.samplers=[]}addChannel(t){const e=this.l.link("channel",this,t);return this.addGraphChild(this.channels,e)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const e=this.l.link("sampler",this,t);return this.addGraphChild(this.samplers,e)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}r([o],f.prototype,"channels",void 0),r([o],f.prototype,"samplers",void 0);class d extends c{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.N=null,this.targetNode=null,this.sampler=null}getTargetPath(){return this.N}setTargetPath(t){return this.N=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.l.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.l.link("sampler",this,t),this}}r([h],d.prototype,"targetNode",void 0),r([h],d.prototype,"sampler",void 0);class g extends c{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.C="LINEAR",this.input=null,this.output=null}getInterpolation(){return this.C}setInterpolation(t){return this.C=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.l.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.l.link("output",this,t),this}}r([h],g.prototype,"input",void 0),r([h],g.prototype,"output",void 0);class p extends c{constructor(){super(...arguments),this.propertyType="Buffer"}getURI(){return this.R}setURI(t){return this.R=t,this}}class m extends c{constructor(){super(...arguments),this.propertyType="Camera",this.v="perspective"}getType(){return this.v}setType(t){return this.v=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.B}setZFar(t){return this.B=t,this}getAspectRatio(){return this.k}setAspectRatio(t){return this.k=t,this}getYFov(){return this.U}setYFov(t){return this.U=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 v{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const e=atob(t.split(",")[1]),s=new Uint8Array(e.length);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s.buffer}{const e=t.split(",")[1],s=t.indexOf("base64")>=0;return this.trim(Buffer.from(e,s?"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:e,byteLength:s}=t;return t.buffer.slice(e,e+s)}static concat(t){let e=0;for(const s of t)e+=s.byteLength;const s=new Uint8Array(e);let r=0;for(const e of t)s.set(new Uint8Array(e),r),r+=e.byteLength;return s.buffer}static pad(t,e=0){const s=this.padNumber(t.byteLength);if(s!==t.byteLength){const r=new Uint8Array(s);if(r.set(new Uint8Array(t)),0!==e)for(let i=t.byteLength;i<s;i++)r[i]=e;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const s=new DataView(t),r=new DataView(e);let i=t.byteLength;for(;i--;)if(s.getUint8(i)!==r.getUint8(i))return!1;return!0}}class w{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 A{static getSizeJPEG(t){let e,s;for(t=t.slice(4);t.length;){if(e=t.readUInt16BE(0),T(t,e),s=t[e+1],192===s||193===s||194===s)return[t.readUInt16BE(e+7),t.readUInt16BE(e+5)];t=t.slice(e+2)}throw new TypeError("Invalid JPG, no size found")}static getSizePNG(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]}}function T(t,e){if(e>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[e])throw new TypeError("Invalid JPG, marker table corrupted")}class x{constructor(t){this.verbosity=t}debug(t){this.verbosity<=x.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=x.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=x.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=x.Verbosity.ERROR&&console.error(t)}}x.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const b="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",M=new Set,y=function(){let t="";for(let e=0;e<6;e++)t+=b.charAt(Math.floor(Math.random()*b.length));return t},E=function(){for(let t=0;t<999;t++){const t=y();if(!M.has(t))return t}return""};class S extends c{constructor(){super(...arguments),this.propertyType="Texture",this.image=null,this.mimeType="",this.uri=""}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?A.getSizePNG(Buffer.from(this.image)):A.getSizeJPEG(Buffer.from(this.image))}}class N{constructor(){this.propertyType="TextureInfo",this.texCoord=0}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class C{constructor(){this.propertyType="TextureSampler",this.P=null,this._=null,this.F=10497,this.G=10497}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this._}setMinFilter(t){return this._=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.G}setWrapT(t){return this.G=t,this}}C.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},C.TextureMagFilter={NEAREST:9728,LINEAR:9729},C.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class R extends i{constructor(){super(...arguments),this.textureInfo=new N,this.sampler=new C}}class I extends i{constructor(){super(...arguments),this.semantic=""}}class B extends i{}class k extends n{linkTexture(t,e,s){if(!s)return null;const r=new R(t,e,s);return this.registerLink(r),r}linkAttribute(t,e,s){if(!s)return null;const r=new I(t,e,s);return this.registerLink(r),r}linkIndex(t,e,s){if(!s)return null;const r=new B(t,e,s);return this.registerLink(r),r}}class U extends c{constructor(){super(...arguments),this.propertyType="Material",this.j="OPAQUE",this.D=.5,this.$=!1,this.J=[1,1,1,1],this.V=[0,0,0],this.W=1,this.Y=1,this.Z=1,this.X=1,this.baseColorTexture=null,this.emissiveTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.metallicRoughnessTexture=null}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=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.J}setBaseColorFactor(t){return this.J=t,this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null}getBaseColorTextureSampler(){return this.baseColorTexture?this.baseColorTexture.sampler:null}setBaseColorTexture(t){return this.baseColorTexture=this.l.linkTexture("baseColorTexture",this,t),this}getEmissiveFactor(){return this.V}setEmissiveFactor(t){return this.V=t,this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null}getEmissiveTextureSampler(){return this.emissiveTexture?this.emissiveTexture.sampler:null}setEmissiveTexture(t){return this.emissiveTexture=this.l.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.l.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.l.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.Z}setRoughnessFactor(t){return this.Z=t,this}getMetallicFactor(){return this.X}setMetallicFactor(t){return this.X=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.l.linkTexture("metallicRoughnessTexture",this,t),this}}r([h],U.prototype,"baseColorTexture",void 0),r([h],U.prototype,"emissiveTexture",void 0),r([h],U.prototype,"normalTexture",void 0),r([h],U.prototype,"occlusionTexture",void 0),r([h],U.prototype,"metallicRoughnessTexture",void 0);class L extends c{constructor(){super(...arguments),this.propertyType="Mesh",this.q=[],this.primitives=[]}addPrimitive(t){return this.addGraphChild(this.primitives,this.l.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.q}setWeights(t){return this.q=t,this}}r([o],L.prototype,"primitives",void 0);class O extends c{constructor(){super(...arguments),this.propertyType="Primitive",this.H=4,this.indices=null,this.attributes=[],this.targets=[],this.material=null}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.l.linkIndex("index",this,t),this}getAttribute(t){const e=this.attributes.find(e=>e.semantic===t);return e?e.getChild():null}setAttribute(t,e){const s=this.getAttribute(t);if(s&&this.removeGraphChild(this.attributes,s),!e)return this;const r=this.l.linkAttribute(t.toLowerCase(),this,e);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.l.link("material",this,t),this}getMode(){return this.H}setMode(t){return this.H=t,this}listTargets(){return this.targets.map(t=>t.getChild())}addTarget(t){return this.addGraphChild(this.targets,this.l.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}r([h],O.prototype,"indices",void 0),r([o],O.prototype,"attributes",void 0),r([o],O.prototype,"targets",void 0),r([h],O.prototype,"material",void 0);class P extends c{constructor(){super(...arguments),this.propertyType="PrimitiveTarget",this.attributes=[]}getAttribute(t){const e=this.attributes.find(e=>e.semantic===t);return e?e.getChild():null}setAttribute(t,e){const s=this.getAttribute(t);if(s&&this.removeGraphChild(this.attributes,s),!e)return this;const r=this.l.linkAttribute(t.toLowerCase(),this,e);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}}r([o],P.prototype,"attributes",void 0);class _ extends c{constructor(){super(...arguments),this.propertyType="Node",this.K=[0,0,0],this.tt=[0,0,0,1],this.et=[1,1,1],this.q=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}getTranslation(){return this.K}getRotation(){return this.tt}getScale(){return this.et}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.et=t,this}addChild(t){const e=this.l.link("child",this,t);return this.addGraphChild(this.children,e)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.l.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.l.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.l.link("skin",this,t),this}getWeights(){return this.q}setWeights(t){return this.q=t,this}}r([h],_.prototype,"camera",void 0),r([h],_.prototype,"mesh",void 0),r([h],_.prototype,"skin",void 0),r([o],_.prototype,"children",void 0);class F extends c{constructor(){super(...arguments),this.propertyType="Root",this.st={generator:"glTF-Transform v0.3.3",version:"2.0"},this.scenes=[],this.nodes=[],this.cameras=[],this.skins=[],this.meshes=[],this.materials=[],this.textures=[],this.animations=[],this.accessors=[],this.buffers=[]}getAsset(){return this.st}addScene(t){return this.addGraphChild(this.scenes,this.l.link("scene",this,t))}removeScene(t){return this.removeGraphChild(this.scenes,t)}listScenes(){return this.scenes.map(t=>t.getChild())}addNode(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}addCamera(t){return this.addGraphChild(this.cameras,this.l.link("camera",this,t))}removeCamera(t){return this.removeGraphChild(this.cameras,t)}listCameras(){return this.cameras.map(t=>t.getChild())}addSkin(t){return this.addGraphChild(this.skins,this.l.link("skin",this,t))}removeSkin(t){return this.removeGraphChild(this.skins,t)}listSkins(){return this.skins.map(t=>t.getChild())}addMesh(t){return this.addGraphChild(this.meshes,this.l.link("mesh",this,t))}removeMesh(t){return this.removeGraphChild(this.meshes,t)}listMeshes(){return this.meshes.map(t=>t.getChild())}addMaterial(t){return this.addGraphChild(this.materials,this.l.link("material",this,t))}removeMaterial(t){return this.removeGraphChild(this.materials,t)}listMaterials(){return this.materials.map(t=>t.getChild())}addTexture(t){return this.addGraphChild(this.textures,this.l.link("texture",this,t))}removeTexture(t){return this.removeGraphChild(this.textures,t)}listTextures(){return this.textures.map(t=>t.getChild())}addAnimation(t){return this.addGraphChild(this.animations,this.l.link("animation",this,t))}removeAnimation(t){return this.removeGraphChild(this.animations,t)}listAnimations(){return this.animations.map(t=>t.getChild())}addAccessor(t){return this.addGraphChild(this.accessors,this.l.link("accessor",this,t))}removeAccessor(t){return this.removeGraphChild(this.accessors,t)}listAccessors(){return this.accessors.map(t=>t.getChild())}addBuffer(t){return this.addGraphChild(this.buffers,this.l.link("buffer",this,t))}removeBuffer(t){return this.removeGraphChild(this.buffers,t)}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([o],F.prototype,"scenes",void 0),r([o],F.prototype,"nodes",void 0),r([o],F.prototype,"cameras",void 0),r([o],F.prototype,"skins",void 0),r([o],F.prototype,"meshes",void 0),r([o],F.prototype,"materials",void 0),r([o],F.prototype,"textures",void 0),r([o],F.prototype,"animations",void 0),r([o],F.prototype,"accessors",void 0),r([o],F.prototype,"buffers",void 0);class G extends c{constructor(){super(...arguments),this.propertyType="Scene",this.nodes=[]}addNode(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([o],G.prototype,"nodes",void 0);class j extends c{constructor(){super(...arguments),this.propertyType="Skin",this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.l.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.l.link("inverseBindMatrices",this,t),this}addJoint(t){const e=this.l.link("joint",this,t);return this.addGraphChild(this.joints,e)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}r([h],j.prototype,"skeleton",void 0),r([h],j.prototype,"inverseBindMatrices",void 0),r([o],j.prototype,"joints",void 0);class D{constructor(){this.graph=new k,this.root=new F(this.graph),this.logger=new x(x.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){throw new Error("Not implemented.")}transform(...t){for(const e of t)e(this);return this}createScene(t){const e=new G(this.graph,t);return this.root.addScene(e),e}createNode(t){const e=new _(this.graph,t);return this.root.addNode(e),e}createCamera(t){const e=new m(this.graph,t);return this.root.addCamera(e),e}createSkin(t){const e=new j(this.graph,t);return this.root.addSkin(e),e}createMesh(t){const e=new L(this.graph,t);return this.root.addMesh(e),e}createPrimitive(){return new O(this.graph)}createPrimitiveTarget(t){return new P(this.graph,t)}createMaterial(t){const e=new U(this.graph,t);return this.root.addMaterial(e),e}createTexture(t){const e=new S(this.graph,t);return this.root.addTexture(e),e}createAnimation(t){const e=new f(this.graph,t);return this.root.addAnimation(e),e}createAnimationChannel(){return new d(this.graph)}createAnimationSampler(){return new g(this.graph)}createAccessor(t,e=null){e||(e=this.getRoot().listBuffers()[0]);const s=new a(this.graph,t).setBuffer(e);return this.root.addAccessor(s),s}createBuffer(t){const e=new p(this.graph,t);return this.root.addBuffer(e),e}}const z={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class ${static read(r){const{json:i}=r,n=new D;if("2.0"!==i.asset.version)throw new Error(`Unsupported glTF version: "${i.asset.version}".`);const h=(i.buffers||[]).map(t=>{const e=n.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&e.setURI(t.uri),e}),o=(i.bufferViews||[]).map(t=>h[t.buffer]),u=(i.accessors||[]).map(t=>{const e=n.createAccessor(t.name,o[t.bufferView]);let s;return e.setType(t.type),s=void 0!==t.sparse?function(t,e){const s=z[t.componentType],r=a.getElementSize(t.type);let i;i=void 0!==t.bufferView?W(t,e).slice():new s(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=W(h,e),c=W(o,e);for(let t=0;t<h.count;t++)for(let e=0;e<r;e++)i[u[t]*r+e]=c[t*r+e];return i}(t,r):W(t,r).slice(),void 0!==t.normalized&&e.setNormalized(t.normalized),e.setArray(s),e}),c=i.textures||[],l=(i.images||[]).map(t=>{const e=n.createTexture(t.name);if(void 0!==t.bufferView){const s=i.bufferViews[t.bufferView],n=r.json.buffers[s.buffer],h=s.byteOffset||0,o=(n.uri?r.resources[n.uri]:r.resources["rt"]).slice(h,h+s.byteLength);e.setImage(o)}else void 0!==t.uri&&(e.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&e.setURI(t.uri));if(void 0!==t.mimeType)e.setMimeType(t.mimeType);else if(t.uri){const s=w.extension(t.uri);e.setMimeType("png"===s?"image/png":"image/jpeg")}return e}),f=(i.materials||[]).map(t=>{const e=n.createMaterial(t.name);void 0!==t.alphaMode&&e.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&e.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&e.setDoubleSided(t.doubleSided);const s=t.pbrMetallicRoughness||{};if(void 0!==s.baseColorFactor&&e.setBaseColorFactor(s.baseColorFactor),void 0!==t.emissiveFactor&&e.setEmissiveFactor(t.emissiveFactor),void 0!==s.metallicFactor&&e.setMetallicFactor(s.metallicFactor),void 0!==s.roughnessFactor&&e.setRoughnessFactor(s.roughnessFactor),void 0!==s.baseColorTexture){const t=s.baseColorTexture;e.setBaseColorTexture(l[c[t.index].source]),J(e.getBaseColorTextureInfo(),t),V(e.getBaseColorTextureSampler(),t,r)}if(void 0!==t.emissiveTexture){const s=t.emissiveTexture;e.setEmissiveTexture(l[c[s.index].source]),J(e.getEmissiveTextureInfo(),s),V(e.getEmissiveTextureSampler(),s,r)}if(void 0!==t.normalTexture){const s=t.normalTexture;e.setNormalTexture(l[c[s.index].source]),J(e.getNormalTextureInfo(),s),V(e.getNormalTextureSampler(),s,r),void 0!==t.normalTexture.scale&&e.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const s=t.occlusionTexture;e.setOcclusionTexture(l[c[s.index].source]),J(e.getOcclusionTextureInfo(),s),V(e.getOcclusionTextureSampler(),s,r),void 0!==t.occlusionTexture.strength&&e.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==s.metallicRoughnessTexture){const t=s.metallicRoughnessTexture;e.setMetallicRoughnessTexture(l[c[t.index].source]),J(e.getMetallicRoughnessTextureInfo(),t),V(e.getMetallicRoughnessTextureSampler(),t,r)}return e}),d=(i.meshes||[]).map(t=>{const e=n.createMesh(t.name);return void 0!==t.weights&&e.setWeights(t.weights),t.primitives.forEach(s=>{const r=n.createPrimitive();void 0!==s.material&&r.setMaterial(f[s.material]),void 0!==s.mode&&r.setMode(s.mode);for(const[t,e]of Object.entries(s.attributes||{}))r.setAttribute(t,u[e]);void 0!==s.indices&&r.setIndices(u[s.indices]);const i=t.extras&&t.extras.targetNames||[];(s.targets||[]).forEach((t,e)=>{const s=i[e]||e.toString(),h=n.createPrimitiveTarget(s);for(const[e,s]of Object.entries(t))h.setAttribute(e,u[s]);r.addTarget(h)}),e.addPrimitive(r)}),e}),g=(i.cameras||[]).map(t=>{const e=n.createCamera(t.name).setType(t.type);return"perspective"===t.type?e.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):e.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),e}),p=i.nodes||[],m=p.map(r=>{const i=n.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(e([],r.matrix)),i.setScale(s([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),v=(i.skins||[]).map(t=>{const e=n.createSkin(t.name);void 0!==t.inverseBindMatrices&&e.setInverseBindMatrices(u[t.inverseBindMatrices]),void 0!==t.skeleton&&e.setSkeleton(m[t.skeleton]);for(const s of t.joints)e.addJoint(m[s]);return e});return p.map((t,e)=>{const s=m[e];(t.children||[]).forEach(t=>s.addChild(m[t])),void 0!==t.mesh&&s.setMesh(d[t.mesh]),void 0!==t.camera&&s.setCamera(g[t.camera]),void 0!==t.skin&&s.setSkin(v[t.skin])}),(i.animations||[]).map(t=>{const e=n.createAnimation(t.name),s=(t.samplers||[]).map(t=>{const s=n.createAnimationSampler().setInput(u[t.input]).setOutput(u[t.output]).setInterpolation(t.interpolation||"LINEAR");return e.addSampler(s),s});return(t.channels||[]).forEach(t=>{const r=n.createAnimationChannel().setSampler(s[t.sampler]).setTargetNode(m[t.target.node]).setTargetPath(t.target.path);e.addChannel(r)}),e}),(i.scenes||[]).map(t=>{const e=n.createScene(t.name);return(t.nodes||[]).map(t=>m[t]).forEach(t=>e.addNode(t)),e}),n}}function J(t,e){void 0!==e.texCoord&&t.setTexCoord(e.texCoord)}function V(t,e,s){const r=s.json.textures[e.index];if(void 0===r.sampler)return;const i=s.json.samplers[r.sampler];void 0!==i.magFilter&&t.setMagFilter(i.magFilter),void 0!==i.minFilter&&t.setMinFilter(i.minFilter),void 0!==i.wrapS&&t.setWrapS(i.wrapS),void 0!==i.wrapT&&t.setWrapT(i.wrapT)}function W(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["rt"],n=z[t.componentType],h=a.getElementSize(t.type);if(void 0!==s.byteStride&&s.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["rt"],n=z[t.componentType],h=a.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),l=new DataView(i,s.byteOffset,s.byteLength),f=s.byteStride;for(let e=0;e<t.count;e++)for(let s=0;s<h;s++){const r=u+e*f+s*o;let i;switch(t.componentType){case 5126:i=l.getFloat32(r,!0);break;case 5125:i=l.getUint32(r,!0);break;case 5123:i=l.getUint16(r,!0);break;case 5121:i=l.getUint8(r);break;case 5122:i=l.getInt16(r,!0);break;case 5120:i=l.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[e*h+s]=i}return c}(t,e);const o=(s.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 Y{static write(t,e){const s=t.getRoot(),r={json:{asset:s.getAsset()},resources:{}},i=r.json,n=t.getLogger(),h=s.listBuffers().length,o=s.listTextures().length,u=new q(h>1,e.basename),c=new q(o>1,e.basename),l=new Map,f=new Map,d=new Map,g=new Map,p=new Map,m=new Map,w=new Map,A=new Map,T=new Map,x=[];function b(t,e,s,r){const n=[];let h=0;for(const e of t){const t=X(e);t.bufferView=i.bufferViews.length;const s=v.pad(e.getArray().buffer);t.byteOffset=h,h+=s.byteLength,n.push(s),l.set(e,i.accessors.length),i.accessors.push(t)}const o={buffer:e,byteOffset:s,byteLength:v.concat(n).byteLength};return r&&(o.target=r),i.bufferViews.push(o),{buffers:n,byteLength:h}}function M(t,e,s){const r=t[0].getCount();let n=0;for(const e of t){const t=X(e);t.bufferView=i.bufferViews.length,t.byteOffset=n;const s=e.getElementSize(),r=e.getComponentSize();n+=v.padNumber(s*r),l.set(e,i.accessors.length),i.accessors.push(t)}const h=r*n,o=new ArrayBuffer(h),u=new DataView(o);for(let e=0;e<r;e++){let s=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const c=e*n+s+r*i,a=o[e*t+r];switch(h){case 5126:u.setFloat32(c,a,!0);break;case 5120:u.setInt8(c,a);break;case 5122:u.setInt16(c,a,!0);break;case 5121:u.setUint8(c,a);break;case 5123:u.setUint16(c,a,!0);break;case 5125:u.setUint32(c,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}s+=v.padNumber(t*i)}}return i.bufferViews.push({buffer:e,byteOffset:s,byteLength:h,byteStride:n,target:34962}),{byteLength:h,buffers:[o]}}function y(t,e,s){const r={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},n=JSON.stringify(r);T.has(n)||(T.set(n,i.samplers.length),i.samplers.push(r));const h={source:w.get(t),sampler:T.get(n)},o=JSON.stringify(h);return A.has(o)||(A.set(o,i.textures.length),i.textures.push(h)),{index:A.get(o),texCoord:e.getTexCoord()}}const E=new Map;for(const e of t.getGraph().getLinks()){if(e.getParent()===s)continue;const t=e.getChild();if(t instanceof a){const s=E.get(t)||[];s.push(e),E.set(t,s)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=s.listTextures().map((t,s)=>{const n=Z(t);if(t.getMimeType()&&(n.mimeType=t.getMimeType()),e.isGLB)x.push(t.getImage()),n.bufferView=i.bufferViews.length,i.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.getImage().byteLength});else{const e="image/png"===t.getMimeType()?"png":"jpeg";n.uri=c.createURI(t,e),r.resources[n.uri]=t.getImage()}return w.set(t,s),n}),i.buffers=[],s.listBuffers().forEach(t=>{const s=Z(t),h=new Map,o=new Set,c=new Set,l=t.listParents().filter(t=>!(t instanceof F));for(const t of l){if(!(t instanceof a))throw new Error("Unimplemented buffer reference: "+t);let e=!1,s=!1,r=!1;const i=E.get(t)||[];for(const t of i)t instanceof I?e=!0:t instanceof B?s=!0:r=!0;if(e||s||r||(r=!0),!e||s||r)if(!s||e||r){if(!r||e||s)throw new Error("Attribute or index accessors must be used only for that purpose.");c.add(t)}else o.add(t);else{const e=i[0].getParent(),s=h.get(e)||new Set;s.add(t),h.set(e,s)}}const f=[],d=i.buffers.length;let g,p=0;if(o.size){const t=b(Array.from(o),d,p,34963);p+=t.byteLength,f.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const e=M(Array.from(t),d,p);p+=e.byteLength,f.push(...e.buffers)}if(c.size){const t=b(Array.from(c),d,p);p+=t.byteLength,f.push(...t.buffers)}if(x.length)for(let t=0;t<x.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=p,p+=x[t].byteLength,f.push(x[t]);p?(e.isGLB?g="__glb.bin":(g=u.createURI(t,"bin"),s.uri=g),s.byteLength=p,r.resources[g]=v.concat(f),i.buffers.push(s)):n.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=s.listMaterials().map((t,e)=>{const s=Z(t);if(s.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(s.alphaCutoff=t.getAlphaCutoff()),s.doubleSided=t.getDoubleSided(),s.pbrMetallicRoughness={},s.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),s.emissiveFactor=t.getEmissiveFactor(),s.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),s.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const e=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo(),i=t.getBaseColorTextureSampler();s.pbrMetallicRoughness.baseColorTexture=y(e,r,i)}if(t.getEmissiveTexture()){const e=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();s.emissiveTexture=y(e,r,i)}if(t.getNormalTexture()){const e=y(t.getNormalTexture(),t.getNormalTextureInfo(),t.getNormalTextureSampler());1!==t.getNormalScale()&&(e.scale=t.getNormalScale()),s.normalTexture=e}if(t.getOcclusionTexture()){const e=y(t.getOcclusionTexture(),t.getOcclusionTextureInfo(),t.getOcclusionTextureSampler());1!==t.getOcclusionStrength()&&(e.strength=t.getOcclusionStrength()),s.occlusionTexture=e}if(t.getMetallicRoughnessTexture()){const e=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();s.pbrMetallicRoughness.metallicRoughnessTexture=y(e,r,i)}return g.set(t,e),s}),i.meshes=s.listMeshes().map((t,e)=>{const s=Z(t);let r;return s.primitives=t.listPrimitives().map(t=>{const e={attributes:{}};e.material=g.get(t.getMaterial()),e.mode=t.getMode(),t.getIndices()&&(e.indices=l.get(t.getIndices()));for(const s of t.listSemantics())e.attributes[s]=l.get(t.getAttribute(s));for(const s of t.listTargets()){const t={};for(const e of s.listSemantics())t[e]=l.get(s.getAttribute(e));e.targets=e.targets||[],e.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),e}),t.getWeights().length&&(s.weights=t.getWeights()),r&&(s.extras=s.extras||{},s.extras.targetNames=r),p.set(t,e),s}),i.cameras=s.listCameras().map((t,e)=>{const s=Z(t);return s.type=t.getType(),"perspective"===s.type?s.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:s.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},f.set(t,e),s}),i.nodes=s.listNodes().map((t,e)=>{const s=Z(t);return s.translation=t.getTranslation(),s.rotation=t.getRotation(),s.scale=t.getScale(),t.getWeights().length&&(s.weights=t.getWeights()),m.set(t,e),s}),i.skins=s.listSkins().map((t,e)=>{const s=Z(t);return t.getInverseBindMatrices()&&(s.inverseBindMatrices=l.get(t.getInverseBindMatrices())),t.getSkeleton()&&(s.skeleton=m.get(t.getSkeleton())),s.joints=t.listJoints().map(t=>m.get(t)),d.set(t,e),s}),s.listNodes().forEach((t,e)=>{const s=i.nodes[e];t.getMesh()&&(s.mesh=p.get(t.getMesh())),t.getCamera()&&(s.camera=f.get(t.getCamera())),t.getSkin()&&(s.skin=d.get(t.getSkin())),t.listChildren().length>0&&(s.children=t.listChildren().map(t=>m.get(t)))}),i.animations=s.listAnimations().map(t=>{const e=Z(t),s=new Map;return e.samplers=t.listSamplers().map((t,e)=>{const r=Z(t);return r.input=l.get(t.getInput()),r.output=l.get(t.getOutput()),r.interpolation=t.getInterpolation(),s.set(t,e),r}),e.channels=t.listChannels().map(t=>{const e=Z(t);return e.sampler=s.get(t.getSampler()),e.target={node:m.get(t.getTargetNode()),path:t.getTargetPath()},e}),e}),i.scenes=s.listScenes().map(t=>{const e=Z(t);return e.nodes=t.listNodes().map(t=>m.get(t)),e}),function(t){const e=[];for(const s in t){const r=t[s];Array.isArray(r)&&0===r.length?e.push(s):null!==r&&""!==r||e.push(r)}for(const s of e)delete t[s]}(i),r}}function Z(t){const e={};return t.getName()&&(e.name=t.getName()),Object.keys(t.getExtras()).length>0&&(e.extras=t.getExtras()),Object.keys(t.getExtensions()).length>0&&(e.extras=t.getExtensions()),e}function X(t){const e=Z(t);return e.type=t.getType(),e.componentType=t.getComponentType(),e.count=t.getCount(),t.getMax(e.max=[]),t.getMin(e.min=[]),e.normalized=t.getNormalized(),e}class q{constructor(t,e){this.multiple=t,this.basename=e,this.counter=1}createURI(t,e){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${e}`:`${this.basename}.${e}`}}class H{createDocument(t){return $.read(t)}createNativeDocument(t,e){if(e.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return Y.write(t,e)}unpackGLB(t){const e=new Uint32Array(t,0,3);if(1179937895!==e[0])throw new Error("Invalid glTF asset.");if(2!==e[1])throw new Error(`Unsupported glTF binary version, "${e[1]}".`);const s=new Uint32Array(t,12,2),r=s[0],i=new Uint32Array(t,20+r,2);if(1313821514!==s[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=v.decodeText(t.slice(20,20+r)),h=JSON.parse(n),o=20+r+8,u=t.slice(o,o+i[0]);return this.createDocument({json:h,resources:{rt:u}})}packGLB(t){const{json:e,resources:s}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(e),i=v.pad(v.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=v.concat([n,i]),o=v.pad(Object.values(s)[0],0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=v.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return v.concat([a,h,c])}}class K extends H{constructor(t,e){super(),this.fs=t,this.path=e}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,e){t.match(/\.glb$/)?this.writeGLB(t,e):this.writeGLTF(t,e)}readGLB(t){const e=this.fs.readFileSync(t),s=v.trim(e);return this.unpackGLB(s)}readGLTF(t){const e=this.path.dirname(t),s={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...s.json.images||[],...s.json.buffers||[]].forEach(t=>{if(t.uri&&!t.uri.match(/data:/)){const r=this.path.resolve(e,t.uri);s.resources[t.uri]=v.trim(this.fs.readFileSync(r))}else{const e=`__${E()}.${w.extension(t.uri)}`;s.resources[e]=v.createBufferFromDataURI(t.uri),t.uri=e}}),$.read(s)}writeGLTF(t,e){const s={basename:w.basename(t),isGLB:!1},{json:r,resources:i}=Y.write(e,s),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const e=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),e)})}writeGLB(t,e){const s=Buffer.from(this.packGLB(e));this.fs.writeFileSync(t,s)}}class Q extends H{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const e={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{e.json=t;const s=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(s=>{e.resources[t.uri]=s})});return Promise.all(s).then(()=>this.createDocument(e))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}export{a as Accessor,f as Animation,d as AnimationChannel,g as AnimationSampler,p as Buffer,v as BufferUtils,m as Camera,D as Document,w as FileUtils,n as Graph,A as ImageUtils,x as Logger,U as Material,L as Mesh,_ as Node,K as NodeIO,O as Primitive,P as PrimitiveTarget,c as Property,F as Root,G as Scene,j as Skin,S as Texture,N as TextureInfo,C as TextureSampler,Q as WebIO,E as uuid}; | ||
//# sourceMappingURL=core.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("gl-matrix/mat4"),require("gl-matrix")):"function"==typeof define&&define.amd?define(["exports","gl-matrix/mat4","gl-matrix"],n):n((t=t||self).core={},t.mat4,t.glMatrix)}(this,function(t,n,r){function i(){return(i=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function u(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,n){return(o=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function f(t,n,r){return(f=s()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var u=new(Function.bind.apply(t,i));return r&&o(u,r.prototype),u}).apply(null,arguments)}function h(t){var n="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return f(t,arguments,e(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)})(t)}function c(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=t[r];return i}function a(t){var n=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,n){if(t){if("string"==typeof t)return c(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(t,void 0):void 0}}(t)))return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function v(t,n,r,i){var u,e=arguments.length,o=e<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,n,r,i);else for(var s=t.length-1;s>=0;s--)(u=t[s])&&(o=(e<3?u(o):e>3?u(n,r,o):u(n,r))||o);return e>3&&o&&Object.defineProperty(n,r,o),o}var l=function(){function t(t,n,r){if(this.t=t,this.i=n,this.u=r,this.o=!1,this.s=[],!n.canLink(r))throw new Error("Cannot link disconnected graphs/documents.")}var n=t.prototype;return n.getName=function(){return this.t},n.getParent=function(){return this.i},n.getChild=function(){return this.u},n.setChild=function(t){return this.u=t,this},n.dispose=function(){this.o||(this.o=!0,this.s.forEach(function(t){return t()}),this.s.length=0)},n.onDispose=function(t){return this.s.push(t),this},n.isDisposed=function(){return this.o},t}(),d=function(){function t(){this.h=[]}var n=t.prototype;return n.getLinks=function(){return this.h},n.listParents=function(t){return this.h.filter(function(n){return n.getChild()===t}).map(function(t){return t.getParent()})},n.listChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).map(function(t){return t.getChild()})},n.disconnectChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).forEach(function(t){return t.dispose()}),this},n.disconnectParents=function(t,n){var r=this.h.filter(function(n){return n.getChild()===t});return n&&(r=r.filter(function(t){return n(t.getParent())})),r.forEach(function(t){return t.dispose()}),this},n.link=function(t,n,r){if(!r)return null;var i=new l(t,n,r);return this.registerLink(i),i},n.registerLink=function(t){var n=this;return this.h.push(t),t.onDispose(function(){return n.unlink(t)}),t},n.unlink=function(t){return this.h=this.h.filter(function(n){return n!==t}),this},t}();function w(t,n){Object.defineProperty(t,n,{get:function(){return this["__"+n]},set:function(t){var r=this,i=this["__"+n];i&&!Array.isArray(i)&&i.dispose(),t&&!Array.isArray(t)&&t.onDispose(function(){r["__"+n]=null}),this["__"+n]=t},enumerable:!0})}function p(t,n){}var y=function(){function t(t){this.o=!1,this.v=t}var n=t.prototype;return n.canLink=function(t){return this.v===t.v},n.isDisposed=function(){return this.o},n.dispose=function(){this.v.disconnectChildren(this),this.v.disconnectParents(this),this.o=!0},n.detach=function(){return this.v.disconnectParents(this),this},n.swap=function(t,n){var r=this;return this.v.getLinks().filter(function(n){return n.getParent()===r&&n.getChild()===t}).forEach(function(t){return t.setChild(n)}),this},n.addGraphChild=function(t,n){return t.push(n),n.onDispose(function(){var r=t.filter(function(t){return t!==n});t.length=0,t.push.apply(t,r)}),this},n.removeGraphChild=function(t,n){return t.filter(function(t){return t.getChild()===n}).forEach(function(t){return t.dispose()}),this},n.listGraphParents=function(){return this.v.listParents(this)},t}(),A=function(t){function n(){return t.call(this,"@gltf-transform/core: Not implemented.")||this}return u(n,t),n}(h(Error)),b=function(t){function n(n,r){var i;return void 0===r&&(r=""),(i=t.call(this,n)||this).t="",i.l={},i.p={},i.t=r,i}u(n,t);var r=n.prototype;return r.getName=function(){return this.t},r.setName=function(t){return this.t=t,this},r.getExtras=function(){return this.l},r.setExtras=function(t){return this.l=t,this},r.getExtensions=function(){return this.p},r.setExtensions=function(t){return this.p=t,this},r.clone=function(){throw new A},r.detach=function(){return this.v.disconnectParents(this,function(t){return"Root"!==t.propertyType}),this},r.listParents=function(){return this.listGraphParents()},n}(y),m=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Accessor",n.A=null,n.m="SCALAR",n.g=null,n.T=!1,n.M=E,n.R=E,n.buffer=null,n}u(n,t),n.getElementSize=function(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)}},n.getComponentSize=function(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)}};var r=n.prototype;return r.getMinNormalized=function(t){var n=this.getElementSize();this.getMin(t);for(var r=0;r<n;r++)t[r]=this.R(t[r]);return t},r.getMin=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++)t[e]=Math.min(t[e],this.A[u+e]);return t},r.getMaxNormalized=function(t){var n=this.getElementSize();this.getMax(t);for(var r=0;r<n;r++)t[r]=this.R(t[r]);return t},r.getMax=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=-Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++)t[e]=Math.max(t[e],this.A[u+e]);return t},r.getCount=function(){return this.A.length/this.getElementSize()},r.getType=function(){return this.m},r.setType=function(t){return this.m=t,this},r.getElementSize=function(){return n.getElementSize(this.m)},r.getComponentSize=function(){return this.A.BYTES_PER_ELEMENT},r.getComponentType=function(){return this.g},r.getNormalized=function(){return this.T},r.setNormalized=function(t){var n=this;return this.T=t,t?(this.R=function(t){return function(t,n){switch(n){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)}}(t,n.g)},this.M=function(t){return function(t,n){switch(n){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)}}(t,n.g)}):(this.R=E,this.M=E),this},r.getScalar=function(t){var n=this.getElementSize();return this.R(this.A[t*n])},r.setScalar=function(t,n){return this.A[t*this.getElementSize()]=this.M(n),this},r.getElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)n[i]=this.R(this.A[t*r+i]);return n},r.setElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)this.A[t*r+i]=this.M(n[i]);return this},r.getBuffer=function(){return this.buffer.getChild()},r.setBuffer=function(t){return this.buffer=this.v.link("buffer",this,t),this},r.getArray=function(){return this.A},r.setArray=function(t){return this.g=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.A=t,this},r.getByteLength=function(){return this.A.byteLength},n}(b);function E(t){return t}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},v([w],m.prototype,"buffer",void 0);var g=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Animation",n.channels=[],n.samplers=[],n}u(n,t);var r=n.prototype;return r.addChannel=function(t){var n=this.v.link("channel",this,t);return this.addGraphChild(this.channels,n)},r.removeChannel=function(t){return this.removeGraphChild(this.channels,t)},r.listChannels=function(){return this.channels.map(function(t){return t.getChild()})},r.addSampler=function(t){var n=this.v.link("sampler",this,t);return this.addGraphChild(this.samplers,n)},r.removeSampler=function(t){return this.removeGraphChild(this.samplers,t)},r.listSamplers=function(){return this.samplers.map(function(t){return t.getChild()})},n}(b);v([p],g.prototype,"channels",void 0),v([p],g.prototype,"samplers",void 0);var T=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="AnimationChannel",n.S=null,n.targetNode=null,n.sampler=null,n}u(n,t);var r=n.prototype;return r.getTargetPath=function(){return this.S},r.setTargetPath=function(t){return this.S=t,this},r.getTargetNode=function(){return this.targetNode?this.targetNode.getChild():null},r.setTargetNode=function(t){return this.targetNode=this.v.link("target.node",this,t),this},r.getSampler=function(){return this.sampler?this.sampler.getChild():null},r.setSampler=function(t){return this.sampler=this.v.link("sampler",this,t),this},n}(b);v([w],T.prototype,"targetNode",void 0),v([w],T.prototype,"sampler",void 0);var M=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="AnimationChannel",n.O="LINEAR",n.input=null,n.output=null,n}u(n,t);var r=n.prototype;return r.getInterpolation=function(){return this.O},r.setInterpolation=function(t){return this.O=t,this},r.getInput=function(){return this.input?this.input.getChild():null},r.setInput=function(t){return this.input=this.v.link("input",this,t),this},r.getOutput=function(){return this.output?this.output.getChild():null},r.setOutput=function(t){return this.output=this.v.link("output",this,t),this},n}(b);v([w],M.prototype,"input",void 0),v([w],M.prototype,"output",void 0);var R=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Buffer",n}u(n,t);var r=n.prototype;return r.getURI=function(){return this.U},r.setURI=function(t){return this.U=t,this},n}(b),x=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Camera",n.m="perspective",n}u(n,t);var r=n.prototype;return r.getType=function(){return this.m},r.setType=function(t){return this.m=t,this},r.getZNear=function(){return this.I},r.setZNear=function(t){return this.I=t,this},r.getZFar=function(){return this.N},r.setZFar=function(t){return this.N=t,this},r.getAspectRatio=function(){return this.j},r.setAspectRatio=function(t){return this.j=t,this},r.getYFov=function(){return this._},r.setYFov=function(t){return this._=t,this},r.getXMag=function(){return this.C},r.setXMag=function(t){return this.C=t,this},r.getYMag=function(){return this.L},r.setYMag=function(t){return this.L=t,this},n}(b),S=function(){function t(){}return t.createBufferFromDataURI=function(t){if("undefined"==typeof Buffer){for(var n=atob(t.split(",")[1]),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}var u=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(u,e?"base64":"utf8"))},t.encodeText=function(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))},t.decodeText=function(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")},t.trim=function(t){var n=t.byteOffset;return t.buffer.slice(n,n+t.byteLength)},t.concat=function(t){for(var n,r=0,i=a(t);!(n=i()).done;)r+=n.value.byteLength;for(var u,e=new Uint8Array(r),o=0,s=a(t);!(u=s()).done;){var f=u.value;e.set(new Uint8Array(f),o),o+=f.byteLength}return e.buffer},t.pad=function(t,n){void 0===n&&(n=0);var r=this.padNumber(t.byteLength);if(r!==t.byteLength){var i=new Uint8Array(r);if(i.set(new Uint8Array(t)),0!==n)for(var u=t.byteLength;u<r;u++)i[u]=n;return i.buffer}return t},t.padNumber=function(t){return 4*Math.ceil(t/4)},t.equals=function(t,n){if(t===n)return!0;if(t.byteLength!==n.byteLength)return!1;for(var r=new DataView(t),i=new DataView(n),u=t.byteLength;u--;)if(r.getUint8(u)!==i.getUint8(u))return!1;return!0},t}(),O=function(){function t(){}return t.basename=function(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()},t.extension=function(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"},t}(),U=function(){function t(){}return t.getSizeJPEG=function(t){var n,r;for(t=t.slice(4);t.length;){if(n=t.readUInt16BE(0),I(t,n),192===(r=t[n+1])||193===r||194===r)return[t.readUInt16BE(n+7),t.readUInt16BE(n+5)];t=t.slice(n+2)}throw new TypeError("Invalid JPG, no size found")},t.getSizePNG=function(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]},t}();function I(t,n){if(n>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[n])throw new TypeError("Invalid JPG, marker table corrupted")}var N=function(){function t(t){this.verbosity=t}var n=t.prototype;return n.debug=function(n){this.verbosity<=t.Verbosity.DEBUG&&console.debug(n)},n.info=function(n){this.verbosity<=t.Verbosity.INFO&&console.info(n)},n.warn=function(n){this.verbosity<=t.Verbosity.WARN&&console.warn(n)},n.error=function(n){this.verbosity<=t.Verbosity.ERROR&&console.error(n)},t}();N.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};var j="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",_=new Set,C=function(){for(var t="",n=0;n<6;n++)t+=j.charAt(Math.floor(Math.random()*j.length));return t},L=function(){for(var t=0;t<999;t++){var n=C();if(!_.has(n))return n}return""},k=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Texture",n.image=null,n.mimeType="",n.uri="",n}u(n,t);var r=n.prototype;return r.getMimeType=function(){return this.mimeType},r.setMimeType=function(t){return this.mimeType=t,this},r.getURI=function(){return this.uri},r.setURI=function(t){return this.uri=t,this},r.getImage=function(){return this.image},r.setImage=function(t){return this.image=t,this},r.getSize=function(){return(this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/))?U.getSizePNG(Buffer.from(this.image)):U.getSizeJPEG(Buffer.from(this.image))},n}(b),B=function(){function t(){this.propertyType="TextureInfo",this.texCoord=0}var n=t.prototype;return n.getTexCoord=function(){return this.texCoord},n.setTexCoord=function(t){return this.texCoord=t,this},t}(),P=function(){function t(){this.propertyType="TextureSampler",this.k=null,this.B=null,this.P=10497,this.D=10497}var n=t.prototype;return n.getMagFilter=function(){return this.k},n.setMagFilter=function(t){return this.k=t,this},n.getMinFilter=function(){return this.B},n.setMinFilter=function(t){return this.B=t,this},n.getWrapS=function(){return this.P},n.setWrapS=function(t){return this.P=t,this},n.getWrapT=function(){return this.D},n.setWrapT=function(t){return this.D=t,this},t}();P.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},P.TextureMagFilter={NEAREST:9728,LINEAR:9729},P.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var D=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).textureInfo=new B,n.sampler=new P,n}return u(n,t),n}(l),V=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).semantic="",n}return u(n,t),n}(l),F=function(t){function n(){return t.apply(this,arguments)||this}return u(n,t),n}(l),G=function(t){function n(){return t.apply(this,arguments)||this}u(n,t);var r=n.prototype;return r.linkTexture=function(t,n,r){if(!r)return null;var i=new D(t,n,r);return this.registerLink(i),i},r.linkAttribute=function(t,n,r){if(!r)return null;var i=new V(t,n,r);return this.registerLink(i),i},r.linkIndex=function(t,n,r){if(!r)return null;var i=new F(t,n,r);return this.registerLink(i),i},n}(d),J=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Material",n.V="OPAQUE",n.F=.5,n.G=!1,n.J=[1,1,1,1],n.$=[0,0,0],n.q=1,n.Y=1,n.H=1,n.K=1,n.baseColorTexture=null,n.emissiveTexture=null,n.normalTexture=null,n.occlusionTexture=null,n.metallicRoughnessTexture=null,n}u(n,t);var r=n.prototype;return r.getDoubleSided=function(){return this.G},r.setDoubleSided=function(t){return this.G=t,this},r.getAlphaMode=function(){return this.V},r.setAlphaMode=function(t){return this.V=t,this},r.getAlphaCutoff=function(){return this.F},r.setAlphaCutoff=function(t){return this.F=t,this},r.getBaseColorFactor=function(){return this.J},r.setBaseColorFactor=function(t){return this.J=t,this},r.getBaseColorTexture=function(){return this.baseColorTexture?this.baseColorTexture.getChild():null},r.getBaseColorTextureInfo=function(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null},r.getBaseColorTextureSampler=function(){return this.baseColorTexture?this.baseColorTexture.sampler:null},r.setBaseColorTexture=function(t){return this.baseColorTexture=this.v.linkTexture("baseColorTexture",this,t),this},r.getEmissiveFactor=function(){return this.$},r.setEmissiveFactor=function(t){return this.$=t,this},r.getEmissiveTexture=function(){return this.emissiveTexture?this.emissiveTexture.getChild():null},r.getEmissiveTextureInfo=function(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null},r.getEmissiveTextureSampler=function(){return this.emissiveTexture?this.emissiveTexture.sampler:null},r.setEmissiveTexture=function(t){return this.emissiveTexture=this.v.linkTexture("emissiveTexture",this,t),this},r.getNormalScale=function(){return this.q},r.setNormalScale=function(t){return this.q=t,this},r.getNormalTexture=function(){return this.normalTexture?this.normalTexture.getChild():null},r.getNormalTextureInfo=function(){return this.normalTexture?this.normalTexture.textureInfo:null},r.getNormalTextureSampler=function(){return this.normalTexture?this.normalTexture.sampler:null},r.setNormalTexture=function(t){return this.normalTexture=this.v.linkTexture("normalTexture",this,t),this},r.getOcclusionStrength=function(){return this.Y},r.setOcclusionStrength=function(t){return this.Y=t,this},r.getOcclusionTexture=function(){return this.occlusionTexture?this.occlusionTexture.getChild():null},r.getOcclusionTextureInfo=function(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null},r.getOcclusionTextureSampler=function(){return this.occlusionTexture?this.occlusionTexture.sampler:null},r.setOcclusionTexture=function(t){return this.occlusionTexture=this.v.linkTexture("occlusionTexture",this,t),this},r.getRoughnessFactor=function(){return this.H},r.setRoughnessFactor=function(t){return this.H=t,this},r.getMetallicFactor=function(){return this.K},r.setMetallicFactor=function(t){return this.K=t,this},r.getMetallicRoughnessTexture=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null},r.getMetallicRoughnessTextureInfo=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null},r.getMetallicRoughnessTextureSampler=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null},r.setMetallicRoughnessTexture=function(t){return this.metallicRoughnessTexture=this.v.linkTexture("metallicRoughnessTexture",this,t),this},n}(b);v([w],J.prototype,"baseColorTexture",void 0),v([w],J.prototype,"emissiveTexture",void 0),v([w],J.prototype,"normalTexture",void 0),v([w],J.prototype,"occlusionTexture",void 0),v([w],J.prototype,"metallicRoughnessTexture",void 0);var z=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Mesh",n.W=[],n.primitives=[],n}u(n,t);var r=n.prototype;return r.addPrimitive=function(t){return this.addGraphChild(this.primitives,this.v.link("primitive",this,t))},r.removePrimitive=function(t){return this.removeGraphChild(this.primitives,t)},r.listPrimitives=function(){return this.primitives.map(function(t){return t.getChild()})},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(b);v([p],z.prototype,"primitives",void 0);var $=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Primitive",n.X=4,n.indices=null,n.attributes=[],n.targets=[],n.material=null,n}u(n,t);var r=n.prototype;return r.getIndices=function(){return this.indices?this.indices.getChild():null},r.setIndices=function(t){return this.indices=this.v.linkIndex("index",this,t),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.v.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},r.getMaterial=function(){return this.material?this.material.getChild():null},r.setMaterial=function(t){return this.material=this.v.link("material",this,t),this},r.getMode=function(){return this.X},r.setMode=function(t){return this.X=t,this},r.listTargets=function(){return this.targets.map(function(t){return t.getChild()})},r.addTarget=function(t){return this.addGraphChild(this.targets,this.v.link("target",this,t)),this},r.removeTarget=function(t){return this.removeGraphChild(this.targets,t)},n}(b);v([w],$.prototype,"indices",void 0),v([p],$.prototype,"attributes",void 0),v([p],$.prototype,"targets",void 0),v([w],$.prototype,"material",void 0);var q=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="PrimitiveTarget",n.attributes=[],n}u(n,t);var r=n.prototype;return r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.v.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},n}(b);v([p],q.prototype,"attributes",void 0);var Y=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Node",n.Z=[0,0,0],n.tt=[0,0,0,1],n.nt=[1,1,1],n.W=[],n.camera=null,n.mesh=null,n.skin=null,n.children=[],n}u(n,t);var r=n.prototype;return r.getTranslation=function(){return this.Z},r.getRotation=function(){return this.tt},r.getScale=function(){return this.nt},r.setTranslation=function(t){return this.Z=t,this},r.setRotation=function(t){return this.tt=t,this},r.setScale=function(t){return this.nt=t,this},r.addChild=function(t){var n=this.v.link("child",this,t);return this.addGraphChild(this.children,n)},r.removeChild=function(t){return this.removeGraphChild(this.children,t)},r.listChildren=function(){return this.children.map(function(t){return t.getChild()})},r.getMesh=function(){return this.mesh?this.mesh.getChild():null},r.setMesh=function(t){return this.mesh=this.v.link("mesh",this,t),this},r.getCamera=function(){return this.camera?this.camera.getChild():null},r.setCamera=function(t){return this.camera=this.v.link("camera",this,t),this},r.getSkin=function(){return this.skin?this.skin.getChild():null},r.setSkin=function(t){return this.skin=this.v.link("skin",this,t),this},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(b);v([w],Y.prototype,"camera",void 0),v([w],Y.prototype,"mesh",void 0),v([w],Y.prototype,"skin",void 0),v([p],Y.prototype,"children",void 0);var H=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Root",n.rt={generator:"glTF-Transform v0.3",version:"2.0"},n.scenes=[],n.nodes=[],n.cameras=[],n.skins=[],n.meshes=[],n.materials=[],n.textures=[],n.animations=[],n.accessors=[],n.buffers=[],n}u(n,t);var r=n.prototype;return r.getAsset=function(){return this.rt},r.addScene=function(t){return this.addGraphChild(this.scenes,this.v.link("scene",this,t))},r.removeScene=function(t){return this.removeGraphChild(this.scenes,t)},r.listScenes=function(){return this.scenes.map(function(t){return t.getChild()})},r.addNode=function(t){return this.addGraphChild(this.nodes,this.v.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},r.addCamera=function(t){return this.addGraphChild(this.cameras,this.v.link("camera",this,t))},r.removeCamera=function(t){return this.removeGraphChild(this.cameras,t)},r.listCameras=function(){return this.cameras.map(function(t){return t.getChild()})},r.addSkin=function(t){return this.addGraphChild(this.skins,this.v.link("skin",this,t))},r.removeSkin=function(t){return this.removeGraphChild(this.skins,t)},r.listSkins=function(){return this.skins.map(function(t){return t.getChild()})},r.addMesh=function(t){return this.addGraphChild(this.meshes,this.v.link("mesh",this,t))},r.removeMesh=function(t){return this.removeGraphChild(this.meshes,t)},r.listMeshes=function(){return this.meshes.map(function(t){return t.getChild()})},r.addMaterial=function(t){return this.addGraphChild(this.materials,this.v.link("material",this,t))},r.removeMaterial=function(t){return this.removeGraphChild(this.materials,t)},r.listMaterials=function(){return this.materials.map(function(t){return t.getChild()})},r.addTexture=function(t){return this.addGraphChild(this.textures,this.v.link("texture",this,t))},r.removeTexture=function(t){return this.removeGraphChild(this.textures,t)},r.listTextures=function(){return this.textures.map(function(t){return t.getChild()})},r.addAnimation=function(t){return this.addGraphChild(this.animations,this.v.link("animation",this,t))},r.removeAnimation=function(t){return this.removeGraphChild(this.animations,t)},r.listAnimations=function(){return this.animations.map(function(t){return t.getChild()})},r.addAccessor=function(t){return this.addGraphChild(this.accessors,this.v.link("accessor",this,t))},r.removeAccessor=function(t){return this.removeGraphChild(this.accessors,t)},r.listAccessors=function(){return this.accessors.map(function(t){return t.getChild()})},r.addBuffer=function(t){return this.addGraphChild(this.buffers,this.v.link("buffer",this,t))},r.removeBuffer=function(t){return this.removeGraphChild(this.buffers,t)},r.listBuffers=function(){return this.buffers.map(function(t){return t.getChild()})},n}(b);v([p],H.prototype,"scenes",void 0),v([p],H.prototype,"nodes",void 0),v([p],H.prototype,"cameras",void 0),v([p],H.prototype,"skins",void 0),v([p],H.prototype,"meshes",void 0),v([p],H.prototype,"materials",void 0),v([p],H.prototype,"textures",void 0),v([p],H.prototype,"animations",void 0),v([p],H.prototype,"accessors",void 0),v([p],H.prototype,"buffers",void 0);var K=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Scene",n.nodes=[],n}u(n,t);var r=n.prototype;return r.addNode=function(t){return this.addGraphChild(this.nodes,this.v.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},n}(b);v([p],K.prototype,"nodes",void 0);var Q=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Skin",n.skeleton=null,n.inverseBindMatrices=null,n.joints=[],n}u(n,t);var r=n.prototype;return r.getSkeleton=function(){return this.skeleton?this.skeleton.getChild():null},r.setSkeleton=function(t){return this.skeleton=this.v.link("skeleton",this,t),this},r.getInverseBindMatrices=function(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null},r.setInverseBindMatrices=function(t){return this.inverseBindMatrices=this.v.link("inverseBindMatrices",this,t),this},r.addJoint=function(t){var n=this.v.link("joint",this,t);return this.addGraphChild(this.joints,n)},r.removeJoint=function(t){return this.removeGraphChild(this.joints,t)},r.listJoints=function(){return this.joints.map(function(t){return t.getChild()})},n}(b);v([w],Q.prototype,"skeleton",void 0),v([w],Q.prototype,"inverseBindMatrices",void 0),v([p],Q.prototype,"joints",void 0);var W=function(){function t(){this.graph=new G,this.root=new H(this.graph),this.logger=new N(N.Verbosity.INFO)}var n=t.prototype;return n.getRoot=function(){return this.root},n.getGraph=function(){return this.graph},n.getLogger=function(){return this.logger},n.setLogger=function(t){return this.logger=t,this},n.clone=function(){throw new Error("Not implemented.")},n.transform=function(){for(var t,n=a([].slice.call(arguments));!(t=n()).done;){var r=t.value;r(this)}return this},n.createScene=function(t){var n=new K(this.graph,t);return this.root.addScene(n),n},n.createNode=function(t){var n=new Y(this.graph,t);return this.root.addNode(n),n},n.createCamera=function(t){var n=new x(this.graph,t);return this.root.addCamera(n),n},n.createSkin=function(t){var n=new Q(this.graph,t);return this.root.addSkin(n),n},n.createMesh=function(t){var n=new z(this.graph,t);return this.root.addMesh(n),n},n.createPrimitive=function(){return new $(this.graph)},n.createPrimitiveTarget=function(t){return new q(this.graph,t)},n.createMaterial=function(t){var n=new J(this.graph,t);return this.root.addMaterial(n),n},n.createTexture=function(t){var n=new k(this.graph,t);return this.root.addTexture(n),n},n.createAnimation=function(t){var n=new g(this.graph,t);return this.root.addAnimation(n),n},n.createAnimationChannel=function(){return new T(this.graph)},n.createAnimationSampler=function(){return new M(this.graph)},n.createAccessor=function(t,n){void 0===n&&(n=null),n||(n=this.getRoot().listBuffers()[0]);var r=new m(this.graph,t).setBuffer(n);return this.root.addAccessor(r),r},n.createBuffer=function(t){var n=new R(this.graph,t);return this.root.addBuffer(n),n},t}(),X={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Z=function(){function t(){}return t.read=function(t){var r=t.json,u=new W;if("2.0"!==r.asset.version)throw new Error('Unsupported glTF version: "'+r.asset.version+'".');var e=(r.buffers||[]).map(function(t){var n=u.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&n.setURI(t.uri),n}),o=(r.bufferViews||[]).map(function(t){return e[t.buffer]}),s=(r.accessors||[]).map(function(n){var r,e=u.createAccessor(n.name,o[n.bufferView]);return e.setType(n.type),r=void 0!==n.sparse?function(t,n){var r,u=X[t.componentType],e=m.getElementSize(t.type);r=void 0!==t.bufferView?rt(t,n).slice():new u(t.count*e);for(var o=t.sparse.count,s=i(i(i({},t),t.sparse.indices),{},{count:o,type:"SCALAR"}),f=i(i(i({},t),t.sparse.values),{},{count:o}),h=rt(s,n),c=rt(f,n),a=0;a<s.count;a++)for(var v=0;v<e;v++)r[h[a]*e+v]=c[a*e+v];return r}(n,t):rt(n,t).slice(),void 0!==n.normalized&&e.setNormalized(n.normalized),e.setArray(r),e}),f=r.textures||[],h=(r.images||[]).map(function(n){var i=u.createTexture(n.name);if(void 0!==n.bufferView){var e=r.bufferViews[n.bufferView],o=t.json.buffers[e.buffer],s=e.byteOffset||0,f=(o.uri?t.resources[o.uri]:t.resources["it"]).slice(s,s+e.byteLength);i.setImage(f)}else void 0!==n.uri&&(i.setImage(t.resources[n.uri]),0!==n.uri.indexOf("__")&&i.setURI(n.uri));if(void 0!==n.mimeType)i.setMimeType(n.mimeType);else if(n.uri){var h=O.extension(n.uri);i.setMimeType("png"===h?"image/png":"image/jpeg")}return i}),c=(r.materials||[]).map(function(n){var r=u.createMaterial(n.name);void 0!==n.alphaMode&&r.setAlphaMode(n.alphaMode),void 0!==n.alphaCutoff&&r.setAlphaCutoff(n.alphaCutoff),void 0!==n.doubleSided&&r.setDoubleSided(n.doubleSided);var i=n.pbrMetallicRoughness||{};if(void 0!==i.baseColorFactor&&r.setBaseColorFactor(i.baseColorFactor),void 0!==n.emissiveFactor&&r.setEmissiveFactor(n.emissiveFactor),void 0!==i.metallicFactor&&r.setMetallicFactor(i.metallicFactor),void 0!==i.roughnessFactor&&r.setRoughnessFactor(i.roughnessFactor),void 0!==i.baseColorTexture){var e=i.baseColorTexture;r.setBaseColorTexture(h[f[e.index].source]),tt(r.getBaseColorTextureInfo(),e),nt(r.getBaseColorTextureSampler(),e,t)}if(void 0!==n.emissiveTexture){var o=n.emissiveTexture;r.setEmissiveTexture(h[f[o.index].source]),tt(r.getEmissiveTextureInfo(),o),nt(r.getEmissiveTextureSampler(),o,t)}if(void 0!==n.normalTexture){var s=n.normalTexture;r.setNormalTexture(h[f[s.index].source]),tt(r.getNormalTextureInfo(),s),nt(r.getNormalTextureSampler(),s,t),void 0!==n.normalTexture.scale&&r.setNormalScale(n.normalTexture.scale)}if(void 0!==n.occlusionTexture){var c=n.occlusionTexture;r.setOcclusionTexture(h[f[c.index].source]),tt(r.getOcclusionTextureInfo(),c),nt(r.getOcclusionTextureSampler(),c,t),void 0!==n.occlusionTexture.strength&&r.setOcclusionStrength(n.occlusionTexture.strength)}if(void 0!==i.metallicRoughnessTexture){var a=i.metallicRoughnessTexture;r.setMetallicRoughnessTexture(h[f[a.index].source]),tt(r.getMetallicRoughnessTextureInfo(),a),nt(r.getMetallicRoughnessTextureSampler(),a,t)}return r}),v=(r.meshes||[]).map(function(t){var n=u.createMesh(t.name);return void 0!==t.weights&&n.setWeights(t.weights),t.primitives.forEach(function(r){var i=u.createPrimitive();void 0!==r.material&&i.setMaterial(c[r.material]),void 0!==r.mode&&i.setMode(r.mode);for(var e=0,o=Object.entries(r.attributes||{});e<o.length;e++){var f=o[e];i.setAttribute(f[0],s[f[1]])}void 0!==r.indices&&i.setIndices(s[r.indices]);var h=t.extras&&t.extras.targetNames||[];(r.targets||[]).forEach(function(t,n){for(var r=h[n]||n.toString(),e=u.createPrimitiveTarget(r),o=0,f=Object.entries(t);o<f.length;o++){var c=f[o];e.setAttribute(c[0],s[c[1]])}i.addTarget(e)}),n.addPrimitive(i)}),n}),l=(r.cameras||[]).map(function(t){var n=u.createCamera(t.name).setType(t.type);return"perspective"===t.type?n.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):n.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),n}),d=r.nodes||[],w=d.map(function(t){var r=u.createNode(t.name);return void 0!==t.translation&&r.setTranslation(t.translation),void 0!==t.rotation&&r.setRotation(t.rotation),void 0!==t.scale&&r.setScale(t.scale),void 0!==t.matrix&&(r.setTranslation(n.getTranslation([],t.matrix)),r.setRotation(n.getRotation([],t.matrix)),r.setScale(n.getScaling([],t.matrix))),void 0!==t.weights&&r.setWeights(t.weights),r}),p=(r.skins||[]).map(function(t){var n=u.createSkin(t.name);void 0!==t.inverseBindMatrices&&n.setInverseBindMatrices(s[t.inverseBindMatrices]),void 0!==t.skeleton&&n.setSkeleton(w[t.skeleton]);for(var r,i=a(t.joints);!(r=i()).done;)n.addJoint(w[r.value]);return n});return d.map(function(t,n){var r=w[n];(t.children||[]).forEach(function(t){return r.addChild(w[t])}),void 0!==t.mesh&&r.setMesh(v[t.mesh]),void 0!==t.camera&&r.setCamera(l[t.camera]),void 0!==t.skin&&r.setSkin(p[t.skin])}),(r.animations||[]).map(function(t){var n=u.createAnimation(t.name),r=(t.samplers||[]).map(function(t){var r=u.createAnimationSampler().setInput(s[t.input]).setOutput(s[t.output]).setInterpolation(t.interpolation||"LINEAR");return n.addSampler(r),r});return(t.channels||[]).forEach(function(t){var i=u.createAnimationChannel().setSampler(r[t.sampler]).setTargetNode(w[t.target.node]).setTargetPath(t.target.path);n.addChannel(i)}),n}),(r.scenes||[]).map(function(t){var n=u.createScene(t.name);return(t.nodes||[]).map(function(t){return w[t]}).forEach(function(t){return n.addNode(t)}),n}),u},t}();function tt(t,n){void 0!==n.texCoord&&t.setTexCoord(n.texCoord)}function nt(t,n,r){var i=r.json.textures[n.index];if(void 0!==i.sampler){var u=r.json.samplers[i.sampler];void 0!==u.magFilter&&t.setMagFilter(u.magFilter),void 0!==u.minFilter&&t.setMinFilter(u.minFilter),void 0!==u.wrapS&&t.setWrapS(u.wrapS),void 0!==u.wrapT&&t.setWrapT(u.wrapT)}}function rt(t,n){var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["it"],e=X[t.componentType],o=m.getElementSize(t.type);if(void 0!==r.byteStride&&r.byteStride!==o*e.BYTES_PER_ELEMENT)return function(t,n){for(var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["it"],e=X[t.componentType],o=m.getElementSize(t.type),s=e.BYTES_PER_ELEMENT,f=t.byteOffset||0,h=new e(t.count*o),c=new DataView(u,r.byteOffset,r.byteLength),a=r.byteStride,v=0;v<t.count;v++)for(var l=0;l<o;l++){var d=f+v*a+l*s,w=void 0;switch(t.componentType){case 5126:w=c.getFloat32(d,!0);break;case 5125:w=c.getUint32(d,!0);break;case 5123:w=c.getUint16(d,!0);break;case 5121:w=c.getUint8(d);break;case 5122:w=c.getInt16(d,!0);break;case 5120:w=c.getInt8(d);break;default:throw new Error('Unexpected componentType "'+t.componentType+'".')}h[v*o+l]=w}return h}(t,n);var s=(r.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(u,s,t.count*o);case 5125:return new Uint32Array(u,s,t.count*o);case 5123:return new Uint16Array(u,s,t.count*o);case 5121:return new Uint8Array(u,s,t.count*o);case 5122:return new Int16Array(u,s,t.count*o);case 5120:return new Int8Array(u,s,t.count*o);default:throw new Error('Unexpected componentType "'+t.componentType+'".')}}var it=function(){function t(){}return t.write=function(t,n){var r=t.getRoot(),i={json:{asset:r.getAsset()},resources:{}},u=i.json,e=t.getLogger(),o=r.listBuffers().length,s=r.listTextures().length,f=new ot(o>1,n.basename),h=new ot(s>1,n.basename),c=new Map,v=new Map,l=new Map,d=new Map,w=new Map,p=new Map,y=new Map,A=new Map,b=new Map,E=[];function g(t,n,r,i){for(var e,o=[],s=0,f=a(t);!(e=f()).done;){var h=e.value,v=et(h);v.bufferView=u.bufferViews.length;var l=S.pad(h.getArray().buffer);v.byteOffset=s,s+=l.byteLength,o.push(l),c.set(h,u.accessors.length),u.accessors.push(v)}var d={buffer:n,byteOffset:r,byteLength:S.concat(o).byteLength};return i&&(d.target=i),u.bufferViews.push(d),{buffers:o,byteLength:s}}function T(t,n,r){for(var i,e=t[0].getCount(),o=0,s=a(t);!(i=s()).done;){var f=i.value,h=et(f);h.bufferView=u.bufferViews.length,h.byteOffset=o;var v=f.getElementSize(),l=f.getComponentSize();o+=S.padNumber(v*l),c.set(f,u.accessors.length),u.accessors.push(h)}for(var d=e*o,w=new ArrayBuffer(d),p=new DataView(w),y=0;y<e;y++)for(var A,b=0,m=a(t);!(A=m()).done;){for(var E=A.value,g=E.getElementSize(),T=E.getComponentSize(),M=E.getComponentType(),R=E.getArray(),x=0;x<g;x++){var O=y*o+b+x*T,U=R[y*g+x];switch(M){case 5126:p.setFloat32(O,U,!0);break;case 5120:p.setInt8(O,U);break;case 5122:p.setInt16(O,U,!0);break;case 5121:p.setUint8(O,U);break;case 5123:p.setUint16(O,U,!0);break;case 5125:p.setUint32(O,U,!0);break;default:throw new Error("Unexpected component type: "+M)}}b+=S.padNumber(g*T)}return u.bufferViews.push({buffer:n,byteOffset:r,byteLength:d,byteStride:o,target:34962}),{byteLength:d,buffers:[w]}}function M(t,n,r){var i={magFilter:r.getMagFilter()||void 0,minFilter:r.getMinFilter()||void 0,wrapS:r.getWrapS(),wrapT:r.getWrapT()},e=JSON.stringify(i);b.has(e)||(b.set(e,u.samplers.length),u.samplers.push(i));var o={source:y.get(t),sampler:b.get(e)},s=JSON.stringify(o);return A.has(s)||(A.set(s,u.textures.length),u.textures.push(o)),{index:A.get(s),texCoord:n.getTexCoord()}}for(var R,x=new Map,O=a(t.getGraph().getLinks());!(R=O()).done;){var U=R.value;if(U.getParent()!==r){var I=U.getChild();if(I instanceof m){var N=x.get(I)||[];N.push(U),x.set(I,N)}}}return u.accessors=[],u.bufferViews=[],u.samplers=[],u.textures=[],u.images=r.listTextures().map(function(t,r){var e=ut(t);if(t.getMimeType()&&(e.mimeType=t.getMimeType()),n.isGLB)E.push(t.getImage()),e.bufferView=u.bufferViews.length,u.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.getImage().byteLength});else{var o="image/png"===t.getMimeType()?"png":"jpeg";e.uri=h.createURI(t,o),i.resources[e.uri]=t.getImage()}return y.set(t,r),e}),u.buffers=[],r.listBuffers().forEach(function(t){for(var r,o=ut(t),s=new Map,h=new Set,c=new Set,v=a(t.listParents().filter(function(t){return!(t instanceof H)}));!(r=v()).done;){var l=r.value;if(!(l instanceof m))throw new Error("Unimplemented buffer reference: "+l);for(var d,w=!1,p=!1,y=!1,A=x.get(l)||[],b=a(A);!(d=b()).done;){var M=d.value;M instanceof V?w=!0:M instanceof F?p=!0:y=!0}if(w||p||y||(y=!0),!w||p||y)if(!p||w||y){if(!y||w||p)throw new Error("Attribute or index accessors must be used only for that purpose.");c.add(l)}else h.add(l);else{var R=A[0].getParent(),O=s.get(R)||new Set;O.add(l),s.set(R,O)}}var U,I=[],N=u.buffers.length,j=0;if(h.size){var _=g(Array.from(h),N,j,34963);j+=_.byteLength,I.push.apply(I,_.buffers)}for(var C=0,L=Array.from(s.values());C<L.length;C++){var k=L[C];if(k.size){var B=T(Array.from(k),N,j);j+=B.byteLength,I.push.apply(I,B.buffers)}}if(c.size){var P=g(Array.from(c),N,j);j+=P.byteLength,I.push.apply(I,P.buffers)}if(E.length)for(var D=0;D<E.length;D++)u.bufferViews[u.images[D].bufferView].byteOffset=j,j+=E[D].byteLength,I.push(E[D]);j?(n.isGLB?U="__glb.bin":(U=f.createURI(t,"bin"),o.uri=U),o.byteLength=j,i.resources[U]=S.concat(I),u.buffers.push(o)):e.warn('@gltf-transform/core: Skipping empty buffer, "'+t.getName()+'".')}),u.materials=r.listMaterials().map(function(t,n){var r=ut(t);if(r.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(r.alphaCutoff=t.getAlphaCutoff()),r.doubleSided=t.getDoubleSided(),r.pbrMetallicRoughness={},r.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),r.emissiveFactor=t.getEmissiveFactor(),r.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),r.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){var i=t.getBaseColorTexture(),u=t.getBaseColorTextureInfo(),e=t.getBaseColorTextureSampler();r.pbrMetallicRoughness.baseColorTexture=M(i,u,e)}if(t.getEmissiveTexture()){var o=t.getEmissiveTexture(),s=t.getEmissiveTextureInfo(),f=t.getEmissiveTextureSampler();r.emissiveTexture=M(o,s,f)}if(t.getNormalTexture()){var h=M(t.getNormalTexture(),t.getNormalTextureInfo(),t.getNormalTextureSampler());1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),r.normalTexture=h}if(t.getOcclusionTexture()){var c=M(t.getOcclusionTexture(),t.getOcclusionTextureInfo(),t.getOcclusionTextureSampler());1!==t.getOcclusionStrength()&&(c.strength=t.getOcclusionStrength()),r.occlusionTexture=c}if(t.getMetallicRoughnessTexture()){var a=t.getMetallicRoughnessTexture(),v=t.getMetallicRoughnessTextureInfo(),l=t.getMetallicRoughnessTextureSampler();r.pbrMetallicRoughness.metallicRoughnessTexture=M(a,v,l)}return d.set(t,n),r}),u.meshes=r.listMeshes().map(function(t,n){var r,i=ut(t);return i.primitives=t.listPrimitives().map(function(t){var n={attributes:{}};n.material=d.get(t.getMaterial()),n.mode=t.getMode(),t.getIndices()&&(n.indices=c.get(t.getIndices()));for(var i,u=a(t.listSemantics());!(i=u()).done;){var e=i.value;n.attributes[e]=c.get(t.getAttribute(e))}for(var o,s=a(t.listTargets());!(o=s()).done;){for(var f,h=o.value,v={},l=a(h.listSemantics());!(f=l()).done;){var w=f.value;v[w]=c.get(h.getAttribute(w))}n.targets=n.targets||[],n.targets.push(v)}return t.listTargets().length&&!r&&(r=t.listTargets().map(function(t){return t.getName()})),n}),t.getWeights().length&&(i.weights=t.getWeights()),r&&(i.extras=i.extras||{},i.extras.targetNames=r),w.set(t,n),i}),u.cameras=r.listCameras().map(function(t,n){var r=ut(t);return r.type=t.getType(),"perspective"===r.type?r.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:r.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},v.set(t,n),r}),u.nodes=r.listNodes().map(function(t,n){var r=ut(t);return r.translation=t.getTranslation(),r.rotation=t.getRotation(),r.scale=t.getScale(),t.getWeights().length&&(r.weights=t.getWeights()),p.set(t,n),r}),u.skins=r.listSkins().map(function(t,n){var r=ut(t);return t.getInverseBindMatrices()&&(r.inverseBindMatrices=c.get(t.getInverseBindMatrices())),t.getSkeleton()&&(r.skeleton=p.get(t.getSkeleton())),r.joints=t.listJoints().map(function(t){return p.get(t)}),l.set(t,n),r}),r.listNodes().forEach(function(t,n){var r=u.nodes[n];t.getMesh()&&(r.mesh=w.get(t.getMesh())),t.getCamera()&&(r.camera=v.get(t.getCamera())),t.getSkin()&&(r.skin=l.get(t.getSkin())),t.listChildren().length>0&&(r.children=t.listChildren().map(function(t){return p.get(t)}))}),u.animations=r.listAnimations().map(function(t){var n=ut(t),r=new Map;return n.samplers=t.listSamplers().map(function(t,n){var i=ut(t);return i.input=c.get(t.getInput()),i.output=c.get(t.getOutput()),i.interpolation=t.getInterpolation(),r.set(t,n),i}),n.channels=t.listChannels().map(function(t){var n=ut(t);return n.sampler=r.get(t.getSampler()),n.target={node:p.get(t.getTargetNode()),path:t.getTargetPath()},n}),n}),u.scenes=r.listScenes().map(function(t){var n=ut(t);return n.nodes=t.listNodes().map(function(t){return p.get(t)}),n}),function(t){var n=[];for(var r in t){var i=t[r];Array.isArray(i)&&0===i.length?n.push(r):null!==i&&""!==i||n.push(i)}for(var u=0,e=n;u<e.length;u++)delete t[e[u]]}(u),i},t}();function ut(t){var n={};return t.getName()&&(n.name=t.getName()),Object.keys(t.getExtras()).length>0&&(n.extras=t.getExtras()),Object.keys(t.getExtensions()).length>0&&(n.extras=t.getExtensions()),n}function et(t){var n=ut(t);return n.type=t.getType(),n.componentType=t.getComponentType(),n.count=t.getCount(),t.getMax(n.max=[]),t.getMin(n.min=[]),n.normalized=t.getNormalized(),n}var ot=function(){function t(t,n){this.multiple=t,this.basename=n,this.counter=1}return t.prototype.createURI=function(t,n){return t.getURI()?t.getURI():this.multiple?this.basename+"_"+this.counter+++"."+n:this.basename+"."+n},t}(),st=function(){function t(){}var n=t.prototype;return n.createDocument=function(t){return Z.read(t)},n.createNativeDocument=function(t,n){if(n.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return it.write(t,n)},n.unpackGLB=function(t){var n,r=new Uint32Array(t,0,3);if(1179937895!==r[0])throw new Error("Invalid glTF asset.");if(2!==r[1])throw new Error('Unsupported glTF binary version, "'+r[1]+'".');var i=new Uint32Array(t,12,2),u=i[0],e=new Uint32Array(t,20+u,2);if(1313821514!==i[1]||5130562!==e[1])throw new Error("Unexpected GLB layout.");var o=S.decodeText(t.slice(20,20+u)),s=JSON.parse(o),f=20+u+8,h=t.slice(f,f+e[0]);return this.createDocument({json:s,resources:(n={},n["it"]=h,n)})},n.packGLB=function(t){var n=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=n.resources,i=JSON.stringify(n.json),u=S.pad(S.encodeText(i),32),e=new Uint32Array([u.byteLength,1313821514]).buffer,o=S.concat([e,u]),s=S.pad(Object.values(r)[0],0),f=new Uint32Array([s.byteLength,5130562]).buffer,h=S.concat([f,s]),c=new Uint32Array([1179937895,2,12+o.byteLength+h.byteLength]).buffer;return S.concat([c,o,h])},t}(),ft=function(t){function n(n,r){var i;return(i=t.call(this)||this).fs=n,i.path=r,i}u(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.write=function(t,n){t.match(/\.glb$/)?this.writeGLB(t,n):this.writeGLTF(t,n)},r.readGLB=function(t){var n=this.fs.readFileSync(t),r=S.trim(n);return this.unpackGLB(r)},r.readGLTF=function(t){var n=this,r=this.path.dirname(t),i={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[].concat(i.json.images||[],i.json.buffers||[]).forEach(function(t){if(t.uri&&!t.uri.match(/data:/)){var u=n.path.resolve(r,t.uri);i.resources[t.uri]=S.trim(n.fs.readFileSync(u))}else{var e="__"+L()+"."+O.extension(t.uri);i.resources[e]=S.createBufferFromDataURI(t.uri),t.uri=e}}),Z.read(i)},r.writeGLTF=function(t,n){var r={basename:O.basename(t),isGLB:!1},i=it.write(n,r),u=i.json,e=i.resources,o=this.fs,s=this.path,f=s.dirname(t);o.writeFileSync(t,JSON.stringify(u,null,2)),Object.keys(e).forEach(function(t){var n=Buffer.from(e[t]);o.writeFileSync(s.join(f,t),n)})},r.writeGLB=function(t,n){var r=Buffer.from(this.packGLB(n));this.fs.writeFileSync(t,r)},n}(st),ht=function(t){function n(n){var r;return(r=t.call(this)||this).fetchConfig=n,r}u(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.readGLTF=function(t){var n=this,r={json:{},resources:{}};return fetch(t,this.fetchConfig).then(function(t){return t.json()}).then(function(t){r.json=t;var i=[].concat(t.images,t.buffers).map(function(t){if(t.uri)return fetch(t.uri,n.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(n){r.resources[t.uri]=n})});return Promise.all(i).then(function(){return n.createDocument(r)})})},r.readGLB=function(t){var n=this;return fetch(t,this.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(t){return n.unpackGLB(t)})},n}(st);r.glMatrix.setMatrixArrayType(Array),t.Accessor=m,t.Animation=g,t.AnimationChannel=T,t.AnimationSampler=M,t.Buffer=R,t.BufferUtils=S,t.Camera=x,t.Document=W,t.FileUtils=O,t.Graph=d,t.ImageUtils=U,t.Logger=N,t.Material=J,t.Mesh=z,t.Node=Y,t.NodeIO=ft,t.Primitive=$,t.PrimitiveTarget=q,t.Property=b,t.Root=H,t.Scene=K,t.Skin=Q,t.Texture=k,t.TextureInfo=B,t.TextureSampler=P,t.WebIO=ht,t.uuid=L}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("gl-matrix/mat4")):"function"==typeof define&&define.amd?define(["exports","gl-matrix/mat4"],n):n((t=t||self).core={},t.mat4)}(this,function(t,n){function r(){return(r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function i(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function e(t,n){return(e=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function s(t,n,r){return(s=o()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var u=new(Function.bind.apply(t,i));return r&&e(u,r.prototype),u}).apply(null,arguments)}function f(t){var n="function"==typeof Map?new Map:void 0;return(f=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return s(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),e(r,t)})(t)}function h(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=t[r];return i}function c(t){var n=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,n){if(t){if("string"==typeof t)return h(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(t,void 0):void 0}}(t)))return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function a(t,n,r,i){var u,e=arguments.length,o=e<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,n,r,i);else for(var s=t.length-1;s>=0;s--)(u=t[s])&&(o=(e<3?u(o):e>3?u(n,r,o):u(n,r))||o);return e>3&&o&&Object.defineProperty(n,r,o),o}var v=function(){function t(t,n,r){if(this.t=t,this.i=n,this.u=r,this.o=!1,this.s=[],!n.canLink(r))throw new Error("Cannot link disconnected graphs/documents.")}var n=t.prototype;return n.getName=function(){return this.t},n.getParent=function(){return this.i},n.getChild=function(){return this.u},n.setChild=function(t){return this.u=t,this},n.dispose=function(){this.o||(this.o=!0,this.s.forEach(function(t){return t()}),this.s.length=0)},n.onDispose=function(t){return this.s.push(t),this},n.isDisposed=function(){return this.o},t}(),l=function(){function t(){this.h=[]}var n=t.prototype;return n.getLinks=function(){return this.h},n.listParents=function(t){return this.h.filter(function(n){return n.getChild()===t}).map(function(t){return t.getParent()})},n.listChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).map(function(t){return t.getChild()})},n.disconnectChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).forEach(function(t){return t.dispose()}),this},n.disconnectParents=function(t,n){var r=this.h.filter(function(n){return n.getChild()===t});return n&&(r=r.filter(function(t){return n(t.getParent())})),r.forEach(function(t){return t.dispose()}),this},n.link=function(t,n,r){if(!r)return null;var i=new v(t,n,r);return this.registerLink(i),i},n.registerLink=function(t){var n=this;return this.h.push(t),t.onDispose(function(){return n.unlink(t)}),t},n.unlink=function(t){return this.h=this.h.filter(function(n){return n!==t}),this},t}();function d(t,n){Object.defineProperty(t,n,{get:function(){return this["__"+n]},set:function(t){var r=this,i=this["__"+n];i&&!Array.isArray(i)&&i.dispose(),t&&!Array.isArray(t)&&t.onDispose(function(){r["__"+n]=null}),this["__"+n]=t},enumerable:!0})}function w(t,n){}var p=function(){function t(t){this.o=!1,this.v=t}var n=t.prototype;return n.canLink=function(t){return this.v===t.v},n.isDisposed=function(){return this.o},n.dispose=function(){this.v.disconnectChildren(this),this.v.disconnectParents(this),this.o=!0},n.detach=function(){return this.v.disconnectParents(this),this},n.swap=function(t,n){var r=this;return this.v.getLinks().filter(function(n){return n.getParent()===r&&n.getChild()===t}).forEach(function(t){return t.setChild(n)}),this},n.addGraphChild=function(t,n){return t.push(n),n.onDispose(function(){var r=t.filter(function(t){return t!==n});t.length=0,t.push.apply(t,r)}),this},n.removeGraphChild=function(t,n){return t.filter(function(t){return t.getChild()===n}).forEach(function(t){return t.dispose()}),this},n.listGraphParents=function(){return this.v.listParents(this)},t}(),y=function(t){function n(){return t.call(this,"@gltf-transform/core: Not implemented.")||this}return i(n,t),n}(f(Error)),b=function(t){function n(n,r){var i;return void 0===r&&(r=""),(i=t.call(this,n)||this).t="",i.l={},i.p={},i.t=r,i}i(n,t);var r=n.prototype;return r.getName=function(){return this.t},r.setName=function(t){return this.t=t,this},r.getExtras=function(){return this.l},r.setExtras=function(t){return this.l=t,this},r.getExtensions=function(){return this.p},r.setExtensions=function(t){return this.p=t,this},r.clone=function(){throw new y},r.detach=function(){return this.v.disconnectParents(this,function(t){return"Root"!==t.propertyType}),this},r.listParents=function(){return this.listGraphParents()},n}(p),A=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Accessor",n.A=null,n.m="SCALAR",n.g=null,n.T=!1,n.M=m,n.R=m,n.buffer=null,n}i(n,t),n.getElementSize=function(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)}},n.getComponentSize=function(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)}};var r=n.prototype;return r.getMinNormalized=function(t){var n=this.getElementSize();this.getMin(t);for(var r=0;r<n;r++)t[r]=this.R(t[r]);return t},r.getMin=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var o=this.A[u+e];Number.isFinite(o)&&(t[e]=Math.min(t[e],o))}return t},r.getMaxNormalized=function(t){var n=this.getElementSize();this.getMax(t);for(var r=0;r<n;r++)t[r]=this.R(t[r]);return t},r.getMax=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=-Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var o=this.A[u+e];Number.isFinite(o)&&(t[e]=Math.max(t[e],o))}return t},r.getCount=function(){return this.A.length/this.getElementSize()},r.getType=function(){return this.m},r.setType=function(t){return this.m=t,this},r.getElementSize=function(){return n.getElementSize(this.m)},r.getComponentSize=function(){return this.A.BYTES_PER_ELEMENT},r.getComponentType=function(){return this.g},r.getNormalized=function(){return this.T},r.setNormalized=function(t){var n=this;return this.T=t,t?(this.R=function(t){return function(t,n){switch(n){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)}}(t,n.g)},this.M=function(t){return function(t,n){switch(n){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)}}(t,n.g)}):(this.R=m,this.M=m),this},r.getScalar=function(t){var n=this.getElementSize();return this.R(this.A[t*n])},r.setScalar=function(t,n){return this.A[t*this.getElementSize()]=this.M(n),this},r.getElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)n[i]=this.R(this.A[t*r+i]);return n},r.setElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)this.A[t*r+i]=this.M(n[i]);return this},r.getBuffer=function(){return this.buffer.getChild()},r.setBuffer=function(t){return this.buffer=this.v.link("buffer",this,t),this},r.getArray=function(){return this.A},r.setArray=function(t){return this.g=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.A=t,this},r.getByteLength=function(){return this.A.byteLength},n}(b);function m(t){return t}A.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},A.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},a([d],A.prototype,"buffer",void 0);var E=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Animation",n.channels=[],n.samplers=[],n}i(n,t);var r=n.prototype;return r.addChannel=function(t){var n=this.v.link("channel",this,t);return this.addGraphChild(this.channels,n)},r.removeChannel=function(t){return this.removeGraphChild(this.channels,t)},r.listChannels=function(){return this.channels.map(function(t){return t.getChild()})},r.addSampler=function(t){var n=this.v.link("sampler",this,t);return this.addGraphChild(this.samplers,n)},r.removeSampler=function(t){return this.removeGraphChild(this.samplers,t)},r.listSamplers=function(){return this.samplers.map(function(t){return t.getChild()})},n}(b);a([w],E.prototype,"channels",void 0),a([w],E.prototype,"samplers",void 0);var g=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="AnimationChannel",n.S=null,n.targetNode=null,n.sampler=null,n}i(n,t);var r=n.prototype;return r.getTargetPath=function(){return this.S},r.setTargetPath=function(t){return this.S=t,this},r.getTargetNode=function(){return this.targetNode?this.targetNode.getChild():null},r.setTargetNode=function(t){return this.targetNode=this.v.link("target.node",this,t),this},r.getSampler=function(){return this.sampler?this.sampler.getChild():null},r.setSampler=function(t){return this.sampler=this.v.link("sampler",this,t),this},n}(b);a([d],g.prototype,"targetNode",void 0),a([d],g.prototype,"sampler",void 0);var T=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="AnimationChannel",n.N="LINEAR",n.input=null,n.output=null,n}i(n,t);var r=n.prototype;return r.getInterpolation=function(){return this.N},r.setInterpolation=function(t){return this.N=t,this},r.getInput=function(){return this.input?this.input.getChild():null},r.setInput=function(t){return this.input=this.v.link("input",this,t),this},r.getOutput=function(){return this.output?this.output.getChild():null},r.setOutput=function(t){return this.output=this.v.link("output",this,t),this},n}(b);a([d],T.prototype,"input",void 0),a([d],T.prototype,"output",void 0);var M=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Buffer",n}i(n,t);var r=n.prototype;return r.getURI=function(){return this.O},r.setURI=function(t){return this.O=t,this},n}(b),R=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Camera",n.m="perspective",n}i(n,t);var r=n.prototype;return r.getType=function(){return this.m},r.setType=function(t){return this.m=t,this},r.getZNear=function(){return this.U},r.setZNear=function(t){return this.U=t,this},r.getZFar=function(){return this.I},r.setZFar=function(t){return this.I=t,this},r.getAspectRatio=function(){return this.j},r.setAspectRatio=function(t){return this.j=t,this},r.getYFov=function(){return this._},r.setYFov=function(t){return this._=t,this},r.getXMag=function(){return this.C},r.setXMag=function(t){return this.C=t,this},r.getYMag=function(){return this.L},r.setYMag=function(t){return this.L=t,this},n}(b),x=function(){function t(){}return t.createBufferFromDataURI=function(t){if("undefined"==typeof Buffer){for(var n=atob(t.split(",")[1]),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}var u=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(u,e?"base64":"utf8"))},t.encodeText=function(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))},t.decodeText=function(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")},t.trim=function(t){var n=t.byteOffset;return t.buffer.slice(n,n+t.byteLength)},t.concat=function(t){for(var n,r=0,i=c(t);!(n=i()).done;)r+=n.value.byteLength;for(var u,e=new Uint8Array(r),o=0,s=c(t);!(u=s()).done;){var f=u.value;e.set(new Uint8Array(f),o),o+=f.byteLength}return e.buffer},t.pad=function(t,n){void 0===n&&(n=0);var r=this.padNumber(t.byteLength);if(r!==t.byteLength){var i=new Uint8Array(r);if(i.set(new Uint8Array(t)),0!==n)for(var u=t.byteLength;u<r;u++)i[u]=n;return i.buffer}return t},t.padNumber=function(t){return 4*Math.ceil(t/4)},t.equals=function(t,n){if(t===n)return!0;if(t.byteLength!==n.byteLength)return!1;for(var r=new DataView(t),i=new DataView(n),u=t.byteLength;u--;)if(r.getUint8(u)!==i.getUint8(u))return!1;return!0},t}(),S=function(){function t(){}return t.basename=function(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()},t.extension=function(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"},t}(),N=function(){function t(){}return t.getSizeJPEG=function(t){var n,r;for(t=t.slice(4);t.length;){if(n=t.readUInt16BE(0),O(t,n),192===(r=t[n+1])||193===r||194===r)return[t.readUInt16BE(n+7),t.readUInt16BE(n+5)];t=t.slice(n+2)}throw new TypeError("Invalid JPG, no size found")},t.getSizePNG=function(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]},t}();function O(t,n){if(n>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[n])throw new TypeError("Invalid JPG, marker table corrupted")}var U=function(){function t(t){this.verbosity=t}var n=t.prototype;return n.debug=function(n){this.verbosity<=t.Verbosity.DEBUG&&console.debug(n)},n.info=function(n){this.verbosity<=t.Verbosity.INFO&&console.info(n)},n.warn=function(n){this.verbosity<=t.Verbosity.WARN&&console.warn(n)},n.error=function(n){this.verbosity<=t.Verbosity.ERROR&&console.error(n)},t}();U.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};var I="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",j=new Set,_=function(){for(var t="",n=0;n<6;n++)t+=I.charAt(Math.floor(Math.random()*I.length));return t},C=function(){for(var t=0;t<999;t++){var n=_();if(!j.has(n))return n}return""},L=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Texture",n.image=null,n.mimeType="",n.uri="",n}i(n,t);var r=n.prototype;return r.getMimeType=function(){return this.mimeType},r.setMimeType=function(t){return this.mimeType=t,this},r.getURI=function(){return this.uri},r.setURI=function(t){return this.uri=t,this},r.getImage=function(){return this.image},r.setImage=function(t){return this.image=t,this},r.getSize=function(){return(this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/))?N.getSizePNG(Buffer.from(this.image)):N.getSizeJPEG(Buffer.from(this.image))},n}(b),k=function(){function t(){this.propertyType="TextureInfo",this.texCoord=0}var n=t.prototype;return n.getTexCoord=function(){return this.texCoord},n.setTexCoord=function(t){return this.texCoord=t,this},t}(),B=function(){function t(){this.propertyType="TextureSampler",this.k=null,this.B=null,this.P=10497,this.D=10497}var n=t.prototype;return n.getMagFilter=function(){return this.k},n.setMagFilter=function(t){return this.k=t,this},n.getMinFilter=function(){return this.B},n.setMinFilter=function(t){return this.B=t,this},n.getWrapS=function(){return this.P},n.setWrapS=function(t){return this.P=t,this},n.getWrapT=function(){return this.D},n.setWrapT=function(t){return this.D=t,this},t}();B.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},B.TextureMagFilter={NEAREST:9728,LINEAR:9729},B.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var P=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).textureInfo=new k,n.sampler=new B,n}return i(n,t),n}(v),D=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).semantic="",n}return i(n,t),n}(v),V=function(t){function n(){return t.apply(this,arguments)||this}return i(n,t),n}(v),F=function(t){function n(){return t.apply(this,arguments)||this}i(n,t);var r=n.prototype;return r.linkTexture=function(t,n,r){if(!r)return null;var i=new P(t,n,r);return this.registerLink(i),i},r.linkAttribute=function(t,n,r){if(!r)return null;var i=new D(t,n,r);return this.registerLink(i),i},r.linkIndex=function(t,n,r){if(!r)return null;var i=new V(t,n,r);return this.registerLink(i),i},n}(l),G=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Material",n.V="OPAQUE",n.F=.5,n.G=!1,n.J=[1,1,1,1],n.$=[0,0,0],n.Y=1,n.q=1,n.H=1,n.K=1,n.baseColorTexture=null,n.emissiveTexture=null,n.normalTexture=null,n.occlusionTexture=null,n.metallicRoughnessTexture=null,n}i(n,t);var r=n.prototype;return r.getDoubleSided=function(){return this.G},r.setDoubleSided=function(t){return this.G=t,this},r.getAlphaMode=function(){return this.V},r.setAlphaMode=function(t){return this.V=t,this},r.getAlphaCutoff=function(){return this.F},r.setAlphaCutoff=function(t){return this.F=t,this},r.getBaseColorFactor=function(){return this.J},r.setBaseColorFactor=function(t){return this.J=t,this},r.getBaseColorTexture=function(){return this.baseColorTexture?this.baseColorTexture.getChild():null},r.getBaseColorTextureInfo=function(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null},r.getBaseColorTextureSampler=function(){return this.baseColorTexture?this.baseColorTexture.sampler:null},r.setBaseColorTexture=function(t){return this.baseColorTexture=this.v.linkTexture("baseColorTexture",this,t),this},r.getEmissiveFactor=function(){return this.$},r.setEmissiveFactor=function(t){return this.$=t,this},r.getEmissiveTexture=function(){return this.emissiveTexture?this.emissiveTexture.getChild():null},r.getEmissiveTextureInfo=function(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null},r.getEmissiveTextureSampler=function(){return this.emissiveTexture?this.emissiveTexture.sampler:null},r.setEmissiveTexture=function(t){return this.emissiveTexture=this.v.linkTexture("emissiveTexture",this,t),this},r.getNormalScale=function(){return this.Y},r.setNormalScale=function(t){return this.Y=t,this},r.getNormalTexture=function(){return this.normalTexture?this.normalTexture.getChild():null},r.getNormalTextureInfo=function(){return this.normalTexture?this.normalTexture.textureInfo:null},r.getNormalTextureSampler=function(){return this.normalTexture?this.normalTexture.sampler:null},r.setNormalTexture=function(t){return this.normalTexture=this.v.linkTexture("normalTexture",this,t),this},r.getOcclusionStrength=function(){return this.q},r.setOcclusionStrength=function(t){return this.q=t,this},r.getOcclusionTexture=function(){return this.occlusionTexture?this.occlusionTexture.getChild():null},r.getOcclusionTextureInfo=function(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null},r.getOcclusionTextureSampler=function(){return this.occlusionTexture?this.occlusionTexture.sampler:null},r.setOcclusionTexture=function(t){return this.occlusionTexture=this.v.linkTexture("occlusionTexture",this,t),this},r.getRoughnessFactor=function(){return this.H},r.setRoughnessFactor=function(t){return this.H=t,this},r.getMetallicFactor=function(){return this.K},r.setMetallicFactor=function(t){return this.K=t,this},r.getMetallicRoughnessTexture=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null},r.getMetallicRoughnessTextureInfo=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null},r.getMetallicRoughnessTextureSampler=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null},r.setMetallicRoughnessTexture=function(t){return this.metallicRoughnessTexture=this.v.linkTexture("metallicRoughnessTexture",this,t),this},n}(b);a([d],G.prototype,"baseColorTexture",void 0),a([d],G.prototype,"emissiveTexture",void 0),a([d],G.prototype,"normalTexture",void 0),a([d],G.prototype,"occlusionTexture",void 0),a([d],G.prototype,"metallicRoughnessTexture",void 0);var J=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Mesh",n.W=[],n.primitives=[],n}i(n,t);var r=n.prototype;return r.addPrimitive=function(t){return this.addGraphChild(this.primitives,this.v.link("primitive",this,t))},r.removePrimitive=function(t){return this.removeGraphChild(this.primitives,t)},r.listPrimitives=function(){return this.primitives.map(function(t){return t.getChild()})},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(b);a([w],J.prototype,"primitives",void 0);var z=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Primitive",n.X=4,n.indices=null,n.attributes=[],n.targets=[],n.material=null,n}i(n,t);var r=n.prototype;return r.getIndices=function(){return this.indices?this.indices.getChild():null},r.setIndices=function(t){return this.indices=this.v.linkIndex("index",this,t),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.v.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},r.getMaterial=function(){return this.material?this.material.getChild():null},r.setMaterial=function(t){return this.material=this.v.link("material",this,t),this},r.getMode=function(){return this.X},r.setMode=function(t){return this.X=t,this},r.listTargets=function(){return this.targets.map(function(t){return t.getChild()})},r.addTarget=function(t){return this.addGraphChild(this.targets,this.v.link("target",this,t)),this},r.removeTarget=function(t){return this.removeGraphChild(this.targets,t)},n}(b);a([d],z.prototype,"indices",void 0),a([w],z.prototype,"attributes",void 0),a([w],z.prototype,"targets",void 0),a([d],z.prototype,"material",void 0);var $=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="PrimitiveTarget",n.attributes=[],n}i(n,t);var r=n.prototype;return r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.v.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},n}(b);a([w],$.prototype,"attributes",void 0);var Y=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Node",n.Z=[0,0,0],n.tt=[0,0,0,1],n.nt=[1,1,1],n.W=[],n.camera=null,n.mesh=null,n.skin=null,n.children=[],n}i(n,t);var r=n.prototype;return r.getTranslation=function(){return this.Z},r.getRotation=function(){return this.tt},r.getScale=function(){return this.nt},r.setTranslation=function(t){return this.Z=t,this},r.setRotation=function(t){return this.tt=t,this},r.setScale=function(t){return this.nt=t,this},r.addChild=function(t){var n=this.v.link("child",this,t);return this.addGraphChild(this.children,n)},r.removeChild=function(t){return this.removeGraphChild(this.children,t)},r.listChildren=function(){return this.children.map(function(t){return t.getChild()})},r.getMesh=function(){return this.mesh?this.mesh.getChild():null},r.setMesh=function(t){return this.mesh=this.v.link("mesh",this,t),this},r.getCamera=function(){return this.camera?this.camera.getChild():null},r.setCamera=function(t){return this.camera=this.v.link("camera",this,t),this},r.getSkin=function(){return this.skin?this.skin.getChild():null},r.setSkin=function(t){return this.skin=this.v.link("skin",this,t),this},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(b);a([d],Y.prototype,"camera",void 0),a([d],Y.prototype,"mesh",void 0),a([d],Y.prototype,"skin",void 0),a([w],Y.prototype,"children",void 0);var q=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Root",n.rt={generator:"glTF-Transform v0.3.3",version:"2.0"},n.scenes=[],n.nodes=[],n.cameras=[],n.skins=[],n.meshes=[],n.materials=[],n.textures=[],n.animations=[],n.accessors=[],n.buffers=[],n}i(n,t);var r=n.prototype;return r.getAsset=function(){return this.rt},r.addScene=function(t){return this.addGraphChild(this.scenes,this.v.link("scene",this,t))},r.removeScene=function(t){return this.removeGraphChild(this.scenes,t)},r.listScenes=function(){return this.scenes.map(function(t){return t.getChild()})},r.addNode=function(t){return this.addGraphChild(this.nodes,this.v.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},r.addCamera=function(t){return this.addGraphChild(this.cameras,this.v.link("camera",this,t))},r.removeCamera=function(t){return this.removeGraphChild(this.cameras,t)},r.listCameras=function(){return this.cameras.map(function(t){return t.getChild()})},r.addSkin=function(t){return this.addGraphChild(this.skins,this.v.link("skin",this,t))},r.removeSkin=function(t){return this.removeGraphChild(this.skins,t)},r.listSkins=function(){return this.skins.map(function(t){return t.getChild()})},r.addMesh=function(t){return this.addGraphChild(this.meshes,this.v.link("mesh",this,t))},r.removeMesh=function(t){return this.removeGraphChild(this.meshes,t)},r.listMeshes=function(){return this.meshes.map(function(t){return t.getChild()})},r.addMaterial=function(t){return this.addGraphChild(this.materials,this.v.link("material",this,t))},r.removeMaterial=function(t){return this.removeGraphChild(this.materials,t)},r.listMaterials=function(){return this.materials.map(function(t){return t.getChild()})},r.addTexture=function(t){return this.addGraphChild(this.textures,this.v.link("texture",this,t))},r.removeTexture=function(t){return this.removeGraphChild(this.textures,t)},r.listTextures=function(){return this.textures.map(function(t){return t.getChild()})},r.addAnimation=function(t){return this.addGraphChild(this.animations,this.v.link("animation",this,t))},r.removeAnimation=function(t){return this.removeGraphChild(this.animations,t)},r.listAnimations=function(){return this.animations.map(function(t){return t.getChild()})},r.addAccessor=function(t){return this.addGraphChild(this.accessors,this.v.link("accessor",this,t))},r.removeAccessor=function(t){return this.removeGraphChild(this.accessors,t)},r.listAccessors=function(){return this.accessors.map(function(t){return t.getChild()})},r.addBuffer=function(t){return this.addGraphChild(this.buffers,this.v.link("buffer",this,t))},r.removeBuffer=function(t){return this.removeGraphChild(this.buffers,t)},r.listBuffers=function(){return this.buffers.map(function(t){return t.getChild()})},n}(b);a([w],q.prototype,"scenes",void 0),a([w],q.prototype,"nodes",void 0),a([w],q.prototype,"cameras",void 0),a([w],q.prototype,"skins",void 0),a([w],q.prototype,"meshes",void 0),a([w],q.prototype,"materials",void 0),a([w],q.prototype,"textures",void 0),a([w],q.prototype,"animations",void 0),a([w],q.prototype,"accessors",void 0),a([w],q.prototype,"buffers",void 0);var H=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Scene",n.nodes=[],n}i(n,t);var r=n.prototype;return r.addNode=function(t){return this.addGraphChild(this.nodes,this.v.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},n}(b);a([w],H.prototype,"nodes",void 0);var K=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Skin",n.skeleton=null,n.inverseBindMatrices=null,n.joints=[],n}i(n,t);var r=n.prototype;return r.getSkeleton=function(){return this.skeleton?this.skeleton.getChild():null},r.setSkeleton=function(t){return this.skeleton=this.v.link("skeleton",this,t),this},r.getInverseBindMatrices=function(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null},r.setInverseBindMatrices=function(t){return this.inverseBindMatrices=this.v.link("inverseBindMatrices",this,t),this},r.addJoint=function(t){var n=this.v.link("joint",this,t);return this.addGraphChild(this.joints,n)},r.removeJoint=function(t){return this.removeGraphChild(this.joints,t)},r.listJoints=function(){return this.joints.map(function(t){return t.getChild()})},n}(b);a([d],K.prototype,"skeleton",void 0),a([d],K.prototype,"inverseBindMatrices",void 0),a([w],K.prototype,"joints",void 0);var Q=function(){function t(){this.graph=new F,this.root=new q(this.graph),this.logger=new U(U.Verbosity.INFO)}var n=t.prototype;return n.getRoot=function(){return this.root},n.getGraph=function(){return this.graph},n.getLogger=function(){return this.logger},n.setLogger=function(t){return this.logger=t,this},n.clone=function(){throw new Error("Not implemented.")},n.transform=function(){for(var t,n=c([].slice.call(arguments));!(t=n()).done;){var r=t.value;r(this)}return this},n.createScene=function(t){var n=new H(this.graph,t);return this.root.addScene(n),n},n.createNode=function(t){var n=new Y(this.graph,t);return this.root.addNode(n),n},n.createCamera=function(t){var n=new R(this.graph,t);return this.root.addCamera(n),n},n.createSkin=function(t){var n=new K(this.graph,t);return this.root.addSkin(n),n},n.createMesh=function(t){var n=new J(this.graph,t);return this.root.addMesh(n),n},n.createPrimitive=function(){return new z(this.graph)},n.createPrimitiveTarget=function(t){return new $(this.graph,t)},n.createMaterial=function(t){var n=new G(this.graph,t);return this.root.addMaterial(n),n},n.createTexture=function(t){var n=new L(this.graph,t);return this.root.addTexture(n),n},n.createAnimation=function(t){var n=new E(this.graph,t);return this.root.addAnimation(n),n},n.createAnimationChannel=function(){return new g(this.graph)},n.createAnimationSampler=function(){return new T(this.graph)},n.createAccessor=function(t,n){void 0===n&&(n=null),n||(n=this.getRoot().listBuffers()[0]);var r=new A(this.graph,t).setBuffer(n);return this.root.addAccessor(r),r},n.createBuffer=function(t){var n=new M(this.graph,t);return this.root.addBuffer(n),n},t}(),W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},X=function(){function t(){}return t.read=function(t){var i=t.json,u=new Q;if("2.0"!==i.asset.version)throw new Error('Unsupported glTF version: "'+i.asset.version+'".');var e=(i.buffers||[]).map(function(t){var n=u.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&n.setURI(t.uri),n}),o=(i.bufferViews||[]).map(function(t){return e[t.buffer]}),s=(i.accessors||[]).map(function(n){var i,e=u.createAccessor(n.name,o[n.bufferView]);return e.setType(n.type),i=void 0!==n.sparse?function(t,n){var i,u=W[t.componentType],e=A.getElementSize(t.type);i=void 0!==t.bufferView?nt(t,n).slice():new u(t.count*e);for(var o=t.sparse.count,s=r(r(r({},t),t.sparse.indices),{},{count:o,type:"SCALAR"}),f=r(r(r({},t),t.sparse.values),{},{count:o}),h=nt(s,n),c=nt(f,n),a=0;a<s.count;a++)for(var v=0;v<e;v++)i[h[a]*e+v]=c[a*e+v];return i}(n,t):nt(n,t).slice(),void 0!==n.normalized&&e.setNormalized(n.normalized),e.setArray(i),e}),f=i.textures||[],h=(i.images||[]).map(function(n){var r=u.createTexture(n.name);if(void 0!==n.bufferView){var e=i.bufferViews[n.bufferView],o=t.json.buffers[e.buffer],s=e.byteOffset||0,f=(o.uri?t.resources[o.uri]:t.resources["it"]).slice(s,s+e.byteLength);r.setImage(f)}else void 0!==n.uri&&(r.setImage(t.resources[n.uri]),0!==n.uri.indexOf("__")&&r.setURI(n.uri));if(void 0!==n.mimeType)r.setMimeType(n.mimeType);else if(n.uri){var h=S.extension(n.uri);r.setMimeType("png"===h?"image/png":"image/jpeg")}return r}),a=(i.materials||[]).map(function(n){var r=u.createMaterial(n.name);void 0!==n.alphaMode&&r.setAlphaMode(n.alphaMode),void 0!==n.alphaCutoff&&r.setAlphaCutoff(n.alphaCutoff),void 0!==n.doubleSided&&r.setDoubleSided(n.doubleSided);var i=n.pbrMetallicRoughness||{};if(void 0!==i.baseColorFactor&&r.setBaseColorFactor(i.baseColorFactor),void 0!==n.emissiveFactor&&r.setEmissiveFactor(n.emissiveFactor),void 0!==i.metallicFactor&&r.setMetallicFactor(i.metallicFactor),void 0!==i.roughnessFactor&&r.setRoughnessFactor(i.roughnessFactor),void 0!==i.baseColorTexture){var e=i.baseColorTexture;r.setBaseColorTexture(h[f[e.index].source]),Z(r.getBaseColorTextureInfo(),e),tt(r.getBaseColorTextureSampler(),e,t)}if(void 0!==n.emissiveTexture){var o=n.emissiveTexture;r.setEmissiveTexture(h[f[o.index].source]),Z(r.getEmissiveTextureInfo(),o),tt(r.getEmissiveTextureSampler(),o,t)}if(void 0!==n.normalTexture){var s=n.normalTexture;r.setNormalTexture(h[f[s.index].source]),Z(r.getNormalTextureInfo(),s),tt(r.getNormalTextureSampler(),s,t),void 0!==n.normalTexture.scale&&r.setNormalScale(n.normalTexture.scale)}if(void 0!==n.occlusionTexture){var c=n.occlusionTexture;r.setOcclusionTexture(h[f[c.index].source]),Z(r.getOcclusionTextureInfo(),c),tt(r.getOcclusionTextureSampler(),c,t),void 0!==n.occlusionTexture.strength&&r.setOcclusionStrength(n.occlusionTexture.strength)}if(void 0!==i.metallicRoughnessTexture){var a=i.metallicRoughnessTexture;r.setMetallicRoughnessTexture(h[f[a.index].source]),Z(r.getMetallicRoughnessTextureInfo(),a),tt(r.getMetallicRoughnessTextureSampler(),a,t)}return r}),v=(i.meshes||[]).map(function(t){var n=u.createMesh(t.name);return void 0!==t.weights&&n.setWeights(t.weights),t.primitives.forEach(function(r){var i=u.createPrimitive();void 0!==r.material&&i.setMaterial(a[r.material]),void 0!==r.mode&&i.setMode(r.mode);for(var e=0,o=Object.entries(r.attributes||{});e<o.length;e++){var f=o[e];i.setAttribute(f[0],s[f[1]])}void 0!==r.indices&&i.setIndices(s[r.indices]);var h=t.extras&&t.extras.targetNames||[];(r.targets||[]).forEach(function(t,n){for(var r=h[n]||n.toString(),e=u.createPrimitiveTarget(r),o=0,f=Object.entries(t);o<f.length;o++){var c=f[o];e.setAttribute(c[0],s[c[1]])}i.addTarget(e)}),n.addPrimitive(i)}),n}),l=(i.cameras||[]).map(function(t){var n=u.createCamera(t.name).setType(t.type);return"perspective"===t.type?n.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):n.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),n}),d=i.nodes||[],w=d.map(function(t){var r=u.createNode(t.name);return void 0!==t.translation&&r.setTranslation(t.translation),void 0!==t.rotation&&r.setRotation(t.rotation),void 0!==t.scale&&r.setScale(t.scale),void 0!==t.matrix&&(r.setTranslation(n.getTranslation([],t.matrix)),r.setRotation(n.getRotation([],t.matrix)),r.setScale(n.getScaling([],t.matrix))),void 0!==t.weights&&r.setWeights(t.weights),r}),p=(i.skins||[]).map(function(t){var n=u.createSkin(t.name);void 0!==t.inverseBindMatrices&&n.setInverseBindMatrices(s[t.inverseBindMatrices]),void 0!==t.skeleton&&n.setSkeleton(w[t.skeleton]);for(var r,i=c(t.joints);!(r=i()).done;)n.addJoint(w[r.value]);return n});return d.map(function(t,n){var r=w[n];(t.children||[]).forEach(function(t){return r.addChild(w[t])}),void 0!==t.mesh&&r.setMesh(v[t.mesh]),void 0!==t.camera&&r.setCamera(l[t.camera]),void 0!==t.skin&&r.setSkin(p[t.skin])}),(i.animations||[]).map(function(t){var n=u.createAnimation(t.name),r=(t.samplers||[]).map(function(t){var r=u.createAnimationSampler().setInput(s[t.input]).setOutput(s[t.output]).setInterpolation(t.interpolation||"LINEAR");return n.addSampler(r),r});return(t.channels||[]).forEach(function(t){var i=u.createAnimationChannel().setSampler(r[t.sampler]).setTargetNode(w[t.target.node]).setTargetPath(t.target.path);n.addChannel(i)}),n}),(i.scenes||[]).map(function(t){var n=u.createScene(t.name);return(t.nodes||[]).map(function(t){return w[t]}).forEach(function(t){return n.addNode(t)}),n}),u},t}();function Z(t,n){void 0!==n.texCoord&&t.setTexCoord(n.texCoord)}function tt(t,n,r){var i=r.json.textures[n.index];if(void 0!==i.sampler){var u=r.json.samplers[i.sampler];void 0!==u.magFilter&&t.setMagFilter(u.magFilter),void 0!==u.minFilter&&t.setMinFilter(u.minFilter),void 0!==u.wrapS&&t.setWrapS(u.wrapS),void 0!==u.wrapT&&t.setWrapT(u.wrapT)}}function nt(t,n){var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["it"],e=W[t.componentType],o=A.getElementSize(t.type);if(void 0!==r.byteStride&&r.byteStride!==o*e.BYTES_PER_ELEMENT)return function(t,n){for(var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["it"],e=W[t.componentType],o=A.getElementSize(t.type),s=e.BYTES_PER_ELEMENT,f=t.byteOffset||0,h=new e(t.count*o),c=new DataView(u,r.byteOffset,r.byteLength),a=r.byteStride,v=0;v<t.count;v++)for(var l=0;l<o;l++){var d=f+v*a+l*s,w=void 0;switch(t.componentType){case 5126:w=c.getFloat32(d,!0);break;case 5125:w=c.getUint32(d,!0);break;case 5123:w=c.getUint16(d,!0);break;case 5121:w=c.getUint8(d);break;case 5122:w=c.getInt16(d,!0);break;case 5120:w=c.getInt8(d);break;default:throw new Error('Unexpected componentType "'+t.componentType+'".')}h[v*o+l]=w}return h}(t,n);var s=(r.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(u,s,t.count*o);case 5125:return new Uint32Array(u,s,t.count*o);case 5123:return new Uint16Array(u,s,t.count*o);case 5121:return new Uint8Array(u,s,t.count*o);case 5122:return new Int16Array(u,s,t.count*o);case 5120:return new Int8Array(u,s,t.count*o);default:throw new Error('Unexpected componentType "'+t.componentType+'".')}}var rt=function(){function t(){}return t.write=function(t,n){var r=t.getRoot(),i={json:{asset:r.getAsset()},resources:{}},u=i.json,e=t.getLogger(),o=r.listBuffers().length,s=r.listTextures().length,f=new et(o>1,n.basename),h=new et(s>1,n.basename),a=new Map,v=new Map,l=new Map,d=new Map,w=new Map,p=new Map,y=new Map,b=new Map,m=new Map,E=[];function g(t,n,r,i){for(var e,o=[],s=0,f=c(t);!(e=f()).done;){var h=e.value,v=ut(h);v.bufferView=u.bufferViews.length;var l=x.pad(h.getArray().buffer);v.byteOffset=s,s+=l.byteLength,o.push(l),a.set(h,u.accessors.length),u.accessors.push(v)}var d={buffer:n,byteOffset:r,byteLength:x.concat(o).byteLength};return i&&(d.target=i),u.bufferViews.push(d),{buffers:o,byteLength:s}}function T(t,n,r){for(var i,e=t[0].getCount(),o=0,s=c(t);!(i=s()).done;){var f=i.value,h=ut(f);h.bufferView=u.bufferViews.length,h.byteOffset=o;var v=f.getElementSize(),l=f.getComponentSize();o+=x.padNumber(v*l),a.set(f,u.accessors.length),u.accessors.push(h)}for(var d=e*o,w=new ArrayBuffer(d),p=new DataView(w),y=0;y<e;y++)for(var b,A=0,m=c(t);!(b=m()).done;){for(var E=b.value,g=E.getElementSize(),T=E.getComponentSize(),M=E.getComponentType(),R=E.getArray(),S=0;S<g;S++){var N=y*o+A+S*T,O=R[y*g+S];switch(M){case 5126:p.setFloat32(N,O,!0);break;case 5120:p.setInt8(N,O);break;case 5122:p.setInt16(N,O,!0);break;case 5121:p.setUint8(N,O);break;case 5123:p.setUint16(N,O,!0);break;case 5125:p.setUint32(N,O,!0);break;default:throw new Error("Unexpected component type: "+M)}}A+=x.padNumber(g*T)}return u.bufferViews.push({buffer:n,byteOffset:r,byteLength:d,byteStride:o,target:34962}),{byteLength:d,buffers:[w]}}function M(t,n,r){var i={magFilter:r.getMagFilter()||void 0,minFilter:r.getMinFilter()||void 0,wrapS:r.getWrapS(),wrapT:r.getWrapT()},e=JSON.stringify(i);m.has(e)||(m.set(e,u.samplers.length),u.samplers.push(i));var o={source:y.get(t),sampler:m.get(e)},s=JSON.stringify(o);return b.has(s)||(b.set(s,u.textures.length),u.textures.push(o)),{index:b.get(s),texCoord:n.getTexCoord()}}for(var R,S=new Map,N=c(t.getGraph().getLinks());!(R=N()).done;){var O=R.value;if(O.getParent()!==r){var U=O.getChild();if(U instanceof A){var I=S.get(U)||[];I.push(O),S.set(U,I)}}}return u.accessors=[],u.bufferViews=[],u.samplers=[],u.textures=[],u.images=r.listTextures().map(function(t,r){var e=it(t);if(t.getMimeType()&&(e.mimeType=t.getMimeType()),n.isGLB)E.push(t.getImage()),e.bufferView=u.bufferViews.length,u.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.getImage().byteLength});else{var o="image/png"===t.getMimeType()?"png":"jpeg";e.uri=h.createURI(t,o),i.resources[e.uri]=t.getImage()}return y.set(t,r),e}),u.buffers=[],r.listBuffers().forEach(function(t){for(var r,o=it(t),s=new Map,h=new Set,a=new Set,v=c(t.listParents().filter(function(t){return!(t instanceof q)}));!(r=v()).done;){var l=r.value;if(!(l instanceof A))throw new Error("Unimplemented buffer reference: "+l);for(var d,w=!1,p=!1,y=!1,b=S.get(l)||[],m=c(b);!(d=m()).done;){var M=d.value;M instanceof D?w=!0:M instanceof V?p=!0:y=!0}if(w||p||y||(y=!0),!w||p||y)if(!p||w||y){if(!y||w||p)throw new Error("Attribute or index accessors must be used only for that purpose.");a.add(l)}else h.add(l);else{var R=b[0].getParent(),N=s.get(R)||new Set;N.add(l),s.set(R,N)}}var O,U=[],I=u.buffers.length,j=0;if(h.size){var _=g(Array.from(h),I,j,34963);j+=_.byteLength,U.push.apply(U,_.buffers)}for(var C=0,L=Array.from(s.values());C<L.length;C++){var k=L[C];if(k.size){var B=T(Array.from(k),I,j);j+=B.byteLength,U.push.apply(U,B.buffers)}}if(a.size){var P=g(Array.from(a),I,j);j+=P.byteLength,U.push.apply(U,P.buffers)}if(E.length)for(var F=0;F<E.length;F++)u.bufferViews[u.images[F].bufferView].byteOffset=j,j+=E[F].byteLength,U.push(E[F]);j?(n.isGLB?O="__glb.bin":(O=f.createURI(t,"bin"),o.uri=O),o.byteLength=j,i.resources[O]=x.concat(U),u.buffers.push(o)):e.warn('@gltf-transform/core: Skipping empty buffer, "'+t.getName()+'".')}),u.materials=r.listMaterials().map(function(t,n){var r=it(t);if(r.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(r.alphaCutoff=t.getAlphaCutoff()),r.doubleSided=t.getDoubleSided(),r.pbrMetallicRoughness={},r.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),r.emissiveFactor=t.getEmissiveFactor(),r.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),r.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){var i=t.getBaseColorTexture(),u=t.getBaseColorTextureInfo(),e=t.getBaseColorTextureSampler();r.pbrMetallicRoughness.baseColorTexture=M(i,u,e)}if(t.getEmissiveTexture()){var o=t.getEmissiveTexture(),s=t.getEmissiveTextureInfo(),f=t.getEmissiveTextureSampler();r.emissiveTexture=M(o,s,f)}if(t.getNormalTexture()){var h=M(t.getNormalTexture(),t.getNormalTextureInfo(),t.getNormalTextureSampler());1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),r.normalTexture=h}if(t.getOcclusionTexture()){var c=M(t.getOcclusionTexture(),t.getOcclusionTextureInfo(),t.getOcclusionTextureSampler());1!==t.getOcclusionStrength()&&(c.strength=t.getOcclusionStrength()),r.occlusionTexture=c}if(t.getMetallicRoughnessTexture()){var a=t.getMetallicRoughnessTexture(),v=t.getMetallicRoughnessTextureInfo(),l=t.getMetallicRoughnessTextureSampler();r.pbrMetallicRoughness.metallicRoughnessTexture=M(a,v,l)}return d.set(t,n),r}),u.meshes=r.listMeshes().map(function(t,n){var r,i=it(t);return i.primitives=t.listPrimitives().map(function(t){var n={attributes:{}};n.material=d.get(t.getMaterial()),n.mode=t.getMode(),t.getIndices()&&(n.indices=a.get(t.getIndices()));for(var i,u=c(t.listSemantics());!(i=u()).done;){var e=i.value;n.attributes[e]=a.get(t.getAttribute(e))}for(var o,s=c(t.listTargets());!(o=s()).done;){for(var f,h=o.value,v={},l=c(h.listSemantics());!(f=l()).done;){var w=f.value;v[w]=a.get(h.getAttribute(w))}n.targets=n.targets||[],n.targets.push(v)}return t.listTargets().length&&!r&&(r=t.listTargets().map(function(t){return t.getName()})),n}),t.getWeights().length&&(i.weights=t.getWeights()),r&&(i.extras=i.extras||{},i.extras.targetNames=r),w.set(t,n),i}),u.cameras=r.listCameras().map(function(t,n){var r=it(t);return r.type=t.getType(),"perspective"===r.type?r.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:r.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},v.set(t,n),r}),u.nodes=r.listNodes().map(function(t,n){var r=it(t);return r.translation=t.getTranslation(),r.rotation=t.getRotation(),r.scale=t.getScale(),t.getWeights().length&&(r.weights=t.getWeights()),p.set(t,n),r}),u.skins=r.listSkins().map(function(t,n){var r=it(t);return t.getInverseBindMatrices()&&(r.inverseBindMatrices=a.get(t.getInverseBindMatrices())),t.getSkeleton()&&(r.skeleton=p.get(t.getSkeleton())),r.joints=t.listJoints().map(function(t){return p.get(t)}),l.set(t,n),r}),r.listNodes().forEach(function(t,n){var r=u.nodes[n];t.getMesh()&&(r.mesh=w.get(t.getMesh())),t.getCamera()&&(r.camera=v.get(t.getCamera())),t.getSkin()&&(r.skin=l.get(t.getSkin())),t.listChildren().length>0&&(r.children=t.listChildren().map(function(t){return p.get(t)}))}),u.animations=r.listAnimations().map(function(t){var n=it(t),r=new Map;return n.samplers=t.listSamplers().map(function(t,n){var i=it(t);return i.input=a.get(t.getInput()),i.output=a.get(t.getOutput()),i.interpolation=t.getInterpolation(),r.set(t,n),i}),n.channels=t.listChannels().map(function(t){var n=it(t);return n.sampler=r.get(t.getSampler()),n.target={node:p.get(t.getTargetNode()),path:t.getTargetPath()},n}),n}),u.scenes=r.listScenes().map(function(t){var n=it(t);return n.nodes=t.listNodes().map(function(t){return p.get(t)}),n}),function(t){var n=[];for(var r in t){var i=t[r];Array.isArray(i)&&0===i.length?n.push(r):null!==i&&""!==i||n.push(i)}for(var u=0,e=n;u<e.length;u++)delete t[e[u]]}(u),i},t}();function it(t){var n={};return t.getName()&&(n.name=t.getName()),Object.keys(t.getExtras()).length>0&&(n.extras=t.getExtras()),Object.keys(t.getExtensions()).length>0&&(n.extras=t.getExtensions()),n}function ut(t){var n=it(t);return n.type=t.getType(),n.componentType=t.getComponentType(),n.count=t.getCount(),t.getMax(n.max=[]),t.getMin(n.min=[]),n.normalized=t.getNormalized(),n}var et=function(){function t(t,n){this.multiple=t,this.basename=n,this.counter=1}return t.prototype.createURI=function(t,n){return t.getURI()?t.getURI():this.multiple?this.basename+"_"+this.counter+++"."+n:this.basename+"."+n},t}(),ot=function(){function t(){}var n=t.prototype;return n.createDocument=function(t){return X.read(t)},n.createNativeDocument=function(t,n){if(n.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return rt.write(t,n)},n.unpackGLB=function(t){var n,r=new Uint32Array(t,0,3);if(1179937895!==r[0])throw new Error("Invalid glTF asset.");if(2!==r[1])throw new Error('Unsupported glTF binary version, "'+r[1]+'".');var i=new Uint32Array(t,12,2),u=i[0],e=new Uint32Array(t,20+u,2);if(1313821514!==i[1]||5130562!==e[1])throw new Error("Unexpected GLB layout.");var o=x.decodeText(t.slice(20,20+u)),s=JSON.parse(o),f=20+u+8,h=t.slice(f,f+e[0]);return this.createDocument({json:s,resources:(n={},n["it"]=h,n)})},n.packGLB=function(t){var n=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=n.resources,i=JSON.stringify(n.json),u=x.pad(x.encodeText(i),32),e=new Uint32Array([u.byteLength,1313821514]).buffer,o=x.concat([e,u]),s=x.pad(Object.values(r)[0],0),f=new Uint32Array([s.byteLength,5130562]).buffer,h=x.concat([f,s]),c=new Uint32Array([1179937895,2,12+o.byteLength+h.byteLength]).buffer;return x.concat([c,o,h])},t}(),st=function(t){function n(n,r){var i;return(i=t.call(this)||this).fs=n,i.path=r,i}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.write=function(t,n){t.match(/\.glb$/)?this.writeGLB(t,n):this.writeGLTF(t,n)},r.readGLB=function(t){var n=this.fs.readFileSync(t),r=x.trim(n);return this.unpackGLB(r)},r.readGLTF=function(t){var n=this,r=this.path.dirname(t),i={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[].concat(i.json.images||[],i.json.buffers||[]).forEach(function(t){if(t.uri&&!t.uri.match(/data:/)){var u=n.path.resolve(r,t.uri);i.resources[t.uri]=x.trim(n.fs.readFileSync(u))}else{var e="__"+C()+"."+S.extension(t.uri);i.resources[e]=x.createBufferFromDataURI(t.uri),t.uri=e}}),X.read(i)},r.writeGLTF=function(t,n){var r={basename:S.basename(t),isGLB:!1},i=rt.write(n,r),u=i.json,e=i.resources,o=this.fs,s=this.path,f=s.dirname(t);o.writeFileSync(t,JSON.stringify(u,null,2)),Object.keys(e).forEach(function(t){var n=Buffer.from(e[t]);o.writeFileSync(s.join(f,t),n)})},r.writeGLB=function(t,n){var r=Buffer.from(this.packGLB(n));this.fs.writeFileSync(t,r)},n}(ot),ft=function(t){function n(n){var r;return(r=t.call(this)||this).fetchConfig=n,r}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.readGLTF=function(t){var n=this,r={json:{},resources:{}};return fetch(t,this.fetchConfig).then(function(t){return t.json()}).then(function(t){r.json=t;var i=[].concat(t.images,t.buffers).map(function(t){if(t.uri)return fetch(t.uri,n.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(n){r.resources[t.uri]=n})});return Promise.all(i).then(function(){return n.createDocument(r)})})},r.readGLB=function(t){var n=this;return fetch(t,this.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(t){return n.unpackGLB(t)})},n}(ot);t.Accessor=A,t.Animation=E,t.AnimationChannel=g,t.AnimationSampler=T,t.Buffer=M,t.BufferUtils=x,t.Camera=R,t.Document=Q,t.FileUtils=S,t.Graph=l,t.ImageUtils=N,t.Logger=U,t.Material=G,t.Mesh=J,t.Node=Y,t.NodeIO=st,t.Primitive=z,t.PrimitiveTarget=$,t.Property=b,t.Root=q,t.Scene=H,t.Skin=K,t.Texture=L,t.TextureInfo=k,t.TextureSampler=B,t.WebIO=ft,t.uuid=C}); | ||
//# sourceMappingURL=core.umd.js.map |
@@ -23,3 +23,3 @@ import { Link } from './graph-links'; | ||
*/ | ||
link(name: string, a: GraphNode, b: GraphNode | null): Link<GraphNode, GraphNode>; | ||
link<A extends GraphNode, B extends GraphNode>(name: string, a: A, b: B): Link<A, B>; | ||
protected registerLink(link: Link<GraphNode, GraphNode>): Link<GraphNode, GraphNode>; | ||
@@ -26,0 +26,0 @@ /** |
{ | ||
"name": "@gltf-transform/core", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -10,6 +10,7 @@ "description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js", | ||
"types": "dist/core.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"dist": "microbundle --format modern,umd", | ||
"watch": "microbundle watch --format modern,umd", | ||
"watch:debug": "microbundle watch --no-compress --format modern,umd" | ||
"dist": "microbundle --format modern,umd --define PACKAGE_VERSION=$npm_package_version", | ||
"watch": "microbundle watch --format modern,umd --define PACKAGE_VERSION=$npm_package_version", | ||
"watch:debug": "microbundle watch --no-compress --format modern,umd --define PACKAGE_VERSION=$npm_package_version" | ||
}, | ||
@@ -38,3 +39,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "e4108cc371764e6cc869e293ea07644b1a64e5cd" | ||
"gitHead": "dc590cd720a6a40ace781edf1b68262b0c0ab674" | ||
} |
@@ -0,1 +1,4 @@ | ||
// Injected at compile time, from $npm_package_version. | ||
declare const PACKAGE_VERSION: string; | ||
/** | ||
@@ -5,3 +8,3 @@ * Current version of the package. | ||
*/ | ||
export const VERSION = 'v0.3'; | ||
export const VERSION = `v${PACKAGE_VERSION}`; | ||
@@ -8,0 +11,0 @@ /** @hidden */ |
@@ -7,6 +7,2 @@ export { Document, Transform } from './document'; | ||
// Improved gl-matrix performance in modern web browsers. | ||
import {glMatrix} from 'gl-matrix'; | ||
glMatrix.setMatrixArrayType(Array); | ||
/** [[include:CONCEPTS.md]] */ | ||
@@ -13,0 +9,0 @@ namespace Concepts {}; |
@@ -56,3 +56,3 @@ import { Link } from './graph-links'; | ||
*/ | ||
public link(name: string, a: GraphNode, b: GraphNode | null): Link<GraphNode, GraphNode> { | ||
public link<A extends GraphNode, B extends GraphNode>(name: string, a: A, b: B): Link<A, B> { | ||
// If there's no resource, return a null link. Avoids a lot of boilerplate in node setters. | ||
@@ -59,0 +59,0 @@ if (!b) return null; |
@@ -189,3 +189,6 @@ import { TypedArray } from '../constants'; | ||
for (let j = 0; j < elementSize; j++) { | ||
target[j] = Math.min(target[j], this._array[i + j]); | ||
const value = this._array[i + j]; | ||
if (Number.isFinite(value)) { | ||
target[j] = Math.min(target[j], value); | ||
} | ||
} | ||
@@ -224,3 +227,6 @@ } | ||
for (let j = 0; j < elementSize; j++) { | ||
target[j] = Math.max(target[j], this._array[i + j]); | ||
const value = this._array[i + j]; | ||
if (Number.isFinite(value)) { | ||
target[j] = Math.max(target[j], value); | ||
} | ||
} | ||
@@ -368,3 +374,3 @@ } | ||
public setBuffer(buffer: Buffer): this { | ||
this.buffer = this._graph.link('buffer', this, buffer) as Link<Accessor, Buffer>; | ||
this.buffer = this._graph.link('buffer', this, buffer); | ||
return this; | ||
@@ -371,0 +377,0 @@ } |
@@ -49,3 +49,3 @@ import { GraphChild, GraphChildList, Link } from '../graph'; | ||
public addChannel(channel: AnimationChannel): this { | ||
const link = this._graph.link('channel', this, channel) as Link<Animation, AnimationChannel>; | ||
const link = this._graph.link('channel', this, channel); | ||
return this.addGraphChild(this.channels, link); | ||
@@ -66,3 +66,3 @@ } | ||
public addSampler(sampler: AnimationSampler): this { | ||
const link = this._graph.link('sampler', this, sampler) as Link<Animation, AnimationSampler>; | ||
const link = this._graph.link('sampler', this, sampler); | ||
return this.addGraphChild(this.samplers, link); | ||
@@ -140,3 +140,3 @@ } | ||
public setTargetNode(targetNode: Node): this { | ||
this.targetNode = this._graph.link('target.node', this, targetNode) as Link<AnimationChannel, Node>; | ||
this.targetNode = this._graph.link('target.node', this, targetNode); | ||
return this; | ||
@@ -158,3 +158,3 @@ } | ||
public setSampler(sampler: AnimationSampler): this { | ||
this.sampler = this._graph.link('sampler', this, sampler) as Link<AnimationChannel, AnimationSampler>; | ||
this.sampler = this._graph.link('sampler', this, sampler); | ||
return this; | ||
@@ -230,3 +230,3 @@ } | ||
public setInput(input: Accessor): this { | ||
this.input = this._graph.link('input', this, input) as Link<AnimationSampler, Accessor>; | ||
this.input = this._graph.link('input', this, input); | ||
return this; | ||
@@ -248,5 +248,5 @@ } | ||
public setOutput(output: Accessor): this { | ||
this.output = this._graph.link('output', this, output) as Link<AnimationSampler, Accessor>; | ||
this.output = this._graph.link('output', this, output); | ||
return this; | ||
} | ||
} |
@@ -147,3 +147,3 @@ import { GraphChild, GraphChildList } from '../graph/index'; | ||
public setIndices(indices: Accessor): this { | ||
this.indices = this._graph.linkIndex('index', this, indices) as Link<Primitive, Accessor>; | ||
this.indices = this._graph.linkIndex('index', this, indices); | ||
return this; | ||
@@ -199,3 +199,3 @@ } | ||
public setMaterial(material: Material): this { | ||
this.material = this._graph.link('material', this, material) as Link<Primitive, Material>; | ||
this.material = this._graph.link('material', this, material); | ||
return this; | ||
@@ -202,0 +202,0 @@ } |
@@ -79,3 +79,3 @@ import { vec3, vec4 } from '../constants'; | ||
public addChild(child: Node): this { | ||
const link = this._graph.link('child', this, child) as Link<Root, Node>; | ||
const link = this._graph.link('child', this, child); | ||
return this.addGraphChild(this.children, link); | ||
@@ -102,3 +102,3 @@ } | ||
public setMesh(mesh: Mesh): this { | ||
this.mesh = this._graph.link('mesh', this, mesh) as Link<Node, Mesh>; | ||
this.mesh = this._graph.link('mesh', this, mesh); | ||
return this; | ||
@@ -112,3 +112,3 @@ } | ||
public setCamera(camera: Camera): this { | ||
this.camera = this._graph.link('camera', this, camera) as Link<Node, Camera>; | ||
this.camera = this._graph.link('camera', this, camera); | ||
return this; | ||
@@ -122,3 +122,3 @@ } | ||
public setSkin(skin: Skin): this { | ||
this.skin = this._graph.link('skin', this, skin) as Link<Node, Skin>; | ||
this.skin = this._graph.link('skin', this, skin); | ||
return this; | ||
@@ -125,0 +125,0 @@ } |
@@ -83,3 +83,3 @@ import { VERSION } from '../constants'; | ||
public addScene(scene: Scene): this { | ||
return this.addGraphChild(this.scenes, this._graph.link('scene', this, scene) as Link<Root, Scene>); | ||
return this.addGraphChild(this.scenes, this._graph.link('scene', this, scene)); | ||
} | ||
@@ -109,3 +109,3 @@ | ||
public addNode(node: Node): this { | ||
return this.addGraphChild(this.nodes, this._graph.link('node', this, node) as Link<Root, Node>); | ||
return this.addGraphChild(this.nodes, this._graph.link('node', this, node)); | ||
} | ||
@@ -135,3 +135,3 @@ | ||
public addCamera(camera: Camera): this { | ||
return this.addGraphChild(this.cameras, this._graph.link('camera', this, camera) as Link<Root, Camera>); | ||
return this.addGraphChild(this.cameras, this._graph.link('camera', this, camera)); | ||
} | ||
@@ -161,3 +161,3 @@ | ||
public addSkin(skin: Skin): this { | ||
return this.addGraphChild(this.skins, this._graph.link('skin', this, skin) as Link<Root, Skin>); | ||
return this.addGraphChild(this.skins, this._graph.link('skin', this, skin)); | ||
} | ||
@@ -187,3 +187,3 @@ | ||
public addMesh(mesh: Mesh): this { | ||
return this.addGraphChild(this.meshes, this._graph.link('mesh', this, mesh) as Link<Root, Mesh>); | ||
return this.addGraphChild(this.meshes, this._graph.link('mesh', this, mesh)); | ||
} | ||
@@ -213,3 +213,3 @@ | ||
public addMaterial(material: Material): this { | ||
return this.addGraphChild(this.materials, this._graph.link('material', this, material) as Link<Root, Material>); | ||
return this.addGraphChild(this.materials, this._graph.link('material', this, material)); | ||
} | ||
@@ -239,3 +239,3 @@ | ||
public addTexture(texture: Texture): this { | ||
return this.addGraphChild(this.textures, this._graph.link('texture', this, texture) as Link<Root, Texture>); | ||
return this.addGraphChild(this.textures, this._graph.link('texture', this, texture)); | ||
} | ||
@@ -265,3 +265,3 @@ | ||
public addAnimation(animation: Animation): this { | ||
return this.addGraphChild(this.animations, this._graph.link('animation', this, animation) as Link<Root, Animation>); | ||
return this.addGraphChild(this.animations, this._graph.link('animation', this, animation)); | ||
} | ||
@@ -292,3 +292,3 @@ | ||
public addAccessor(accessor: Accessor): this { | ||
return this.addGraphChild(this.accessors, this._graph.link('accessor', this, accessor) as Link<Root, Accessor>); | ||
return this.addGraphChild(this.accessors, this._graph.link('accessor', this, accessor)); | ||
} | ||
@@ -318,3 +318,3 @@ | ||
public addBuffer(buffer: Buffer): this { | ||
return this.addGraphChild(this.buffers, this._graph.link('buffer', this, buffer) as Link<Root, Buffer>); | ||
return this.addGraphChild(this.buffers, this._graph.link('buffer', this, buffer)); | ||
} | ||
@@ -321,0 +321,0 @@ |
@@ -29,3 +29,3 @@ import { GraphChildList, Link } from '../graph/index'; | ||
public addNode(node: Node): this { | ||
return this.addGraphChild(this.nodes, this._graph.link('node', this, node) as Link<Root, Node>); | ||
return this.addGraphChild(this.nodes, this._graph.link('node', this, node)); | ||
} | ||
@@ -32,0 +32,0 @@ |
@@ -37,3 +37,3 @@ import { GraphChild, GraphChildList, Link } from '../graph'; | ||
public setSkeleton(skeleton: Node): this { | ||
this.skeleton = this._graph.link('skeleton', this, skeleton) as Link<Skin, Node>; | ||
this.skeleton = this._graph.link('skeleton', this, skeleton); | ||
return this; | ||
@@ -57,3 +57,3 @@ } | ||
public setInverseBindMatrices(inverseBindMatrices: Accessor): this { | ||
this.inverseBindMatrices = this._graph.link('inverseBindMatrices', this, inverseBindMatrices) as Link<Skin, Accessor>; | ||
this.inverseBindMatrices = this._graph.link('inverseBindMatrices', this, inverseBindMatrices); | ||
return this; | ||
@@ -64,3 +64,3 @@ } | ||
public addJoint(joint: Node): this { | ||
const link = this._graph.link('joint', this, joint) as Link<Skin, Node>; | ||
const link = this._graph.link('joint', this, joint); | ||
return this.addGraphChild(this.joints, link); | ||
@@ -67,0 +67,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7153
841853