@gltf-transform/core
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -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}var i;!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{constructor(t,e,s){if(this.t=t,this.s=e,this.i=s,this.h=!1,this.o=[],!e.canLink(s))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class h{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(e=>e.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(e=>e.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(e=>e.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,e){let s=this.u.filter(e=>e.getChild()===t);return e&&(s=s.filter(t=>e(t.getParent()))),s.forEach(t=>t.dispose()),this}link(t,e,s){if(!s)return null;const r=new n(t,e,s);return this.registerLink(r),r}registerLink(t){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(e=>e!==t),this}}function o(t,e){Object.defineProperty(t,e,{get:function(){return this["__"+e]},set:function(t){const s=this["__"+e];s&&!Array.isArray(s)&&s.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+e]=null}),this["__"+e]=t},enumerable:!0})}function u(t,e){}class c extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,e){return this.graph.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.graph.listParents(this)}}{constructor(t,e=""){super(t),this.l={},this.t="",this.t=e}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){throw new Error("Not implemented.")}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class a extends c{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?(e.g(this),this.addGraphChild(this.extensions,this.graph.link(e.extensionName,this,e))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],a.prototype,"extensions",void 0);class l extends a{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.p=null,this.m="SCALAR",this.v=null,this.A=!1,this.T=d,this.M=d,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 l.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=d,this.T=d),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.graph.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 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},r([o],l.prototype,"buffer",void 0);class f extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}addChannel(t){const e=this.graph.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.graph.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([u],f.prototype,"channels",void 0),r([u],f.prototype,"samplers",void 0);class g extends c{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,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.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}r([o],g.prototype,"targetNode",void 0),r([o],g.prototype,"sampler",void 0);class p extends c{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,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.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],p.prototype,"input",void 0),r([o],p.prototype,"output",void 0);class m extends a{constructor(){super(...arguments),this.propertyType=i.BUFFER}getURI(){return this.R}setURI(t){return this.R=t,this}}class w extends a{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.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 v extends c{constructor(t,e){super(t),this.L=e,this.L.addExtensionProperty(this)}dispose(){this.L.removeExtensionProperty(this),super.dispose()}g(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class x{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const e=atob(t.split(",")[1]),s=new Uint8Array(e.length);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s.buffer}{const e=t.split(",")[1],s=t.indexOf("base64")>=0;return this.trim(Buffer.from(e,s?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:e,byteLength:s}=t;return t.buffer.slice(e,e+s)}static concat(t){let e=0;for(const s of t)e+=s.byteLength;const s=new Uint8Array(e);let r=0;for(const e of t)s.set(new Uint8Array(e),r),r+=e.byteLength;return s.buffer}static pad(t,e=0){const s=this.padNumber(t.byteLength);if(s!==t.byteLength){const r=new Uint8Array(s);if(r.set(new Uint8Array(t)),0!==e)for(let i=t.byteLength;i<s;i++)r[i]=e;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const s=new DataView(t),r=new DataView(e);let i=t.byteLength;for(;i--;)if(s.getUint8(i)!==r.getUint8(i))return!1;return!0}}class A{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class T{static getSizeJPEG(t){let e,s;for(t=t.slice(4);t.length;){if(e=t.readUInt16BE(0),E(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)]}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":"image/"+t}}function E(t,e){if(e>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[e])throw new TypeError("Invalid JPG, marker table corrupted")}class y{constructor(t){this.verbosity=t}debug(t){this.verbosity<=y.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=y.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=y.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=y.Verbosity.ERROR&&console.error(t)}}y.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const b="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",M=new Set,S=function(){let t="";for(let e=0;e<6;e++)t+=b.charAt(Math.floor(Math.random()*b.length));return t},N=function(){for(let t=0;t<999;t++){const t=S();if(!M.has(t))return M.add(t),t}};class R extends a{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?T.getSizePNG(Buffer.from(this.image)):T.getSizeJPEG(Buffer.from(this.image))}}class I{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class C{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.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 _ extends n{constructor(){super(...arguments),this.textureInfo=new I,this.sampler=new C}}class B extends n{constructor(){super(...arguments),this.semantic=""}}class U extends n{}class k extends h{linkTexture(t,e,s){if(!s)return null;const r=new _(t,e,s);return this.registerLink(r),r}linkAttribute(t,e,s){if(!s)return null;const r=new B(t,e,s);return this.registerLink(r),r}linkIndex(t,e,s){if(!s)return null;const r=new U(t,e,s);return this.registerLink(r),r}}class L extends a{constructor(){super(...arguments),this.propertyType=i.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.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.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.graph.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.graph.linkTexture("emissiveTexture",this,t),this}getNormalScale(){return this.W}setNormalScale(t){return this.W=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTexture.textureInfo:null}getNormalTextureSampler(){return this.normalTexture?this.normalTexture.sampler:null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.q}setRoughnessFactor(t){return this.q=t,this}getMetallicFactor(){return this.Z}setMetallicFactor(t){return this.Z=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null}getMetallicRoughnessTextureSampler(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this}}r([o],L.prototype,"baseColorTexture",void 0),r([o],L.prototype,"emissiveTexture",void 0),r([o],L.prototype,"normalTexture",void 0),r([o],L.prototype,"occlusionTexture",void 0),r([o],L.prototype,"metallicRoughnessTexture",void 0);class P extends a{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([u],P.prototype,"primitives",void 0);class O extends c{constructor(){super(...arguments),this.propertyType=i.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.graph.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.graph.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.graph.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.graph.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}r([o],O.prototype,"indices",void 0),r([u],O.prototype,"attributes",void 0),r([u],O.prototype,"targets",void 0),r([o],O.prototype,"material",void 0);class F extends c{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,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.graph.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([u],F.prototype,"attributes",void 0);class G extends a{constructor(){super(...arguments),this.propertyType=i.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.graph.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.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([o],G.prototype,"camera",void 0),r([o],G.prototype,"mesh",void 0),r([o],G.prototype,"skin",void 0),r([u],G.prototype,"children",void 0);class j extends c{constructor(){super(...arguments),this.propertyType=i.ROOT,this.st={generator:"glTF-Transform v0.4.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.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}at(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}gt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}pt(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],j.prototype,"scenes",void 0),r([u],j.prototype,"nodes",void 0),r([u],j.prototype,"cameras",void 0),r([u],j.prototype,"skins",void 0),r([u],j.prototype,"meshes",void 0),r([u],j.prototype,"materials",void 0),r([u],j.prototype,"textures",void 0),r([u],j.prototype,"animations",void 0),r([u],j.prototype,"accessors",void 0),r([u],j.prototype,"buffers",void 0);class D extends a{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],D.prototype,"nodes",void 0);class $ extends a{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const e=this.graph.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([o],$.prototype,"skeleton",void 0),r([o],$.prototype,"inverseBindMatrices",void 0),r([u],$.prototype,"joints",void 0);class z{constructor(){this.graph=new k,this.root=new j(this.graph),this.logger=new y(y.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){throw new Error("Not implemented.")}transform(...t){for(const e of t)e(this);return this}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 G(this.graph,t);return this.root.ot(e),e}createCamera(t){const e=new w(this.graph,t);return this.root.ut(e),e}createSkin(t){const e=new $(this.graph,t);return this.root.ct(e),e}createMesh(t){const e=new P(this.graph,t);return this.root.at(e),e}createPrimitive(){return new O(this.graph)}createPrimitiveTarget(t){return new F(this.graph,t)}createMaterial(t){const e=new L(this.graph,t);return this.root.lt(e),e}createTexture(t){const e=new R(this.graph,t);return this.root.dt(e),e}createAnimation(t){const e=new f(this.graph,t);return this.root.ft(e),e}createAnimationChannel(){return new g(this.graph)}createAnimationSampler(){return new p(this.graph)}createAccessor(t,e=null){e||(e=this.getRoot().listBuffers()[0]);const s=new l(this.graph,t).setBuffer(e);return this.root.gt(s),s}createBuffer(t){const e=new m(this.graph,t);return this.root.pt(e),e}}class J{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 V{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,e){void 0!==e.texCoord&&t.setTexCoord(e.texCoord)}setTextureSampler(t,e){const s=this.nativeDocument.json.textures[e.index];if(void 0===s.sampler)return;const r=this.nativeDocument.json.samplers[s.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class Y{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 V(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=W[t.componentType],r=l.getElementSize(t.type);let i;i=void 0!==t.bufferView?q(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=q(h,e),c=q(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):q(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["xt"]).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(T.extensionToMimeType(s))}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]),o.setTextureInfo(e.getBaseColorTextureInfo(),t),o.setTextureSampler(e.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const s=t.emissiveTexture;e.setEmissiveTexture(o.textures[u[s.index].source]),o.setTextureInfo(e.getEmissiveTextureInfo(),s),o.setTextureSampler(e.getEmissiveTextureSampler(),s)}if(void 0!==t.normalTexture){const s=t.normalTexture;e.setNormalTexture(o.textures[u[s.index].source]),o.setTextureInfo(e.getNormalTextureInfo(),s),o.setTextureSampler(e.getNormalTextureSampler(),s),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]),o.setTextureInfo(e.getOcclusionTextureInfo(),s),o.setTextureSampler(e.getOcclusionTextureSampler(),s),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]),o.setTextureInfo(e.getMetallicRoughnessTextureInfo(),t),o.setTextureSampler(e.getMetallicRoughnessTextureSampler(),t)}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 a=n.extensionsUsed||[],d=n.extensionsRequired||[];for(const t of i.extensions)a.includes(t.EXTENSION_NAME)&&h.createExtension(t).setRequired(d.includes(t.EXTENSION_NAME)).read(o);return h}}function q(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["xt"],n=W[t.componentType],h=l.getElementSize(t.type);if(void 0!==s.byteStride&&s.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["xt"],n=W[t.componentType],h=l.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,s.byteOffset,s.byteLength),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=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[e*h+s]=i}return c}(t,e);const o=(s.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class Z{constructor(t,e){this.nativeDocument=t,this.options=e,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}createImageData(t,e,s){if(this.options.isGLB)this.imageData.push(e),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:e.byteLength});else{const r=T.mimeTypeToExtension(s.getMimeType());t.uri=this.imageURIGenerator.createURI(s,r),this.nativeDocument.resources[t.uri]=e}}}class X{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{static write(t,e){const s=t.getRoot(),r={json:{asset:s.getAsset()},resources:{}},i=r.json,n=new Z(r,e),h=s.listBuffers().length,o=s.listTextures().length;function u(t,e,s,r){const h=[];let o=0;for(const e of t){const t=n.createAccessorDef(e);t.bufferView=i.bufferViews.length;const s=x.pad(e.getArray().buffer);t.byteOffset=o,o+=s.byteLength,h.push(s),n.accessorIndexMap.set(e,i.accessors.length),i.accessors.push(t)}const u={buffer:e,byteOffset:s,byteLength:x.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function c(t,e,s){const r=t[0].getCount();let h=0;for(const e of t){const t=n.createAccessorDef(e);t.bufferView=i.bufferViews.length,t.byteOffset=h;const s=e.getElementSize(),r=e.getComponentSize();h+=x.padNumber(s*r),n.accessorIndexMap.set(e,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),c=new DataView(u);for(let e=0;e<r;e++){let s=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=e*h+s+r*i,a=o[e*t+r];switch(n){case 5126:c.setFloat32(u,a,!0);break;case 5120:c.setInt8(u,a);break;case 5122:c.setInt16(u,a,!0);break;case 5121:c.setUint8(u,a);break;case 5123:c.setUint16(u,a,!0);break;case 5125:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+n)}}s+=x.padNumber(t*i)}}return i.bufferViews.push({buffer:e,byteOffset:s,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new X(h>1,e.basename),n.imageURIGenerator=new X(o>1,e.basename),n.logger=t.getLogger();const a=new Map;for(const e of t.getGraph().getLinks()){if(e.getParent()===s)continue;const t=e.getChild();if(t instanceof l){const s=a.get(t)||[];s.push(e),a.set(t,s)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=s.listTextures().map((t,e)=>{const s=n.createPropertyDef(t);return t.getMimeType()&&(s.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(s,t.getImage(),t),n.imageIndexMap.set(t,e),s}),i.buffers=[],s.listBuffers().forEach(t=>{const s=n.createPropertyDef(t),h=new Map,o=new Set,d=new Set,f=t.listParents().filter(t=>!(t instanceof j));for(const t of f){if(!(t instanceof l))throw new Error("Unimplemented buffer reference: "+t);let e=!1,s=!1,r=!1;const i=a.get(t)||[];for(const t of i)t instanceof B?e=!0:t instanceof U?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.");d.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 g=[],p=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),p,w,34963);w+=t.byteLength,g.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const e=c(Array.from(t),p,w);w+=e.byteLength,g.push(...e.buffers)}if(d.size){const t=u(Array.from(d),p,w);w+=t.byteLength,g.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,g.push(n.imageData[t]);w?(e.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),s.uri=m),s.byteLength=w,r.resources[m]=x.concat(g),i.buffers.push(s)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=s.listMaterials().map((t,e)=>{const s=n.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=n.createTextureInfoDef(e,r,i)}if(t.getEmissiveTexture()){const e=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();s.emissiveTexture=n.createTextureInfoDef(e,r,i)}if(t.getNormalTexture()){const e=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(e,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),s.normalTexture=h}if(t.getOcclusionTexture()){const e=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(e,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),s.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const e=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();s.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(e,r,i)}return n.materialIndexMap.set(t,e),s}),i.meshes=s.listMeshes().map((t,e)=>{const s=n.createPropertyDef(t);let r;return s.primitives=t.listPrimitives().map(t=>{const e={attributes:{}};e.material=n.materialIndexMap.get(t.getMaterial()),e.mode=t.getMode(),t.getIndices()&&(e.indices=n.accessorIndexMap.get(t.getIndices()));for(const s of t.listSemantics())e.attributes[s]=n.accessorIndexMap.get(t.getAttribute(s));for(const s of t.listTargets()){const t={};for(const e of s.listSemantics())t[e]=n.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),n.meshIndexMap.set(t,e),s}),i.cameras=s.listCameras().map((t,e)=>{const s=n.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()},n.cameraIndexMap.set(t,e),s}),i.nodes=s.listNodes().map((t,e)=>{const s=n.createPropertyDef(t);return s.translation=t.getTranslation(),s.rotation=t.getRotation(),s.scale=t.getScale(),t.getWeights().length&&(s.weights=t.getWeights()),n.nodeIndexMap.set(t,e),s}),i.skins=s.listSkins().map((t,e)=>{const s=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(s.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(s.skeleton=n.nodeIndexMap.get(t.getSkeleton())),s.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,e),s}),s.listNodes().forEach((t,e)=>{const s=i.nodes[e];t.getMesh()&&(s.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(s.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(s.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(s.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=s.listAnimations().map(t=>{const e=n.createPropertyDef(t),s=new Map;return e.samplers=t.listSamplers().map((t,e)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),s.set(t,e),r}),e.channels=t.listChannels().map(t=>{const e=n.createPropertyDef(t);return e.sampler=s.get(t.getSampler()),e.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},e}),e}),i.scenes=s.listScenes().map(t=>{const e=n.createPropertyDef(t);return e.nodes=t.listNodes().map(t=>n.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(n)),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(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return Y.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=x.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:{xt:u}})}packGLB(t){const{json:e,resources:s}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(e),i=x.pad(x.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=x.concat([n,i]),o=x.pad(Object.values(s)[0],0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=x.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return x.concat([a,h,c])}}class Q extends K{constructor(t,e){super(),this.fs=t,this.path=e}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,e){t.match(/\.glb$/)?this.writeGLB(t,e):this.writeGLTF(t,e)}readGLB(t){const e=this.fs.readFileSync(t),s=x.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]=x.trim(this.fs.readFileSync(r))}else{const e=`__${N()}.${A.extension(t.uri)}`;s.resources[e]=x.createBufferFromDataURI(t.uri),t.uri=e}}),Y.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 tt extends K{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const e={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{e.json=t;const s=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(s=>{e.resources[t.uri]=s})});return Promise.all(s).then(()=>this.createDocument(e))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}export{l as Accessor,f as Animation,g as AnimationChannel,p as AnimationSampler,m as Buffer,x as BufferUtils,w as Camera,z as Document,J as Extension,v as ExtensionProperty,A as FileUtils,h as Graph,o as GraphChild,T as ImageUtils,y as Logger,L as Material,P as Mesh,G as Node,Q as NodeIO,O as Primitive,F as PrimitiveTarget,c as Property,i as PropertyType,V as ReaderContext,j as Root,D as Scene,$ as Skin,R as Texture,I as TextureInfo,_ as TextureLink,C as TextureSampler,tt as WebIO,Z as WriterContext,N 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}var i;!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{constructor(t,e,s){if(this.t=t,this.s=e,this.i=s,this.h=!1,this.o=[],!e.canLink(s))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class h{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(e=>e.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(e=>e.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(e=>e.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,e){let s=this.u.filter(e=>e.getChild()===t);return e&&(s=s.filter(t=>e(t.getParent()))),s.forEach(t=>t.dispose()),this}link(t,e,s){if(!s)return null;const r=new n(t,e,s);return this.registerLink(r),r}registerLink(t){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(e=>e!==t),this}}function o(t,e){Object.defineProperty(t,e,{get:function(){return this["__"+e]},set:function(t){const s=this["__"+e];s&&!Array.isArray(s)&&s.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+e]=null}),this["__"+e]=t},enumerable:!0})}function u(t,e){}class c extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,e){return this.graph.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.graph.listParents(this)}}{constructor(t,e=""){super(t),this.l={},this.t="",this.t=e}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){throw new Error("Not implemented.")}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class a extends c{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?(e.g(this),this.addGraphChild(this.extensions,this.graph.link(e.extensionName,this,e))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],a.prototype,"extensions",void 0);class l extends a{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.p=null,this.m="SCALAR",this.v=null,this.A=!1,this.T=d,this.M=d,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 l.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=d,this.T=d),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.graph.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 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},r([o],l.prototype,"buffer",void 0);class f extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}addChannel(t){const e=this.graph.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.graph.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([u],f.prototype,"channels",void 0),r([u],f.prototype,"samplers",void 0);class g extends c{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,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.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}r([o],g.prototype,"targetNode",void 0),r([o],g.prototype,"sampler",void 0);class p extends c{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,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.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],p.prototype,"input",void 0),r([o],p.prototype,"output",void 0);class m extends a{constructor(){super(...arguments),this.propertyType=i.BUFFER}getURI(){return this.R}setURI(t){return this.R=t,this}}class w extends a{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.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 v extends c{constructor(t,e){super(t),this.L=e,this.L.addExtensionProperty(this)}dispose(){this.L.removeExtensionProperty(this),super.dispose()}g(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class x{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const e=atob(t.split(",")[1]),s=new Uint8Array(e.length);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s.buffer}{const e=t.split(",")[1],s=t.indexOf("base64")>=0;return this.trim(Buffer.from(e,s?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:e,byteLength:s}=t;return t.buffer.slice(e,e+s)}static concat(t){let e=0;for(const s of t)e+=s.byteLength;const s=new Uint8Array(e);let r=0;for(const e of t)s.set(new Uint8Array(e),r),r+=e.byteLength;return s.buffer}static pad(t,e=0){const s=this.padNumber(t.byteLength);if(s!==t.byteLength){const r=new Uint8Array(s);if(r.set(new Uint8Array(t)),0!==e)for(let i=t.byteLength;i<s;i++)r[i]=e;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const s=new DataView(t),r=new DataView(e);let i=t.byteLength;for(;i--;)if(s.getUint8(i)!==r.getUint8(i))return!1;return!0}}class A{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class T{static getSizeJPEG(t){let e,s;for(t=t.slice(4);t.length;){if(e=t.readUInt16BE(0),E(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)]}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":"image/"+t}}function E(t,e){if(e>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[e])throw new TypeError("Invalid JPG, marker table corrupted")}class y{constructor(t){this.verbosity=t}debug(t){this.verbosity<=y.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=y.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=y.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=y.Verbosity.ERROR&&console.error(t)}}y.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const b="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",M=new Set,S=function(){let t="";for(let e=0;e<6;e++)t+=b.charAt(Math.floor(Math.random()*b.length));return t},N=function(){for(let t=0;t<999;t++){const t=S();if(!M.has(t))return M.add(t),t}};class R extends a{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?T.getSizePNG(Buffer.from(this.image)):T.getSizeJPEG(Buffer.from(this.image))}}class I{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class C{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.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 _ extends n{constructor(){super(...arguments),this.textureInfo=new I,this.sampler=new C}}class B extends n{constructor(){super(...arguments),this.semantic=""}}class U extends n{}class k extends h{linkTexture(t,e,s){if(!s)return null;const r=new _(t,e,s);return this.registerLink(r),r}linkAttribute(t,e,s){if(!s)return null;const r=new B(t,e,s);return this.registerLink(r),r}linkIndex(t,e,s){if(!s)return null;const r=new U(t,e,s);return this.registerLink(r),r}}class L extends a{constructor(){super(...arguments),this.propertyType=i.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.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.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.graph.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.graph.linkTexture("emissiveTexture",this,t),this}getNormalScale(){return this.W}setNormalScale(t){return this.W=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTexture.textureInfo:null}getNormalTextureSampler(){return this.normalTexture?this.normalTexture.sampler:null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this}getOcclusionStrength(){return this.Y}setOcclusionStrength(t){return this.Y=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null}getOcclusionTextureSampler(){return this.occlusionTexture?this.occlusionTexture.sampler:null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this}getRoughnessFactor(){return this.q}setRoughnessFactor(t){return this.q=t,this}getMetallicFactor(){return this.Z}setMetallicFactor(t){return this.Z=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null}getMetallicRoughnessTextureSampler(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this}}r([o],L.prototype,"baseColorTexture",void 0),r([o],L.prototype,"emissiveTexture",void 0),r([o],L.prototype,"normalTexture",void 0),r([o],L.prototype,"occlusionTexture",void 0),r([o],L.prototype,"metallicRoughnessTexture",void 0);class P extends a{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([u],P.prototype,"primitives",void 0);class O extends c{constructor(){super(...arguments),this.propertyType=i.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.graph.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.graph.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.graph.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.graph.link("target",this,t)),this}removeTarget(t){return this.removeGraphChild(this.targets,t)}}r([o],O.prototype,"indices",void 0),r([u],O.prototype,"attributes",void 0),r([u],O.prototype,"targets",void 0),r([o],O.prototype,"material",void 0);class F extends c{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,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.graph.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([u],F.prototype,"attributes",void 0);class G extends a{constructor(){super(...arguments),this.propertyType=i.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.graph.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.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([o],G.prototype,"camera",void 0),r([o],G.prototype,"mesh",void 0),r([o],G.prototype,"skin",void 0),r([u],G.prototype,"children",void 0);class j extends c{constructor(){super(...arguments),this.propertyType=i.ROOT,this.st={generator:"glTF-Transform v0.4.1",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.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}at(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}lt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}gt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}pt(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],j.prototype,"scenes",void 0),r([u],j.prototype,"nodes",void 0),r([u],j.prototype,"cameras",void 0),r([u],j.prototype,"skins",void 0),r([u],j.prototype,"meshes",void 0),r([u],j.prototype,"materials",void 0),r([u],j.prototype,"textures",void 0),r([u],j.prototype,"animations",void 0),r([u],j.prototype,"accessors",void 0),r([u],j.prototype,"buffers",void 0);class D extends a{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],D.prototype,"nodes",void 0);class $ extends a{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const e=this.graph.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([o],$.prototype,"skeleton",void 0),r([o],$.prototype,"inverseBindMatrices",void 0),r([u],$.prototype,"joints",void 0);class z{constructor(){this.graph=new k,this.root=new j(this.graph),this.logger=new y(y.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){throw new Error("Not implemented.")}transform(...t){for(const e of t)e(this);return this}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 G(this.graph,t);return this.root.ot(e),e}createCamera(t){const e=new w(this.graph,t);return this.root.ut(e),e}createSkin(t){const e=new $(this.graph,t);return this.root.ct(e),e}createMesh(t){const e=new P(this.graph,t);return this.root.at(e),e}createPrimitive(){return new O(this.graph)}createPrimitiveTarget(t){return new F(this.graph,t)}createMaterial(t){const e=new L(this.graph,t);return this.root.lt(e),e}createTexture(t){const e=new R(this.graph,t);return this.root.dt(e),e}createAnimation(t){const e=new f(this.graph,t);return this.root.ft(e),e}createAnimationChannel(){return new g(this.graph)}createAnimationSampler(){return new p(this.graph)}createAccessor(t,e=null){e||(e=this.getRoot().listBuffers()[0]);const s=new l(this.graph,t).setBuffer(e);return this.root.gt(s),s}createBuffer(t){const e=new m(this.graph,t);return this.root.pt(e),e}}class J{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 V{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,e){void 0!==e.texCoord&&t.setTexCoord(e.texCoord)}setTextureSampler(t,e){const s=this.nativeDocument.json.textures[e.index];if(void 0===s.sampler)return;const r=this.nativeDocument.json.samplers[s.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class Y{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 V(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=W[t.componentType],r=l.getElementSize(t.type);let i;i=void 0!==t.bufferView?q(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=q(h,e),c=q(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):q(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["xt"]).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(T.extensionToMimeType(s))}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]),o.setTextureInfo(e.getBaseColorTextureInfo(),t),o.setTextureSampler(e.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const s=t.emissiveTexture;e.setEmissiveTexture(o.textures[u[s.index].source]),o.setTextureInfo(e.getEmissiveTextureInfo(),s),o.setTextureSampler(e.getEmissiveTextureSampler(),s)}if(void 0!==t.normalTexture){const s=t.normalTexture;e.setNormalTexture(o.textures[u[s.index].source]),o.setTextureInfo(e.getNormalTextureInfo(),s),o.setTextureSampler(e.getNormalTextureSampler(),s),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]),o.setTextureInfo(e.getOcclusionTextureInfo(),s),o.setTextureSampler(e.getOcclusionTextureSampler(),s),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]),o.setTextureInfo(e.getMetallicRoughnessTextureInfo(),t),o.setTextureSampler(e.getMetallicRoughnessTextureSampler(),t)}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 a=n.extensionsUsed||[],d=n.extensionsRequired||[];for(const t of i.extensions)a.includes(t.EXTENSION_NAME)&&h.createExtension(t).setRequired(d.includes(t.EXTENSION_NAME)).read(o);return h}}function q(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["xt"],n=W[t.componentType],h=l.getElementSize(t.type);if(void 0!==s.byteStride&&s.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,e){const s=e.json.bufferViews[t.bufferView],r=e.json.buffers[s.buffer],i=r.uri?e.resources[r.uri]:e.resources["xt"],n=W[t.componentType],h=l.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,s.byteOffset,s.byteLength),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=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[e*h+s]=i}return c}(t,e);const o=(s.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class Z{constructor(t,e){this.nativeDocument=t,this.options=e,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}createImageData(t,e,s){if(this.options.isGLB)this.imageData.push(e),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:e.byteLength});else{const r=T.mimeTypeToExtension(s.getMimeType());t.uri=this.imageURIGenerator.createURI(s,r),this.nativeDocument.resources[t.uri]=e}}}class X{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{static write(t,e){const s=t.getRoot(),r={json:{asset:s.getAsset()},resources:{}},i=r.json,n=new Z(r,e),h=s.listBuffers().length,o=s.listTextures().length;function u(t,e,s,r){const h=[];let o=0;for(const e of t){const t=n.createAccessorDef(e);t.bufferView=i.bufferViews.length;const s=x.pad(e.getArray().buffer);t.byteOffset=o,o+=s.byteLength,h.push(s),n.accessorIndexMap.set(e,i.accessors.length),i.accessors.push(t)}const u={buffer:e,byteOffset:s,byteLength:x.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function c(t,e,s){const r=t[0].getCount();let h=0;for(const e of t){const t=n.createAccessorDef(e);t.bufferView=i.bufferViews.length,t.byteOffset=h;const s=e.getElementSize(),r=e.getComponentSize();h+=x.padNumber(s*r),n.accessorIndexMap.set(e,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),c=new DataView(u);for(let e=0;e<r;e++){let s=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=e*h+s+r*i,a=o[e*t+r];switch(n){case 5126:c.setFloat32(u,a,!0);break;case 5120:c.setInt8(u,a);break;case 5122:c.setInt16(u,a,!0);break;case 5121:c.setUint8(u,a);break;case 5123:c.setUint16(u,a,!0);break;case 5125:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+n)}}s+=x.padNumber(t*i)}}return i.bufferViews.push({buffer:e,byteOffset:s,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new X(h>1,e.basename),n.imageURIGenerator=new X(o>1,e.basename),n.logger=t.getLogger();const a=new Map;for(const e of t.getGraph().getLinks()){if(e.getParent()===s)continue;const t=e.getChild();if(t instanceof l){const s=a.get(t)||[];s.push(e),a.set(t,s)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=s.listTextures().map((t,e)=>{const s=n.createPropertyDef(t);return t.getMimeType()&&(s.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(s,t.getImage(),t),n.imageIndexMap.set(t,e),s}),i.buffers=[],s.listBuffers().forEach(t=>{const s=n.createPropertyDef(t),h=new Map,o=new Set,d=new Set,f=t.listParents().filter(t=>!(t instanceof j));for(const t of f){if(!(t instanceof l))throw new Error("Unimplemented buffer reference: "+t);let e=!1,s=!1,r=!1;const i=a.get(t)||[];for(const t of i)t instanceof B?e=!0:t instanceof U?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.");d.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 g=[],p=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),p,w,34963);w+=t.byteLength,g.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const e=c(Array.from(t),p,w);w+=e.byteLength,g.push(...e.buffers)}if(d.size){const t=u(Array.from(d),p,w);w+=t.byteLength,g.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,g.push(n.imageData[t]);w?(e.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),s.uri=m),s.byteLength=w,r.resources[m]=x.concat(g),i.buffers.push(s)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=s.listMaterials().map((t,e)=>{const s=n.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=n.createTextureInfoDef(e,r,i)}if(t.getEmissiveTexture()){const e=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();s.emissiveTexture=n.createTextureInfoDef(e,r,i)}if(t.getNormalTexture()){const e=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(e,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),s.normalTexture=h}if(t.getOcclusionTexture()){const e=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(e,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),s.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const e=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();s.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(e,r,i)}return n.materialIndexMap.set(t,e),s}),i.meshes=s.listMeshes().map((t,e)=>{const s=n.createPropertyDef(t);let r;return s.primitives=t.listPrimitives().map(t=>{const e={attributes:{}};e.material=n.materialIndexMap.get(t.getMaterial()),e.mode=t.getMode(),t.getIndices()&&(e.indices=n.accessorIndexMap.get(t.getIndices()));for(const s of t.listSemantics())e.attributes[s]=n.accessorIndexMap.get(t.getAttribute(s));for(const s of t.listTargets()){const t={};for(const e of s.listSemantics())t[e]=n.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),n.meshIndexMap.set(t,e),s}),i.cameras=s.listCameras().map((t,e)=>{const s=n.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()},n.cameraIndexMap.set(t,e),s}),i.nodes=s.listNodes().map((t,e)=>{const s=n.createPropertyDef(t);return s.translation=t.getTranslation(),s.rotation=t.getRotation(),s.scale=t.getScale(),t.getWeights().length&&(s.weights=t.getWeights()),n.nodeIndexMap.set(t,e),s}),i.skins=s.listSkins().map((t,e)=>{const s=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(s.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(s.skeleton=n.nodeIndexMap.get(t.getSkeleton())),s.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,e),s}),s.listNodes().forEach((t,e)=>{const s=i.nodes[e];t.getMesh()&&(s.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(s.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(s.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(s.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=s.listAnimations().map(t=>{const e=n.createPropertyDef(t),s=new Map;return e.samplers=t.listSamplers().map((t,e)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),s.set(t,e),r}),e.channels=t.listChannels().map(t=>{const e=n.createPropertyDef(t);return e.sampler=s.get(t.getSampler()),e.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},e}),e}),i.scenes=s.listScenes().map(t=>{const e=n.createPropertyDef(t);return e.nodes=t.listNodes().map(t=>n.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(n)),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(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return Y.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=x.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:{xt:u}})}packGLB(t){const{json:e,resources:s}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(e),i=x.pad(x.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=x.concat([n,i]),o=x.pad(Object.values(s)[0],0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=x.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return x.concat([a,h,c])}}class Q extends K{constructor(t,e){super(),this.fs=t,this.path=e}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,e){t.match(/\.glb$/)?this.writeGLB(t,e):this.writeGLTF(t,e)}readGLB(t){const e=this.fs.readFileSync(t),s=x.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]=x.trim(this.fs.readFileSync(r))}else{const e=`__${N()}.${A.extension(t.uri)}`;s.resources[e]=x.createBufferFromDataURI(t.uri),t.uri=e}}),Y.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 tt extends K{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const e={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{e.json=t;const s=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(s=>{e.resources[t.uri]=s})});return Promise.all(s).then(()=>this.createDocument(e))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}export{l as Accessor,f as Animation,g as AnimationChannel,p as AnimationSampler,m as Buffer,x as BufferUtils,w as Camera,z as Document,J as Extension,v as ExtensionProperty,A as FileUtils,h as Graph,o as GraphChild,T as ImageUtils,y as Logger,L as Material,P as Mesh,G as Node,Q as NodeIO,O as Primitive,F as PrimitiveTarget,c as Property,i as PropertyType,V as ReaderContext,j as Root,D as Scene,$ as Skin,R as Texture,I as TextureInfo,_ as TextureLink,C as TextureSampler,tt as WebIO,Z as WriterContext,N as uuid}; | ||
//# sourceMappingURL=core.modern.js.map |
{ | ||
"name": "@gltf-transform/core", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
"description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js", | ||
"main": "dist/core.umd.js", | ||
"main": "dist/core.js", | ||
"module": "dist/core.modern.js", | ||
@@ -12,5 +12,5 @@ "source": "src/core.ts", | ||
"scripts": { | ||
"dist": "microbundle --format modern,umd --define PACKAGE_VERSION=$npm_package_version", | ||
"watch": "microbundle watch --format modern,umd --define PACKAGE_VERSION=$npm_package_version", | ||
"watch:debug": "microbundle watch --no-compress --format modern,umd --define PACKAGE_VERSION=$npm_package_version" | ||
"dist": "microbundle --format modern,cjs --define PACKAGE_VERSION=$npm_package_version", | ||
"watch": "microbundle watch --format modern,cjs --define PACKAGE_VERSION=$npm_package_version", | ||
"watch:debug": "microbundle watch --no-compress --format modern,cjs --define PACKAGE_VERSION=$npm_package_version" | ||
}, | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "9a2c30c6dd0f0222e86e5f65a8c13f07b9765b1c" | ||
"gitHead": "fa72e862b943db559d398918e3091216f54a6592" | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
1229540
89
7908
4
9