@gltf-transform/core
Advanced tools
Comparing version 0.10.1 to 0.11.0-alpha.0
@@ -1,2 +0,2 @@ | ||
import{determinant as t,getRotation as s,multiply as e}from"gl-matrix/mat4";import{length as r}from"gl-matrix/vec3";const i="@glb.bin";var n,h,o;function u(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}!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"}(n||(n={})),function(t){t.INTERLEAVED="interleaved",t.SEPARATE="separate"}(h||(h={})),function(t){t[t.R=4096]="R",t[t.G=256]="G",t[t.B=16]="B",t[t.A=1]="A"}(o||(o={}));class c{constructor(t,s,e){if(this.t=t,this.i=s,this.h=e,this.o=!1,this.u=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.i}getChild(){return this.h}setChild(t){return this.h=t,this}dispose(){this.o||(this.o=!0,this.u.forEach(t=>t()),this.u.length=0)}onDispose(t){return this.u.push(t),this}isDisposed(){return this.o}}class a{constructor(){this.l=new Set,this.p=new Set,this.g=new Map,this.m=new Map,this.u={}}on(t,s){return this.u[t]=this.u[t]||[],this.u[t].push(s),this}emit(t,s){for(const e of this.u[t]||[])e(s);return this}getLinks(){return Array.from(this.p)}listParentLinks(t){return Array.from(this.m.get(t)||this.l)}listParents(t){return this.listParentLinks(t).map(t=>t.getParent())}listChildLinks(t){return Array.from(this.g.get(t)||this.l)}listChildren(t){return this.listChildLinks(t).map(t=>t.getChild())}disconnectChildren(t){return(this.g.get(t)||this.l).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=Array.from(this.m.get(t)||this.l);return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}swapChild(t,s,e){const r=this.g.get(t)||this.l;return Array.from(r).filter(t=>t.getChild()===s).forEach(t=>{this.m.get(s).delete(t),t.setChild(e),this.m.has(e)||this.m.set(e,new Set),this.m.get(e).add(t)}),this}link(t,s,e){if(!e)return null;const r=new c(t,s,e);return this.registerLink(r),r}registerLink(t){this.p.add(t);const s=t.getParent();this.g.has(s)||this.g.set(s,new Set),this.g.get(s).add(t);const e=t.getChild();return this.m.has(e)||this.m.set(e,new Set),this.m.get(e).add(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.p.delete(t),this.g.get(t.getParent()).delete(t),this.m.get(t.getChild()).delete(t),this}}function l(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 f(t,s){}class d{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 p{static hexToFactor(t,s){t=Math.floor(t);const e=s;return e[0]=(t>>16&255)/255,e[1]=(t>>8&255)/255,e[2]=(255&t)/255,this.convertSRGBToLinear(s,s)}static factorToHex(t){const s=[...t],[e,r,i]=this.convertLinearToSRGB(t,s);return 255*e<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(t,s){const e=t,r=s;for(let t=0;t<3;t++)r[t]=e[t]<.04045?.0773993808*e[t]:Math.pow(.9478672986*e[t]+.0521327014,2.4);return s}static convertLinearToSRGB(t,s){const e=t,r=s;for(let t=0;t<3;t++)r[t]=e[t]<.0031308?12.92*e[t]:1.055*Math.pow(e[t],.41666)-.055;return s}}class g{static basename(t){const s=t.split(/[\\/]/).pop();return s.substr(0,s.lastIndexOf("."))}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 w{getSize(t){const s=new DataView(t);return d.decodeText(t.slice(12,16))===w.PNG_FRIED_CHUNK_NAME?[s.getUint32(32,!1),s.getUint32(36,!1)]:[s.getUint32(16,!1),s.getUint32(20,!1)]}getChannels(t){return 4}}w.PNG_FRIED_CHUNK_NAME="CgBI";class m{static registerFormat(t,s){this.impls[t]=s}static getSize(t,s){return this.impls[s]?this.impls[s].getSize(t):null}static getChannels(t,s){return this.impls[s]?this.impls[s].getChannels(t):null}static getMemSize(t,s){if(!this.impls[s])return null;if(this.impls[s].getGPUByteLength)return this.impls[s].getGPUByteLength(t);let e=0;const r=this.getSize(t,s);for(;r[0]>1||r[1]>1;)e+=r[0]*r[1]*4,r[0]=Math.max(Math.floor(r[0]/2),1),r[1]=Math.max(Math.floor(r[1]/2),1);return e+=4,e}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":`image/${t}`}}function v(t,s){if(s>t.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t.getUint8(s))throw new TypeError("Invalid JPG, marker table corrupted");return t}m.impls={"image/jpeg":new class{getSize(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),v(r,s),e=r.getUint8(s+1),192===e||193===e||194===e)return[r.getUint16(s+7,!1),r.getUint16(s+5,!1)];r=new DataView(t,r.byteOffset+s+2)}throw new TypeError("Invalid JPG, no size found")}getChannels(t){return 3}},"image/png":new w};class A{static identity(t){return t}static eq(t,s){if(t.length!==s.length)return!1;for(let e=0;e<t.length;e++)if(Math.abs(t[e]-s[e])>1e-5)return!1;return!0}static denormalize(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}static normalize(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t);default:throw new Error("Invalid component type.")}}static decompose(e,i,n,h){let o=r([e[0],e[1],e[2]]);const u=r([e[4],e[5],e[6]]),c=r([e[8],e[9],e[10]]);t(e)<0&&(o=-o),i[0]=e[12],i[1]=e[13],i[2]=e[14];const a=e.slice(),l=1/o,f=1/u,d=1/c;a[0]*=l,a[1]*=l,a[2]*=l,a[4]*=f,a[5]*=f,a[6]*=f,a[8]*=d,a[9]*=d,a[10]*=d,s(n,a),h[0]=o,h[1]=u,h[2]=c}static compose(t,s,e,r){const i=r,n=s[0],h=s[1],o=s[2],u=s[3],c=n+n,a=h+h,l=o+o,f=n*c,d=n*a,p=n*l,g=h*a,w=h*l,m=o*l,v=u*c,A=u*a,T=u*l,y=e[0],x=e[1],E=e[2];return i[0]=(1-(g+m))*y,i[1]=(d+T)*y,i[2]=(p-A)*y,i[3]=0,i[4]=(d-T)*x,i[5]=(1-(f+m))*x,i[6]=(w+v)*x,i[7]=0,i[8]=(p+A)*E,i[9]=(w-v)*E,i[10]=(1-(f+g))*E,i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i}}class T{constructor(t){this.verbosity=t}debug(t){this.verbosity<=T.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=T.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=T.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=T.Verbosity.ERROR&&console.error(t)}}T.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0},T.DEFAULT_INSTANCE=new T(T.Verbosity.INFO);const y="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",x=new Set,E=function(){let t="";for(let s=0;s<6;s++)t+=y.charAt(Math.floor(Math.random()*y.length));return t},M=function(){for(let t=0;t<999;t++){const t=E();if(!x.has(t))return x.add(t),t}return""},S=t=>t;class b extends class{constructor(t){this.graph=t,this.o=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.o}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.o=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.swapChild(this,t,s),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0;for(const s of e)t.push(s)}),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.graph=t,this.v={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.v}setExtras(t){return this.v=t,this}clone(){const t=new(0,this.constructor)(this.graph).copy(this,S);return this.graph.emit("clone",t),t}copy(t,s=S){return this.t=t.t,this.v=JSON.parse(JSON.stringify(t.v)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}const R="Pass extension name (string) as lookup token, not a constructor.";class I extends b{constructor(){super(...arguments),this.extensions=[]}copy(t,s=S){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.extensionName,s(e))}),this}getExtension(t){if("string"!=typeof t)throw new Error(R);const s=this.extensions.find(s=>s.getChild().extensionName===t);return s?s.getChild():null}setExtension(t,s){if("string"!=typeof t)throw new Error(R);const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.T(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}u([f],I.prototype,"extensions",void 0);class N extends I{constructor(){super(...arguments),this.propertyType=n.ACCESSOR,this.M=null,this.S=N.Type.SCALAR,this.I=N.ComponentType.FLOAT,this.N=!1,this.C=A.identity,this._=A.identity,this.buffer=null}copy(t,s=S){return super.copy(t,s),this.S=t.S,this.I=t.I,this.N=t.N,this.C=t.C,this._=t._,t.M&&(this.M=t.M.slice()),t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case N.Type.SCALAR:return 1;case N.Type.VEC2:return 2;case N.Type.VEC3:return 3;case N.Type.VEC4:case N.Type.MAT2:return 4;case N.Type.MAT3:return 9;case N.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case N.ComponentType.BYTE:case N.ComponentType.UNSIGNED_BYTE:return 1;case N.ComponentType.SHORT:case N.ComponentType.UNSIGNED_SHORT:return 2;case N.ComponentType.UNSIGNED_INT:case N.ComponentType.FLOAT: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._(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.M[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._(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.M[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.M?this.M.length/this.getElementSize():0}getType(){return this.S}setType(t){return this.S=t,this}getElementSize(){return N.getElementSize(this.S)}getComponentSize(){return this.M.BYTES_PER_ELEMENT}getComponentType(){return this.I}getNormalized(){return this.N}setNormalized(t){return this.N=t,t?(this._=t=>A.denormalize(t,this.I),this.C=t=>A.normalize(t,this.I)):(this._=A.identity,this.C=A.identity),this}getScalar(t){const s=this.getElementSize();return this._(this.M[t*s])}setScalar(t,s){return this.M[t*this.getElementSize()]=this.C(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this._(this.M[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.M[t*e+r]=this.C(s[r]);return this}getBuffer(){return this.buffer?this.buffer.getChild():null}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.M}setArray(t){return this.I=t?function(t){switch(t.constructor){case Float32Array:return N.ComponentType.FLOAT;case Uint32Array:return N.ComponentType.UNSIGNED_INT;case Uint16Array:return N.ComponentType.UNSIGNED_SHORT;case Uint8Array:return N.ComponentType.UNSIGNED_BYTE;case Int16Array:return N.ComponentType.SHORT;case Int8Array:return N.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}(t):N.ComponentType.FLOAT,this.M=t,this}getByteLength(){return this.M?this.M.byteLength:0}}N.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"},N.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},u([l],N.prototype,"buffer",void 0);class C extends I{constructor(){super(...arguments),this.propertyType=n.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=S){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())}}u([f],C.prototype,"channels",void 0),u([f],C.prototype,"samplers",void 0);class _ extends b{constructor(){super(...arguments),this.propertyType=n.ANIMATION_CHANNEL,this.L=null,this.targetNode=null,this.sampler=null}copy(t,s=S){return super.copy(t,s),this.L=t.L,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.L}setTargetPath(t){return this.L=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}}_.TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"},u([l],_.prototype,"targetNode",void 0),u([l],_.prototype,"sampler",void 0);class L extends b{constructor(){super(...arguments),this.propertyType=n.ANIMATION_SAMPLER,this.O=L.Interpolation.LINEAR,this.input=null,this.output=null}copy(t,s=S){return super.copy(t,s),this.O=t.O,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.O}setInterpolation(t){return this.O=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}}L.Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"},u([l],L.prototype,"input",void 0),u([l],L.prototype,"output",void 0);class B extends I{constructor(){super(...arguments),this.propertyType=n.BUFFER,this.U=""}copy(t,s=S){return super.copy(t,s),this.U=t.U,this}getURI(){return this.U}setURI(t){return this.U=t,this}}class O extends I{constructor(){super(...arguments),this.propertyType=n.CAMERA,this.S=O.Type.PERSPECTIVE,this.P=.1,this.F=100,this.k=null,this.j=2*Math.PI*50/360,this.D=1,this.J=1}copy(t,s=S){return super.copy(t,s),this.S=t.S,this.P=t.P,this.F=t.F,this.k=t.k,this.j=t.j,this.D=t.D,this.J=t.J,this}getType(){return this.S}setType(t){return this.S=t,this}getZNear(){return this.P}setZNear(t){return this.P=t,this}getZFar(){return this.F}setZFar(t){return this.F=t,this}getAspectRatio(){return this.k}setAspectRatio(t){return this.k=t,this}getYFov(){return this.j}setYFov(t){return this.j=t,this}getXMag(){return this.D}setXMag(t){return this.D=t,this}getYMag(){return this.J}setYMag(t){return this.J=t,this}}O.Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};class U extends b{constructor(t,s){super(t),this.$=s,this.$.addExtensionProperty(this)}dispose(){this.$.removeExtensionProperty(this),super.dispose()}T(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class P extends c{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class F extends c{copy(t){return this}}class k extends c{constructor(){super(...arguments),this.channels=0}copy(t){return this.channels=t.channels,this}}class G extends a{linkAttribute(t,s,e){if(!e)return null;const r=new P(t,s,e);return r.semantic=t,this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new F(t,s,e);return this.registerLink(r),r}linkTexture(t,s,e,r){if(!r)return null;const i=new k(t,e,r);return i.channels=s,this.registerLink(i),i}}class j extends I{constructor(){super(...arguments),this.propertyType=n.TEXTURE_INFO,this.V=0,this.W=null,this.Y=null,this.H=j.WrapMode.REPEAT,this.q=j.WrapMode.REPEAT}copy(t,s=S){return super.copy(t,s),this.V=t.V,this.W=t.W,this.Y=t.Y,this.H=t.H,this.q=t.q,this}getTexCoord(){return this.V}setTexCoord(t){return this.V=t,this}getMagFilter(){return this.W}setMagFilter(t){return this.W=t,this}getMinFilter(){return this.Y}setMinFilter(t){return this.Y=t,this}getWrapS(){return this.H}setWrapS(t){return this.H=t,this}getWrapT(){return this.q}setWrapT(t){return this.q=t,this}}j.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},j.MagFilter={NEAREST:9728,LINEAR:9729},j.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};const{R:D,G:J,B:z,A:$}=o;class V extends I{constructor(){super(...arguments),this.propertyType=n.MATERIAL,this.Z=V.AlphaMode.OPAQUE,this.K=.5,this.X=!1,this.tt=[1,1,1,1],this.st=[0,0,0],this.et=1,this.rt=1,this.it=1,this.nt=1,this.baseColorTexture=null,this.baseColorTextureInfo=this.graph.link("baseColorTextureInfo",this,new j(this.graph)),this.emissiveTexture=null,this.emissiveTextureInfo=this.graph.link("emissiveTextureInfo",this,new j(this.graph)),this.normalTexture=null,this.normalTextureInfo=this.graph.link("normalTextureInfo",this,new j(this.graph)),this.occlusionTexture=null,this.occlusionTextureInfo=this.graph.link("occlusionTextureInfo",this,new j(this.graph)),this.metallicRoughnessTexture=null,this.metallicRoughnessTextureInfo=this.graph.link("metallicRoughnessTextureInfo",this,new j(this.graph))}copy(t,s=S){return super.copy(t,s),this.Z=t.Z,this.K=t.K,this.X=t.X,this.tt=[...t.tt],this.st=[...t.st],this.et=t.et,this.rt=t.rt,this.it=t.it,this.nt=t.nt,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()),s)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()),s)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()),s)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()),s)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()),s)),this}dispose(){this.baseColorTextureInfo.getChild().dispose(),this.emissiveTextureInfo.getChild().dispose(),this.normalTextureInfo.getChild().dispose(),this.occlusionTextureInfo.getChild().dispose(),this.metallicRoughnessTextureInfo.getChild().dispose(),super.dispose()}getDoubleSided(){return this.X}setDoubleSided(t){return this.X=t,this}getAlpha(){return this.tt[3]}setAlpha(t){return this.tt[3]=t,this}getAlphaMode(){return this.Z}setAlphaMode(t){return this.Z=t,this}getAlphaCutoff(){return this.K}setAlphaCutoff(t){return this.K=t,this}getBaseColorFactor(){return this.tt}setBaseColorFactor(t){return this.tt=t,this}getBaseColorHex(){return p.factorToHex(this.tt)}setBaseColorHex(t){return p.hexToFactor(t,this.tt),this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTextureInfo.getChild():null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",D|J|z|$,this,t),this}getEmissiveFactor(){return this.st}setEmissiveFactor(t){return this.st=t,this}getEmissiveHex(){return p.factorToHex(this.st)}setEmissiveHex(t){return p.hexToFactor(t,this.st),this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTextureInfo.getChild():null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",D|J|z,this,t),this}getNormalScale(){return this.et}setNormalScale(t){return this.et=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTextureInfo.getChild():null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",D|J|z,this,t),this}getOcclusionStrength(){return this.rt}setOcclusionStrength(t){return this.rt=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTextureInfo.getChild():null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",D,this,t),this}getRoughnessFactor(){return this.it}setRoughnessFactor(t){return this.it=t,this}getMetallicFactor(){return this.nt}setMetallicFactor(t){return this.nt=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTextureInfo.getChild():null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",J|z,this,t),this}}V.AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"},u([l],V.prototype,"baseColorTexture",void 0),u([l],V.prototype,"baseColorTextureInfo",void 0),u([l],V.prototype,"emissiveTexture",void 0),u([l],V.prototype,"emissiveTextureInfo",void 0),u([l],V.prototype,"normalTexture",void 0),u([l],V.prototype,"normalTextureInfo",void 0),u([l],V.prototype,"occlusionTexture",void 0),u([l],V.prototype,"occlusionTextureInfo",void 0),u([l],V.prototype,"metallicRoughnessTexture",void 0),u([l],V.prototype,"metallicRoughnessTextureInfo",void 0);class W extends I{constructor(){super(...arguments),this.propertyType=n.MESH,this.ht=[],this.primitives=[]}copy(t,s=S){return super.copy(t,s),this.ht=[...t.ht],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.ht}setWeights(t){return this.ht=t,this}}u([f],W.prototype,"primitives",void 0);class Y extends I{constructor(){super(...arguments),this.propertyType=n.NODE,this.ot=[0,0,0],this.ut=[0,0,0,1],this.ct=[1,1,1],this.ht=[],this.i=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=S){return super.copy(t,s),this.ot=[...t.ot],this.ut=[...t.ut],this.ct=[...t.ct],this.ht=[...t.ht],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),s!==S&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}getTranslation(){return this.ot}getRotation(){return this.ut}getScale(){return this.ct}setTranslation(t){return this.ot=t,this}setRotation(t){return this.ut=t,this}setScale(t){return this.ct=t,this}getMatrix(){return A.compose(this.ot,this.ut,this.ct,[])}getWorldTranslation(){const t=[0,0,0];return A.decompose(this.getWorldMatrix(),t,[0,0,0,1],[1,1,1]),t}getWorldRotation(){const t=[0,0,0,1];return A.decompose(this.getWorldMatrix(),[0,0,0],t,[1,1,1]),t}getWorldScale(){const t=[1,1,1];return A.decompose(this.getWorldMatrix(),[0,0,0],[0,0,0,1],t),t}getWorldMatrix(){const t=[];for(let s=this;s instanceof Y;s=s.i)t.push(s);let s;const r=t.pop().getMatrix();for(;s=t.pop();)e(r,r,s.getMatrix());return r}addChild(t){t.i&&t.i.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.i=this,s.onDispose(()=>t.i=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getParent(){return this.i}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.ht}setWeights(t){return this.ht=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}u([l],Y.prototype,"camera",void 0),u([l],Y.prototype,"mesh",void 0),u([l],Y.prototype,"skin",void 0),u([f],Y.prototype,"children",void 0);class H extends I{constructor(){super(...arguments),this.propertyType=n.PRIMITIVE,this.at=H.Mode.TRIANGLES,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=S){return super.copy(t,s),this.at=t.at,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,this,s);return 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.at}setMode(t){return this.at=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)}}H.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},u([l],H.prototype,"material",void 0),u([l],H.prototype,"indices",void 0),u([f],H.prototype,"attributes",void 0),u([f],H.prototype,"targets",void 0);class q extends b{constructor(){super(...arguments),this.propertyType=n.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=S){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)}}u([f],q.prototype,"attributes",void 0);class Z extends I{constructor(){super(...arguments),this.propertyType=n.SCENE,this.children=[]}copy(t,s=S){return super.copy(t,s),s!==S&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}addChild(t){t.i&&t.i.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.i=this,s.onDispose(()=>t.i=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}traverse(t){for(const s of this.listChildren())s.traverse(t);return this}}u([f],Z.prototype,"children",void 0);class K extends I{constructor(){super(...arguments),this.propertyType=n.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=S){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())}}u([l],K.prototype,"skeleton",void 0),u([l],K.prototype,"inverseBindMatrices",void 0),u([f],K.prototype,"joints",void 0);class Q extends I{constructor(){super(...arguments),this.propertyType=n.TEXTURE,this.lt=null,this.ft="",this.U=""}copy(t,s=S){return super.copy(t,s),this.ft=t.ft,this.U=t.U,t.lt&&(this.lt=t.lt.slice(0)),this}getMimeType(){return this.ft||m.extensionToMimeType(g.extension(this.U))}setMimeType(t){return this.ft=t,this}getURI(){return this.U}setURI(t){return this.U=t,this.ft=m.extensionToMimeType(g.extension(t)),this}getImage(){return this.lt}setImage(t){return this.lt=t,this}getSize(){return this.lt?m.getSize(this.lt,this.getMimeType()):null}}class X extends b{constructor(t){super(t),this.propertyType=n.ROOT,this.dt={generator:"glTF-Transform v0.10.1",version:"2.0"},this.gt=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[],t.on("clone",t=>this.wt(t))}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=S){if(super.copy(t,s),s===S)throw new Error("Root cannot be copied.");return Object.assign(this.dt,t.dt),t.accessors.forEach(t=>this.vt(s(t.getChild()))),t.animations.forEach(t=>this.At(s(t.getChild()))),t.buffers.forEach(t=>this.Tt(s(t.getChild()))),t.cameras.forEach(t=>this.yt(s(t.getChild()))),t.materials.forEach(t=>this.xt(s(t.getChild()))),t.meshes.forEach(t=>this.Et(s(t.getChild()))),t.nodes.forEach(t=>this.Mt(s(t.getChild()))),t.scenes.forEach(t=>this.St(s(t.getChild()))),t.skins.forEach(t=>this.bt(s(t.getChild()))),t.textures.forEach(t=>this.Rt(s(t.getChild()))),this}wt(t){return t instanceof Z?this.St(t):t instanceof Y?this.Mt(t):t instanceof O?this.yt(t):t instanceof K?this.bt(t):t instanceof W?this.Et(t):t instanceof V?this.xt(t):t instanceof Q?this.Rt(t):t instanceof C?this.At(t):t instanceof N?this.vt(t):t instanceof B&&this.Tt(t),this}getAsset(){return this.dt}listExtensionsUsed(){return Array.from(this.gt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}It(t){return this.gt.add(t),this}Nt(t){return this.gt.delete(t),this}St(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}Mt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}yt(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}bt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}Et(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}xt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}Rt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}At(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}vt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}Tt(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}u([f],X.prototype,"accessors",void 0),u([f],X.prototype,"animations",void 0),u([f],X.prototype,"buffers",void 0),u([f],X.prototype,"cameras",void 0),u([f],X.prototype,"materials",void 0),u([f],X.prototype,"meshes",void 0),u([f],X.prototype,"nodes",void 0),u([f],X.prototype,"scenes",void 0),u([f],X.prototype,"skins",void 0),u([f],X.prototype,"textures",void 0);class tt{constructor(){this.Ct=new G,this._t=new X(this.Ct),this.Lt=T.DEFAULT_INSTANCE}getRoot(){return this._t}getGraph(){return this.Ct}getLogger(){return this.Lt}setLogger(t){return this.Lt=t,this}clone(){return(new tt).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._t),r.set(t._t,this._t);for(const i of t.Ct.getLinks())for(const t of[i.getParent(),i.getChild()]){if(e.has(t))continue;let i;if(t.propertyType===n.TEXTURE_INFO)i=t;else{const e=t.constructor;i=t instanceof U?new e(this.Ct,s[t.extensionName]):new e(this.Ct)}r.set(t,i),e.add(t)}const i=t=>{const s=r.get(t);if(!s)throw new Error("Could resolve property.");return s};for(const t of e){const s=r.get(t);if(!s)throw new Error("Could resolve property.");s.copy(t,i)}return this}async transform(...t){for(const s of t)await s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t=""){const s=new Z(this.Ct,t);return this._t.St(s),s}createNode(t=""){const s=new Y(this.Ct,t);return this._t.Mt(s),s}createCamera(t=""){const s=new O(this.Ct,t);return this._t.yt(s),s}createSkin(t=""){const s=new K(this.Ct,t);return this._t.bt(s),s}createMesh(t=""){const s=new W(this.Ct,t);return this._t.Et(s),s}createPrimitive(){return new H(this.Ct)}createPrimitiveTarget(t=""){return new q(this.Ct,t)}createMaterial(t=""){const s=new V(this.Ct,t);return this._t.xt(s),s}createTexture(t=""){const s=new Q(this.Ct,t);return this._t.Rt(s),s}createAnimation(t=""){const s=new C(this.Ct,t);return this._t.At(s),s}createAnimationChannel(t=""){return new _(this.Ct,t)}createAnimationSampler(t=""){return new L(this.Ct,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new N(this.Ct,t).setBuffer(s);return this._t.vt(e),e}createBuffer(t=""){const s=new B(this.Ct,t);return this._t.Tt(s),s}}class st{constructor(t){this.doc=t,this.prereadTypes=[],this.prewriteTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().It(this)}dispose(){this.doc.getRoot().Nt(this);for(const t of this.properties)t.dispose()}static register(){}isRequired(){return this.required}setRequired(t){return this.required=t,this}addExtensionProperty(t){return this.properties.add(t),this}removeExtensionProperty(t){return this.properties.delete(t),this}install(t,s){return this}preread(t,s){return this}prewrite(t,s){return this}}function et(){return(et=Object.assign||function(t){for(var s=1;s<arguments.length;s++){var e=arguments[s];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}class rt{constructor(t){this.jsonDoc=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){this.textureInfos.set(t,s),void 0!==s.texCoord&&t.setTexCoord(s.texCoord);const e=this.jsonDoc.json.textures[s.index];if(void 0===e.sampler)return;const r=this.jsonDoc.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const it={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},nt={logger:T.DEFAULT_INSTANCE,extensions:[],dependencies:{}};class ht{static read(t,s=nt){const{json:e}=t,r=new tt;this.validate(t,s);const i=new rt(t),h=t.json.asset,o=r.getRoot().getAsset();h.copyright&&(o.copyright=h.copyright),h.extras&&(o.extras=h.extras),h.generator&&(o.generator=h.generator),h.minVersion&&(o.minVersion=h.minVersion);const u=e.extensionsUsed||[],c=e.extensionsRequired||[];for(const t of s.extensions)if(u.includes(t.EXTENSION_NAME)){const e=r.createExtension(t).setRequired(c.includes(t.EXTENSION_NAME));for(const t of e.dependencies)e.install(t,s.dependencies[t])}i.buffers=(e.buffers||[]).map(t=>{const s=r.createBuffer(t.name);return t.extras&&s.setExtras(t.extras),t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),i.bufferViewBuffers=(e.bufferViews||[]).map(t=>i.buffers[t.buffer]),i.accessors=(e.accessors||[]).map(s=>{const e=r.createAccessor(s.name,i.bufferViewBuffers[s.bufferView]).setType(s.type);if(s.extras&&e.setExtras(s.extras),void 0!==s.normalized&&e.setNormalized(s.normalized),void 0===s.bufferView&&!s.sparse)return e;let n;return n=void 0!==s.sparse?function(t,s){const e=it[t.componentType],r=N.getElementSize(t.type);let i;i=void 0!==t.bufferView?ot(t,s).slice():new e(t.count*r);const n=t.sparse.count,h=et({},t,t.sparse.indices,{count:n,type:"SCALAR"}),o=et({},t,t.sparse.values,{count:n}),u=ot(h,s),c=ot(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(s,t):ot(s,t).slice(),e.setArray(n),e});const a=e.images||[],l=e.textures||[];r.getRoot().listExtensionsUsed().filter(t=>t.prereadTypes.includes(n.TEXTURE)).forEach(t=>t.preread(i,n.TEXTURE)),i.textures=a.map(s=>{const i=r.createTexture(s.name);if(s.extras&&i.setExtras(s.extras),void 0!==s.bufferView){const r=e.bufferViews[s.bufferView],n=t.json.buffers[r.buffer],h=r.byteOffset||0,o=(n.uri?t.resources[n.uri]:t.resources["@glb.bin"]).slice(h,h+r.byteLength);i.setImage(o)}else void 0!==s.uri&&(i.setImage(t.resources[s.uri]),0!==s.uri.indexOf("__")&&i.setURI(s.uri));if(void 0!==s.mimeType)i.setMimeType(s.mimeType);else if(s.uri){const t=g.extension(s.uri);i.setMimeType(m.extensionToMimeType(t))}return i}),i.materials=(e.materials||[]).map(t=>{const s=r.createMaterial(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(i.textures[l[t.index].source]),i.setTextureInfo(s.getBaseColorTextureInfo(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getEmissiveTextureInfo(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getNormalTextureInfo(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getOcclusionTextureInfo(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(i.textures[l[t.index].source]),i.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t)}return s});const f=e.meshes||[];r.getRoot().listExtensionsUsed().filter(t=>t.prereadTypes.includes(n.PRIMITIVE)).forEach(t=>t.preread(i,n.PRIMITIVE)),i.meshes=f.map(t=>{const s=r.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),(t.primitives||[]).forEach(e=>{const n=r.createPrimitive();e.extras&&n.setExtras(e.extras),void 0!==e.material&&n.setMaterial(i.materials[e.material]),void 0!==e.mode&&n.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))n.setAttribute(t,i.accessors[s]);void 0!==e.indices&&n.setIndices(i.accessors[e.indices]);const h=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=h[s]||s.toString(),o=r.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))o.setAttribute(s,i.accessors[e]);n.addTarget(o)}),s.addPrimitive(n)}),s}),i.cameras=(e.cameras||[]).map(t=>{const s=r.createCamera(t.name).setType(t.type);return t.extras&&s.setExtras(t.extras),t.type===O.Type.PERSPECTIVE?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 d=e.nodes||[];return i.nodes=d.map(t=>{const s=r.createNode(t.name);if(t.extras&&s.setExtras(t.extras),void 0!==t.translation&&s.setTranslation(t.translation),void 0!==t.rotation&&s.setRotation(t.rotation),void 0!==t.scale&&s.setScale(t.scale),void 0!==t.matrix){const e=[0,0,0],r=[0,0,0,1],i=[1,1,1];A.decompose(t.matrix,e,r,i),s.setTranslation(e),s.setRotation(r),s.setScale(i)}return void 0!==t.weights&&s.setWeights(t.weights),s}),i.skins=(e.skins||[]).map(t=>{const s=r.createSkin(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(i.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(i.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(i.nodes[e]);return s}),d.map((t,s)=>{const e=i.nodes[s];(t.children||[]).forEach(t=>e.addChild(i.nodes[t])),void 0!==t.mesh&&e.setMesh(i.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(i.cameras[t.camera]),void 0!==t.skin&&e.setSkin(i.skins[t.skin])}),i.animations=(e.animations||[]).map(t=>{const s=r.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=r.createAnimationSampler().setInput(i.accessors[t.input]).setOutput(i.accessors[t.output]).setInterpolation(t.interpolation||L.Interpolation.LINEAR);return t.extras&&e.setExtras(t.extras),s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const n=r.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(i.nodes[t.target.node]).setTargetPath(t.target.path);t.extras&&n.setExtras(t.extras),s.addChannel(n)}),s}),i.scenes=(e.scenes||[]).map(t=>{const s=r.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>i.nodes[t]).forEach(t=>s.addChild(t)),s}),r.getRoot().listExtensionsUsed().forEach(t=>t.read(i)),r}static validate(t,s){const e=t.json;if("2.0"!==e.asset.version)throw new Error(`Unsupported glTF version, "${e.asset.version}".`);if(e.extensionsRequired)for(const t of e.extensionsRequired)if(!s.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);if(e.extensionsUsed)for(const t of e.extensionsUsed)s.extensions.find(s=>s.EXTENSION_NAME===t)||s.logger.warn(`Missing optional extension, "${t}".`)}}function ot(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=it[t.componentType],h=N.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=it[t.componentType],h=N.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case N.ComponentType.FLOAT:i=a.getFloat32(r,!0);break;case N.ComponentType.UNSIGNED_INT:i=a.getUint32(r,!0);break;case N.ComponentType.UNSIGNED_SHORT:i=a.getUint16(r,!0);break;case N.ComponentType.UNSIGNED_BYTE:i=a.getUint8(r);break;case N.ComponentType.SHORT:i=a.getInt16(r,!0);break;case N.ComponentType.BYTE: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 N.ComponentType.FLOAT:return new Float32Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_INT:return new Uint32Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_SHORT:return new Uint16Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_BYTE:return new Uint8Array(i,o,t.count*h);case N.ComponentType.SHORT:return new Int16Array(i,o,t.count*h);case N.ComponentType.BYTE:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class ut{constructor(t,s){this.jsonDoc=t,this.options=s,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.textureInfoDefMap=new Map,this.samplerDefIndexMap=new Map,this.imageBufferViews=[],this.otherBufferViews=new Map,this.otherBufferViewsIndexMap=new Map,this.extensionData={},this.Bt=new Map,this.accessorUsageGroupedByParent=new Set(["ARRAY_BUFFER"])}createTextureInfoDef(t,s){const e={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},r=JSON.stringify(e);this.samplerDefIndexMap.has(r)||(this.samplerDefIndexMap.set(r,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(e));const i={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(r)},n=JSON.stringify(i);this.textureDefIndexMap.has(n)||(this.textureDefIndexMap.set(n,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(i));const h={index:this.textureDefIndexMap.get(n),texCoord:s.getTexCoord()};return this.textureInfoDefMap.set(s,h),h}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.imageBufferViews.push(s),t.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=m.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.jsonDoc.resources[t.uri]=s}}getAccessorUsage(t){return this.Bt.get(t)}setAccessorUsage(t,s){const e=this.Bt.get(t);if(e&&e!==s)throw new Error(`Accessor with usage "${e}" cannot be reused as "${s}".`);return this.Bt.set(t,s),this}listAccessorsByUsage(){const t={};for(const[s,e]of Array.from(this.Bt.entries()))t[e]=t[e]||[],t[e].push(s);return t}}class ct{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}const at={logger:T.DEFAULT_INSTANCE,basename:"",isGLB:!0,vertexLayout:h.INTERLEAVED,dependencies:{}};class lt{static write(t,s=at){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=s.logger||T.DEFAULT_INSTANCE,o=r.json;o.asset.generator="glTF-Transform v0.10.1";const u=new ut(r,s),c=e.listBuffers().length,a=e.listTextures().length;u.bufferURIGenerator=new ct(c>1,s.basename),u.imageURIGenerator=new ct(a>1,s.basename),u.logger=t.getLogger();for(const e of t.getRoot().listExtensionsUsed())for(const t of e.dependencies)e.install(t,s.dependencies[t]);function l(t,s,e,r){const i=[];let n=0;for(const s of t){const t=u.createAccessorDef(s);t.bufferView=o.bufferViews.length;const e=d.pad(s.getArray().buffer);t.byteOffset=n,n+=e.byteLength,i.push(e),u.accessorIndexMap.set(s,o.accessors.length),o.accessors.push(t)}const h={buffer:s,byteOffset:e,byteLength:d.concat(i).byteLength};return r&&(h.target=r),o.bufferViews.push(h),{buffers:i,byteLength:n}}function f(t,s,e){const r=t[0].getCount();let i=0;for(const s of t){const t=u.createAccessorDef(s);t.bufferView=o.bufferViews.length,t.byteOffset=i;const e=s.getElementSize(),r=s.getComponentSize();i+=d.padNumber(e*r),u.accessorIndexMap.set(s,o.accessors.length),o.accessors.push(t)}const n=r*i,h=new ArrayBuffer(n),c=new DataView(h);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),n=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*i+e+r*n,a=o[s*t+r];switch(h){case N.ComponentType.FLOAT:c.setFloat32(u,a,!0);break;case N.ComponentType.BYTE:c.setInt8(u,a);break;case N.ComponentType.SHORT:c.setInt16(u,a,!0);break;case N.ComponentType.UNSIGNED_BYTE:c.setUint8(u,a);break;case N.ComponentType.UNSIGNED_SHORT:c.setUint16(u,a,!0);break;case N.ComponentType.UNSIGNED_INT:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}e+=d.padNumber(t*n)}}return o.bufferViews.push({buffer:s,byteOffset:e,byteLength:n,byteStride:i,target:34962}),{byteLength:n,buffers:[h]}}const p=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof N){const e=p.get(t)||[];e.push(s),p.set(t,e)}}return o.accessors=[],o.bufferViews=[],o.samplers=[],o.textures=[],o.images=e.listTextures().map((t,s)=>{const e=u.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&u.createImageData(e,t.getImage(),t),u.imageIndexMap.set(t,s),e}),t.getRoot().listExtensionsUsed().filter(t=>t.prewriteTypes.includes(n.ACCESSOR)).forEach(t=>t.prewrite(u,n.ACCESSOR)),o.buffers=[],e.listBuffers().forEach(t=>{const e=u.createPropertyDef(t),i=u.accessorUsageGroupedByParent,n=new Map,c=t.listParents().filter(t=>t instanceof N),a=new Set(c);for(const t of c){if(u.accessorIndexMap.has(t))continue;const s=p.get(t)||[];for(const e of s){if(u.getAccessorUsage(t))break;e instanceof P?u.setAccessorUsage(t,"ARRAY_BUFFER"):e instanceof F?u.setAccessorUsage(t,"ELEMENT_ARRAY_BUFFER"):"inverseBindMatrices"===e.getName()&&u.setAccessorUsage(t,"INVERSE_BIND_MATRICES")}if(u.getAccessorUsage(t)||u.setAccessorUsage(t,"OTHER"),i.has(u.getAccessorUsage(t))){const e=s[0].getParent(),r=n.get(e)||new Set;r.add(t),n.set(e,r)}}const g=[],w=o.buffers.length;let m=0;const v=u.listAccessorsByUsage();for(const t in v)if(i.has(t))for(const e of Array.from(n.values())){const r=Array.from(e).filter(t=>a.has(t)).filter(s=>u.getAccessorUsage(s)===t);if(r.length)if("ARRAY_BUFFER"!==t||s.vertexLayout===h.INTERLEAVED){const s="ARRAY_BUFFER"===t?f(r,w,m):l(r,w,m);m+=s.byteLength,g.push(...s.buffers)}else for(const t of r){const s=f([t],w,m);m+=s.byteLength,g.push(...s.buffers)}}else{const s=v[t].filter(t=>a.has(t));if(!s.length)continue;const e=l(s,w,m,"ELEMENT_ARRAY_BUFFER"===t?34963:null);m+=e.byteLength,g.push(...e.buffers)}if(u.imageBufferViews.length)for(let t=0;t<u.imageBufferViews.length;t++)if(o.bufferViews[o.images[t].bufferView].byteOffset=m,m+=u.imageBufferViews[t].byteLength,g.push(u.imageBufferViews[t]),m%4){const t=4-m%4;m+=t,g.push(new ArrayBuffer(t))}if(u.otherBufferViews.has(t))for(const s of u.otherBufferViews.get(t))o.bufferViews.push({buffer:w,byteOffset:m,byteLength:s.byteLength}),u.otherBufferViewsIndexMap.set(s,o.bufferViews.length-1),m+=s.byteLength,g.push(s);if(!m)return void u.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`);let A;s.isGLB?A="@glb.bin":(A=u.bufferURIGenerator.createURI(t,"bin"),e.uri=A),e.byteLength=m,r.resources[A]=d.concat(g),o.buffers.push(e)}),e.listAccessors().find(t=>!t.getBuffer())&&i.warn("Skipped writing one or more Accessors: no Buffer assigned."),o.materials=e.listMaterials().map((t,s)=>{const e=u.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),t.getAlphaMode()===V.AlphaMode.MASK&&(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();e.pbrMetallicRoughness.baseColorTexture=u.createTextureInfoDef(s,r)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo();e.emissiveTexture=u.createTextureInfoDef(s,r)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=u.createTextureInfoDef(s,r);1!==t.getNormalScale()&&(i.scale=t.getNormalScale()),e.normalTexture=i}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=u.createTextureInfoDef(s,r);1!==t.getOcclusionStrength()&&(i.strength=t.getOcclusionStrength()),e.occlusionTexture=i}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo();e.pbrMetallicRoughness.metallicRoughnessTexture=u.createTextureInfoDef(s,r)}return u.materialIndexMap.set(t,s),e}),o.meshes=e.listMeshes().map((t,s)=>{const e=u.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.mode=t.getMode(),t.getMaterial()&&(s.material=u.materialIndexMap.get(t.getMaterial())),Object.keys(t.getExtras()).length&&(s.extras=t.getExtras()),t.getIndices()&&(s.indices=u.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=u.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=u.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),u.meshIndexMap.set(t,s),e}),o.cameras=e.listCameras().map((t,s)=>{const e=u.createPropertyDef(t);return e.type=t.getType(),e.type===O.Type.PERSPECTIVE?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()},u.cameraIndexMap.set(t,s),e}),o.nodes=e.listNodes().map((t,s)=>{const e=u.createPropertyDef(t);return A.eq(t.getTranslation(),[0,0,0])||(e.translation=t.getTranslation()),A.eq(t.getRotation(),[0,0,0,1])||(e.rotation=t.getRotation()),A.eq(t.getScale(),[1,1,1])||(e.scale=t.getScale()),t.getWeights().length&&(e.weights=t.getWeights()),u.nodeIndexMap.set(t,s),e}),o.skins=e.listSkins().map((t,s)=>{const e=u.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=u.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=u.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>u.nodeIndexMap.get(t)),u.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=o.nodes[s];t.getMesh()&&(e.mesh=u.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=u.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=u.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>u.nodeIndexMap.get(t)))}),o.animations=e.listAnimations().map(t=>{const s=u.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=u.createPropertyDef(t);return r.input=u.accessorIndexMap.get(t.getInput()),r.output=u.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=u.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:u.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),o.scenes=e.listScenes().map(t=>{const s=u.createPropertyDef(t);return s.nodes=t.listChildren().map(t=>u.nodeIndexMap.get(t)),s}),o.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),o.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(u)),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]}(o),r}}class ft{constructor(){this.Lt=T.DEFAULT_INSTANCE,this.gt=[],this.Ot={},this.Ut=h.INTERLEAVED}setLogger(t){return this.Lt=t,this}registerExtensions(t){for(const s of t)this.gt.push(s),s.register();return this}registerDependencies(t){return Object.assign(this.Ot,t),this}setVertexLayout(t){return this.Ut=t,this}readJSON(t){return ht.read(t,{extensions:this.gt,dependencies:this.Ot,logger:this.Lt})}writeJSON(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return s.vertexLayout=this.Ut,s.dependencies=et({},this.Ot,s.dependencies),lt.write(t,s)}binaryToJSON(t){const s=this.Pt(t),e=s.json;if(e.buffers&&e.buffers.length>1)throw new Error("Cannot resolve external buffers with binaryToJSON().");if(e.images&&e.images.find(t=>void 0===t.bufferView))throw new Error("Cannot resolve external images with binaryToJSON().");return s}Pt(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=d.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{"@glb.bin":t.slice(h,h+i[0])}}}readBinary(t){return this.readJSON(this.binaryToJSON(t))}writeBinary(t){const{json:s,resources:e}=this.writeJSON(t,{basename:"",isGLB:!0,logger:this.Lt,dependencies:this.Ot,vertexLayout:this.Ut}),r=JSON.stringify(s),i=d.pad(d.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=d.concat([n,i]),o=d.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=d.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return d.concat([a,h,c])}}class dt extends ft{constructor(){super(),this.lastReadBytes=0,this.lastWriteBytes=0,this.Ft=require("fs"),this.kt=require("path")}read(t){const s=this.readAsJSON(t);return ht.read(s,{extensions:this.gt,dependencies:this.Ot,logger:this.Lt})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Gt(t):this.jt(t)}write(t,s){t.match(/\.glb$/)?this.Dt(t,s):this.Jt(t,s)}Gt(t){const s=this.Ft.readFileSync(t),e=d.trim(s);this.lastReadBytes=e.byteLength;const r=this.Pt(e);return this.zt(r,this.kt.dirname(t),!0),r}jt(t){this.lastReadBytes=0;const s=this.Ft.readFileSync(t,"utf8");this.lastReadBytes+=s.length;const e={json:JSON.parse(s),resources:{}};return this.zt(e,this.kt.dirname(t),!1),e}zt(t,s,e){const r=t.json.images||[],i=t.json.buffers||[];[...r,...i].forEach((i,n)=>{if(i.uri)if(i.uri.match(/data:/)){const s=`__${M()}.${g.extension(i.uri)}`;t.resources[s]=d.createBufferFromDataURI(i.uri),i.uri=s}else{const e=this.kt.resolve(s,i.uri);t.resources[i.uri]=d.trim(this.Ft.readFileSync(e)),this.lastReadBytes+=t.resources[i.uri].byteLength}else{const t=e&&n===r.length;if(void 0===i.bufferView&&!t)throw new Error("Missing resource URI.")}})}Jt(t,s){this.lastWriteBytes=0;const{json:e,resources:r}=lt.write(s,{basename:g.basename(t),isGLB:!1,logger:this.Lt,dependencies:this.Ot,vertexLayout:this.Ut}),{Ft:i,kt:n}=this,h=n.dirname(t),o=JSON.stringify(e,null,2);this.lastWriteBytes+=o.length,i.writeFileSync(t,o),Object.keys(r).forEach(t=>{const s=Buffer.from(r[t]);i.writeFileSync(n.join(h,t),s),this.lastWriteBytes+=s.byteLength})}Dt(t,s){const e=Buffer.from(this.writeBinary(s));this.Ft.writeFileSync(t,e),this.lastWriteBytes=e.byteLength}}const pt={};class gt extends ft{constructor(t=pt){super(),this.$t=t}read(t){return this.readAsJSON(t).then(t=>this.readJSON(t))}readAsJSON(t){return t.match(/^data:application\/octet-stream;/)||new URL(t,window.location.href).pathname.match(/\.glb$/)?this.Gt(t):this.jt(t)}jt(t){var s=this;const e={json:{},resources:{}};return fetch(t,this.$t).then(t=>t.json()).then(async function(r){return e.json=r,await s.zt(e,wt(t),!1),e})}Gt(t){var s=this;return fetch(t,this.$t).then(t=>t.arrayBuffer()).then(async function(e){const r=s.Pt(e);return await s.zt(r,wt(t),!0),r})}zt(t,s,e){const r=t.json,i=r.images||[],n=r.buffers||[],h=[...i,...n].map((r,n)=>{if(r.uri)return fetch(function(t,s){if(!function(t){return!/^(?:[a-zA-Z]+:)?\//.test(t)}(s))return s;const e=t.split("/"),r=s.split("/");e.pop();for(let t=0;t<r.length;t++)"."!==r[t]&&(".."===r[t]?e.pop():e.push(r[t]));return e.join("/")}(s,r.uri),this.$t).then(t=>t.arrayBuffer()).then(s=>{t.resources[r.uri]=s});{const t=e&&n===i.length;if(void 0===r.bufferView&&!t)throw new Error("Missing resource URI.")}});return Promise.all(h).then(()=>{})}}function wt(t){const s=t.lastIndexOf("/");return-1===s?"./":t.substr(0,s+1)}export{N as Accessor,C as Animation,_ as AnimationChannel,L as AnimationSampler,P as AttributeLink,B as Buffer,d as BufferUtils,S as COPY_IDENTITY,O as Camera,p as ColorUtils,tt as Document,st as Extension,U as ExtensionProperty,g as FileUtils,i as GLB_BUFFER,a as Graph,l as GraphChild,f as GraphChildList,m as ImageUtils,F as IndexLink,c as Link,T as Logger,V as Material,A as MathUtils,W as Mesh,Y as Node,dt as NodeIO,H as Primitive,q as PrimitiveTarget,b as Property,n as PropertyType,rt as ReaderContext,X as Root,Z as Scene,K as Skin,Q as Texture,o as TextureChannel,j as TextureInfo,k as TextureLink,h as VertexLayout,gt as WebIO,ut as WriterContext,M as uuid}; | ||
import{determinant as t,getRotation as s,multiply as e}from"gl-matrix/mat4";import{length as r}from"gl-matrix/vec3";const i="@glb.bin";var n,h,o;function u(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}!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"}(n||(n={})),function(t){t.INTERLEAVED="interleaved",t.SEPARATE="separate"}(h||(h={})),function(t){t[t.R=4096]="R",t[t.G=256]="G",t[t.B=16]="B",t[t.A=1]="A"}(o||(o={}));class c{constructor(t,s,e){if(this.t=t,this.i=s,this.h=e,this.o=!1,this.u=[],!s.canLink(e))throw new Error("Cannot link disconnected graphs/documents.")}getName(){return this.t}getParent(){return this.i}getChild(){return this.h}setChild(t){return this.h=t,this}dispose(){this.o||(this.o=!0,this.u.forEach(t=>t()),this.u.length=0)}onDispose(t){return this.u.push(t),this}isDisposed(){return this.o}}class a{constructor(){this.l=new Set,this.p=new Set,this.g=new Map,this.m=new Map,this.u={}}on(t,s){return this.u[t]=this.u[t]||[],this.u[t].push(s),this}emit(t,s){for(const e of this.u[t]||[])e(s);return this}getLinks(){return Array.from(this.p)}listParentLinks(t){return Array.from(this.m.get(t)||this.l)}listParents(t){return this.listParentLinks(t).map(t=>t.getParent())}listChildLinks(t){return Array.from(this.g.get(t)||this.l)}listChildren(t){return this.listChildLinks(t).map(t=>t.getChild())}disconnectChildren(t){return(this.g.get(t)||this.l).forEach(t=>t.dispose()),this}disconnectParents(t,s){let e=Array.from(this.m.get(t)||this.l);return s&&(e=e.filter(t=>s(t.getParent()))),e.forEach(t=>t.dispose()),this}swapChild(t,s,e){const r=this.g.get(t)||this.l;return Array.from(r).filter(t=>t.getChild()===s).forEach(t=>{this.m.get(s).delete(t),t.setChild(e),this.m.has(e)||this.m.set(e,new Set),this.m.get(e).add(t)}),this}link(t,s,e){if(!e)return null;const r=new c(t,s,e);return this.registerLink(r),r}registerLink(t){this.p.add(t);const s=t.getParent();this.g.has(s)||this.g.set(s,new Set),this.g.get(s).add(t);const e=t.getChild();return this.m.has(e)||this.m.set(e,new Set),this.m.get(e).add(t),t.onDispose(()=>this.unlink(t)),t}unlink(t){return this.p.delete(t),this.g.get(t.getParent()).delete(t),this.m.get(t.getChild()).delete(t),this}}function l(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 f(t,s){}class d{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 p{static hexToFactor(t,s){t=Math.floor(t);const e=s;return e[0]=(t>>16&255)/255,e[1]=(t>>8&255)/255,e[2]=(255&t)/255,this.convertSRGBToLinear(s,s)}static factorToHex(t){const s=[...t],[e,r,i]=this.convertLinearToSRGB(t,s);return 255*e<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(t,s){const e=t,r=s;for(let t=0;t<3;t++)r[t]=e[t]<.04045?.0773993808*e[t]:Math.pow(.9478672986*e[t]+.0521327014,2.4);return s}static convertLinearToSRGB(t,s){const e=t,r=s;for(let t=0;t<3;t++)r[t]=e[t]<.0031308?12.92*e[t]:1.055*Math.pow(e[t],.41666)-.055;return s}}class g{static basename(t){const s=t.split(/[\\/]/).pop();return s.substr(0,s.lastIndexOf("."))}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 w{getSize(t){const s=new DataView(t);return d.decodeText(t.slice(12,16))===w.PNG_FRIED_CHUNK_NAME?[s.getUint32(32,!1),s.getUint32(36,!1)]:[s.getUint32(16,!1),s.getUint32(20,!1)]}getChannels(t){return 4}}w.PNG_FRIED_CHUNK_NAME="CgBI";class m{static registerFormat(t,s){this.impls[t]=s}static getSize(t,s){return this.impls[s]?this.impls[s].getSize(t):null}static getChannels(t,s){return this.impls[s]?this.impls[s].getChannels(t):null}static getMemSize(t,s){if(!this.impls[s])return null;if(this.impls[s].getGPUByteLength)return this.impls[s].getGPUByteLength(t);let e=0;const r=this.getSize(t,s);for(;r[0]>1||r[1]>1;)e+=r[0]*r[1]*4,r[0]=Math.max(Math.floor(r[0]/2),1),r[1]=Math.max(Math.floor(r[1]/2),1);return e+=4,e}static mimeTypeToExtension(t){return"image/jpeg"===t?"jpg":t.split("/").pop()}static extensionToMimeType(t){return"jpg"===t?"image/jpeg":`image/${t}`}}function v(t,s){if(s>t.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(255!==t.getUint8(s))throw new TypeError("Invalid JPG, marker table corrupted");return t}m.impls={"image/jpeg":new class{getSize(t){let s,e,r=new DataView(t,4);for(;r.byteLength;){if(s=r.getUint16(0,!1),v(r,s),e=r.getUint8(s+1),192===e||193===e||194===e)return[r.getUint16(s+7,!1),r.getUint16(s+5,!1)];r=new DataView(t,r.byteOffset+s+2)}throw new TypeError("Invalid JPG, no size found")}getChannels(t){return 3}},"image/png":new w};class A{static identity(t){return t}static eq(t,s){if(t.length!==s.length)return!1;for(let e=0;e<t.length;e++)if(Math.abs(t[e]-s[e])>1e-5)return!1;return!0}static denormalize(t,s){switch(s){case 5126:return t;case 5123:return t/65535;case 5121:return t/255;case 5122:return Math.max(t/32767,-1);case 5120:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}static normalize(t,s){switch(s){case 5126:return t;case 5123:return Math.round(65535*t);case 5121:return Math.round(255*t);case 5122:return Math.round(32767*t);case 5120:return Math.round(127*t);default:throw new Error("Invalid component type.")}}static decompose(e,i,n,h){let o=r([e[0],e[1],e[2]]);const u=r([e[4],e[5],e[6]]),c=r([e[8],e[9],e[10]]);t(e)<0&&(o=-o),i[0]=e[12],i[1]=e[13],i[2]=e[14];const a=e.slice(),l=1/o,f=1/u,d=1/c;a[0]*=l,a[1]*=l,a[2]*=l,a[4]*=f,a[5]*=f,a[6]*=f,a[8]*=d,a[9]*=d,a[10]*=d,s(n,a),h[0]=o,h[1]=u,h[2]=c}static compose(t,s,e,r){const i=r,n=s[0],h=s[1],o=s[2],u=s[3],c=n+n,a=h+h,l=o+o,f=n*c,d=n*a,p=n*l,g=h*a,w=h*l,m=o*l,v=u*c,A=u*a,T=u*l,y=e[0],x=e[1],E=e[2];return i[0]=(1-(g+m))*y,i[1]=(d+T)*y,i[2]=(p-A)*y,i[3]=0,i[4]=(d-T)*x,i[5]=(1-(f+m))*x,i[6]=(w+v)*x,i[7]=0,i[8]=(p+A)*E,i[9]=(w-v)*E,i[10]=(1-(f+g))*E,i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i}}class T{constructor(t){this.verbosity=t}debug(t){this.verbosity<=T.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=T.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=T.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=T.Verbosity.ERROR&&console.error(t)}}T.Verbosity={SILENT:4,ERROR:3,WARN:2,INFO:1,DEBUG:0},T.DEFAULT_INSTANCE=new T(T.Verbosity.INFO);const y="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",x=new Set,E=function(){let t="";for(let s=0;s<6;s++)t+=y.charAt(Math.floor(Math.random()*y.length));return t},M=function(){for(let t=0;t<999;t++){const t=E();if(!x.has(t))return x.add(t),t}return""},S=t=>t;class b extends class{constructor(t){this.graph=t,this.o=!1,this.graph=t}canLink(t){return this.graph===t.graph}isDisposed(){return this.o}dispose(){this.graph.disconnectChildren(this),this.graph.disconnectParents(this),this.o=!0}detach(){return this.graph.disconnectParents(this),this}swap(t,s){return this.graph.swapChild(this,t,s),this}addGraphChild(t,s){return t.push(s),s.onDispose(()=>{const e=t.filter(t=>t!==s);t.length=0;for(const s of e)t.push(s)}),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.graph=t,this.v={},this.t="",this.t=s}getName(){return this.t}setName(t){return this.t=t,this}getExtras(){return this.v}setExtras(t){return this.v=t,this}clone(){const t=new(0,this.constructor)(this.graph).copy(this,S);return this.graph.emit("clone",t),t}copy(t,s=S){return this.t=t.t,this.v=JSON.parse(JSON.stringify(t.v)),this}detach(){return this.graph.disconnectParents(this,t=>"Root"!==t.propertyType),this}listParents(){return this.listGraphParents()}}const R="Pass extension name (string) as lookup token, not a constructor.";class I extends b{constructor(){super(...arguments),this.extensions=[]}copy(t,s=S){return super.copy(t,s),this.clearGraphChildList(this.extensions),t.extensions.forEach(t=>{const e=t.getChild();this.setExtension(e.extensionName,s(e))}),this}getExtension(t){if("string"!=typeof t)throw new Error(R);const s=this.extensions.find(s=>s.getChild().extensionName===t);return s?s.getChild():null}setExtension(t,s){if("string"!=typeof t)throw new Error(R);const e=this.getExtension(t);return e&&this.removeGraphChild(this.extensions,e),s?(s.T(this),this.addGraphChild(this.extensions,this.graph.link(t,this,s))):this}listExtensions(){return this.extensions.map(t=>t.getChild())}}u([f],I.prototype,"extensions",void 0);class N extends I{constructor(){super(...arguments),this.propertyType=n.ACCESSOR,this.M=null,this.S=N.Type.SCALAR,this.I=N.ComponentType.FLOAT,this.N=!1,this.C=A.identity,this._=A.identity,this.buffer=null}copy(t,s=S){return super.copy(t,s),this.S=t.S,this.I=t.I,this.N=t.N,this.C=t.C,this._=t._,t.M&&(this.M=t.M.slice()),t.buffer&&this.setBuffer(s(t.buffer.getChild())),this}static getElementSize(t){switch(t){case N.Type.SCALAR:return 1;case N.Type.VEC2:return 2;case N.Type.VEC3:return 3;case N.Type.VEC4:case N.Type.MAT2:return 4;case N.Type.MAT3:return 9;case N.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case N.ComponentType.BYTE:case N.ComponentType.UNSIGNED_BYTE:return 1;case N.ComponentType.SHORT:case N.ComponentType.UNSIGNED_SHORT:return 2;case N.ComponentType.UNSIGNED_INT:case N.ComponentType.FLOAT: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._(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.M[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._(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.M[r+s];Number.isFinite(e)&&(t[s]=Math.max(t[s],e))}return t}getCount(){return this.M?this.M.length/this.getElementSize():0}getType(){return this.S}setType(t){return this.S=t,this}getElementSize(){return N.getElementSize(this.S)}getComponentSize(){return this.M.BYTES_PER_ELEMENT}getComponentType(){return this.I}getNormalized(){return this.N}setNormalized(t){return this.N=t,t?(this._=t=>A.denormalize(t,this.I),this.C=t=>A.normalize(t,this.I)):(this._=A.identity,this.C=A.identity),this}getScalar(t){const s=this.getElementSize();return this._(this.M[t*s])}setScalar(t,s){return this.M[t*this.getElementSize()]=this.C(s),this}getElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)s[r]=this._(this.M[t*e+r]);return s}setElement(t,s){const e=this.getElementSize();for(let r=0;r<e;r++)this.M[t*e+r]=this.C(s[r]);return this}getBuffer(){return this.buffer?this.buffer.getChild():null}setBuffer(t){return this.buffer=this.graph.link("buffer",this,t),this}getArray(){return this.M}setArray(t){return this.I=t?function(t){switch(t.constructor){case Float32Array:return N.ComponentType.FLOAT;case Uint32Array:return N.ComponentType.UNSIGNED_INT;case Uint16Array:return N.ComponentType.UNSIGNED_SHORT;case Uint8Array:return N.ComponentType.UNSIGNED_BYTE;case Int16Array:return N.ComponentType.SHORT;case Int8Array:return N.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}(t):N.ComponentType.FLOAT,this.M=t,this}getByteLength(){return this.M?this.M.byteLength:0}}N.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"},N.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},u([l],N.prototype,"buffer",void 0);class C extends I{constructor(){super(...arguments),this.propertyType=n.ANIMATION,this.channels=[],this.samplers=[]}copy(t,s=S){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())}}u([f],C.prototype,"channels",void 0),u([f],C.prototype,"samplers",void 0);class _ extends b{constructor(){super(...arguments),this.propertyType=n.ANIMATION_CHANNEL,this.L=null,this.targetNode=null,this.sampler=null}copy(t,s=S){return super.copy(t,s),this.L=t.L,t.targetNode&&this.setTargetNode(s(t.targetNode.getChild())),t.sampler&&this.setSampler(s(t.sampler.getChild())),this}getTargetPath(){return this.L}setTargetPath(t){return this.L=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}}_.TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"},u([l],_.prototype,"targetNode",void 0),u([l],_.prototype,"sampler",void 0);class L extends b{constructor(){super(...arguments),this.propertyType=n.ANIMATION_SAMPLER,this.O=L.Interpolation.LINEAR,this.input=null,this.output=null}copy(t,s=S){return super.copy(t,s),this.O=t.O,t.input&&this.setInput(s(t.input.getChild())),t.output&&this.setOutput(s(t.output.getChild())),this}getInterpolation(){return this.O}setInterpolation(t){return this.O=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}}L.Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"},u([l],L.prototype,"input",void 0),u([l],L.prototype,"output",void 0);class B extends I{constructor(){super(...arguments),this.propertyType=n.BUFFER,this.U=""}copy(t,s=S){return super.copy(t,s),this.U=t.U,this}getURI(){return this.U}setURI(t){return this.U=t,this}}class O extends I{constructor(){super(...arguments),this.propertyType=n.CAMERA,this.S=O.Type.PERSPECTIVE,this.P=.1,this.F=100,this.k=null,this.j=2*Math.PI*50/360,this.D=1,this.J=1}copy(t,s=S){return super.copy(t,s),this.S=t.S,this.P=t.P,this.F=t.F,this.k=t.k,this.j=t.j,this.D=t.D,this.J=t.J,this}getType(){return this.S}setType(t){return this.S=t,this}getZNear(){return this.P}setZNear(t){return this.P=t,this}getZFar(){return this.F}setZFar(t){return this.F=t,this}getAspectRatio(){return this.k}setAspectRatio(t){return this.k=t,this}getYFov(){return this.j}setYFov(t){return this.j=t,this}getXMag(){return this.D}setXMag(t){return this.D=t,this}getYMag(){return this.J}setYMag(t){return this.J=t,this}}O.Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};class U extends b{constructor(t,s){super(t),this.$=s,this.$.addExtensionProperty(this)}dispose(){this.$.removeExtensionProperty(this),super.dispose()}T(t){if(!this.parentTypes.includes(t.propertyType))throw new Error(`Parent "${t.propertyType}" invalid for child "${this.propertyType}".`)}}class P extends c{constructor(){super(...arguments),this.semantic=""}copy(t){return this.semantic=t.semantic,this}}class F extends c{copy(t){return this}}class k extends c{constructor(){super(...arguments),this.channels=0}copy(t){return this.channels=t.channels,this}}class G extends a{linkAttribute(t,s,e){if(!e)return null;const r=new P(t,s,e);return r.semantic=t,this.registerLink(r),r}linkIndex(t,s,e){if(!e)return null;const r=new F(t,s,e);return this.registerLink(r),r}linkTexture(t,s,e,r){if(!r)return null;const i=new k(t,e,r);return i.channels=s,this.registerLink(i),i}}class j extends I{constructor(){super(...arguments),this.propertyType=n.TEXTURE_INFO,this.V=0,this.W=null,this.Y=null,this.H=j.WrapMode.REPEAT,this.q=j.WrapMode.REPEAT}copy(t,s=S){return super.copy(t,s),this.V=t.V,this.W=t.W,this.Y=t.Y,this.H=t.H,this.q=t.q,this}getTexCoord(){return this.V}setTexCoord(t){return this.V=t,this}getMagFilter(){return this.W}setMagFilter(t){return this.W=t,this}getMinFilter(){return this.Y}setMinFilter(t){return this.Y=t,this}getWrapS(){return this.H}setWrapS(t){return this.H=t,this}getWrapT(){return this.q}setWrapT(t){return this.q=t,this}}j.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},j.MagFilter={NEAREST:9728,LINEAR:9729},j.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};const{R:D,G:J,B:z,A:$}=o;class V extends I{constructor(){super(...arguments),this.propertyType=n.MATERIAL,this.Z=V.AlphaMode.OPAQUE,this.K=.5,this.X=!1,this.tt=[1,1,1,1],this.st=[0,0,0],this.et=1,this.rt=1,this.it=1,this.nt=1,this.baseColorTexture=null,this.baseColorTextureInfo=this.graph.link("baseColorTextureInfo",this,new j(this.graph)),this.emissiveTexture=null,this.emissiveTextureInfo=this.graph.link("emissiveTextureInfo",this,new j(this.graph)),this.normalTexture=null,this.normalTextureInfo=this.graph.link("normalTextureInfo",this,new j(this.graph)),this.occlusionTexture=null,this.occlusionTextureInfo=this.graph.link("occlusionTextureInfo",this,new j(this.graph)),this.metallicRoughnessTexture=null,this.metallicRoughnessTextureInfo=this.graph.link("metallicRoughnessTextureInfo",this,new j(this.graph))}copy(t,s=S){return super.copy(t,s),this.Z=t.Z,this.K=t.K,this.X=t.X,this.tt=[...t.tt],this.st=[...t.st],this.et=t.et,this.rt=t.rt,this.it=t.it,this.nt=t.nt,t.baseColorTexture&&(this.setBaseColorTexture(s(t.baseColorTexture.getChild())),this.getBaseColorTextureInfo().copy(s(t.baseColorTextureInfo.getChild()),s)),t.emissiveTexture&&(this.setEmissiveTexture(s(t.emissiveTexture.getChild())),this.getEmissiveTextureInfo().copy(s(t.emissiveTextureInfo.getChild()),s)),t.normalTexture&&(this.setNormalTexture(s(t.normalTexture.getChild())),this.getNormalTextureInfo().copy(s(t.normalTextureInfo.getChild()),s)),t.occlusionTexture&&(this.setOcclusionTexture(s(t.occlusionTexture.getChild())),this.getOcclusionTextureInfo().copy(s(t.occlusionTextureInfo.getChild()),s)),t.metallicRoughnessTexture&&(this.setMetallicRoughnessTexture(s(t.metallicRoughnessTexture.getChild())),this.getMetallicRoughnessTextureInfo().copy(s(t.metallicRoughnessTextureInfo.getChild()),s)),this}dispose(){this.baseColorTextureInfo.getChild().dispose(),this.emissiveTextureInfo.getChild().dispose(),this.normalTextureInfo.getChild().dispose(),this.occlusionTextureInfo.getChild().dispose(),this.metallicRoughnessTextureInfo.getChild().dispose(),super.dispose()}getDoubleSided(){return this.X}setDoubleSided(t){return this.X=t,this}getAlpha(){return this.tt[3]}setAlpha(t){return this.tt[3]=t,this}getAlphaMode(){return this.Z}setAlphaMode(t){return this.Z=t,this}getAlphaCutoff(){return this.K}setAlphaCutoff(t){return this.K=t,this}getBaseColorFactor(){return this.tt}setBaseColorFactor(t){return this.tt=t,this}getBaseColorHex(){return p.factorToHex(this.tt)}setBaseColorHex(t){return p.hexToFactor(t,this.tt),this}getBaseColorTexture(){return this.baseColorTexture?this.baseColorTexture.getChild():null}getBaseColorTextureInfo(){return this.baseColorTexture?this.baseColorTextureInfo.getChild():null}setBaseColorTexture(t){return this.baseColorTexture=this.graph.linkTexture("baseColorTexture",D|J|z|$,this,t),this}getEmissiveFactor(){return this.st}setEmissiveFactor(t){return this.st=t,this}getEmissiveHex(){return p.factorToHex(this.st)}setEmissiveHex(t){return p.hexToFactor(t,this.st),this}getEmissiveTexture(){return this.emissiveTexture?this.emissiveTexture.getChild():null}getEmissiveTextureInfo(){return this.emissiveTexture?this.emissiveTextureInfo.getChild():null}setEmissiveTexture(t){return this.emissiveTexture=this.graph.linkTexture("emissiveTexture",D|J|z,this,t),this}getNormalScale(){return this.et}setNormalScale(t){return this.et=t,this}getNormalTexture(){return this.normalTexture?this.normalTexture.getChild():null}getNormalTextureInfo(){return this.normalTexture?this.normalTextureInfo.getChild():null}setNormalTexture(t){return this.normalTexture=this.graph.linkTexture("normalTexture",D|J|z,this,t),this}getOcclusionStrength(){return this.rt}setOcclusionStrength(t){return this.rt=t,this}getOcclusionTexture(){return this.occlusionTexture?this.occlusionTexture.getChild():null}getOcclusionTextureInfo(){return this.occlusionTexture?this.occlusionTextureInfo.getChild():null}setOcclusionTexture(t){return this.occlusionTexture=this.graph.linkTexture("occlusionTexture",D,this,t),this}getRoughnessFactor(){return this.it}setRoughnessFactor(t){return this.it=t,this}getMetallicFactor(){return this.nt}setMetallicFactor(t){return this.nt=t,this}getMetallicRoughnessTexture(){return this.metallicRoughnessTexture?this.metallicRoughnessTexture.getChild():null}getMetallicRoughnessTextureInfo(){return this.metallicRoughnessTexture?this.metallicRoughnessTextureInfo.getChild():null}setMetallicRoughnessTexture(t){return this.metallicRoughnessTexture=this.graph.linkTexture("metallicRoughnessTexture",J|z,this,t),this}}V.AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"},u([l],V.prototype,"baseColorTexture",void 0),u([l],V.prototype,"baseColorTextureInfo",void 0),u([l],V.prototype,"emissiveTexture",void 0),u([l],V.prototype,"emissiveTextureInfo",void 0),u([l],V.prototype,"normalTexture",void 0),u([l],V.prototype,"normalTextureInfo",void 0),u([l],V.prototype,"occlusionTexture",void 0),u([l],V.prototype,"occlusionTextureInfo",void 0),u([l],V.prototype,"metallicRoughnessTexture",void 0),u([l],V.prototype,"metallicRoughnessTextureInfo",void 0);class W extends I{constructor(){super(...arguments),this.propertyType=n.MESH,this.ht=[],this.primitives=[]}copy(t,s=S){return super.copy(t,s),this.ht=[...t.ht],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.ht}setWeights(t){return this.ht=t,this}}u([f],W.prototype,"primitives",void 0);class Y extends I{constructor(){super(...arguments),this.propertyType=n.NODE,this.ot=[0,0,0],this.ut=[0,0,0,1],this.ct=[1,1,1],this.ht=[],this.i=null,this.camera=null,this.mesh=null,this.skin=null,this.children=[]}copy(t,s=S){return super.copy(t,s),this.ot=[...t.ot],this.ut=[...t.ut],this.ct=[...t.ct],this.ht=[...t.ht],t.camera&&this.setCamera(s(t.camera.getChild())),t.mesh&&this.setMesh(s(t.mesh.getChild())),t.skin&&this.setSkin(s(t.skin.getChild())),s!==S&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}getTranslation(){return this.ot}getRotation(){return this.ut}getScale(){return this.ct}setTranslation(t){return this.ot=t,this}setRotation(t){return this.ut=t,this}setScale(t){return this.ct=t,this}getMatrix(){return A.compose(this.ot,this.ut,this.ct,[])}getWorldTranslation(){const t=[0,0,0];return A.decompose(this.getWorldMatrix(),t,[0,0,0,1],[1,1,1]),t}getWorldRotation(){const t=[0,0,0,1];return A.decompose(this.getWorldMatrix(),[0,0,0],t,[1,1,1]),t}getWorldScale(){const t=[1,1,1];return A.decompose(this.getWorldMatrix(),[0,0,0],[0,0,0,1],t),t}getWorldMatrix(){const t=[];for(let s=this;s instanceof Y;s=s.i)t.push(s);let s;const r=t.pop().getMatrix();for(;s=t.pop();)e(r,r,s.getMatrix());return r}addChild(t){t.i&&t.i.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.i=this,s.onDispose(()=>t.i=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}getParent(){return this.i}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.ht}setWeights(t){return this.ht=t,this}traverse(t){t(this);for(const s of this.listChildren())s.traverse(t);return this}}u([l],Y.prototype,"camera",void 0),u([l],Y.prototype,"mesh",void 0),u([l],Y.prototype,"skin",void 0),u([f],Y.prototype,"children",void 0);class H extends I{constructor(){super(...arguments),this.propertyType=n.PRIMITIVE,this.at=H.Mode.TRIANGLES,this.material=null,this.indices=null,this.attributes=[],this.targets=[]}copy(t,s=S){return super.copy(t,s),this.at=t.at,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,this,s);return 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.at}setMode(t){return this.at=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)}}H.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},u([l],H.prototype,"material",void 0),u([l],H.prototype,"indices",void 0),u([f],H.prototype,"attributes",void 0),u([f],H.prototype,"targets",void 0);class q extends b{constructor(){super(...arguments),this.propertyType=n.PRIMITIVE_TARGET,this.attributes=[]}copy(t,s=S){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)}}u([f],q.prototype,"attributes",void 0);class Z extends I{constructor(){super(...arguments),this.propertyType=n.SCENE,this.children=[]}copy(t,s=S){return super.copy(t,s),s!==S&&(this.clearGraphChildList(this.children),t.children.forEach(t=>this.addChild(s(t.getChild())))),this}addChild(t){t.i&&t.i.removeChild(t);const s=this.graph.link("child",this,t);return this.addGraphChild(this.children,s),t.i=this,s.onDispose(()=>t.i=null),this}removeChild(t){return this.removeGraphChild(this.children,t)}listChildren(){return this.children.map(t=>t.getChild())}traverse(t){for(const s of this.listChildren())s.traverse(t);return this}}u([f],Z.prototype,"children",void 0);class K extends I{constructor(){super(...arguments),this.propertyType=n.SKIN,this.skeleton=null,this.inverseBindMatrices=null,this.joints=[]}copy(t,s=S){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())}}u([l],K.prototype,"skeleton",void 0),u([l],K.prototype,"inverseBindMatrices",void 0),u([f],K.prototype,"joints",void 0);class Q extends I{constructor(){super(...arguments),this.propertyType=n.TEXTURE,this.lt=null,this.ft="",this.U=""}copy(t,s=S){return super.copy(t,s),this.ft=t.ft,this.U=t.U,t.lt&&(this.lt=t.lt.slice(0)),this}getMimeType(){return this.ft||m.extensionToMimeType(g.extension(this.U))}setMimeType(t){return this.ft=t,this}getURI(){return this.U}setURI(t){return this.U=t,this.ft=m.extensionToMimeType(g.extension(t)),this}getImage(){return this.lt}setImage(t){return this.lt=t,this}getSize(){return this.lt?m.getSize(this.lt,this.getMimeType()):null}}class X extends b{constructor(t){super(t),this.propertyType=n.ROOT,this.dt={generator:"glTF-Transform v0.11.0-alpha.0",version:"2.0"},this.gt=new Set,this.accessors=[],this.animations=[],this.buffers=[],this.cameras=[],this.materials=[],this.meshes=[],this.nodes=[],this.scenes=[],this.skins=[],this.textures=[],t.on("clone",t=>this.wt(t))}clone(){throw new Error("Root cannot be cloned.")}copy(t,s=S){if(super.copy(t,s),s===S)throw new Error("Root cannot be copied.");return Object.assign(this.dt,t.dt),t.accessors.forEach(t=>this.vt(s(t.getChild()))),t.animations.forEach(t=>this.At(s(t.getChild()))),t.buffers.forEach(t=>this.Tt(s(t.getChild()))),t.cameras.forEach(t=>this.yt(s(t.getChild()))),t.materials.forEach(t=>this.xt(s(t.getChild()))),t.meshes.forEach(t=>this.Et(s(t.getChild()))),t.nodes.forEach(t=>this.Mt(s(t.getChild()))),t.scenes.forEach(t=>this.St(s(t.getChild()))),t.skins.forEach(t=>this.bt(s(t.getChild()))),t.textures.forEach(t=>this.Rt(s(t.getChild()))),this}wt(t){return t instanceof Z?this.St(t):t instanceof Y?this.Mt(t):t instanceof O?this.yt(t):t instanceof K?this.bt(t):t instanceof W?this.Et(t):t instanceof V?this.xt(t):t instanceof Q?this.Rt(t):t instanceof C?this.At(t):t instanceof N?this.vt(t):t instanceof B&&this.Tt(t),this}getAsset(){return this.dt}listExtensionsUsed(){return Array.from(this.gt)}listExtensionsRequired(){return this.listExtensionsUsed().filter(t=>t.isRequired())}It(t){return this.gt.add(t),this}Nt(t){return this.gt.delete(t),this}St(t){return this.addGraphChild(this.scenes,this.graph.link("scene",this,t))}listScenes(){return this.scenes.map(t=>t.getChild())}Mt(t){return this.addGraphChild(this.nodes,this.graph.link("node",this,t))}listNodes(){return this.nodes.map(t=>t.getChild())}yt(t){return this.addGraphChild(this.cameras,this.graph.link("camera",this,t))}listCameras(){return this.cameras.map(t=>t.getChild())}bt(t){return this.addGraphChild(this.skins,this.graph.link("skin",this,t))}listSkins(){return this.skins.map(t=>t.getChild())}Et(t){return this.addGraphChild(this.meshes,this.graph.link("mesh",this,t))}listMeshes(){return this.meshes.map(t=>t.getChild())}xt(t){return this.addGraphChild(this.materials,this.graph.link("material",this,t))}listMaterials(){return this.materials.map(t=>t.getChild())}Rt(t){return this.addGraphChild(this.textures,this.graph.link("texture",this,t))}listTextures(){return this.textures.map(t=>t.getChild())}At(t){return this.addGraphChild(this.animations,this.graph.link("animation",this,t))}listAnimations(){return this.animations.map(t=>t.getChild())}vt(t){return this.addGraphChild(this.accessors,this.graph.link("accessor",this,t))}listAccessors(){return this.accessors.map(t=>t.getChild())}Tt(t){return this.addGraphChild(this.buffers,this.graph.link("buffer",this,t))}listBuffers(){return this.buffers.map(t=>t.getChild())}}u([f],X.prototype,"accessors",void 0),u([f],X.prototype,"animations",void 0),u([f],X.prototype,"buffers",void 0),u([f],X.prototype,"cameras",void 0),u([f],X.prototype,"materials",void 0),u([f],X.prototype,"meshes",void 0),u([f],X.prototype,"nodes",void 0),u([f],X.prototype,"scenes",void 0),u([f],X.prototype,"skins",void 0),u([f],X.prototype,"textures",void 0);class tt{constructor(){this.Ct=new G,this._t=new X(this.Ct),this.Lt=T.DEFAULT_INSTANCE}getRoot(){return this._t}getGraph(){return this.Ct}getLogger(){return this.Lt}setLogger(t){return this.Lt=t,this}clone(){return(new tt).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._t),r.set(t._t,this._t);for(const i of t.Ct.getLinks())for(const t of[i.getParent(),i.getChild()]){if(e.has(t))continue;let i;if(t.propertyType===n.TEXTURE_INFO)i=t;else{const e=t.constructor;i=t instanceof U?new e(this.Ct,s[t.extensionName]):new e(this.Ct)}r.set(t,i),e.add(t)}const i=t=>{const s=r.get(t);if(!s)throw new Error("Could resolve property.");return s};for(const t of e){const s=r.get(t);if(!s)throw new Error("Could resolve property.");s.copy(t,i)}return this}async transform(...t){for(const s of t)await s(this);return this}createExtension(t){return this.getRoot().listExtensionsUsed().find(s=>s.extensionName===t.EXTENSION_NAME)||new t(this)}createScene(t=""){const s=new Z(this.Ct,t);return this._t.St(s),s}createNode(t=""){const s=new Y(this.Ct,t);return this._t.Mt(s),s}createCamera(t=""){const s=new O(this.Ct,t);return this._t.yt(s),s}createSkin(t=""){const s=new K(this.Ct,t);return this._t.bt(s),s}createMesh(t=""){const s=new W(this.Ct,t);return this._t.Et(s),s}createPrimitive(){return new H(this.Ct)}createPrimitiveTarget(t=""){return new q(this.Ct,t)}createMaterial(t=""){const s=new V(this.Ct,t);return this._t.xt(s),s}createTexture(t=""){const s=new Q(this.Ct,t);return this._t.Rt(s),s}createAnimation(t=""){const s=new C(this.Ct,t);return this._t.At(s),s}createAnimationChannel(t=""){return new _(this.Ct,t)}createAnimationSampler(t=""){return new L(this.Ct,t)}createAccessor(t="",s=null){s||(s=this.getRoot().listBuffers()[0]);const e=new N(this.Ct,t).setBuffer(s);return this._t.vt(e),e}createBuffer(t=""){const s=new B(this.Ct,t);return this._t.Tt(s),s}}class st{constructor(t){this.doc=t,this.prereadTypes=[],this.prewriteTypes=[],this.dependencies=[],this.required=!1,this.properties=new Set,t.getRoot().It(this)}dispose(){this.doc.getRoot().Nt(this);for(const t of this.properties)t.dispose()}static register(){}isRequired(){return this.required}setRequired(t){return this.required=t,this}addExtensionProperty(t){return this.properties.add(t),this}removeExtensionProperty(t){return this.properties.delete(t),this}install(t,s){return this}preread(t,s){return this}prewrite(t,s){return this}}function et(){return(et=Object.assign||function(t){for(var s=1;s<arguments.length;s++){var e=arguments[s];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}class rt{constructor(t){this.jsonDoc=t,this.buffers=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[]}setTextureInfo(t,s){this.textureInfos.set(t,s),void 0!==s.texCoord&&t.setTexCoord(s.texCoord);const e=this.jsonDoc.json.textures[s.index];if(void 0===e.sampler)return;const r=this.jsonDoc.json.samplers[e.sampler];void 0!==r.magFilter&&t.setMagFilter(r.magFilter),void 0!==r.minFilter&&t.setMinFilter(r.minFilter),void 0!==r.wrapS&&t.setWrapS(r.wrapS),void 0!==r.wrapT&&t.setWrapT(r.wrapT)}}const it={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},nt={logger:T.DEFAULT_INSTANCE,extensions:[],dependencies:{}};class ht{static read(t,s=nt){const{json:e}=t,r=new tt;this.validate(t,s);const i=new rt(t),h=t.json.asset,o=r.getRoot().getAsset();h.copyright&&(o.copyright=h.copyright),h.extras&&(o.extras=h.extras),h.generator&&(o.generator=h.generator),h.minVersion&&(o.minVersion=h.minVersion);const u=e.extensionsUsed||[],c=e.extensionsRequired||[];for(const t of s.extensions)if(u.includes(t.EXTENSION_NAME)){const e=r.createExtension(t).setRequired(c.includes(t.EXTENSION_NAME));for(const t of e.dependencies)e.install(t,s.dependencies[t])}i.buffers=(e.buffers||[]).map(t=>{const s=r.createBuffer(t.name);return t.extras&&s.setExtras(t.extras),t.uri&&0!==t.uri.indexOf("__")&&s.setURI(t.uri),s}),i.bufferViewBuffers=(e.bufferViews||[]).map(t=>i.buffers[t.buffer]),i.accessors=(e.accessors||[]).map(s=>{const e=r.createAccessor(s.name,i.bufferViewBuffers[s.bufferView]).setType(s.type);if(s.extras&&e.setExtras(s.extras),void 0!==s.normalized&&e.setNormalized(s.normalized),void 0===s.bufferView&&!s.sparse)return e;let n;return n=void 0!==s.sparse?function(t,s){const e=it[t.componentType],r=N.getElementSize(t.type);let i;i=void 0!==t.bufferView?ot(t,s).slice():new e(t.count*r);const n=t.sparse.count,h=et({},t,t.sparse.indices,{count:n,type:"SCALAR"}),o=et({},t,t.sparse.values,{count:n}),u=ot(h,s),c=ot(o,s);for(let t=0;t<h.count;t++)for(let s=0;s<r;s++)i[u[t]*r+s]=c[t*r+s];return i}(s,t):ot(s,t).slice(),e.setArray(n),e});const a=e.images||[],l=e.textures||[];r.getRoot().listExtensionsUsed().filter(t=>t.prereadTypes.includes(n.TEXTURE)).forEach(t=>t.preread(i,n.TEXTURE)),i.textures=a.map(s=>{const i=r.createTexture(s.name);if(s.extras&&i.setExtras(s.extras),void 0!==s.bufferView){const r=e.bufferViews[s.bufferView],n=t.json.buffers[r.buffer],h=r.byteOffset||0,o=(n.uri?t.resources[n.uri]:t.resources["@glb.bin"]).slice(h,h+r.byteLength);i.setImage(o)}else void 0!==s.uri&&(i.setImage(t.resources[s.uri]),0!==s.uri.indexOf("__")&&i.setURI(s.uri));if(void 0!==s.mimeType)i.setMimeType(s.mimeType);else if(s.uri){const t=g.extension(s.uri);i.setMimeType(m.extensionToMimeType(t))}return i}),i.materials=(e.materials||[]).map(t=>{const s=r.createMaterial(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.alphaMode&&s.setAlphaMode(t.alphaMode),void 0!==t.alphaCutoff&&s.setAlphaCutoff(t.alphaCutoff),void 0!==t.doubleSided&&s.setDoubleSided(t.doubleSided);const e=t.pbrMetallicRoughness||{};if(void 0!==e.baseColorFactor&&s.setBaseColorFactor(e.baseColorFactor),void 0!==t.emissiveFactor&&s.setEmissiveFactor(t.emissiveFactor),void 0!==e.metallicFactor&&s.setMetallicFactor(e.metallicFactor),void 0!==e.roughnessFactor&&s.setRoughnessFactor(e.roughnessFactor),void 0!==e.baseColorTexture){const t=e.baseColorTexture;s.setBaseColorTexture(i.textures[l[t.index].source]),i.setTextureInfo(s.getBaseColorTextureInfo(),t)}if(void 0!==t.emissiveTexture){const e=t.emissiveTexture;s.setEmissiveTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getEmissiveTextureInfo(),e)}if(void 0!==t.normalTexture){const e=t.normalTexture;s.setNormalTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getNormalTextureInfo(),e),void 0!==t.normalTexture.scale&&s.setNormalScale(t.normalTexture.scale)}if(void 0!==t.occlusionTexture){const e=t.occlusionTexture;s.setOcclusionTexture(i.textures[l[e.index].source]),i.setTextureInfo(s.getOcclusionTextureInfo(),e),void 0!==t.occlusionTexture.strength&&s.setOcclusionStrength(t.occlusionTexture.strength)}if(void 0!==e.metallicRoughnessTexture){const t=e.metallicRoughnessTexture;s.setMetallicRoughnessTexture(i.textures[l[t.index].source]),i.setTextureInfo(s.getMetallicRoughnessTextureInfo(),t)}return s});const f=e.meshes||[];r.getRoot().listExtensionsUsed().filter(t=>t.prereadTypes.includes(n.PRIMITIVE)).forEach(t=>t.preread(i,n.PRIMITIVE)),i.meshes=f.map(t=>{const s=r.createMesh(t.name);return t.extras&&s.setExtras(t.extras),void 0!==t.weights&&s.setWeights(t.weights),(t.primitives||[]).forEach(e=>{const n=r.createPrimitive();e.extras&&n.setExtras(e.extras),void 0!==e.material&&n.setMaterial(i.materials[e.material]),void 0!==e.mode&&n.setMode(e.mode);for(const[t,s]of Object.entries(e.attributes||{}))n.setAttribute(t,i.accessors[s]);void 0!==e.indices&&n.setIndices(i.accessors[e.indices]);const h=t.extras&&t.extras.targetNames||[];(e.targets||[]).forEach((t,s)=>{const e=h[s]||s.toString(),o=r.createPrimitiveTarget(e);for(const[s,e]of Object.entries(t))o.setAttribute(s,i.accessors[e]);n.addTarget(o)}),s.addPrimitive(n)}),s}),i.cameras=(e.cameras||[]).map(t=>{const s=r.createCamera(t.name).setType(t.type);return t.extras&&s.setExtras(t.extras),t.type===O.Type.PERSPECTIVE?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 d=e.nodes||[];return i.nodes=d.map(t=>{const s=r.createNode(t.name);if(t.extras&&s.setExtras(t.extras),void 0!==t.translation&&s.setTranslation(t.translation),void 0!==t.rotation&&s.setRotation(t.rotation),void 0!==t.scale&&s.setScale(t.scale),void 0!==t.matrix){const e=[0,0,0],r=[0,0,0,1],i=[1,1,1];A.decompose(t.matrix,e,r,i),s.setTranslation(e),s.setRotation(r),s.setScale(i)}return void 0!==t.weights&&s.setWeights(t.weights),s}),i.skins=(e.skins||[]).map(t=>{const s=r.createSkin(t.name);t.extras&&s.setExtras(t.extras),void 0!==t.inverseBindMatrices&&s.setInverseBindMatrices(i.accessors[t.inverseBindMatrices]),void 0!==t.skeleton&&s.setSkeleton(i.nodes[t.skeleton]);for(const e of t.joints)s.addJoint(i.nodes[e]);return s}),d.map((t,s)=>{const e=i.nodes[s];(t.children||[]).forEach(t=>e.addChild(i.nodes[t])),void 0!==t.mesh&&e.setMesh(i.meshes[t.mesh]),void 0!==t.camera&&e.setCamera(i.cameras[t.camera]),void 0!==t.skin&&e.setSkin(i.skins[t.skin])}),i.animations=(e.animations||[]).map(t=>{const s=r.createAnimation(t.name);t.extras&&s.setExtras(t.extras);const e=(t.samplers||[]).map(t=>{const e=r.createAnimationSampler().setInput(i.accessors[t.input]).setOutput(i.accessors[t.output]).setInterpolation(t.interpolation||L.Interpolation.LINEAR);return t.extras&&e.setExtras(t.extras),s.addSampler(e),e});return(t.channels||[]).forEach(t=>{const n=r.createAnimationChannel().setSampler(e[t.sampler]).setTargetNode(i.nodes[t.target.node]).setTargetPath(t.target.path);t.extras&&n.setExtras(t.extras),s.addChannel(n)}),s}),i.scenes=(e.scenes||[]).map(t=>{const s=r.createScene(t.name);return t.extras&&s.setExtras(t.extras),(t.nodes||[]).map(t=>i.nodes[t]).forEach(t=>s.addChild(t)),s}),r.getRoot().listExtensionsUsed().forEach(t=>t.read(i)),r}static validate(t,s){const e=t.json;if("2.0"!==e.asset.version)throw new Error(`Unsupported glTF version, "${e.asset.version}".`);if(e.extensionsRequired)for(const t of e.extensionsRequired)if(!s.extensions.find(s=>s.EXTENSION_NAME===t))throw new Error(`Missing required extension, "${t}".`);if(e.extensionsUsed)for(const t of e.extensionsUsed)s.extensions.find(s=>s.EXTENSION_NAME===t)||s.logger.warn(`Missing optional extension, "${t}".`)}}function ot(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=it[t.componentType],h=N.getElementSize(t.type);if(void 0!==e.byteStride&&e.byteStride!==h*n.BYTES_PER_ELEMENT)return function(t,s){const e=s.json.bufferViews[t.bufferView],r=s.json.buffers[e.buffer],i=r.uri?s.resources[r.uri]:s.resources["@glb.bin"],n=it[t.componentType],h=N.getElementSize(t.type),o=n.BYTES_PER_ELEMENT,u=t.byteOffset||0,c=new n(t.count*h),a=new DataView(i,e.byteOffset,e.byteLength),l=e.byteStride;for(let s=0;s<t.count;s++)for(let e=0;e<h;e++){const r=u+s*l+e*o;let i;switch(t.componentType){case N.ComponentType.FLOAT:i=a.getFloat32(r,!0);break;case N.ComponentType.UNSIGNED_INT:i=a.getUint32(r,!0);break;case N.ComponentType.UNSIGNED_SHORT:i=a.getUint16(r,!0);break;case N.ComponentType.UNSIGNED_BYTE:i=a.getUint8(r);break;case N.ComponentType.SHORT:i=a.getInt16(r,!0);break;case N.ComponentType.BYTE: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 N.ComponentType.FLOAT:return new Float32Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_INT:return new Uint32Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_SHORT:return new Uint16Array(i,o,t.count*h);case N.ComponentType.UNSIGNED_BYTE:return new Uint8Array(i,o,t.count*h);case N.ComponentType.SHORT:return new Int16Array(i,o,t.count*h);case N.ComponentType.BYTE:return new Int8Array(i,o,t.count*h);default:throw new Error(`Unexpected componentType "${t.componentType}".`)}}class ut{constructor(t,s){this.jsonDoc=t,this.options=s,this.accessorIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.textureInfoDefMap=new Map,this.samplerDefIndexMap=new Map,this.imageBufferViews=[],this.otherBufferViews=new Map,this.otherBufferViewsIndexMap=new Map,this.extensionData={},this.Bt=new Map,this.accessorUsageGroupedByParent=new Set(["ARRAY_BUFFER"])}createTextureInfoDef(t,s){const e={magFilter:s.getMagFilter()||void 0,minFilter:s.getMinFilter()||void 0,wrapS:s.getWrapS(),wrapT:s.getWrapT()},r=JSON.stringify(e);this.samplerDefIndexMap.has(r)||(this.samplerDefIndexMap.set(r,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(e));const i={source:this.imageIndexMap.get(t),sampler:this.samplerDefIndexMap.get(r)},n=JSON.stringify(i);this.textureDefIndexMap.has(n)||(this.textureDefIndexMap.set(n,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(i));const h={index:this.textureDefIndexMap.get(n),texCoord:s.getTexCoord()};return this.textureInfoDefMap.set(s,h),h}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.imageBufferViews.push(s),t.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:s.byteLength});else{const r=m.mimeTypeToExtension(e.getMimeType());t.uri=this.imageURIGenerator.createURI(e,r),this.jsonDoc.resources[t.uri]=s}}getAccessorUsage(t){return this.Bt.get(t)}setAccessorUsage(t,s){const e=this.Bt.get(t);if(e&&e!==s)throw new Error(`Accessor with usage "${e}" cannot be reused as "${s}".`);return this.Bt.set(t,s),this}listAccessorsByUsage(){const t={};for(const[s,e]of Array.from(this.Bt.entries()))t[e]=t[e]||[],t[e].push(s);return t}}class ct{constructor(t,s){this.multiple=t,this.basename=s,this.counter=1}createURI(t,s){return t.getURI()?t.getURI():this.multiple?`${this.basename}_${this.counter++}.${s}`:`${this.basename}.${s}`}}const at={logger:T.DEFAULT_INSTANCE,basename:"",isGLB:!0,vertexLayout:h.INTERLEAVED,dependencies:{}};class lt{static write(t,s=at){const e=t.getRoot(),r={json:{asset:e.getAsset()},resources:{}},i=s.logger||T.DEFAULT_INSTANCE,o=r.json;o.asset.generator="glTF-Transform v0.11.0-alpha.0";const u=new ut(r,s),c=e.listBuffers().length,a=e.listTextures().length;u.bufferURIGenerator=new ct(c>1,s.basename),u.imageURIGenerator=new ct(a>1,s.basename),u.logger=t.getLogger();for(const e of t.getRoot().listExtensionsUsed())for(const t of e.dependencies)e.install(t,s.dependencies[t]);function l(t,s,e,r){const i=[];let n=0;for(const s of t){const t=u.createAccessorDef(s);t.bufferView=o.bufferViews.length;const e=d.pad(s.getArray().buffer);t.byteOffset=n,n+=e.byteLength,i.push(e),u.accessorIndexMap.set(s,o.accessors.length),o.accessors.push(t)}const h={buffer:s,byteOffset:e,byteLength:d.concat(i).byteLength};return r&&(h.target=r),o.bufferViews.push(h),{buffers:i,byteLength:n}}function f(t,s,e){const r=t[0].getCount();let i=0;for(const s of t){const t=u.createAccessorDef(s);t.bufferView=o.bufferViews.length,t.byteOffset=i;const e=s.getElementSize(),r=s.getComponentSize();i+=d.padNumber(e*r),u.accessorIndexMap.set(s,o.accessors.length),o.accessors.push(t)}const n=r*i,h=new ArrayBuffer(n),c=new DataView(h);for(let s=0;s<r;s++){let e=0;for(const r of t){const t=r.getElementSize(),n=r.getComponentSize(),h=r.getComponentType(),o=r.getArray();for(let r=0;r<t;r++){const u=s*i+e+r*n,a=o[s*t+r];switch(h){case N.ComponentType.FLOAT:c.setFloat32(u,a,!0);break;case N.ComponentType.BYTE:c.setInt8(u,a);break;case N.ComponentType.SHORT:c.setInt16(u,a,!0);break;case N.ComponentType.UNSIGNED_BYTE:c.setUint8(u,a);break;case N.ComponentType.UNSIGNED_SHORT:c.setUint16(u,a,!0);break;case N.ComponentType.UNSIGNED_INT:c.setUint32(u,a,!0);break;default:throw new Error("Unexpected component type: "+h)}}e+=d.padNumber(t*n)}}return o.bufferViews.push({buffer:s,byteOffset:e,byteLength:n,byteStride:i,target:34962}),{byteLength:n,buffers:[h]}}const p=new Map;for(const s of t.getGraph().getLinks()){if(s.getParent()===e)continue;const t=s.getChild();if(t instanceof N){const e=p.get(t)||[];e.push(s),p.set(t,e)}}return o.accessors=[],o.bufferViews=[],o.samplers=[],o.textures=[],o.images=e.listTextures().map((t,s)=>{const e=u.createPropertyDef(t);return t.getMimeType()&&(e.mimeType=t.getMimeType()),t.getImage()&&u.createImageData(e,t.getImage(),t),u.imageIndexMap.set(t,s),e}),t.getRoot().listExtensionsUsed().filter(t=>t.prewriteTypes.includes(n.ACCESSOR)).forEach(t=>t.prewrite(u,n.ACCESSOR)),o.buffers=[],e.listBuffers().forEach(t=>{const e=u.createPropertyDef(t),i=u.accessorUsageGroupedByParent,n=new Map,c=t.listParents().filter(t=>t instanceof N),a=new Set(c);for(const t of c){if(u.accessorIndexMap.has(t))continue;const s=p.get(t)||[];for(const e of s){if(u.getAccessorUsage(t))break;e instanceof P?u.setAccessorUsage(t,"ARRAY_BUFFER"):e instanceof F?u.setAccessorUsage(t,"ELEMENT_ARRAY_BUFFER"):"inverseBindMatrices"===e.getName()&&u.setAccessorUsage(t,"INVERSE_BIND_MATRICES")}if(u.getAccessorUsage(t)||u.setAccessorUsage(t,"OTHER"),i.has(u.getAccessorUsage(t))){const e=s[0].getParent(),r=n.get(e)||new Set;r.add(t),n.set(e,r)}}const g=[],w=o.buffers.length;let m=0;const v=u.listAccessorsByUsage();for(const t in v)if(i.has(t))for(const e of Array.from(n.values())){const r=Array.from(e).filter(t=>a.has(t)).filter(s=>u.getAccessorUsage(s)===t);if(r.length)if("ARRAY_BUFFER"!==t||s.vertexLayout===h.INTERLEAVED){const s="ARRAY_BUFFER"===t?f(r,w,m):l(r,w,m);m+=s.byteLength,g.push(...s.buffers)}else for(const t of r){const s=f([t],w,m);m+=s.byteLength,g.push(...s.buffers)}}else{const s=v[t].filter(t=>a.has(t));if(!s.length)continue;const e=l(s,w,m,"ELEMENT_ARRAY_BUFFER"===t?34963:null);m+=e.byteLength,g.push(...e.buffers)}if(u.imageBufferViews.length)for(let t=0;t<u.imageBufferViews.length;t++)if(o.bufferViews[o.images[t].bufferView].byteOffset=m,m+=u.imageBufferViews[t].byteLength,g.push(u.imageBufferViews[t]),m%4){const t=4-m%4;m+=t,g.push(new ArrayBuffer(t))}if(u.otherBufferViews.has(t))for(const s of u.otherBufferViews.get(t))o.bufferViews.push({buffer:w,byteOffset:m,byteLength:s.byteLength}),u.otherBufferViewsIndexMap.set(s,o.bufferViews.length-1),m+=s.byteLength,g.push(s);if(!m)return void u.logger.warn(`@gltf-transform/core: Skipping empty buffer, "${t.getName()}".`);let A;s.isGLB?A="@glb.bin":(A=u.bufferURIGenerator.createURI(t,"bin"),e.uri=A),e.byteLength=m,r.resources[A]=d.concat(g),o.buffers.push(e)}),e.listAccessors().find(t=>!t.getBuffer())&&i.warn("Skipped writing one or more Accessors: no Buffer assigned."),o.materials=e.listMaterials().map((t,s)=>{const e=u.createPropertyDef(t);if(e.alphaMode=t.getAlphaMode(),t.getAlphaMode()===V.AlphaMode.MASK&&(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();e.pbrMetallicRoughness.baseColorTexture=u.createTextureInfoDef(s,r)}if(t.getEmissiveTexture()){const s=t.getEmissiveTexture(),r=t.getEmissiveTextureInfo();e.emissiveTexture=u.createTextureInfoDef(s,r)}if(t.getNormalTexture()){const s=t.getNormalTexture(),r=t.getNormalTextureInfo(),i=u.createTextureInfoDef(s,r);1!==t.getNormalScale()&&(i.scale=t.getNormalScale()),e.normalTexture=i}if(t.getOcclusionTexture()){const s=t.getOcclusionTexture(),r=t.getOcclusionTextureInfo(),i=u.createTextureInfoDef(s,r);1!==t.getOcclusionStrength()&&(i.strength=t.getOcclusionStrength()),e.occlusionTexture=i}if(t.getMetallicRoughnessTexture()){const s=t.getMetallicRoughnessTexture(),r=t.getMetallicRoughnessTextureInfo();e.pbrMetallicRoughness.metallicRoughnessTexture=u.createTextureInfoDef(s,r)}return u.materialIndexMap.set(t,s),e}),o.meshes=e.listMeshes().map((t,s)=>{const e=u.createPropertyDef(t);let r;return e.primitives=t.listPrimitives().map(t=>{const s={attributes:{}};s.mode=t.getMode(),t.getMaterial()&&(s.material=u.materialIndexMap.get(t.getMaterial())),Object.keys(t.getExtras()).length&&(s.extras=t.getExtras()),t.getIndices()&&(s.indices=u.accessorIndexMap.get(t.getIndices()));for(const e of t.listSemantics())s.attributes[e]=u.accessorIndexMap.get(t.getAttribute(e));for(const e of t.listTargets()){const t={};for(const s of e.listSemantics())t[s]=u.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),u.meshIndexMap.set(t,s),e}),o.cameras=e.listCameras().map((t,s)=>{const e=u.createPropertyDef(t);return e.type=t.getType(),e.type===O.Type.PERSPECTIVE?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()},u.cameraIndexMap.set(t,s),e}),o.nodes=e.listNodes().map((t,s)=>{const e=u.createPropertyDef(t);return A.eq(t.getTranslation(),[0,0,0])||(e.translation=t.getTranslation()),A.eq(t.getRotation(),[0,0,0,1])||(e.rotation=t.getRotation()),A.eq(t.getScale(),[1,1,1])||(e.scale=t.getScale()),t.getWeights().length&&(e.weights=t.getWeights()),u.nodeIndexMap.set(t,s),e}),o.skins=e.listSkins().map((t,s)=>{const e=u.createPropertyDef(t);return t.getInverseBindMatrices()&&(e.inverseBindMatrices=u.accessorIndexMap.get(t.getInverseBindMatrices())),t.getSkeleton()&&(e.skeleton=u.nodeIndexMap.get(t.getSkeleton())),e.joints=t.listJoints().map(t=>u.nodeIndexMap.get(t)),u.skinIndexMap.set(t,s),e}),e.listNodes().forEach((t,s)=>{const e=o.nodes[s];t.getMesh()&&(e.mesh=u.meshIndexMap.get(t.getMesh())),t.getCamera()&&(e.camera=u.cameraIndexMap.get(t.getCamera())),t.getSkin()&&(e.skin=u.skinIndexMap.get(t.getSkin())),t.listChildren().length>0&&(e.children=t.listChildren().map(t=>u.nodeIndexMap.get(t)))}),o.animations=e.listAnimations().map(t=>{const s=u.createPropertyDef(t),e=new Map;return s.samplers=t.listSamplers().map((t,s)=>{const r=u.createPropertyDef(t);return r.input=u.accessorIndexMap.get(t.getInput()),r.output=u.accessorIndexMap.get(t.getOutput()),r.interpolation=t.getInterpolation(),e.set(t,s),r}),s.channels=t.listChannels().map(t=>{const s=u.createPropertyDef(t);return s.sampler=e.get(t.getSampler()),s.target={node:u.nodeIndexMap.get(t.getTargetNode()),path:t.getTargetPath()},s}),s}),o.scenes=e.listScenes().map(t=>{const s=u.createPropertyDef(t);return s.nodes=t.listChildren().map(t=>u.nodeIndexMap.get(t)),s}),o.extensionsUsed=e.listExtensionsUsed().map(t=>t.extensionName),o.extensionsRequired=e.listExtensionsRequired().map(t=>t.extensionName),e.listExtensionsUsed().forEach(t=>t.write(u)),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]}(o),r}}class ft{constructor(){this.Lt=T.DEFAULT_INSTANCE,this.gt=[],this.Ot={},this.Ut=h.INTERLEAVED}setLogger(t){return this.Lt=t,this}registerExtensions(t){for(const s of t)this.gt.push(s),s.register();return this}registerDependencies(t){return Object.assign(this.Ot,t),this}setVertexLayout(t){return this.Ut=t,this}readJSON(t){return ht.read(t,{extensions:this.gt,dependencies:this.Ot,logger:this.Lt})}writeJSON(t,s){if(s.isGLB&&1!==t.getRoot().listBuffers().length)throw new Error("GLB must have exactly 1 buffer.");return s.vertexLayout=this.Ut,s.dependencies=et({},this.Ot,s.dependencies),lt.write(t,s)}binaryToJSON(t){const s=this.Pt(t),e=s.json;if(e.buffers&&e.buffers.length>1)throw new Error("Cannot resolve external buffers with binaryToJSON().");if(e.images&&e.images.find(t=>void 0===t.bufferView))throw new Error("Cannot resolve external images with binaryToJSON().");return s}Pt(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=d.decodeText(t.slice(20,20+r)),h=20+r+8;return{json:JSON.parse(n),resources:{"@glb.bin":t.slice(h,h+i[0])}}}readBinary(t){return this.readJSON(this.binaryToJSON(t))}writeBinary(t){const{json:s,resources:e}=this.writeJSON(t,{basename:"",isGLB:!0,logger:this.Lt,dependencies:this.Ot,vertexLayout:this.Ut}),r=JSON.stringify(s),i=d.pad(d.encodeText(r),32),n=new Uint32Array([i.byteLength,1313821514]).buffer,h=d.concat([n,i]),o=d.pad(Object.values(e)[0]||new ArrayBuffer(0),0),u=new Uint32Array([o.byteLength,5130562]).buffer,c=d.concat([u,o]),a=new Uint32Array([1179937895,2,12+h.byteLength+c.byteLength]).buffer;return d.concat([a,h,c])}}class dt extends ft{constructor(){super(),this.lastReadBytes=0,this.lastWriteBytes=0,this.Ft=require("fs"),this.kt=require("path")}read(t){const s=this.readAsJSON(t);return ht.read(s,{extensions:this.gt,dependencies:this.Ot,logger:this.Lt})}readAsJSON(t){return t.match(/\.glb$/)||t.match(/^data:application\/octet-stream;/)?this.Gt(t):this.jt(t)}write(t,s){t.match(/\.glb$/)?this.Dt(t,s):this.Jt(t,s)}Gt(t){const s=this.Ft.readFileSync(t),e=d.trim(s);this.lastReadBytes=e.byteLength;const r=this.Pt(e);return this.zt(r,this.kt.dirname(t),!0),r}jt(t){this.lastReadBytes=0;const s=this.Ft.readFileSync(t,"utf8");this.lastReadBytes+=s.length;const e={json:JSON.parse(s),resources:{}};return this.zt(e,this.kt.dirname(t),!1),e}zt(t,s,e){const r=t.json.images||[],i=t.json.buffers||[];[...r,...i].forEach((i,n)=>{if(i.uri)if(i.uri.match(/data:/)){const s=`__${M()}.${g.extension(i.uri)}`;t.resources[s]=d.createBufferFromDataURI(i.uri),i.uri=s}else{const e=this.kt.resolve(s,i.uri);t.resources[i.uri]=d.trim(this.Ft.readFileSync(e)),this.lastReadBytes+=t.resources[i.uri].byteLength}else{const t=e&&n===r.length;if(void 0===i.bufferView&&!t)throw new Error("Missing resource URI.")}})}Jt(t,s){this.lastWriteBytes=0;const{json:e,resources:r}=lt.write(s,{basename:g.basename(t),isGLB:!1,logger:this.Lt,dependencies:this.Ot,vertexLayout:this.Ut}),{Ft:i,kt:n}=this,h=n.dirname(t),o=JSON.stringify(e,null,2);this.lastWriteBytes+=o.length,i.writeFileSync(t,o),Object.keys(r).forEach(t=>{const s=Buffer.from(r[t]);i.writeFileSync(n.join(h,t),s),this.lastWriteBytes+=s.byteLength})}Dt(t,s){const e=Buffer.from(this.writeBinary(s));this.Ft.writeFileSync(t,e),this.lastWriteBytes=e.byteLength}}const pt={};class gt extends ft{constructor(t=pt){super(),this.$t=t}read(t){return this.readAsJSON(t).then(t=>this.readJSON(t))}readAsJSON(t){return t.match(/^data:application\/octet-stream;/)||new URL(t,window.location.href).pathname.match(/\.glb$/)?this.Gt(t):this.jt(t)}jt(t){var s=this;const e={json:{},resources:{}};return fetch(t,this.$t).then(t=>t.json()).then(async function(r){return e.json=r,await s.zt(e,wt(t),!1),e})}Gt(t){var s=this;return fetch(t,this.$t).then(t=>t.arrayBuffer()).then(async function(e){const r=s.Pt(e);return await s.zt(r,wt(t),!0),r})}zt(t,s,e){const r=t.json,i=r.images||[],n=r.buffers||[],h=[...i,...n].map((r,n)=>{if(r.uri)return fetch(function(t,s){if(!function(t){return!/^(?:[a-zA-Z]+:)?\//.test(t)}(s))return s;const e=t.split("/"),r=s.split("/");e.pop();for(let t=0;t<r.length;t++)"."!==r[t]&&(".."===r[t]?e.pop():e.push(r[t]));return e.join("/")}(s,r.uri),this.$t).then(t=>t.arrayBuffer()).then(s=>{t.resources[r.uri]=s});{const t=e&&n===i.length;if(void 0===r.bufferView&&!t)throw new Error("Missing resource URI.")}});return Promise.all(h).then(()=>{})}}function wt(t){const s=t.lastIndexOf("/");return-1===s?"./":t.substr(0,s+1)}export{N as Accessor,C as Animation,_ as AnimationChannel,L as AnimationSampler,P as AttributeLink,B as Buffer,d as BufferUtils,S as COPY_IDENTITY,O as Camera,p as ColorUtils,tt as Document,st as Extension,U as ExtensionProperty,g as FileUtils,i as GLB_BUFFER,a as Graph,l as GraphChild,f as GraphChildList,m as ImageUtils,F as IndexLink,c as Link,T as Logger,V as Material,A as MathUtils,W as Mesh,Y as Node,dt as NodeIO,H as Primitive,q as PrimitiveTarget,b as Property,n as PropertyType,rt as ReaderContext,X as Root,Z as Scene,K as Skin,Q as Texture,o as TextureChannel,j as TextureInfo,k as TextureLink,h as VertexLayout,gt as WebIO,ut as WriterContext,M as uuid}; | ||
//# sourceMappingURL=core.modern.js.map |
{ | ||
"name": "@gltf-transform/core", | ||
"version": "0.10.1", | ||
"version": "0.11.0-alpha.0", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -42,3 +42,3 @@ "description": "glTF 2.0 SDK for JavaScript, TypeScript, and Node.js", | ||
}, | ||
"gitHead": "52687a745e0c71ba8bff90b9b6cda2dbe923f1f2" | ||
"gitHead": "bc8df906af19985151a1de5ee78281f96411e9fb" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1234529
10974