@gltf-transform/core
Advanced tools
Comparing version 0.3.3 to 0.4.0-alpha.0
@@ -53,5 +53,1 @@ /** | ||
export declare type TypedArray = Float32Array | Uint32Array | Uint16Array | Uint8Array | Int16Array | Int8Array; | ||
/** @hidden */ | ||
export declare class NotImplementedError extends Error { | ||
constructor(); | ||
} |
export { Document, Transform } from './document'; | ||
export { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, Property, Material, Mesh, Node, Primitive, PrimitiveTarget, Root, Scene, Skin, Texture, TextureInfo, TextureSampler } from './properties'; | ||
export { Extension } from './extension'; | ||
export { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, ExtensionProperty, Property, Material, Mesh, Node, Primitive, PrimitiveTarget, Root, Scene, Skin, Texture, TextureInfo, TextureSampler } from './properties'; | ||
export { Graph } from './graph/'; | ||
export { NodeIO, WebIO } from './io/'; | ||
export { NodeIO, WebIO, ReaderContext, WriterContext } from './io/'; | ||
export { BufferUtils, FileUtils, ImageUtils, Logger, uuid } from './utils/'; |
@@ -1,2 +0,2 @@ | ||
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}; | ||
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 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.t=e}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.g}setExtras(t){return this.g=t,this}clone(){throw new Error("Not implemented.")}detach(){return this.l.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class c extends u{constructor(){super(...arguments),this.extensions=[]}getExtension(t){const e=t.EXTENSION_NAME,s=this.extensions.find(t=>t.getChild().extensionName===e);return s?s.getChild():null}setExtension(t,e){const s=this.getExtension(t);return s&&this.removeGraphChild(this.extensions,s),e?this.addGraphChild(this.extensions,this.l.link(e.extensionName,this,e)):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([o],c.prototype,"extensions",void 0);class a extends c{constructor(){super(...arguments),this.propertyType="Accessor",this.p=null,this.m="SCALAR",this.v=null,this.A=!1,this.T=l,this.M=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.M(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.p[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.M(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.p[r+e];Number.isFinite(s)&&(t[e]=Math.max(t[e],s))}return t}getCount(){return this.p.length/this.getElementSize()}getType(){return this.m}setType(t){return this.m=t,this}getElementSize(){return a.getElementSize(this.m)}getComponentSize(){return this.p.BYTES_PER_ELEMENT}getComponentType(){return this.v}getNormalized(){return this.A}setNormalized(t){return this.A=t,t?(this.M=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.v),this.T=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.v)):(this.M=l,this.T=l),this}getScalar(t){const e=this.getElementSize();return this.M(this.p[t*e])}setScalar(t,e){return this.p[t*this.getElementSize()]=this.T(e),this}getElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)e[r]=this.M(this.p[t*s+r]);return e}setElement(t,e){const s=this.getElementSize();for(let r=0;r<s;r++)this.p[t*s+r]=this.T(e[r]);return this}getBuffer(){return this.buffer.getChild()}setBuffer(t){return this.buffer=this.l.link("buffer",this,t),this}getArray(){return this.p}setArray(t){return this.v=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.p=t,this}getByteLength(){return this.p.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 d 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],d.prototype,"channels",void 0),r([o],d.prototype,"samplers",void 0);class f extends u{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.S=null,this.targetNode=null,this.sampler=null}getTargetPath(){return this.S}setTargetPath(t){return this.S=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.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],f.prototype,"targetNode",void 0),r([h],f.prototype,"sampler",void 0);class g extends u{constructor(){super(...arguments),this.propertyType="AnimationChannel",this.N="LINEAR",this.input=null,this.output=null}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.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.m="perspective"}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.C}setZNear(t){return this.C=t,this}getZFar(){return this.I}setZFar(t){return this.I=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.B}setYFov(t){return this.B=t,this}getXMag(){return this.U}setXMag(t){return this.U=t,this}getYMag(){return this.k}setYMag(t){return this.k=t,this}}class w extends u{constructor(t,e){super(t),this.L=e,this.L.addExtensionProperty(this)}dispose(){this.L.removeExtensionProperty(this),super.dispose()}}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 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 x{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 E{constructor(t){this.verbosity=t}debug(t){this.verbosity<=E.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=E.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=E.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=E.Verbosity.ERROR&&console.error(t)}}E.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const y="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",b=new Set,M=function(){let t="";for(let e=0;e<6;e++)t+=y.charAt(Math.floor(Math.random()*y.length));return t},S=function(){for(let t=0;t<999;t++){const t=M();if(!b.has(t))return b.add(t),t}};class N 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?x.getSizePNG(Buffer.from(this.image)):x.getSizeJPEG(Buffer.from(this.image))}}class R{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.O=null,this.F=10497,this.G=10497}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.O}setMinFilter(t){return this.O=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.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 I extends i{constructor(){super(...arguments),this.textureInfo=new R,this.sampler=new C}}class _ extends i{constructor(){super(...arguments),this.semantic=""}}class B extends i{}class U extends n{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 _(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 k extends c{constructor(){super(...arguments),this.propertyType="Material",this.D="OPAQUE",this.j=.5,this.$=!1,this.J=[1,1,1,1],this.V=[0,0,0],this.W=1,this.Y=1,this.q=1,this.Z=1,this.baseColorTexture=null,this.emissiveTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.metallicRoughnessTexture=null}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=t,this}getAlphaMode(){return this.D}setAlphaMode(t){return this.D=t,this}getAlphaCutoff(){return this.j}setAlphaCutoff(t){return this.j=t,this}getBaseColorFactor(){return this.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.q}setRoughnessFactor(t){return this.q=t,this}getMetallicFactor(){return this.Z}setMetallicFactor(t){return this.Z=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null}getMetallicRoughnessTextureSampler(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.l.linkTexture("metallicRoughnessTexture",this,t),this}}r([h],k.prototype,"baseColorTexture",void 0),r([h],k.prototype,"emissiveTexture",void 0),r([h],k.prototype,"normalTexture",void 0),r([h],k.prototype,"occlusionTexture",void 0),r([h],k.prototype,"metallicRoughnessTexture",void 0);class L extends c{constructor(){super(...arguments),this.propertyType="Mesh",this.X=[],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.X}setWeights(t){return this.X=t,this}}r([o],L.prototype,"primitives",void 0);class P extends u{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],P.prototype,"indices",void 0),r([o],P.prototype,"attributes",void 0),r([o],P.prototype,"targets",void 0),r([h],P.prototype,"material",void 0);class O extends u{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],O.prototype,"attributes",void 0);class F 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.X=[],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.X}setWeights(t){return this.X=t,this}}r([h],F.prototype,"camera",void 0),r([h],F.prototype,"mesh",void 0),r([h],F.prototype,"skin",void 0),r([o],F.prototype,"children",void 0);class G extends u{constructor(){super(...arguments),this.propertyType="Root",this.st={generator:"glTF-Transform v0.4.0-alpha.0",version:"2.0"},this.rt=new Set,this.scenes=[],this.nodes=[],this.cameras=[],this.skins=[],this.meshes=[],this.materials=[],this.textures=[],this.animations=[],this.accessors=[],this.buffers=[]}getAsset(){return this.st}listExtensionsUsed(){return Array.from(this.rt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}it(t){if(this.rt.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.rt.add(t),this}nt(t){return this.rt.delete(t),this}ht(t){return this.addGraphChild(this.scenes,this.l.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.cameras,this.l.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.skins,this.l.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}at(t){return this.addGraphChild(this.meshes,this.l.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.materials,this.l.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.textures,this.l.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.animations,this.l.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}gt(t){return this.addGraphChild(this.accessors,this.l.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}pt(t){return this.addGraphChild(this.buffers,this.l.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([o],G.prototype,"scenes",void 0),r([o],G.prototype,"nodes",void 0),r([o],G.prototype,"cameras",void 0),r([o],G.prototype,"skins",void 0),r([o],G.prototype,"meshes",void 0),r([o],G.prototype,"materials",void 0),r([o],G.prototype,"textures",void 0),r([o],G.prototype,"animations",void 0),r([o],G.prototype,"accessors",void 0),r([o],G.prototype,"buffers",void 0);class D 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],D.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 z{constructor(){this.graph=new U,this.root=new G(this.graph),this.logger=new E(E.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}createExtension(t){return this.getRoot().listExtensionsUsed().find(e=>e.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t){const e=new D(this.graph,t);return this.root.ht(e),e}createNode(t){const e=new F(this.graph,t);return this.root.ot(e),e}createCamera(t){const e=new m(this.graph,t);return this.root.ut(e),e}createSkin(t){const e=new j(this.graph,t);return this.root.ct(e),e}createMesh(t){const e=new L(this.graph,t);return this.root.at(e),e}createPrimitive(){return new P(this.graph)}createPrimitiveTarget(t){return new O(this.graph,t)}createMaterial(t){const e=new k(this.graph,t);return this.root.lt(e),e}createTexture(t){const e=new N(this.graph,t);return this.root.dt(e),e}createAnimation(t){const e=new d(this.graph,t);return this.root.ft(e),e}createAnimationChannel(){return new f(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.gt(s),s}createBuffer(t){const e=new p(this.graph,t);return this.root.pt(e),e}}class ${constructor(t){this.doc=t,this.wt=!1,this.vt=new Set,t.getRoot().it(this)}dispose(){this.doc.getRoot().nt(this);for(const t of this.vt)t.dispose()}isRequired(){return this.wt}setRequired(t){return this.wt=t,this}addExtensionProperty(t){return this.vt.add(t),this}removeExtensionProperty(t){return this.vt.delete(t),this}}class J{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}}const V={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class W{static read(r,i){const{json:n}=r,h=new z;if("2.0"!==n.asset.version)throw new Error(`Unsupported glTF version: "${n.asset.version}".`);const o=new J(r);o.buffers=(n.buffers||[]).map(t=>{const e=h.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&e.setURI(t.uri),e}),o.bufferViewBuffers=(n.bufferViews||[]).map(t=>o.buffers[t.buffer]),o.accessors=(n.accessors||[]).map(t=>{const e=h.createAccessor(t.name,o.bufferViewBuffers[t.bufferView]);let s;return e.setType(t.type),s=void 0!==t.sparse?function(t,e){const s=V[t.componentType],r=a.getElementSize(t.type);let i;i=void 0!==t.bufferView?Z(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=Z(h,e),c=Z(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):Z(t,r).slice(),void 0!==t.normalized&&e.setNormalized(t.normalized),e.setArray(s),e});const u=n.textures||[];o.textures=(n.images||[]).map(t=>{const e=h.createTexture(t.name);if(void 0!==t.bufferView){const s=n.bufferViews[t.bufferView],i=r.json.buffers[s.buffer],h=s.byteOffset||0,o=(i.uri?r.resources[i.uri]:r.resources["At"]).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}),o.materials=(n.materials||[]).map(t=>{const e=h.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(o.textures[u[t.index].source]),Y(e.getBaseColorTextureInfo(),t),q(e.getBaseColorTextureSampler(),t,r)}if(void 0!==t.emissiveTexture){const s=t.emissiveTexture;e.setEmissiveTexture(o.textures[u[s.index].source]),Y(e.getEmissiveTextureInfo(),s),q(e.getEmissiveTextureSampler(),s,r)}if(void 0!==t.normalTexture){const s=t.normalTexture;e.setNormalTexture(o.textures[u[s.index].source]),Y(e.getNormalTextureInfo(),s),q(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(o.textures[u[s.index].source]),Y(e.getOcclusionTextureInfo(),s),q(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(o.textures[u[t.index].source]),Y(e.getMetallicRoughnessTextureInfo(),t),q(e.getMetallicRoughnessTextureSampler(),t,r)}return e}),o.meshes=(n.meshes||[]).map(t=>{const e=h.createMesh(t.name);return void 0!==t.weights&&e.setWeights(t.weights),t.primitives.forEach(s=>{const r=h.createPrimitive();void 0!==s.material&&r.setMaterial(o.materials[s.material]),void 0!==s.mode&&r.setMode(s.mode);for(const[t,e]of Object.entries(s.attributes||{}))r.setAttribute(t,o.accessors[e]);void 0!==s.indices&&r.setIndices(o.accessors[s.indices]);const i=t.extras&&t.extras.targetNames||[];(s.targets||[]).forEach((t,e)=>{const s=i[e]||e.toString(),n=h.createPrimitiveTarget(s);for(const[e,s]of Object.entries(t))n.setAttribute(e,o.accessors[s]);r.addTarget(n)}),e.addPrimitive(r)}),e}),o.cameras=(n.cameras||[]).map(t=>{const e=h.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});const c=n.nodes||[];o.nodes=c.map(r=>{const i=h.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}),o.skins=(n.skins||[]).map(t=>{const e=h.createSkin(t.name);void 0!==t.inverseBindMatrices&&e.setInverseBindMatrices(o.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&e.setSkeleton(o.nodes[t.skeleton]);for(const s of t.joints)e.addJoint(o.nodes[s]);return e}),c.map((t,e)=>{const s=o.nodes[e];(t.children||[]).forEach(t=>s.addChild(o.nodes[t])),void 0!==t.mesh&&s.setMesh(o.meshes[t.mesh]),void 0!==t.camera&&s.setCamera(o.cameras[t.camera]),void 0!==t.skin&&s.setSkin(o.skins[t.skin])}),o.animations=(n.animations||[]).map(t=>{const e=h.createAnimation(t.name),s=(t.samplers||[]).map(t=>{const s=h.createAnimationSampler().setInput(o.accessors[t.input]).setOutput(o.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return e.addSampler(s),s});return(t.channels||[]).forEach(t=>{const r=h.createAnimationChannel().setSampler(s[t.sampler]).setTargetNode(o.nodes[t.target.node]).setTargetPath(t.target.path);e.addChannel(r)}),e}),o.scenes=(n.scenes||[]).map(t=>{const e=h.createScene(t.name);return(t.nodes||[]).map(t=>o.nodes[t]).forEach(t=>e.addNode(t)),e});const l=n.extensionsUsed||[],d=n.extensionsRequired||[];for(const t of i.extensions)l.includes(t.EXTENSION_NAME)&&h.createExtension(t).setRequired(d.includes(t.EXTENSION_NAME)).read(o);return h}}function Y(t,e){void 0!==e.texCoord&&t.setTexCoord(e.texCoord)}function q(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 Z(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["At"],n=V[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["At"],n=V[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),d=s.byteStride;for(let e=0;e<t.count;e++)for(let s=0;s<h;s++){const r=u+e*d+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 X{constructor(t){this.nativeDocument=t,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}createTextureInfoDef(t,e,s){const r={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},i=JSON.stringify(r);this.samplerDefIndexMap.has(i)||(this.samplerDefIndexMap.set(i,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(r));const n={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(i)},h=JSON.stringify(n);return this.textureDefIndexMap.has(h)||(this.textureDefIndexMap.set(h,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(n)),{index:this.textureDefIndexMap.get(h),texCoord:e.getTexCoord()}}createPropertyDef(t){const e={};return t.getName()&&(e.name=t.getName()),Object.keys(t.getExtras()).length>0&&(e.extras=t.getExtras()),e}createAccessorDef(t){const e=this.createPropertyDef(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{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 K(h>1,e.basename),c=new K(o>1,e.basename),l=new X(r);function d(t,e,s,r){const n=[];let h=0;for(const e of t){const t=l.createAccessorDef(e);t.bufferView=i.bufferViews.length;const s=v.pad(e.getArray().buffer);t.byteOffset=h,h+=s.byteLength,n.push(s),l.accessorIndexMap.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 f(t,e,s){const r=t[0].getCount();let n=0;for(const e of t){const t=l.createAccessorDef(e);t.bufferView=i.bufferViews.length,t.byteOffset=n;const s=e.getElementSize(),r=e.getComponentSize();n+=v.padNumber(s*r),l.accessorIndexMap.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]}}const g=new Map;for(const e of t.getGraph().getLinks()){if(e.getParent()===s)continue;const t=e.getChild();if(t instanceof a){const s=g.get(t)||[];s.push(e),g.set(t,s)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=s.listTextures().map((t,s)=>{const n=l.createPropertyDef(t);if(t.getMimeType()&&(n.mimeType=t.getMimeType()),e.isGLB)l.imageData.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 l.imageIndexMap.set(t,s),n}),i.buffers=[],s.listBuffers().forEach(t=>{const s=l.createPropertyDef(t),h=new Map,o=new Set,c=new Set,p=t.listParents().filter(t=>!(t instanceof G));for(const t of p){if(!(t instanceof a))throw new Error("Unimplemented buffer reference: "+t);let e=!1,s=!1,r=!1;const i=g.get(t)||[];for(const t of i)t instanceof _?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 m=[],w=i.buffers.length;let A,x=0;if(o.size){const t=d(Array.from(o),w,x,34963);x+=t.byteLength,m.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const e=f(Array.from(t),w,x);x+=e.byteLength,m.push(...e.buffers)}if(c.size){const t=d(Array.from(c),w,x);x+=t.byteLength,m.push(...t.buffers)}if(l.imageData.length)for(let t=0;t<l.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=x,x+=l.imageData[t].byteLength,m.push(l.imageData[t]);x?(e.isGLB?A="__glb.bin":(A=u.createURI(t,"bin"),s.uri=A),s.byteLength=x,r.resources[A]=v.concat(m),i.buffers.push(s)):n.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=s.listMaterials().map((t,e)=>{const s=l.createPropertyDef(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=l.createTextureInfoDef(e,r,i)}if(t.getEmissiveTexture()){const e=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();s.emissiveTexture=l.createTextureInfoDef(e,r,i)}if(t.getNormalTexture()){const e=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),n=l.createTextureInfoDef(e,r,i);1!==t.getNormalScale()&&(n.scale=t.getNormalScale()),s.normalTexture=n}if(t.getOcclusionTexture()){const e=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),n=l.createTextureInfoDef(e,r,i);1!==t.getOcclusionStrength()&&(n.strength=t.getOcclusionStrength()),s.occlusionTexture=n}if(t.getMetallicRoughnessTexture()){const e=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();s.pbrMetallicRoughness.metallicRoughnessTexture=l.createTextureInfoDef(e,r,i)}return l.materialIndexMap.set(t,e),s}),i.meshes=s.listMeshes().map((t,e)=>{const s=l.createPropertyDef(t);let r;return s.primitives=t.listPrimitives().map(t=>{const e={attributes:{}};e.material=l.materialIndexMap.get(t.getMaterial()),e.mode=t.getMode(),t.getIndices()&&(e.indices=l.accessorIndexMap.get(t.getIndices()));for(const s of t.listSemantics())e.attributes[s]=l.accessorIndexMap.get(t.getAttribute(s));for(const s of t.listTargets()){const t={};for(const e of s.listSemantics())t[e]=l.accessorIndexMap.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),l.meshIndexMap.set(t,e),s}),i.cameras=s.listCameras().map((t,e)=>{const s=l.createPropertyDef(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()},l.cameraIndexMap.set(t,e),s}),i.nodes=s.listNodes().map((t,e)=>{const s=l.createPropertyDef(t);return s.translation=t.getTranslation(),s.rotation=t.getRotation(),s.scale=t.getScale(),t.getWeights().length&&(s.weights=t.getWeights()),l.nodeIndexMap.set(t,e),s}),i.skins=s.listSkins().map((t,e)=>{const s=l.createPropertyDef(t);return t.getInverseBindMatrices()&&(s.inverseBindMatrices=l.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(s.skeleton=l.nodeIndexMap.get(t.getSkeleton())),s.joints=t.listJoints().map(t=>l.nodeIndexMap.get(t)),l.skinIndexMap.set(t,e),s}),s.listNodes().forEach((t,e)=>{const s=i.nodes[e];t.getMesh()&&(s.mesh=l.meshIndexMap.get(t.getMesh())),t.getCamera()&&(s.camera=l.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(s.skin=l.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(s.children=t.listChildren().map(t=>l.nodeIndexMap.get(t)))}),i.animations=s.listAnimations().map(t=>{const e=l.createPropertyDef(t),s=new Map;return e.samplers=t.listSamplers().map((t,e)=>{const r=l.createPropertyDef(t);return r.input=l.accessorIndexMap.get(t.getInput()),r.output=l.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),s.set(t,e),r}),e.channels=t.listChannels().map(t=>{const e=l.createPropertyDef(t);return e.sampler=s.get(t.getSampler()),e.target={node:l.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},e}),e}),i.scenes=s.listScenes().map(t=>{const e=l.createPropertyDef(t);return e.nodes=t.listNodes().map(t=>l.nodeIndexMap.get(t)),e}),i.extensionsUsed=s.listExtensionsUsed().map(t=>t.extensionName),i.extensionsRequired=s.listExtensionsRequired().map(t=>t.extensionName),s.listExtensionsUsed().forEach(t=>t.write(l)),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}}class K{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 Q{constructor(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return W.read(t,{extensions:this.rt})}createNativeDocument(t,e){if(e.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return H.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:{At: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 tt extends Q{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=`__${S()}.${A.extension(t.uri)}`;s.resources[e]=v.createBufferFromDataURI(t.uri),t.uri=e}}),W.read(s,{extensions:this.rt})}writeGLTF(t,e){const s={basename:A.basename(t),isGLB:!1},{json:r,resources:i}=H.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 et extends Q{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,d as Animation,f as AnimationChannel,g as AnimationSampler,p as Buffer,v as BufferUtils,m as Camera,z as Document,$ as Extension,w as ExtensionProperty,A as FileUtils,n as Graph,x as ImageUtils,E as Logger,k as Material,L as Mesh,F as Node,tt as NodeIO,P as Primitive,O as PrimitiveTarget,u as Property,J as ReaderContext,G as Root,D as Scene,j as Skin,N as Texture,R as TextureInfo,C as TextureSampler,et as WebIO,X as WriterContext,S 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")):"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}); | ||
!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,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 e(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 u(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)?u(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 s(t,n,r,i){var u,e=arguments.length,s=e<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,n,r,i);else for(var o=t.length-1;o>=0;o--)(u=t[o])&&(s=(e<3?u(s):e>3?u(n,r,s):u(n,r))||s);return e>3&&s&&Object.defineProperty(n,r,s),s}var o=function(){function t(t,n,r){if(this.t=t,this.i=n,this.u=r,this.s=!1,this.o=[],!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.s||(this.s=!0,this.o.forEach(function(t){return t()}),this.o.length=0)},n.onDispose=function(t){return this.o.push(t),this},n.isDisposed=function(){return this.s},t}(),h=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 o(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 f(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 c(t,n){}var a=function(t){function n(n,r){var i;return void 0===r&&(r=""),(i=t.call(this,n)||this).t="",i.v={},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.v},r.setExtras=function(t){return this.v=t,this},r.clone=function(){throw new Error("Not implemented.")},r.detach=function(){return this.l.disconnectParents(this,function(t){return"Root"!==t.propertyType}),this},r.listParents=function(){return this.listGraphParents()},n}(function(){function t(t){this.s=!1,this.l=t}var n=t.prototype;return n.canLink=function(t){return this.l===t.l},n.isDisposed=function(){return this.s},n.dispose=function(){this.l.disconnectChildren(this),this.l.disconnectParents(this),this.s=!0},n.detach=function(){return this.l.disconnectParents(this),this},n.swap=function(t,n){var r=this;return this.l.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.l.listParents(this)},t}()),v=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).extensions=[],n}i(n,t);var r=n.prototype;return r.getExtension=function(t){var n=t.EXTENSION_NAME,r=this.extensions.find(function(t){return t.getChild().extensionName===n});return r?r.getChild():null},r.setExtension=function(t,n){var r=this.getExtension(t);return r&&this.removeGraphChild(this.extensions,r),n?this.addGraphChild(this.extensions,this.l.link(n.extensionName,this,n)):this},r.listExtensions=function(){return this.extensions.map(function(t){return t.getChild()})},n}(a);s([c],v.prototype,"extensions",void 0);var l=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Accessor",n.p=null,n.A="SCALAR",n.m=null,n.T=!1,n.g=d,n.M=d,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.M(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 s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.min(t[e],s))}return t},r.getMaxNormalized=function(t){var n=this.getElementSize();this.getMax(t);for(var r=0;r<n;r++)t[r]=this.M(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 s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.max(t[e],s))}return t},r.getCount=function(){return this.p.length/this.getElementSize()},r.getType=function(){return this.A},r.setType=function(t){return this.A=t,this},r.getElementSize=function(){return n.getElementSize(this.A)},r.getComponentSize=function(){return this.p.BYTES_PER_ELEMENT},r.getComponentType=function(){return this.m},r.getNormalized=function(){return this.T},r.setNormalized=function(t){var n=this;return this.T=t,t?(this.M=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.m)},this.g=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.m)}):(this.M=d,this.g=d),this},r.getScalar=function(t){var n=this.getElementSize();return this.M(this.p[t*n])},r.setScalar=function(t,n){return this.p[t*this.getElementSize()]=this.g(n),this},r.getElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)n[i]=this.M(this.p[t*r+i]);return n},r.setElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)this.p[t*r+i]=this.g(n[i]);return this},r.getBuffer=function(){return this.buffer.getChild()},r.setBuffer=function(t){return this.buffer=this.l.link("buffer",this,t),this},r.getArray=function(){return this.p},r.setArray=function(t){return this.m=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.p=t,this},r.getByteLength=function(){return this.p.byteLength},n}(v);function d(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},s([f],l.prototype,"buffer",void 0);var w=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.l.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.l.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}(v);s([c],w.prototype,"channels",void 0),s([c],w.prototype,"samplers",void 0);var p=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.l.link("target.node",this,t),this},r.getSampler=function(){return this.sampler?this.sampler.getChild():null},r.setSampler=function(t){return this.sampler=this.l.link("sampler",this,t),this},n}(a);s([f],p.prototype,"targetNode",void 0),s([f],p.prototype,"sampler",void 0);var A=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="AnimationChannel",n.R="LINEAR",n.input=null,n.output=null,n}i(n,t);var r=n.prototype;return r.getInterpolation=function(){return this.R},r.setInterpolation=function(t){return this.R=t,this},r.getInput=function(){return this.input?this.input.getChild():null},r.setInput=function(t){return this.input=this.l.link("input",this,t),this},r.getOutput=function(){return this.output?this.output.getChild():null},r.setOutput=function(t){return this.output=this.l.link("output",this,t),this},n}(a);s([f],A.prototype,"input",void 0),s([f],A.prototype,"output",void 0);var y=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.N},r.setURI=function(t){return this.N=t,this},n}(v),b=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Camera",n.A="perspective",n}i(n,t);var r=n.prototype;return r.getType=function(){return this.A},r.setType=function(t){return this.A=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._},r.setAspectRatio=function(t){return this._=t,this},r.getYFov=function(){return this.O},r.setYFov=function(t){return this.O=t,this},r.getXMag=function(){return this.j},r.setXMag=function(t){return this.j=t,this},r.getYMag=function(){return this.C},r.setYMag=function(t){return this.C=t,this},n}(v),m=function(t){function n(n,r){var i;return(i=t.call(this,n)||this).L=r,i.L.addExtensionProperty(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i)),i}return i(n,t),n.prototype.dispose=function(){this.L.removeExtensionProperty(this),t.prototype.dispose.call(this)},n}(a),E=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=e(t);!(n=i()).done;)r+=n.value.byteLength;for(var u,s=new Uint8Array(r),o=0,h=e(t);!(u=h()).done;){var f=u.value;s.set(new Uint8Array(f),o),o+=f.byteLength}return s.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}(),T=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}(),g=function(){function t(){}return t.getSizeJPEG=function(t){var n,r;for(t=t.slice(4);t.length;){if(n=t.readUInt16BE(0),M(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 M(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 x=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}();x.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};var S="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",R=new Set,N=function(){for(var t="",n=0;n<6;n++)t+=S.charAt(Math.floor(Math.random()*S.length));return t},U=function(){for(var t=0;t<999;t++){var n=N();if(!R.has(n))return R.add(n),n}},I=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$/))?g.getSizePNG(Buffer.from(this.image)):g.getSizeJPEG(Buffer.from(this.image))},n}(v),_=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}(),O=function(){function t(){this.propertyType="TextureSampler",this.k=null,this.B=null,this.P=10497,this.V=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.V},n.setWrapT=function(t){return this.V=t,this},t}();O.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},O.TextureMagFilter={NEAREST:9728,LINEAR:9729},O.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var j=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).textureInfo=new _,n.sampler=new O,n}return i(n,t),n}(o),C=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).semantic="",n}return i(n,t),n}(o),L=function(t){function n(){return t.apply(this,arguments)||this}return i(n,t),n}(o),k=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 j(t,n,r);return this.registerLink(i),i},r.linkAttribute=function(t,n,r){if(!r)return null;var i=new C(t,n,r);return this.registerLink(i),i},r.linkIndex=function(t,n,r){if(!r)return null;var i=new L(t,n,r);return this.registerLink(i),i},n}(h),B=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Material",n.D="OPAQUE",n.G=.5,n.F=!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.F},r.setDoubleSided=function(t){return this.F=t,this},r.getAlphaMode=function(){return this.D},r.setAlphaMode=function(t){return this.D=t,this},r.getAlphaCutoff=function(){return this.G},r.setAlphaCutoff=function(t){return this.G=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.l.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.l.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.l.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.l.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.l.linkTexture("metallicRoughnessTexture",this,t),this},n}(v);s([f],B.prototype,"baseColorTexture",void 0),s([f],B.prototype,"emissiveTexture",void 0),s([f],B.prototype,"normalTexture",void 0),s([f],B.prototype,"occlusionTexture",void 0),s([f],B.prototype,"metallicRoughnessTexture",void 0);var P=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.l.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}(v);s([c],P.prototype,"primitives",void 0);var V=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.l.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.l.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.l.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.l.link("target",this,t)),this},r.removeTarget=function(t){return this.removeGraphChild(this.targets,t)},n}(a);s([f],V.prototype,"indices",void 0),s([c],V.prototype,"attributes",void 0),s([c],V.prototype,"targets",void 0),s([f],V.prototype,"material",void 0);var D=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.l.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}(a);s([c],D.prototype,"attributes",void 0);var G=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.l.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.l.link("mesh",this,t),this},r.getCamera=function(){return this.camera?this.camera.getChild():null},r.setCamera=function(t){return this.camera=this.l.link("camera",this,t),this},r.getSkin=function(){return this.skin?this.skin.getChild():null},r.setSkin=function(t){return this.skin=this.l.link("skin",this,t),this},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(v);s([f],G.prototype,"camera",void 0),s([f],G.prototype,"mesh",void 0),s([f],G.prototype,"skin",void 0),s([c],G.prototype,"children",void 0);var F=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType="Root",n.rt={generator:"glTF-Transform v0.4.0-alpha.0",version:"2.0"},n.it=new Set,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.listExtensionsUsed=function(){return Array.from(this.it)},r.listExtensionsRequired=function(){return this.listExtensionsUsed().filter(function(t){return t.isRequired()})},r.ut=function(t){if(this.it.has(t))throw new Error('Extension "'+t.extensionName+'" is already enabled.');return this.it.add(t),this},r.et=function(t){return this.it.delete(t),this},r.st=function(t){return this.addGraphChild(this.scenes,this.l.link("scene",this,t))},r.listScenes=function(){return this.scenes.map(function(t){return t.getChild()})},r.ot=function(t){return this.addGraphChild(this.nodes,this.l.link("node",this,t))},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},r.ht=function(t){return this.addGraphChild(this.cameras,this.l.link("camera",this,t))},r.listCameras=function(){return this.cameras.map(function(t){return t.getChild()})},r.ft=function(t){return this.addGraphChild(this.skins,this.l.link("skin",this,t))},r.listSkins=function(){return this.skins.map(function(t){return t.getChild()})},r.ct=function(t){return this.addGraphChild(this.meshes,this.l.link("mesh",this,t))},r.listMeshes=function(){return this.meshes.map(function(t){return t.getChild()})},r.at=function(t){return this.addGraphChild(this.materials,this.l.link("material",this,t))},r.listMaterials=function(){return this.materials.map(function(t){return t.getChild()})},r.vt=function(t){return this.addGraphChild(this.textures,this.l.link("texture",this,t))},r.listTextures=function(){return this.textures.map(function(t){return t.getChild()})},r.lt=function(t){return this.addGraphChild(this.animations,this.l.link("animation",this,t))},r.listAnimations=function(){return this.animations.map(function(t){return t.getChild()})},r.dt=function(t){return this.addGraphChild(this.accessors,this.l.link("accessor",this,t))},r.listAccessors=function(){return this.accessors.map(function(t){return t.getChild()})},r.wt=function(t){return this.addGraphChild(this.buffers,this.l.link("buffer",this,t))},r.listBuffers=function(){return this.buffers.map(function(t){return t.getChild()})},n}(a);s([c],F.prototype,"scenes",void 0),s([c],F.prototype,"nodes",void 0),s([c],F.prototype,"cameras",void 0),s([c],F.prototype,"skins",void 0),s([c],F.prototype,"meshes",void 0),s([c],F.prototype,"materials",void 0),s([c],F.prototype,"textures",void 0),s([c],F.prototype,"animations",void 0),s([c],F.prototype,"accessors",void 0),s([c],F.prototype,"buffers",void 0);var J=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.l.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}(v);s([c],J.prototype,"nodes",void 0);var z=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.l.link("skeleton",this,t),this},r.getInverseBindMatrices=function(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null},r.setInverseBindMatrices=function(t){return this.inverseBindMatrices=this.l.link("inverseBindMatrices",this,t),this},r.addJoint=function(t){var n=this.l.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}(v);s([f],z.prototype,"skeleton",void 0),s([f],z.prototype,"inverseBindMatrices",void 0),s([c],z.prototype,"joints",void 0);var $=function(){function t(){this.graph=new k,this.root=new F(this.graph),this.logger=new x(x.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=e([].slice.call(arguments));!(t=n()).done;){var r=t.value;r(this)}return this},n.createExtension=function(t){return this.getRoot().listExtensionsUsed().find(function(n){return n.extensionName===t.EXTENSION_NAME})||new t(this)},n.createScene=function(t){var n=new J(this.graph,t);return this.root.st(n),n},n.createNode=function(t){var n=new G(this.graph,t);return this.root.ot(n),n},n.createCamera=function(t){var n=new b(this.graph,t);return this.root.ht(n),n},n.createSkin=function(t){var n=new z(this.graph,t);return this.root.ft(n),n},n.createMesh=function(t){var n=new P(this.graph,t);return this.root.ct(n),n},n.createPrimitive=function(){return new V(this.graph)},n.createPrimitiveTarget=function(t){return new D(this.graph,t)},n.createMaterial=function(t){var n=new B(this.graph,t);return this.root.at(n),n},n.createTexture=function(t){var n=new I(this.graph,t);return this.root.vt(n),n},n.createAnimation=function(t){var n=new w(this.graph,t);return this.root.lt(n),n},n.createAnimationChannel=function(){return new p(this.graph)},n.createAnimationSampler=function(){return new A(this.graph)},n.createAccessor=function(t,n){void 0===n&&(n=null),n||(n=this.getRoot().listBuffers()[0]);var r=new l(this.graph,t).setBuffer(n);return this.root.dt(r),r},n.createBuffer=function(t){var n=new y(this.graph,t);return this.root.wt(n),n},t}(),Y=function(){function t(t){this.doc=t,this.pt=!1,this.At=new Set,t.getRoot().ut(this)}var n=t.prototype;return n.dispose=function(){this.doc.getRoot().et(this);for(var t,n=e(this.At);!(t=n()).done;)t.value.dispose()},n.isRequired=function(){return this.pt},n.setRequired=function(t){return this.pt=t,this},n.addExtensionProperty=function(t){return this.At.add(t),this},n.removeExtensionProperty=function(t){return this.At.delete(t),this},t}(),q=function(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]},H={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},K=function(){function t(){}return t.read=function(t,i){var u=t.json,s=new $;if("2.0"!==u.asset.version)throw new Error('Unsupported glTF version: "'+u.asset.version+'".');var o=new q(t);o.buffers=(u.buffers||[]).map(function(t){var n=s.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&n.setURI(t.uri),n}),o.bufferViewBuffers=(u.bufferViews||[]).map(function(t){return o.buffers[t.buffer]}),o.accessors=(u.accessors||[]).map(function(n){var i,u=s.createAccessor(n.name,o.bufferViewBuffers[n.bufferView]);return u.setType(n.type),i=void 0!==n.sparse?function(t,n){var i,u=H[t.componentType],e=l.getElementSize(t.type);i=void 0!==t.bufferView?X(t,n).slice():new u(t.count*e);for(var s=t.sparse.count,o=r(r(r({},t),t.sparse.indices),{},{count:s,type:"SCALAR"}),h=r(r(r({},t),t.sparse.values),{},{count:s}),f=X(o,n),c=X(h,n),a=0;a<o.count;a++)for(var v=0;v<e;v++)i[f[a]*e+v]=c[a*e+v];return i}(n,t):X(n,t).slice(),void 0!==n.normalized&&u.setNormalized(n.normalized),u.setArray(i),u});var h=u.textures||[];o.textures=(u.images||[]).map(function(n){var r=s.createTexture(n.name);if(void 0!==n.bufferView){var i=u.bufferViews[n.bufferView],e=t.json.buffers[i.buffer],o=i.byteOffset||0,h=(e.uri?t.resources[e.uri]:t.resources["yt"]).slice(o,o+i.byteLength);r.setImage(h)}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 f=T.extension(n.uri);r.setMimeType("png"===f?"image/png":"image/jpeg")}return r}),o.materials=(u.materials||[]).map(function(n){var r=s.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 u=i.baseColorTexture;r.setBaseColorTexture(o.textures[h[u.index].source]),Q(r.getBaseColorTextureInfo(),u),W(r.getBaseColorTextureSampler(),u,t)}if(void 0!==n.emissiveTexture){var e=n.emissiveTexture;r.setEmissiveTexture(o.textures[h[e.index].source]),Q(r.getEmissiveTextureInfo(),e),W(r.getEmissiveTextureSampler(),e,t)}if(void 0!==n.normalTexture){var f=n.normalTexture;r.setNormalTexture(o.textures[h[f.index].source]),Q(r.getNormalTextureInfo(),f),W(r.getNormalTextureSampler(),f,t),void 0!==n.normalTexture.scale&&r.setNormalScale(n.normalTexture.scale)}if(void 0!==n.occlusionTexture){var c=n.occlusionTexture;r.setOcclusionTexture(o.textures[h[c.index].source]),Q(r.getOcclusionTextureInfo(),c),W(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(o.textures[h[a.index].source]),Q(r.getMetallicRoughnessTextureInfo(),a),W(r.getMetallicRoughnessTextureSampler(),a,t)}return r}),o.meshes=(u.meshes||[]).map(function(t){var n=s.createMesh(t.name);return void 0!==t.weights&&n.setWeights(t.weights),t.primitives.forEach(function(r){var i=s.createPrimitive();void 0!==r.material&&i.setMaterial(o.materials[r.material]),void 0!==r.mode&&i.setMode(r.mode);for(var u=0,e=Object.entries(r.attributes||{});u<e.length;u++){var h=e[u];i.setAttribute(h[0],o.accessors[h[1]])}void 0!==r.indices&&i.setIndices(o.accessors[r.indices]);var f=t.extras&&t.extras.targetNames||[];(r.targets||[]).forEach(function(t,n){for(var r=f[n]||n.toString(),u=s.createPrimitiveTarget(r),e=0,h=Object.entries(t);e<h.length;e++){var c=h[e];u.setAttribute(c[0],o.accessors[c[1]])}i.addTarget(u)}),n.addPrimitive(i)}),n}),o.cameras=(u.cameras||[]).map(function(t){var n=s.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});var f=u.nodes||[];o.nodes=f.map(function(t){var r=s.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}),o.skins=(u.skins||[]).map(function(t){var n=s.createSkin(t.name);void 0!==t.inverseBindMatrices&&n.setInverseBindMatrices(o.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&n.setSkeleton(o.nodes[t.skeleton]);for(var r,i=e(t.joints);!(r=i()).done;)n.addJoint(o.nodes[r.value]);return n}),f.map(function(t,n){var r=o.nodes[n];(t.children||[]).forEach(function(t){return r.addChild(o.nodes[t])}),void 0!==t.mesh&&r.setMesh(o.meshes[t.mesh]),void 0!==t.camera&&r.setCamera(o.cameras[t.camera]),void 0!==t.skin&&r.setSkin(o.skins[t.skin])}),o.animations=(u.animations||[]).map(function(t){var n=s.createAnimation(t.name),r=(t.samplers||[]).map(function(t){var r=s.createAnimationSampler().setInput(o.accessors[t.input]).setOutput(o.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return n.addSampler(r),r});return(t.channels||[]).forEach(function(t){var i=s.createAnimationChannel().setSampler(r[t.sampler]).setTargetNode(o.nodes[t.target.node]).setTargetPath(t.target.path);n.addChannel(i)}),n}),o.scenes=(u.scenes||[]).map(function(t){var n=s.createScene(t.name);return(t.nodes||[]).map(function(t){return o.nodes[t]}).forEach(function(t){return n.addNode(t)}),n});for(var c,a=u.extensionsUsed||[],v=u.extensionsRequired||[],d=e(i.extensions);!(c=d()).done;){var w=c.value;a.includes(w.EXTENSION_NAME)&&s.createExtension(w).setRequired(v.includes(w.EXTENSION_NAME)).read(o)}return s},t}();function Q(t,n){void 0!==n.texCoord&&t.setTexCoord(n.texCoord)}function W(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 X(t,n){var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["yt"],e=H[t.componentType],s=l.getElementSize(t.type);if(void 0!==r.byteStride&&r.byteStride!==s*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["yt"],e=H[t.componentType],s=l.getElementSize(t.type),o=e.BYTES_PER_ELEMENT,h=t.byteOffset||0,f=new e(t.count*s),c=new DataView(u,r.byteOffset,r.byteLength),a=r.byteStride,v=0;v<t.count;v++)for(var d=0;d<s;d++){var w=h+v*a+d*o,p=void 0;switch(t.componentType){case 5126:p=c.getFloat32(w,!0);break;case 5125:p=c.getUint32(w,!0);break;case 5123:p=c.getUint16(w,!0);break;case 5121:p=c.getUint8(w);break;case 5122:p=c.getInt16(w,!0);break;case 5120:p=c.getInt8(w);break;default:throw new Error('Unexpected componentType "'+t.componentType+'".')}f[v*s+d]=p}return f}(t,n);var o=(r.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(u,o,t.count*s);case 5125:return new Uint32Array(u,o,t.count*s);case 5123:return new Uint16Array(u,o,t.count*s);case 5121:return new Uint8Array(u,o,t.count*s);case 5122:return new Int16Array(u,o,t.count*s);case 5120:return new Int8Array(u,o,t.count*s);default:throw new Error('Unexpected componentType "'+t.componentType+'".')}}var Z=function(){function t(t){this.nativeDocument=t,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}var n=t.prototype;return n.createTextureInfoDef=function(t,n,r){var i={magFilter:r.getMagFilter()||void 0,minFilter:r.getMinFilter()||void 0,wrapS:r.getWrapS(),wrapT:r.getWrapT()},u=JSON.stringify(i);this.samplerDefIndexMap.has(u)||(this.samplerDefIndexMap.set(u,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(i));var e={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(u)},s=JSON.stringify(e);return this.textureDefIndexMap.has(s)||(this.textureDefIndexMap.set(s,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(e)),{index:this.textureDefIndexMap.get(s),texCoord:n.getTexCoord()}},n.createPropertyDef=function(t){var n={};return t.getName()&&(n.name=t.getName()),Object.keys(t.getExtras()).length>0&&(n.extras=t.getExtras()),n},n.createAccessorDef=function(t){var n=this.createPropertyDef(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},t}(),tt=function(){function t(){}return t.write=function(t,n){var r=t.getRoot(),i={json:{asset:r.getAsset()},resources:{}},u=i.json,s=t.getLogger(),o=r.listBuffers().length,h=r.listTextures().length,f=new nt(o>1,n.basename),c=new nt(h>1,n.basename),a=new Z(i);function v(t,n,r,i){for(var s,o=[],h=0,f=e(t);!(s=f()).done;){var c=s.value,v=a.createAccessorDef(c);v.bufferView=u.bufferViews.length;var l=E.pad(c.getArray().buffer);v.byteOffset=h,h+=l.byteLength,o.push(l),a.accessorIndexMap.set(c,u.accessors.length),u.accessors.push(v)}var d={buffer:n,byteOffset:r,byteLength:E.concat(o).byteLength};return i&&(d.target=i),u.bufferViews.push(d),{buffers:o,byteLength:h}}function d(t,n,r){for(var i,s=t[0].getCount(),o=0,h=e(t);!(i=h()).done;){var f=i.value,c=a.createAccessorDef(f);c.bufferView=u.bufferViews.length,c.byteOffset=o;var v=f.getElementSize(),l=f.getComponentSize();o+=E.padNumber(v*l),a.accessorIndexMap.set(f,u.accessors.length),u.accessors.push(c)}for(var d=s*o,w=new ArrayBuffer(d),p=new DataView(w),A=0;A<s;A++)for(var y,b=0,m=e(t);!(y=m()).done;){for(var T=y.value,g=T.getElementSize(),M=T.getComponentSize(),x=T.getComponentType(),S=T.getArray(),R=0;R<g;R++){var N=A*o+b+R*M,U=S[A*g+R];switch(x){case 5126:p.setFloat32(N,U,!0);break;case 5120:p.setInt8(N,U);break;case 5122:p.setInt16(N,U,!0);break;case 5121:p.setUint8(N,U);break;case 5123:p.setUint16(N,U,!0);break;case 5125:p.setUint32(N,U,!0);break;default:throw new Error("Unexpected component type: "+x)}}b+=E.padNumber(g*M)}return u.bufferViews.push({buffer:n,byteOffset:r,byteLength:d,byteStride:o,target:34962}),{byteLength:d,buffers:[w]}}for(var w,p=new Map,A=e(t.getGraph().getLinks());!(w=A()).done;){var y=w.value;if(y.getParent()!==r){var b=y.getChild();if(b instanceof l){var m=p.get(b)||[];m.push(y),p.set(b,m)}}}return u.accessors=[],u.bufferViews=[],u.samplers=[],u.textures=[],u.images=r.listTextures().map(function(t,r){var e=a.createPropertyDef(t);if(t.getMimeType()&&(e.mimeType=t.getMimeType()),n.isGLB)a.imageData.push(t.getImage()),e.bufferView=u.bufferViews.length,u.bufferViews.push({buffer:0,byteOffset:-1,byteLength:t.getImage().byteLength});else{var s="image/png"===t.getMimeType()?"png":"jpeg";e.uri=c.createURI(t,s),i.resources[e.uri]=t.getImage()}return a.imageIndexMap.set(t,r),e}),u.buffers=[],r.listBuffers().forEach(function(t){for(var r,o=a.createPropertyDef(t),h=new Map,c=new Set,w=new Set,A=e(t.listParents().filter(function(t){return!(t instanceof F)}));!(r=A()).done;){var y=r.value;if(!(y instanceof l))throw new Error("Unimplemented buffer reference: "+y);for(var b,m=!1,T=!1,g=!1,M=p.get(y)||[],x=e(M);!(b=x()).done;){var S=b.value;S instanceof C?m=!0:S instanceof L?T=!0:g=!0}if(m||T||g||(g=!0),!m||T||g)if(!T||m||g){if(!g||m||T)throw new Error("Attribute or index accessors must be used only for that purpose.");w.add(y)}else c.add(y);else{var R=M[0].getParent(),N=h.get(R)||new Set;N.add(y),h.set(R,N)}}var U,I=[],_=u.buffers.length,O=0;if(c.size){var j=v(Array.from(c),_,O,34963);O+=j.byteLength,I.push.apply(I,j.buffers)}for(var k=0,B=Array.from(h.values());k<B.length;k++){var P=B[k];if(P.size){var V=d(Array.from(P),_,O);O+=V.byteLength,I.push.apply(I,V.buffers)}}if(w.size){var D=v(Array.from(w),_,O);O+=D.byteLength,I.push.apply(I,D.buffers)}if(a.imageData.length)for(var G=0;G<a.imageData.length;G++)u.bufferViews[u.images[G].bufferView].byteOffset=O,O+=a.imageData[G].byteLength,I.push(a.imageData[G]);O?(n.isGLB?U="__glb.bin":(U=f.createURI(t,"bin"),o.uri=U),o.byteLength=O,i.resources[U]=E.concat(I),u.buffers.push(o)):s.warn('@gltf-transform/core: Skipping empty buffer, "'+t.getName()+'".')}),u.materials=r.listMaterials().map(function(t,n){var r=a.createPropertyDef(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=a.createTextureInfoDef(i,u,e)}if(t.getEmissiveTexture()){var s=t.getEmissiveTexture(),o=t.getEmissiveTextureInfo(),h=t.getEmissiveTextureSampler();r.emissiveTexture=a.createTextureInfoDef(s,o,h)}if(t.getNormalTexture()){var f=t.getNormalTexture(),c=t.getNormalTextureInfo(),v=t.getNormalTextureSampler(),l=a.createTextureInfoDef(f,c,v);1!==t.getNormalScale()&&(l.scale=t.getNormalScale()),r.normalTexture=l}if(t.getOcclusionTexture()){var d=t.getOcclusionTexture(),w=t.getOcclusionTextureInfo(),p=t.getOcclusionTextureSampler(),A=a.createTextureInfoDef(d,w,p);1!==t.getOcclusionStrength()&&(A.strength=t.getOcclusionStrength()),r.occlusionTexture=A}if(t.getMetallicRoughnessTexture()){var y=t.getMetallicRoughnessTexture(),b=t.getMetallicRoughnessTextureInfo(),m=t.getMetallicRoughnessTextureSampler();r.pbrMetallicRoughness.metallicRoughnessTexture=a.createTextureInfoDef(y,b,m)}return a.materialIndexMap.set(t,n),r}),u.meshes=r.listMeshes().map(function(t,n){var r,i=a.createPropertyDef(t);return i.primitives=t.listPrimitives().map(function(t){var n={attributes:{}};n.material=a.materialIndexMap.get(t.getMaterial()),n.mode=t.getMode(),t.getIndices()&&(n.indices=a.accessorIndexMap.get(t.getIndices()));for(var i,u=e(t.listSemantics());!(i=u()).done;){var s=i.value;n.attributes[s]=a.accessorIndexMap.get(t.getAttribute(s))}for(var o,h=e(t.listTargets());!(o=h()).done;){for(var f,c=o.value,v={},l=e(c.listSemantics());!(f=l()).done;){var d=f.value;v[d]=a.accessorIndexMap.get(c.getAttribute(d))}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),a.meshIndexMap.set(t,n),i}),u.cameras=r.listCameras().map(function(t,n){var r=a.createPropertyDef(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()},a.cameraIndexMap.set(t,n),r}),u.nodes=r.listNodes().map(function(t,n){var r=a.createPropertyDef(t);return r.translation=t.getTranslation(),r.rotation=t.getRotation(),r.scale=t.getScale(),t.getWeights().length&&(r.weights=t.getWeights()),a.nodeIndexMap.set(t,n),r}),u.skins=r.listSkins().map(function(t,n){var r=a.createPropertyDef(t);return t.getInverseBindMatrices()&&(r.inverseBindMatrices=a.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(r.skeleton=a.nodeIndexMap.get(t.getSkeleton())),r.joints=t.listJoints().map(function(t){return a.nodeIndexMap.get(t)}),a.skinIndexMap.set(t,n),r}),r.listNodes().forEach(function(t,n){var r=u.nodes[n];t.getMesh()&&(r.mesh=a.meshIndexMap.get(t.getMesh())),t.getCamera()&&(r.camera=a.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(r.skin=a.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(r.children=t.listChildren().map(function(t){return a.nodeIndexMap.get(t)}))}),u.animations=r.listAnimations().map(function(t){var n=a.createPropertyDef(t),r=new Map;return n.samplers=t.listSamplers().map(function(t,n){var i=a.createPropertyDef(t);return i.input=a.accessorIndexMap.get(t.getInput()),i.output=a.accessorIndexMap.get(t.getOutput()),i.interpolation=t.getInterpolation(),r.set(t,n),i}),n.channels=t.listChannels().map(function(t){var n=a.createPropertyDef(t);return n.sampler=r.get(t.getSampler()),n.target={node:a.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},n}),n}),u.scenes=r.listScenes().map(function(t){var n=a.createPropertyDef(t);return n.nodes=t.listNodes().map(function(t){return a.nodeIndexMap.get(t)}),n}),u.extensionsUsed=r.listExtensionsUsed().map(function(t){return t.extensionName}),u.extensionsRequired=r.listExtensionsRequired().map(function(t){return t.extensionName}),r.listExtensionsUsed().forEach(function(t){return t.write(a)}),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}(),nt=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}(),rt=function(){function t(){this.it=[]}var n=t.prototype;return n.registerExtensions=function(t){var n;return(n=this.it).push.apply(n,t),this},n.createDocument=function(t){return K.read(t,{extensions:this.it})},n.createNativeDocument=function(t,n){if(n.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return tt.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 s=E.decodeText(t.slice(20,20+u)),o=JSON.parse(s),h=20+u+8,f=t.slice(h,h+e[0]);return this.createDocument({json:o,resources:(n={},n["yt"]=f,n)})},n.packGLB=function(t){var n=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=n.resources,i=JSON.stringify(n.json),u=E.pad(E.encodeText(i),32),e=new Uint32Array([u.byteLength,1313821514]).buffer,s=E.concat([e,u]),o=E.pad(Object.values(r)[0],0),h=new Uint32Array([o.byteLength,5130562]).buffer,f=E.concat([h,o]),c=new Uint32Array([1179937895,2,12+s.byteLength+f.byteLength]).buffer;return E.concat([c,s,f])},t}(),it=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=E.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]=E.trim(n.fs.readFileSync(u))}else{var e="__"+U()+"."+T.extension(t.uri);i.resources[e]=E.createBufferFromDataURI(t.uri),t.uri=e}}),K.read(i,{extensions:this.it})},r.writeGLTF=function(t,n){var r={basename:T.basename(t),isGLB:!1},i=tt.write(n,r),u=i.json,e=i.resources,s=this.fs,o=this.path,h=o.dirname(t);s.writeFileSync(t,JSON.stringify(u,null,2)),Object.keys(e).forEach(function(t){var n=Buffer.from(e[t]);s.writeFileSync(o.join(h,t),n)})},r.writeGLB=function(t,n){var r=Buffer.from(this.packGLB(n));this.fs.writeFileSync(t,r)},n}(rt),ut=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}(rt);t.Accessor=l,t.Animation=w,t.AnimationChannel=p,t.AnimationSampler=A,t.Buffer=y,t.BufferUtils=E,t.Camera=b,t.Document=$,t.Extension=Y,t.ExtensionProperty=m,t.FileUtils=T,t.Graph=h,t.ImageUtils=g,t.Logger=x,t.Material=B,t.Mesh=P,t.Node=G,t.NodeIO=it,t.Primitive=V,t.PrimitiveTarget=D,t.Property=a,t.ReaderContext=q,t.Root=F,t.Scene=J,t.Skin=z,t.Texture=I,t.TextureInfo=_,t.TextureSampler=O,t.WebIO=ut,t.WriterContext=Z,t.uuid=U}); | ||
//# sourceMappingURL=core.umd.js.map |
@@ -0,1 +1,2 @@ | ||
import { Extension, ExtensionConstructor } from './extension'; | ||
import { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, Material, Mesh, Node, Primitive, PrimitiveTarget, PropertyGraph, Root, Scene, Skin, Texture } from './properties/index'; | ||
@@ -99,2 +100,10 @@ import { Logger } from './utils'; | ||
/********************************************************************************************** | ||
* Extension factory method. | ||
*/ | ||
/** | ||
* Creates a new {@link Extension}, for the extension type of the given constructor. If the | ||
* extension is already enabled for this Document, the previous Extension reference is reused. | ||
*/ | ||
createExtension(ctor: ExtensionConstructor): Extension; | ||
/********************************************************************************************** | ||
* Property factory methods. | ||
@@ -101,0 +110,0 @@ */ |
export { NodeIO, WebIO } from './io'; | ||
export { NativeDocument as Asset } from '../native-document'; | ||
export { ReaderOptions } from './reader'; | ||
export { WriterOptions } from './writer'; | ||
export { ReaderContext } from './reader-context'; | ||
export { WriterContext } from './writer-context'; |
import { Document } from '../document'; | ||
import { Extension } from '../extension'; | ||
import { NativeDocument } from '../native-document'; | ||
@@ -14,2 +15,5 @@ import { WriterOptions } from './writer'; | ||
declare abstract class PlatformIO { | ||
protected _extensions: typeof Extension[]; | ||
/** Registers extensions, enabling I/O class to read and write glTF assets requiring them. */ | ||
registerExtensions(extensions: typeof Extension[]): this; | ||
/** Converts glTF-formatted JSON and a resource map to a {@link Document}. */ | ||
@@ -16,0 +20,0 @@ createDocument(nativeDoc: NativeDocument): Document; |
import { Document } from '../document'; | ||
import { Extension } from '../extension'; | ||
import { NativeDocument } from '../native-document'; | ||
export interface ReaderOptions { | ||
extensions: (typeof Extension)[]; | ||
} | ||
/** @hidden */ | ||
export declare class GLTFReader { | ||
static read(nativeDoc: NativeDocument): Document; | ||
static read(nativeDoc: NativeDocument, options: ReaderOptions): Document; | ||
} |
import { TypedArray } from '../constants'; | ||
import { Buffer } from './buffer'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
/** | ||
@@ -79,3 +79,3 @@ * # Accessor | ||
*/ | ||
export declare class Accessor extends Property { | ||
export declare class Accessor extends ExtensibleProperty { | ||
readonly propertyType = "Accessor"; | ||
@@ -82,0 +82,0 @@ /** Raw data of the accessor. */ |
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
@@ -40,3 +41,3 @@ import { Property } from './property'; | ||
*/ | ||
export declare class Animation extends Property { | ||
export declare class Animation extends ExtensibleProperty { | ||
readonly propertyType = "Animation"; | ||
@@ -43,0 +44,0 @@ private channels; |
@@ -1,2 +0,2 @@ | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
/** | ||
@@ -57,3 +57,3 @@ * # Buffer | ||
*/ | ||
export declare class Buffer extends Property { | ||
export declare class Buffer extends ExtensibleProperty { | ||
readonly propertyType = "Buffer"; | ||
@@ -60,0 +60,0 @@ /** URI (or filename) of the buffer. */ |
@@ -1,2 +0,2 @@ | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
/** | ||
@@ -30,3 +30,3 @@ * # Camera | ||
*/ | ||
export declare class Camera extends Property { | ||
export declare class Camera extends ExtensibleProperty { | ||
readonly propertyType = "Camera"; | ||
@@ -33,0 +33,0 @@ private _type; |
@@ -5,2 +5,3 @@ export * from './accessor'; | ||
export * from './camera'; | ||
export * from './extension-property'; | ||
export * from './property'; | ||
@@ -7,0 +8,0 @@ export * from './property-graph'; |
import { vec3, vec4 } from '../constants'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Texture, TextureInfo, TextureSampler } from './texture'; | ||
@@ -36,3 +36,3 @@ /** | ||
*/ | ||
export declare class Material extends Property { | ||
export declare class Material extends ExtensibleProperty { | ||
readonly propertyType = "Material"; | ||
@@ -39,0 +39,0 @@ /** Mode of the material's alpha channels. (`OPAQUE`, `BLEND`, or `MASK`) */ |
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Material } from './material'; | ||
@@ -37,3 +38,3 @@ import { Property } from './property'; | ||
*/ | ||
export declare class Mesh extends Property { | ||
export declare class Mesh extends ExtensibleProperty { | ||
readonly propertyType = "Mesh"; | ||
@@ -40,0 +41,0 @@ private _weights; |
import { vec3, vec4 } from '../constants'; | ||
import { Camera } from './camera'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Mesh } from './mesh'; | ||
import { Property } from './property'; | ||
import { Skin } from './skin'; | ||
@@ -34,3 +34,3 @@ /** | ||
*/ | ||
export declare class Node extends Property { | ||
export declare class Node extends ExtensibleProperty { | ||
readonly propertyType = "Node"; | ||
@@ -37,0 +37,0 @@ private _translation; |
@@ -40,9 +40,11 @@ import { GraphNode } from '../graph'; | ||
/** Property type. */ | ||
readonly propertyType: string; | ||
abstract readonly propertyType: string; | ||
protected readonly _graph: PropertyGraph; | ||
protected _name: string; | ||
protected _extras: object; | ||
protected _extensions: object; | ||
/** @hidden */ | ||
constructor(graph: PropertyGraph, name?: string); | ||
/********************************************************************************************** | ||
* Name. | ||
*/ | ||
/** | ||
@@ -60,2 +62,5 @@ * Returns the name of this property. While names are not required to be unique, this is | ||
setName(name: string): this; | ||
/********************************************************************************************** | ||
* Extras. | ||
*/ | ||
/** @hidden */ | ||
@@ -65,6 +70,5 @@ getExtras(): object; | ||
setExtras(extras: object): this; | ||
/** @hidden */ | ||
getExtensions(): object; | ||
/** @hidden */ | ||
setExtensions(extensions: object): this; | ||
/********************************************************************************************** | ||
* Graph state. | ||
*/ | ||
/** | ||
@@ -71,0 +75,0 @@ * Makes a copy of this property, referencing the same resources (not copies) as the original. |
@@ -0,1 +1,2 @@ | ||
import { Extension } from '../extension'; | ||
import { Accessor } from './accessor'; | ||
@@ -47,2 +48,3 @@ import { Animation } from './animation'; | ||
private readonly _asset; | ||
private readonly _extensions; | ||
private scenes; | ||
@@ -66,2 +68,13 @@ private nodes; | ||
/********************************************************************************************** | ||
* Extensions. | ||
*/ | ||
/** Lists all {@link Extension} properties enabled for this root. */ | ||
listExtensionsUsed(): Extension[]; | ||
/** Lists all {@link Extension} properties enabled and required for this root. */ | ||
listExtensionsRequired(): Extension[]; | ||
/** @hidden */ | ||
_enableExtension(extension: Extension): this; | ||
/** @hidden */ | ||
_disableExtension(extension: Extension): this; | ||
/********************************************************************************************** | ||
* Scenes. | ||
@@ -73,8 +86,3 @@ */ | ||
*/ | ||
addScene(scene: Scene): this; | ||
/** | ||
* Removes a {@link Scene} from the root list. | ||
* @hidden | ||
*/ | ||
removeScene(scene: Scene): this; | ||
_addScene(scene: Scene): this; | ||
/** Lists all {@link Scene} properties associated with this root. */ | ||
@@ -89,8 +97,3 @@ listScenes(): Scene[]; | ||
*/ | ||
addNode(node: Node): this; | ||
/** | ||
* Removes a {@link Node} from the root list. | ||
* @hidden | ||
*/ | ||
removeNode(node: Node): this; | ||
_addNode(node: Node): this; | ||
/** Lists all {@link Node} properties associated with this root. */ | ||
@@ -105,8 +108,3 @@ listNodes(): Node[]; | ||
*/ | ||
addCamera(camera: Camera): this; | ||
/** | ||
* Removes a {@link Camera} from the root list. | ||
* @hidden | ||
*/ | ||
removeCamera(camera: Camera): this; | ||
_addCamera(camera: Camera): this; | ||
/** Lists all {@link Camera} properties associated with this root. */ | ||
@@ -121,8 +119,3 @@ listCameras(): Camera[]; | ||
*/ | ||
addSkin(skin: Skin): this; | ||
/** | ||
* Removes a {@link Skin} from the root list. | ||
* @hidden | ||
*/ | ||
removeSkin(skin: Skin): this; | ||
_addSkin(skin: Skin): this; | ||
/** Lists all {@link Skin} properties associated with this root. */ | ||
@@ -137,8 +130,3 @@ listSkins(): Skin[]; | ||
*/ | ||
addMesh(mesh: Mesh): this; | ||
/** | ||
* Removes a {@link Mesh} from the root list. | ||
* @hidden | ||
*/ | ||
removeMesh(mesh: Mesh): this; | ||
_addMesh(mesh: Mesh): this; | ||
/** Lists all {@link Mesh} properties associated with this root. */ | ||
@@ -153,8 +141,3 @@ listMeshes(): Mesh[]; | ||
*/ | ||
addMaterial(material: Material): this; | ||
/** | ||
* Removes a {@link Material} from the root list. | ||
* @hidden | ||
*/ | ||
removeMaterial(material: Material): this; | ||
_addMaterial(material: Material): this; | ||
/** Lists all {@link Material} properties associated with this root. */ | ||
@@ -169,8 +152,3 @@ listMaterials(): Material[]; | ||
*/ | ||
addTexture(texture: Texture): this; | ||
/** | ||
* Removes a {@link Texture} from the root list. | ||
* @hidden | ||
*/ | ||
removeTexture(texture: Texture): this; | ||
_addTexture(texture: Texture): this; | ||
/** Lists all {@link Texture} properties associated with this root. */ | ||
@@ -185,8 +163,3 @@ listTextures(): Texture[]; | ||
*/ | ||
addAnimation(animation: Animation): this; | ||
/** | ||
* Removes a {@link Animation} from the root list. | ||
* @hidden | ||
*/ | ||
removeAnimation(animation: Animation): this; | ||
_addAnimation(animation: Animation): this; | ||
/** Lists all {@link Animation} properties associated with this root. */ | ||
@@ -201,8 +174,3 @@ listAnimations(): Animation[]; | ||
*/ | ||
addAccessor(accessor: Accessor): this; | ||
/** | ||
* Removes an {@link Accessor} from the root list. | ||
* @hidden | ||
*/ | ||
removeAccessor(accessor: Accessor): this; | ||
_addAccessor(accessor: Accessor): this; | ||
/** Lists all {@link Accessor} properties associated with this root. */ | ||
@@ -217,10 +185,5 @@ listAccessors(): Accessor[]; | ||
*/ | ||
addBuffer(buffer: Buffer): this; | ||
/** | ||
* Removes a {@link Buffer} from the root list. | ||
* @hidden | ||
*/ | ||
removeBuffer(buffer: Buffer): this; | ||
_addBuffer(buffer: Buffer): this; | ||
/** Lists all {@link Buffer} properties associated with this root. */ | ||
listBuffers(): Buffer[]; | ||
} |
@@ -0,3 +1,3 @@ | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
import { Property } from './property'; | ||
/** | ||
@@ -19,3 +19,3 @@ * # Scene | ||
*/ | ||
export declare class Scene extends Property { | ||
export declare class Scene extends ExtensibleProperty { | ||
readonly propertyType = "Scene"; | ||
@@ -22,0 +22,0 @@ private nodes; |
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
import { Property } from './property'; | ||
/** | ||
@@ -15,3 +15,3 @@ * # Skin | ||
*/ | ||
export declare class Skin extends Property { | ||
export declare class Skin extends ExtensibleProperty { | ||
readonly propertyType = "Skin"; | ||
@@ -18,0 +18,0 @@ private skeleton; |
import { vec2 } from '../constants'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
/** | ||
@@ -24,3 +24,3 @@ * # Texture | ||
*/ | ||
export declare class Texture extends Property { | ||
export declare class Texture extends ExtensibleProperty { | ||
readonly propertyType = "Texture"; | ||
@@ -27,0 +27,0 @@ /** Raw image data for this texture. */ |
{ | ||
"name": "@gltf-transform/core", | ||
"version": "0.3.3", | ||
"version": "0.4.0-alpha.0", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -38,3 +38,3 @@ "description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js", | ||
}, | ||
"gitHead": "dc590cd720a6a40ace781edf1b68262b0c0ab674" | ||
"gitHead": "b06dc5b509890c0712850fca6b17a68df3749066" | ||
} |
@@ -74,8 +74,1 @@ // Injected at compile time, from $npm_package_version. | ||
export type TypedArray = Float32Array | Uint32Array | Uint16Array | Uint8Array | Int16Array | Int8Array; | ||
/** @hidden */ | ||
export class NotImplementedError extends Error { | ||
constructor () { | ||
super('@gltf-transform/core: Not implemented.'); | ||
} | ||
} |
export { Document, Transform } from './document'; | ||
export { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, Property, Material, Mesh, Node, Primitive, PrimitiveTarget, Root, Scene, Skin, Texture, TextureInfo, TextureSampler } from './properties'; | ||
export { Extension } from './extension'; | ||
export { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, ExtensionProperty, Property, Material, Mesh, Node, Primitive, PrimitiveTarget, Root, Scene, Skin, Texture, TextureInfo, TextureSampler } from './properties'; | ||
export { Graph } from './graph/'; | ||
export { NodeIO, WebIO } from './io/'; | ||
export { NodeIO, WebIO, ReaderContext, WriterContext } from './io/'; | ||
export { BufferUtils, FileUtils, ImageUtils, Logger, uuid } from './utils/'; | ||
@@ -13,3 +14,6 @@ | ||
/** [[include:EXTENSIONS.md]] */ | ||
namespace Extensions {}; | ||
/** [[include:CONTRIBUTING.md]] */ | ||
namespace Contributing {}; |
@@ -0,1 +1,2 @@ | ||
import { Extension, ExtensionConstructor } from './extension'; | ||
import { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, Material, Mesh, Node, Primitive, PrimitiveTarget, PropertyGraph, Root, Scene, Skin, Texture } from './properties/index'; | ||
@@ -124,2 +125,16 @@ import { Logger } from './utils'; | ||
/********************************************************************************************** | ||
* Extension factory method. | ||
*/ | ||
/** | ||
* Creates a new {@link Extension}, for the extension type of the given constructor. If the | ||
* extension is already enabled for this Document, the previous Extension reference is reused. | ||
*/ | ||
createExtension(ctor: ExtensionConstructor): Extension { | ||
const prevExtension = this.getRoot().listExtensionsUsed() | ||
.find((ext) => ext.extensionName === ctor.EXTENSION_NAME); | ||
return prevExtension || new ctor(this); | ||
} | ||
/********************************************************************************************** | ||
* Property factory methods. | ||
@@ -131,3 +146,3 @@ */ | ||
const scene = new Scene(this.graph, name); | ||
this.root.addScene(scene); | ||
this.root._addScene(scene); | ||
return scene; | ||
@@ -139,3 +154,3 @@ } | ||
const node = new Node(this.graph, name); | ||
this.root.addNode(node); | ||
this.root._addNode(node); | ||
return node; | ||
@@ -147,3 +162,3 @@ } | ||
const camera = new Camera(this.graph, name); | ||
this.root.addCamera(camera); | ||
this.root._addCamera(camera); | ||
return camera; | ||
@@ -155,3 +170,3 @@ } | ||
const skin = new Skin(this.graph, name); | ||
this.root.addSkin(skin); | ||
this.root._addSkin(skin); | ||
return skin; | ||
@@ -163,3 +178,3 @@ } | ||
const mesh = new Mesh(this.graph, name); | ||
this.root.addMesh(mesh); | ||
this.root._addMesh(mesh); | ||
return mesh; | ||
@@ -187,3 +202,3 @@ } | ||
const material = new Material(this.graph, name); | ||
this.root.addMaterial(material); | ||
this.root._addMaterial(material); | ||
return material; | ||
@@ -195,3 +210,3 @@ } | ||
const texture = new Texture(this.graph, name); | ||
this.root.addTexture(texture); | ||
this.root._addTexture(texture); | ||
return texture; | ||
@@ -203,3 +218,3 @@ } | ||
const animation = new Animation(this.graph, name); | ||
this.root.addAnimation(animation); | ||
this.root._addAnimation(animation); | ||
return animation; | ||
@@ -230,3 +245,3 @@ } | ||
const accessor = new Accessor(this.graph, name).setBuffer(buffer); | ||
this.root.addAccessor(accessor); | ||
this.root._addAccessor(accessor); | ||
return accessor; | ||
@@ -238,5 +253,5 @@ } | ||
const buffer = new Buffer(this.graph, name); | ||
this.root.addBuffer(buffer); | ||
this.root._addBuffer(buffer); | ||
return buffer; | ||
} | ||
} |
export { NodeIO, WebIO } from './io'; | ||
export { NativeDocument as Asset } from '../native-document'; | ||
export { ReaderOptions } from './reader'; | ||
export { WriterOptions } from './writer'; | ||
export { ReaderContext } from './reader-context'; | ||
export { WriterContext } from './writer-context'; |
import { GLB_BUFFER } from '../constants'; | ||
import { Document } from '../document'; | ||
import { Extension } from '../extension'; | ||
import { NativeDocument } from '../native-document'; | ||
@@ -18,5 +19,14 @@ import { BufferUtils, FileUtils, uuid } from '../utils/'; | ||
abstract class PlatformIO { | ||
protected _extensions: typeof Extension[] = []; | ||
/** Registers extensions, enabling I/O class to read and write glTF assets requiring them. */ | ||
public registerExtensions(extensions: typeof Extension[]): this { | ||
this._extensions.push(...extensions); | ||
return this; | ||
} | ||
/** Converts glTF-formatted JSON and a resource map to a {@link Document}. */ | ||
public createDocument (nativeDoc: NativeDocument): Document { | ||
return GLTFReader.read(nativeDoc); | ||
return GLTFReader.read(nativeDoc, {extensions: this._extensions}); | ||
} | ||
@@ -161,3 +171,3 @@ | ||
}) | ||
return GLTFReader.read(nativeDoc); | ||
return GLTFReader.read(nativeDoc, {extensions: this._extensions}); | ||
} | ||
@@ -164,0 +174,0 @@ |
import { getRotation, getScaling, getTranslation } from 'gl-matrix/mat4' | ||
import { GLB_BUFFER, TypedArray, vec3, vec4 } from '../constants'; | ||
import { Document } from '../document'; | ||
import { Extension, ExtensionConstructor } from '../extension'; | ||
import { NativeDocument } from '../native-document'; | ||
import { Accessor, TextureInfo, TextureSampler } from '../properties'; | ||
import { FileUtils } from '../utils'; | ||
import { ReaderContext } from './reader-context'; | ||
@@ -17,5 +19,9 @@ const ComponentTypeToTypedArray = { | ||
export interface ReaderOptions { | ||
extensions: (typeof Extension)[]; | ||
} | ||
/** @hidden */ | ||
export class GLTFReader { | ||
public static read(nativeDoc: NativeDocument): Document { | ||
public static read(nativeDoc: NativeDocument, options: ReaderOptions): Document { | ||
const {json} = nativeDoc; | ||
@@ -28,6 +34,10 @@ const doc = new Document(); | ||
/* Reader context. */ | ||
const context = new ReaderContext(nativeDoc); | ||
/** Buffers. */ | ||
const bufferDefs = json.buffers || []; | ||
const buffers = bufferDefs.map((bufferDef) => { | ||
context.buffers = bufferDefs.map((bufferDef) => { | ||
const buffer = doc.createBuffer(bufferDef.name); | ||
@@ -43,4 +53,4 @@ if (bufferDef.uri && bufferDef.uri.indexOf('__') !== 0) { | ||
const bufferViewDefs = json.bufferViews || []; | ||
const bufferViewToBuffer = bufferViewDefs.map((bufferViewDef) => { | ||
return buffers[bufferViewDef.buffer]; | ||
context.bufferViewBuffers = bufferViewDefs.map((bufferViewDef) => { | ||
return context.buffers[bufferViewDef.buffer]; | ||
}); | ||
@@ -52,4 +62,4 @@ | ||
const accessorDefs = json.accessors || []; | ||
const accessors = accessorDefs.map((accessorDef) => { | ||
const buffer = bufferViewToBuffer[accessorDef.bufferView]; | ||
context.accessors = accessorDefs.map((accessorDef) => { | ||
const buffer = context.bufferViewBuffers[accessorDef.bufferView]; | ||
const accessor = doc.createAccessor(accessorDef.name, buffer); | ||
@@ -82,3 +92,3 @@ accessor.setType(accessorDef.type); | ||
const textureDefs = json.textures || []; | ||
const textures = imageDefs.map((imageDef) => { | ||
context.textures = imageDefs.map((imageDef) => { | ||
const texture = doc.createTexture(imageDef.name); | ||
@@ -116,3 +126,3 @@ | ||
const materialDefs = json.materials || []; | ||
const materials = materialDefs.map((materialDef) => { | ||
context.materials = materialDefs.map((materialDef) => { | ||
const material = doc.createMaterial(materialDef.name); | ||
@@ -158,3 +168,3 @@ | ||
const textureInfoDef = pbrDef.baseColorTexture; | ||
const texture = textures[textureDefs[textureInfoDef.index].source]; | ||
const texture = context.textures[textureDefs[textureInfoDef.index].source]; | ||
material.setBaseColorTexture(texture); | ||
@@ -167,3 +177,3 @@ setTextureInfo(material.getBaseColorTextureInfo(), textureInfoDef); | ||
const textureInfoDef = materialDef.emissiveTexture; | ||
const texture = textures[textureDefs[textureInfoDef.index].source]; | ||
const texture = context.textures[textureDefs[textureInfoDef.index].source]; | ||
material.setEmissiveTexture(texture); | ||
@@ -176,3 +186,3 @@ setTextureInfo(material.getEmissiveTextureInfo(), textureInfoDef); | ||
const textureInfoDef = materialDef.normalTexture; | ||
const texture = textures[textureDefs[textureInfoDef.index].source]; | ||
const texture = context.textures[textureDefs[textureInfoDef.index].source]; | ||
material.setNormalTexture(texture); | ||
@@ -188,3 +198,3 @@ setTextureInfo(material.getNormalTextureInfo(), textureInfoDef); | ||
const textureInfoDef = materialDef.occlusionTexture; | ||
const texture = textures[textureDefs[textureInfoDef.index].source]; | ||
const texture = context.textures[textureDefs[textureInfoDef.index].source]; | ||
material.setOcclusionTexture(texture); | ||
@@ -200,3 +210,3 @@ setTextureInfo(material.getOcclusionTextureInfo(), textureInfoDef); | ||
const textureInfoDef = pbrDef.metallicRoughnessTexture; | ||
const texture = textures[textureDefs[textureInfoDef.index].source]; | ||
const texture = context.textures[textureDefs[textureInfoDef.index].source]; | ||
material.setMetallicRoughnessTexture(texture); | ||
@@ -213,3 +223,3 @@ setTextureInfo(material.getMetallicRoughnessTextureInfo(), textureInfoDef); | ||
const meshDefs = json.meshes || []; | ||
const meshes = meshDefs.map((meshDef) => { | ||
context.meshes = meshDefs.map((meshDef) => { | ||
const mesh = doc.createMesh(meshDef.name); | ||
@@ -225,3 +235,3 @@ | ||
if (primitiveDef.material !== undefined) { | ||
primitive.setMaterial(materials[primitiveDef.material]); | ||
primitive.setMaterial(context.materials[primitiveDef.material]); | ||
} | ||
@@ -234,7 +244,7 @@ | ||
for (const [semantic, index] of Object.entries(primitiveDef.attributes || {})) { | ||
primitive.setAttribute(semantic, accessors[index]); | ||
primitive.setAttribute(semantic, context.accessors[index]); | ||
} | ||
if (primitiveDef.indices !== undefined) { | ||
primitive.setIndices(accessors[primitiveDef.indices]); | ||
primitive.setIndices(context.accessors[primitiveDef.indices]); | ||
} | ||
@@ -249,3 +259,3 @@ | ||
for (const [semantic, accessorIndex] of Object.entries(targetDef)) { | ||
target.setAttribute(semantic, accessors[accessorIndex]); | ||
target.setAttribute(semantic, context.accessors[accessorIndex]); | ||
} | ||
@@ -265,3 +275,3 @@ | ||
const cameraDefs = json.cameras || []; | ||
const cameras = cameraDefs.map((cameraDef) => { | ||
context.cameras = cameraDefs.map((cameraDef) => { | ||
const camera = doc.createCamera(cameraDef.name).setType(cameraDef.type); | ||
@@ -287,3 +297,3 @@ if (cameraDef.type === GLTF.CameraType.PERSPECTIVE) { | ||
const nodeDefs = json.nodes || []; | ||
const nodes = nodeDefs.map((nodeDef) => { | ||
context.nodes = nodeDefs.map((nodeDef) => { | ||
const node = doc.createNode(nodeDef.name); | ||
@@ -321,15 +331,15 @@ | ||
const skinDefs = json.skins || []; | ||
const skins = skinDefs.map((skinDef) => { | ||
context.skins = skinDefs.map((skinDef) => { | ||
const skin = doc.createSkin(skinDef.name); | ||
if (skinDef.inverseBindMatrices !== undefined) { | ||
skin.setInverseBindMatrices(accessors[skinDef.inverseBindMatrices]); | ||
skin.setInverseBindMatrices(context.accessors[skinDef.inverseBindMatrices]); | ||
} | ||
if (skinDef.skeleton !== undefined) { | ||
skin.setSkeleton(nodes[skinDef.skeleton]); | ||
skin.setSkeleton(context.nodes[skinDef.skeleton]); | ||
} | ||
for (const nodeIndex of skinDef.joints) { | ||
skin.addJoint(nodes[nodeIndex]); | ||
skin.addJoint(context.nodes[nodeIndex]); | ||
} | ||
@@ -343,12 +353,12 @@ | ||
nodeDefs.map((nodeDef, nodeIndex) => { | ||
const node = nodes[nodeIndex]; | ||
const node = context.nodes[nodeIndex]; | ||
const children = nodeDef.children || []; | ||
children.forEach((childIndex) => node.addChild(nodes[childIndex])); | ||
children.forEach((childIndex) => node.addChild(context.nodes[childIndex])); | ||
if (nodeDef.mesh !== undefined) node.setMesh(meshes[nodeDef.mesh]); | ||
if (nodeDef.mesh !== undefined) node.setMesh(context.meshes[nodeDef.mesh]); | ||
if (nodeDef.camera !== undefined) node.setCamera(cameras[nodeDef.camera]); | ||
if (nodeDef.camera !== undefined) node.setCamera(context.cameras[nodeDef.camera]); | ||
if (nodeDef.skin !== undefined) node.setSkin(skins[nodeDef.skin]); | ||
if (nodeDef.skin !== undefined) node.setSkin(context.skins[nodeDef.skin]); | ||
}) | ||
@@ -359,3 +369,3 @@ | ||
const animationDefs = json.animations || []; | ||
const animations = animationDefs.map((animationDef) => { | ||
context.animations = animationDefs.map((animationDef) => { | ||
const animation = doc.createAnimation(animationDef.name); | ||
@@ -366,4 +376,4 @@ | ||
const sampler = doc.createAnimationSampler() | ||
.setInput(accessors[samplerDef.input]) | ||
.setOutput(accessors[samplerDef.output]) | ||
.setInput(context.accessors[samplerDef.input]) | ||
.setOutput(context.accessors[samplerDef.output]) | ||
.setInterpolation(samplerDef.interpolation || GLTF.AnimationSamplerInterpolation.LINEAR); | ||
@@ -378,3 +388,3 @@ animation.addSampler(sampler); | ||
.setSampler(samplers[channelDef.sampler]) | ||
.setTargetNode(nodes[channelDef.target.node]) | ||
.setTargetNode(context.nodes[channelDef.target.node]) | ||
.setTargetPath(channelDef.target.path); | ||
@@ -390,3 +400,3 @@ animation.addChannel(channel); | ||
const sceneDefs = json.scenes || []; | ||
const scenes = sceneDefs.map((sceneDef) => { | ||
context.scenes = sceneDefs.map((sceneDef) => { | ||
const scene = doc.createScene(sceneDef.name); | ||
@@ -397,3 +407,3 @@ | ||
children | ||
.map((nodeIndex) => nodes[nodeIndex]) | ||
.map((nodeIndex) => context.nodes[nodeIndex]) | ||
.forEach((node) => (scene.addNode(node))); | ||
@@ -404,2 +414,14 @@ | ||
/** Extensions. */ | ||
const extensionsUsed = json.extensionsUsed || []; | ||
const extensionsRequired = json.extensionsRequired || []; | ||
for (const Extension of options.extensions) { | ||
if (extensionsUsed.includes(Extension.EXTENSION_NAME)) { | ||
doc.createExtension(Extension as ExtensionConstructor) | ||
.setRequired(extensionsRequired.includes(Extension.EXTENSION_NAME)) | ||
.read(context); | ||
} | ||
} | ||
return doc; | ||
@@ -406,0 +428,0 @@ } |
@@ -5,7 +5,6 @@ import { GLB_BUFFER, NAME } from '../constants'; | ||
import { NativeDocument } from '../native-document'; | ||
import { Accessor, AnimationSampler, AttributeLink, Buffer, Camera, IndexLink, Material, Mesh, Node, Primitive, Property, Root, Skin, Texture, TextureInfo, TextureSampler } from '../properties'; | ||
import { Accessor, AnimationSampler, AttributeLink, Buffer, IndexLink, Primitive, Property, Root, Texture } from '../properties'; | ||
import { BufferUtils } from '../utils'; | ||
import { WriterContext } from './writer-context'; | ||
type PropertyDef = GLTF.IScene | GLTF.INode | GLTF.IMaterial | GLTF.ISkin | GLTF.ITexture; | ||
const BufferViewTarget = { | ||
@@ -35,16 +34,6 @@ ARRAY_BUFFER: 34962, | ||
/* Lookup tables. */ | ||
/* Writer context. */ | ||
const accessorIndexMap = new Map<Accessor, number>(); | ||
const cameraIndexMap = new Map<Camera, number>(); | ||
const skinIndexMap = new Map<Skin, number>(); | ||
const materialIndexMap = new Map<Material, number>(); | ||
const meshIndexMap = new Map<Mesh, number>(); | ||
const nodeIndexMap = new Map<Node, number>(); | ||
const imageIndexMap = new Map<Texture, number>(); | ||
const textureIndexMap = new Map<string, number>(); // textureDef JSON -> index | ||
const samplerIndexMap = new Map<string, number>(); // samplerDef JSON -> index | ||
const context = new WriterContext(nativeDoc); | ||
const imageData: ArrayBuffer[] = []; | ||
/* Utilities. */ | ||
@@ -72,3 +61,3 @@ | ||
for (const accessor of accessors) { | ||
const accessorDef = createAccessorDef(accessor); | ||
const accessorDef = context.createAccessorDef(accessor); | ||
accessorDef.bufferView = json.bufferViews.length; | ||
@@ -82,3 +71,3 @@ // TODO(feat): accessorDef.sparse | ||
accessorIndexMap.set(accessor, json.accessors.length); | ||
context.accessorIndexMap.set(accessor, json.accessors.length); | ||
json.accessors.push(accessorDef); | ||
@@ -118,3 +107,3 @@ } | ||
for (const accessor of accessors) { | ||
const accessorDef = createAccessorDef(accessor); | ||
const accessorDef = context.createAccessorDef(accessor); | ||
accessorDef.bufferView = json.bufferViews.length; | ||
@@ -127,3 +116,3 @@ accessorDef.byteOffset = byteStride; | ||
accessorIndexMap.set(accessor, json.accessors.length); | ||
context.accessorIndexMap.set(accessor, json.accessors.length); | ||
json.accessors.push(accessorDef); | ||
@@ -188,37 +177,2 @@ } | ||
/** | ||
* Creates a TextureInfo definition, and any Texture or Sampler definitions it requires. If | ||
* possible, Texture and Sampler definitions are shared. | ||
*/ | ||
function createTextureInfoDef(texture: Texture, textureInfo: TextureInfo, textureSampler: TextureSampler): GLTF.ITextureInfo { | ||
const samplerDef = { | ||
magFilter: textureSampler.getMagFilter() || undefined, | ||
minFilter: textureSampler.getMinFilter() || undefined, | ||
wrapS: textureSampler.getWrapS(), | ||
wrapT: textureSampler.getWrapT(), | ||
} as GLTF.ISampler; | ||
const samplerKey = JSON.stringify(samplerDef); | ||
if (!samplerIndexMap.has(samplerKey)) { | ||
samplerIndexMap.set(samplerKey, json.samplers.length); | ||
json.samplers.push(samplerDef); | ||
} | ||
const textureDef = { | ||
source: imageIndexMap.get(texture), | ||
sampler: samplerIndexMap.get(samplerKey) | ||
} as GLTF.ITexture; | ||
const textureKey = JSON.stringify(textureDef); | ||
if (!textureIndexMap.has(textureKey)) { | ||
textureIndexMap.set(textureKey, json.textures.length); | ||
json.textures.push(textureDef); | ||
} | ||
return { | ||
index: textureIndexMap.get(textureKey), | ||
texCoord: textureInfo.getTexCoord(), | ||
} as GLTF.ITextureInfo; | ||
} | ||
/* Data use pre-processing. */ | ||
@@ -252,3 +206,3 @@ | ||
json.images = root.listTextures().map((texture, textureIndex) => { | ||
const imageDef = createPropertyDef(texture) as GLTF.IImage; | ||
const imageDef = context.createPropertyDef(texture) as GLTF.IImage; | ||
@@ -260,3 +214,3 @@ if (texture.getMimeType()) { | ||
if (options.isGLB) { | ||
imageData.push(texture.getImage()); | ||
context.imageData.push(texture.getImage()); | ||
imageDef.bufferView = json.bufferViews.length; | ||
@@ -274,3 +228,3 @@ json.bufferViews.push({ | ||
imageIndexMap.set(texture, textureIndex); | ||
context.imageIndexMap.set(texture, textureIndex); | ||
return imageDef; | ||
@@ -283,3 +237,3 @@ }); | ||
root.listBuffers().forEach((buffer) => { | ||
const bufferDef = createPropertyDef(buffer) as GLTF.IBuffer; | ||
const bufferDef = context.createPropertyDef(buffer) as GLTF.IBuffer; | ||
@@ -362,7 +316,7 @@ // Attributes are grouped and interleaved in one buffer view per mesh primitive. Indices for | ||
// We only support embedded images in GLB, so we know there is only one buffer. | ||
if (imageData.length) { | ||
for (let i = 0; i < imageData.length; i++) { | ||
if (context.imageData.length) { | ||
for (let i = 0; i < context.imageData.length; i++) { | ||
json.bufferViews[json.images[i].bufferView].byteOffset = bufferByteLength; | ||
bufferByteLength += imageData[i].byteLength; | ||
buffers.push(imageData[i]); | ||
bufferByteLength += context.imageData[i].byteLength; | ||
buffers.push(context.imageData[i]); | ||
} | ||
@@ -397,3 +351,3 @@ } | ||
json.materials = root.listMaterials().map((material, index) => { | ||
const materialDef = createPropertyDef(material) as GLTF.IMaterial; | ||
const materialDef = context.createPropertyDef(material) as GLTF.IMaterial; | ||
@@ -422,3 +376,3 @@ // Program state & blending. | ||
const textureSampler = material.getBaseColorTextureSampler(); | ||
materialDef.pbrMetallicRoughness.baseColorTexture = createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.pbrMetallicRoughness.baseColorTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
} | ||
@@ -430,3 +384,3 @@ | ||
const textureSampler = material.getEmissiveTextureSampler(); | ||
materialDef.emissiveTexture = createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.emissiveTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
} | ||
@@ -438,3 +392,3 @@ | ||
const textureSampler = material.getNormalTextureSampler(); | ||
const textureInfoDef = createTextureInfoDef(texture, textureInfo, textureSampler) as GLTF.IMaterialNormalTextureInfo; | ||
const textureInfoDef = context.createTextureInfoDef(texture, textureInfo, textureSampler) as GLTF.IMaterialNormalTextureInfo; | ||
if (material.getNormalScale() !== 1) { | ||
@@ -450,3 +404,3 @@ textureInfoDef.scale = material.getNormalScale(); | ||
const textureSampler = material.getOcclusionTextureSampler(); | ||
const textureInfoDef = createTextureInfoDef(texture, textureInfo, textureSampler) as GLTF.IMaterialOcclusionTextureInfo; | ||
const textureInfoDef = context.createTextureInfoDef(texture, textureInfo, textureSampler) as GLTF.IMaterialOcclusionTextureInfo; | ||
if (material.getOcclusionStrength() !== 1) { | ||
@@ -462,6 +416,6 @@ textureInfoDef.strength = material.getOcclusionStrength(); | ||
const textureSampler = material.getMetallicRoughnessTextureSampler(); | ||
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
} | ||
materialIndexMap.set(material, index); | ||
context.materialIndexMap.set(material, index); | ||
return materialDef; | ||
@@ -473,3 +427,3 @@ }); | ||
json.meshes = root.listMeshes().map((mesh, index) => { | ||
const meshDef = createPropertyDef(mesh) as GLTF.IMesh; | ||
const meshDef = context.createPropertyDef(mesh) as GLTF.IMesh; | ||
@@ -480,11 +434,11 @@ let targetNames: string[]; | ||
const primitiveDef: GLTF.IMeshPrimitive = {attributes: {}}; | ||
primitiveDef.material = materialIndexMap.get(primitive.getMaterial()); | ||
primitiveDef.material = context.materialIndexMap.get(primitive.getMaterial()); | ||
primitiveDef.mode = primitive.getMode(); | ||
if (primitive.getIndices()) { | ||
primitiveDef.indices = accessorIndexMap.get(primitive.getIndices()); | ||
primitiveDef.indices = context.accessorIndexMap.get(primitive.getIndices()); | ||
} | ||
for (const semantic of primitive.listSemantics()) { | ||
primitiveDef.attributes[semantic] = accessorIndexMap.get(primitive.getAttribute(semantic)); | ||
primitiveDef.attributes[semantic] = context.accessorIndexMap.get(primitive.getAttribute(semantic)); | ||
} | ||
@@ -496,3 +450,3 @@ | ||
for (const semantic of target.listSemantics()) { | ||
targetDef[semantic] = accessorIndexMap.get(target.getAttribute(semantic)); | ||
targetDef[semantic] = context.accessorIndexMap.get(target.getAttribute(semantic)); | ||
} | ||
@@ -520,3 +474,3 @@ | ||
meshIndexMap.set(mesh, index); | ||
context.meshIndexMap.set(mesh, index); | ||
return meshDef; | ||
@@ -528,3 +482,3 @@ }); | ||
json.cameras = root.listCameras().map((camera, index) => { | ||
const cameraDef = createPropertyDef(camera) as GLTF.ICamera; | ||
const cameraDef = context.createPropertyDef(camera) as GLTF.ICamera; | ||
cameraDef.type = camera.getType(); | ||
@@ -547,3 +501,3 @@ if (cameraDef.type === GLTF.CameraType.PERSPECTIVE) { | ||
cameraIndexMap.set(camera, index); | ||
context.cameraIndexMap.set(camera, index); | ||
return cameraDef; | ||
@@ -555,3 +509,3 @@ }); | ||
json.nodes = root.listNodes().map((node, index) => { | ||
const nodeDef = createPropertyDef(node) as GLTF.INode; | ||
const nodeDef = context.createPropertyDef(node) as GLTF.INode; | ||
nodeDef.translation = node.getTranslation(); | ||
@@ -567,3 +521,3 @@ nodeDef.rotation = node.getRotation(); | ||
nodeIndexMap.set(node, index); | ||
context.nodeIndexMap.set(node, index); | ||
return nodeDef; | ||
@@ -575,15 +529,15 @@ }); | ||
json.skins = root.listSkins().map((skin, index) => { | ||
const skinDef = createPropertyDef(skin) as GLTF.ISkin; | ||
const skinDef = context.createPropertyDef(skin) as GLTF.ISkin; | ||
if (skin.getInverseBindMatrices()) { | ||
skinDef.inverseBindMatrices = accessorIndexMap.get(skin.getInverseBindMatrices()); | ||
skinDef.inverseBindMatrices = context.accessorIndexMap.get(skin.getInverseBindMatrices()); | ||
} | ||
if (skin.getSkeleton()) { | ||
skinDef.skeleton = nodeIndexMap.get(skin.getSkeleton()); | ||
skinDef.skeleton = context.nodeIndexMap.get(skin.getSkeleton()); | ||
} | ||
skinDef.joints = skin.listJoints().map((joint) => nodeIndexMap.get(joint)); | ||
skinDef.joints = skin.listJoints().map((joint) => context.nodeIndexMap.get(joint)); | ||
skinIndexMap.set(skin, index); | ||
context.skinIndexMap.set(skin, index); | ||
return skinDef; | ||
@@ -598,15 +552,15 @@ }); | ||
if (node.getMesh()) { | ||
nodeDef.mesh = meshIndexMap.get(node.getMesh()); | ||
nodeDef.mesh = context.meshIndexMap.get(node.getMesh()); | ||
} | ||
if (node.getCamera()) { | ||
nodeDef.camera = cameraIndexMap.get(node.getCamera()); | ||
nodeDef.camera = context.cameraIndexMap.get(node.getCamera()); | ||
} | ||
if (node.getSkin()) { | ||
nodeDef.skin = skinIndexMap.get(node.getSkin()); | ||
nodeDef.skin = context.skinIndexMap.get(node.getSkin()); | ||
} | ||
if (node.listChildren().length > 0) { | ||
nodeDef.children = node.listChildren().map((node) => nodeIndexMap.get(node)); | ||
nodeDef.children = node.listChildren().map((node) => context.nodeIndexMap.get(node)); | ||
} | ||
@@ -618,3 +572,3 @@ }); | ||
json.animations = root.listAnimations().map((animation) => { | ||
const animationDef = createPropertyDef(animation) as GLTF.IAnimation; | ||
const animationDef = context.createPropertyDef(animation) as GLTF.IAnimation; | ||
@@ -625,5 +579,5 @@ const samplerIndexMap: Map<AnimationSampler, number> = new Map(); | ||
.map((sampler, samplerIndex) => { | ||
const samplerDef = createPropertyDef(sampler) as GLTF.IAnimationSampler; | ||
samplerDef.input = accessorIndexMap.get(sampler.getInput()); | ||
samplerDef.output = accessorIndexMap.get(sampler.getOutput()); | ||
const samplerDef = context.createPropertyDef(sampler) as GLTF.IAnimationSampler; | ||
samplerDef.input = context.accessorIndexMap.get(sampler.getInput()); | ||
samplerDef.output = context.accessorIndexMap.get(sampler.getOutput()); | ||
samplerDef.interpolation = sampler.getInterpolation(); | ||
@@ -636,6 +590,6 @@ samplerIndexMap.set(sampler, samplerIndex); | ||
.map((channel) => { | ||
const channelDef = createPropertyDef(channel) as GLTF.IAnimationChannel; | ||
const channelDef = context.createPropertyDef(channel) as GLTF.IAnimationChannel; | ||
channelDef.sampler = samplerIndexMap.get(channel.getSampler()); | ||
channelDef.target = { | ||
node: nodeIndexMap.get(channel.getTargetNode()), | ||
node: context.nodeIndexMap.get(channel.getTargetNode()), | ||
path: channel.getTargetPath(), | ||
@@ -652,7 +606,13 @@ }; | ||
json.scenes = root.listScenes().map((scene) => { | ||
const sceneDef = createPropertyDef(scene) as GLTF.IScene; | ||
sceneDef.nodes = scene.listNodes().map((node) => nodeIndexMap.get(node)); | ||
const sceneDef = context.createPropertyDef(scene) as GLTF.IScene; | ||
sceneDef.nodes = scene.listNodes().map((node) => context.nodeIndexMap.get(node)); | ||
return sceneDef; | ||
}); | ||
/* Extensions. */ | ||
json.extensionsUsed = root.listExtensionsUsed().map((ext) => ext.extensionName); | ||
json.extensionsRequired = root.listExtensionsRequired().map((ext) => ext.extensionName); | ||
root.listExtensionsUsed().forEach((extension) => extension.write(context)); | ||
// | ||
@@ -666,27 +626,2 @@ | ||
function createPropertyDef(property: Property): PropertyDef { | ||
const def = {} as PropertyDef; | ||
if (property.getName()) { | ||
def.name = property.getName(); | ||
} | ||
if (Object.keys(property.getExtras()).length > 0) { | ||
def.extras = property.getExtras(); | ||
} | ||
if (Object.keys(property.getExtensions()).length > 0) { | ||
def.extras = property.getExtensions(); | ||
} | ||
return def; | ||
} | ||
function createAccessorDef(accessor: Accessor): GLTF.IAccessor { | ||
const accessorDef = createPropertyDef(accessor) as GLTF.IAccessor; | ||
accessorDef.type = accessor.getType(); | ||
accessorDef.componentType = accessor.getComponentType(); | ||
accessorDef.count = accessor.getCount(); | ||
accessor.getMax((accessorDef.max = [])); | ||
accessor.getMin((accessorDef.min = [])); | ||
accessorDef.normalized = accessor.getNormalized(); | ||
return accessorDef; | ||
} | ||
/** | ||
@@ -693,0 +628,0 @@ * Removes empty and null values from an object. |
import { TypedArray } from '../constants'; | ||
import { GraphChild, Link } from '../graph'; | ||
import { Buffer } from './buffer'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
@@ -81,3 +81,3 @@ /** | ||
*/ | ||
export class Accessor extends Property { | ||
export class Accessor extends ExtensibleProperty { | ||
public readonly propertyType = 'Accessor'; | ||
@@ -84,0 +84,0 @@ |
import { GraphChild, GraphChildList, Link } from '../graph'; | ||
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
@@ -42,3 +43,3 @@ import { Property } from './property'; | ||
*/ | ||
export class Animation extends Property { | ||
export class Animation extends ExtensibleProperty { | ||
public readonly propertyType = 'Animation'; | ||
@@ -45,0 +46,0 @@ @GraphChildList private channels: Link<Animation, AnimationChannel>[] = []; |
@@ -1,2 +0,2 @@ | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
@@ -58,3 +58,3 @@ /** | ||
*/ | ||
export class Buffer extends Property { | ||
export class Buffer extends ExtensibleProperty { | ||
public readonly propertyType = 'Buffer'; | ||
@@ -61,0 +61,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
@@ -31,3 +31,3 @@ /** | ||
*/ | ||
export class Camera extends Property { | ||
export class Camera extends ExtensibleProperty { | ||
public readonly propertyType = 'Camera'; | ||
@@ -34,0 +34,0 @@ |
@@ -5,2 +5,3 @@ export * from './accessor'; | ||
export * from './camera'; | ||
export * from './extension-property'; | ||
export * from './property'; | ||
@@ -7,0 +8,0 @@ export * from './property-graph'; |
import { vec3, vec4 } from '../constants'; | ||
import { GraphChild } from '../graph/index'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { TextureLink } from './property-links'; | ||
@@ -39,3 +39,3 @@ import { Texture, TextureInfo, TextureSampler } from './texture'; | ||
*/ | ||
export class Material extends Property { | ||
export class Material extends ExtensibleProperty { | ||
public readonly propertyType = 'Material'; | ||
@@ -42,0 +42,0 @@ |
import { GraphChild, GraphChildList } from '../graph/index'; | ||
import { Link } from '../graph/index'; | ||
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Material } from './material'; | ||
@@ -41,3 +42,3 @@ import { Property } from './property'; | ||
*/ | ||
export class Mesh extends Property { | ||
export class Mesh extends ExtensibleProperty { | ||
public readonly propertyType = 'Mesh'; | ||
@@ -44,0 +45,0 @@ |
@@ -5,5 +5,4 @@ import { vec3, vec4 } from '../constants'; | ||
import { Camera } from './camera'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Mesh } from './mesh'; | ||
import { Property } from './property'; | ||
import { Root } from './root'; | ||
import { Skin } from './skin'; | ||
@@ -39,3 +38,3 @@ | ||
*/ | ||
export class Node extends Property { | ||
export class Node extends ExtensibleProperty { | ||
public readonly propertyType = 'Node'; | ||
@@ -42,0 +41,0 @@ private _translation: vec3 = [0, 0, 0]; |
@@ -1,2 +0,1 @@ | ||
import { NotImplementedError } from '../constants'; | ||
import { GraphNode } from '../graph'; | ||
@@ -42,3 +41,3 @@ import { PropertyGraph } from './property-graph'; | ||
/** Property type. */ | ||
public readonly propertyType: string; | ||
public abstract readonly propertyType: string; | ||
@@ -51,5 +50,2 @@ protected readonly _graph: PropertyGraph; | ||
// TODO(feat): Extensions should be Properties. | ||
protected _extensions: object = {}; | ||
/** @hidden */ | ||
@@ -61,2 +57,6 @@ constructor(graph: PropertyGraph, name = '') { | ||
/********************************************************************************************** | ||
* Name. | ||
*/ | ||
/** | ||
@@ -79,2 +79,6 @@ * Returns the name of this property. While names are not required to be unique, this is | ||
/********************************************************************************************** | ||
* Extras. | ||
*/ | ||
/** @hidden */ | ||
@@ -89,11 +93,6 @@ public getExtras(): object { return this._extras; } | ||
/** @hidden */ | ||
public getExtensions(): object { return this._extensions; } | ||
/********************************************************************************************** | ||
* Graph state. | ||
*/ | ||
/** @hidden */ | ||
public setExtensions(extensions: object): this { | ||
this._extensions = extensions; | ||
return this; | ||
} | ||
/** | ||
@@ -104,3 +103,3 @@ * Makes a copy of this property, referencing the same resources (not copies) as the original. | ||
public clone(): Property { | ||
throw new NotImplementedError(); | ||
throw new Error('Not implemented.'); | ||
} | ||
@@ -107,0 +106,0 @@ |
import { VERSION } from '../constants'; | ||
import { Extension } from '../extension'; | ||
import { GraphChildList, Link } from '../graph/index'; | ||
@@ -55,2 +56,4 @@ import { Accessor } from './accessor'; | ||
private readonly _extensions: Set<Extension> = new Set(); | ||
@GraphChildList private scenes: Link<Root, Scene>[] = []; | ||
@@ -76,2 +79,31 @@ @GraphChildList private nodes: Link<Root, Node>[] = []; | ||
/********************************************************************************************** | ||
* Extensions. | ||
*/ | ||
/** Lists all {@link Extension} properties enabled for this root. */ | ||
public listExtensionsUsed(): Extension[] { | ||
return Array.from(this._extensions); | ||
} | ||
/** Lists all {@link Extension} properties enabled and required for this root. */ | ||
public listExtensionsRequired(): Extension[] { | ||
return this.listExtensionsUsed().filter((extension) => extension.isRequired()); | ||
} | ||
/** @hidden */ | ||
public _enableExtension(extension: Extension): this { | ||
if (this._extensions.has(extension)) { | ||
throw new Error(`Extension "${extension.extensionName}" is already enabled.`); | ||
} | ||
this._extensions.add(extension); | ||
return this; | ||
} | ||
/** @hidden */ | ||
public _disableExtension(extension: Extension): this { | ||
this._extensions.delete(extension); | ||
return this; | ||
} | ||
/********************************************************************************************** | ||
* Scenes. | ||
@@ -84,14 +116,6 @@ */ | ||
*/ | ||
public addScene(scene: Scene): this { | ||
public _addScene(scene: Scene): this { | ||
return this.addGraphChild(this.scenes, this._graph.link('scene', this, scene)); | ||
} | ||
/** | ||
* Removes a {@link Scene} from the root list. | ||
* @hidden | ||
*/ | ||
public removeScene(scene: Scene): this { | ||
return this.removeGraphChild(this.scenes, scene); | ||
} | ||
/** Lists all {@link Scene} properties associated with this root. */ | ||
@@ -110,14 +134,6 @@ public listScenes(): Scene[] { | ||
*/ | ||
public addNode(node: Node): this { | ||
public _addNode(node: Node): this { | ||
return this.addGraphChild(this.nodes, this._graph.link('node', this, node)); | ||
} | ||
/** | ||
* Removes a {@link Node} from the root list. | ||
* @hidden | ||
*/ | ||
public removeNode(node: Node): this { | ||
return this.removeGraphChild(this.nodes, node); | ||
} | ||
/** Lists all {@link Node} properties associated with this root. */ | ||
@@ -136,14 +152,6 @@ public listNodes(): Node[] { | ||
*/ | ||
public addCamera(camera: Camera): this { | ||
public _addCamera(camera: Camera): this { | ||
return this.addGraphChild(this.cameras, this._graph.link('camera', this, camera)); | ||
} | ||
/** | ||
* Removes a {@link Camera} from the root list. | ||
* @hidden | ||
*/ | ||
public removeCamera(camera: Camera): this { | ||
return this.removeGraphChild(this.cameras, camera); | ||
} | ||
/** Lists all {@link Camera} properties associated with this root. */ | ||
@@ -162,14 +170,6 @@ public listCameras(): Camera[] { | ||
*/ | ||
public addSkin(skin: Skin): this { | ||
public _addSkin(skin: Skin): this { | ||
return this.addGraphChild(this.skins, this._graph.link('skin', this, skin)); | ||
} | ||
/** | ||
* Removes a {@link Skin} from the root list. | ||
* @hidden | ||
*/ | ||
public removeSkin(skin: Skin): this { | ||
return this.removeGraphChild(this.skins, skin); | ||
} | ||
/** Lists all {@link Skin} properties associated with this root. */ | ||
@@ -188,14 +188,6 @@ public listSkins(): Skin[] { | ||
*/ | ||
public addMesh(mesh: Mesh): this { | ||
public _addMesh(mesh: Mesh): this { | ||
return this.addGraphChild(this.meshes, this._graph.link('mesh', this, mesh)); | ||
} | ||
/** | ||
* Removes a {@link Mesh} from the root list. | ||
* @hidden | ||
*/ | ||
public removeMesh(mesh: Mesh): this { | ||
return this.removeGraphChild(this.meshes, mesh); | ||
} | ||
/** Lists all {@link Mesh} properties associated with this root. */ | ||
@@ -214,14 +206,6 @@ public listMeshes(): Mesh[] { | ||
*/ | ||
public addMaterial(material: Material): this { | ||
public _addMaterial(material: Material): this { | ||
return this.addGraphChild(this.materials, this._graph.link('material', this, material)); | ||
} | ||
/** | ||
* Removes a {@link Material} from the root list. | ||
* @hidden | ||
*/ | ||
public removeMaterial(material: Material): this { | ||
return this.removeGraphChild(this.materials, material); | ||
} | ||
/** Lists all {@link Material} properties associated with this root. */ | ||
@@ -240,13 +224,6 @@ public listMaterials(): Material[] { | ||
*/ | ||
public addTexture(texture: Texture): this { | ||
public _addTexture(texture: Texture): this { | ||
return this.addGraphChild(this.textures, this._graph.link('texture', this, texture)); | ||
} | ||
/** | ||
* Removes a {@link Texture} from the root list. | ||
* @hidden | ||
*/ | ||
public removeTexture(texture: Texture): this { | ||
return this.removeGraphChild(this.textures, texture); | ||
} | ||
@@ -266,14 +243,6 @@ /** Lists all {@link Texture} properties associated with this root. */ | ||
*/ | ||
public addAnimation(animation: Animation): this { | ||
public _addAnimation(animation: Animation): this { | ||
return this.addGraphChild(this.animations, this._graph.link('animation', this, animation)); | ||
} | ||
/** | ||
* Removes a {@link Animation} from the root list. | ||
* @hidden | ||
*/ | ||
public removeAnimation(animation: Animation): this { | ||
return this.removeGraphChild(this.animations, animation); | ||
} | ||
/** Lists all {@link Animation} properties associated with this root. */ | ||
@@ -293,14 +262,6 @@ public listAnimations(): Animation[] { | ||
*/ | ||
public addAccessor(accessor: Accessor): this { | ||
public _addAccessor(accessor: Accessor): this { | ||
return this.addGraphChild(this.accessors, this._graph.link('accessor', this, accessor)); | ||
} | ||
/** | ||
* Removes an {@link Accessor} from the root list. | ||
* @hidden | ||
*/ | ||
public removeAccessor(accessor: Accessor): this { | ||
return this.removeGraphChild(this.accessors, accessor); | ||
} | ||
/** Lists all {@link Accessor} properties associated with this root. */ | ||
@@ -319,14 +280,6 @@ public listAccessors(): Accessor[] { | ||
*/ | ||
public addBuffer(buffer: Buffer): this { | ||
public _addBuffer(buffer: Buffer): this { | ||
return this.addGraphChild(this.buffers, this._graph.link('buffer', this, buffer)); | ||
} | ||
/** | ||
* Removes a {@link Buffer} from the root list. | ||
* @hidden | ||
*/ | ||
public removeBuffer(buffer: Buffer): this { | ||
return this.removeGraphChild(this.buffers, buffer); | ||
} | ||
/** Lists all {@link Buffer} properties associated with this root. */ | ||
@@ -333,0 +286,0 @@ public listBuffers(): Buffer[] { |
import { GraphChildList, Link } from '../graph/index'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
import { Property } from './property'; | ||
import { Root } from './root'; | ||
@@ -22,3 +21,3 @@ /** | ||
*/ | ||
export class Scene extends Property { | ||
export class Scene extends ExtensibleProperty { | ||
public readonly propertyType = 'Scene'; | ||
@@ -25,0 +24,0 @@ |
import { GraphChild, GraphChildList, Link } from '../graph'; | ||
import { Accessor } from './accessor'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
import { Node } from './node'; | ||
import { Property } from './property'; | ||
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
export class Skin extends Property { | ||
export class Skin extends ExtensibleProperty { | ||
public readonly propertyType = 'Skin'; | ||
@@ -20,0 +20,0 @@ |
import { vec2 } from '../constants'; | ||
import { ImageUtils } from '../utils'; | ||
import { Property } from './property'; | ||
import { ExtensibleProperty } from './extensible-property'; | ||
@@ -26,3 +26,3 @@ /** | ||
*/ | ||
export class Texture extends Property { | ||
export class Texture extends ExtensibleProperty { | ||
public readonly propertyType = 'Texture'; | ||
@@ -29,0 +29,0 @@ |
@@ -28,6 +28,8 @@ const ALPHABET = '23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ'; | ||
for (let retries = 0; retries < UNIQUE_RETRIES; retries++) { | ||
const id = generateOne(); | ||
if (!previousIDs.has(id)) return id; | ||
const id = generateOne(); | ||
if (!previousIDs.has(id)) { | ||
previousIDs.add(id); | ||
return id; | ||
} | ||
} | ||
return ''; | ||
}; |
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
904018
87
7652