@gltf-transform/core
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -1,2 +0,2 @@ | ||
var t,n=require("gl-matrix/mat4");function r(){return(r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function i(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=t[r];return i}function e(t){var n=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,n){if(t){if("string"==typeof t)return u(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,void 0):void 0}}(t)))return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function s(t,n,r,i){var u,e=arguments.length,s=e<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,n,r,i);else for(var o=t.length-1;o>=0;o--)(u=t[o])&&(s=(e<3?u(s):e>3?u(n,r,s):u(n,r))||s);return e>3&&s&&Object.defineProperty(n,r,s),s}(t=exports.PropertyType||(exports.PropertyType={})).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";var o=function(){function t(t,n,r){if(this.t=t,this.i=n,this.u=r,this.s=!1,this.o=[],!n.canLink(r))throw new Error("Cannot link disconnected graphs/documents.")}var n=t.prototype;return n.getName=function(){return this.t},n.getParent=function(){return this.i},n.getChild=function(){return this.u},n.setChild=function(t){return this.u=t,this},n.dispose=function(){this.s||(this.s=!0,this.o.forEach(function(t){return t()}),this.o.length=0)},n.onDispose=function(t){return this.o.push(t),this},n.isDisposed=function(){return this.s},t}(),h=function(){function t(){this.h=[]}var n=t.prototype;return n.getLinks=function(){return this.h},n.listParents=function(t){return this.h.filter(function(n){return n.getChild()===t}).map(function(t){return t.getParent()})},n.listChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).map(function(t){return t.getChild()})},n.disconnectChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).forEach(function(t){return t.dispose()}),this},n.disconnectParents=function(t,n){var r=this.h.filter(function(n){return n.getChild()===t});return n&&(r=r.filter(function(t){return n(t.getParent())})),r.forEach(function(t){return t.dispose()}),this},n.link=function(t,n,r){if(!r)return null;var i=new o(t,n,r);return this.registerLink(i),i},n.registerLink=function(t){var n=this;return this.h.push(t),t.onDispose(function(){return n.unlink(t)}),t},n.unlink=function(t){return this.h=this.h.filter(function(n){return n!==t}),this},t}();function f(t,n){Object.defineProperty(t,n,{get:function(){return this["__"+n]},set:function(t){var r=this,i=this["__"+n];i&&!Array.isArray(i)&&i.dispose(),t&&!Array.isArray(t)&&t.onDispose(function(){r["__"+n]=null}),this["__"+n]=t},enumerable:!0})}function c(t,n){}var a=function(t){return t},v=function(t){function n(n,r){var i;return void 0===r&&(r=""),(i=t.call(this,n)||this).v={},i.t="",i.t=r,i}i(n,t);var r=n.prototype;return r.getName=function(){return this.t},r.setName=function(t){return this.t=t,this},r.getExtras=function(){return this.v},r.setExtras=function(t){return this.v=t,this},r.clone=function(){return new(0,this.constructor)(this.graph).copy(this,a)},r.copy=function(t,n){return this.t=t.t,this.v=JSON.parse(JSON.stringify(t.v)),this},r.detach=function(){return this.graph.disconnectParents(this,function(t){return"Root"!==t.propertyType}),this},r.listParents=function(){return this.listGraphParents()},n}(function(){function t(t){this.s=!1,this.graph=t}var n=t.prototype;return n.canLink=function(t){return this.graph===t.graph},n.isDisposed=function(){return this.s},n.dispose=function(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.s=!0},n.detach=function(){return this.graph.disconnectParents(this),this},n.swap=function(t,n){var r=this;return this.graph.getLinks().filter(function(n){return n.getParent()===r&&n.getChild()===t}).forEach(function(t){return t.setChild(n)}),this},n.addGraphChild=function(t,n){return t.push(n),n.onDispose(function(){var r=t.filter(function(t){return t!==n});t.length=0,t.push.apply(t,r)}),this},n.removeGraphChild=function(t,n){return t.filter(function(t){return t.getChild()===n}).forEach(function(t){return t.dispose()}),this},n.clearGraphChildList=function(t){for(;t.length>0;)t[0].dispose();return this},n.listGraphParents=function(){return this.graph.listParents(this)},t}()),l=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).extensions=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.extensions),n.extensions.forEach(function(t){var n=t.getChild();i.setExtension(n.constructor,r(n))}),this},r.getExtension=function(t){var n=t.EXTENSION_NAME,r=this.extensions.find(function(t){return t.getChild().extensionName===n});return r?r.getChild():null},r.setExtension=function(t,n){var r=this.getExtension(t);return r&&this.removeGraphChild(this.extensions,r),n?(n.l(this),this.addGraphChild(this.extensions,this.graph.link(n.extensionName,this,n))):this},r.listExtensions=function(){return this.extensions.map(function(t){return t.getChild()})},n}(v);s([c],l.prototype,"extensions",void 0);var d=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ACCESSOR,n.p=null,n.A="SCALAR",n.m=null,n.T=!1,n.g=p,n.M=p,n.buffer=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.p=n.p.slice(),this.A=n.A,this.m=n.m,this.T=n.T,this.g=n.g,this.M=n.M,n.buffer&&this.setBuffer(r(n.buffer.getChild())),this},n.getElementSize=function(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}},n.getComponentSize=function(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}},r.getMinNormalized=function(t){var n=this.getElementSize();this.getMin(t);for(var r=0;r<n;r++)t[r]=this.M(t[r]);return t},r.getMin=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.min(t[e],s))}return t},r.getMaxNormalized=function(t){var n=this.getElementSize();this.getMax(t);for(var r=0;r<n;r++)t[r]=this.M(t[r]);return t},r.getMax=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=-Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.max(t[e],s))}return t},r.getCount=function(){return this.p.length/this.getElementSize()},r.getType=function(){return this.A},r.setType=function(t){return this.A=t,this},r.getElementSize=function(){return n.getElementSize(this.A)},r.getComponentSize=function(){return this.p.BYTES_PER_ELEMENT},r.getComponentType=function(){return this.m},r.getNormalized=function(){return this.T},r.setNormalized=function(t){var n=this;return this.T=t,t?(this.M=function(t){return function(t,n){switch(n){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}(t,n.m)},this.g=function(t){return function(t,n){switch(n){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}(t,n.m)}):(this.M=p,this.g=p),this},r.getScalar=function(t){var n=this.getElementSize();return this.M(this.p[t*n])},r.setScalar=function(t,n){return this.p[t*this.getElementSize()]=this.g(n),this},r.getElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)n[i]=this.M(this.p[t*r+i]);return n},r.setElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)this.p[t*r+i]=this.g(n[i]);return this},r.getBuffer=function(){return this.buffer.getChild()},r.setBuffer=function(t){return this.buffer=this.graph.link("buffer",this,t),this},r.getArray=function(){return this.p},r.setArray=function(t){return this.m=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.p=t,this},r.getByteLength=function(){return this.p.byteLength},n}(l);function p(t){return t}d.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},d.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},s([f],d.prototype,"buffer",void 0);var w=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION,n.channels=[],n.samplers=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),n.channels.forEach(function(t){return i.addChannel(r(t.getChild()))}),n.samplers.forEach(function(t){return i.addSampler(r(t.getChild()))}),this},r.addChannel=function(t){var n=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,n)},r.removeChannel=function(t){return this.removeGraphChild(this.channels,t)},r.listChannels=function(){return this.channels.map(function(t){return t.getChild()})},r.addSampler=function(t){var n=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,n)},r.removeSampler=function(t){return this.removeGraphChild(this.samplers,t)},r.listSamplers=function(){return this.samplers.map(function(t){return t.getChild()})},n}(l);s([c],w.prototype,"channels",void 0),s([c],w.prototype,"samplers",void 0);var x=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION_CHANNEL,n.S=null,n.targetNode=null,n.sampler=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.S=n.S,n.targetNode&&this.setTargetNode(r(n.targetNode.getChild())),n.sampler&&this.setSampler(r(n.sampler.getChild())),this},r.getTargetPath=function(){return this.S},r.setTargetPath=function(t){return this.S=t,this},r.getTargetNode=function(){return this.targetNode?this.targetNode.getChild():null},r.setTargetNode=function(t){return this.targetNode=this.graph.link("target.node",this,t),this},r.getSampler=function(){return this.sampler?this.sampler.getChild():null},r.setSampler=function(t){return this.sampler=this.graph.link("sampler",this,t),this},n}(v);s([f],x.prototype,"targetNode",void 0),s([f],x.prototype,"sampler",void 0);var A=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION_SAMPLER,n.R="LINEAR",n.input=null,n.output=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.R=n.R,n.input&&this.setInput(r(n.input.getChild())),n.output&&this.setOutput(r(n.output.getChild())),this},r.getInterpolation=function(){return this.R},r.setInterpolation=function(t){return this.R=t,this},r.getInput=function(){return this.input?this.input.getChild():null},r.setInput=function(t){return this.input=this.graph.link("input",this,t),this},r.getOutput=function(){return this.output?this.output.getChild():null},r.setOutput=function(t){return this.output=this.graph.link("output",this,t),this},n}(v);s([f],A.prototype,"input",void 0),s([f],A.prototype,"output",void 0);var b=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.BUFFER,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.N=n.N,this},r.getURI=function(){return this.N},r.setURI=function(t){return this.N=t,this},n}(l),y=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.CAMERA,n.A="perspective",n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.A=n.A,this.U=n.U,this.I=n.I,this.O=n.O,this._=n._,this.j=n.j,this.L=n.L,this},r.getType=function(){return this.A},r.setType=function(t){return this.A=t,this},r.getZNear=function(){return this.U},r.setZNear=function(t){return this.U=t,this},r.getZFar=function(){return this.I},r.setZFar=function(t){return this.I=t,this},r.getAspectRatio=function(){return this.O},r.setAspectRatio=function(t){return this.O=t,this},r.getYFov=function(){return this._},r.setYFov=function(t){return this._=t,this},r.getXMag=function(){return this.j},r.setXMag=function(t){return this.j=t,this},r.getYMag=function(){return this.L},r.setYMag=function(t){return this.L=t,this},n}(l),m=function(t){function n(n,r){var i;return(i=t.call(this,n)||this).k=r,i.k.addExtensionProperty(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i)),i}i(n,t);var r=n.prototype;return r.dispose=function(){this.k.removeExtensionProperty(this),t.prototype.dispose.call(this)},r.l=function(t){if(!this.parentTypes.includes(t.propertyType))throw new Error('Parent "'+t.propertyType+'" invalid for child "'+this.propertyType+'".')},n}(v),E=function(){function t(){}return t.createBufferFromDataURI=function(t){if("undefined"==typeof Buffer){for(var n=atob(t.split(",")[1]),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}var u=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(u,e?"base64":"utf8"))},t.encodeText=function(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))},t.decodeText=function(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")},t.trim=function(t){var n=t.byteOffset;return t.buffer.slice(n,n+t.byteLength)},t.concat=function(t){for(var n,r=0,i=e(t);!(n=i()).done;)r+=n.value.byteLength;for(var u,s=new Uint8Array(r),o=0,h=e(t);!(u=h()).done;){var f=u.value;s.set(new Uint8Array(f),o),o+=f.byteLength}return s.buffer},t.pad=function(t,n){void 0===n&&(n=0);var r=this.padNumber(t.byteLength);if(r!==t.byteLength){var i=new Uint8Array(r);if(i.set(new Uint8Array(t)),0!==n)for(var u=t.byteLength;u<r;u++)i[u]=n;return i.buffer}return t},t.padNumber=function(t){return 4*Math.ceil(t/4)},t.equals=function(t,n){if(t===n)return!0;if(t.byteLength!==n.byteLength)return!1;for(var r=new DataView(t),i=new DataView(n),u=t.byteLength;u--;)if(r.getUint8(u)!==i.getUint8(u))return!1;return!0},t}(),T=function(){function t(){}return t.basename=function(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()},t.extension=function(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"},t}(),g=function(){function t(){}return t.getSizeJPEG=function(t){var n,r;for(t=t.slice(4);t.length;){if(n=t.readUInt16BE(0),M(t,n),192===(r=t[n+1])||193===r||194===r)return[t.readUInt16BE(n+7),t.readUInt16BE(n+5)];t=t.slice(n+2)}throw new TypeError("Invalid JPG, no size found")},t.getSizePNG=function(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]},t.mimeTypeToExtension=function(t){return"image/jpeg"===t?"jpg":t.split("/").pop()},t.extensionToMimeType=function(t){return"jpg"===t?"image/jpeg":"image/"+t},t}();function M(t,n){if(n>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[n])throw new TypeError("Invalid JPG, marker table corrupted")}var S=function(){function t(t){this.verbosity=t}var n=t.prototype;return n.debug=function(n){this.verbosity<=t.Verbosity.DEBUG&&console.debug(n)},n.info=function(n){this.verbosity<=t.Verbosity.INFO&&console.info(n)},n.warn=function(n){this.verbosity<=t.Verbosity.WARN&&console.warn(n)},n.error=function(n){this.verbosity<=t.Verbosity.ERROR&&console.error(n)},t}();S.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};var R="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",N=new Set,U=function(){for(var t="",n=0;n<6;n++)t+=R.charAt(Math.floor(Math.random()*R.length));return t},I=function(){for(var t=0;t<999;t++){var n=U();if(!N.has(n))return N.add(n),n}},O=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.TEXTURE,n.image=null,n.mimeType="",n.uri="",n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.mimeType=n.mimeType,this.uri=n.uri,n.image&&(this.image=n.image.slice(0)),this},r.getMimeType=function(){return this.mimeType},r.setMimeType=function(t){return this.mimeType=t,this},r.getURI=function(){return this.uri},r.setURI=function(t){return this.uri=t,this},r.getImage=function(){return this.image},r.setImage=function(t){return this.image=t,this},r.getSize=function(){return(this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/))?g.getSizePNG(Buffer.from(this.image)):g.getSizeJPEG(Buffer.from(this.image))},n}(l),_=function(){function t(){this.propertyType=exports.PropertyType.TEXTURE_INFO,this.texCoord=0}var n=t.prototype;return n.copy=function(t){return this.texCoord=t.texCoord,this},n.getTexCoord=function(){return this.texCoord},n.setTexCoord=function(t){return this.texCoord=t,this},t}(),j=function(){function t(){this.propertyType=exports.PropertyType.TEXTURE_SAMPLER,this.C=null,this.B=null,this.P=10497,this.V=10497}var n=t.prototype;return n.copy=function(t){return this.C=t.C,this.B=t.B,this.P=t.P,this.V=t.V,this},n.getMagFilter=function(){return this.C},n.setMagFilter=function(t){return this.C=t,this},n.getMinFilter=function(){return this.B},n.setMinFilter=function(t){return this.B=t,this},n.getWrapS=function(){return this.P},n.setWrapS=function(t){return this.P=t,this},n.getWrapT=function(){return this.V},n.setWrapT=function(t){return this.V=t,this},t}();j.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},j.TextureMagFilter={NEAREST:9728,LINEAR:9729},j.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var L=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).textureInfo=new _,n.sampler=new j,n}return i(n,t),n.prototype.copy=function(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this},n}(o),k=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).semantic="",n}return i(n,t),n.prototype.copy=function(t){return this.semantic=t.semantic,this},n}(o),C=function(t){function n(){return t.apply(this,arguments)||this}return i(n,t),n.prototype.copy=function(t){return this},n}(o),B=function(t){function n(){return t.apply(this,arguments)||this}i(n,t);var r=n.prototype;return r.linkTexture=function(t,n,r){if(!r)return null;var i=new L(t,n,r);return this.registerLink(i),i},r.linkAttribute=function(t,n,r){if(!r)return null;var i=new k(t,n,r);return this.registerLink(i),i},r.linkIndex=function(t,n,r){if(!r)return null;var i=new C(t,n,r);return this.registerLink(i),i},n}(h),P=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.MATERIAL,n.D="OPAQUE",n.G=.5,n.F=!1,n.J=[1,1,1,1],n.$=[0,0,0],n.q=1,n.Y=1,n.H=1,n.K=1,n.baseColorTexture=null,n.emissiveTexture=null,n.normalTexture=null,n.occlusionTexture=null,n.metallicRoughnessTexture=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.D=n.D,this.G=n.G,this.F=n.F,this.J=[].concat(n.J),this.$=[].concat(n.$),this.q=n.q,this.Y=n.Y,this.H=n.H,this.K=n.K,n.baseColorTexture&&(this.setBaseColorTexture(r(n.baseColorTexture.getChild())),this.baseColorTexture.copy(n.baseColorTexture)),n.emissiveTexture&&(this.setEmissiveTexture(r(n.emissiveTexture.getChild())),this.emissiveTexture.copy(n.emissiveTexture)),n.normalTexture&&(this.setNormalTexture(r(n.normalTexture.getChild())),this.normalTexture.copy(n.normalTexture)),n.occlusionTexture&&(this.setOcclusionTexture(r(n.occlusionTexture.getChild())),this.occlusionTexture.copy(n.occlusionTexture)),n.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(r(n.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(n.metallicRoughnessTexture)),this},r.getDoubleSided=function(){return this.F},r.setDoubleSided=function(t){return this.F=t,this},r.getAlphaMode=function(){return this.D},r.setAlphaMode=function(t){return this.D=t,this},r.getAlphaCutoff=function(){return this.G},r.setAlphaCutoff=function(t){return this.G=t,this},r.getBaseColorFactor=function(){return this.J},r.setBaseColorFactor=function(t){return this.J=t,this},r.getBaseColorTexture=function(){return this.baseColorTexture?this.baseColorTexture.getChild():null},r.getBaseColorTextureInfo=function(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null},r.getBaseColorTextureSampler=function(){return this.baseColorTexture?this.baseColorTexture.sampler:null},r.setBaseColorTexture=function(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",this,t),this},r.getEmissiveFactor=function(){return this.$},r.setEmissiveFactor=function(t){return this.$=t,this},r.getEmissiveTexture=function(){return this.emissiveTexture?this.emissiveTexture.getChild():null},r.getEmissiveTextureInfo=function(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null},r.getEmissiveTextureSampler=function(){return this.emissiveTexture?this.emissiveTexture.sampler:null},r.setEmissiveTexture=function(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",this,t),this},r.getNormalScale=function(){return this.q},r.setNormalScale=function(t){return this.q=t,this},r.getNormalTexture=function(){return this.normalTexture?this.normalTexture.getChild():null},r.getNormalTextureInfo=function(){return this.normalTexture?this.normalTexture.textureInfo:null},r.getNormalTextureSampler=function(){return this.normalTexture?this.normalTexture.sampler:null},r.setNormalTexture=function(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this},r.getOcclusionStrength=function(){return this.Y},r.setOcclusionStrength=function(t){return this.Y=t,this},r.getOcclusionTexture=function(){return this.occlusionTexture?this.occlusionTexture.getChild():null},r.getOcclusionTextureInfo=function(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null},r.getOcclusionTextureSampler=function(){return this.occlusionTexture?this.occlusionTexture.sampler:null},r.setOcclusionTexture=function(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this},r.getRoughnessFactor=function(){return this.H},r.setRoughnessFactor=function(t){return this.H=t,this},r.getMetallicFactor=function(){return this.K},r.setMetallicFactor=function(t){return this.K=t,this},r.getMetallicRoughnessTexture=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null},r.getMetallicRoughnessTextureInfo=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null},r.getMetallicRoughnessTextureSampler=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null},r.setMetallicRoughnessTexture=function(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this},n}(l);s([f],P.prototype,"baseColorTexture",void 0),s([f],P.prototype,"emissiveTexture",void 0),s([f],P.prototype,"normalTexture",void 0),s([f],P.prototype,"occlusionTexture",void 0),s([f],P.prototype,"metallicRoughnessTexture",void 0);var V=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.MESH,n.W=[],n.primitives=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.W=[].concat(n.W),this.clearGraphChildList(this.primitives),n.primitives.forEach(function(t){return i.addPrimitive(r(t.getChild()))}),this},r.addPrimitive=function(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))},r.removePrimitive=function(t){return this.removeGraphChild(this.primitives,t)},r.listPrimitives=function(){return this.primitives.map(function(t){return t.getChild()})},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(l);s([c],V.prototype,"primitives",void 0);var D=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.PRIMITIVE,n.X=4,n.material=null,n.indices=null,n.attributes=[],n.targets=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.X=n.X,n.indices&&this.setIndices(r(n.indices.getChild())),n.material&&this.setMaterial(r(n.material.getChild())),this.clearGraphChildList(this.attributes),n.listSemantics().forEach(function(t){i.setAttribute(t,r(n.getAttribute(t)))}),this.clearGraphChildList(this.targets),n.targets.forEach(function(t){return i.addTarget(r(t.getChild()))}),this},r.getIndices=function(){return this.indices?this.indices.getChild():null},r.setIndices=function(t){return this.indices=this.graph.linkIndex("index",this,t),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.graph.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},r.getMaterial=function(){return this.material?this.material.getChild():null},r.setMaterial=function(t){return this.material=this.graph.link("material",this,t),this},r.getMode=function(){return this.X},r.setMode=function(t){return this.X=t,this},r.listTargets=function(){return this.targets.map(function(t){return t.getChild()})},r.addTarget=function(t){return this.addGraphChild(this.targets,this.graph.link("target",this,t)),this},r.removeTarget=function(t){return this.removeGraphChild(this.targets,t)},n}(v);s([f],D.prototype,"material",void 0),s([f],D.prototype,"indices",void 0),s([c],D.prototype,"attributes",void 0),s([c],D.prototype,"targets",void 0);var G=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.PRIMITIVE_TARGET,n.attributes=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.attributes),n.listSemantics().forEach(function(t){i.setAttribute(t,r(n.getAttribute(t)))}),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.graph.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},n}(v);s([c],G.prototype,"attributes",void 0);var F=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.NODE,n.Z=[0,0,0],n.tt=[0,0,0,1],n.nt=[1,1,1],n.W=[],n.camera=null,n.mesh=null,n.skin=null,n.children=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.Z=[].concat(n.Z),this.tt=[].concat(n.tt),this.nt=[].concat(n.nt),this.W=[].concat(n.W),n.camera&&this.setCamera(r(n.camera.getChild())),n.mesh&&this.setMesh(r(n.mesh.getChild())),n.skin&&this.setSkin(r(n.skin.getChild())),this.clearGraphChildList(this.children),n.children.forEach(function(t){return i.addChild(r(t.getChild()))}),this},r.getTranslation=function(){return this.Z},r.getRotation=function(){return this.tt},r.getScale=function(){return this.nt},r.setTranslation=function(t){return this.Z=t,this},r.setRotation=function(t){return this.tt=t,this},r.setScale=function(t){return this.nt=t,this},r.addChild=function(t){var n=this.graph.link("child",this,t);return this.addGraphChild(this.children,n)},r.removeChild=function(t){return this.removeGraphChild(this.children,t)},r.listChildren=function(){return this.children.map(function(t){return t.getChild()})},r.getMesh=function(){return this.mesh?this.mesh.getChild():null},r.setMesh=function(t){return this.mesh=this.graph.link("mesh",this,t),this},r.getCamera=function(){return this.camera?this.camera.getChild():null},r.setCamera=function(t){return this.camera=this.graph.link("camera",this,t),this},r.getSkin=function(){return this.skin?this.skin.getChild():null},r.setSkin=function(t){return this.skin=this.graph.link("skin",this,t),this},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(l);s([f],F.prototype,"camera",void 0),s([f],F.prototype,"mesh",void 0),s([f],F.prototype,"skin",void 0),s([c],F.prototype,"children",void 0);var J=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ROOT,n.rt={generator:"glTF-Transform v0.5.0",version:"2.0"},n.it=new Set,n.accessors=[],n.animations=[],n.buffers=[],n.cameras=[],n.materials=[],n.meshes=[],n.nodes=[],n.scenes=[],n.skins=[],n.textures=[],n}i(n,t);var r=n.prototype;return r.clone=function(){throw new Error("Root cannot be cloned.")},r.copy=function(n,r){var i=this;if(void 0===r&&(r=a),t.prototype.copy.call(this,n,r),!r)throw new Error("Root cannot be copied.");return Object.assign(this.rt,n.rt),n.accessors.forEach(function(t){return i.ut(r(t.getChild()))}),n.animations.forEach(function(t){return i.et(r(t.getChild()))}),n.buffers.forEach(function(t){return i.st(r(t.getChild()))}),n.cameras.forEach(function(t){return i.ot(r(t.getChild()))}),n.materials.forEach(function(t){return i.ht(r(t.getChild()))}),n.meshes.forEach(function(t){return i.ft(r(t.getChild()))}),n.nodes.forEach(function(t){return i.ct(r(t.getChild()))}),n.scenes.forEach(function(t){return i.at(r(t.getChild()))}),n.skins.forEach(function(t){return i.vt(r(t.getChild()))}),n.textures.forEach(function(t){return i.lt(r(t.getChild()))}),this},r.getAsset=function(){return this.rt},r.listExtensionsUsed=function(){return Array.from(this.it)},r.listExtensionsRequired=function(){return this.listExtensionsUsed().filter(function(t){return t.isRequired()})},r.dt=function(t){if(this.it.has(t))throw new Error('Extension "'+t.extensionName+'" is already enabled.');return this.it.add(t),this},r.pt=function(t){return this.it.delete(t),this},r.at=function(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))},r.listScenes=function(){return this.scenes.map(function(t){return t.getChild()})},r.ct=function(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},r.ot=function(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))},r.listCameras=function(){return this.cameras.map(function(t){return t.getChild()})},r.vt=function(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))},r.listSkins=function(){return this.skins.map(function(t){return t.getChild()})},r.ft=function(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))},r.listMeshes=function(){return this.meshes.map(function(t){return t.getChild()})},r.ht=function(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))},r.listMaterials=function(){return this.materials.map(function(t){return t.getChild()})},r.lt=function(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))},r.listTextures=function(){return this.textures.map(function(t){return t.getChild()})},r.et=function(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))},r.listAnimations=function(){return this.animations.map(function(t){return t.getChild()})},r.ut=function(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))},r.listAccessors=function(){return this.accessors.map(function(t){return t.getChild()})},r.st=function(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))},r.listBuffers=function(){return this.buffers.map(function(t){return t.getChild()})},n}(v);s([c],J.prototype,"accessors",void 0),s([c],J.prototype,"animations",void 0),s([c],J.prototype,"buffers",void 0),s([c],J.prototype,"cameras",void 0),s([c],J.prototype,"materials",void 0),s([c],J.prototype,"meshes",void 0),s([c],J.prototype,"nodes",void 0),s([c],J.prototype,"scenes",void 0),s([c],J.prototype,"skins",void 0),s([c],J.prototype,"textures",void 0);var z=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.SCENE,n.nodes=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.nodes),n.nodes.forEach(function(t){return i.addNode(r(t.getChild()))}),this},r.addNode=function(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},n}(l);s([c],z.prototype,"nodes",void 0);var $=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.SKIN,n.skeleton=null,n.inverseBindMatrices=null,n.joints=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),n.skeleton&&this.setSkeleton(r(n.skeleton.getChild())),n.inverseBindMatrices&&this.setInverseBindMatrices(r(n.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),n.joints.forEach(function(t){return i.addJoint(r(t.getChild()))}),this},r.getSkeleton=function(){return this.skeleton?this.skeleton.getChild():null},r.setSkeleton=function(t){return this.skeleton=this.graph.link("skeleton",this,t),this},r.getInverseBindMatrices=function(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null},r.setInverseBindMatrices=function(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this},r.addJoint=function(t){var n=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,n)},r.removeJoint=function(t){return this.removeGraphChild(this.joints,t)},r.listJoints=function(){return this.joints.map(function(t){return t.getChild()})},n}(l);s([f],$.prototype,"skeleton",void 0),s([f],$.prototype,"inverseBindMatrices",void 0),s([c],$.prototype,"joints",void 0);var q=function(){function t(){this.graph=new B,this.root=new J(this.graph),this.logger=new S(S.Verbosity.INFO)}var n=t.prototype;return n.getRoot=function(){return this.root},n.getGraph=function(){return this.graph},n.getLogger=function(){return this.logger},n.setLogger=function(t){return this.logger=t,this},n.clone=function(){return(new t).merge(this)},n.merge=function(t){for(var n,r={},i=e(t.getRoot().listExtensionsUsed());!(n=i()).done;){var u=n.value,s=this.createExtension(u.constructor);u.isRequired()&&s.setRequired(!0),r[s.extensionName]=s}var o=new Set,h=new Map;o.add(t.root),h.set(t.root,this.root);for(var f,c=e(t.graph.getLinks());!(f=c()).done;)for(var a=f.value,v=0,l=[a.getParent(),a.getChild()];v<l.length;v++){var d=l[v];if(!o.has(d)){var p=d.constructor,w=d instanceof m?new p(this.graph,r[d.extensionName]):new p(this.graph);h.set(d,w),o.add(d)}}for(var x,A=function(t){return h.get(t)},b=e(o);!(x=b()).done;){var y=x.value;h.get(y).copy(y,A)}return this},n.transform=function(){for(var t,n=e([].slice.call(arguments));!(t=n()).done;){var r=t.value;r(this)}return this},n.createExtension=function(t){return this.getRoot().listExtensionsUsed().find(function(n){return n.extensionName===t.EXTENSION_NAME})||new t(this)},n.createScene=function(t){var n=new z(this.graph,t);return this.root.at(n),n},n.createNode=function(t){var n=new F(this.graph,t);return this.root.ct(n),n},n.createCamera=function(t){var n=new y(this.graph,t);return this.root.ot(n),n},n.createSkin=function(t){var n=new $(this.graph,t);return this.root.vt(n),n},n.createMesh=function(t){var n=new V(this.graph,t);return this.root.ft(n),n},n.createPrimitive=function(){return new D(this.graph)},n.createPrimitiveTarget=function(t){return new G(this.graph,t)},n.createMaterial=function(t){var n=new P(this.graph,t);return this.root.ht(n),n},n.createTexture=function(t){var n=new O(this.graph,t);return this.root.lt(n),n},n.createAnimation=function(t){var n=new w(this.graph,t);return this.root.et(n),n},n.createAnimationChannel=function(){return new x(this.graph)},n.createAnimationSampler=function(){return new A(this.graph)},n.createAccessor=function(t,n){void 0===n&&(n=null),n||(n=this.getRoot().listBuffers()[0]);var r=new d(this.graph,t).setBuffer(n);return this.root.ut(r),r},n.createBuffer=function(t){var n=new b(this.graph,t);return this.root.st(n),n},t}(),Y=function(){function t(t){this.doc=t,this.provideTypes=[],this.wt=!1,this.xt=new Set,t.getRoot().dt(this)}var n=t.prototype;return n.dispose=function(){this.doc.getRoot().pt(this);for(var t,n=e(this.xt);!(t=n()).done;)t.value.dispose()},n.isRequired=function(){return this.wt},n.setRequired=function(t){return this.wt=t,this},n.addExtensionProperty=function(t){return this.xt.add(t),this},n.removeExtensionProperty=function(t){return this.xt.delete(t),this},n.provide=function(t,n){return this},t}(),H=function(){function t(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=[]}var n=t.prototype;return n.setTextureInfo=function(t,n){void 0!==n.texCoord&&t.setTexCoord(n.texCoord)},n.setTextureSampler=function(t,n){var r=this.nativeDocument.json.textures[n.index];if(void 0!==r.sampler){var i=this.nativeDocument.json.samplers[r.sampler];void 0!==i.magFilter&&t.setMagFilter(i.magFilter),void 0!==i.minFilter&&t.setMinFilter(i.minFilter),void 0!==i.wrapS&&t.setWrapS(i.wrapS),void 0!==i.wrapT&&t.setWrapT(i.wrapT)}},t}(),K={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Q=function(){function t(){}return t.read=function(t,i){var u=t.json,s=new q;if("2.0"!==u.asset.version)throw new Error('Unsupported glTF version, "'+u.asset.version+'".');if(u.extensionsRequired)for(var o,h=function(){var t=o.value;if(!i.extensions.find(function(n){return n.EXTENSION_NAME===t}))throw new Error('Missing required extension, "'+t+'".')},f=e(u.extensionsRequired);!(o=f()).done;)h();s.getRoot().getAsset().generator=t.json.asset.generator;for(var c,a=new H(t),v=u.extensionsUsed||[],l=u.extensionsRequired||[],p=e(i.extensions);!(c=p()).done;){var w=c.value;v.includes(w.EXTENSION_NAME)&&s.createExtension(w).setRequired(l.includes(w.EXTENSION_NAME))}a.buffers=(u.buffers||[]).map(function(t){var n=s.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&n.setURI(t.uri),n}),a.bufferViewBuffers=(u.bufferViews||[]).map(function(t){return a.buffers[t.buffer]}),a.accessors=(u.accessors||[]).map(function(n){var i,u=s.createAccessor(n.name,a.bufferViewBuffers[n.bufferView]);return u.setType(n.type),i=void 0!==n.sparse?function(t,n){var i,u=K[t.componentType],e=d.getElementSize(t.type);i=void 0!==t.bufferView?W(t,n).slice():new u(t.count*e);for(var s=t.sparse.count,o=r(r(r({},t),t.sparse.indices),{},{count:s,type:"SCALAR"}),h=r(r(r({},t),t.sparse.values),{},{count:s}),f=W(o,n),c=W(h,n),a=0;a<o.count;a++)for(var v=0;v<e;v++)i[f[a]*e+v]=c[a*e+v];return i}(n,t):W(n,t).slice(),void 0!==n.normalized&&u.setNormalized(n.normalized),u.setArray(i),u});var x=u.images||[],A=u.textures||[];s.getRoot().listExtensionsUsed().filter(function(t){return t.provideTypes.includes(exports.PropertyType.TEXTURE)}).forEach(function(t){return t.provide(a,exports.PropertyType.TEXTURE)}),a.textures=x.map(function(n){var r=s.createTexture(n.name);if(void 0!==n.bufferView){var i=u.bufferViews[n.bufferView],e=t.json.buffers[i.buffer],o=i.byteOffset||0,h=(e.uri?t.resources[e.uri]:t.resources["At"]).slice(o,o+i.byteLength);r.setImage(h)}else void 0!==n.uri&&(r.setImage(t.resources[n.uri]),0!==n.uri.indexOf("__")&&r.setURI(n.uri));if(void 0!==n.mimeType)r.setMimeType(n.mimeType);else if(n.uri){var f=T.extension(n.uri);r.setMimeType(g.extensionToMimeType(f))}return r}),a.materials=(u.materials||[]).map(function(t){var n=s.createMaterial(t.name);void 0!==t.alphaMode&&n.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&n.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&n.setDoubleSided(t.doubleSided);var r=t.pbrMetallicRoughness||{};if(void 0!==r.baseColorFactor&&n.setBaseColorFactor(r.baseColorFactor),void 0!==t.emissiveFactor&&n.setEmissiveFactor(t.emissiveFactor),void 0!==r.metallicFactor&&n.setMetallicFactor(r.metallicFactor),void 0!==r.roughnessFactor&&n.setRoughnessFactor(r.roughnessFactor),void 0!==r.baseColorTexture){var i=r.baseColorTexture;n.setBaseColorTexture(a.textures[A[i.index].source]),a.setTextureInfo(n.getBaseColorTextureInfo(),i),a.setTextureSampler(n.getBaseColorTextureSampler(),i)}if(void 0!==t.emissiveTexture){var u=t.emissiveTexture;n.setEmissiveTexture(a.textures[A[u.index].source]),a.setTextureInfo(n.getEmissiveTextureInfo(),u),a.setTextureSampler(n.getEmissiveTextureSampler(),u)}if(void 0!==t.normalTexture){var e=t.normalTexture;n.setNormalTexture(a.textures[A[e.index].source]),a.setTextureInfo(n.getNormalTextureInfo(),e),a.setTextureSampler(n.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&n.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){var o=t.occlusionTexture;n.setOcclusionTexture(a.textures[A[o.index].source]),a.setTextureInfo(n.getOcclusionTextureInfo(),o),a.setTextureSampler(n.getOcclusionTextureSampler(),o),void 0!==t.occlusionTexture.strength&&n.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==r.metallicRoughnessTexture){var h=r.metallicRoughnessTexture;n.setMetallicRoughnessTexture(a.textures[A[h.index].source]),a.setTextureInfo(n.getMetallicRoughnessTextureInfo(),h),a.setTextureSampler(n.getMetallicRoughnessTextureSampler(),h)}return n}),a.meshes=(u.meshes||[]).map(function(t){var n=s.createMesh(t.name);return void 0!==t.weights&&n.setWeights(t.weights),t.primitives.forEach(function(r){var i=s.createPrimitive();void 0!==r.material&&i.setMaterial(a.materials[r.material]),void 0!==r.mode&&i.setMode(r.mode);for(var u=0,e=Object.entries(r.attributes||{});u<e.length;u++){var o=e[u];i.setAttribute(o[0],a.accessors[o[1]])}void 0!==r.indices&&i.setIndices(a.accessors[r.indices]);var h=t.extras&&t.extras.targetNames||[];(r.targets||[]).forEach(function(t,n){for(var r=h[n]||n.toString(),u=s.createPrimitiveTarget(r),e=0,o=Object.entries(t);e<o.length;e++){var f=o[e];u.setAttribute(f[0],a.accessors[f[1]])}i.addTarget(u)}),n.addPrimitive(i)}),n}),a.cameras=(u.cameras||[]).map(function(t){var n=s.createCamera(t.name).setType(t.type);return"perspective"===t.type?n.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):n.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),n});var b=u.nodes||[];return a.nodes=b.map(function(t){var r=s.createNode(t.name);return void 0!==t.translation&&r.setTranslation(t.translation),void 0!==t.rotation&&r.setRotation(t.rotation),void 0!==t.scale&&r.setScale(t.scale),void 0!==t.matrix&&(r.setTranslation(n.getTranslation([],t.matrix)),r.setRotation(n.getRotation([],t.matrix)),r.setScale(n.getScaling([],t.matrix))),void 0!==t.weights&&r.setWeights(t.weights),r}),a.skins=(u.skins||[]).map(function(t){var n=s.createSkin(t.name);void 0!==t.inverseBindMatrices&&n.setInverseBindMatrices(a.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&n.setSkeleton(a.nodes[t.skeleton]);for(var r,i=e(t.joints);!(r=i()).done;)n.addJoint(a.nodes[r.value]);return n}),b.map(function(t,n){var r=a.nodes[n];(t.children||[]).forEach(function(t){return r.addChild(a.nodes[t])}),void 0!==t.mesh&&r.setMesh(a.meshes[t.mesh]),void 0!==t.camera&&r.setCamera(a.cameras[t.camera]),void 0!==t.skin&&r.setSkin(a.skins[t.skin])}),a.animations=(u.animations||[]).map(function(t){var n=s.createAnimation(t.name),r=(t.samplers||[]).map(function(t){var r=s.createAnimationSampler().setInput(a.accessors[t.input]).setOutput(a.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return n.addSampler(r),r});return(t.channels||[]).forEach(function(t){var i=s.createAnimationChannel().setSampler(r[t.sampler]).setTargetNode(a.nodes[t.target.node]).setTargetPath(t.target.path);n.addChannel(i)}),n}),a.scenes=(u.scenes||[]).map(function(t){var n=s.createScene(t.name);return(t.nodes||[]).map(function(t){return a.nodes[t]}).forEach(function(t){return n.addNode(t)}),n}),s.getRoot().listExtensionsUsed().forEach(function(t){return t.read(a)}),s},t}();function W(t,n){var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["At"],e=K[t.componentType],s=d.getElementSize(t.type);if(void 0!==r.byteStride&&r.byteStride!==s*e.BYTES_PER_ELEMENT)return function(t,n){for(var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["At"],e=K[t.componentType],s=d.getElementSize(t.type),o=e.BYTES_PER_ELEMENT,h=t.byteOffset||0,f=new e(t.count*s),c=new DataView(u,r.byteOffset,r.byteLength),a=r.byteStride,v=0;v<t.count;v++)for(var l=0;l<s;l++){var p=h+v*a+l*o,w=void 0;switch(t.componentType){case 5126:w=c.getFloat32(p,!0);break;case 5125:w=c.getUint32(p,!0);break;case 5123:w=c.getUint16(p,!0);break;case 5121:w=c.getUint8(p);break;case 5122:w=c.getInt16(p,!0);break;case 5120:w=c.getInt8(p);break;default:throw new Error('Unexpected componentType "'+t.componentType+'".')}f[v*s+l]=w}return f}(t,n);var o=(r.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(u,o,t.count*s);case 5125:return new Uint32Array(u,o,t.count*s);case 5123:return new Uint16Array(u,o,t.count*s);case 5121:return new Uint8Array(u,o,t.count*s);case 5122:return new Int16Array(u,o,t.count*s);case 5120:return new Int8Array(u,o,t.count*s);default:throw new Error('Unexpected componentType "'+t.componentType+'".')}}var X=function(){function t(t,n){this.nativeDocument=t,this.options=n,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}var n=t.prototype;return n.createTextureInfoDef=function(t,n,r){var i={magFilter:r.getMagFilter()||void 0,minFilter:r.getMinFilter()||void 0,wrapS:r.getWrapS(),wrapT:r.getWrapT()},u=JSON.stringify(i);this.samplerDefIndexMap.has(u)||(this.samplerDefIndexMap.set(u,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(i));var e={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(u)},s=JSON.stringify(e);return this.textureDefIndexMap.has(s)||(this.textureDefIndexMap.set(s,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(e)),{index:this.textureDefIndexMap.get(s),texCoord:n.getTexCoord()}},n.createPropertyDef=function(t){var n={};return t.getName()&&(n.name=t.getName()),Object.keys(t.getExtras()).length>0&&(n.extras=t.getExtras()),n},n.createAccessorDef=function(t){var n=this.createPropertyDef(t);return n.type=t.getType(),n.componentType=t.getComponentType(),n.count=t.getCount(),t.getMax(n.max=[]),t.getMin(n.min=[]),n.normalized=t.getNormalized(),n},n.createImageData=function(t,n,r){if(this.options.isGLB)this.imageData.push(n),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:n.byteLength});else{var i=g.mimeTypeToExtension(r.getMimeType());t.uri=this.imageURIGenerator.createURI(r,i),this.nativeDocument.resources[t.uri]=n}},t}(),Z=function(){function t(t,n){this.multiple=t,this.basename=n,this.counter=1}return t.prototype.createURI=function(t,n){return t.getURI()?t.getURI():this.multiple?this.basename+"_"+this.counter+++"."+n:this.basename+"."+n},t}(),tt=function(){function t(){}return t.write=function(t,n){var r=t.getRoot(),i={json:{asset:r.getAsset()},resources:{}},u=i.json;u.asset.generator="glTF-Transform v0.5.0";var s=new X(i,n),o=r.listBuffers().length,h=r.listTextures().length;function f(t,n,r,i){for(var o,h=[],f=0,c=e(t);!(o=c()).done;){var a=o.value,v=s.createAccessorDef(a);v.bufferView=u.bufferViews.length;var l=E.pad(a.getArray().buffer);v.byteOffset=f,f+=l.byteLength,h.push(l),s.accessorIndexMap.set(a,u.accessors.length),u.accessors.push(v)}var d={buffer:n,byteOffset:r,byteLength:E.concat(h).byteLength};return i&&(d.target=i),u.bufferViews.push(d),{buffers:h,byteLength:f}}function c(t,n,r){for(var i,o=t[0].getCount(),h=0,f=e(t);!(i=f()).done;){var c=i.value,a=s.createAccessorDef(c);a.bufferView=u.bufferViews.length,a.byteOffset=h;var v=c.getElementSize(),l=c.getComponentSize();h+=E.padNumber(v*l),s.accessorIndexMap.set(c,u.accessors.length),u.accessors.push(a)}for(var d=o*h,p=new ArrayBuffer(d),w=new DataView(p),x=0;x<o;x++)for(var A,b=0,y=e(t);!(A=y()).done;){for(var m=A.value,T=m.getElementSize(),g=m.getComponentSize(),M=m.getComponentType(),S=m.getArray(),R=0;R<T;R++){var N=x*h+b+R*g,U=S[x*T+R];switch(M){case 5126:w.setFloat32(N,U,!0);break;case 5120:w.setInt8(N,U);break;case 5122:w.setInt16(N,U,!0);break;case 5121:w.setUint8(N,U);break;case 5123:w.setUint16(N,U,!0);break;case 5125:w.setUint32(N,U,!0);break;default:throw new Error("Unexpected component type: "+M)}}b+=E.padNumber(T*g)}return u.bufferViews.push({buffer:n,byteOffset:r,byteLength:d,byteStride:h,target:34962}),{byteLength:d,buffers:[p]}}s.bufferURIGenerator=new Z(o>1,n.basename),s.imageURIGenerator=new Z(h>1,n.basename),s.logger=t.getLogger();for(var a,v=new Map,l=e(t.getGraph().getLinks());!(a=l()).done;){var p=a.value;if(p.getParent()!==r){var w=p.getChild();if(w instanceof d){var x=v.get(w)||[];x.push(p),v.set(w,x)}}}return u.accessors=[],u.bufferViews=[],u.samplers=[],u.textures=[],u.images=r.listTextures().map(function(t,n){var r=s.createPropertyDef(t);return t.getMimeType()&&(r.mimeType=t.getMimeType()),t.getImage()&&s.createImageData(r,t.getImage(),t),s.imageIndexMap.set(t,n),r}),u.buffers=[],r.listBuffers().forEach(function(t){for(var r,o=s.createPropertyDef(t),h=new Map,a=new Set,l=new Set,p=e(t.listParents().filter(function(t){return!(t instanceof J)}));!(r=p()).done;){var w=r.value;if(!(w instanceof d))throw new Error("Unimplemented buffer reference: "+w);for(var x,A=!1,b=!1,y=!1,m=v.get(w)||[],T=e(m);!(x=T()).done;){var g=x.value;g instanceof k?A=!0:g instanceof C?b=!0:y=!0}if(A||b||y||(y=!0),!A||b||y)if(!b||A||y){if(!y||A||b)throw new Error("Attribute or index accessors must be used only for that purpose.");l.add(w)}else a.add(w);else{var M=m[0].getParent(),S=h.get(M)||new Set;S.add(w),h.set(M,S)}}var R,N=[],U=u.buffers.length,I=0;if(a.size){var O=f(Array.from(a),U,I,34963);I+=O.byteLength,N.push.apply(N,O.buffers)}for(var _=0,j=Array.from(h.values());_<j.length;_++){var L=j[_];if(L.size){var B=c(Array.from(L),U,I);I+=B.byteLength,N.push.apply(N,B.buffers)}}if(l.size){var P=f(Array.from(l),U,I);I+=P.byteLength,N.push.apply(N,P.buffers)}if(s.imageData.length)for(var V=0;V<s.imageData.length;V++)u.bufferViews[u.images[V].bufferView].byteOffset=I,I+=s.imageData[V].byteLength,N.push(s.imageData[V]);I?(n.isGLB?R="__glb.bin":(R=s.bufferURIGenerator.createURI(t,"bin"),o.uri=R),o.byteLength=I,i.resources[R]=E.concat(N),u.buffers.push(o)):s.logger.warn('@gltf-transform/core: Skipping empty buffer, "'+t.getName()+'".')}),u.materials=r.listMaterials().map(function(t,n){var r=s.createPropertyDef(t);if(r.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(r.alphaCutoff=t.getAlphaCutoff()),r.doubleSided=t.getDoubleSided(),r.pbrMetallicRoughness={},r.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),r.emissiveFactor=t.getEmissiveFactor(),r.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),r.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){var i=t.getBaseColorTexture(),u=t.getBaseColorTextureInfo(),e=t.getBaseColorTextureSampler();r.pbrMetallicRoughness.baseColorTexture=s.createTextureInfoDef(i,u,e)}if(t.getEmissiveTexture()){var o=t.getEmissiveTexture(),h=t.getEmissiveTextureInfo(),f=t.getEmissiveTextureSampler();r.emissiveTexture=s.createTextureInfoDef(o,h,f)}if(t.getNormalTexture()){var c=t.getNormalTexture(),a=t.getNormalTextureInfo(),v=t.getNormalTextureSampler(),l=s.createTextureInfoDef(c,a,v);1!==t.getNormalScale()&&(l.scale=t.getNormalScale()),r.normalTexture=l}if(t.getOcclusionTexture()){var d=t.getOcclusionTexture(),p=t.getOcclusionTextureInfo(),w=t.getOcclusionTextureSampler(),x=s.createTextureInfoDef(d,p,w);1!==t.getOcclusionStrength()&&(x.strength=t.getOcclusionStrength()),r.occlusionTexture=x}if(t.getMetallicRoughnessTexture()){var A=t.getMetallicRoughnessTexture(),b=t.getMetallicRoughnessTextureInfo(),y=t.getMetallicRoughnessTextureSampler();r.pbrMetallicRoughness.metallicRoughnessTexture=s.createTextureInfoDef(A,b,y)}return s.materialIndexMap.set(t,n),r}),u.meshes=r.listMeshes().map(function(t,n){var r,i=s.createPropertyDef(t);return i.primitives=t.listPrimitives().map(function(t){var n={attributes:{}};n.material=s.materialIndexMap.get(t.getMaterial()),n.mode=t.getMode(),t.getIndices()&&(n.indices=s.accessorIndexMap.get(t.getIndices()));for(var i,u=e(t.listSemantics());!(i=u()).done;){var o=i.value;n.attributes[o]=s.accessorIndexMap.get(t.getAttribute(o))}for(var h,f=e(t.listTargets());!(h=f()).done;){for(var c,a=h.value,v={},l=e(a.listSemantics());!(c=l()).done;){var d=c.value;v[d]=s.accessorIndexMap.get(a.getAttribute(d))}n.targets=n.targets||[],n.targets.push(v)}return t.listTargets().length&&!r&&(r=t.listTargets().map(function(t){return t.getName()})),n}),t.getWeights().length&&(i.weights=t.getWeights()),r&&(i.extras=i.extras||{},i.extras.targetNames=r),s.meshIndexMap.set(t,n),i}),u.cameras=r.listCameras().map(function(t,n){var r=s.createPropertyDef(t);return r.type=t.getType(),"perspective"===r.type?r.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:r.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},s.cameraIndexMap.set(t,n),r}),u.nodes=r.listNodes().map(function(t,n){var r=s.createPropertyDef(t);return r.translation=t.getTranslation(),r.rotation=t.getRotation(),r.scale=t.getScale(),t.getWeights().length&&(r.weights=t.getWeights()),s.nodeIndexMap.set(t,n),r}),u.skins=r.listSkins().map(function(t,n){var r=s.createPropertyDef(t);return t.getInverseBindMatrices()&&(r.inverseBindMatrices=s.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(r.skeleton=s.nodeIndexMap.get(t.getSkeleton())),r.joints=t.listJoints().map(function(t){return s.nodeIndexMap.get(t)}),s.skinIndexMap.set(t,n),r}),r.listNodes().forEach(function(t,n){var r=u.nodes[n];t.getMesh()&&(r.mesh=s.meshIndexMap.get(t.getMesh())),t.getCamera()&&(r.camera=s.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(r.skin=s.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(r.children=t.listChildren().map(function(t){return s.nodeIndexMap.get(t)}))}),u.animations=r.listAnimations().map(function(t){var n=s.createPropertyDef(t),r=new Map;return n.samplers=t.listSamplers().map(function(t,n){var i=s.createPropertyDef(t);return i.input=s.accessorIndexMap.get(t.getInput()),i.output=s.accessorIndexMap.get(t.getOutput()),i.interpolation=t.getInterpolation(),r.set(t,n),i}),n.channels=t.listChannels().map(function(t){var n=s.createPropertyDef(t);return n.sampler=r.get(t.getSampler()),n.target={node:s.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},n}),n}),u.scenes=r.listScenes().map(function(t){var n=s.createPropertyDef(t);return n.nodes=t.listNodes().map(function(t){return s.nodeIndexMap.get(t)}),n}),u.extensionsUsed=r.listExtensionsUsed().map(function(t){return t.extensionName}),u.extensionsRequired=r.listExtensionsRequired().map(function(t){return t.extensionName}),r.listExtensionsUsed().forEach(function(t){return t.write(s)}),function(t){var n=[];for(var r in t){var i=t[r];Array.isArray(i)&&0===i.length?n.push(r):null!==i&&""!==i||n.push(i)}for(var u=0,e=n;u<e.length;u++)delete t[e[u]]}(u),i},t}(),nt=function(){function t(){this.it=[]}var n=t.prototype;return n.registerExtensions=function(t){var n;return(n=this.it).push.apply(n,t),this},n.createDocument=function(t){return Q.read(t,{extensions:this.it})},n.createNativeDocument=function(t,n){if(n.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return tt.write(t,n)},n.unpackGLB=function(t){var n,r=new Uint32Array(t,0,3);if(1179937895!==r[0])throw new Error("Invalid glTF asset.");if(2!==r[1])throw new Error('Unsupported glTF binary version, "'+r[1]+'".');var i=new Uint32Array(t,12,2),u=i[0],e=new Uint32Array(t,20+u,2);if(1313821514!==i[1]||5130562!==e[1])throw new Error("Unexpected GLB layout.");var s=E.decodeText(t.slice(20,20+u)),o=JSON.parse(s),h=20+u+8,f=t.slice(h,h+e[0]);return this.createDocument({json:o,resources:(n={},n["At"]=f,n)})},n.packGLB=function(t){var n=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=n.resources,i=JSON.stringify(n.json),u=E.pad(E.encodeText(i),32),e=new Uint32Array([u.byteLength,1313821514]).buffer,s=E.concat([e,u]),o=E.pad(Object.values(r)[0]||new ArrayBuffer(0),0),h=new Uint32Array([o.byteLength,5130562]).buffer,f=E.concat([h,o]),c=new Uint32Array([1179937895,2,12+s.byteLength+f.byteLength]).buffer;return E.concat([c,s,f])},t}(),rt=function(t){function n(n,r){var i;return(i=t.call(this)||this).fs=n,i.path=r,i}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.write=function(t,n){t.match(/\.glb$/)?this.writeGLB(t,n):this.writeGLTF(t,n)},r.readGLB=function(t){var n=this.fs.readFileSync(t),r=E.trim(n);return this.unpackGLB(r)},r.readGLTF=function(t){var n=this,r=this.path.dirname(t),i={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[].concat(i.json.images||[],i.json.buffers||[]).forEach(function(t){if(t.uri&&!t.uri.match(/data:/)){var u=n.path.resolve(r,t.uri);i.resources[t.uri]=E.trim(n.fs.readFileSync(u))}else{var e="__"+I()+"."+T.extension(t.uri);i.resources[e]=E.createBufferFromDataURI(t.uri),t.uri=e}}),Q.read(i,{extensions:this.it})},r.writeGLTF=function(t,n){var r={basename:T.basename(t),isGLB:!1},i=tt.write(n,r),u=i.json,e=i.resources,s=this.fs,o=this.path,h=o.dirname(t);s.writeFileSync(t,JSON.stringify(u,null,2)),Object.keys(e).forEach(function(t){var n=Buffer.from(e[t]);s.writeFileSync(o.join(h,t),n)})},r.writeGLB=function(t,n){var r=Buffer.from(this.packGLB(n));this.fs.writeFileSync(t,r)},n}(nt),it=function(t){function n(n){var r;return(r=t.call(this)||this).fetchConfig=n,r}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.readGLTF=function(t){var n=this,r={json:{},resources:{}};return fetch(t,this.fetchConfig).then(function(t){return t.json()}).then(function(t){r.json=t;var i=[].concat(t.images,t.buffers).map(function(t){if(t.uri)return fetch(t.uri,n.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(n){r.resources[t.uri]=n})});return Promise.all(i).then(function(){return n.createDocument(r)})})},r.readGLB=function(t){var n=this;return fetch(t,this.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(t){return n.unpackGLB(t)})},n}(nt);exports.Accessor=d,exports.Animation=w,exports.AnimationChannel=x,exports.AnimationSampler=A,exports.Buffer=b,exports.BufferUtils=E,exports.COPY_IDENTITY=a,exports.Camera=y,exports.Document=q,exports.Extension=Y,exports.ExtensionProperty=m,exports.FileUtils=T,exports.Graph=h,exports.GraphChild=f,exports.ImageUtils=g,exports.Logger=S,exports.Material=P,exports.Mesh=V,exports.Node=F,exports.NodeIO=rt,exports.Primitive=D,exports.PrimitiveTarget=G,exports.Property=v,exports.ReaderContext=H,exports.Root=J,exports.Scene=z,exports.Skin=$,exports.Texture=O,exports.TextureInfo=_,exports.TextureLink=L,exports.TextureSampler=j,exports.WebIO=it,exports.WriterContext=X,exports.uuid=I; | ||
var t,n=require("gl-matrix/mat4");function r(){return(r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function i(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=t[r];return i}function e(t){var n=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,n){if(t){if("string"==typeof t)return u(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,void 0):void 0}}(t)))return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function s(t,n,r,i){var u,e=arguments.length,s=e<3?n:null===i?i=Object.getOwnPropertyDescriptor(n,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,n,r,i);else for(var o=t.length-1;o>=0;o--)(u=t[o])&&(s=(e<3?u(s):e>3?u(n,r,s):u(n,r))||s);return e>3&&s&&Object.defineProperty(n,r,s),s}(t=exports.PropertyType||(exports.PropertyType={})).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";var o=function(){function t(t,n,r){if(this.t=t,this.i=n,this.u=r,this.s=!1,this.o=[],!n.canLink(r))throw new Error("Cannot link disconnected graphs/documents.")}var n=t.prototype;return n.getName=function(){return this.t},n.getParent=function(){return this.i},n.getChild=function(){return this.u},n.setChild=function(t){return this.u=t,this},n.dispose=function(){this.s||(this.s=!0,this.o.forEach(function(t){return t()}),this.o.length=0)},n.onDispose=function(t){return this.o.push(t),this},n.isDisposed=function(){return this.s},t}(),h=function(){function t(){this.h=[]}var n=t.prototype;return n.getLinks=function(){return this.h},n.listParents=function(t){return this.h.filter(function(n){return n.getChild()===t}).map(function(t){return t.getParent()})},n.listChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).map(function(t){return t.getChild()})},n.disconnectChildren=function(t){return this.h.filter(function(n){return n.getParent()===t}).forEach(function(t){return t.dispose()}),this},n.disconnectParents=function(t,n){var r=this.h.filter(function(n){return n.getChild()===t});return n&&(r=r.filter(function(t){return n(t.getParent())})),r.forEach(function(t){return t.dispose()}),this},n.link=function(t,n,r){if(!r)return null;var i=new o(t,n,r);return this.registerLink(i),i},n.registerLink=function(t){var n=this;return this.h.push(t),t.onDispose(function(){return n.unlink(t)}),t},n.unlink=function(t){return this.h=this.h.filter(function(n){return n!==t}),this},t}();function f(t,n){Object.defineProperty(t,n,{get:function(){return this["__"+n]},set:function(t){var r=this,i=this["__"+n];i&&!Array.isArray(i)&&i.dispose(),t&&!Array.isArray(t)&&t.onDispose(function(){r["__"+n]=null}),this["__"+n]=t},enumerable:!0})}function c(t,n){}var a=function(t){return t},v=function(t){function n(n,r){var i;return void 0===r&&(r=""),(i=t.call(this,n)||this).v={},i.t="",i.t=r,i}i(n,t);var r=n.prototype;return r.getName=function(){return this.t},r.setName=function(t){return this.t=t,this},r.getExtras=function(){return this.v},r.setExtras=function(t){return this.v=t,this},r.clone=function(){return new(0,this.constructor)(this.graph).copy(this,a)},r.copy=function(t,n){return this.t=t.t,this.v=JSON.parse(JSON.stringify(t.v)),this},r.detach=function(){return this.graph.disconnectParents(this,function(t){return"Root"!==t.propertyType}),this},r.listParents=function(){return this.listGraphParents()},n}(function(){function t(t){this.s=!1,this.graph=t}var n=t.prototype;return n.canLink=function(t){return this.graph===t.graph},n.isDisposed=function(){return this.s},n.dispose=function(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.s=!0},n.detach=function(){return this.graph.disconnectParents(this),this},n.swap=function(t,n){var r=this;return this.graph.getLinks().filter(function(n){return n.getParent()===r&&n.getChild()===t}).forEach(function(t){return t.setChild(n)}),this},n.addGraphChild=function(t,n){return t.push(n),n.onDispose(function(){var r=t.filter(function(t){return t!==n});t.length=0,t.push.apply(t,r)}),this},n.removeGraphChild=function(t,n){return t.filter(function(t){return t.getChild()===n}).forEach(function(t){return t.dispose()}),this},n.clearGraphChildList=function(t){for(;t.length>0;)t[0].dispose();return this},n.listGraphParents=function(){return this.graph.listParents(this)},t}()),l=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).extensions=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.extensions),n.extensions.forEach(function(t){var n=t.getChild();i.setExtension(n.constructor,r(n))}),this},r.getExtension=function(t){var n=t.EXTENSION_NAME,r=this.extensions.find(function(t){return t.getChild().extensionName===n});return r?r.getChild():null},r.setExtension=function(t,n){var r=this.getExtension(t);return r&&this.removeGraphChild(this.extensions,r),n?(n.l(this),this.addGraphChild(this.extensions,this.graph.link(n.extensionName,this,n))):this},r.listExtensions=function(){return this.extensions.map(function(t){return t.getChild()})},n}(v);s([c],l.prototype,"extensions",void 0);var d=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ACCESSOR,n.p=null,n.A="SCALAR",n.m=null,n.T=!1,n.g=p,n.M=p,n.buffer=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.p=n.p.slice(),this.A=n.A,this.m=n.m,this.T=n.T,this.g=n.g,this.M=n.M,n.buffer&&this.setBuffer(r(n.buffer.getChild())),this},n.getElementSize=function(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}},n.getComponentSize=function(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}},r.getMinNormalized=function(t){var n=this.getElementSize();this.getMin(t);for(var r=0;r<n;r++)t[r]=this.M(t[r]);return t},r.getMin=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.min(t[e],s))}return t},r.getMaxNormalized=function(t){var n=this.getElementSize();this.getMax(t);for(var r=0;r<n;r++)t[r]=this.M(t[r]);return t},r.getMax=function(t){for(var n=this.getCount(),r=this.getElementSize(),i=0;i<r;i++)t[i]=-Infinity;for(var u=0;u<n*r;u+=r)for(var e=0;e<r;e++){var s=this.p[u+e];Number.isFinite(s)&&(t[e]=Math.max(t[e],s))}return t},r.getCount=function(){return this.p.length/this.getElementSize()},r.getType=function(){return this.A},r.setType=function(t){return this.A=t,this},r.getElementSize=function(){return n.getElementSize(this.A)},r.getComponentSize=function(){return this.p.BYTES_PER_ELEMENT},r.getComponentType=function(){return this.m},r.getNormalized=function(){return this.T},r.setNormalized=function(t){var n=this;return this.T=t,t?(this.M=function(t){return function(t,n){switch(n){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}(t,n.m)},this.g=function(t){return function(t,n){switch(n){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}(t,n.m)}):(this.M=p,this.g=p),this},r.getScalar=function(t){var n=this.getElementSize();return this.M(this.p[t*n])},r.setScalar=function(t,n){return this.p[t*this.getElementSize()]=this.g(n),this},r.getElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)n[i]=this.M(this.p[t*r+i]);return n},r.setElement=function(t,n){for(var r=this.getElementSize(),i=0;i<r;i++)this.p[t*r+i]=this.g(n[i]);return this},r.getBuffer=function(){return this.buffer.getChild()},r.setBuffer=function(t){return this.buffer=this.graph.link("buffer",this,t),this},r.getArray=function(){return this.p},r.setArray=function(t){return this.m=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.p=t,this},r.getByteLength=function(){return this.p.byteLength},n}(l);function p(t){return t}d.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},d.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},s([f],d.prototype,"buffer",void 0);var w=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION,n.channels=[],n.samplers=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),n.channels.forEach(function(t){return i.addChannel(r(t.getChild()))}),n.samplers.forEach(function(t){return i.addSampler(r(t.getChild()))}),this},r.addChannel=function(t){var n=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,n)},r.removeChannel=function(t){return this.removeGraphChild(this.channels,t)},r.listChannels=function(){return this.channels.map(function(t){return t.getChild()})},r.addSampler=function(t){var n=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,n)},r.removeSampler=function(t){return this.removeGraphChild(this.samplers,t)},r.listSamplers=function(){return this.samplers.map(function(t){return t.getChild()})},n}(l);s([c],w.prototype,"channels",void 0),s([c],w.prototype,"samplers",void 0);var x=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION_CHANNEL,n.S=null,n.targetNode=null,n.sampler=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.S=n.S,n.targetNode&&this.setTargetNode(r(n.targetNode.getChild())),n.sampler&&this.setSampler(r(n.sampler.getChild())),this},r.getTargetPath=function(){return this.S},r.setTargetPath=function(t){return this.S=t,this},r.getTargetNode=function(){return this.targetNode?this.targetNode.getChild():null},r.setTargetNode=function(t){return this.targetNode=this.graph.link("target.node",this,t),this},r.getSampler=function(){return this.sampler?this.sampler.getChild():null},r.setSampler=function(t){return this.sampler=this.graph.link("sampler",this,t),this},n}(v);s([f],x.prototype,"targetNode",void 0),s([f],x.prototype,"sampler",void 0);var A=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ANIMATION_SAMPLER,n.R="LINEAR",n.input=null,n.output=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.R=n.R,n.input&&this.setInput(r(n.input.getChild())),n.output&&this.setOutput(r(n.output.getChild())),this},r.getInterpolation=function(){return this.R},r.setInterpolation=function(t){return this.R=t,this},r.getInput=function(){return this.input?this.input.getChild():null},r.setInput=function(t){return this.input=this.graph.link("input",this,t),this},r.getOutput=function(){return this.output?this.output.getChild():null},r.setOutput=function(t){return this.output=this.graph.link("output",this,t),this},n}(v);s([f],A.prototype,"input",void 0),s([f],A.prototype,"output",void 0);var b=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.BUFFER,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.N=n.N,this},r.getURI=function(){return this.N},r.setURI=function(t){return this.N=t,this},n}(l),y=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.CAMERA,n.A="perspective",n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.A=n.A,this.U=n.U,this.I=n.I,this.O=n.O,this._=n._,this.j=n.j,this.L=n.L,this},r.getType=function(){return this.A},r.setType=function(t){return this.A=t,this},r.getZNear=function(){return this.U},r.setZNear=function(t){return this.U=t,this},r.getZFar=function(){return this.I},r.setZFar=function(t){return this.I=t,this},r.getAspectRatio=function(){return this.O},r.setAspectRatio=function(t){return this.O=t,this},r.getYFov=function(){return this._},r.setYFov=function(t){return this._=t,this},r.getXMag=function(){return this.j},r.setXMag=function(t){return this.j=t,this},r.getYMag=function(){return this.L},r.setYMag=function(t){return this.L=t,this},n}(l),m=function(t){function n(n,r){var i;return(i=t.call(this,n)||this).k=r,i.k.addExtensionProperty(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i)),i}i(n,t);var r=n.prototype;return r.dispose=function(){this.k.removeExtensionProperty(this),t.prototype.dispose.call(this)},r.l=function(t){if(!this.parentTypes.includes(t.propertyType))throw new Error('Parent "'+t.propertyType+'" invalid for child "'+this.propertyType+'".')},n}(v),E=function(){function t(){}return t.createBufferFromDataURI=function(t){if("undefined"==typeof Buffer){for(var n=atob(t.split(",")[1]),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}var u=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(u,e?"base64":"utf8"))},t.encodeText=function(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))},t.decodeText=function(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")},t.trim=function(t){var n=t.byteOffset;return t.buffer.slice(n,n+t.byteLength)},t.concat=function(t){for(var n,r=0,i=e(t);!(n=i()).done;)r+=n.value.byteLength;for(var u,s=new Uint8Array(r),o=0,h=e(t);!(u=h()).done;){var f=u.value;s.set(new Uint8Array(f),o),o+=f.byteLength}return s.buffer},t.pad=function(t,n){void 0===n&&(n=0);var r=this.padNumber(t.byteLength);if(r!==t.byteLength){var i=new Uint8Array(r);if(i.set(new Uint8Array(t)),0!==n)for(var u=t.byteLength;u<r;u++)i[u]=n;return i.buffer}return t},t.padNumber=function(t){return 4*Math.ceil(t/4)},t.equals=function(t,n){if(t===n)return!0;if(t.byteLength!==n.byteLength)return!1;for(var r=new DataView(t),i=new DataView(n),u=t.byteLength;u--;)if(r.getUint8(u)!==i.getUint8(u))return!1;return!0},t}(),T=function(){function t(){}return t.basename=function(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()},t.extension=function(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"},t}(),g=function(){function t(){}return t.getSizeJPEG=function(t){var n,r;for(t=t.slice(4);t.length;){if(n=t.readUInt16BE(0),M(t,n),192===(r=t[n+1])||193===r||194===r)return[t.readUInt16BE(n+7),t.readUInt16BE(n+5)];t=t.slice(n+2)}throw new TypeError("Invalid JPG, no size found")},t.getSizePNG=function(t){return"CgBI"===t.toString("ascii",12,16)?[t.readUInt32BE(32),t.readUInt32BE(36)]:[t.readUInt32BE(16),t.readUInt32BE(20)]},t.mimeTypeToExtension=function(t){return"image/jpeg"===t?"jpg":t.split("/").pop()},t.extensionToMimeType=function(t){return"jpg"===t?"image/jpeg":"image/"+t},t}();function M(t,n){if(n>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[n])throw new TypeError("Invalid JPG, marker table corrupted")}var S=function(){function t(t){this.verbosity=t}var n=t.prototype;return n.debug=function(n){this.verbosity<=t.Verbosity.DEBUG&&console.debug(n)},n.info=function(n){this.verbosity<=t.Verbosity.INFO&&console.info(n)},n.warn=function(n){this.verbosity<=t.Verbosity.WARN&&console.warn(n)},n.error=function(n){this.verbosity<=t.Verbosity.ERROR&&console.error(n)},t}();S.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};var R="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",N=new Set,U=function(){for(var t="",n=0;n<6;n++)t+=R.charAt(Math.floor(Math.random()*R.length));return t},I=function(){for(var t=0;t<999;t++){var n=U();if(!N.has(n))return N.add(n),n}},O=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.TEXTURE,n.image=null,n.mimeType="",n.uri="",n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.mimeType=n.mimeType,this.uri=n.uri,n.image&&(this.image=n.image.slice(0)),this},r.getMimeType=function(){return this.mimeType},r.setMimeType=function(t){return this.mimeType=t,this},r.getURI=function(){return this.uri},r.setURI=function(t){return this.uri=t,this},r.getImage=function(){return this.image},r.setImage=function(t){return this.image=t,this},r.getSize=function(){return(this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/))?g.getSizePNG(Buffer.from(this.image)):g.getSizeJPEG(Buffer.from(this.image))},n}(l),_=function(){function t(){this.propertyType=exports.PropertyType.TEXTURE_INFO,this.texCoord=0}var n=t.prototype;return n.copy=function(t){return this.texCoord=t.texCoord,this},n.getTexCoord=function(){return this.texCoord},n.setTexCoord=function(t){return this.texCoord=t,this},t}(),j=function(){function t(){this.propertyType=exports.PropertyType.TEXTURE_SAMPLER,this.C=null,this.B=null,this.P=10497,this.V=10497}var n=t.prototype;return n.copy=function(t){return this.C=t.C,this.B=t.B,this.P=t.P,this.V=t.V,this},n.getMagFilter=function(){return this.C},n.setMagFilter=function(t){return this.C=t,this},n.getMinFilter=function(){return this.B},n.setMinFilter=function(t){return this.B=t,this},n.getWrapS=function(){return this.P},n.setWrapS=function(t){return this.P=t,this},n.getWrapT=function(){return this.V},n.setWrapT=function(t){return this.V=t,this},t}();j.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},j.TextureMagFilter={NEAREST:9728,LINEAR:9729},j.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var L=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).textureInfo=new _,n.sampler=new j,n}return i(n,t),n.prototype.copy=function(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this},n}(o),k=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).semantic="",n}return i(n,t),n.prototype.copy=function(t){return this.semantic=t.semantic,this},n}(o),C=function(t){function n(){return t.apply(this,arguments)||this}return i(n,t),n.prototype.copy=function(t){return this},n}(o),B=function(t){function n(){return t.apply(this,arguments)||this}i(n,t);var r=n.prototype;return r.linkTexture=function(t,n,r){if(!r)return null;var i=new L(t,n,r);return this.registerLink(i),i},r.linkAttribute=function(t,n,r){if(!r)return null;var i=new k(t,n,r);return this.registerLink(i),i},r.linkIndex=function(t,n,r){if(!r)return null;var i=new C(t,n,r);return this.registerLink(i),i},n}(h),P=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.MATERIAL,n.D="OPAQUE",n.G=.5,n.F=!1,n.J=[1,1,1,1],n.$=[0,0,0],n.q=1,n.Y=1,n.H=1,n.K=1,n.baseColorTexture=null,n.emissiveTexture=null,n.normalTexture=null,n.occlusionTexture=null,n.metallicRoughnessTexture=null,n}i(n,t);var r=n.prototype;return r.copy=function(n,r){return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.D=n.D,this.G=n.G,this.F=n.F,this.J=[].concat(n.J),this.$=[].concat(n.$),this.q=n.q,this.Y=n.Y,this.H=n.H,this.K=n.K,n.baseColorTexture&&(this.setBaseColorTexture(r(n.baseColorTexture.getChild())),this.baseColorTexture.copy(n.baseColorTexture)),n.emissiveTexture&&(this.setEmissiveTexture(r(n.emissiveTexture.getChild())),this.emissiveTexture.copy(n.emissiveTexture)),n.normalTexture&&(this.setNormalTexture(r(n.normalTexture.getChild())),this.normalTexture.copy(n.normalTexture)),n.occlusionTexture&&(this.setOcclusionTexture(r(n.occlusionTexture.getChild())),this.occlusionTexture.copy(n.occlusionTexture)),n.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(r(n.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(n.metallicRoughnessTexture)),this},r.getDoubleSided=function(){return this.F},r.setDoubleSided=function(t){return this.F=t,this},r.getAlphaMode=function(){return this.D},r.setAlphaMode=function(t){return this.D=t,this},r.getAlphaCutoff=function(){return this.G},r.setAlphaCutoff=function(t){return this.G=t,this},r.getBaseColorFactor=function(){return this.J},r.setBaseColorFactor=function(t){return this.J=t,this},r.getBaseColorTexture=function(){return this.baseColorTexture?this.baseColorTexture.getChild():null},r.getBaseColorTextureInfo=function(){return this.baseColorTexture?this.baseColorTexture.textureInfo:null},r.getBaseColorTextureSampler=function(){return this.baseColorTexture?this.baseColorTexture.sampler:null},r.setBaseColorTexture=function(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",this,t),this},r.getEmissiveFactor=function(){return this.$},r.setEmissiveFactor=function(t){return this.$=t,this},r.getEmissiveTexture=function(){return this.emissiveTexture?this.emissiveTexture.getChild():null},r.getEmissiveTextureInfo=function(){return this.emissiveTexture?this.emissiveTexture.textureInfo:null},r.getEmissiveTextureSampler=function(){return this.emissiveTexture?this.emissiveTexture.sampler:null},r.setEmissiveTexture=function(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",this,t),this},r.getNormalScale=function(){return this.q},r.setNormalScale=function(t){return this.q=t,this},r.getNormalTexture=function(){return this.normalTexture?this.normalTexture.getChild():null},r.getNormalTextureInfo=function(){return this.normalTexture?this.normalTexture.textureInfo:null},r.getNormalTextureSampler=function(){return this.normalTexture?this.normalTexture.sampler:null},r.setNormalTexture=function(t){return this.normalTexture=this.graph.linkTexture("normalTexture",this,t),this},r.getOcclusionStrength=function(){return this.Y},r.setOcclusionStrength=function(t){return this.Y=t,this},r.getOcclusionTexture=function(){return this.occlusionTexture?this.occlusionTexture.getChild():null},r.getOcclusionTextureInfo=function(){return this.occlusionTexture?this.occlusionTexture.textureInfo:null},r.getOcclusionTextureSampler=function(){return this.occlusionTexture?this.occlusionTexture.sampler:null},r.setOcclusionTexture=function(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",this,t),this},r.getRoughnessFactor=function(){return this.H},r.setRoughnessFactor=function(t){return this.H=t,this},r.getMetallicFactor=function(){return this.K},r.setMetallicFactor=function(t){return this.K=t,this},r.getMetallicRoughnessTexture=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null},r.getMetallicRoughnessTextureInfo=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.textureInfo:null},r.getMetallicRoughnessTextureSampler=function(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.sampler:null},r.setMetallicRoughnessTexture=function(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",this,t),this},n}(l);s([f],P.prototype,"baseColorTexture",void 0),s([f],P.prototype,"emissiveTexture",void 0),s([f],P.prototype,"normalTexture",void 0),s([f],P.prototype,"occlusionTexture",void 0),s([f],P.prototype,"metallicRoughnessTexture",void 0);var V=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.MESH,n.W=[],n.primitives=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.W=[].concat(n.W),this.clearGraphChildList(this.primitives),n.primitives.forEach(function(t){return i.addPrimitive(r(t.getChild()))}),this},r.addPrimitive=function(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))},r.removePrimitive=function(t){return this.removeGraphChild(this.primitives,t)},r.listPrimitives=function(){return this.primitives.map(function(t){return t.getChild()})},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(l);s([c],V.prototype,"primitives",void 0);var D=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.PRIMITIVE,n.X=4,n.material=null,n.indices=null,n.attributes=[],n.targets=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.X=n.X,n.indices&&this.setIndices(r(n.indices.getChild())),n.material&&this.setMaterial(r(n.material.getChild())),this.clearGraphChildList(this.attributes),n.listSemantics().forEach(function(t){i.setAttribute(t,r(n.getAttribute(t)))}),this.clearGraphChildList(this.targets),n.targets.forEach(function(t){return i.addTarget(r(t.getChild()))}),this},r.getIndices=function(){return this.indices?this.indices.getChild():null},r.setIndices=function(t){return this.indices=this.graph.linkIndex("index",this,t),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.graph.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},r.getMaterial=function(){return this.material?this.material.getChild():null},r.setMaterial=function(t){return this.material=this.graph.link("material",this,t),this},r.getMode=function(){return this.X},r.setMode=function(t){return this.X=t,this},r.listTargets=function(){return this.targets.map(function(t){return t.getChild()})},r.addTarget=function(t){return this.addGraphChild(this.targets,this.graph.link("target",this,t)),this},r.removeTarget=function(t){return this.removeGraphChild(this.targets,t)},n}(v);s([f],D.prototype,"material",void 0),s([f],D.prototype,"indices",void 0),s([c],D.prototype,"attributes",void 0),s([c],D.prototype,"targets",void 0);var G=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.PRIMITIVE_TARGET,n.attributes=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.attributes),n.listSemantics().forEach(function(t){i.setAttribute(t,r(n.getAttribute(t)))}),this},r.getAttribute=function(t){var n=this.attributes.find(function(n){return n.semantic===t});return n?n.getChild():null},r.setAttribute=function(t,n){var r=this.getAttribute(t);if(r&&this.removeGraphChild(this.attributes,r),!n)return this;var i=this.graph.linkAttribute(t.toLowerCase(),this,n);return i.semantic=t,this.addGraphChild(this.attributes,i)},r.listAttributes=function(){return this.attributes.map(function(t){return t.getChild()})},r.listSemantics=function(){return this.attributes.map(function(t){return t.semantic})},n}(v);s([c],G.prototype,"attributes",void 0);var F=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.NODE,n.Z=[0,0,0],n.tt=[0,0,0,1],n.nt=[1,1,1],n.W=[],n.camera=null,n.mesh=null,n.skin=null,n.children=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.Z=[].concat(n.Z),this.tt=[].concat(n.tt),this.nt=[].concat(n.nt),this.W=[].concat(n.W),n.camera&&this.setCamera(r(n.camera.getChild())),n.mesh&&this.setMesh(r(n.mesh.getChild())),n.skin&&this.setSkin(r(n.skin.getChild())),this.clearGraphChildList(this.children),n.children.forEach(function(t){return i.addChild(r(t.getChild()))}),this},r.getTranslation=function(){return this.Z},r.getRotation=function(){return this.tt},r.getScale=function(){return this.nt},r.setTranslation=function(t){return this.Z=t,this},r.setRotation=function(t){return this.tt=t,this},r.setScale=function(t){return this.nt=t,this},r.addChild=function(t){var n=this.graph.link("child",this,t);return this.addGraphChild(this.children,n)},r.removeChild=function(t){return this.removeGraphChild(this.children,t)},r.listChildren=function(){return this.children.map(function(t){return t.getChild()})},r.getMesh=function(){return this.mesh?this.mesh.getChild():null},r.setMesh=function(t){return this.mesh=this.graph.link("mesh",this,t),this},r.getCamera=function(){return this.camera?this.camera.getChild():null},r.setCamera=function(t){return this.camera=this.graph.link("camera",this,t),this},r.getSkin=function(){return this.skin?this.skin.getChild():null},r.setSkin=function(t){return this.skin=this.graph.link("skin",this,t),this},r.getWeights=function(){return this.W},r.setWeights=function(t){return this.W=t,this},n}(l);s([f],F.prototype,"camera",void 0),s([f],F.prototype,"mesh",void 0),s([f],F.prototype,"skin",void 0),s([c],F.prototype,"children",void 0);var J=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.ROOT,n.rt={generator:"glTF-Transform v0.5.1",version:"2.0"},n.it=new Set,n.accessors=[],n.animations=[],n.buffers=[],n.cameras=[],n.materials=[],n.meshes=[],n.nodes=[],n.scenes=[],n.skins=[],n.textures=[],n}i(n,t);var r=n.prototype;return r.clone=function(){throw new Error("Root cannot be cloned.")},r.copy=function(n,r){var i=this;if(void 0===r&&(r=a),t.prototype.copy.call(this,n,r),!r)throw new Error("Root cannot be copied.");return Object.assign(this.rt,n.rt),n.accessors.forEach(function(t){return i.ut(r(t.getChild()))}),n.animations.forEach(function(t){return i.et(r(t.getChild()))}),n.buffers.forEach(function(t){return i.st(r(t.getChild()))}),n.cameras.forEach(function(t){return i.ot(r(t.getChild()))}),n.materials.forEach(function(t){return i.ht(r(t.getChild()))}),n.meshes.forEach(function(t){return i.ft(r(t.getChild()))}),n.nodes.forEach(function(t){return i.ct(r(t.getChild()))}),n.scenes.forEach(function(t){return i.at(r(t.getChild()))}),n.skins.forEach(function(t){return i.vt(r(t.getChild()))}),n.textures.forEach(function(t){return i.lt(r(t.getChild()))}),this},r.getAsset=function(){return this.rt},r.listExtensionsUsed=function(){return Array.from(this.it)},r.listExtensionsRequired=function(){return this.listExtensionsUsed().filter(function(t){return t.isRequired()})},r.dt=function(t){if(this.it.has(t))throw new Error('Extension "'+t.extensionName+'" is already enabled.');return this.it.add(t),this},r.pt=function(t){return this.it.delete(t),this},r.at=function(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))},r.listScenes=function(){return this.scenes.map(function(t){return t.getChild()})},r.ct=function(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},r.ot=function(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))},r.listCameras=function(){return this.cameras.map(function(t){return t.getChild()})},r.vt=function(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))},r.listSkins=function(){return this.skins.map(function(t){return t.getChild()})},r.ft=function(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))},r.listMeshes=function(){return this.meshes.map(function(t){return t.getChild()})},r.ht=function(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))},r.listMaterials=function(){return this.materials.map(function(t){return t.getChild()})},r.lt=function(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))},r.listTextures=function(){return this.textures.map(function(t){return t.getChild()})},r.et=function(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))},r.listAnimations=function(){return this.animations.map(function(t){return t.getChild()})},r.ut=function(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))},r.listAccessors=function(){return this.accessors.map(function(t){return t.getChild()})},r.st=function(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))},r.listBuffers=function(){return this.buffers.map(function(t){return t.getChild()})},n}(v);s([c],J.prototype,"accessors",void 0),s([c],J.prototype,"animations",void 0),s([c],J.prototype,"buffers",void 0),s([c],J.prototype,"cameras",void 0),s([c],J.prototype,"materials",void 0),s([c],J.prototype,"meshes",void 0),s([c],J.prototype,"nodes",void 0),s([c],J.prototype,"scenes",void 0),s([c],J.prototype,"skins",void 0),s([c],J.prototype,"textures",void 0);var z=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.SCENE,n.nodes=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),this.clearGraphChildList(this.nodes),n.nodes.forEach(function(t){return i.addNode(r(t.getChild()))}),this},r.addNode=function(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))},r.removeNode=function(t){return this.removeGraphChild(this.nodes,t)},r.listNodes=function(){return this.nodes.map(function(t){return t.getChild()})},n}(l);s([c],z.prototype,"nodes",void 0);var $=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).propertyType=exports.PropertyType.SKIN,n.skeleton=null,n.inverseBindMatrices=null,n.joints=[],n}i(n,t);var r=n.prototype;return r.copy=function(n,r){var i=this;return void 0===r&&(r=a),t.prototype.copy.call(this,n,r),n.skeleton&&this.setSkeleton(r(n.skeleton.getChild())),n.inverseBindMatrices&&this.setInverseBindMatrices(r(n.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),n.joints.forEach(function(t){return i.addJoint(r(t.getChild()))}),this},r.getSkeleton=function(){return this.skeleton?this.skeleton.getChild():null},r.setSkeleton=function(t){return this.skeleton=this.graph.link("skeleton",this,t),this},r.getInverseBindMatrices=function(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null},r.setInverseBindMatrices=function(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this},r.addJoint=function(t){var n=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,n)},r.removeJoint=function(t){return this.removeGraphChild(this.joints,t)},r.listJoints=function(){return this.joints.map(function(t){return t.getChild()})},n}(l);s([f],$.prototype,"skeleton",void 0),s([f],$.prototype,"inverseBindMatrices",void 0),s([c],$.prototype,"joints",void 0);var q=function(){function t(){this.graph=new B,this.root=new J(this.graph),this.logger=new S(S.Verbosity.INFO)}var n=t.prototype;return n.getRoot=function(){return this.root},n.getGraph=function(){return this.graph},n.getLogger=function(){return this.logger},n.setLogger=function(t){return this.logger=t,this},n.clone=function(){return(new t).merge(this)},n.merge=function(t){for(var n,r={},i=e(t.getRoot().listExtensionsUsed());!(n=i()).done;){var u=n.value,s=this.createExtension(u.constructor);u.isRequired()&&s.setRequired(!0),r[s.extensionName]=s}var o=new Set,h=new Map;o.add(t.root),h.set(t.root,this.root);for(var f,c=e(t.graph.getLinks());!(f=c()).done;)for(var a=f.value,v=0,l=[a.getParent(),a.getChild()];v<l.length;v++){var d=l[v];if(!o.has(d)){var p=d.constructor,w=d instanceof m?new p(this.graph,r[d.extensionName]):new p(this.graph);h.set(d,w),o.add(d)}}for(var x,A=function(t){return h.get(t)},b=e(o);!(x=b()).done;){var y=x.value;h.get(y).copy(y,A)}return this},n.transform=function(){for(var t,n=e([].slice.call(arguments));!(t=n()).done;){var r=t.value;r(this)}return this},n.createExtension=function(t){return this.getRoot().listExtensionsUsed().find(function(n){return n.extensionName===t.EXTENSION_NAME})||new t(this)},n.createScene=function(t){var n=new z(this.graph,t);return this.root.at(n),n},n.createNode=function(t){var n=new F(this.graph,t);return this.root.ct(n),n},n.createCamera=function(t){var n=new y(this.graph,t);return this.root.ot(n),n},n.createSkin=function(t){var n=new $(this.graph,t);return this.root.vt(n),n},n.createMesh=function(t){var n=new V(this.graph,t);return this.root.ft(n),n},n.createPrimitive=function(){return new D(this.graph)},n.createPrimitiveTarget=function(t){return new G(this.graph,t)},n.createMaterial=function(t){var n=new P(this.graph,t);return this.root.ht(n),n},n.createTexture=function(t){var n=new O(this.graph,t);return this.root.lt(n),n},n.createAnimation=function(t){var n=new w(this.graph,t);return this.root.et(n),n},n.createAnimationChannel=function(){return new x(this.graph)},n.createAnimationSampler=function(){return new A(this.graph)},n.createAccessor=function(t,n){void 0===n&&(n=null),n||(n=this.getRoot().listBuffers()[0]);var r=new d(this.graph,t).setBuffer(n);return this.root.ut(r),r},n.createBuffer=function(t){var n=new b(this.graph,t);return this.root.st(n),n},t}(),Y=function(){function t(t){this.doc=t,this.provideTypes=[],this.wt=!1,this.xt=new Set,t.getRoot().dt(this)}var n=t.prototype;return n.dispose=function(){this.doc.getRoot().pt(this);for(var t,n=e(this.xt);!(t=n()).done;)t.value.dispose()},n.isRequired=function(){return this.wt},n.setRequired=function(t){return this.wt=t,this},n.addExtensionProperty=function(t){return this.xt.add(t),this},n.removeExtensionProperty=function(t){return this.xt.delete(t),this},n.provide=function(t,n){return this},t}(),H=function(){function t(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=[]}var n=t.prototype;return n.setTextureInfo=function(t,n){void 0!==n.texCoord&&t.setTexCoord(n.texCoord)},n.setTextureSampler=function(t,n){var r=this.nativeDocument.json.textures[n.index];if(void 0!==r.sampler){var i=this.nativeDocument.json.samplers[r.sampler];void 0!==i.magFilter&&t.setMagFilter(i.magFilter),void 0!==i.minFilter&&t.setMinFilter(i.minFilter),void 0!==i.wrapS&&t.setWrapS(i.wrapS),void 0!==i.wrapT&&t.setWrapT(i.wrapT)}},t}(),K={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Q=function(){function t(){}return t.read=function(t,i){var u=t.json,s=new q;if("2.0"!==u.asset.version)throw new Error('Unsupported glTF version, "'+u.asset.version+'".');if(u.extensionsRequired)for(var o,h=function(){var t=o.value;if(!i.extensions.find(function(n){return n.EXTENSION_NAME===t}))throw new Error('Missing required extension, "'+t+'".')},f=e(u.extensionsRequired);!(o=f()).done;)h();s.getRoot().getAsset().generator=t.json.asset.generator;for(var c,a=new H(t),v=u.extensionsUsed||[],l=u.extensionsRequired||[],p=e(i.extensions);!(c=p()).done;){var w=c.value;v.includes(w.EXTENSION_NAME)&&s.createExtension(w).setRequired(l.includes(w.EXTENSION_NAME))}a.buffers=(u.buffers||[]).map(function(t){var n=s.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&n.setURI(t.uri),n}),a.bufferViewBuffers=(u.bufferViews||[]).map(function(t){return a.buffers[t.buffer]}),a.accessors=(u.accessors||[]).map(function(n){var i,u=s.createAccessor(n.name,a.bufferViewBuffers[n.bufferView]);return u.setType(n.type),i=void 0!==n.sparse?function(t,n){var i,u=K[t.componentType],e=d.getElementSize(t.type);i=void 0!==t.bufferView?W(t,n).slice():new u(t.count*e);for(var s=t.sparse.count,o=r(r(r({},t),t.sparse.indices),{},{count:s,type:"SCALAR"}),h=r(r(r({},t),t.sparse.values),{},{count:s}),f=W(o,n),c=W(h,n),a=0;a<o.count;a++)for(var v=0;v<e;v++)i[f[a]*e+v]=c[a*e+v];return i}(n,t):W(n,t).slice(),void 0!==n.normalized&&u.setNormalized(n.normalized),u.setArray(i),u});var x=u.images||[],A=u.textures||[];s.getRoot().listExtensionsUsed().filter(function(t){return t.provideTypes.includes(exports.PropertyType.TEXTURE)}).forEach(function(t){return t.provide(a,exports.PropertyType.TEXTURE)}),a.textures=x.map(function(n){var r=s.createTexture(n.name);if(void 0!==n.bufferView){var i=u.bufferViews[n.bufferView],e=t.json.buffers[i.buffer],o=i.byteOffset||0,h=(e.uri?t.resources[e.uri]:t.resources["At"]).slice(o,o+i.byteLength);r.setImage(h)}else void 0!==n.uri&&(r.setImage(t.resources[n.uri]),0!==n.uri.indexOf("__")&&r.setURI(n.uri));if(void 0!==n.mimeType)r.setMimeType(n.mimeType);else if(n.uri){var f=T.extension(n.uri);r.setMimeType(g.extensionToMimeType(f))}return r}),a.materials=(u.materials||[]).map(function(t){var n=s.createMaterial(t.name);void 0!==t.alphaMode&&n.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&n.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&n.setDoubleSided(t.doubleSided);var r=t.pbrMetallicRoughness||{};if(void 0!==r.baseColorFactor&&n.setBaseColorFactor(r.baseColorFactor),void 0!==t.emissiveFactor&&n.setEmissiveFactor(t.emissiveFactor),void 0!==r.metallicFactor&&n.setMetallicFactor(r.metallicFactor),void 0!==r.roughnessFactor&&n.setRoughnessFactor(r.roughnessFactor),void 0!==r.baseColorTexture){var i=r.baseColorTexture;n.setBaseColorTexture(a.textures[A[i.index].source]),a.setTextureInfo(n.getBaseColorTextureInfo(),i),a.setTextureSampler(n.getBaseColorTextureSampler(),i)}if(void 0!==t.emissiveTexture){var u=t.emissiveTexture;n.setEmissiveTexture(a.textures[A[u.index].source]),a.setTextureInfo(n.getEmissiveTextureInfo(),u),a.setTextureSampler(n.getEmissiveTextureSampler(),u)}if(void 0!==t.normalTexture){var e=t.normalTexture;n.setNormalTexture(a.textures[A[e.index].source]),a.setTextureInfo(n.getNormalTextureInfo(),e),a.setTextureSampler(n.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&n.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){var o=t.occlusionTexture;n.setOcclusionTexture(a.textures[A[o.index].source]),a.setTextureInfo(n.getOcclusionTextureInfo(),o),a.setTextureSampler(n.getOcclusionTextureSampler(),o),void 0!==t.occlusionTexture.strength&&n.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==r.metallicRoughnessTexture){var h=r.metallicRoughnessTexture;n.setMetallicRoughnessTexture(a.textures[A[h.index].source]),a.setTextureInfo(n.getMetallicRoughnessTextureInfo(),h),a.setTextureSampler(n.getMetallicRoughnessTextureSampler(),h)}return n}),a.meshes=(u.meshes||[]).map(function(t){var n=s.createMesh(t.name);return void 0!==t.weights&&n.setWeights(t.weights),t.primitives.forEach(function(r){var i=s.createPrimitive();void 0!==r.material&&i.setMaterial(a.materials[r.material]),void 0!==r.mode&&i.setMode(r.mode);for(var u=0,e=Object.entries(r.attributes||{});u<e.length;u++){var o=e[u];i.setAttribute(o[0],a.accessors[o[1]])}void 0!==r.indices&&i.setIndices(a.accessors[r.indices]);var h=t.extras&&t.extras.targetNames||[];(r.targets||[]).forEach(function(t,n){for(var r=h[n]||n.toString(),u=s.createPrimitiveTarget(r),e=0,o=Object.entries(t);e<o.length;e++){var f=o[e];u.setAttribute(f[0],a.accessors[f[1]])}i.addTarget(u)}),n.addPrimitive(i)}),n}),a.cameras=(u.cameras||[]).map(function(t){var n=s.createCamera(t.name).setType(t.type);return"perspective"===t.type?n.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):n.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),n});var b=u.nodes||[];return a.nodes=b.map(function(t){var r=s.createNode(t.name);return void 0!==t.translation&&r.setTranslation(t.translation),void 0!==t.rotation&&r.setRotation(t.rotation),void 0!==t.scale&&r.setScale(t.scale),void 0!==t.matrix&&(r.setTranslation(n.getTranslation([],t.matrix)),r.setRotation(n.getRotation([],t.matrix)),r.setScale(n.getScaling([],t.matrix))),void 0!==t.weights&&r.setWeights(t.weights),r}),a.skins=(u.skins||[]).map(function(t){var n=s.createSkin(t.name);void 0!==t.inverseBindMatrices&&n.setInverseBindMatrices(a.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&n.setSkeleton(a.nodes[t.skeleton]);for(var r,i=e(t.joints);!(r=i()).done;)n.addJoint(a.nodes[r.value]);return n}),b.map(function(t,n){var r=a.nodes[n];(t.children||[]).forEach(function(t){return r.addChild(a.nodes[t])}),void 0!==t.mesh&&r.setMesh(a.meshes[t.mesh]),void 0!==t.camera&&r.setCamera(a.cameras[t.camera]),void 0!==t.skin&&r.setSkin(a.skins[t.skin])}),a.animations=(u.animations||[]).map(function(t){var n=s.createAnimation(t.name),r=(t.samplers||[]).map(function(t){var r=s.createAnimationSampler().setInput(a.accessors[t.input]).setOutput(a.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return n.addSampler(r),r});return(t.channels||[]).forEach(function(t){var i=s.createAnimationChannel().setSampler(r[t.sampler]).setTargetNode(a.nodes[t.target.node]).setTargetPath(t.target.path);n.addChannel(i)}),n}),a.scenes=(u.scenes||[]).map(function(t){var n=s.createScene(t.name);return(t.nodes||[]).map(function(t){return a.nodes[t]}).forEach(function(t){return n.addNode(t)}),n}),s.getRoot().listExtensionsUsed().forEach(function(t){return t.read(a)}),s},t}();function W(t,n){var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["At"],e=K[t.componentType],s=d.getElementSize(t.type);if(void 0!==r.byteStride&&r.byteStride!==s*e.BYTES_PER_ELEMENT)return function(t,n){for(var r=n.json.bufferViews[t.bufferView],i=n.json.buffers[r.buffer],u=i.uri?n.resources[i.uri]:n.resources["At"],e=K[t.componentType],s=d.getElementSize(t.type),o=e.BYTES_PER_ELEMENT,h=t.byteOffset||0,f=new e(t.count*s),c=new DataView(u,r.byteOffset,r.byteLength),a=r.byteStride,v=0;v<t.count;v++)for(var l=0;l<s;l++){var p=h+v*a+l*o,w=void 0;switch(t.componentType){case 5126:w=c.getFloat32(p,!0);break;case 5125:w=c.getUint32(p,!0);break;case 5123:w=c.getUint16(p,!0);break;case 5121:w=c.getUint8(p);break;case 5122:w=c.getInt16(p,!0);break;case 5120:w=c.getInt8(p);break;default:throw new Error('Unexpected componentType "'+t.componentType+'".')}f[v*s+l]=w}return f}(t,n);var o=(r.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(u,o,t.count*s);case 5125:return new Uint32Array(u,o,t.count*s);case 5123:return new Uint16Array(u,o,t.count*s);case 5121:return new Uint8Array(u,o,t.count*s);case 5122:return new Int16Array(u,o,t.count*s);case 5120:return new Int8Array(u,o,t.count*s);default:throw new Error('Unexpected componentType "'+t.componentType+'".')}}var X=function(){function t(t,n){this.nativeDocument=t,this.options=n,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}var n=t.prototype;return n.createTextureInfoDef=function(t,n,r){var i={magFilter:r.getMagFilter()||void 0,minFilter:r.getMinFilter()||void 0,wrapS:r.getWrapS(),wrapT:r.getWrapT()},u=JSON.stringify(i);this.samplerDefIndexMap.has(u)||(this.samplerDefIndexMap.set(u,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(i));var e={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(u)},s=JSON.stringify(e);return this.textureDefIndexMap.has(s)||(this.textureDefIndexMap.set(s,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(e)),{index:this.textureDefIndexMap.get(s),texCoord:n.getTexCoord()}},n.createPropertyDef=function(t){var n={};return t.getName()&&(n.name=t.getName()),Object.keys(t.getExtras()).length>0&&(n.extras=t.getExtras()),n},n.createAccessorDef=function(t){var n=this.createPropertyDef(t);return n.type=t.getType(),n.componentType=t.getComponentType(),n.count=t.getCount(),t.getMax(n.max=[]),t.getMin(n.min=[]),n.normalized=t.getNormalized(),n},n.createImageData=function(t,n,r){if(this.options.isGLB)this.imageData.push(n),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:n.byteLength});else{var i=g.mimeTypeToExtension(r.getMimeType());t.uri=this.imageURIGenerator.createURI(r,i),this.nativeDocument.resources[t.uri]=n}},t}(),Z=function(){function t(t,n){this.multiple=t,this.basename=n,this.counter=1}return t.prototype.createURI=function(t,n){return t.getURI()?t.getURI():this.multiple?this.basename+"_"+this.counter+++"."+n:this.basename+"."+n},t}(),tt=function(){function t(){}return t.write=function(t,n){var r=t.getRoot(),i={json:{asset:r.getAsset()},resources:{}},u=i.json;u.asset.generator="glTF-Transform v0.5.1";var s=new X(i,n),o=r.listBuffers().length,h=r.listTextures().length;function f(t,n,r,i){for(var o,h=[],f=0,c=e(t);!(o=c()).done;){var a=o.value,v=s.createAccessorDef(a);v.bufferView=u.bufferViews.length;var l=E.pad(a.getArray().buffer);v.byteOffset=f,f+=l.byteLength,h.push(l),s.accessorIndexMap.set(a,u.accessors.length),u.accessors.push(v)}var d={buffer:n,byteOffset:r,byteLength:E.concat(h).byteLength};return i&&(d.target=i),u.bufferViews.push(d),{buffers:h,byteLength:f}}function c(t,n,r){for(var i,o=t[0].getCount(),h=0,f=e(t);!(i=f()).done;){var c=i.value,a=s.createAccessorDef(c);a.bufferView=u.bufferViews.length,a.byteOffset=h;var v=c.getElementSize(),l=c.getComponentSize();h+=E.padNumber(v*l),s.accessorIndexMap.set(c,u.accessors.length),u.accessors.push(a)}for(var d=o*h,p=new ArrayBuffer(d),w=new DataView(p),x=0;x<o;x++)for(var A,b=0,y=e(t);!(A=y()).done;){for(var m=A.value,T=m.getElementSize(),g=m.getComponentSize(),M=m.getComponentType(),S=m.getArray(),R=0;R<T;R++){var N=x*h+b+R*g,U=S[x*T+R];switch(M){case 5126:w.setFloat32(N,U,!0);break;case 5120:w.setInt8(N,U);break;case 5122:w.setInt16(N,U,!0);break;case 5121:w.setUint8(N,U);break;case 5123:w.setUint16(N,U,!0);break;case 5125:w.setUint32(N,U,!0);break;default:throw new Error("Unexpected component type: "+M)}}b+=E.padNumber(T*g)}return u.bufferViews.push({buffer:n,byteOffset:r,byteLength:d,byteStride:h,target:34962}),{byteLength:d,buffers:[p]}}s.bufferURIGenerator=new Z(o>1,n.basename),s.imageURIGenerator=new Z(h>1,n.basename),s.logger=t.getLogger();for(var a,v=new Map,l=e(t.getGraph().getLinks());!(a=l()).done;){var p=a.value;if(p.getParent()!==r){var w=p.getChild();if(w instanceof d){var x=v.get(w)||[];x.push(p),v.set(w,x)}}}return u.accessors=[],u.bufferViews=[],u.samplers=[],u.textures=[],u.images=r.listTextures().map(function(t,n){var r=s.createPropertyDef(t);return t.getMimeType()&&(r.mimeType=t.getMimeType()),t.getImage()&&s.createImageData(r,t.getImage(),t),s.imageIndexMap.set(t,n),r}),u.buffers=[],r.listBuffers().forEach(function(t){for(var r,o=s.createPropertyDef(t),h=new Map,a=new Set,l=new Set,p=e(t.listParents().filter(function(t){return!(t instanceof J)}));!(r=p()).done;){var w=r.value;if(!(w instanceof d))throw new Error("Unimplemented buffer reference: "+w);for(var x,A=!1,b=!1,y=!1,m=v.get(w)||[],T=e(m);!(x=T()).done;){var g=x.value;g instanceof k?A=!0:g instanceof C?b=!0:y=!0}if(A||b||y||(y=!0),!A||b||y)if(!b||A||y){if(!y||A||b)throw new Error("Attribute or index accessors must be used only for that purpose.");l.add(w)}else a.add(w);else{var M=m[0].getParent(),S=h.get(M)||new Set;S.add(w),h.set(M,S)}}var R,N=[],U=u.buffers.length,I=0;if(a.size){var O=f(Array.from(a),U,I,34963);I+=O.byteLength,N.push.apply(N,O.buffers)}for(var _=0,j=Array.from(h.values());_<j.length;_++){var L=j[_];if(L.size){var B=c(Array.from(L),U,I);I+=B.byteLength,N.push.apply(N,B.buffers)}}if(l.size){var P=f(Array.from(l),U,I);I+=P.byteLength,N.push.apply(N,P.buffers)}if(s.imageData.length)for(var V=0;V<s.imageData.length;V++)u.bufferViews[u.images[V].bufferView].byteOffset=I,I+=s.imageData[V].byteLength,N.push(s.imageData[V]);I?(n.isGLB?R="__glb.bin":(R=s.bufferURIGenerator.createURI(t,"bin"),o.uri=R),o.byteLength=I,i.resources[R]=E.concat(N),u.buffers.push(o)):s.logger.warn('@gltf-transform/core: Skipping empty buffer, "'+t.getName()+'".')}),u.materials=r.listMaterials().map(function(t,n){var r=s.createPropertyDef(t);if(r.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(r.alphaCutoff=t.getAlphaCutoff()),r.doubleSided=t.getDoubleSided(),r.pbrMetallicRoughness={},r.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),r.emissiveFactor=t.getEmissiveFactor(),r.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),r.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){var i=t.getBaseColorTexture(),u=t.getBaseColorTextureInfo(),e=t.getBaseColorTextureSampler();r.pbrMetallicRoughness.baseColorTexture=s.createTextureInfoDef(i,u,e)}if(t.getEmissiveTexture()){var o=t.getEmissiveTexture(),h=t.getEmissiveTextureInfo(),f=t.getEmissiveTextureSampler();r.emissiveTexture=s.createTextureInfoDef(o,h,f)}if(t.getNormalTexture()){var c=t.getNormalTexture(),a=t.getNormalTextureInfo(),v=t.getNormalTextureSampler(),l=s.createTextureInfoDef(c,a,v);1!==t.getNormalScale()&&(l.scale=t.getNormalScale()),r.normalTexture=l}if(t.getOcclusionTexture()){var d=t.getOcclusionTexture(),p=t.getOcclusionTextureInfo(),w=t.getOcclusionTextureSampler(),x=s.createTextureInfoDef(d,p,w);1!==t.getOcclusionStrength()&&(x.strength=t.getOcclusionStrength()),r.occlusionTexture=x}if(t.getMetallicRoughnessTexture()){var A=t.getMetallicRoughnessTexture(),b=t.getMetallicRoughnessTextureInfo(),y=t.getMetallicRoughnessTextureSampler();r.pbrMetallicRoughness.metallicRoughnessTexture=s.createTextureInfoDef(A,b,y)}return s.materialIndexMap.set(t,n),r}),u.meshes=r.listMeshes().map(function(t,n){var r,i=s.createPropertyDef(t);return i.primitives=t.listPrimitives().map(function(t){var n={attributes:{}};n.material=s.materialIndexMap.get(t.getMaterial()),n.mode=t.getMode(),t.getIndices()&&(n.indices=s.accessorIndexMap.get(t.getIndices()));for(var i,u=e(t.listSemantics());!(i=u()).done;){var o=i.value;n.attributes[o]=s.accessorIndexMap.get(t.getAttribute(o))}for(var h,f=e(t.listTargets());!(h=f()).done;){for(var c,a=h.value,v={},l=e(a.listSemantics());!(c=l()).done;){var d=c.value;v[d]=s.accessorIndexMap.get(a.getAttribute(d))}n.targets=n.targets||[],n.targets.push(v)}return t.listTargets().length&&!r&&(r=t.listTargets().map(function(t){return t.getName()})),n}),t.getWeights().length&&(i.weights=t.getWeights()),r&&(i.extras=i.extras||{},i.extras.targetNames=r),s.meshIndexMap.set(t,n),i}),u.cameras=r.listCameras().map(function(t,n){var r=s.createPropertyDef(t);return r.type=t.getType(),"perspective"===r.type?r.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:r.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},s.cameraIndexMap.set(t,n),r}),u.nodes=r.listNodes().map(function(t,n){var r=s.createPropertyDef(t);return r.translation=t.getTranslation(),r.rotation=t.getRotation(),r.scale=t.getScale(),t.getWeights().length&&(r.weights=t.getWeights()),s.nodeIndexMap.set(t,n),r}),u.skins=r.listSkins().map(function(t,n){var r=s.createPropertyDef(t);return t.getInverseBindMatrices()&&(r.inverseBindMatrices=s.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(r.skeleton=s.nodeIndexMap.get(t.getSkeleton())),r.joints=t.listJoints().map(function(t){return s.nodeIndexMap.get(t)}),s.skinIndexMap.set(t,n),r}),r.listNodes().forEach(function(t,n){var r=u.nodes[n];t.getMesh()&&(r.mesh=s.meshIndexMap.get(t.getMesh())),t.getCamera()&&(r.camera=s.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(r.skin=s.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(r.children=t.listChildren().map(function(t){return s.nodeIndexMap.get(t)}))}),u.animations=r.listAnimations().map(function(t){var n=s.createPropertyDef(t),r=new Map;return n.samplers=t.listSamplers().map(function(t,n){var i=s.createPropertyDef(t);return i.input=s.accessorIndexMap.get(t.getInput()),i.output=s.accessorIndexMap.get(t.getOutput()),i.interpolation=t.getInterpolation(),r.set(t,n),i}),n.channels=t.listChannels().map(function(t){var n=s.createPropertyDef(t);return n.sampler=r.get(t.getSampler()),n.target={node:s.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},n}),n}),u.scenes=r.listScenes().map(function(t){var n=s.createPropertyDef(t);return n.nodes=t.listNodes().map(function(t){return s.nodeIndexMap.get(t)}),n}),u.extensionsUsed=r.listExtensionsUsed().map(function(t){return t.extensionName}),u.extensionsRequired=r.listExtensionsRequired().map(function(t){return t.extensionName}),r.listExtensionsUsed().forEach(function(t){return t.write(s)}),function(t){var n=[];for(var r in t){var i=t[r];Array.isArray(i)&&0===i.length?n.push(r):null!==i&&""!==i||n.push(i)}for(var u=0,e=n;u<e.length;u++)delete t[e[u]]}(u),i},t}(),nt=function(){function t(){this.it=[]}var n=t.prototype;return n.registerExtensions=function(t){var n;return(n=this.it).push.apply(n,t),this},n.createDocument=function(t){return Q.read(t,{extensions:this.it})},n.createNativeDocument=function(t,n){if(n.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return tt.write(t,n)},n.unpackGLB=function(t){var n,r=new Uint32Array(t,0,3);if(1179937895!==r[0])throw new Error("Invalid glTF asset.");if(2!==r[1])throw new Error('Unsupported glTF binary version, "'+r[1]+'".');var i=new Uint32Array(t,12,2),u=i[0],e=new Uint32Array(t,20+u,2);if(1313821514!==i[1]||5130562!==e[1])throw new Error("Unexpected GLB layout.");var s=E.decodeText(t.slice(20,20+u)),o=JSON.parse(s),h=20+u+8,f=t.slice(h,h+e[0]);return this.createDocument({json:o,resources:(n={},n["At"]=f,n)})},n.packGLB=function(t){var n=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=n.resources,i=JSON.stringify(n.json),u=E.pad(E.encodeText(i),32),e=new Uint32Array([u.byteLength,1313821514]).buffer,s=E.concat([e,u]),o=E.pad(Object.values(r)[0]||new ArrayBuffer(0),0),h=new Uint32Array([o.byteLength,5130562]).buffer,f=E.concat([h,o]),c=new Uint32Array([1179937895,2,12+s.byteLength+f.byteLength]).buffer;return E.concat([c,s,f])},t}(),rt=function(t){function n(n,r){var i;return(i=t.call(this)||this).fs=n,i.path=r,i}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.write=function(t,n){t.match(/\.glb$/)?this.writeGLB(t,n):this.writeGLTF(t,n)},r.readGLB=function(t){var n=this.fs.readFileSync(t),r=E.trim(n);return this.unpackGLB(r)},r.readGLTF=function(t){var n=this,r=this.path.dirname(t),i={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[].concat(i.json.images||[],i.json.buffers||[]).forEach(function(t){if(t.uri&&!t.uri.match(/data:/)){var u=n.path.resolve(r,t.uri);i.resources[t.uri]=E.trim(n.fs.readFileSync(u))}else{var e="__"+I()+"."+T.extension(t.uri);i.resources[e]=E.createBufferFromDataURI(t.uri),t.uri=e}}),Q.read(i,{extensions:this.it})},r.writeGLTF=function(t,n){var r={basename:T.basename(t),isGLB:!1},i=tt.write(n,r),u=i.json,e=i.resources,s=this.fs,o=this.path,h=o.dirname(t);s.writeFileSync(t,JSON.stringify(u,null,2)),Object.keys(e).forEach(function(t){var n=Buffer.from(e[t]);s.writeFileSync(o.join(h,t),n)})},r.writeGLB=function(t,n){var r=Buffer.from(this.packGLB(n));this.fs.writeFileSync(t,r)},n}(nt),it=function(t){function n(n){var r;return(r=t.call(this)||this).fetchConfig=n,r}i(n,t);var r=n.prototype;return r.read=function(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)},r.readGLTF=function(t){var n=this,r={json:{},resources:{}};return fetch(t,this.fetchConfig).then(function(t){return t.json()}).then(function(t){r.json=t;var i=[].concat(t.images,t.buffers).map(function(t){if(t.uri)return fetch(t.uri,n.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(n){r.resources[t.uri]=n})});return Promise.all(i).then(function(){return n.createDocument(r)})})},r.readGLB=function(t){var n=this;return fetch(t,this.fetchConfig).then(function(t){return t.arrayBuffer()}).then(function(t){return n.unpackGLB(t)})},n}(nt);exports.Accessor=d,exports.Animation=w,exports.AnimationChannel=x,exports.AnimationSampler=A,exports.Buffer=b,exports.BufferUtils=E,exports.COPY_IDENTITY=a,exports.Camera=y,exports.Document=q,exports.Extension=Y,exports.ExtensionProperty=m,exports.FileUtils=T,exports.Graph=h,exports.GraphChild=f,exports.ImageUtils=g,exports.Logger=S,exports.Material=P,exports.Mesh=V,exports.Node=F,exports.NodeIO=rt,exports.Primitive=D,exports.PrimitiveTarget=G,exports.Property=v,exports.ReaderContext=H,exports.Root=J,exports.Scene=z,exports.Skin=$,exports.Texture=O,exports.TextureInfo=_,exports.TextureLink=L,exports.TextureSampler=j,exports.WebIO=it,exports.WriterContext=X,exports.uuid=I; | ||
//# sourceMappingURL=core.js.map |
@@ -1,2 +0,2 @@ | ||
import{getTranslation as t,getRotation as s,getScaling as e}from"gl-matrix/mat4";function r(t,s,e,r){var i,n=arguments.length,h=n<3?s:null===r?r=Object.getOwnPropertyDescriptor(s,e):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,s,e,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(s,e,h):i(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h}var i;!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{constructor(t,s,e){if(this.t=t,this.s=s,this.i=e,this.h=!1,this.o=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class h{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(s=>s.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(s=>s.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(s=>s.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=this.u.filter(s=>s.getChild()===t);return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}link(t,s,e){if(!e)return null;const r=new n(t,s,e);return this.registerLink(r),r}registerLink(t){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(s=>s!==t),this}}function o(t,s){Object.defineProperty(t,s,{get:function(){return this["__"+s]},set:function(t){const e=this["__"+s];e&&!Array.isArray(e)&&e.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+s]=null}),this["__"+s]=t},enumerable:!0})}function u(t,s){}const c=t=>t;class a extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.getLinks().filter(s=>s.getParent()===this&&s.getChild()===t).forEach(t=>t.setChild(s)),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0,t.push(...e)}),this}removeGraphChild(t,s){return t.filter(t=>t.getChild()===s).forEach(t=>t.dispose()),this}clearGraphChildList(t){for(;t.length>0;)t[0].dispose();return this}listGraphParents(){return this.graph.listParents(this)}}{constructor(t,s=""){super(t),this.l={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,c)}copy(t,s){return this.t=t.t,this.l=JSON.parse(JSON.stringify(t.l)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class l extends a{constructor(){super(...arguments),this.extensions=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.constructor,s(e))}),this}getExtension(t){const s=t.EXTENSION_NAME,e=this.extensions.find(t=>t.getChild().extensionName===s);return e?e.getChild():null}setExtension(t,s){const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.p(this),this.addGraphChild(this.extensions,this.graph.link(s.extensionName,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],l.prototype,"extensions",void 0);class f extends l{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.A=!1,this.T=d,this.M=d,this.buffer=null}copy(t,s=c){return super.copy(t,s),this.g=t.g.slice(),this.m=t.m,this.v=t.v,this.A=t.A,this.T=t.T,this.M=t.M,t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}}getMinNormalized(t){const s=this.getElementSize();this.getMin(t);for(let e=0;e<s;e++)t[e]=this.M(t[e]);return t}getMin(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.g[r+s];Number.isFinite(e)&&(t[s]=Math.min(t[s],e))}return t}getMaxNormalized(t){const s=this.getElementSize();this.getMax(t);for(let e=0;e<s;e++)t[e]=this.M(t[e]);return t}getMax(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=-Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.g[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.g.length/this.getElementSize()}getType(){return this.m}setType(t){return this.m=t,this}getElementSize(){return f.getElementSize(this.m)}getComponentSize(){return this.g.BYTES_PER_ELEMENT}getComponentType(){return this.v}getNormalized(){return this.A}setNormalized(t){return this.A=t,t?(this.M=t=>function(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}(t,this.v),this.T=t=>function(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}(t,this.v)):(this.M=d,this.T=d),this}getScalar(t){const s=this.getElementSize();return this.M(this.g[t*s])}setScalar(t,s){return this.g[t*this.getElementSize()]=this.T(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.M(this.g[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.g[t*e+r]=this.T(s[r]);return this}getBuffer(){return this.buffer.getChild()}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.g}setArray(t){return this.v=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.g=t,this}getByteLength(){return this.g.byteLength}}function d(t){return t}f.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},f.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},r([o],f.prototype,"buffer",void 0);class p extends l{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),t.channels.forEach(t=>this.addChannel(s(t.getChild()))),t.samplers.forEach(t=>this.addSampler(s(t.getChild()))),this}addChannel(t){const s=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,s)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const s=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,s)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}r([u],p.prototype,"channels",void 0),r([u],p.prototype,"samplers",void 0);class g extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=c){return super.copy(t,s),this.S=t.S,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.S}setTargetPath(t){return this.S=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}r([o],g.prototype,"targetNode",void 0),r([o],g.prototype,"sampler",void 0);class m extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,this.N="LINEAR",this.input=null,this.output=null}copy(t,s=c){return super.copy(t,s),this.N=t.N,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],m.prototype,"input",void 0),r([o],m.prototype,"output",void 0);class w extends l{constructor(){super(...arguments),this.propertyType=i.BUFFER}copy(t,s=c){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class v extends l{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}copy(t,s=c){return super.copy(t,s),this.m=t.m,this.I=t.I,this.C=t.C,this._=t._,this.B=t.B,this.U=t.U,this.k=t.k,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.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 x extends a{constructor(t,s){super(t),this.L=s,this.L.addExtensionProperty(this)}dispose(){this.L.removeExtensionProperty(this),super.dispose()}p(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class y{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const s=atob(t.split(",")[1]),e=new Uint8Array(s.length);for(let t=0;t<s.length;t++)e[t]=s.charCodeAt(t);return e.buffer}{const s=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(s,e?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:s,byteLength:e}=t;return t.buffer.slice(s,s+e)}static concat(t){let s=0;for(const e of t)s+=e.byteLength;const e=new Uint8Array(s);let r=0;for(const s of t)e.set(new Uint8Array(s),r),r+=s.byteLength;return e.buffer}static pad(t,s=0){const e=this.padNumber(t.byteLength);if(e!==t.byteLength){const r=new Uint8Array(e);if(r.set(new Uint8Array(t)),0!==s)for(let i=t.byteLength;i<e;i++)r[i]=s;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,s){if(t===s)return!0;if(t.byteLength!==s.byteLength)return!1;const e=new DataView(t),r=new DataView(s);let i=t.byteLength;for(;i--;)if(e.getUint8(i)!==r.getUint8(i))return!1;return!0}}class A{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class T{static getSizeJPEG(t){let s,e;for(t=t.slice(4);t.length;){if(s=t.readUInt16BE(0),E(t,s),e=t[s+1],192===e||193===e||194===e)return[t.readUInt16BE(s+7),t.readUInt16BE(s+5)];t=t.slice(s+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,s){if(s>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[s])throw new TypeError("Invalid JPG, marker table corrupted")}class b{constructor(t){this.verbosity=t}debug(t){this.verbosity<=b.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=b.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=b.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=b.Verbosity.ERROR&&console.error(t)}}b.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const M="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",S=new Set,N=function(){let t="";for(let s=0;s<6;s++)t+=M.charAt(Math.floor(Math.random()*M.length));return t},R=function(){for(let t=0;t<999;t++){const t=N();if(!S.has(t))return S.add(t),t}};class I extends l{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}copy(t,s=c){return super.copy(t,s),this.mimeType=t.mimeType,this.uri=t.uri,t.image&&(this.image=t.image.slice(0)),this}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?T.getSizePNG(Buffer.from(this.image)):T.getSizeJPEG(Buffer.from(this.image))}}class C{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}copy(t){return this.texCoord=t.texCoord,this}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class _{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.G=10497}copy(t){return this.P=t.P,this.O=t.O,this.F=t.F,this.G=t.G,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.O}setMinFilter(t){return this.O=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.G}setWrapT(t){return this.G=t,this}}_.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},_.TextureMagFilter={NEAREST:9728,LINEAR:9729},_.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class B extends n{constructor(){super(...arguments),this.textureInfo=new C,this.sampler=new _}copy(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this}}class U extends n{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class k extends n{copy(t){return this}}class L extends h{linkTexture(t,s,e){if(!e)return null;const r=new B(t,s,e);return this.registerLink(r),r}linkAttribute(t,s,e){if(!e)return null;const r=new U(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new k(t,s,e);return this.registerLink(r),r}}class P extends l{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}copy(t,s=c){return super.copy(t,s),this.j=t.j,this.D=t.D,this.$=t.$,this.J=[...t.J],this.V=[...t.V],this.W=t.W,this.Y=t.Y,this.q=t.q,this.Z=t.Z,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.baseColorTexture.copy(t.baseColorTexture)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.emissiveTexture.copy(t.emissiveTexture)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.normalTexture.copy(t.normalTexture)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.occlusionTexture.copy(t.occlusionTexture)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(t.metallicRoughnessTexture)),this}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=t,this}getAlphaMode(){return this.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],P.prototype,"baseColorTexture",void 0),r([o],P.prototype,"emissiveTexture",void 0),r([o],P.prototype,"normalTexture",void 0),r([o],P.prototype,"occlusionTexture",void 0),r([o],P.prototype,"metallicRoughnessTexture",void 0);class O extends l{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}copy(t,s=c){return super.copy(t,s),this.X=[...t.X],this.clearGraphChildList(this.primitives),t.primitives.forEach(t=>this.addPrimitive(s(t.getChild()))),this}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([u],O.prototype,"primitives",void 0);class F extends a{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE,this.H=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=c){return super.copy(t,s),this.H=t.H,t.indices&&this.setIndices(s(t.indices.getChild())),t.material&&this.setMaterial(s(t.material.getChild())),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this.clearGraphChildList(this.targets),t.targets.forEach(t=>this.addTarget(s(t.getChild()))),this}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.graph.linkIndex("index",this,t),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}getMaterial(){return this.material?this.material.getChild():null}setMaterial(t){return this.material=this.graph.link("material",this,t),this}getMode(){return this.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],F.prototype,"material",void 0),r([o],F.prototype,"indices",void 0),r([u],F.prototype,"attributes",void 0),r([u],F.prototype,"targets",void 0);class G extends a{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}}r([u],G.prototype,"attributes",void 0);class j extends l{constructor(){super(...arguments),this.propertyType=i.NODE,this.K=[0,0,0],this.tt=[0,0,0,1],this.st=[1,1,1],this.X=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=c){return super.copy(t,s),this.K=[...t.K],this.tt=[...t.tt],this.st=[...t.st],this.X=[...t.X],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild()))),this}getTranslation(){return this.K}getRotation(){return this.tt}getScale(){return this.st}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.st=t,this}addChild(t){const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([o],j.prototype,"camera",void 0),r([o],j.prototype,"mesh",void 0),r([o],j.prototype,"skin",void 0),r([u],j.prototype,"children",void 0);class D extends a{constructor(){super(...arguments),this.propertyType=i.ROOT,this.et={generator:"glTF-Transform v0.5.0",version:"2.0"},this.rt=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[]}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=c){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.et,t.et),t.accessors.forEach(t=>this.it(s(t.getChild()))),t.animations.forEach(t=>this.nt(s(t.getChild()))),t.buffers.forEach(t=>this.ht(s(t.getChild()))),t.cameras.forEach(t=>this.ot(s(t.getChild()))),t.materials.forEach(t=>this.ut(s(t.getChild()))),t.meshes.forEach(t=>this.ct(s(t.getChild()))),t.nodes.forEach(t=>this.at(s(t.getChild()))),t.scenes.forEach(t=>this.lt(s(t.getChild()))),t.skins.forEach(t=>this.ft(s(t.getChild()))),t.textures.forEach(t=>this.dt(s(t.getChild()))),this}getAsset(){return this.et}listExtensionsUsed(){return Array.from(this.rt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}pt(t){if(this.rt.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.rt.add(t),this}gt(t){return this.rt.delete(t),this}lt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}it(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],D.prototype,"accessors",void 0),r([u],D.prototype,"animations",void 0),r([u],D.prototype,"buffers",void 0),r([u],D.prototype,"cameras",void 0),r([u],D.prototype,"materials",void 0),r([u],D.prototype,"meshes",void 0),r([u],D.prototype,"nodes",void 0),r([u],D.prototype,"scenes",void 0),r([u],D.prototype,"skins",void 0),r([u],D.prototype,"textures",void 0);class $ extends l{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.nodes),t.nodes.forEach(t=>this.addNode(s(t.getChild()))),this}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],$.prototype,"nodes",void 0);class z extends l{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=c){return super.copy(t,s),t.skeleton&&this.setSkeleton(s(t.skeleton.getChild())),t.inverseBindMatrices&&this.setInverseBindMatrices(s(t.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),t.joints.forEach(t=>this.addJoint(s(t.getChild()))),this}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const s=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,s)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}r([o],z.prototype,"skeleton",void 0),r([o],z.prototype,"inverseBindMatrices",void 0),r([u],z.prototype,"joints",void 0);class J{constructor(){this.graph=new L,this.root=new D(this.graph),this.logger=new b(b.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){return(new J).merge(this)}merge(t){const s={};for(const e of t.getRoot().listExtensionsUsed()){const t=this.createExtension(e.constructor);e.isRequired()&&t.setRequired(!0),s[t.extensionName]=t}const e=new Set,r=new Map;e.add(t.root),r.set(t.root,this.root);for(const i of t.graph.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof x?new i(this.graph,s[t.extensionName]):new i(this.graph);r.set(t,n),e.add(t)}const i=t=>r.get(t);for(const t of e)r.get(t).copy(t,i);return this}transform(...t){for(const s of t)s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t){const s=new $(this.graph,t);return this.root.lt(s),s}createNode(t){const s=new j(this.graph,t);return this.root.at(s),s}createCamera(t){const s=new v(this.graph,t);return this.root.ot(s),s}createSkin(t){const s=new z(this.graph,t);return this.root.ft(s),s}createMesh(t){const s=new O(this.graph,t);return this.root.ct(s),s}createPrimitive(){return new F(this.graph)}createPrimitiveTarget(t){return new G(this.graph,t)}createMaterial(t){const s=new P(this.graph,t);return this.root.ut(s),s}createTexture(t){const s=new I(this.graph,t);return this.root.dt(s),s}createAnimation(t){const s=new p(this.graph,t);return this.root.nt(s),s}createAnimationChannel(){return new g(this.graph)}createAnimationSampler(){return new m(this.graph)}createAccessor(t,s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new f(this.graph,t).setBuffer(s);return this.root.it(e),e}createBuffer(t){const s=new w(this.graph,t);return this.root.ht(s),s}}class V{constructor(t){this.doc=t,this.provideTypes=[],this.wt=!1,this.vt=new Set,t.getRoot().pt(this)}dispose(){this.doc.getRoot().gt(this);for(const t of this.vt)t.dispose()}isRequired(){return this.wt}setRequired(t){return this.wt=t,this}addExtensionProperty(t){return this.vt.add(t),this}removeExtensionProperty(t){return this.vt.delete(t),this}provide(t,s){return this}}class W{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){void 0!==s.texCoord&&t.setTexCoord(s.texCoord)}setTextureSampler(t,s){const e=this.nativeDocument.json.textures[s.index];if(void 0===e.sampler)return;const r=this.nativeDocument.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const Y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class q{static read(r,n){const{json:h}=r,o=new J;if("2.0"!==h.asset.version)throw new Error(`Unsupported glTF version, "${h.asset.version}".`);if(h.extensionsRequired)for(const t of h.extensionsRequired)if(!n.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);o.getRoot().getAsset().generator=r.json.asset.generator;const u=new W(r),c=h.extensionsUsed||[],a=h.extensionsRequired||[];for(const t of n.extensions)c.includes(t.EXTENSION_NAME)&&o.createExtension(t).setRequired(a.includes(t.EXTENSION_NAME));u.buffers=(h.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(h.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(h.accessors||[]).map(t=>{const s=o.createAccessor(t.name,u.bufferViewBuffers[t.bufferView]);let e;return s.setType(t.type),e=void 0!==t.sparse?function(t,s){const e=Y[t.componentType],r=f.getElementSize(t.type);let i;i=void 0!==t.bufferView?Z(t,s).slice():new e(t.count*r);const n=t.sparse.count,h={...t,...t.sparse.indices,count:n,type:"SCALAR"},o={...t,...t.sparse.values,count:n},u=Z(h,s),c=Z(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(t,r):Z(t,r).slice(),void 0!==t.normalized&&s.setNormalized(t.normalized),s.setArray(e),s});const l=h.images||[],d=h.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(i.TEXTURE)).forEach(t=>t.provide(u,i.TEXTURE)),u.textures=l.map(t=>{const s=o.createTexture(t.name);if(void 0!==t.bufferView){const e=h.bufferViews[t.bufferView],i=r.json.buffers[e.buffer],n=e.byteOffset||0,o=(i.uri?r.resources[i.uri]:r.resources["xt"]).slice(n,n+e.byteLength);s.setImage(o)}else void 0!==t.uri&&(s.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&s.setURI(t.uri));if(void 0!==t.mimeType)s.setMimeType(t.mimeType);else if(t.uri){const e=A.extension(t.uri);s.setMimeType(T.extensionToMimeType(e))}return s}),u.materials=(h.materials||[]).map(t=>{const s=o.createMaterial(t.name);void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[d[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t),u.setTextureSampler(s.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e),u.setTextureSampler(s.getEmissiveTextureSampler(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),u.setTextureSampler(s.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),u.setTextureSampler(s.getOcclusionTextureSampler(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[d[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t),u.setTextureSampler(s.getMetallicRoughnessTextureSampler(),t)}return s}),u.meshes=(h.meshes||[]).map(t=>{const s=o.createMesh(t.name);return void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(h.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return"perspective"===t.type?s.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):s.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),s});const p=h.nodes||[];return u.nodes=p.map(r=>{const i=o.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(s([],r.matrix)),i.setScale(e([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),u.skins=(h.skins||[]).map(t=>{const s=o.createSkin(t.name);void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(u.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(u.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(u.nodes[e]);return s}),p.map((t,s)=>{const e=u.nodes[s];(t.children||[]).forEach(t=>e.addChild(u.nodes[t])),void 0!==t.mesh&&e.setMesh(u.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(u.cameras[t.camera]),void 0!==t.skin&&e.setSkin(u.skins[t.skin])}),u.animations=(h.animations||[]).map(t=>{const s=o.createAnimation(t.name),e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);s.addChannel(r)}),s}),u.scenes=(h.scenes||[]).map(t=>{const s=o.createScene(t.name);return(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addNode(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}}function Z(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["xt"],n=Y[t.componentType],h=f.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["xt"],n=Y[t.componentType],h=f.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case 5126:i=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[s*h+e]=i}return c}(t,s);const o=(e.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class X{constructor(t,s){this.nativeDocument=t,this.options=s,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}createTextureInfoDef(t,s,e){const r={magFilter:e.getMagFilter()||void 0,minFilter:e.getMinFilter()||void 0,wrapS:e.getWrapS(),wrapT:e.getWrapT()},i=JSON.stringify(r);this.samplerDefIndexMap.has(i)||(this.samplerDefIndexMap.set(i,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(r));const n={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(i)},h=JSON.stringify(n);return this.textureDefIndexMap.has(h)||(this.textureDefIndexMap.set(h,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(n)),{index:this.textureDefIndexMap.get(h),texCoord:s.getTexCoord()}}createPropertyDef(t){const s={};return t.getName()&&(s.name=t.getName()),Object.keys(t.getExtras()).length>0&&(s.extras=t.getExtras()),s}createAccessorDef(t){const s=this.createPropertyDef(t);return s.type=t.getType(),s.componentType=t.getComponentType(),s.count=t.getCount(),t.getMax(s.max=[]),t.getMin(s.min=[]),s.normalized=t.getNormalized(),s}createImageData(t,s,e){if(this.options.isGLB)this.imageData.push(s),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=T.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.nativeDocument.resources[t.uri]=s}}}class H{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}class K{static write(t,s){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=r.json;i.asset.generator="glTF-Transform v0.5.0";const n=new X(r,s),h=e.listBuffers().length,o=e.listTextures().length;function u(t,s,e,r){const h=[];let o=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length;const e=y.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,h.push(e),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:y.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function c(t,s,e){const r=t[0].getCount();let h=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length,t.byteOffset=h;const e=s.getElementSize(),r=s.getComponentSize();h+=y.padNumber(e*r),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),c=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*h+e+r*i,a=o[s*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)}}e+=y.padNumber(t*i)}}return i.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new H(h>1,s.basename),n.imageURIGenerator=new H(o>1,s.basename),n.logger=t.getLogger();const a=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof f){const e=a.get(t)||[];e.push(s),a.set(t,e)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=e.listTextures().map((t,s)=>{const e=n.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(e,t.getImage(),t),n.imageIndexMap.set(t,s),e}),i.buffers=[],e.listBuffers().forEach(t=>{const e=n.createPropertyDef(t),h=new Map,o=new Set,l=new Set,d=t.listParents().filter(t=>!(t instanceof D));for(const t of d){if(!(t instanceof f))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1;const i=a.get(t)||[];for(const t of i)t instanceof U?s=!0:t instanceof k?e=!0:r=!0;if(s||e||r||(r=!0),!s||e||r)if(!e||s||r){if(!r||s||e)throw new Error("Attribute or index accessors must be used only for that purpose.");l.add(t)}else o.add(t);else{const s=i[0].getParent(),e=h.get(s)||new Set;e.add(t),h.set(s,e)}}const p=[],g=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),g,w,34963);w+=t.byteLength,p.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const s=c(Array.from(t),g,w);w+=s.byteLength,p.push(...s.buffers)}if(l.size){const t=u(Array.from(l),g,w);w+=t.byteLength,p.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,p.push(n.imageData[t]);w?(s.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=w,r.resources[m]=y.concat(p),i.buffers.push(e)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=e.listMaterials().map((t,s)=>{const e=n.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(e.alphaCutoff=t.getAlphaCutoff()),e.doubleSided=t.getDoubleSided(),e.pbrMetallicRoughness={},e.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),e.emissiveFactor=t.getEmissiveFactor(),e.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),e.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const s=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo(),i=t.getBaseColorTextureSampler();e.pbrMetallicRoughness.baseColorTexture=n.createTextureInfoDef(s,r,i)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();e.emissiveTexture=n.createTextureInfoDef(s,r,i)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),e.normalTexture=h}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),e.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();e.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(s,r,i)}return n.materialIndexMap.set(t,s),e}),i.meshes=e.listMeshes().map((t,s)=>{const e=n.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=n.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),t.getIndices()&&(s.indices=n.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=n.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=n.accessorIndexMap.get(e.getAttribute(s));s.targets=s.targets||[],s.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),s}),t.getWeights().length&&(e.weights=t.getWeights()),r&&(e.extras=e.extras||{},e.extras.targetNames=r),n.meshIndexMap.set(t,s),e}),i.cameras=e.listCameras().map((t,s)=>{const e=n.createPropertyDef(t);return e.type=t.getType(),"perspective"===e.type?e.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:e.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},n.cameraIndexMap.set(t,s),e}),i.nodes=e.listNodes().map((t,s)=>{const e=n.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),n.nodeIndexMap.set(t,s),e}),i.skins=e.listSkins().map((t,s)=>{const e=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=n.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=i.nodes[s];t.getMesh()&&(e.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=e.listAnimations().map(t=>{const s=n.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=n.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),i.scenes=e.listScenes().map(t=>{const s=n.createPropertyDef(t);return s.nodes=t.listNodes().map(t=>n.nodeIndexMap.get(t)),s}),i.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),i.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(n)),function(t){const s=[];for(const e in t){const r=t[e];Array.isArray(r)&&0===r.length?s.push(e):null!==r&&""!==r||s.push(r)}for(const e of s)delete t[e]}(i),r}}class Q{constructor(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return q.read(t,{extensions:this.rt})}createNativeDocument(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return K.write(t,s)}unpackGLB(t){const s=new Uint32Array(t,0,3);if(1179937895!==s[0])throw new Error("Invalid glTF asset.");if(2!==s[1])throw new Error(`Unsupported glTF binary version, "${s[1]}".`);const e=new Uint32Array(t,12,2),r=e[0],i=new Uint32Array(t,20+r,2);if(1313821514!==e[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=y.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:s,resources:e}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(s),i=y.pad(y.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=y.concat([n,i]),o=y.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=y.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return y.concat([a,h,c])}}class tt extends Q{constructor(t,s){super(),this.fs=t,this.path=s}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,s){t.match(/\.glb$/)?this.writeGLB(t,s):this.writeGLTF(t,s)}readGLB(t){const s=this.fs.readFileSync(t),e=y.trim(s);return this.unpackGLB(e)}readGLTF(t){const s=this.path.dirname(t),e={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri&&!t.uri.match(/data:/)){const r=this.path.resolve(s,t.uri);e.resources[t.uri]=y.trim(this.fs.readFileSync(r))}else{const s=`__${R()}.${A.extension(t.uri)}`;e.resources[s]=y.createBufferFromDataURI(t.uri),t.uri=s}}),q.read(e,{extensions:this.rt})}writeGLTF(t,s){const e={basename:A.basename(t),isGLB:!1},{json:r,resources:i}=K.write(s,e),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const s=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),s)})}writeGLB(t,s){const e=Buffer.from(this.packGLB(s));this.fs.writeFileSync(t,e)}}class st extends Q{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const s={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{s.json=t;const e=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>this.createDocument(s))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}export{f as Accessor,p as Animation,g as AnimationChannel,m as AnimationSampler,w as Buffer,y as BufferUtils,c as COPY_IDENTITY,v as Camera,J as Document,V as Extension,x as ExtensionProperty,A as FileUtils,h as Graph,o as GraphChild,T as ImageUtils,b as Logger,P as Material,O as Mesh,j as Node,tt as NodeIO,F as Primitive,G as PrimitiveTarget,a as Property,i as PropertyType,W as ReaderContext,D as Root,$ as Scene,z as Skin,I as Texture,C as TextureInfo,B as TextureLink,_ as TextureSampler,st as WebIO,X as WriterContext,R as uuid}; | ||
import{getTranslation as t,getRotation as s,getScaling as e}from"gl-matrix/mat4";function r(t,s,e,r){var i,n=arguments.length,h=n<3?s:null===r?r=Object.getOwnPropertyDescriptor(s,e):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,s,e,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(h=(n<3?i(h):n>3?i(s,e,h):i(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h}var i;!function(t){t.ACCESSOR="Accessor",t.ANIMATION="Animation",t.ANIMATION_CHANNEL="AnimationChannel",t.ANIMATION_SAMPLER="AnimationSampler",t.BUFFER="Buffer",t.CAMERA="Camera",t.MATERIAL="Material",t.MESH="Mesh",t.PRIMITIVE="Primitive",t.PRIMITIVE_TARGET="PrimitiveTarget",t.NODE="Node",t.ROOT="Root",t.SCENE="Scene",t.SKIN="Skin",t.TEXTURE="Texture",t.TEXTURE_INFO="TextureInfo",t.TEXTURE_SAMPLER="TextureSampler"}(i||(i={}));class n{constructor(t,s,e){if(this.t=t,this.s=s,this.i=e,this.h=!1,this.o=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.s}getChild(){return this.i}setChild(t){return this.i=t,this}dispose(){this.h||(this.h=!0,this.o.forEach(t=>t()),this.o.length=0)}onDispose(t){return this.o.push(t),this}isDisposed(){return this.h}}class h{constructor(){this.u=[]}getLinks(){return this.u}listParents(t){return this.u.filter(s=>s.getChild()===t).map(t=>t.getParent())}listChildren(t){return this.u.filter(s=>s.getParent()===t).map(t=>t.getChild())}disconnectChildren(t){return this.u.filter(s=>s.getParent()===t).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=this.u.filter(s=>s.getChild()===t);return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}link(t,s,e){if(!e)return null;const r=new n(t,s,e);return this.registerLink(r),r}registerLink(t){return this.u.push(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.u=this.u.filter(s=>s!==t),this}}function o(t,s){Object.defineProperty(t,s,{get:function(){return this["__"+s]},set:function(t){const e=this["__"+s];e&&!Array.isArray(e)&&e.dispose(),t&&!Array.isArray(t)&&t.onDispose(()=>{this["__"+s]=null}),this["__"+s]=t},enumerable:!0})}function u(t,s){}const c=t=>t;class a extends class{constructor(t){this.h=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.h}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.h=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.getLinks().filter(s=>s.getParent()===this&&s.getChild()===t).forEach(t=>t.setChild(s)),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0,t.push(...e)}),this}removeGraphChild(t,s){return t.filter(t=>t.getChild()===s).forEach(t=>t.dispose()),this}clearGraphChildList(t){for(;t.length>0;)t[0].dispose();return this}listGraphParents(){return this.graph.listParents(this)}}{constructor(t,s=""){super(t),this.l={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.l}setExtras(t){return this.l=t,this}clone(){return new(0,this.constructor)(this.graph).copy(this,c)}copy(t,s){return this.t=t.t,this.l=JSON.parse(JSON.stringify(t.l)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}class l extends a{constructor(){super(...arguments),this.extensions=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.constructor,s(e))}),this}getExtension(t){const s=t.EXTENSION_NAME,e=this.extensions.find(t=>t.getChild().extensionName===s);return e?e.getChild():null}setExtension(t,s){const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.p(this),this.addGraphChild(this.extensions,this.graph.link(s.extensionName,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}r([u],l.prototype,"extensions",void 0);class f extends l{constructor(){super(...arguments),this.propertyType=i.ACCESSOR,this.g=null,this.m="SCALAR",this.v=null,this.A=!1,this.T=d,this.M=d,this.buffer=null}copy(t,s=c){return super.copy(t,s),this.g=t.g.slice(),this.m=t.m,this.v=t.v,this.A=t.A,this.T=t.T,this.M=t.M,t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4;default:throw new Error("Unexpected component type: "+t)}}getMinNormalized(t){const s=this.getElementSize();this.getMin(t);for(let e=0;e<s;e++)t[e]=this.M(t[e]);return t}getMin(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.g[r+s];Number.isFinite(e)&&(t[s]=Math.min(t[s],e))}return t}getMaxNormalized(t){const s=this.getElementSize();this.getMax(t);for(let e=0;e<s;e++)t[e]=this.M(t[e]);return t}getMax(t){const s=this.getCount(),e=this.getElementSize();for(let s=0;s<e;s++)t[s]=-Infinity;for(let r=0;r<s*e;r+=e)for(let s=0;s<e;s++){const e=this.g[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.g.length/this.getElementSize()}getType(){return this.m}setType(t){return this.m=t,this}getElementSize(){return f.getElementSize(this.m)}getComponentSize(){return this.g.BYTES_PER_ELEMENT}getComponentType(){return this.v}getNormalized(){return this.A}setNormalized(t){return this.A=t,t?(this.M=t=>function(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1)}}(t,this.v),this.T=t=>function(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t)}}(t,this.v)):(this.M=d,this.T=d),this}getScalar(t){const s=this.getElementSize();return this.M(this.g[t*s])}setScalar(t,s){return this.g[t*this.getElementSize()]=this.T(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this.M(this.g[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.g[t*e+r]=this.T(s[r]);return this}getBuffer(){return this.buffer.getChild()}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.g}setArray(t){return this.v=function(t){switch(t.constructor){case Float32Array:return 5126;case Uint32Array:return 5125;case Uint16Array:return 5123;case Uint8Array:return 5121;case Int16Array:return 5122;case Int8Array:return 5120;default:throw new Error("Unknown accessor componentType.")}}(t),this.g=t,this}getByteLength(){return this.g.byteLength}}function d(t){return t}f.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT3:"MAT3",MAT4:"MAT4"},f.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},r([o],f.prototype,"buffer",void 0);class p extends l{constructor(){super(...arguments),this.propertyType=i.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.channels),this.clearGraphChildList(this.samplers),t.channels.forEach(t=>this.addChannel(s(t.getChild()))),t.samplers.forEach(t=>this.addSampler(s(t.getChild()))),this}addChannel(t){const s=this.graph.link("channel",this,t);return this.addGraphChild(this.channels,s)}removeChannel(t){return this.removeGraphChild(this.channels,t)}listChannels(){return this.channels.map(t=>t.getChild())}addSampler(t){const s=this.graph.link("sampler",this,t);return this.addGraphChild(this.samplers,s)}removeSampler(t){return this.removeGraphChild(this.samplers,t)}listSamplers(){return this.samplers.map(t=>t.getChild())}}r([u],p.prototype,"channels",void 0),r([u],p.prototype,"samplers",void 0);class g extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION_CHANNEL,this.S=null,this.targetNode=null,this.sampler=null}copy(t,s=c){return super.copy(t,s),this.S=t.S,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.S}setTargetPath(t){return this.S=t,this}getTargetNode(){return this.targetNode?this.targetNode.getChild():null}setTargetNode(t){return this.targetNode=this.graph.link("target.node",this,t),this}getSampler(){return this.sampler?this.sampler.getChild():null}setSampler(t){return this.sampler=this.graph.link("sampler",this,t),this}}r([o],g.prototype,"targetNode",void 0),r([o],g.prototype,"sampler",void 0);class m extends a{constructor(){super(...arguments),this.propertyType=i.ANIMATION_SAMPLER,this.N="LINEAR",this.input=null,this.output=null}copy(t,s=c){return super.copy(t,s),this.N=t.N,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.N}setInterpolation(t){return this.N=t,this}getInput(){return this.input?this.input.getChild():null}setInput(t){return this.input=this.graph.link("input",this,t),this}getOutput(){return this.output?this.output.getChild():null}setOutput(t){return this.output=this.graph.link("output",this,t),this}}r([o],m.prototype,"input",void 0),r([o],m.prototype,"output",void 0);class w extends l{constructor(){super(...arguments),this.propertyType=i.BUFFER}copy(t,s=c){return super.copy(t,s),this.R=t.R,this}getURI(){return this.R}setURI(t){return this.R=t,this}}class v extends l{constructor(){super(...arguments),this.propertyType=i.CAMERA,this.m="perspective"}copy(t,s=c){return super.copy(t,s),this.m=t.m,this.I=t.I,this.C=t.C,this._=t._,this.B=t.B,this.U=t.U,this.k=t.k,this}getType(){return this.m}setType(t){return this.m=t,this}getZNear(){return this.I}setZNear(t){return this.I=t,this}getZFar(){return this.C}setZFar(t){return this.C=t,this}getAspectRatio(){return this._}setAspectRatio(t){return this._=t,this}getYFov(){return this.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 x extends a{constructor(t,s){super(t),this.L=s,this.L.addExtensionProperty(this)}dispose(){this.L.removeExtensionProperty(this),super.dispose()}p(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class y{static createBufferFromDataURI(t){if("undefined"==typeof Buffer){const s=atob(t.split(",")[1]),e=new Uint8Array(s.length);for(let t=0;t<s.length;t++)e[t]=s.charCodeAt(t);return e.buffer}{const s=t.split(",")[1],e=t.indexOf("base64")>=0;return this.trim(Buffer.from(s,e?"base64":"utf8"))}}static encodeText(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).buffer:this.trim(Buffer.from(t))}static decodeText(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}static trim(t){const{byteOffset:s,byteLength:e}=t;return t.buffer.slice(s,s+e)}static concat(t){let s=0;for(const e of t)s+=e.byteLength;const e=new Uint8Array(s);let r=0;for(const s of t)e.set(new Uint8Array(s),r),r+=s.byteLength;return e.buffer}static pad(t,s=0){const e=this.padNumber(t.byteLength);if(e!==t.byteLength){const r=new Uint8Array(e);if(r.set(new Uint8Array(t)),0!==s)for(let i=t.byteLength;i<e;i++)r[i]=s;return r.buffer}return t}static padNumber(t){return 4*Math.ceil(t/4)}static equals(t,s){if(t===s)return!0;if(t.byteLength!==s.byteLength)return!1;const e=new DataView(t),r=new DataView(s);let i=t.byteLength;for(;i--;)if(e.getUint8(i)!==r.getUint8(i))return!1;return!0}}class A{static basename(t){return t.split(/[\\/]/).pop().split(/[.]/).shift()}static extension(t){return 0!==t.indexOf("data:")?t.split(/[\\/]/).pop().split(/[.]/).pop():0===t.indexOf("data:image/png")?"png":0===t.indexOf("data:image/jpeg")?"jpeg":"bin"}}class T{static getSizeJPEG(t){let s,e;for(t=t.slice(4);t.length;){if(s=t.readUInt16BE(0),E(t,s),e=t[s+1],192===e||193===e||194===e)return[t.readUInt16BE(s+7),t.readUInt16BE(s+5)];t=t.slice(s+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,s){if(s>t.length)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t[s])throw new TypeError("Invalid JPG, marker table corrupted")}class b{constructor(t){this.verbosity=t}debug(t){this.verbosity<=b.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=b.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=b.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=b.Verbosity.ERROR&&console.error(t)}}b.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0};const M="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",S=new Set,N=function(){let t="";for(let s=0;s<6;s++)t+=M.charAt(Math.floor(Math.random()*M.length));return t},R=function(){for(let t=0;t<999;t++){const t=N();if(!S.has(t))return S.add(t),t}};class I extends l{constructor(){super(...arguments),this.propertyType=i.TEXTURE,this.image=null,this.mimeType="",this.uri=""}copy(t,s=c){return super.copy(t,s),this.mimeType=t.mimeType,this.uri=t.uri,t.image&&(this.image=t.image.slice(0)),this}getMimeType(){return this.mimeType}setMimeType(t){return this.mimeType=t,this}getURI(){return this.uri}setURI(t){return this.uri=t,this}getImage(){return this.image}setImage(t){return this.image=t,this}getSize(){let t;return t=this.mimeType?"image/png"===this.mimeType:this.uri.match(/\.png$/),t?T.getSizePNG(Buffer.from(this.image)):T.getSizeJPEG(Buffer.from(this.image))}}class C{constructor(){this.propertyType=i.TEXTURE_INFO,this.texCoord=0}copy(t){return this.texCoord=t.texCoord,this}getTexCoord(){return this.texCoord}setTexCoord(t){return this.texCoord=t,this}}class _{constructor(){this.propertyType=i.TEXTURE_SAMPLER,this.P=null,this.O=null,this.F=10497,this.G=10497}copy(t){return this.P=t.P,this.O=t.O,this.F=t.F,this.G=t.G,this}getMagFilter(){return this.P}setMagFilter(t){return this.P=t,this}getMinFilter(){return this.O}setMinFilter(t){return this.O=t,this}getWrapS(){return this.F}setWrapS(t){return this.F=t,this}getWrapT(){return this.G}setWrapT(t){return this.G=t,this}}_.TextureWrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},_.TextureMagFilter={NEAREST:9728,LINEAR:9729},_.TextureMinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};class B extends n{constructor(){super(...arguments),this.textureInfo=new C,this.sampler=new _}copy(t){return this.textureInfo.copy(t.textureInfo),this.sampler.copy(t.sampler),this}}class U extends n{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class k extends n{copy(t){return this}}class L extends h{linkTexture(t,s,e){if(!e)return null;const r=new B(t,s,e);return this.registerLink(r),r}linkAttribute(t,s,e){if(!e)return null;const r=new U(t,s,e);return this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new k(t,s,e);return this.registerLink(r),r}}class P extends l{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}copy(t,s=c){return super.copy(t,s),this.j=t.j,this.D=t.D,this.$=t.$,this.J=[...t.J],this.V=[...t.V],this.W=t.W,this.Y=t.Y,this.q=t.q,this.Z=t.Z,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.baseColorTexture.copy(t.baseColorTexture)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.emissiveTexture.copy(t.emissiveTexture)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.normalTexture.copy(t.normalTexture)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.occlusionTexture.copy(t.occlusionTexture)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.metallicRoughnessTexture.copy(t.metallicRoughnessTexture)),this}getDoubleSided(){return this.$}setDoubleSided(t){return this.$=t,this}getAlphaMode(){return this.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],P.prototype,"baseColorTexture",void 0),r([o],P.prototype,"emissiveTexture",void 0),r([o],P.prototype,"normalTexture",void 0),r([o],P.prototype,"occlusionTexture",void 0),r([o],P.prototype,"metallicRoughnessTexture",void 0);class O extends l{constructor(){super(...arguments),this.propertyType=i.MESH,this.X=[],this.primitives=[]}copy(t,s=c){return super.copy(t,s),this.X=[...t.X],this.clearGraphChildList(this.primitives),t.primitives.forEach(t=>this.addPrimitive(s(t.getChild()))),this}addPrimitive(t){return this.addGraphChild(this.primitives,this.graph.link("primitive",this,t))}removePrimitive(t){return this.removeGraphChild(this.primitives,t)}listPrimitives(){return this.primitives.map(t=>t.getChild())}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([u],O.prototype,"primitives",void 0);class F extends a{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE,this.H=4,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=c){return super.copy(t,s),this.H=t.H,t.indices&&this.setIndices(s(t.indices.getChild())),t.material&&this.setMaterial(s(t.material.getChild())),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this.clearGraphChildList(this.targets),t.targets.forEach(t=>this.addTarget(s(t.getChild()))),this}getIndices(){return this.indices?this.indices.getChild():null}setIndices(t){return this.indices=this.graph.linkIndex("index",this,t),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}getMaterial(){return this.material?this.material.getChild():null}setMaterial(t){return this.material=this.graph.link("material",this,t),this}getMode(){return this.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],F.prototype,"material",void 0),r([o],F.prototype,"indices",void 0),r([u],F.prototype,"attributes",void 0),r([u],F.prototype,"targets",void 0);class G extends a{constructor(){super(...arguments),this.propertyType=i.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.attributes),t.listSemantics().forEach(e=>{this.setAttribute(e,s(t.getAttribute(e)))}),this}getAttribute(t){const s=this.attributes.find(s=>s.semantic===t);return s?s.getChild():null}setAttribute(t,s){const e=this.getAttribute(t);if(e&&this.removeGraphChild(this.attributes,e),!s)return this;const r=this.graph.linkAttribute(t.toLowerCase(),this,s);return r.semantic=t,this.addGraphChild(this.attributes,r)}listAttributes(){return this.attributes.map(t=>t.getChild())}listSemantics(){return this.attributes.map(t=>t.semantic)}}r([u],G.prototype,"attributes",void 0);class j extends l{constructor(){super(...arguments),this.propertyType=i.NODE,this.K=[0,0,0],this.tt=[0,0,0,1],this.st=[1,1,1],this.X=[],this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=c){return super.copy(t,s),this.K=[...t.K],this.tt=[...t.tt],this.st=[...t.st],this.X=[...t.X],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild()))),this}getTranslation(){return this.K}getRotation(){return this.tt}getScale(){return this.st}setTranslation(t){return this.K=t,this}setRotation(t){return this.tt=t,this}setScale(t){return this.st=t,this}addChild(t){const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s)}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getMesh(){return this.mesh?this.mesh.getChild():null}setMesh(t){return this.mesh=this.graph.link("mesh",this,t),this}getCamera(){return this.camera?this.camera.getChild():null}setCamera(t){return this.camera=this.graph.link("camera",this,t),this}getSkin(){return this.skin?this.skin.getChild():null}setSkin(t){return this.skin=this.graph.link("skin",this,t),this}getWeights(){return this.X}setWeights(t){return this.X=t,this}}r([o],j.prototype,"camera",void 0),r([o],j.prototype,"mesh",void 0),r([o],j.prototype,"skin",void 0),r([u],j.prototype,"children",void 0);class D extends a{constructor(){super(...arguments),this.propertyType=i.ROOT,this.et={generator:"glTF-Transform v0.5.1",version:"2.0"},this.rt=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[]}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=c){if(super.copy(t,s),!s)throw new Error("Root cannot be copied.");return Object.assign(this.et,t.et),t.accessors.forEach(t=>this.it(s(t.getChild()))),t.animations.forEach(t=>this.nt(s(t.getChild()))),t.buffers.forEach(t=>this.ht(s(t.getChild()))),t.cameras.forEach(t=>this.ot(s(t.getChild()))),t.materials.forEach(t=>this.ut(s(t.getChild()))),t.meshes.forEach(t=>this.ct(s(t.getChild()))),t.nodes.forEach(t=>this.at(s(t.getChild()))),t.scenes.forEach(t=>this.lt(s(t.getChild()))),t.skins.forEach(t=>this.ft(s(t.getChild()))),t.textures.forEach(t=>this.dt(s(t.getChild()))),this}getAsset(){return this.et}listExtensionsUsed(){return Array.from(this.rt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}pt(t){if(this.rt.has(t))throw new Error(`Extension "${t.extensionName}" is already enabled.`);return this.rt.add(t),this}gt(t){return this.rt.delete(t),this}lt(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}at(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}ot(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}ft(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}ct(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}ut(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}dt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}nt(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}it(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}ht(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}r([u],D.prototype,"accessors",void 0),r([u],D.prototype,"animations",void 0),r([u],D.prototype,"buffers",void 0),r([u],D.prototype,"cameras",void 0),r([u],D.prototype,"materials",void 0),r([u],D.prototype,"meshes",void 0),r([u],D.prototype,"nodes",void 0),r([u],D.prototype,"scenes",void 0),r([u],D.prototype,"skins",void 0),r([u],D.prototype,"textures",void 0);class $ extends l{constructor(){super(...arguments),this.propertyType=i.SCENE,this.nodes=[]}copy(t,s=c){return super.copy(t,s),this.clearGraphChildList(this.nodes),t.nodes.forEach(t=>this.addNode(s(t.getChild()))),this}addNode(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}removeNode(t){return this.removeGraphChild(this.nodes,t)}listNodes(){return this.nodes.map(t=>t.getChild())}}r([u],$.prototype,"nodes",void 0);class z extends l{constructor(){super(...arguments),this.propertyType=i.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=c){return super.copy(t,s),t.skeleton&&this.setSkeleton(s(t.skeleton.getChild())),t.inverseBindMatrices&&this.setInverseBindMatrices(s(t.inverseBindMatrices.getChild())),this.clearGraphChildList(this.joints),t.joints.forEach(t=>this.addJoint(s(t.getChild()))),this}getSkeleton(){return this.skeleton?this.skeleton.getChild():null}setSkeleton(t){return this.skeleton=this.graph.link("skeleton",this,t),this}getInverseBindMatrices(){return this.inverseBindMatrices?this.inverseBindMatrices.getChild():null}setInverseBindMatrices(t){return this.inverseBindMatrices=this.graph.link("inverseBindMatrices",this,t),this}addJoint(t){const s=this.graph.link("joint",this,t);return this.addGraphChild(this.joints,s)}removeJoint(t){return this.removeGraphChild(this.joints,t)}listJoints(){return this.joints.map(t=>t.getChild())}}r([o],z.prototype,"skeleton",void 0),r([o],z.prototype,"inverseBindMatrices",void 0),r([u],z.prototype,"joints",void 0);class J{constructor(){this.graph=new L,this.root=new D(this.graph),this.logger=new b(b.Verbosity.INFO)}getRoot(){return this.root}getGraph(){return this.graph}getLogger(){return this.logger}setLogger(t){return this.logger=t,this}clone(){return(new J).merge(this)}merge(t){const s={};for(const e of t.getRoot().listExtensionsUsed()){const t=this.createExtension(e.constructor);e.isRequired()&&t.setRequired(!0),s[t.extensionName]=t}const e=new Set,r=new Map;e.add(t.root),r.set(t.root,this.root);for(const i of t.graph.getLinks())for(const t of[i.getParent(),i.getChild()])if(!e.has(t)){const i=t.constructor,n=t instanceof x?new i(this.graph,s[t.extensionName]):new i(this.graph);r.set(t,n),e.add(t)}const i=t=>r.get(t);for(const t of e)r.get(t).copy(t,i);return this}transform(...t){for(const s of t)s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t){const s=new $(this.graph,t);return this.root.lt(s),s}createNode(t){const s=new j(this.graph,t);return this.root.at(s),s}createCamera(t){const s=new v(this.graph,t);return this.root.ot(s),s}createSkin(t){const s=new z(this.graph,t);return this.root.ft(s),s}createMesh(t){const s=new O(this.graph,t);return this.root.ct(s),s}createPrimitive(){return new F(this.graph)}createPrimitiveTarget(t){return new G(this.graph,t)}createMaterial(t){const s=new P(this.graph,t);return this.root.ut(s),s}createTexture(t){const s=new I(this.graph,t);return this.root.dt(s),s}createAnimation(t){const s=new p(this.graph,t);return this.root.nt(s),s}createAnimationChannel(){return new g(this.graph)}createAnimationSampler(){return new m(this.graph)}createAccessor(t,s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new f(this.graph,t).setBuffer(s);return this.root.it(e),e}createBuffer(t){const s=new w(this.graph,t);return this.root.ht(s),s}}class V{constructor(t){this.doc=t,this.provideTypes=[],this.wt=!1,this.vt=new Set,t.getRoot().pt(this)}dispose(){this.doc.getRoot().gt(this);for(const t of this.vt)t.dispose()}isRequired(){return this.wt}setRequired(t){return this.wt=t,this}addExtensionProperty(t){return this.vt.add(t),this}removeExtensionProperty(t){return this.vt.delete(t),this}provide(t,s){return this}}class W{constructor(t){this.nativeDocument=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){void 0!==s.texCoord&&t.setTexCoord(s.texCoord)}setTextureSampler(t,s){const e=this.nativeDocument.json.textures[s.index];if(void 0===e.sampler)return;const r=this.nativeDocument.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const Y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};class q{static read(r,n){const{json:h}=r,o=new J;if("2.0"!==h.asset.version)throw new Error(`Unsupported glTF version, "${h.asset.version}".`);if(h.extensionsRequired)for(const t of h.extensionsRequired)if(!n.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);o.getRoot().getAsset().generator=r.json.asset.generator;const u=new W(r),c=h.extensionsUsed||[],a=h.extensionsRequired||[];for(const t of n.extensions)c.includes(t.EXTENSION_NAME)&&o.createExtension(t).setRequired(a.includes(t.EXTENSION_NAME));u.buffers=(h.buffers||[]).map(t=>{const s=o.createBuffer(t.name);return t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),u.bufferViewBuffers=(h.bufferViews||[]).map(t=>u.buffers[t.buffer]),u.accessors=(h.accessors||[]).map(t=>{const s=o.createAccessor(t.name,u.bufferViewBuffers[t.bufferView]);let e;return s.setType(t.type),e=void 0!==t.sparse?function(t,s){const e=Y[t.componentType],r=f.getElementSize(t.type);let i;i=void 0!==t.bufferView?Z(t,s).slice():new e(t.count*r);const n=t.sparse.count,h={...t,...t.sparse.indices,count:n,type:"SCALAR"},o={...t,...t.sparse.values,count:n},u=Z(h,s),c=Z(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(t,r):Z(t,r).slice(),void 0!==t.normalized&&s.setNormalized(t.normalized),s.setArray(e),s});const l=h.images||[],d=h.textures||[];o.getRoot().listExtensionsUsed().filter(t=>t.provideTypes.includes(i.TEXTURE)).forEach(t=>t.provide(u,i.TEXTURE)),u.textures=l.map(t=>{const s=o.createTexture(t.name);if(void 0!==t.bufferView){const e=h.bufferViews[t.bufferView],i=r.json.buffers[e.buffer],n=e.byteOffset||0,o=(i.uri?r.resources[i.uri]:r.resources["xt"]).slice(n,n+e.byteLength);s.setImage(o)}else void 0!==t.uri&&(s.setImage(r.resources[t.uri]),0!==t.uri.indexOf("__")&&s.setURI(t.uri));if(void 0!==t.mimeType)s.setMimeType(t.mimeType);else if(t.uri){const e=A.extension(t.uri);s.setMimeType(T.extensionToMimeType(e))}return s}),u.materials=(h.materials||[]).map(t=>{const s=o.createMaterial(t.name);void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(u.textures[d[t.index].source]),u.setTextureInfo(s.getBaseColorTextureInfo(),t),u.setTextureSampler(s.getBaseColorTextureSampler(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getEmissiveTextureInfo(),e),u.setTextureSampler(s.getEmissiveTextureSampler(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getNormalTextureInfo(),e),u.setTextureSampler(s.getNormalTextureSampler(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(u.textures[d[e.index].source]),u.setTextureInfo(s.getOcclusionTextureInfo(),e),u.setTextureSampler(s.getOcclusionTextureSampler(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(u.textures[d[t.index].source]),u.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t),u.setTextureSampler(s.getMetallicRoughnessTextureSampler(),t)}return s}),u.meshes=(h.meshes||[]).map(t=>{const s=o.createMesh(t.name);return void 0!==t.weights&&s.setWeights(t.weights),t.primitives.forEach(e=>{const r=o.createPrimitive();void 0!==e.material&&r.setMaterial(u.materials[e.material]),void 0!==e.mode&&r.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))r.setAttribute(t,u.accessors[s]);void 0!==e.indices&&r.setIndices(u.accessors[e.indices]);const i=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=i[s]||s.toString(),n=o.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))n.setAttribute(s,u.accessors[e]);r.addTarget(n)}),s.addPrimitive(r)}),s}),u.cameras=(h.cameras||[]).map(t=>{const s=o.createCamera(t.name).setType(t.type);return"perspective"===t.type?s.setZNear(t.perspective.znear).setZFar(t.perspective.zfar).setYFov(t.perspective.yfov).setAspectRatio(t.perspective.aspectRatio):s.setZNear(t.orthographic.znear).setZFar(t.orthographic.zfar).setXMag(t.orthographic.xmag).setYMag(t.orthographic.ymag),s});const p=h.nodes||[];return u.nodes=p.map(r=>{const i=o.createNode(r.name);return void 0!==r.translation&&i.setTranslation(r.translation),void 0!==r.rotation&&i.setRotation(r.rotation),void 0!==r.scale&&i.setScale(r.scale),void 0!==r.matrix&&(i.setTranslation(t([],r.matrix)),i.setRotation(s([],r.matrix)),i.setScale(e([],r.matrix))),void 0!==r.weights&&i.setWeights(r.weights),i}),u.skins=(h.skins||[]).map(t=>{const s=o.createSkin(t.name);void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(u.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(u.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(u.nodes[e]);return s}),p.map((t,s)=>{const e=u.nodes[s];(t.children||[]).forEach(t=>e.addChild(u.nodes[t])),void 0!==t.mesh&&e.setMesh(u.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(u.cameras[t.camera]),void 0!==t.skin&&e.setSkin(u.skins[t.skin])}),u.animations=(h.animations||[]).map(t=>{const s=o.createAnimation(t.name),e=(t.samplers||[]).map(t=>{const e=o.createAnimationSampler().setInput(u.accessors[t.input]).setOutput(u.accessors[t.output]).setInterpolation(t.interpolation||"LINEAR");return s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const r=o.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(u.nodes[t.target.node]).setTargetPath(t.target.path);s.addChannel(r)}),s}),u.scenes=(h.scenes||[]).map(t=>{const s=o.createScene(t.name);return(t.nodes||[]).map(t=>u.nodes[t]).forEach(t=>s.addNode(t)),s}),o.getRoot().listExtensionsUsed().forEach(t=>t.read(u)),o}}function Z(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["xt"],n=Y[t.componentType],h=f.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["xt"],n=Y[t.componentType],h=f.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case 5126:i=a.getFloat32(r,!0);break;case 5125:i=a.getUint32(r,!0);break;case 5123:i=a.getUint16(r,!0);break;case 5121:i=a.getUint8(r);break;case 5122:i=a.getInt16(r,!0);break;case 5120:i=a.getInt8(r);break;default:throw new Error(`Unexpected componentType "${t.componentType}".`)}c[s*h+e]=i}return c}(t,s);const o=(e.byteOffset||0)+(t.byteOffset||0);switch(t.componentType){case 5126:return new Float32Array(i,o,t.count*h);case 5125:return new Uint32Array(i,o,t.count*h);case 5123:return new Uint16Array(i,o,t.count*h);case 5121:return new Uint8Array(i,o,t.count*h);case 5122:return new Int16Array(i,o,t.count*h);case 5120:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class X{constructor(t,s){this.nativeDocument=t,this.options=s,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.samplerDefIndexMap=new Map,this.imageData=[]}createTextureInfoDef(t,s,e){const r={magFilter:e.getMagFilter()||void 0,minFilter:e.getMinFilter()||void 0,wrapS:e.getWrapS(),wrapT:e.getWrapT()},i=JSON.stringify(r);this.samplerDefIndexMap.has(i)||(this.samplerDefIndexMap.set(i,this.nativeDocument.json.samplers.length),this.nativeDocument.json.samplers.push(r));const n={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(i)},h=JSON.stringify(n);return this.textureDefIndexMap.has(h)||(this.textureDefIndexMap.set(h,this.nativeDocument.json.textures.length),this.nativeDocument.json.textures.push(n)),{index:this.textureDefIndexMap.get(h),texCoord:s.getTexCoord()}}createPropertyDef(t){const s={};return t.getName()&&(s.name=t.getName()),Object.keys(t.getExtras()).length>0&&(s.extras=t.getExtras()),s}createAccessorDef(t){const s=this.createPropertyDef(t);return s.type=t.getType(),s.componentType=t.getComponentType(),s.count=t.getCount(),t.getMax(s.max=[]),t.getMin(s.min=[]),s.normalized=t.getNormalized(),s}createImageData(t,s,e){if(this.options.isGLB)this.imageData.push(s),t.bufferView=this.nativeDocument.json.bufferViews.length,this.nativeDocument.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=T.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.nativeDocument.resources[t.uri]=s}}}class H{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}class K{static write(t,s){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=r.json;i.asset.generator="glTF-Transform v0.5.1";const n=new X(r,s),h=e.listBuffers().length,o=e.listTextures().length;function u(t,s,e,r){const h=[];let o=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length;const e=y.pad(s.getArray().buffer);t.byteOffset=o,o+=e.byteLength,h.push(e),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const u={buffer:s,byteOffset:e,byteLength:y.concat(h).byteLength};return r&&(u.target=r),i.bufferViews.push(u),{buffers:h,byteLength:o}}function c(t,s,e){const r=t[0].getCount();let h=0;for(const s of t){const t=n.createAccessorDef(s);t.bufferView=i.bufferViews.length,t.byteOffset=h;const e=s.getElementSize(),r=s.getComponentSize();h+=y.padNumber(e*r),n.accessorIndexMap.set(s,i.accessors.length),i.accessors.push(t)}const o=r*h,u=new ArrayBuffer(o),c=new DataView(u);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),i=r.getComponentSize(),n=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*h+e+r*i,a=o[s*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)}}e+=y.padNumber(t*i)}}return i.bufferViews.push({buffer:s,byteOffset:e,byteLength:o,byteStride:h,target:34962}),{byteLength:o,buffers:[u]}}n.bufferURIGenerator=new H(h>1,s.basename),n.imageURIGenerator=new H(o>1,s.basename),n.logger=t.getLogger();const a=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof f){const e=a.get(t)||[];e.push(s),a.set(t,e)}}return i.accessors=[],i.bufferViews=[],i.samplers=[],i.textures=[],i.images=e.listTextures().map((t,s)=>{const e=n.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&n.createImageData(e,t.getImage(),t),n.imageIndexMap.set(t,s),e}),i.buffers=[],e.listBuffers().forEach(t=>{const e=n.createPropertyDef(t),h=new Map,o=new Set,l=new Set,d=t.listParents().filter(t=>!(t instanceof D));for(const t of d){if(!(t instanceof f))throw new Error("Unimplemented buffer reference: "+t);let s=!1,e=!1,r=!1;const i=a.get(t)||[];for(const t of i)t instanceof U?s=!0:t instanceof k?e=!0:r=!0;if(s||e||r||(r=!0),!s||e||r)if(!e||s||r){if(!r||s||e)throw new Error("Attribute or index accessors must be used only for that purpose.");l.add(t)}else o.add(t);else{const s=i[0].getParent(),e=h.get(s)||new Set;e.add(t),h.set(s,e)}}const p=[],g=i.buffers.length;let m,w=0;if(o.size){const t=u(Array.from(o),g,w,34963);w+=t.byteLength,p.push(...t.buffers)}for(const t of Array.from(h.values()))if(t.size){const s=c(Array.from(t),g,w);w+=s.byteLength,p.push(...s.buffers)}if(l.size){const t=u(Array.from(l),g,w);w+=t.byteLength,p.push(...t.buffers)}if(n.imageData.length)for(let t=0;t<n.imageData.length;t++)i.bufferViews[i.images[t].bufferView].byteOffset=w,w+=n.imageData[t].byteLength,p.push(n.imageData[t]);w?(s.isGLB?m="__glb.bin":(m=n.bufferURIGenerator.createURI(t,"bin"),e.uri=m),e.byteLength=w,r.resources[m]=y.concat(p),i.buffers.push(e)):n.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`)}),i.materials=e.listMaterials().map((t,s)=>{const e=n.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),"MASK"===t.getAlphaMode()&&(e.alphaCutoff=t.getAlphaCutoff()),e.doubleSided=t.getDoubleSided(),e.pbrMetallicRoughness={},e.pbrMetallicRoughness.baseColorFactor=t.getBaseColorFactor(),e.emissiveFactor=t.getEmissiveFactor(),e.pbrMetallicRoughness.roughnessFactor=t.getRoughnessFactor(),e.pbrMetallicRoughness.metallicFactor=t.getMetallicFactor(),t.getBaseColorTexture()){const s=t.getBaseColorTexture(),r=t.getBaseColorTextureInfo(),i=t.getBaseColorTextureSampler();e.pbrMetallicRoughness.baseColorTexture=n.createTextureInfoDef(s,r,i)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo(),i=t.getEmissiveTextureSampler();e.emissiveTexture=n.createTextureInfoDef(s,r,i)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=t.getNormalTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getNormalScale()&&(h.scale=t.getNormalScale()),e.normalTexture=h}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=t.getOcclusionTextureSampler(),h=n.createTextureInfoDef(s,r,i);1!==t.getOcclusionStrength()&&(h.strength=t.getOcclusionStrength()),e.occlusionTexture=h}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo(),i=t.getMetallicRoughnessTextureSampler();e.pbrMetallicRoughness.metallicRoughnessTexture=n.createTextureInfoDef(s,r,i)}return n.materialIndexMap.set(t,s),e}),i.meshes=e.listMeshes().map((t,s)=>{const e=n.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.material=n.materialIndexMap.get(t.getMaterial()),s.mode=t.getMode(),t.getIndices()&&(s.indices=n.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=n.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=n.accessorIndexMap.get(e.getAttribute(s));s.targets=s.targets||[],s.targets.push(t)}return t.listTargets().length&&!r&&(r=t.listTargets().map(t=>t.getName())),s}),t.getWeights().length&&(e.weights=t.getWeights()),r&&(e.extras=e.extras||{},e.extras.targetNames=r),n.meshIndexMap.set(t,s),e}),i.cameras=e.listCameras().map((t,s)=>{const e=n.createPropertyDef(t);return e.type=t.getType(),"perspective"===e.type?e.perspective={znear:t.getZNear(),zfar:t.getZFar(),yfov:t.getYFov(),aspectRatio:t.getAspectRatio()}:e.orthographic={znear:t.getZNear(),zfar:t.getZFar(),xmag:t.getXMag(),ymag:t.getYMag()},n.cameraIndexMap.set(t,s),e}),i.nodes=e.listNodes().map((t,s)=>{const e=n.createPropertyDef(t);return e.translation=t.getTranslation(),e.rotation=t.getRotation(),e.scale=t.getScale(),t.getWeights().length&&(e.weights=t.getWeights()),n.nodeIndexMap.set(t,s),e}),i.skins=e.listSkins().map((t,s)=>{const e=n.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=n.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=n.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>n.nodeIndexMap.get(t)),n.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=i.nodes[s];t.getMesh()&&(e.mesh=n.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=n.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=n.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>n.nodeIndexMap.get(t)))}),i.animations=e.listAnimations().map(t=>{const s=n.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=n.createPropertyDef(t);return r.input=n.accessorIndexMap.get(t.getInput()),r.output=n.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=n.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:n.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),i.scenes=e.listScenes().map(t=>{const s=n.createPropertyDef(t);return s.nodes=t.listNodes().map(t=>n.nodeIndexMap.get(t)),s}),i.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),i.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(n)),function(t){const s=[];for(const e in t){const r=t[e];Array.isArray(r)&&0===r.length?s.push(e):null!==r&&""!==r||s.push(r)}for(const e of s)delete t[e]}(i),r}}class Q{constructor(){this.rt=[]}registerExtensions(t){return this.rt.push(...t),this}createDocument(t){return q.read(t,{extensions:this.rt})}createNativeDocument(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return K.write(t,s)}unpackGLB(t){const s=new Uint32Array(t,0,3);if(1179937895!==s[0])throw new Error("Invalid glTF asset.");if(2!==s[1])throw new Error(`Unsupported glTF binary version, "${s[1]}".`);const e=new Uint32Array(t,12,2),r=e[0],i=new Uint32Array(t,20+r,2);if(1313821514!==e[1]||5130562!==i[1])throw new Error("Unexpected GLB layout.");const n=y.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:s,resources:e}=this.createNativeDocument(t,{basename:"",isGLB:!0}),r=JSON.stringify(s),i=y.pad(y.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=y.concat([n,i]),o=y.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=y.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return y.concat([a,h,c])}}class tt extends Q{constructor(t,s){super(),this.fs=t,this.path=s}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}write(t,s){t.match(/\.glb$/)?this.writeGLB(t,s):this.writeGLTF(t,s)}readGLB(t){const s=this.fs.readFileSync(t),e=y.trim(s);return this.unpackGLB(e)}readGLTF(t){const s=this.path.dirname(t),e={json:JSON.parse(this.fs.readFileSync(t,"utf8")),resources:{}};return[...e.json.images||[],...e.json.buffers||[]].forEach(t=>{if(t.uri&&!t.uri.match(/data:/)){const r=this.path.resolve(s,t.uri);e.resources[t.uri]=y.trim(this.fs.readFileSync(r))}else{const s=`__${R()}.${A.extension(t.uri)}`;e.resources[s]=y.createBufferFromDataURI(t.uri),t.uri=s}}),q.read(e,{extensions:this.rt})}writeGLTF(t,s){const e={basename:A.basename(t),isGLB:!1},{json:r,resources:i}=K.write(s,e),{fs:n,path:h}=this,o=h.dirname(t);n.writeFileSync(t,JSON.stringify(r,null,2)),Object.keys(i).forEach(t=>{const s=Buffer.from(i[t]);n.writeFileSync(h.join(o,t),s)})}writeGLB(t,s){const e=Buffer.from(this.packGLB(s));this.fs.writeFileSync(t,e)}}class st extends Q{constructor(t){super(),this.fetchConfig=t}read(t){return t.match(/\.glb$/)?this.readGLB(t):this.readGLTF(t)}readGLTF(t){const s={json:{},resources:{}};return fetch(t,this.fetchConfig).then(t=>t.json()).then(t=>{s.json=t;const e=[...t.images,...t.buffers].map(t=>{if(t.uri)return fetch(t.uri,this.fetchConfig).then(t=>t.arrayBuffer()).then(e=>{s.resources[t.uri]=e})});return Promise.all(e).then(()=>this.createDocument(s))})}readGLB(t){return fetch(t,this.fetchConfig).then(t=>t.arrayBuffer()).then(t=>this.unpackGLB(t))}}export{f as Accessor,p as Animation,g as AnimationChannel,m as AnimationSampler,w as Buffer,y as BufferUtils,c as COPY_IDENTITY,v as Camera,J as Document,V as Extension,x as ExtensionProperty,A as FileUtils,h as Graph,o as GraphChild,T as ImageUtils,b as Logger,P as Material,O as Mesh,j as Node,tt as NodeIO,F as Primitive,G as PrimitiveTarget,a as Property,i as PropertyType,W as ReaderContext,D as Root,$ as Scene,z as Skin,I as Texture,C as TextureInfo,B as TextureLink,_ as TextureSampler,st as WebIO,X as WriterContext,R as uuid}; | ||
//# sourceMappingURL=core.modern.js.map |
{ | ||
"name": "@gltf-transform/core", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -38,3 +38,3 @@ "description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js", | ||
}, | ||
"gitHead": "347954a19aa9d6aa876b851ea88c39ba9dd54d9e" | ||
"gitHead": "0d434833027500a98f542dc7a05f362548d6a921" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package