webgi-gltf-extensions
Version:
WEBGI GLTF Extensions for glTF-Transform and three.js
14 lines • 60.7 kB
JavaScript
/**
* @license
* webgi-gltf-extensions v0.1.0
* Copyright 2022-2023 repalash <palash@shaders.app>
* MIT License
*/
"use strict";let e=class{constructor(){this._listeners={}}addEventListener(e,t){const s=this._listeners;return void 0===s[e]&&(s[e]=[]),-1===s[e].indexOf(t)&&s[e].push(t),this}removeEventListener(e,t){if(void 0===this._listeners)return this;const s=this._listeners[e];if(void 0!==s){const e=s.indexOf(t);-1!==e&&s.splice(e,1)}return this}dispatchEvent(e){if(void 0===this._listeners)return this;const t=this._listeners[e.type];if(void 0!==t){const s=t.slice(0);for(let t=0,r=s.length;t<r;t++)s[t].call(this,e)}return this}dispose(){for(const e in this._listeners)delete this._listeners[e]}},t=class extends e{constructor(e,t,s,r={}){if(super(),this._name=void 0,this._parent=void 0,this._child=void 0,this._attributes=void 0,this._disposed=!1,this._name=e,this._parent=t,this._child=s,this._attributes=r,!t.isOnGraph(s))throw new Error("Cannot connect disconnected graphs.")}getName(){return this._name}getParent(){return this._parent}getChild(){return this._child}setChild(e){return this._child=e,this}getAttributes(){return this._attributes}dispose(){this._disposed||(this._disposed=!0,this.dispatchEvent({type:"dispose",target:this}),super.dispose())}isDisposed(){return this._disposed}};function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},s.apply(this,arguments)}function r(e){return e instanceof t}function i(e){return Array.isArray(e)&&e[0]instanceof t}function n(e){return!!(function(e){return Boolean(e)&&Object.getPrototypeOf(e)===Object.prototype}(e)&&function(e){for(const t in e)return e[t]}(e)instanceof t)}const o=Symbol("attributes"),a=Symbol("immutableKeys");let h=class t extends e{constructor(e){super(),this._disposed=!1,this.graph=void 0,this[o]=void 0,this[a]=void 0,this.graph=e,this[a]=new Set,this[o]=this._createAttributes()}getDefaults(){return{}}_createAttributes(){const e=this.getDefaults(),s={};for(const r in e){const i=e[r];if(i instanceof t){const e=this.graph.createEdge(r,this,i);e.addEventListener("dispose",(()=>i.dispose())),this[a].add(r),s[r]=e}else s[r]=i}return s}isOnGraph(e){return this.graph===e.graph}isDisposed(){return this._disposed}dispose(){this._disposed||(this.graph.listChildEdges(this).forEach((e=>e.dispose())),this.graph.disconnectParents(this),this._disposed=!0,this.dispatchEvent({type:"dispose"}))}detach(){return this.graph.disconnectParents(this),this}swap(e,t){for(const s in this[o]){const a=this[o][s];if(r(a)){const r=a;r.getChild()===e&&this.setRef(s,t,r.getAttributes())}else if(i(a)){const r=a.find((t=>t.getChild()===e));if(r){const i=r.getAttributes();this.removeRef(s,e).addRef(s,t,i)}}else if(n(a)){const r=a;for(const i in r){const n=r[i];n.getChild()===e&&this.setRefMap(s,i,t,n.getAttributes())}}}return this}get(e){return this[o][e]}set(e,t){return this[o][e]=t,this.dispatchEvent({type:"change",attribute:e})}getRef(e){const t=this[o][e];return t?t.getChild():null}setRef(e,t,s){if(this[a].has(e))throw new Error(`Cannot overwrite immutable attribute, "${e}".`);const r=this[o][e];if(r&&r.dispose(),!t)return this;const i=this.graph.createEdge(e,this,t,s);return i.addEventListener("dispose",(()=>{delete this[o][e],this.dispatchEvent({type:"change",attribute:e})})),this[o][e]=i,this.dispatchEvent({type:"change",attribute:e})}listRefs(e){return this[o][e].map((e=>e.getChild()))}addRef(e,t,s){const r=this.graph.createEdge(e,this,t,s),i=this[o][e];return i.push(r),r.addEventListener("dispose",(()=>{const t=i.filter((e=>e!==r));i.length=0;for(const e of t)i.push(e);this.dispatchEvent({type:"change",attribute:e})})),this.dispatchEvent({type:"change",attribute:e})}removeRef(e,t){return this[o][e].filter((e=>e.getChild()===t)).forEach((e=>e.dispose())),this}listRefMapKeys(e){return Object.keys(this[o][e])}listRefMapValues(e){return Object.values(this[o][e]).map((e=>e.getChild()))}getRefMap(e,t){const s=this[o][e];return s[t]?s[t].getChild():null}setRefMap(e,t,r,i){const n=this[o][e],a=n[t];if(a&&a.dispose(),!r)return this;i=Object.assign(i||{},{key:t});const h=this.graph.createEdge(e,this,r,s({},i,{key:t}));return h.addEventListener("dispose",(()=>{delete n[t],this.dispatchEvent({type:"change",attribute:e,key:t})})),n[t]=h,this.dispatchEvent({type:"change",attribute:e,key:t})}dispatchEvent(e){return super.dispatchEvent(s({},e,{target:this})),this.graph.dispatchEvent(s({},e,{target:this,type:`node:${e.type}`})),this}};var u,c,l,p,g,E;(E=u||(u={})).ACCESSOR="Accessor",E.ANIMATION="Animation",E.ANIMATION_CHANNEL="AnimationChannel",E.ANIMATION_SAMPLER="AnimationSampler",E.BUFFER="Buffer",E.CAMERA="Camera",E.MATERIAL="Material",E.MESH="Mesh",E.PRIMITIVE="Primitive",E.PRIMITIVE_TARGET="PrimitiveTarget",E.NODE="Node",E.ROOT="Root",E.SCENE="Scene",E.SKIN="Skin",E.TEXTURE="Texture",E.TEXTURE_INFO="TextureInfo",function(e){e.INTERLEAVED="interleaved",e.SEPARATE="separate"}(c||(c={})),function(e){e.ARRAY_BUFFER="ARRAY_BUFFER",e.ELEMENT_ARRAY_BUFFER="ELEMENT_ARRAY_BUFFER",e.INVERSE_BIND_MATRICES="INVERSE_BIND_MATRICES",e.OTHER="OTHER",e.SPARSE="SPARSE"}(l||(l={})),function(e){e[e.R=4096]="R",e[e.G=256]="G",e[e.B=16]="B",e[e.A=1]="A"}(p||(p={})),function(e){e.GLTF="GLTF",e.GLB="GLB"}(g||(g={}));var d,f="undefined"!=typeof Float32Array?Float32Array:Array;function T(e){return Math.hypot(e[0],e[1],e[2])}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),d=new f(3),f!=Float32Array&&(d[0]=0,d[1]=0,d[2]=0);let m=class{static hexToFactor(e,t){e=Math.floor(e);const s=t;return s[0]=(e>>16&255)/255,s[1]=(e>>8&255)/255,s[2]=(255&e)/255,this.convertSRGBToLinear(t,t)}static factorToHex(e){const t=[...e],[s,r,i]=this.convertLinearToSRGB(e,t);return 255*s<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(e,t){const s=e,r=t;for(let e=0;e<3;e++)r[e]=s[e]<.04045?.0773993808*s[e]:Math.pow(.9478672986*s[e]+.0521327014,2.4);return t}static convertLinearToSRGB(e,t){const s=e,r=t;for(let e=0;e<3;e++)r[e]=s[e]<.0031308?12.92*s[e]:1.055*Math.pow(s[e],.41666)-.055;return t}};function x(e){return"[object Object]"===Object.prototype.toString.call(e)}function R(e){if(!1===x(e))return!1;const t=e.constructor;if(void 0===t)return!0;const s=t.prototype;return!1!==x(s)&&!1!==Object.prototype.hasOwnProperty.call(s,"isPrototypeOf")}var N;!function(e){e[e.SILENT=4]="SILENT",e[e.ERROR=3]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=1]="INFO",e[e.DEBUG=0]="DEBUG"}(N||(N={}));let y=class e{constructor(e){this.verbosity=void 0,this.verbosity=e}debug(t){this.verbosity<=e.Verbosity.DEBUG&&console.debug(t)}info(t){this.verbosity<=e.Verbosity.INFO&&console.info(t)}warn(t){this.verbosity<=e.Verbosity.WARN&&console.warn(t)}error(t){this.verbosity<=e.Verbosity.ERROR&&console.error(t)}};y.Verbosity=N,y.DEFAULT_INSTANCE=new y(y.Verbosity.INFO);let A=class e{static identity(e){return e}static eq(e,t,s=1e-5){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(Math.abs(e[r]-t[r])>s)return!1;return!0}static decodeNormalizedInt(e,t){switch(t){case 5126:return e;case 5123:return e/65535;case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5120:return Math.max(e/127,-1);default:throw new Error("Invalid component type.")}}static denormalize(t,s){return e.decodeNormalizedInt(t,s)}static encodeNormalizedInt(e,t){switch(t){case 5126:return e;case 5123:return Math.round(65535*e);case 5121:return Math.round(255*e);case 5122:return Math.round(32767*e);case 5120:return Math.round(127*e);default:throw new Error("Invalid component type.")}}static normalize(t,s){return e.encodeNormalizedInt(t,s)}static decompose(e,t,s,r){let i=T([e[0],e[1],e[2]]);const n=T([e[4],e[5],e[6]]),o=T([e[8],e[9],e[10]]);var a,h,u,c,l,p,g,E,d,m,x,R,N,y,A,M,I;((h=(a=e)[0])*(g=a[5])-(u=a[1])*(p=a[4]))*((R=a[10])*(I=a[15])-(N=a[11])*(M=a[14]))-(h*(E=a[6])-(c=a[2])*p)*((x=a[9])*I-N*(A=a[13]))+(h*(d=a[7])-(l=a[3])*p)*(x*M-R*A)+(u*E-c*g)*((m=a[8])*I-N*(y=a[12]))-(u*d-l*g)*(m*M-R*y)+(c*d-l*E)*(m*A-x*y)<0&&(i=-i),t[0]=e[12],t[1]=e[13],t[2]=e[14];const S=e.slice(),_=1/i,C=1/n,b=1/o;S[0]*=_,S[1]*=_,S[2]*=_,S[4]*=C,S[5]*=C,S[6]*=C,S[8]*=b,S[9]*=b,S[10]*=b,function(e,t){var s=new f(3);!function(e,t){var s=t[4],r=t[5],i=t[6],n=t[8],o=t[9],a=t[10];e[0]=Math.hypot(t[0],t[1],t[2]),e[1]=Math.hypot(s,r,i),e[2]=Math.hypot(n,o,a)}(s,t);var r=1/s[0],i=1/s[1],n=1/s[2],o=t[0]*r,a=t[1]*i,h=t[2]*n,u=t[4]*r,c=t[5]*i,l=t[6]*n,p=t[8]*r,g=t[9]*i,E=t[10]*n,d=o+c+E,T=0;d>0?(T=2*Math.sqrt(d+1),e[3]=.25*T,e[0]=(l-g)/T,e[1]=(p-h)/T,e[2]=(a-u)/T):o>c&&o>E?(T=2*Math.sqrt(1+o-c-E),e[3]=(l-g)/T,e[0]=.25*T,e[1]=(a+u)/T,e[2]=(p+h)/T):c>E?(T=2*Math.sqrt(1+c-o-E),e[3]=(p-h)/T,e[0]=(a+u)/T,e[1]=.25*T,e[2]=(l+g)/T):(T=2*Math.sqrt(1+E-o-c),e[3]=(a-u)/T,e[0]=(p+h)/T,e[1]=(l+g)/T,e[2]=.25*T)}(s,S),r[0]=i,r[1]=n,r[2]=o}static compose(e,t,s,r){const i=r,n=t[0],o=t[1],a=t[2],h=t[3],u=n+n,c=o+o,l=a+a,p=n*u,g=n*c,E=n*l,d=o*c,f=o*l,T=a*l,m=h*u,x=h*c,R=h*l,N=s[0],y=s[1],A=s[2];return i[0]=(1-(d+T))*N,i[1]=(g+R)*N,i[2]=(E-x)*N,i[3]=0,i[4]=(g-R)*y,i[5]=(1-(p+T))*y,i[6]=(f+m)*y,i[7]=0,i[8]=(E+x)*A,i[9]=(f-m)*A,i[10]=(1-(p+d))*A,i[11]=0,i[12]=e[0],i[13]=e[1],i[14]=e[2],i[15]=1,i}};function M(e,t){if(!!e!=!!t)return!1;const s=e.getChild(),r=t.getChild();return s===r||s.equals(r)}function I(e,t){if(!!e!=!!t)return!1;if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++){const r=e[s],i=t[s];if(r.getChild()!==i.getChild()&&!r.getChild().equals(i.getChild()))return!1}return!0}function S(e,t){if(!!e!=!!t)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const s in e){const r=e[s],i=t[s];if(!!r!=!!i)return!1;const n=r.getChild(),o=i.getChild();if(n!==o&&!n.equals(o))return!1}return!0}function _(e,t){if(e===t)return!0;if(!!e!=!!t||!e||!t)return!1;if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}function C(e,t){if(e===t)return!0;if(!!e!=!!t)return!1;if(!R(e)||!R(t))return e===t;const s=e,r=t;let i,n=0,o=0;for(i in s)n++;for(i in r)o++;if(n!==o)return!1;for(i in s){const e=s[i],t=r[i];if(b(e)&&b(t)){if(!_(e,t))return!1}else if(R(e)&&R(t)){if(!C(e,t))return!1}else if(e!==t)return!1}return!0}function b(e){return Array.isArray(e)||ArrayBuffer.isView(e)}const v=e=>e,O=new Set;let F=class extends h{constructor(e,t=""){super(e),this[o].name=t,this.init(),this.dispatchEvent({type:"create"})}getGraph(){return this.graph}getDefaults(){return Object.assign(super.getDefaults(),{name:"",extras:{}})}set(e,t){return Array.isArray(t)&&(t=t.slice()),super.set(e,t)}getName(){return this.get("name")}setName(e){return this.set("name",e)}getExtras(){return this.get("extras")}setExtras(e){return this.set("extras",e)}clone(){return new this.constructor(this.graph).copy(this,v)}copy(e,s=v){for(const e in this[o]){const s=this[o][e];if(s instanceof t)this[a].has(e)||s.dispose();else if(i(s))for(const e of s)e.dispose();else if(n(s))for(const e in s)s[e].dispose()}for(const r in e[o]){const h=this[o][r],u=e[o][r];if(u instanceof t)this[a].has(r)?h.getChild().copy(s(u.getChild()),s):this.setRef(r,s(u.getChild()),u.getAttributes());else if(i(u))for(const e of u)this.addRef(r,s(e.getChild()),e.getAttributes());else if(n(u))for(const e in u){const t=u[e];this.setRefMap(r,e,s(t.getChild()),t.getAttributes())}else this[o][r]=R(u)?JSON.parse(JSON.stringify(u)):Array.isArray(u)||u instanceof ArrayBuffer||ArrayBuffer.isView(u)?u.slice():u}return this}equals(e,t=O){if(this===e)return!0;if(this.propertyType!==e.propertyType)return!1;for(const s in this[o]){if(t.has(s))continue;const a=this[o][s],h=e[o][s];if(r(a)||r(h)){if(!M(a,h))return!1}else if(i(a)||i(h)){if(!I(a,h))return!1}else if(n(a)||n(h)){if(!S(a,h))return!1}else if(R(a)||R(h)){if(!C(a,h))return!1}else if(b(a)||b(h)){if(!_(a,h))return!1}else if(a!==h)return!1}return!0}detach(){return this.graph.disconnectParents(this,(e=>"Root"!==e.propertyType)),this}listParents(){return this.graph.listParents(this)}},L=class extends F{getDefaults(){return Object.assign(super.getDefaults(),{extensions:{}})}getExtension(e){return this.getRefMap("extensions",e)}setExtension(e,t){return t&&t.t(this),this.setRefMap("extensions",e,t)}listExtensions(){return this.listRefMapValues("extensions")}},B=class e extends L{constructor(...e){super(...e),this.i=A.identity,this.o=A.identity}init(){this.propertyType=u.ACCESSOR}getDefaults(){return Object.assign(super.getDefaults(),{array:null,type:e.Type.SCALAR,componentType:e.ComponentType.FLOAT,normalized:!1,sparse:!1,buffer:null})}copy(e,t=v){return super.copy(e,t),this.i=e.i,this.o=e.o,this}static getElementSize(t){switch(t){case e.Type.SCALAR:return 1;case e.Type.VEC2:return 2;case e.Type.VEC3:return 3;case e.Type.VEC4:case e.Type.MAT2:return 4;case e.Type.MAT3:return 9;case e.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+t)}}static getComponentSize(t){switch(t){case e.ComponentType.BYTE:case e.ComponentType.UNSIGNED_BYTE:return 1;case e.ComponentType.SHORT:case e.ComponentType.UNSIGNED_SHORT:return 2;case e.ComponentType.UNSIGNED_INT:case e.ComponentType.FLOAT:return 4;default:throw new Error("Unexpected component type: "+t)}}getMinNormalized(e){const t=this.getElementSize();this.getMin(e);for(let s=0;s<t;s++)e[s]=this.o(e[s]);return e}getMin(e){const t=this.get("array"),s=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=1/0;for(let i=0;i<s*r;i+=r)for(let s=0;s<r;s++){const r=t[i+s];Number.isFinite(r)&&(e[s]=Math.min(e[s],r))}return e}getMaxNormalized(e){const t=this.getElementSize();this.getMax(e);for(let s=0;s<t;s++)e[s]=this.o(e[s]);return e}getMax(e){const t=this.get("array"),s=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=-1/0;for(let i=0;i<s*r;i+=r)for(let s=0;s<r;s++){const r=t[i+s];Number.isFinite(r)&&(e[s]=Math.max(e[s],r))}return e}getCount(){const e=this.get("array");return e?e.length/this.getElementSize():0}getType(){return this.get("type")}setType(e){return this.set("type",e)}getElementSize(){return e.getElementSize(this.get("type"))}getComponentSize(){return this.get("array").BYTES_PER_ELEMENT}getComponentType(){return this.get("componentType")}getNormalized(){return this.get("normalized")}setNormalized(e){return this.set("normalized",e),e?(this.o=e=>A.decodeNormalizedInt(e,this.get("componentType")),this.i=e=>A.encodeNormalizedInt(e,this.get("componentType"))):(this.o=A.identity,this.i=A.identity),this}getScalar(e){const t=this.getElementSize();return this.o(this.get("array")[e*t])}setScalar(e,t){return this.get("array")[e*this.getElementSize()]=this.i(t),this}getElement(e,t){const s=this.getElementSize(),r=this.get("array");for(let i=0;i<s;i++)t[i]=this.o(r[e*s+i]);return t}setElement(e,t){const s=this.getElementSize(),r=this.get("array");for(let i=0;i<s;i++)r[e*s+i]=this.i(t[i]);return this}getSparse(){return this.get("sparse")}setSparse(e){return this.set("sparse",e)}getBuffer(){return this.getRef("buffer")}setBuffer(e){return this.setRef("buffer",e)}getArray(){return this.get("array")}setArray(t){return this.set("componentType",t?function(t){switch(t.constructor){case Float32Array:return e.ComponentType.FLOAT;case Uint32Array:return e.ComponentType.UNSIGNED_INT;case Uint16Array:return e.ComponentType.UNSIGNED_SHORT;case Uint8Array:return e.ComponentType.UNSIGNED_BYTE;case Int16Array:return e.ComponentType.SHORT;case Int8Array:return e.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}(t):e.ComponentType.FLOAT),this.set("array",t),this}getByteLength(){const e=this.get("array");return e?e.byteLength:0}};B.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"},B.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126};(class extends L{init(){this.propertyType=u.ANIMATION_CHANNEL}getDefaults(){return Object.assign(super.getDefaults(),{targetPath:null,targetNode:null,sampler:null})}getTargetPath(){return this.get("targetPath")}setTargetPath(e){return this.set("targetPath",e)}getTargetNode(){return this.getRef("targetNode")}setTargetNode(e){return this.setRef("targetNode",e)}getSampler(){return this.getRef("sampler")}setSampler(e){return this.setRef("sampler",e)}}).TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"};(class e extends L{init(){this.propertyType=u.ANIMATION_SAMPLER}getDefaultAttributes(){return Object.assign(super.getDefaults(),{interpolation:e.Interpolation.LINEAR,input:null,output:null})}getInterpolation(){return this.get("interpolation")}setInterpolation(e){return this.set("interpolation",e)}getInput(){return this.getRef("input")}setInput(e){return this.setRef("input",e,{usage:l.OTHER})}getOutput(){return this.getRef("output")}setOutput(e){return this.setRef("output",e,{usage:l.OTHER})}}).Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"};(class e extends L{init(){this.propertyType=u.CAMERA}getDefaults(){return Object.assign(super.getDefaults(),{type:e.Type.PERSPECTIVE,znear:.1,zfar:100,aspectRatio:null,yfov:2*Math.PI*50/360,xmag:1,ymag:1})}getType(){return this.get("type")}setType(e){return this.set("type",e)}getZNear(){return this.get("znear")}setZNear(e){return this.set("znear",e)}getZFar(){return this.get("zfar")}setZFar(e){return this.set("zfar",e)}getAspectRatio(){return this.get("aspectRatio")}setAspectRatio(e){return this.set("aspectRatio",e)}getYFov(){return this.get("yfov")}setYFov(e){return this.set("yfov",e)}getXMag(){return this.get("xmag")}setXMag(e){return this.set("xmag",e)}getYMag(){return this.get("ymag")}setYMag(e){return this.set("ymag",e)}}).Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};let w=class extends F{t(e){if(!this.parentTypes.includes(e.propertyType))throw new Error(`Parent "${e.propertyType}" invalid for child "${this.propertyType}".`)}};w.EXTENSION_NAME=void 0;let G=class e extends L{init(){this.propertyType=u.TEXTURE_INFO}getDefaults(){return Object.assign(super.getDefaults(),{texCoord:0,magFilter:null,minFilter:null,wrapS:e.WrapMode.REPEAT,wrapT:e.WrapMode.REPEAT})}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}getMagFilter(){return this.get("magFilter")}setMagFilter(e){return this.set("magFilter",e)}getMinFilter(){return this.get("minFilter")}setMinFilter(e){return this.set("minFilter",e)}getWrapS(){return this.get("wrapS")}setWrapS(e){return this.set("wrapS",e)}getWrapT(){return this.get("wrapT")}setWrapT(e){return this.set("wrapT",e)}};G.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},G.MagFilter={NEAREST:9728,LINEAR:9729},G.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};const{R:P,G:D,B:U,A:j}=p;(class e extends L{init(){this.propertyType=u.MATERIAL}getDefaults(){return Object.assign(super.getDefaults(),{alphaMode:e.AlphaMode.OPAQUE,alphaCutoff:.5,doubleSided:!1,baseColorFactor:[1,1,1,1],baseColorTexture:null,baseColorTextureInfo:new G(this.graph,"baseColorTextureInfo"),emissiveFactor:[0,0,0],emissiveTexture:null,emissiveTextureInfo:new G(this.graph,"emissiveTextureInfo"),normalScale:1,normalTexture:null,normalTextureInfo:new G(this.graph,"normalTextureInfo"),occlusionStrength:1,occlusionTexture:null,occlusionTextureInfo:new G(this.graph,"occlusionTextureInfo"),roughnessFactor:1,metallicFactor:1,metallicRoughnessTexture:null,metallicRoughnessTextureInfo:new G(this.graph,"metallicRoughnessTextureInfo")})}getDoubleSided(){return this.get("doubleSided")}setDoubleSided(e){return this.set("doubleSided",e)}getAlpha(){return this.get("baseColorFactor")[3]}setAlpha(e){const t=this.get("baseColorFactor").slice();return t[3]=e,this.set("baseColorFactor",t)}getAlphaMode(){return this.get("alphaMode")}setAlphaMode(e){return this.set("alphaMode",e)}getAlphaCutoff(){return this.get("alphaCutoff")}setAlphaCutoff(e){return this.set("alphaCutoff",e)}getBaseColorFactor(){return this.get("baseColorFactor")}setBaseColorFactor(e){return this.set("baseColorFactor",e)}getBaseColorHex(){return m.factorToHex(this.get("baseColorFactor"))}setBaseColorHex(e){const t=this.get("baseColorFactor").slice();return this.set("baseColorFactor",m.hexToFactor(e,t))}getBaseColorTexture(){return this.getRef("baseColorTexture")}getBaseColorTextureInfo(){return this.getRef("baseColorTexture")?this.getRef("baseColorTextureInfo"):null}setBaseColorTexture(e){return this.setRef("baseColorTexture",e,{channels:P|D|U|j,isColor:!0})}getEmissiveFactor(){return this.get("emissiveFactor")}setEmissiveFactor(e){return this.set("emissiveFactor",e)}getEmissiveHex(){return m.factorToHex(this.get("emissiveFactor"))}setEmissiveHex(e){const t=this.get("emissiveFactor").slice();return this.set("emissiveFactor",m.hexToFactor(e,t))}getEmissiveTexture(){return this.getRef("emissiveTexture")}getEmissiveTextureInfo(){return this.getRef("emissiveTexture")?this.getRef("emissiveTextureInfo"):null}setEmissiveTexture(e){return this.setRef("emissiveTexture",e,{channels:P|D|U,isColor:!0})}getNormalScale(){return this.get("normalScale")}setNormalScale(e){return this.set("normalScale",e)}getNormalTexture(){return this.getRef("normalTexture")}getNormalTextureInfo(){return this.getRef("normalTexture")?this.getRef("normalTextureInfo"):null}setNormalTexture(e){return this.setRef("normalTexture",e,{channels:P|D|U})}getOcclusionStrength(){return this.get("occlusionStrength")}setOcclusionStrength(e){return this.set("occlusionStrength",e)}getOcclusionTexture(){return this.getRef("occlusionTexture")}getOcclusionTextureInfo(){return this.getRef("occlusionTexture")?this.getRef("occlusionTextureInfo"):null}setOcclusionTexture(e){return this.setRef("occlusionTexture",e,{channels:P})}getRoughnessFactor(){return this.get("roughnessFactor")}setRoughnessFactor(e){return this.set("roughnessFactor",e)}getMetallicFactor(){return this.get("metallicFactor")}setMetallicFactor(e){return this.set("metallicFactor",e)}getMetallicRoughnessTexture(){return this.getRef("metallicRoughnessTexture")}getMetallicRoughnessTextureInfo(){return this.getRef("metallicRoughnessTexture")?this.getRef("metallicRoughnessTextureInfo"):null}setMetallicRoughnessTexture(e){return this.setRef("metallicRoughnessTexture",e,{channels:D|U})}}).AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};(class e extends L{init(){this.propertyType=u.PRIMITIVE}getDefaults(){return Object.assign(super.getDefaults(),{mode:e.Mode.TRIANGLES,material:null,indices:null,attributes:{},targets:[]})}getIndices(){return this.getRef("indices")}setIndices(e){return this.setRef("indices",e,{usage:l.ELEMENT_ARRAY_BUFFER})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:l.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}getMode(){return this.get("mode")}setMode(e){return this.set("mode",e)}listTargets(){return this.listRefs("targets")}addTarget(e){return this.addRef("targets",e)}removeTarget(e){return this.removeRef("targets",e)}}).Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6};let W=class{constructor(e){this.extensionName="",this.prereadTypes=[],this.prewriteTypes=[],this.readDependencies=[],this.writeDependencies=[],this.document=void 0,this.required=!1,this.properties=new Set,this.S=void 0,this.document=e,e.getRoot().g(this),this.S=e=>{const t=e,s=t.target;s instanceof w&&s.extensionName===this.extensionName&&("node:create"===t.type&&this.I(s),"node:dispose"===t.type&&this.N(s))};const t=e.getGraph();t.addEventListener("node:create",this.S),t.addEventListener("node:dispose",this.S)}dispose(){this.document.getRoot().p(this);const e=this.document.getGraph();e.removeEventListener("node:create",this.S),e.removeEventListener("node:dispose",this.S);for(const e of this.properties)e.dispose()}static register(){}isRequired(){return this.required}setRequired(e){return this.required=e,this}listProperties(){return Array.from(this.properties)}I(e){return this.properties.add(e),this}N(e){return this.properties.delete(e),this}install(e,t){return this}preread(e,t){return this}prewrite(e,t){return this}};var z,V;W.EXTENSION_NAME=void 0,function(e){e[e.ARRAY_BUFFER=34962]="ARRAY_BUFFER",e[e.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER"}(z||(z={})),l.ARRAY_BUFFER,z.ARRAY_BUFFER,l.ELEMENT_ARRAY_BUFFER,z.ELEMENT_ARRAY_BUFFER,B.ComponentType,function(e){e[e.JSON=1313821514]="JSON",e[e.BIN=5130562]="BIN"}(V||(V={}));const Y="WEBGI_viewer";class X extends w{constructor(){super(...arguments),this.extensionName=Y,this.parentTypes=[u.SCENE],this.propertyType="ViewerJSON"}init(){}}class H extends W{constructor(){super(...arguments),this.extensionName=Y,this._viewerConfig={},this._texturesRef=[],this.required=!0}read(e){return this._viewerConfig={},e.jsonDoc.json.scenes?.forEach(((t,s)=>{if(t.extensions&&t.extensions[Y]){const r=new X(this.document.getGraph());e.scenes[s].setExtension(Y,r),this._viewerConfig=t.extensions[Y]}})),this}write(e){return this.document.getRoot().listScenes().forEach((t=>{if(t.getExtension(Y)){const t=e.jsonDoc.json.scenes?.[e.jsonDoc.json.scene||0];t&&Object.keys(this._viewerConfig).length>0&&(t.extensions=t.extensions||{},t.extensions[Y]=this._viewerConfig,this._texturesRef=[],this._viewerConfig={})}})),this}}H.EXTENSION_NAME=Y;
/**
* @license
* gltf-transform-generic-ext v0.1.0
* Copyright 2022-2023 repalash <palash@shaders.app>
* MIT License
*/
class q{constructor(){this._listeners={}}addEventListener(e,t){const s=this._listeners;return void 0===s[e]&&(s[e]=[]),-1===s[e].indexOf(t)&&s[e].push(t),this}removeEventListener(e,t){if(void 0===this._listeners)return this;const s=this._listeners[e];if(void 0!==s){const e=s.indexOf(t);-1!==e&&s.splice(e,1)}return this}dispatchEvent(e){if(void 0===this._listeners)return this;const t=this._listeners[e.type];if(void 0!==t){const s=t.slice(0);for(let t=0,r=s.length;t<r;t++)s[t].call(this,e)}return this}dispose(){for(const e in this._listeners)delete this._listeners[e]}}class k extends q{constructor(e,t,s,r={}){if(super(),this._name=void 0,this._parent=void 0,this._child=void 0,this._attributes=void 0,this._disposed=!1,this._name=e,this._parent=t,this._child=s,this._attributes=r,!t.isOnGraph(s))throw new Error("Cannot connect disconnected graphs.")}getName(){return this._name}getParent(){return this._parent}getChild(){return this._child}setChild(e){return this._child=e,this}getAttributes(){return this._attributes}dispose(){this._disposed||(this._disposed=!0,this.dispatchEvent({type:"dispose",target:this}),super.dispose())}isDisposed(){return this._disposed}}function K(){return K=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},K.apply(this,arguments)}function J(e){return e instanceof k}function Z(e){return Array.isArray(e)&&e[0]instanceof k}function $(e){return!!(function(e){return Boolean(e)&&Object.getPrototypeOf(e)===Object.prototype}(e)&&function(e){for(const t in e)return e[t]}(e)instanceof k)}const Q=Symbol("attributes"),ee=Symbol("immutableKeys");class te extends q{constructor(e){super(),this._disposed=!1,this.graph=void 0,this[Q]=void 0,this[ee]=void 0,this.graph=e,this[ee]=new Set,this[Q]=this._createAttributes()}getDefaults(){return{}}_createAttributes(){const e=this.getDefaults(),t={};for(const s in e){const r=e[s];if(r instanceof te){const e=this.graph.createEdge(s,this,r);e.addEventListener("dispose",(()=>r.dispose())),this[ee].add(s),t[s]=e}else t[s]=r}return t}isOnGraph(e){return this.graph===e.graph}isDisposed(){return this._disposed}dispose(){this._disposed||(this.graph.listChildEdges(this).forEach((e=>e.dispose())),this.graph.disconnectParents(this),this._disposed=!0,this.dispatchEvent({type:"dispose"}))}detach(){return this.graph.disconnectParents(this),this}swap(e,t){for(const s in this[Q]){const r=this[Q][s];if(J(r)){const i=r;i.getChild()===e&&this.setRef(s,t,i.getAttributes())}else if(Z(r)){const i=r.find((t=>t.getChild()===e));if(i){const r=i.getAttributes();this.removeRef(s,e).addRef(s,t,r)}}else if($(r)){const i=r;for(const r in i){const n=i[r];n.getChild()===e&&this.setRefMap(s,r,t,n.getAttributes())}}}return this}get(e){return this[Q][e]}set(e,t){return this[Q][e]=t,this.dispatchEvent({type:"change",attribute:e})}getRef(e){const t=this[Q][e];return t?t.getChild():null}setRef(e,t,s){if(this[ee].has(e))throw new Error(`Cannot overwrite immutable attribute, "${e}".`);const r=this[Q][e];if(r&&r.dispose(),!t)return this;const i=this.graph.createEdge(e,this,t,s);return i.addEventListener("dispose",(()=>{delete this[Q][e],this.dispatchEvent({type:"change",attribute:e})})),this[Q][e]=i,this.dispatchEvent({type:"change",attribute:e})}listRefs(e){return this[Q][e].map((e=>e.getChild()))}addRef(e,t,s){const r=this.graph.createEdge(e,this,t,s),i=this[Q][e];return i.push(r),r.addEventListener("dispose",(()=>{const t=i.filter((e=>e!==r));i.length=0;for(const e of t)i.push(e);this.dispatchEvent({type:"change",attribute:e})})),this.dispatchEvent({type:"change",attribute:e})}removeRef(e,t){return this[Q][e].filter((e=>e.getChild()===t)).forEach((e=>e.dispose())),this}listRefMapKeys(e){return Object.keys(this[Q][e])}listRefMapValues(e){return Object.values(this[Q][e]).map((e=>e.getChild()))}getRefMap(e,t){const s=this[Q][e];return s[t]?s[t].getChild():null}setRefMap(e,t,s,r){const i=this[Q][e],n=i[t];if(n&&n.dispose(),!s)return this;r=Object.assign(r||{},{key:t});const o=this.graph.createEdge(e,this,s,K({},r,{key:t}));return o.addEventListener("dispose",(()=>{delete i[t],this.dispatchEvent({type:"change",attribute:e,key:t})})),i[t]=o,this.dispatchEvent({type:"change",attribute:e,key:t})}dispatchEvent(e){return super.dispatchEvent(K({},e,{target:this})),this.graph.dispatchEvent(K({},e,{target:this,type:`node:${e.type}`})),this}}var se,re,ie,ne,oe;!function(e){e.ACCESSOR="Accessor",e.ANIMATION="Animation",e.ANIMATION_CHANNEL="AnimationChannel",e.ANIMATION_SAMPLER="AnimationSampler",e.BUFFER="Buffer",e.CAMERA="Camera",e.MATERIAL="Material",e.MESH="Mesh",e.PRIMITIVE="Primitive",e.PRIMITIVE_TARGET="PrimitiveTarget",e.NODE="Node",e.ROOT="Root",e.SCENE="Scene",e.SKIN="Skin",e.TEXTURE="Texture",e.TEXTURE_INFO="TextureInfo"}(se||(se={})),function(e){e.INTERLEAVED="interleaved",e.SEPARATE="separate"}(re||(re={})),function(e){e.ARRAY_BUFFER="ARRAY_BUFFER",e.ELEMENT_ARRAY_BUFFER="ELEMENT_ARRAY_BUFFER",e.INVERSE_BIND_MATRICES="INVERSE_BIND_MATRICES",e.OTHER="OTHER",e.SPARSE="SPARSE"}(ie||(ie={})),function(e){e[e.R=4096]="R",e[e.G=256]="G",e[e.B=16]="B",e[e.A=1]="A"}(ne||(ne={})),function(e){e.GLTF="GLTF",e.GLB="GLB"}(oe||(oe={}));var ae,he,ue="undefined"!=typeof Float32Array?Float32Array:Array;function ce(e){return Math.hypot(e[0],e[1],e[2])}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),ae=new ue(3),ue!=Float32Array&&(ae[0]=0,ae[1]=0,ae[2]=0);class le{static hexToFactor(e,t){e=Math.floor(e);const s=t;return s[0]=(e>>16&255)/255,s[1]=(e>>8&255)/255,s[2]=(255&e)/255,this.convertSRGBToLinear(t,t)}static factorToHex(e){const t=[...e],[s,r,i]=this.convertLinearToSRGB(e,t);return 255*s<<16^255*r<<8^255*i<<0}static convertSRGBToLinear(e,t){const s=e,r=t;for(let e=0;e<3;e++)r[e]=s[e]<.04045?.0773993808*s[e]:Math.pow(.9478672986*s[e]+.0521327014,2.4);return t}static convertLinearToSRGB(e,t){const s=e,r=t;for(let e=0;e<3;e++)r[e]=s[e]<.0031308?12.92*s[e]:1.055*Math.pow(s[e],.41666)-.055;return t}}function pe(e){return"[object Object]"===Object.prototype.toString.call(e)}function ge(e){if(!1===pe(e))return!1;const t=e.constructor;if(void 0===t)return!0;const s=t.prototype;return!1!==pe(s)&&!1!==Object.prototype.hasOwnProperty.call(s,"isPrototypeOf")}!function(e){e[e.SILENT=4]="SILENT",e[e.ERROR=3]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=1]="INFO",e[e.DEBUG=0]="DEBUG"}(he||(he={}));class Ee{constructor(e){this.verbosity=void 0,this.verbosity=e}debug(e){this.verbosity<=Ee.Verbosity.DEBUG&&console.debug(e)}info(e){this.verbosity<=Ee.Verbosity.INFO&&console.info(e)}warn(e){this.verbosity<=Ee.Verbosity.WARN&&console.warn(e)}error(e){this.verbosity<=Ee.Verbosity.ERROR&&console.error(e)}}Ee.Verbosity=he,Ee.DEFAULT_INSTANCE=new Ee(Ee.Verbosity.INFO);class de{static identity(e){return e}static eq(e,t,s=1e-5){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(Math.abs(e[r]-t[r])>s)return!1;return!0}static decodeNormalizedInt(e,t){switch(t){case 5126:return e;case 5123:return e/65535;case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5120:return Math.max(e/127,-1);default:throw new Error("Invalid component type.")}}static denormalize(e,t){return de.decodeNormalizedInt(e,t)}static encodeNormalizedInt(e,t){switch(t){case 5126:return e;case 5123:return Math.round(65535*e);case 5121:return Math.round(255*e);case 5122:return Math.round(32767*e);case 5120:return Math.round(127*e);default:throw new Error("Invalid component type.")}}static normalize(e,t){return de.encodeNormalizedInt(e,t)}static decompose(e,t,s,r){let i=ce([e[0],e[1],e[2]]);const n=ce([e[4],e[5],e[6]]),o=ce([e[8],e[9],e[10]]);var a,h,u,c,l,p,g,E,d,f,T,m,x,R,N,y,A;((h=(a=e)[0])*(g=a[5])-(u=a[1])*(p=a[4]))*((m=a[10])*(A=a[15])-(x=a[11])*(y=a[14]))-(h*(E=a[6])-(c=a[2])*p)*((T=a[9])*A-x*(N=a[13]))+(h*(d=a[7])-(l=a[3])*p)*(T*y-m*N)+(u*E-c*g)*((f=a[8])*A-x*(R=a[12]))-(u*d-l*g)*(f*y-m*R)+(c*d-l*E)*(f*N-T*R)<0&&(i=-i),t[0]=e[12],t[1]=e[13],t[2]=e[14];const M=e.slice(),I=1/i,S=1/n,_=1/o;M[0]*=I,M[1]*=I,M[2]*=I,M[4]*=S,M[5]*=S,M[6]*=S,M[8]*=_,M[9]*=_,M[10]*=_,function(e,t){var s=new ue(3);!function(e,t){var s=t[4],r=t[5],i=t[6],n=t[8],o=t[9],a=t[10];e[0]=Math.hypot(t[0],t[1],t[2]),e[1]=Math.hypot(s,r,i),e[2]=Math.hypot(n,o,a)}(s,t);var r=1/s[0],i=1/s[1],n=1/s[2],o=t[0]*r,a=t[1]*i,h=t[2]*n,u=t[4]*r,c=t[5]*i,l=t[6]*n,p=t[8]*r,g=t[9]*i,E=t[10]*n,d=o+c+E,f=0;d>0?(f=2*Math.sqrt(d+1),e[3]=.25*f,e[0]=(l-g)/f,e[1]=(p-h)/f,e[2]=(a-u)/f):o>c&&o>E?(f=2*Math.sqrt(1+o-c-E),e[3]=(l-g)/f,e[0]=.25*f,e[1]=(a+u)/f,e[2]=(p+h)/f):c>E?(f=2*Math.sqrt(1+c-o-E),e[3]=(p-h)/f,e[0]=(a+u)/f,e[1]=.25*f,e[2]=(l+g)/f):(f=2*Math.sqrt(1+E-o-c),e[3]=(a-u)/f,e[0]=(p+h)/f,e[1]=(l+g)/f,e[2]=.25*f)}(s,M),r[0]=i,r[1]=n,r[2]=o}static compose(e,t,s,r){const i=r,n=t[0],o=t[1],a=t[2],h=t[3],u=n+n,c=o+o,l=a+a,p=n*u,g=n*c,E=n*l,d=o*c,f=o*l,T=a*l,m=h*u,x=h*c,R=h*l,N=s[0],y=s[1],A=s[2];return i[0]=(1-(d+T))*N,i[1]=(g+R)*N,i[2]=(E-x)*N,i[3]=0,i[4]=(g-R)*y,i[5]=(1-(p+T))*y,i[6]=(f+m)*y,i[7]=0,i[8]=(E+x)*A,i[9]=(f-m)*A,i[10]=(1-(p+d))*A,i[11]=0,i[12]=e[0],i[13]=e[1],i[14]=e[2],i[15]=1,i}}function fe(e,t){if(!!e!=!!t)return!1;const s=e.getChild(),r=t.getChild();return s===r||s.equals(r)}function Te(e,t){if(!!e!=!!t)return!1;if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++){const r=e[s],i=t[s];if(r.getChild()!==i.getChild()&&!r.getChild().equals(i.getChild()))return!1}return!0}function me(e,t){if(!!e!=!!t)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const s in e){const r=e[s],i=t[s];if(!!r!=!!i)return!1;const n=r.getChild(),o=i.getChild();if(n!==o&&!n.equals(o))return!1}return!0}function xe(e,t){if(e===t)return!0;if(!!e!=!!t||!e||!t)return!1;if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}function Re(e,t){if(e===t)return!0;if(!!e!=!!t)return!1;if(!ge(e)||!ge(t))return e===t;const s=e,r=t;let i,n=0,o=0;for(i in s)n++;for(i in r)o++;if(n!==o)return!1;for(i in s){const e=s[i],t=r[i];if(Ne(e)&&Ne(t)){if(!xe(e,t))return!1}else if(ge(e)&&ge(t)){if(!Re(e,t))return!1}else if(e!==t)return!1}return!0}function Ne(e){return Array.isArray(e)||ArrayBuffer.isView(e)}const ye=e=>e,Ae=new Set;class Me extends te{constructor(e,t=""){super(e),this[Q].name=t,this.init(),this.dispatchEvent({type:"create"})}getGraph(){return this.graph}getDefaults(){return Object.assign(super.getDefaults(),{name:"",extras:{}})}set(e,t){return Array.isArray(t)&&(t=t.slice()),super.set(e,t)}getName(){return this.get("name")}setName(e){return this.set("name",e)}getExtras(){return this.get("extras")}setExtras(e){return this.set("extras",e)}clone(){return new this.constructor(this.graph).copy(this,ye)}copy(e,t=ye){for(const e in this[Q]){const t=this[Q][e];if(t instanceof k)this[ee].has(e)||t.dispose();else if(Z(t))for(const e of t)e.dispose();else if($(t))for(const e in t)t[e].dispose()}for(const s in e[Q]){const r=this[Q][s],i=e[Q][s];if(i instanceof k)this[ee].has(s)?r.getChild().copy(t(i.getChild()),t):this.setRef(s,t(i.getChild()),i.getAttributes());else if(Z(i))for(const e of i)this.addRef(s,t(e.getChild()),e.getAttributes());else if($(i))for(const e in i){const r=i[e];this.setRefMap(s,e,t(r.getChild()),r.getAttributes())}else this[Q][s]=ge(i)?JSON.parse(JSON.stringify(i)):Array.isArray(i)||i instanceof ArrayBuffer||ArrayBuffer.isView(i)?i.slice():i}return this}equals(e,t=Ae){if(this===e)return!0;if(this.propertyType!==e.propertyType)return!1;for(const s in this[Q]){if(t.has(s))continue;const r=this[Q][s],i=e[Q][s];if(J(r)||J(i)){if(!fe(r,i))return!1}else if(Z(r)||Z(i)){if(!Te(r,i))return!1}else if($(r)||$(i)){if(!me(r,i))return!1}else if(ge(r)||ge(i)){if(!Re(r,i))return!1}else if(Ne(r)||Ne(i)){if(!xe(r,i))return!1}else if(r!==i)return!1}return!0}detach(){return this.graph.disconnectParents(this,(e=>"Root"!==e.propertyType)),this}listParents(){return this.graph.listParents(this)}}class Ie extends Me{getDefaults(){return Object.assign(super.getDefaults(),{extensions:{}})}getExtension(e){return this.getRefMap("extensions",e)}setExtension(e,t){return t&&t.t(this),this.setRefMap("extensions",e,t)}listExtensions(){return this.listRefMapValues("extensions")}}class Se extends Ie{constructor(...e){super(...e),this.i=de.identity,this.o=de.identity}init(){this.propertyType=se.ACCESSOR}getDefaults(){return Object.assign(super.getDefaults(),{array:null,type:Se.Type.SCALAR,componentType:Se.ComponentType.FLOAT,normalized:!1,sparse:!1,buffer:null})}copy(e,t=ye){return super.copy(e,t),this.i=e.i,this.o=e.o,this}static getElementSize(e){switch(e){case Se.Type.SCALAR:return 1;case Se.Type.VEC2:return 2;case Se.Type.VEC3:return 3;case Se.Type.VEC4:case Se.Type.MAT2:return 4;case Se.Type.MAT3:return 9;case Se.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+e)}}static getComponentSize(e){switch(e){case Se.ComponentType.BYTE:case Se.ComponentType.UNSIGNED_BYTE:return 1;case Se.ComponentType.SHORT:case Se.ComponentType.UNSIGNED_SHORT:return 2;case Se.ComponentType.UNSIGNED_INT:case Se.ComponentType.FLOAT:return 4;default:throw new Error("Unexpected component type: "+e)}}getMinNormalized(e){const t=this.getElementSize();this.getMin(e);for(let s=0;s<t;s++)e[s]=this.o(e[s]);return e}getMin(e){const t=this.get("array"),s=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=1/0;for(let i=0;i<s*r;i+=r)for(let s=0;s<r;s++){const r=t[i+s];Number.isFinite(r)&&(e[s]=Math.min(e[s],r))}return e}getMaxNormalized(e){const t=this.getElementSize();this.getMax(e);for(let s=0;s<t;s++)e[s]=this.o(e[s]);return e}getMax(e){const t=this.get("array"),s=this.getCount(),r=this.getElementSize();for(let t=0;t<r;t++)e[t]=-1/0;for(let i=0;i<s*r;i+=r)for(let s=0;s<r;s++){const r=t[i+s];Number.isFinite(r)&&(e[s]=Math.max(e[s],r))}return e}getCount(){const e=this.get("array");return e?e.length/this.getElementSize():0}getType(){return this.get("type")}setType(e){return this.set("type",e)}getElementSize(){return Se.getElementSize(this.get("type"))}getComponentSize(){return this.get("array").BYTES_PER_ELEMENT}getComponentType(){return this.get("componentType")}getNormalized(){return this.get("normalized")}setNormalized(e){return this.set("normalized",e),e?(this.o=e=>de.decodeNormalizedInt(e,this.get("componentType")),this.i=e=>de.encodeNormalizedInt(e,this.get("componentType"))):(this.o=de.identity,this.i=de.identity),this}getScalar(e){const t=this.getElementSize();return this.o(this.get("array")[e*t])}setScalar(e,t){return this.get("array")[e*this.getElementSize()]=this.i(t),this}getElement(e,t){const s=this.getElementSize(),r=this.get("array");for(let i=0;i<s;i++)t[i]=this.o(r[e*s+i]);return t}setElement(e,t){const s=this.getElementSize(),r=this.get("array");for(let i=0;i<s;i++)r[e*s+i]=this.i(t[i]);return this}getSparse(){return this.get("sparse")}setSparse(e){return this.set("sparse",e)}getBuffer(){return this.getRef("buffer")}setBuffer(e){return this.setRef("buffer",e)}getArray(){return this.get("array")}setArray(e){return this.set("componentType",e?function(e){switch(e.constructor){case Float32Array:return Se.ComponentType.FLOAT;case Uint32Array:return Se.ComponentType.UNSIGNED_INT;case Uint16Array:return Se.ComponentType.UNSIGNED_SHORT;case Uint8Array:return Se.ComponentType.UNSIGNED_BYTE;case Int16Array:return Se.ComponentType.SHORT;case Int8Array:return Se.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}(e):Se.ComponentType.FLOAT),this.set("array",e),this}getByteLength(){const e=this.get("array");return e?e.byteLength:0}}Se.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"},Se.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126};(class extends Ie{init(){this.propertyType=se.ANIMATION_CHANNEL}getDefaults(){return Object.assign(super.getDefaults(),{targetPath:null,targetNode:null,sampler:null})}getTargetPath(){return this.get("targetPath")}setTargetPath(e){return this.set("targetPath",e)}getTargetNode(){return this.getRef("targetNode")}setTargetNode(e){return this.setRef("targetNode",e)}getSampler(){return this.getRef("sampler")}setSampler(e){return this.setRef("sampler",e)}}).TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"};class _e extends Ie{init(){this.propertyType=se.ANIMATION_SAMPLER}getDefaultAttributes(){return Object.assign(super.getDefaults(),{interpolation:_e.Interpolation.LINEAR,input:null,output:null})}getInterpolation(){return this.get("interpolation")}setInterpolation(e){return this.set("interpolation",e)}getInput(){return this.getRef("input")}setInput(e){return this.setRef("input",e,{usage:ie.OTHER})}getOutput(){return this.getRef("output")}setOutput(e){return this.setRef("output",e,{usage:ie.OTHER})}}_e.Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"};class Ce extends Ie{init(){this.propertyType=se.CAMERA}getDefaults(){return Object.assign(super.getDefaults(),{type:Ce.Type.PERSPECTIVE,znear:.1,zfar:100,aspectRatio:null,yfov:2*Math.PI*50/360,xmag:1,ymag:1})}getType(){return this.get("type")}setType(e){return this.set("type",e)}getZNear(){return this.get("znear")}setZNear(e){return this.set("znear",e)}getZFar(){return this.get("zfar")}setZFar(e){return this.set("zfar",e)}getAspectRatio(){return this.get("aspectRatio")}setAspectRatio(e){return this.set("aspectRatio",e)}getYFov(){return this.get("yfov")}setYFov(e){return this.set("yfov",e)}getXMag(){return this.get("xmag")}setXMag(e){return this.set("xmag",e)}getYMag(){return this.get("ymag")}setYMag(e){return this.set("ymag",e)}}Ce.Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};class be extends Me{t(e){if(!this.parentTypes.includes(e.propertyType))throw new Error(`Parent "${e.propertyType}" invalid for child "${this.propertyType}".`)}}be.EXTENSION_NAME=void 0;class ve extends Ie{init(){this.propertyType=se.TEXTURE_INFO}getDefaults(){return Object.assign(super.getDefaults(),{texCoord:0,magFilter:null,minFilter:null,wrapS:ve.WrapMode.REPEAT,wrapT:ve.WrapMode.REPEAT})}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}getMagFilter(){return this.get("magFilter")}setMagFilter(e){return this.set("magFilter",e)}getMinFilter(){return this.get("minFilter")}setMinFilter(e){return this.set("minFilter",e)}getWrapS(){return this.get("wrapS")}setWrapS(e){return this.set("wrapS",e)}getWrapT(){return this.get("wrapT")}setWrapT(e){return this.set("wrapT",e)}}ve.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},ve.MagFilter={NEAREST:9728,LINEAR:9729},ve.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};const{R:Oe,G:Fe,B:Le,A:Be}=ne;class we extends Ie{init(){this.propertyType=se.MATERIAL}getDefaults(){return Object.assign(super.getDefaults(),{alphaMode:we.AlphaMode.OPAQUE,alphaCutoff:.5,doubleSided:!1,baseColorFactor:[1,1,1,1],baseColorTexture:null,baseColorTextureInfo:new ve(this.graph,"baseColorTextureInfo"),emissiveFactor:[0,0,0],emissiveTexture:null,emissiveTextureInfo:new ve(this.graph,"emissiveTextureInfo"),normalScale:1,normalTexture:null,normalTextureInfo:new ve(this.graph,"normalTextureInfo"),occlusionStrength:1,occlusionTexture:null,occlusionTextureInfo:new ve(this.graph,"occlusionTextureInfo"),roughnessFactor:1,metallicFactor:1,metallicRoughnessTexture:null,metallicRoughnessTextureInfo:new ve(this.graph,"metallicRoughnessTextureInfo")})}getDoubleSided(){return this.get("doubleSided")}setDoubleSided(e){return this.set("doubleSided",e)}getAlpha(){return this.get("baseColorFactor")[3]}setAlpha(e){const t=this.get("baseColorFactor").slice();return t[3]=e,this.set("baseColorFactor",t)}getAlphaMode(){return this.get("alphaMode")}setAlphaMode(e){return this.set("alphaMode",e)}getAlphaCutoff(){return this.get("alphaCutoff")}setAlphaCutoff(e){return this.set("alphaCutoff",e)}getBaseColorFactor(){return this.get("baseColorFactor")}setBaseColorFactor(e){return this.set("baseColorFactor",e)}getBaseColorHex(){return le.factorToHex(this.get("baseColorFactor"))}setBaseColorHex(e){const t=this.get("baseColorFactor").slice();return this.set("baseColorFactor",le.hexToFactor(e,t))}getBaseColorTexture(){return this.getRef("baseColorTexture")}getBaseColorTextureInfo(){return this.getRef("baseColorTexture")?this.getRef("baseColorTextureInfo"):null}setBaseColorTexture(e){return this.setRef("baseColorTexture",e,{channels:Oe|Fe|Le|Be,isColor:!0})}getEmissiveFactor(){return this.get("emissiveFactor")}setEmissiveFactor(e){return this.set("emissiveFactor",e)}getEmissiveHex(){return le.factorToHex(this.get("emissiveFactor"))}setEmissiveHex(e){const t=this.get("emissiveFactor").slice();return this.set("emissiveFactor",le.hexToFactor(e,t))}getEmissiveTexture(){return this.getRef("emissiveTexture")}getEmissiveTextureInfo(){return this.getRef("emissiveTexture")?this.getRef("emissiveTextureInfo"):null}setEmissiveTexture(e){return this.setRef("emissiveTexture",e,{channels:Oe|Fe|Le,isColor:!0})}getNormalScale(){return this.get("normalScale")}setNormalScale(e){return this.set("normalScale",e)}getNormalTexture(){return this.getRef("normalTexture")}getNormalTextureInfo(){return this.getRef("normalTexture")?this.getRef("normalTextureInfo"):null}setNormalTexture(e){return this.setRef("normalTexture",e,{channels:Oe|Fe|Le})}getOcclusionStrength(){return this.get("occlusionStrength")}setOcclusionStrength(e){return this.set("occlusionStrength",e)}getOcclusionTexture(){return this.getRef("occlusionTexture")}getOcclusionTextureInfo(){return this.getRef("occlusionTexture")?this.getRef("occlusionTextureInfo"):null}setOcclusionTexture(e){return this.setRef("occlusionTexture",e,{channels:Oe})}getRoughnessFactor(){return this.get("roughnessFactor")}setRoughnessFactor(e){return this.set("roughnessFactor",e)}getMetallicFactor(){return this.get("metallicFactor")}setMetallicFactor(e){return this.set("metallicFactor",e)}getMetallicRoughnessTexture(){return this.getRef("metallicRoughnessTexture")}getMetallicRoughnessTextureInfo(){return this.getRef("metallicRoughnessTexture")?this.getRef("metallicRoughnessTextureInfo"):null}setMetallicRoughnessTexture(e){return this.setRef("metallicRoughnessTexture",e,{channels:Fe|Le})}}we.AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};class Ge extends Ie{init(){this.propertyType=se.PRIMITIVE}getDefaults(){return Object.assign(super.getDefaults(),{mode:Ge.Mode.TRIANGLES,material:null,indices:null,attributes:{},targets:[]})}getIndices(){return this.getRef("indices")}setIndices(e){return this.setRef("indices",e,{usage:ie.ELEMENT_ARRAY_BUFFER})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:ie.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}getMode(){return this.get("mode")}setMode(e){return this.set("mode",e)}listTargets(){return this.listRefs("targets")}addTarget(e){return this.addRef("targets",e)}removeTarget(e){return this.removeRef("targets",e)}}Ge.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6};class Pe{constructor(e){this.extensionName="",this.prereadTypes=[],this.prewriteTypes=[],this.readDependencies=[],this.writeDependencies=[],this.document=void 0,this.required=!1,this.properties=new Set,this.S=void 0,this.document=e,e.getRoot().g(this),this.S=e=>{const t=e,s=t.target;s instanceof be&&s.extensionName===this.extensionName&&("node:create"===t.type&&this.I(s),"node:dispose"===t.type&&this.N(s))};const t=e.getGraph();t.addEventListener("node:create",this.S),t.addEventListener("node:dispose",this.S)}dispose(){this.document.getRoot().p(this);const e=this.document.getGraph();e.removeEventListener("node:create",this.S),e.removeEventListener("node:dispose",this.S);for(const e of this.properties)e.dispose()}static register(){}isRequired(){return this.required}setRequired(e){return this.required=e,this}listProperties(){return Array.from(this.properties)}I(e){return this.properties.add(e),this}N(e){return this.properties.delete(e),this}install(e,t){return this}preread(e,t){return this}prewrite(e,t){re