Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gltf-transform/functions

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/functions - npm Package Compare versions

Comparing version 0.12.1 to 0.12.2

2

dist/functions.js

@@ -1,2 +0,2 @@

var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),r=require("@gltf-transform/extensions"),n=require("ndarray"),i=require("ndarray-lanczos");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n);function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var f="center",c={pivot:"center"},g={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE]},p=function(e,r,n){try{if(!e)return Promise.resolve(null);var i=e.getImage();return i?Promise.resolve(t.getPixels(new Uint8Array(i),e.getMimeType())).then(function(e){for(var i=0;i<e.shape[0];++i)for(var o=0;o<e.shape[1];++o)n(e,i,o);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return r.setImage(e.buffer).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function d(t){var r=t.getIndices(),n=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return n.getCount();case e.Primitive.Mode.LINES:return r?r.getCount()/2:n.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return n.getCount();case e.Primitive.Mode.LINE_STRIP:return n.getCount()-1;case e.Primitive.Mode.TRIANGLES:return r?r.getCount()/3:n.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}function v(t){return{properties:t.getRoot().listScenes().map(function(t){var r=t.listChildren()[0],n=e.bounds(t);return{name:t.getName(),rootName:r?r.getName():"",bboxMin:S(n.min),bboxMax:S(n.max)}})}}function m(e){return{properties:e.getRoot().listMeshes().map(function(e){var t=e.listParents().filter(function(e){return"Root"!==e.propertyType}).length,r=0,n=0,i=new Set,o=new Set,a=new Set;e.listPrimitives().forEach(function(e){for(var t,s=l(e.listSemantics());!(t=s()).done;){var u=t.value,f=e.getAttribute(u);i.add(u+":"+T(f.getArray())),a.add(f)}for(var c,g=l(e.listTargets());!(c=g()).done;)c.value.listAttributes().forEach(function(e){return a.add(e)});var p=e.getIndices();p&&(o.add(T(p.getArray())),a.add(p)),n+=e.listAttributes()[0].getCount(),r+=d(e)});var s=0;Array.from(a).forEach(function(e){return s+=e.getArray().byteLength});var u=e.listPrimitives().map(function(e){return b[e.getMode()]});return{name:e.getName(),mode:Array.from(new Set(u)),primitives:e.listPrimitives().length,glPrimitives:r,vertices:n,indices:Array.from(o).sort(),attributes:Array.from(i).sort(),instances:t,size:s}})}}function h(t){return{properties:t.getRoot().listMaterials().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=new Set(r.listExtensions()),o=t.getGraph().getLinks().filter(function(t){var n=t.getChild(),o=t.getParent();return n instanceof e.Texture&&o===r||!!(n instanceof e.Texture&&o instanceof e.ExtensionProperty&&i.has(o))}).map(function(e){return e.getName()});return{name:r.getName(),instances:n,textures:o,alphaMode:r.getAlphaMode(),doubleSided:r.getDoubleSided()}})}}function y(t){return{properties:t.getRoot().listTextures().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=t.getGraph().listParentLinks(r).map(function(e){return e.getName()}).filter(function(e){return"texture"!==e}),o=e.ImageUtils.getSize(r.getImage(),r.getMimeType());return{name:r.getName(),uri:r.getURI(),slots:Array.from(new Set(i)),instances:n,mimeType:r.getMimeType(),resolution:o?o.join("x"):"",size:r.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(r.getImage(),r.getMimeType())}})}}function A(e){return{properties:e.getRoot().listAnimations().map(function(e){var t=Infinity,r=-Infinity;e.listSamplers().forEach(function(e){var n=e.getInput();n&&(t=Math.min(t,n.getMin([])[0]),r=Math.max(r,n.getMax([])[0]))});var n=0,i=0,o=new Set;return e.listSamplers().forEach(function(e){var t=e.getInput(),r=e.getOutput();t&&(i+=t.getCount(),o.add(t),r&&o.add(r))}),Array.from(o).forEach(function(e){n+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(r-t))/1e3,keyframes:i,size:n}})}}var b=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function S(e){for(var t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function T(e){return e.constructor.name.replace("Array","").toLowerCase()}var E="instance",I={};function w(t,r){for(var n,i=0;n=t.pop();)if(!(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)){var o=n.getParent();o instanceof e.Node&&t.push(o),n.dispose(),i++}r.debug(E+": Removed "+i+" unused nodes.")}function R(e,t,r,n){var i=r.listPrimitives()[0].getAttribute("POSITION").getBuffer(),o=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*n)).setBuffer(i),a=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*n)).setBuffer(i),s=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*n)).setBuffer(i);return t.createInstancedMesh().setAttribute("TRANSLATION",o).setAttribute("ROTATION",a).setAttribute("SCALE",s)}var N="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function P(e,t,r){if(!e.s){if(r instanceof M){if(!r.s)return void(r.o=P.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(P.bind(null,e,t),P.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var M=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var o=1&i?t:r;if(o){try{P(n,1,o(this.v))}catch(e){P(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?P(n,1,t?t(i):i):r?P(n,1,r(i)):P(n,2,i)}catch(e){P(n,2,e)}},n},e}();function x(e){return e instanceof M&&1&e.s}var C={},O="partition",z={animations:!0,meshes:!0};function L(e,t){for(var r=e+".bin",n=1;t.has(r);)r=e+"_"+n+++".bin";return r}var U={},F="quantize",_=[Int8Array,Int16Array,Int32Array],k={excludeAttributes:[],quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12};function q(t,r,n,i){for(var o,a=t.getRoot(),s=t.getLogger(),u=n?n.nodeRemap:null,f=l(r.listSemantics());!(o=f()).done;){var c=o.value;if(!i.excludeAttributes.includes(c)){var g=r.getAttribute(c),p=V(c,g,s,i),d=p.bits,v=p.ctor;if(v){if(d<8||d>16)throw new Error(F+": Requires bits = 8–16.");if(!(g.getComponentSize()<=d/8)){var m=t.getGraph().listParentLinks(g).filter(function(e){return e.getParent()!==a}).map(function(e){return e.getName()});if(new Set(m).size>1)s.warn(F+": Skipping "+c+"; attribute usage conflict.");else{if("POSITION"===c){if(!u)throw new Error(F+": Failed precondition; missing node transform.");for(var h=0,y=[0,0,0],A=g.getCount();h<A;h++)g.setElement(h,u(g.getElement(h,y)))}j(g,v,d),g.setNormalized(!0)}}}}}if(r instanceof e.Primitive&&r.getIndices()&&r.listAttributes().length&&r.listAttributes()[0].getCount()<65535){var b=r.getIndices();b.setArray(new Uint16Array(b.getArray()))}}function G(e,t){var r=e.listPrimitives().map(function(e){return e.getAttribute("POSITION")});if(!r.some(function(e){return!!e}))return null;var n=[Infinity,Infinity,Infinity],i=[-Infinity,-Infinity,-Infinity];return t?(n=[].concat(t.min),i=[].concat(t.max)):function(e,t,r){for(var n=r[0].getElementSize(),i=0;i<n;i++)e[i]=Infinity;for(var o=0;o<n;o++)t[o]=-Infinity;for(var a,s=[],u=[],f=l(r);!(a=f()).done;){var c=a.value;c.getMinNormalized(s),c.getMaxNormalized(u);for(var g=0;g<n;g++)e[g]=Math.min(e[g],s[g]),t[g]=Math.max(t[g],u[g])}}(n,i,r),{nodeRemap:function(e){return[2*(e[0]-n[0])/(i[0]-n[0])-1,2*(e[1]-n[1])/(i[1]-n[1])-1,2*(e[2]-n[2])/(i[2]-n[2])-1]},nodeOffset:[n[0]+(i[0]-n[0])/2,n[1]+(i[1]-n[1])/2,n[2]+(i[2]-n[2])/2],nodeScale:[(i[0]-n[0])/2,(i[1]-n[1])/2,(i[2]-n[2])/2]}}function B(t,r,n){for(var i,o=n.nodeOffset||[0,0,0],a=n.nodeScale||[1,1,1],s=l(r.listParents());!(i=s()).done;){var u=i.value;if(u instanceof e.Node){var f=u.listChildren().length>0,c=!!u.listParents().find(function(t){return t instanceof e.Animation}),g=void 0;f||c?(g=t.createNode("").setMesh(r),u.addChild(g).setMesh(null)):g=u;var p=g.getTranslation(),d=g.getScale();g.setTranslation([p[0]+o[0],p[1]+o[1],p[2]+o[2]]).setScale([d[0]*a[0],d[1]*a[1],d[2]*a[2]])}}}function j(e,t,r){for(var n=new t(e.getArray().length),i=_.includes(t)?1:0,o=r-i,a=8*t.BYTES_PER_ELEMENT-i,s=Math.pow(2,o)-1,u=a-o,l=2*o-a,f=0,c=0,g=[];f<e.getCount();f++){e.getElement(f,g);for(var p=0;p<g.length;p++){var d=Math.round(Math.abs(g[p])*s);n[c++]=(d=d<<u|d>>l)*Math.sign(g[p])}}e.setArray(n)}function V(e,t,r,n){var i,o,a=t.getMinNormalized([]),s=t.getMinNormalized([]);if("POSITION"===e)o=(i=n.quantizePosition)<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)o=(i=n.quantizeNormal)<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))o=(i=n.quantizeColor)<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(a.some(function(e){return e<0})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};o=(i=n.quantizeTexcoord)<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return o=(i=Math.max.apply(Math,t.getMax([]))<=255?8:16)<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new o(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(a.some(function(e){return e<0})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};o=(i=n.quantizeWeight)<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(F+': Unexpected semantic, "'+e+'".');if(a.some(function(e){return e<-1})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};i=n.quantizeGeneric,o=o=a.some(function(e){return e<0})?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:o}}var W={tolerance:1e-4};function D(e,t){if(["STEP","LINEAR"].includes(e.getInterpolation())){for(var r,n=e.getInput().clone(),i=e.getOutput().clone(),o=t.tolerance,a=n.getCount()-1,s=[],u=1,l=1;l<a;++l){var f=n.getScalar(l),c=n.getScalar(l-1),g=n.getScalar(l+1),p=(f-c)/(g-c),d=!1;if(f!==g&&(1!==l||f!==n.getScalar(0)))for(var v=0;v<i.getElementSize();v++){var m=i.getElement(l,s)[v],h=i.getElement(l-1,s)[v],y=i.getElement(l+1,s)[v];if("LINEAR"===e.getInterpolation()){if(Math.abs(m-(h*(1-(r=p))+y*r))>o){d=!0;break}}else if("STEP"===e.getInterpolation()&&(m!==h||m!==y)){d=!0;break}}d&&(l!==u&&(n.setScalar(u,n.getScalar(l)),i.setElement(u,i.getElement(l,s))),u++)}a>0&&(n.setScalar(u,n.getScalar(a)),i.setElement(u,i.getElement(a,s)),u++),u!==n.getCount()?(n.setArray(n.getArray().slice(0,u)),i.setArray(i.getArray().slice(0,u*i.getElementSize())),e.setInput(n),e.setOutput(i)):(n.dispose(),i.dispose())}}var X={name:"",fps:10,pattern:/.*/,sort:!0},H="tangents",Z={overwrite:!1};function K(t,r,n,i,o){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!o?(r.debug(H+": Skipping primitive "+i+' of mesh "'+n+'": TANGENT found.'),!1):!t.getIndices()||(r.warn(H+": Skipping primitive "+i+' of mesh "'+n+'": primitives must be unwelded.'),!1):(r.debug(H+": Skipping primitive "+i+' of mesh "'+n+'": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.'),!1)}var Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function J(e,t,r){if(!e.s){if(r instanceof Y){if(!r.s)return void(r.o=J.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(J.bind(null,e,t),J.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Y=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var o=1&i?t:r;if(o){try{J(n,1,o(this.v))}catch(e){J(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?J(n,1,t?t(i):i):r?J(n,1,r(i)):J(n,2,i)}catch(e){J(n,2,e)}},n},e}();function $(e){return e instanceof Y&&1&e.s}var ee,te="textureResize";(ee=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",ee.LANCZOS2="lanczos2";var re={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},ne={};function ie(e,t,r,n){if(n.has(e)&&n.get(e).has(t))return r.debug('unweld: Cache hit for reused attribute, "'+e.getName()+'".'),n.get(e).get(t);var i=e.clone(),o=e.getArray().constructor;i.setArray(new o(t.getCount()*e.getElementSize()));for(var a=[],s=0;s<t.getCount();s++)i.setElement(s,e.getElement(t.getScalar(s),a));return n.has(e)||n.set(e,new Map),n.get(e).set(t,i),i}var oe={tolerance:1e-4};function ae(t,r){if(!r.getIndices()){for(var n=r.listAttributes()[0].getBuffer(),i=t.createAccessor().setBuffer(n).setType(e.Accessor.Type.SCALAR).setArray(new Uint32Array(3*d(r))),o=0;o<i.getCount();o++)i.setScalar(o,o);r.setIndices(i)}}function se(e,t,r){var n=Math.max(r.tolerance,Number.EPSILON),i=Math.log10(1/n),o=Math.pow(10,i),a={},s=t.getIndices(),u=s?s.getCount():t.listAttributes()[0].getCount(),f=new Map;t.listAttributes().forEach(function(e){return f.set(e,[])}),t.listTargets().forEach(function(e){e.listAttributes().forEach(function(e){return f.set(e,[])})});for(var c=[],g=0,p=0;p<u;p++){for(var d,v=s?s.getScalar(p):p,m=[],h=[],y=l(t.listAttributes());!(d=y()).done;)for(var A=d.value,b=0;b<A.getElementSize();b++)m.push(~~(A.getElement(v,h)[b]*o));var S=m.join("|");if(S in a)c.push(a[S]);else{for(var T,E=l(t.listAttributes());!(T=E()).done;){var I=T.value;f.get(I).push(I.getElement(v,[]))}for(var w,R=l(t.listTargets());!(w=R()).done;)for(var N,P=l(w.value.listAttributes());!(N=P()).done;){var M=N.value;f.get(M).push(M.getElement(v,[]))}a[S]=g,c.push(g),g++}}var x=t.listAttributes()[0].getCount(),C=f.get(t.getAttribute("POSITION")).length;e.getLogger().debug("weld: "+x+" → "+C+" vertices.");for(var O,z=l(t.listAttributes());!(O=z()).done;){var L=O.value;le(t,L,f.get(L)),1===L.listParents().length&&L.dispose()}for(var U,F=l(t.listTargets());!(U=F()).done;)for(var _,k=U.value,q=l(k.listAttributes());!(_=q()).done;){var G=_.value;le(k,G,f.get(G)),1===G.listParents().length&&G.dispose()}if(s){var B=ue(s.getArray(),c.length);B.set(c),t.setIndices(s.clone().setArray(B)),1===s.listParents().length&&s.dispose()}else t.setIndices(e.createAccessor().setArray(new Uint32Array(c)))}function ue(e,t){return new(0,e.constructor)(t)}function le(e,t,r){for(var n=r.length*t.getElementSize(),i=ue(t.getArray(),n),o=t.clone().setArray(i),a=0;a<r.length;a++)o.setElement(a,r[a]);e.swap(t,o)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.QUANTIZE_DEFAULTS=k,exports.TEXTURE_RESIZE_DEFAULTS=re,exports.center=function(t){void 0===t&&(t=c);var r=s({},c,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=i.listAnimations().length>0||i.listSkins().length>0;t.getRoot().listScenes().forEach(function(a,s){var u;if(n.debug(f+": Scene "+(s+1)+" / "+i.listScenes().length+"."),"string"==typeof r.pivot){var l=e.bounds(a);u=[(l.max[0]-l.min[0])/2+l.min[0],(l.max[1]-l.min[1])/2+l.min[1],(l.max[2]-l.min[2])/2+l.min[2]],"above"===r.pivot&&(u[1]=l.max[1]),"below"===r.pivot&&(u[1]=l.min[1])}else u=r.pivot;n.debug(f+': Pivot "'+u.join(", ")+'".');var c=[-1*u[0],-1*u[1],-1*u[2]];if(o){n.debug(f+": Model contains animation or skin. Adding a wrapper node.");var g=t.createNode("Pivot").setTranslation(c);a.listChildren().forEach(function(e){return g.addChild(e)}),a.addChild(g)}else n.debug(f+": Skipping wrapper, offsetting all root nodes."),a.listChildren().forEach(function(e){var t=e.getTranslation();e.setTranslation([t[0]+c[0],t[1]+c[1],t[2]+c[2]])})}),n.debug(f+": Complete.")}},exports.colorspace=function(e){return function(t){var r=t.getLogger();if("linear"!==e.inputEncoding)if("sRGB"===e.inputEncoding){var n=new Set;t.getRoot().listMeshes().forEach(function(e){return e.listPrimitives().forEach(o)}),r.debug("colorspace: Complete.")}else r.error('colorspace: Unknown input encoding "'+e.inputEncoding+'" – should be "sRGB" or "linear". Skipping conversion.');else r.info("colorspace: Vertex colors already linear. Skipping conversion.");function i(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function o(e){for(var t,r=[0,0,0],o=0;t=e.getAttribute("COLOR_"+o);o++)if(!n.has(t)){for(var a=0;a<t.getCount();a++)t.getElement(a,r),r[0]=i(r[0]),r[1]=i(r[1]),r[2]=i(r[2]),t.setElement(a,r);n.add(t)}}}},exports.dedup=function(t){void 0===t&&(t=g);for(var r,n=s({},g,t),i=new Set(n.propertyTypes),o=l(n.propertyTypes);!(r=o()).done;){var a=r.value;if(!g.propertyTypes.includes(a))throw new Error('dedup: Unsupported deduplication on type "'+a+'".')}return function(t){var r=t.getLogger();i.has(e.PropertyType.ACCESSOR)&&function(t,r){var n=new Set,i=new Set,o=r.getRoot().listMeshes();function a(t){for(var r=new Map,n=0;n<t.length;n++){var i=t[n],o=i.getArray().slice().buffer;if(!r.has(i))for(var a=0;a<t.length;a++){var s=t[a];i!==s&&(r.has(s)||i.getType()===s.getType()&&i.getComponentType()===s.getComponentType()&&i.getCount()===s.getCount()&&i.getNormalized()===s.getNormalized()&&e.BufferUtils.equals(o,s.getArray().slice().buffer)&&r.set(s,i))}}return r}o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(e){return i.add(e)});var t=e.getIndices();t&&n.add(t)})});var s=a(Array.from(n));t.debug("dedup: Found "+s.size+" duplicates among "+n.size+" indices.");var u=a(Array.from(i));t.debug("dedup: Found "+u.size+" duplicates among "+i.size+" attributes."),o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(t){u.has(t)&&e.swap(t,u.get(t))});var t=e.getIndices();t&&s.has(t)&&e.swap(t,s.get(t))})}),Array.from(s.keys()).forEach(function(e){return e.dispose()}),Array.from(u.keys()).forEach(function(e){return e.dispose()})}(r,t),i.has(e.PropertyType.MESH)&&function(t,r){var n=r.getRoot(),i=new Map;n.listAccessors().forEach(function(e,t){i.set(e,t)});for(var o,a=n.listMeshes().length,s=new Map,u=function(){for(var t,r=o.value,n=[],a=l(r.listPrimitives());!(t=a()).done;){for(var u,f=t.value,c=[],g=l(f.listSemantics());!(u=g()).done;){var p=u.value,d=f.getAttribute(p);c.push(p+":"+i.get(d))}var v=f.getIndices();v&&c.push("indices:"+i.get(v)),n.push(c.join(","))}var m=n.join(";");if(s.has(m)){var h=s.get(m);r.listParents().forEach(function(t){t.propertyType!==e.PropertyType.ROOT&&t.swap(r,h)}),r.dispose()}else s.set(m,r)},f=l(n.listMeshes());!(o=f()).done;)u();t.debug("dedup: Found "+(a-s.size)+" duplicates among "+a+" meshes.")}(r,t),i.has(e.PropertyType.TEXTURE)&&function(t,r){for(var n=r.getRoot(),i=n.listTextures(),o=new Map,a=0;a<i.length;a++){var s=i[a],u=s.getImage();if(!o.has(s))for(var l=0;l<i.length;l++){var f=i[l],c=f.getImage();if(s!==f&&!o.has(f)&&s.getMimeType()===f.getMimeType()){var g=s.getSize(),p=f.getSize();g&&p&&g[0]===p[0]&&g[1]===p[1]&&u&&c&&e.BufferUtils.equals(u,c)&&o.set(f,s)}}}t.debug("dedup: Found "+o.size+" duplicates among "+n.listTextures().length+" textures."),Array.from(o.entries()).forEach(function(t){var r=t[0],n=t[1];r.listParents().forEach(function(t){t instanceof e.Material&&t.swap(r,n)}),r.dispose()})}(r,t),r.debug("dedup: Complete.")}},exports.inspect=function(e){return{scenes:v(e),meshes:m(e),materials:h(e),textures:y(e),animations:A(e)}},exports.instance=function(t){return void 0===t&&(t=I),s({},I,t),function(t){var n=t.getLogger(),i=t.getRoot(),o=t.createExtension(r.MeshGPUInstancing);if(i.listAnimations().length)throw new Error(E+": Instancing is not currently supported for animated models.");for(var a,s=0,u=0,f=function(){var r=a.value,i=new Map;r.traverse(function(e){var t=e.getMesh();t&&i.set(t,(i.get(t)||new Set).add(e))});for(var l=[],f=0,c=Array.from(i.keys());f<c.length;f++){var g=c[f],p=Array.from(i.get(g));if(!(p.length<2||p.some(function(e){return e.getSkin()}))){var d=R(t,o,g,p.length),v=d.getAttribute("TRANSLATION"),m=d.getAttribute("ROTATION"),h=d.getAttribute("SCALE"),y=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",d);r.addChild(y);for(var A=!1,b=!1,S=!1,T=0;T<p.length;T++){var E,I,N,P=p[T];v.setElement(T,E=P.getWorldTranslation()),m.setElement(T,I=P.getWorldRotation()),h.setElement(T,N=P.getWorldScale()),e.MathUtils.eq(E,[0,0,0])||(A=!0),e.MathUtils.eq(I,[0,0,0,1])||(b=!0),e.MathUtils.eq(N,[1,1,1])||(S=!0),P.setMesh(null),l.push(P)}A||v.dispose(),b||m.dispose(),S||h.dispose(),w(l,n),s++,u+=p.length}}},c=l(i.listScenes());!(a=c()).done;)f();s>0?n.info(E+": Created "+s+" batches, with "+u+" total instances."):(n.info(E+": No meshes with multiple parent nodes were found."),o.dispose()),n.debug(E+": Complete.")}},exports.metalRough=function(e){return void 0===e&&(e=C),s({},C,e),function(e){try{var t=function(){s.dispose();for(var e,t=l(u);!(e=t()).done;){var r=e.value;r&&1===r.listParents().length&&r.dispose()}n.debug("metalRough: Complete.")},n=e.getLogger(),i=r.MaterialsPBRSpecularGlossiness.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(function(e){return e.extensionName}).includes(i))return n.warn("metalRough: Extension "+i+" not found on given document."),Promise.resolve();var o=e.createExtension(r.MaterialsIOR),a=e.createExtension(r.MaterialsSpecular),s=e.createExtension(r.MaterialsPBRSpecularGlossiness),u=new Set,f=function(e,t,r){if("function"==typeof e[N]){var n,i,o,a=e[N]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!x(r))return void r.then(e,o||(o=P.bind(null,i=new M,2)));r=r.v}i?P(i,1,r):i=r}catch(e){P(i||(i=new M),2,e)}}(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(s,function(e){throw s(e)});s()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,r){var n,i,o=-1;return function r(a){try{for(;++o<e.length;)if((a=t(o))&&a.then){if(!x(a))return void a.then(r,i||(i=P.bind(null,n=new M,2)));a=a.v}n?P(n,1,a):n=a}catch(e){P(n||(n=new M),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listMaterials(),function(t){function r(){t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}var n=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(n){var i=a.createSpecular().setSpecularFactor(1).setSpecularColorFactor(n.getSpecularFactor());u.add(n.getSpecularGlossinessTexture()),u.add(t.getBaseColorTexture()),u.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(n.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",o.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);var s=n.getDiffuseTexture();s&&(t.setBaseColorTexture(s),t.getBaseColorTextureInfo().copy(n.getDiffuseTextureInfo()));var l=n.getSpecularGlossinessTexture(),f=function(){if(l){var r=n.getSpecularGlossinessTextureInfo(),o=e.createTexture();return Promise.resolve(p(l,o,function(e,t,r){e.set(t,r,3,255)})).then(function(){i.setSpecularTexture(o),i.getSpecularTextureInfo().copy(r);var a=n.getGlossinessFactor(),s=e.createTexture();return Promise.resolve(p(l,s,function(e,t,r){var n=255-Math.round(e.get(t,r,3)*a);e.set(t,r,0,0),e.set(t,r,1,n),e.set(t,r,2,0),e.set(t,r,3,255)})).then(function(){t.setMetallicRoughnessTexture(s),t.getMetallicRoughnessTextureInfo().copy(r)})})}i.setSpecularColorFactor(n.getSpecularFactor()),t.setRoughnessFactor(1-n.getGlossinessFactor())}();return f&&f.then?f.then(r):r()}});return Promise.resolve(f&&f.then?f.then(t):t())}catch(e){return Promise.reject(e)}}},exports.partition=function(e){void 0===e&&(e=z);var t=s({},z,e);return function(e){var r=e.getLogger();!1!==t.meshes&&function(e,t,r){var n=new Set(e.getRoot().listBuffers().map(function(e){return e.getURI()}));e.getRoot().listMeshes().forEach(function(i,o){if(!Array.isArray(r.meshes)||r.meshes.includes(i.getName())){t.debug(O+': Creating buffer for mesh "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(L(i.getName()||"mesh",n));i.listPrimitives().forEach(function(e){var t=e.getIndices();t&&t.setBuffer(a),e.listAttributes().forEach(function(e){return e.setBuffer(a)}),e.listTargets().forEach(function(e){e.listAttributes().forEach(function(e){return e.setBuffer(a)})})})}else t.debug(O+": Skipping mesh #"+o+' with name "'+i.getName()+'".')})}(e,r,t),!1!==t.animations&&function(e,t,r){var n=new Set(e.getRoot().listBuffers().map(function(e){return e.getURI()}));e.getRoot().listAnimations().forEach(function(i,o){if(!Array.isArray(r.animations)||r.animations.includes(i.getName())){t.debug(O+': Creating buffer for animation "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(L(i.getName()||"animation",n));i.listSamplers().forEach(function(e){var t=e.getInput(),r=e.getOutput();t&&t.setBuffer(a),r&&r.setBuffer(a)})}else t.debug(O+": Skipping animation #"+o+' with name "'+i.getName()+'".')})}(e,r,t),t.meshes||t.animations||r.warn(O+": Select animations or meshes to create a partition."),r.debug(O+": Complete.")}},exports.prune=function(t){return void 0===t&&(t=U),s({},U,t),function(t){var r=t.getLogger(),n=t.getRoot(),i=t.getGraph(),o={};n.listNodes().forEach(v),n.listSkins().forEach(v),n.listMeshes().forEach(v),n.listCameras().forEach(v),m(i,e.PropertyType.PRIMITIVE),m(i,e.PropertyType.PRIMITIVE_TARGET);for(var a,s=l(n.listAnimations());!(a=s()).done;){for(var u,f=a.value,c=l(f.listChannels());!(u=c()).done;){var g=u.value;g.getTargetNode()||(g.dispose(),h(g))}if(f.listChannels().length)f.listSamplers().forEach(v);else{var p=f.listSamplers();v(f),p.forEach(v)}}if(n.listMaterials().forEach(v),n.listTextures().forEach(v),n.listAccessors().forEach(v),n.listBuffers().forEach(v),Object.keys(o).length){var d=Object.keys(o).map(function(e){return e+" ("+o[e]+")"}).join(", ");r.info("prune: Removed types... "+d)}else r.info("prune: No unused properties found.");function v(t){t.listParents().filter(function(t){return!(t instanceof e.Root||t instanceof e.AnimationChannel)}).length||(t.dispose(),h(t))}function m(e,t){e.getLinks().map(function(e){return e.getParent()}).filter(function(e){return e.propertyType===t}).forEach(v)}function h(e){o[e.propertyType]=o[e.propertyType]||0,o[e.propertyType]++}r.debug("prune: Complete.")}},exports.quantize=function(t){void 0===t&&(t=k);var n=s({},k,t);return function(t){var i=t.getLogger(),o=t.getRoot();t.createExtension(r.MeshQuantization).setRequired(!0);var a=void 0;"scene"===n.quantizationVolume&&(1!==o.listScenes().length?i.warn("[quantize]: quantizationVolume=scene requires exactly 1 scene."):a=e.bounds(o.listScenes().pop()));for(var s,u=l(t.getRoot().listMeshes());!(s=u()).done;){var f=s.value;if(f.listPrimitives().some(function(e){return e.getAttribute("JOINTS_0")}))i.warn(F+": Quantization for skinned mesh not yet implemented.");else{var c=G(f,a);c&&B(t,f,c);for(var g,p=l(f.listPrimitives());!(g=p()).done;){var d=g.value;q(t,d,c,n);for(var v,m=l(d.listTargets());!(v=m()).done;)q(t,v.value,c,n)}}}i.debug(F+": Complete.")}},exports.resample=function(t){void 0===t&&(t=W);var r=s({},W,t);return function(t){for(var n,i=new Set,o=t.getRoot().listAccessors().length,a=t.getLogger(),s=l(t.getRoot().listAnimations());!(n=s()).done;)for(var u,f=l(n.value.listSamplers());!(u=f()).done;){var c=u.value;"STEP"!==c.getInterpolation()&&"LINEAR"!==c.getInterpolation()||(i.add(c.getInput()),i.add(c.getOutput()),D(c,r))}for(var g=0,p=Array.from(i.values());g<p.length;g++){var d=p[g];d.listParents().find(function(t){return!(t instanceof e.Root)})||d.dispose()}t.getRoot().listAccessors().length>o&&a.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a.debug("resample: Complete.")}},exports.sequence=function(t){void 0===t&&(t=X);var r=s({},X,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=r.fps,a=i.listNodes().filter(function(e){return e.getName().match(r.pattern)});r.sort&&a.sort(function(e,t){return e.getName()>t.getName()?1:-1});var s=t.createAnimation(r.name),u=i.listBuffers()[0];a.forEach(function(r,n){var i,l;0===n?(i=[n/o,(n+1)/o],l=[1,1,1,0,0,0]):n===a.length-1?(i=[(n-1)/o,n/o],l=[0,0,0,1,1,1]):(i=[(n-1)/o,n/o,(n+1)/o],l=[0,0,0,1,1,1,0,0,0]);var f=t.createAccessor().setArray(new Float32Array(i)).setBuffer(u),c=t.createAccessor().setArray(new Float32Array(l)).setBuffer(u).setType(e.Accessor.Type.VEC3),g=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(f).setOutput(c),p=t.createAnimationChannel().setTargetNode(r).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(g);s.addSampler(g).addChannel(p)}),n.debug("sequence: Complete.")}},exports.tangents=function(t){if(void 0===t&&(t=Z),!t.generateTangents)throw new Error(H+': generateTangents callback required — install "mikktspace".');var r=s({},Z,t);return function(t){for(var n,i=t.getLogger(),o=new Map,a=new Map,s=0,u=l(t.getRoot().listMeshes());!(n=u()).done;)for(var f=n.value,c=f.getName(),g=f.listPrimitives(),p=0;p<g.length;p++){var d=g[p];if(K(d,i,c,p,r.overwrite)){var v=d.getAttribute("POSITION").getArray(),m=d.getAttribute("NORMAL").getArray(),h=d.getAttribute("TEXCOORD_0").getArray(),y=o.get(v)||e.uuid();o.set(v,y);var A=o.get(m)||e.uuid();o.set(m,A);var b=o.get(h)||e.uuid();o.set(h,b);var S=d.getAttribute("TANGENT");S&&2===S.listParents().length&&S.dispose();var T=y+"|"+A+"|"+b,E=a.get(T);if(E)i.debug(H+": Found cache for primitive "+p+' of mesh "'+c+'".'),d.setAttribute("TANGENT",E),s++;else{i.debug(H+": Generating for primitive "+p+' of mesh "'+c+'".');for(var I=d.getAttribute("POSITION").getBuffer(),w=r.generateTangents(v instanceof Float32Array?v:new Float32Array(v),m instanceof Float32Array?m:new Float32Array(m),h instanceof Float32Array?h:new Float32Array(h)),R=3;R<w.length;R+=4)w[R]*=-1;E=t.createAccessor().setBuffer(I).setArray(w).setType("VEC4"),d.setAttribute("TANGENT",E),a.set(T,E),s++}}}s?i.debug(H+": Complete."):i.warn(H+": No qualifying primitives found. See debug output.")}},exports.textureResize=function(e){void 0===e&&(e=re);var r=s({},re,e);return function(e){try{var n=function(){o.debug(te+": Complete.")},o=e.getLogger(),s=function(e,t,r){if("function"==typeof e[Q]){var n,i,o,a=e[Q]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!$(r))return void r.then(e,o||(o=J.bind(null,i=new Y,2)));r=r.v}i?J(i,1,r):i=r}catch(e){J(i||(i=new Y),2,e)}}(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(s,function(e){throw s(e)});s()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,r){var n,i,o=-1;return function r(a){try{for(;++o<e.length;)if((a=t(o))&&a.then){if(!$(a))return void a.then(r,i||(i=J.bind(null,n=new Y,2)));a=a.v}n?J(n,1,a):n=a}catch(e){J(n||(n=new Y),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listTextures(),function(e){var n=e.getName(),s=e.getURI();if(!r.pattern||r.pattern.test(n)||r.pattern.test(s))if("image/png"===e.getMimeType()||"image/jpeg"===e.getMimeType()){var u=r.size,l=u[0],f=u[1],c=e.getSize(),g=c[0],p=c[1];if(!(g<=l&&p<=f)){var d=g,v=p;d>l&&(d=l,v=Math.floor(v*(d/g))),v>f&&(v=f,d=Math.floor(d*(v/p)));var m=new Uint8Array(e.getImage());return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(u){var l=a.default(new Uint8Array(d*v*4),[d,v,4]);o.debug(te+': Resizing "'+(s||n)+'", '+u.shape+" → "+l.shape+"...");try{r.filter===exports.TextureResizeFilter.LANCZOS3?i.lanczos3(u,l):i.lanczos2(u,l)}catch(e){return void o.warn(te+': Failed to resize "'+(s||n)+'": "'+e.message+'".')}var f=e.setImage;return Promise.resolve(t.savePixels(l,e.getMimeType())).then(function(t){f.call(e,t.buffer)})})}o.debug(te+': Skipping "'+(s||n)+'", within size range.')}else o.warn('Skipping unsupported texture type, "'+e.getMimeType()+'".')});return Promise.resolve(s&&s.then?s.then(n):n())}catch(e){return Promise.reject(e)}}},exports.unweld=function(e){return void 0===e&&(e=ne),s({},ne,e),function(e){for(var t,r=e.getLogger(),n=new Map,i=l(e.getRoot().listMeshes());!(t=i()).done;)for(var o,a=l(t.value.listPrimitives());!(o=a()).done;){var s=o.value,u=s.getIndices();if(u){for(var f,c=l(s.listAttributes());!(f=c()).done;){var g=f.value;s.swap(g,ie(g,u,r,n)),1===g.listParents().length&&g.dispose()}for(var p,d=l(s.listTargets());!(p=d()).done;)for(var v,m=p.value,h=l(m.listAttributes());!(v=h()).done;){var y=v.value;m.swap(y,ie(y,u,r,n)),1===y.listParents().length&&y.dispose()}s.setIndices(null),1===u.listParents().length&&u.dispose()}}r.debug("unweld: Complete.")}},exports.weld=function(e){void 0===e&&(e=oe);var t=s({},oe,e);return function(e){for(var r,n=e.getLogger(),i=l(e.getRoot().listMeshes());!(r=i()).done;)for(var o,a=l(r.value.listPrimitives());!(o=a()).done;){var s=o.value;0===t.tolerance?ae(e,s):se(e,s,t)}n.debug("weld: Complete.")}};
var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),r=require("@gltf-transform/extensions"),n=require("ndarray"),i=require("ndarray-lanczos");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n);function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var f="center",c={pivot:"center"},g={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE]},p=function(e,r,n){try{if(!e)return Promise.resolve(null);var i=e.getImage();return i?Promise.resolve(t.getPixels(new Uint8Array(i),e.getMimeType())).then(function(e){for(var i=0;i<e.shape[0];++i)for(var o=0;o<e.shape[1];++o)n(e,i,o);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return r.setImage(e.buffer).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function d(t){var r=t.getIndices(),n=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return n.getCount();case e.Primitive.Mode.LINES:return r?r.getCount()/2:n.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return n.getCount();case e.Primitive.Mode.LINE_STRIP:return n.getCount()-1;case e.Primitive.Mode.TRIANGLES:return r?r.getCount()/3:n.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}function v(t){return{properties:t.getRoot().listScenes().map(function(t){var r=t.listChildren()[0],n=e.bounds(t);return{name:t.getName(),rootName:r?r.getName():"",bboxMin:S(n.min),bboxMax:S(n.max)}})}}function m(e){return{properties:e.getRoot().listMeshes().map(function(e){var t=e.listParents().filter(function(e){return"Root"!==e.propertyType}).length,r=0,n=0,i=new Set,o=new Set,a=new Set;e.listPrimitives().forEach(function(e){for(var t,s=l(e.listSemantics());!(t=s()).done;){var u=t.value,f=e.getAttribute(u);i.add(u+":"+T(f.getArray())),a.add(f)}for(var c,g=l(e.listTargets());!(c=g()).done;)c.value.listAttributes().forEach(function(e){return a.add(e)});var p=e.getIndices();p&&(o.add(T(p.getArray())),a.add(p)),n+=e.listAttributes()[0].getCount(),r+=d(e)});var s=0;Array.from(a).forEach(function(e){return s+=e.getArray().byteLength});var u=e.listPrimitives().map(function(e){return b[e.getMode()]});return{name:e.getName(),mode:Array.from(new Set(u)),primitives:e.listPrimitives().length,glPrimitives:r,vertices:n,indices:Array.from(o).sort(),attributes:Array.from(i).sort(),instances:t,size:s}})}}function h(t){return{properties:t.getRoot().listMaterials().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=new Set(r.listExtensions()),o=t.getGraph().getLinks().filter(function(t){var n=t.getChild(),o=t.getParent();return n instanceof e.Texture&&o===r||!!(n instanceof e.Texture&&o instanceof e.ExtensionProperty&&i.has(o))}).map(function(e){return e.getName()});return{name:r.getName(),instances:n,textures:o,alphaMode:r.getAlphaMode(),doubleSided:r.getDoubleSided()}})}}function y(t){return{properties:t.getRoot().listTextures().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=t.getGraph().listParentLinks(r).map(function(e){return e.getName()}).filter(function(e){return"texture"!==e}),o=e.ImageUtils.getSize(r.getImage(),r.getMimeType());return{name:r.getName(),uri:r.getURI(),slots:Array.from(new Set(i)),instances:n,mimeType:r.getMimeType(),resolution:o?o.join("x"):"",size:r.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(r.getImage(),r.getMimeType())}})}}function A(e){return{properties:e.getRoot().listAnimations().map(function(e){var t=Infinity,r=-Infinity;e.listSamplers().forEach(function(e){var n=e.getInput();n&&(t=Math.min(t,n.getMin([])[0]),r=Math.max(r,n.getMax([])[0]))});var n=0,i=0,o=new Set;return e.listSamplers().forEach(function(e){var t=e.getInput(),r=e.getOutput();t&&(i+=t.getCount(),o.add(t),r&&o.add(r))}),Array.from(o).forEach(function(e){n+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(r-t))/1e3,keyframes:i,size:n}})}}var b=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function S(e){for(var t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function T(e){return e.constructor.name.replace("Array","").toLowerCase()}var E="instance",I={};function w(t,r){for(var n,i=0;n=t.pop();)if(!(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)){var o=n.getParent();o instanceof e.Node&&t.push(o),n.dispose(),i++}r.debug(E+": Removed "+i+" unused nodes.")}function R(e,t,r,n){var i=r.listPrimitives()[0].getAttribute("POSITION").getBuffer(),o=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*n)).setBuffer(i),a=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*n)).setBuffer(i),s=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*n)).setBuffer(i);return t.createInstancedMesh().setAttribute("TRANSLATION",o).setAttribute("ROTATION",a).setAttribute("SCALE",s)}var N="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function P(e,t,r){if(!e.s){if(r instanceof M){if(!r.s)return void(r.o=P.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(P.bind(null,e,t),P.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var M=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var o=1&i?t:r;if(o){try{P(n,1,o(this.v))}catch(e){P(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?P(n,1,t?t(i):i):r?P(n,1,r(i)):P(n,2,i)}catch(e){P(n,2,e)}},n},e}();function x(e){return e instanceof M&&1&e.s}var C={},O="partition",z={animations:!0,meshes:!0};function L(e,t){for(var r=e+".bin",n=1;t.has(r);)r=e+"_"+n+++".bin";return r}var U={},F="quantize",_=[Int8Array,Int16Array,Int32Array],k={excludeAttributes:[],quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12};function q(t,r,n,i){for(var o,a=t.getRoot(),s=t.getLogger(),u=n?n.nodeRemap:null,f=l(r.listSemantics());!(o=f()).done;){var c=o.value;if(!i.excludeAttributes.includes(c)){var g=r.getAttribute(c),p=V(c,g,s,i),d=p.bits,v=p.ctor;if(v){if(d<8||d>16)throw new Error(F+": Requires bits = 8–16.");if(!(g.getComponentSize()<=d/8)){var m=t.getGraph().listParentLinks(g).filter(function(e){return e.getParent()!==a}).map(function(e){return e.getName()});if(new Set(m).size>1)s.warn(F+": Skipping "+c+"; attribute usage conflict.");else{if("POSITION"===c){if(!u)throw new Error(F+": Failed precondition; missing node transform.");for(var h=0,y=[0,0,0],A=g.getCount();h<A;h++)g.setElement(h,u(g.getElement(h,y)))}j(g,v,d),g.setNormalized(!0)}}}}}if(r instanceof e.Primitive&&r.getIndices()&&r.listAttributes().length&&r.listAttributes()[0].getCount()<65535){var b=r.getIndices();b.setArray(new Uint16Array(b.getArray()))}}function G(e,t){var r=e.listPrimitives().map(function(e){return e.getAttribute("POSITION")});if(!r.some(function(e){return!!e}))return null;var n=[Infinity,Infinity,Infinity],i=[-Infinity,-Infinity,-Infinity];return t?(n=[].concat(t.min),i=[].concat(t.max)):function(e,t,r){for(var n=r[0].getElementSize(),i=0;i<n;i++)e[i]=Infinity;for(var o=0;o<n;o++)t[o]=-Infinity;for(var a,s=[],u=[],f=l(r);!(a=f()).done;){var c=a.value;c.getMinNormalized(s),c.getMaxNormalized(u);for(var g=0;g<n;g++)e[g]=Math.min(e[g],s[g]),t[g]=Math.max(t[g],u[g])}}(n,i,r),{nodeRemap:function(e){return[2*(e[0]-n[0])/(i[0]-n[0])-1,2*(e[1]-n[1])/(i[1]-n[1])-1,2*(e[2]-n[2])/(i[2]-n[2])-1]},nodeOffset:[n[0]+(i[0]-n[0])/2,n[1]+(i[1]-n[1])/2,n[2]+(i[2]-n[2])/2],nodeScale:[(i[0]-n[0])/2,(i[1]-n[1])/2,(i[2]-n[2])/2]}}function B(t,r,n){for(var i,o=n.nodeOffset||[0,0,0],a=n.nodeScale||[1,1,1],s=l(r.listParents());!(i=s()).done;){var u=i.value;if(u instanceof e.Node){var f=u.listChildren().length>0,c=!!u.listParents().find(function(t){return t instanceof e.Animation}),g=void 0;f||c?(g=t.createNode("").setMesh(r),u.addChild(g).setMesh(null)):g=u;var p=g.getTranslation(),d=g.getScale();g.setTranslation([p[0]+o[0],p[1]+o[1],p[2]+o[2]]).setScale([d[0]*a[0],d[1]*a[1],d[2]*a[2]])}}}function j(e,t,r){for(var n=new t(e.getArray().length),i=_.includes(t)?1:0,o=r-i,a=8*t.BYTES_PER_ELEMENT-i,s=Math.pow(2,o)-1,u=a-o,l=2*o-a,f=0,c=0,g=[];f<e.getCount();f++){e.getElement(f,g);for(var p=0;p<g.length;p++){var d=Math.round(Math.abs(g[p])*s);n[c++]=(d=d<<u|d>>l)*Math.sign(g[p])}}e.setArray(n)}function V(e,t,r,n){var i,o,a=t.getMinNormalized([]),s=t.getMinNormalized([]);if("POSITION"===e)o=(i=n.quantizePosition)<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)o=(i=n.quantizeNormal)<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))o=(i=n.quantizeColor)<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(a.some(function(e){return e<0})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};o=(i=n.quantizeTexcoord)<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return o=(i=Math.max.apply(Math,t.getMax([]))<=255?8:16)<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new o(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(a.some(function(e){return e<0})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};o=(i=n.quantizeWeight)<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(F+': Unexpected semantic, "'+e+'".');if(a.some(function(e){return e<-1})||s.some(function(e){return e>1}))return r.warn(F+": Skipping "+e+"; out of supported range."),{bits:-1};i=n.quantizeGeneric,o=o=a.some(function(e){return e<0})?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:o}}var W={tolerance:1e-4};function D(e,t){if(["STEP","LINEAR"].includes(e.getInterpolation())){for(var r,n=e.getInput().clone(),i=e.getOutput().clone(),o=t.tolerance,a=n.getCount()-1,s=[],u=1,l=1;l<a;++l){var f=n.getScalar(l),c=n.getScalar(l-1),g=n.getScalar(l+1),p=(f-c)/(g-c),d=!1;if(f!==g&&(1!==l||f!==n.getScalar(0)))for(var v=0;v<i.getElementSize();v++){var m=i.getElement(l,s)[v],h=i.getElement(l-1,s)[v],y=i.getElement(l+1,s)[v];if("LINEAR"===e.getInterpolation()){if(Math.abs(m-(h*(1-(r=p))+y*r))>o){d=!0;break}}else if("STEP"===e.getInterpolation()&&(m!==h||m!==y)){d=!0;break}}d&&(l!==u&&(n.setScalar(u,n.getScalar(l)),i.setElement(u,i.getElement(l,s))),u++)}a>0&&(n.setScalar(u,n.getScalar(a)),i.setElement(u,i.getElement(a,s)),u++),u!==n.getCount()?(n.setArray(n.getArray().slice(0,u)),i.setArray(i.getArray().slice(0,u*i.getElementSize())),e.setInput(n),e.setOutput(i)):(n.dispose(),i.dispose())}}var X={name:"",fps:10,pattern:/.*/,sort:!0},H="tangents",Z={overwrite:!1};function K(t,r,n,i,o){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!o?(r.debug(H+": Skipping primitive "+i+' of mesh "'+n+'": TANGENT found.'),!1):!t.getIndices()||(r.warn(H+": Skipping primitive "+i+' of mesh "'+n+'": primitives must be unwelded.'),!1):(r.debug(H+": Skipping primitive "+i+' of mesh "'+n+'": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.'),!1)}var Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function J(e,t,r){if(!e.s){if(r instanceof Y){if(!r.s)return void(r.o=J.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(J.bind(null,e,t),J.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Y=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var o=1&i?t:r;if(o){try{J(n,1,o(this.v))}catch(e){J(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?J(n,1,t?t(i):i):r?J(n,1,r(i)):J(n,2,i)}catch(e){J(n,2,e)}},n},e}();function $(e){return e instanceof Y&&1&e.s}var ee,te="textureResize";(ee=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",ee.LANCZOS2="lanczos2";var re={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},ne={};function ie(e,t,r,n){if(n.has(e)&&n.get(e).has(t))return r.debug('unweld: Cache hit for reused attribute, "'+e.getName()+'".'),n.get(e).get(t);var i=e.clone(),o=e.getArray().constructor;i.setArray(new o(t.getCount()*e.getElementSize()));for(var a=[],s=0;s<t.getCount();s++)i.setElement(s,e.getElement(t.getScalar(s),a));return n.has(e)||n.set(e,new Map),n.get(e).set(t,i),i}var oe={tolerance:1e-4};function ae(t,r){if(!r.getIndices()){for(var n=r.listAttributes()[0],i=n.getCount(),o=n.getBuffer(),a=i<=65534?new Uint16Array(3*d(r)):new Uint32Array(3*d(r)),s=t.createAccessor().setBuffer(o).setType(e.Accessor.Type.SCALAR).setArray(a),u=0;u<s.getCount();u++)s.setScalar(u,u);r.setIndices(s)}}function se(e,t,r){var n=Math.max(r.tolerance,Number.EPSILON),i=Math.log10(1/n),o=Math.pow(10,i),a={},s=t.getIndices(),u=s?s.getCount():t.listAttributes()[0].getCount(),f=new Map;t.listAttributes().forEach(function(e){return f.set(e,[])}),t.listTargets().forEach(function(e){e.listAttributes().forEach(function(e){return f.set(e,[])})});for(var c=[],g=0,p=0;p<u;p++){for(var d,v=s?s.getScalar(p):p,m=[],h=[],y=l(t.listAttributes());!(d=y()).done;)for(var A=d.value,b=0;b<A.getElementSize();b++)m.push(~~(A.getElement(v,h)[b]*o));var S=m.join("|");if(S in a)c.push(a[S]);else{for(var T,E=l(t.listAttributes());!(T=E()).done;){var I=T.value;f.get(I).push(I.getElement(v,[]))}for(var w,R=l(t.listTargets());!(w=R()).done;)for(var N,P=l(w.value.listAttributes());!(N=P()).done;){var M=N.value;f.get(M).push(M.getElement(v,[]))}a[S]=g,c.push(g),g++}}var x=t.listAttributes()[0].getCount(),C=f.get(t.getAttribute("POSITION")).length;e.getLogger().debug("weld: "+x+" → "+C+" vertices.");for(var O,z=l(t.listAttributes());!(O=z()).done;){var L=O.value;le(t,L,f.get(L)),1===L.listParents().length&&L.dispose()}for(var U,F=l(t.listTargets());!(U=F()).done;)for(var _,k=U.value,q=l(k.listAttributes());!(_=q()).done;){var G=_.value;le(k,G,f.get(G)),1===G.listParents().length&&G.dispose()}if(s){var B=ue(s.getArray(),c.length);B.set(c),t.setIndices(s.clone().setArray(B)),1===s.listParents().length&&s.dispose()}else{var j=x<=65534?new Uint16Array(c):new Uint32Array(c);t.setIndices(e.createAccessor().setArray(j))}}function ue(e,t){return new(0,e.constructor)(t)}function le(e,t,r){for(var n=r.length*t.getElementSize(),i=ue(t.getArray(),n),o=t.clone().setArray(i),a=0;a<r.length;a++)o.setElement(a,r[a]);e.swap(t,o)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.QUANTIZE_DEFAULTS=k,exports.TEXTURE_RESIZE_DEFAULTS=re,exports.center=function(t){void 0===t&&(t=c);var r=s({},c,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=i.listAnimations().length>0||i.listSkins().length>0;t.getRoot().listScenes().forEach(function(a,s){var u;if(n.debug(f+": Scene "+(s+1)+" / "+i.listScenes().length+"."),"string"==typeof r.pivot){var l=e.bounds(a);u=[(l.max[0]-l.min[0])/2+l.min[0],(l.max[1]-l.min[1])/2+l.min[1],(l.max[2]-l.min[2])/2+l.min[2]],"above"===r.pivot&&(u[1]=l.max[1]),"below"===r.pivot&&(u[1]=l.min[1])}else u=r.pivot;n.debug(f+': Pivot "'+u.join(", ")+'".');var c=[-1*u[0],-1*u[1],-1*u[2]];if(o){n.debug(f+": Model contains animation or skin. Adding a wrapper node.");var g=t.createNode("Pivot").setTranslation(c);a.listChildren().forEach(function(e){return g.addChild(e)}),a.addChild(g)}else n.debug(f+": Skipping wrapper, offsetting all root nodes."),a.listChildren().forEach(function(e){var t=e.getTranslation();e.setTranslation([t[0]+c[0],t[1]+c[1],t[2]+c[2]])})}),n.debug(f+": Complete.")}},exports.colorspace=function(e){return function(t){var r=t.getLogger();if("linear"!==e.inputEncoding)if("sRGB"===e.inputEncoding){var n=new Set;t.getRoot().listMeshes().forEach(function(e){return e.listPrimitives().forEach(o)}),r.debug("colorspace: Complete.")}else r.error('colorspace: Unknown input encoding "'+e.inputEncoding+'" – should be "sRGB" or "linear". Skipping conversion.');else r.info("colorspace: Vertex colors already linear. Skipping conversion.");function i(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function o(e){for(var t,r=[0,0,0],o=0;t=e.getAttribute("COLOR_"+o);o++)if(!n.has(t)){for(var a=0;a<t.getCount();a++)t.getElement(a,r),r[0]=i(r[0]),r[1]=i(r[1]),r[2]=i(r[2]),t.setElement(a,r);n.add(t)}}}},exports.dedup=function(t){void 0===t&&(t=g);for(var r,n=s({},g,t),i=new Set(n.propertyTypes),o=l(n.propertyTypes);!(r=o()).done;){var a=r.value;if(!g.propertyTypes.includes(a))throw new Error('dedup: Unsupported deduplication on type "'+a+'".')}return function(t){var r=t.getLogger();i.has(e.PropertyType.ACCESSOR)&&function(t,r){var n=new Set,i=new Set,o=r.getRoot().listMeshes();function a(t){for(var r=new Map,n=0;n<t.length;n++){var i=t[n],o=i.getArray().slice().buffer;if(!r.has(i))for(var a=0;a<t.length;a++){var s=t[a];i!==s&&(r.has(s)||i.getType()===s.getType()&&i.getComponentType()===s.getComponentType()&&i.getCount()===s.getCount()&&i.getNormalized()===s.getNormalized()&&e.BufferUtils.equals(o,s.getArray().slice().buffer)&&r.set(s,i))}}return r}o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(e){return i.add(e)});var t=e.getIndices();t&&n.add(t)})});var s=a(Array.from(n));t.debug("dedup: Found "+s.size+" duplicates among "+n.size+" indices.");var u=a(Array.from(i));t.debug("dedup: Found "+u.size+" duplicates among "+i.size+" attributes."),o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(t){u.has(t)&&e.swap(t,u.get(t))});var t=e.getIndices();t&&s.has(t)&&e.swap(t,s.get(t))})}),Array.from(s.keys()).forEach(function(e){return e.dispose()}),Array.from(u.keys()).forEach(function(e){return e.dispose()})}(r,t),i.has(e.PropertyType.MESH)&&function(t,r){var n=r.getRoot(),i=new Map;n.listAccessors().forEach(function(e,t){i.set(e,t)});for(var o,a=n.listMeshes().length,s=new Map,u=function(){for(var t,r=o.value,n=[],a=l(r.listPrimitives());!(t=a()).done;){for(var u,f=t.value,c=[],g=l(f.listSemantics());!(u=g()).done;){var p=u.value,d=f.getAttribute(p);c.push(p+":"+i.get(d))}var v=f.getIndices();v&&c.push("indices:"+i.get(v)),n.push(c.join(","))}var m=n.join(";");if(s.has(m)){var h=s.get(m);r.listParents().forEach(function(t){t.propertyType!==e.PropertyType.ROOT&&t.swap(r,h)}),r.dispose()}else s.set(m,r)},f=l(n.listMeshes());!(o=f()).done;)u();t.debug("dedup: Found "+(a-s.size)+" duplicates among "+a+" meshes.")}(r,t),i.has(e.PropertyType.TEXTURE)&&function(t,r){for(var n=r.getRoot(),i=n.listTextures(),o=new Map,a=0;a<i.length;a++){var s=i[a],u=s.getImage();if(!o.has(s))for(var l=0;l<i.length;l++){var f=i[l],c=f.getImage();if(s!==f&&!o.has(f)&&s.getMimeType()===f.getMimeType()){var g=s.getSize(),p=f.getSize();g&&p&&g[0]===p[0]&&g[1]===p[1]&&u&&c&&e.BufferUtils.equals(u,c)&&o.set(f,s)}}}t.debug("dedup: Found "+o.size+" duplicates among "+n.listTextures().length+" textures."),Array.from(o.entries()).forEach(function(t){var r=t[0],n=t[1];r.listParents().forEach(function(t){t instanceof e.Material&&t.swap(r,n)}),r.dispose()})}(r,t),r.debug("dedup: Complete.")}},exports.inspect=function(e){return{scenes:v(e),meshes:m(e),materials:h(e),textures:y(e),animations:A(e)}},exports.instance=function(t){return void 0===t&&(t=I),s({},I,t),function(t){var n=t.getLogger(),i=t.getRoot(),o=t.createExtension(r.MeshGPUInstancing);if(i.listAnimations().length)throw new Error(E+": Instancing is not currently supported for animated models.");for(var a,s=0,u=0,f=function(){var r=a.value,i=new Map;r.traverse(function(e){var t=e.getMesh();t&&i.set(t,(i.get(t)||new Set).add(e))});for(var l=[],f=0,c=Array.from(i.keys());f<c.length;f++){var g=c[f],p=Array.from(i.get(g));if(!(p.length<2||p.some(function(e){return e.getSkin()}))){var d=R(t,o,g,p.length),v=d.getAttribute("TRANSLATION"),m=d.getAttribute("ROTATION"),h=d.getAttribute("SCALE"),y=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",d);r.addChild(y);for(var A=!1,b=!1,S=!1,T=0;T<p.length;T++){var E,I,N,P=p[T];v.setElement(T,E=P.getWorldTranslation()),m.setElement(T,I=P.getWorldRotation()),h.setElement(T,N=P.getWorldScale()),e.MathUtils.eq(E,[0,0,0])||(A=!0),e.MathUtils.eq(I,[0,0,0,1])||(b=!0),e.MathUtils.eq(N,[1,1,1])||(S=!0),P.setMesh(null),l.push(P)}A||v.dispose(),b||m.dispose(),S||h.dispose(),w(l,n),s++,u+=p.length}}},c=l(i.listScenes());!(a=c()).done;)f();s>0?n.info(E+": Created "+s+" batches, with "+u+" total instances."):(n.info(E+": No meshes with multiple parent nodes were found."),o.dispose()),n.debug(E+": Complete.")}},exports.metalRough=function(e){return void 0===e&&(e=C),s({},C,e),function(e){try{var t=function(){s.dispose();for(var e,t=l(u);!(e=t()).done;){var r=e.value;r&&1===r.listParents().length&&r.dispose()}n.debug("metalRough: Complete.")},n=e.getLogger(),i=r.MaterialsPBRSpecularGlossiness.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(function(e){return e.extensionName}).includes(i))return n.warn("metalRough: Extension "+i+" not found on given document."),Promise.resolve();var o=e.createExtension(r.MaterialsIOR),a=e.createExtension(r.MaterialsSpecular),s=e.createExtension(r.MaterialsPBRSpecularGlossiness),u=new Set,f=function(e,t,r){if("function"==typeof e[N]){var n,i,o,a=e[N]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!x(r))return void r.then(e,o||(o=P.bind(null,i=new M,2)));r=r.v}i?P(i,1,r):i=r}catch(e){P(i||(i=new M),2,e)}}(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(s,function(e){throw s(e)});s()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,r){var n,i,o=-1;return function r(a){try{for(;++o<e.length;)if((a=t(o))&&a.then){if(!x(a))return void a.then(r,i||(i=P.bind(null,n=new M,2)));a=a.v}n?P(n,1,a):n=a}catch(e){P(n||(n=new M),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listMaterials(),function(t){function r(){t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}var n=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(n){var i=a.createSpecular().setSpecularFactor(1).setSpecularColorFactor(n.getSpecularFactor());u.add(n.getSpecularGlossinessTexture()),u.add(t.getBaseColorTexture()),u.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(n.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",o.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);var s=n.getDiffuseTexture();s&&(t.setBaseColorTexture(s),t.getBaseColorTextureInfo().copy(n.getDiffuseTextureInfo()));var l=n.getSpecularGlossinessTexture(),f=function(){if(l){var r=n.getSpecularGlossinessTextureInfo(),o=e.createTexture();return Promise.resolve(p(l,o,function(e,t,r){e.set(t,r,3,255)})).then(function(){i.setSpecularTexture(o),i.getSpecularTextureInfo().copy(r);var a=n.getGlossinessFactor(),s=e.createTexture();return Promise.resolve(p(l,s,function(e,t,r){var n=255-Math.round(e.get(t,r,3)*a);e.set(t,r,0,0),e.set(t,r,1,n),e.set(t,r,2,0),e.set(t,r,3,255)})).then(function(){t.setMetallicRoughnessTexture(s),t.getMetallicRoughnessTextureInfo().copy(r)})})}i.setSpecularColorFactor(n.getSpecularFactor()),t.setRoughnessFactor(1-n.getGlossinessFactor())}();return f&&f.then?f.then(r):r()}});return Promise.resolve(f&&f.then?f.then(t):t())}catch(e){return Promise.reject(e)}}},exports.partition=function(e){void 0===e&&(e=z);var t=s({},z,e);return function(e){var r=e.getLogger();!1!==t.meshes&&function(e,t,r){var n=new Set(e.getRoot().listBuffers().map(function(e){return e.getURI()}));e.getRoot().listMeshes().forEach(function(i,o){if(!Array.isArray(r.meshes)||r.meshes.includes(i.getName())){t.debug(O+': Creating buffer for mesh "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(L(i.getName()||"mesh",n));i.listPrimitives().forEach(function(e){var t=e.getIndices();t&&t.setBuffer(a),e.listAttributes().forEach(function(e){return e.setBuffer(a)}),e.listTargets().forEach(function(e){e.listAttributes().forEach(function(e){return e.setBuffer(a)})})})}else t.debug(O+": Skipping mesh #"+o+' with name "'+i.getName()+'".')})}(e,r,t),!1!==t.animations&&function(e,t,r){var n=new Set(e.getRoot().listBuffers().map(function(e){return e.getURI()}));e.getRoot().listAnimations().forEach(function(i,o){if(!Array.isArray(r.animations)||r.animations.includes(i.getName())){t.debug(O+': Creating buffer for animation "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(L(i.getName()||"animation",n));i.listSamplers().forEach(function(e){var t=e.getInput(),r=e.getOutput();t&&t.setBuffer(a),r&&r.setBuffer(a)})}else t.debug(O+": Skipping animation #"+o+' with name "'+i.getName()+'".')})}(e,r,t),t.meshes||t.animations||r.warn(O+": Select animations or meshes to create a partition."),r.debug(O+": Complete.")}},exports.prune=function(t){return void 0===t&&(t=U),s({},U,t),function(t){var r=t.getLogger(),n=t.getRoot(),i=t.getGraph(),o={};n.listNodes().forEach(v),n.listSkins().forEach(v),n.listMeshes().forEach(v),n.listCameras().forEach(v),m(i,e.PropertyType.PRIMITIVE),m(i,e.PropertyType.PRIMITIVE_TARGET);for(var a,s=l(n.listAnimations());!(a=s()).done;){for(var u,f=a.value,c=l(f.listChannels());!(u=c()).done;){var g=u.value;g.getTargetNode()||(g.dispose(),h(g))}if(f.listChannels().length)f.listSamplers().forEach(v);else{var p=f.listSamplers();v(f),p.forEach(v)}}if(n.listMaterials().forEach(v),n.listTextures().forEach(v),n.listAccessors().forEach(v),n.listBuffers().forEach(v),Object.keys(o).length){var d=Object.keys(o).map(function(e){return e+" ("+o[e]+")"}).join(", ");r.info("prune: Removed types... "+d)}else r.info("prune: No unused properties found.");function v(t){t.listParents().filter(function(t){return!(t instanceof e.Root||t instanceof e.AnimationChannel)}).length||(t.dispose(),h(t))}function m(e,t){e.getLinks().map(function(e){return e.getParent()}).filter(function(e){return e.propertyType===t}).forEach(v)}function h(e){o[e.propertyType]=o[e.propertyType]||0,o[e.propertyType]++}r.debug("prune: Complete.")}},exports.quantize=function(t){void 0===t&&(t=k);var n=s({},k,t);return function(t){var i=t.getLogger(),o=t.getRoot();t.createExtension(r.MeshQuantization).setRequired(!0);var a=void 0;"scene"===n.quantizationVolume&&(1!==o.listScenes().length?i.warn("[quantize]: quantizationVolume=scene requires exactly 1 scene."):a=e.bounds(o.listScenes().pop()));for(var s,u=l(t.getRoot().listMeshes());!(s=u()).done;){var f=s.value;if(f.listPrimitives().some(function(e){return e.getAttribute("JOINTS_0")}))i.warn(F+": Quantization for skinned mesh not yet implemented.");else{var c=G(f,a);c&&B(t,f,c);for(var g,p=l(f.listPrimitives());!(g=p()).done;){var d=g.value;q(t,d,c,n);for(var v,m=l(d.listTargets());!(v=m()).done;)q(t,v.value,c,n)}}}i.debug(F+": Complete.")}},exports.resample=function(t){void 0===t&&(t=W);var r=s({},W,t);return function(t){for(var n,i=new Set,o=t.getRoot().listAccessors().length,a=t.getLogger(),s=l(t.getRoot().listAnimations());!(n=s()).done;)for(var u,f=l(n.value.listSamplers());!(u=f()).done;){var c=u.value;"STEP"!==c.getInterpolation()&&"LINEAR"!==c.getInterpolation()||(i.add(c.getInput()),i.add(c.getOutput()),D(c,r))}for(var g=0,p=Array.from(i.values());g<p.length;g++){var d=p[g];d.listParents().find(function(t){return!(t instanceof e.Root)})||d.dispose()}t.getRoot().listAccessors().length>o&&a.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a.debug("resample: Complete.")}},exports.sequence=function(t){void 0===t&&(t=X);var r=s({},X,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=r.fps,a=i.listNodes().filter(function(e){return e.getName().match(r.pattern)});r.sort&&a.sort(function(e,t){return e.getName()>t.getName()?1:-1});var s=t.createAnimation(r.name),u=i.listBuffers()[0];a.forEach(function(r,n){var i,l;0===n?(i=[n/o,(n+1)/o],l=[1,1,1,0,0,0]):n===a.length-1?(i=[(n-1)/o,n/o],l=[0,0,0,1,1,1]):(i=[(n-1)/o,n/o,(n+1)/o],l=[0,0,0,1,1,1,0,0,0]);var f=t.createAccessor().setArray(new Float32Array(i)).setBuffer(u),c=t.createAccessor().setArray(new Float32Array(l)).setBuffer(u).setType(e.Accessor.Type.VEC3),g=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(f).setOutput(c),p=t.createAnimationChannel().setTargetNode(r).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(g);s.addSampler(g).addChannel(p)}),n.debug("sequence: Complete.")}},exports.tangents=function(t){if(void 0===t&&(t=Z),!t.generateTangents)throw new Error(H+': generateTangents callback required — install "mikktspace".');var r=s({},Z,t);return function(t){for(var n,i=t.getLogger(),o=new Map,a=new Map,s=0,u=l(t.getRoot().listMeshes());!(n=u()).done;)for(var f=n.value,c=f.getName(),g=f.listPrimitives(),p=0;p<g.length;p++){var d=g[p];if(K(d,i,c,p,r.overwrite)){var v=d.getAttribute("POSITION").getArray(),m=d.getAttribute("NORMAL").getArray(),h=d.getAttribute("TEXCOORD_0").getArray(),y=o.get(v)||e.uuid();o.set(v,y);var A=o.get(m)||e.uuid();o.set(m,A);var b=o.get(h)||e.uuid();o.set(h,b);var S=d.getAttribute("TANGENT");S&&2===S.listParents().length&&S.dispose();var T=y+"|"+A+"|"+b,E=a.get(T);if(E)i.debug(H+": Found cache for primitive "+p+' of mesh "'+c+'".'),d.setAttribute("TANGENT",E),s++;else{i.debug(H+": Generating for primitive "+p+' of mesh "'+c+'".');for(var I=d.getAttribute("POSITION").getBuffer(),w=r.generateTangents(v instanceof Float32Array?v:new Float32Array(v),m instanceof Float32Array?m:new Float32Array(m),h instanceof Float32Array?h:new Float32Array(h)),R=3;R<w.length;R+=4)w[R]*=-1;E=t.createAccessor().setBuffer(I).setArray(w).setType("VEC4"),d.setAttribute("TANGENT",E),a.set(T,E),s++}}}s?i.debug(H+": Complete."):i.warn(H+": No qualifying primitives found. See debug output.")}},exports.textureResize=function(e){void 0===e&&(e=re);var r=s({},re,e);return function(e){try{var n=function(){o.debug(te+": Complete.")},o=e.getLogger(),s=function(e,t,r){if("function"==typeof e[Q]){var n,i,o,a=e[Q]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!$(r))return void r.then(e,o||(o=J.bind(null,i=new Y,2)));r=r.v}i?J(i,1,r):i=r}catch(e){J(i||(i=new Y),2,e)}}(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(s,function(e){throw s(e)});s()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,r){var n,i,o=-1;return function r(a){try{for(;++o<e.length;)if((a=t(o))&&a.then){if(!$(a))return void a.then(r,i||(i=J.bind(null,n=new Y,2)));a=a.v}n?J(n,1,a):n=a}catch(e){J(n||(n=new Y),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listTextures(),function(e){var n=e.getName(),s=e.getURI();if(!r.pattern||r.pattern.test(n)||r.pattern.test(s))if("image/png"===e.getMimeType()||"image/jpeg"===e.getMimeType()){var u=r.size,l=u[0],f=u[1],c=e.getSize(),g=c[0],p=c[1];if(!(g<=l&&p<=f)){var d=g,v=p;d>l&&(d=l,v=Math.floor(v*(d/g))),v>f&&(v=f,d=Math.floor(d*(v/p)));var m=new Uint8Array(e.getImage());return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(u){var l=a.default(new Uint8Array(d*v*4),[d,v,4]);o.debug(te+': Resizing "'+(s||n)+'", '+u.shape+" → "+l.shape+"...");try{r.filter===exports.TextureResizeFilter.LANCZOS3?i.lanczos3(u,l):i.lanczos2(u,l)}catch(e){return void o.warn(te+': Failed to resize "'+(s||n)+'": "'+e.message+'".')}var f=e.setImage;return Promise.resolve(t.savePixels(l,e.getMimeType())).then(function(t){f.call(e,t.buffer)})})}o.debug(te+': Skipping "'+(s||n)+'", within size range.')}else o.warn('Skipping unsupported texture type, "'+e.getMimeType()+'".')});return Promise.resolve(s&&s.then?s.then(n):n())}catch(e){return Promise.reject(e)}}},exports.unweld=function(e){return void 0===e&&(e=ne),s({},ne,e),function(e){for(var t,r=e.getLogger(),n=new Map,i=l(e.getRoot().listMeshes());!(t=i()).done;)for(var o,a=l(t.value.listPrimitives());!(o=a()).done;){var s=o.value,u=s.getIndices();if(u){for(var f,c=l(s.listAttributes());!(f=c()).done;){var g=f.value;s.swap(g,ie(g,u,r,n)),1===g.listParents().length&&g.dispose()}for(var p,d=l(s.listTargets());!(p=d()).done;)for(var v,m=p.value,h=l(m.listAttributes());!(v=h()).done;){var y=v.value;m.swap(y,ie(y,u,r,n)),1===y.listParents().length&&y.dispose()}s.setIndices(null),1===u.listParents().length&&u.dispose()}}r.debug("unweld: Complete.")}},exports.weld=function(e){void 0===e&&(e=oe);var t=s({},oe,e);return function(e){for(var r,n=e.getLogger(),i=l(e.getRoot().listMeshes());!(r=i()).done;)for(var o,a=l(r.value.listPrimitives());!(o=a()).done;){var s=o.value;0===t.tolerance?ae(e,s):se(e,s,t)}n.debug("weld: Complete.")}};
//# sourceMappingURL=functions.js.map

@@ -1,2 +0,2 @@

import{bounds as e,PropertyType as t,BufferUtils as n,Material as s,Primitive as o,Texture as r,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,Root as g,AnimationChannel as u,Animation as f,Accessor as p,AnimationSampler as m,uuid as d}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as h,savePixels as A}from"ndarray-pixels";import{MeshGPUInstancing as y,MaterialsIOR as E,MaterialsSpecular as S,MaterialsPBRSpecularGlossiness as T,MeshQuantization as b}from"@gltf-transform/extensions";import I from"ndarray";import{lanczos3 as N,lanczos2 as w}from"ndarray-lanczos";function R(){return(R=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e}).apply(this,arguments)}const M={pivot:"center"};function C(t=M){const n=R({},M,t);return t=>{const s=t.getLogger(),o=t.getRoot(),r=o.listAnimations().length>0||o.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${o.listScenes().length}.`),"string"==typeof n.pivot){const t=e(i);c=[(t.max[0]-t.min[0])/2+t.min[0],(t.max[1]-t.min[1])/2+t.min[1],(t.max[2]-t.min[2])/2+t.min[2]],"above"===n.pivot&&(c[1]=t.max[1]),"below"===n.pivot&&(c[1]=t.min[1])}else c=n.pivot;s.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(r){s.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(l);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else s.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(e=>{const t=e.getTranslation();e.setTranslation([t[0]+l[0],t[1]+l[1],t[2]+l[2]])})}),s.debug("center: Complete.")}}function O(e){return t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info("colorspace: Vertex colors already linear. Skipping conversion.");if("sRGB"!==e.inputEncoding)return void n.error(`colorspace: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const s=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function r(e){const t=[0,0,0];let n;for(let r=0;n=e.getAttribute(`COLOR_${r}`);r++)if(!s.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);s.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(r)),n.debug("colorspace: Complete.")}}const x={propertyTypes:[t.ACCESSOR,t.MESH,t.TEXTURE]},P=function(e=x){const o=R({},x,e),r=new Set(o.propertyTypes);for(const e of o.propertyTypes)if(!x.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return e=>{const o=e.getLogger();r.has(t.ACCESSOR)&&function(e,t){const s=new Set,o=new Set,r=t.getRoot().listMeshes();function i(e){const t=new Map;for(let s=0;s<e.length;s++){const o=e[s],r=o.getArray().slice().buffer;if(!t.has(o))for(let s=0;s<e.length;s++){const i=e[s];o!==i&&(t.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&n.equals(r,i.getArray().slice().buffer)&&t.set(i,o))}}return t}r.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&s.add(t)})});const a=i(Array.from(s));e.debug(`dedup: Found ${a.size} duplicates among ${s.size} indices.`);const c=i(Array.from(o));e.debug(`dedup: Found ${c.size} duplicates among ${o.size} attributes.`),r.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{c.has(t)&&e.swap(t,c.get(t))});const t=e.getIndices();t&&a.has(t)&&e.swap(t,a.get(t))})}),Array.from(a.keys()).forEach(e=>e.dispose()),Array.from(c.keys()).forEach(e=>e.dispose())}(o,e),r.has(t.MESH)&&function(e,n){const s=n.getRoot(),o=new Map;s.listAccessors().forEach((e,t)=>{o.set(e,t)});const r=s.listMeshes().length,i=new Map;for(const e of s.listMeshes()){const n=[];for(const t of e.listPrimitives()){const e=[];for(const n of t.listSemantics()){const s=t.getAttribute(n);e.push(n+":"+o.get(s))}const s=t.getIndices();s&&e.push("indices:"+o.get(s)),n.push(e.join(","))}const s=n.join(";");if(i.has(s)){const n=i.get(s);e.listParents().forEach(s=>{s.propertyType!==t.ROOT&&s.swap(e,n)}),e.dispose()}else i.set(s,e)}e.debug(`dedup: Found ${r-i.size} duplicates among ${r} meshes.`)}(o,e),r.has(t.TEXTURE)&&function(e,t){const o=t.getRoot(),r=o.listTextures(),i=new Map;for(let e=0;e<r.length;e++){const t=r[e],s=t.getImage();if(!i.has(t))for(let e=0;e<r.length;e++){const o=r[e],a=o.getImage();if(t===o)continue;if(i.has(o))continue;if(t.getMimeType()!==o.getMimeType())continue;const c=t.getSize(),l=o.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&s&&a&&n.equals(s,a)&&i.set(o,t)}}e.debug(`dedup: Found ${i.size} duplicates among ${o.listTextures().length} textures.`),Array.from(i.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof s&&n.swap(e,t)}),e.dispose()})}(o,e),o.debug("dedup: Complete.")}};async function z(e,t,n){if(!e)return null;const s=e.getImage();if(!s)return null;const o=await h(new Uint8Array(s),e.getMimeType());for(let e=0;e<o.shape[0];++e)for(let t=0;t<o.shape[1];++t)n(o,e,t);const r=(await A(o,"image/png")).buffer;return t.setImage(r).setMimeType("image/png")}function $(e){const t=e.getIndices(),n=e.getAttribute("POSITION");switch(e.getMode()){case o.Mode.POINTS:return n.getCount();case o.Mode.LINES:return t?t.getCount()/2:n.getCount()/2;case o.Mode.LINE_LOOP:return n.getCount();case o.Mode.LINE_STRIP:return n.getCount()-1;case o.Mode.TRIANGLES:return t?t.getCount()/3:n.getCount()/3;case o.Mode.TRIANGLE_STRIP:case o.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+e.getMode())}}function L(e){return{scenes:v(e),meshes:q(e),materials:k(e),textures:F(e),animations:_(e)}}function v(t){return{properties:t.getRoot().listScenes().map(t=>{const n=t.listChildren()[0],s=e(t);return{name:t.getName(),rootName:n?n.getName():"",bboxMin:U(s.min),bboxMax:U(s.max)}})}}function q(e){return{properties:e.getRoot().listMeshes().map(e=>{const t=e.listParents().filter(e=>"Root"!==e.propertyType).length;let n=0,s=0;const o=new Set,r=new Set,i=new Set;e.listPrimitives().forEach(e=>{for(const t of e.listSemantics()){const n=e.getAttribute(t);o.add(t+":"+B(n.getArray())),i.add(n)}for(const t of e.listTargets())t.listAttributes().forEach(e=>i.add(e));const t=e.getIndices();t&&(r.add(B(t.getArray())),i.add(t)),s+=e.listAttributes()[0].getCount(),n+=$(e)});let a=0;Array.from(i).forEach(e=>a+=e.getArray().byteLength);const c=e.listPrimitives().map(e=>G[e.getMode()]);return{name:e.getName(),mode:Array.from(new Set(c)),primitives:e.listPrimitives().length,glPrimitives:n,vertices:s,indices:Array.from(r).sort(),attributes:Array.from(o).sort(),instances:t,size:a}})}}function k(e){return{properties:e.getRoot().listMaterials().map(t=>{const n=t.listParents().filter(e=>"Root"!==e.propertyType).length,s=new Set(t.listExtensions()),o=e.getGraph().getLinks().filter(e=>{const n=e.getChild(),o=e.getParent();return n instanceof r&&o===t||!!(n instanceof r&&o instanceof i&&s.has(o))}).map(e=>e.getName());return{name:t.getName(),instances:n,textures:o,alphaMode:t.getAlphaMode(),doubleSided:t.getDoubleSided()}})}}function F(e){return{properties:e.getRoot().listTextures().map(t=>{const n=t.listParents().filter(e=>"Root"!==e.propertyType).length,s=e.getGraph().listParentLinks(t).map(e=>e.getName()).filter(e=>"texture"!==e),o=a.getSize(t.getImage(),t.getMimeType());return{name:t.getName(),uri:t.getURI(),slots:Array.from(new Set(s)),instances:n,mimeType:t.getMimeType(),resolution:o?o.join("x"):"",size:t.getImage().byteLength,gpuSize:a.getMemSize(t.getImage(),t.getMimeType())}})}}function _(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const s=e.getInput();s&&(t=Math.min(t,s.getMin([])[0]),n=Math.max(n,s.getMax([])[0]))});let s=0,o=0;const r=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),r.add(t),n&&r.add(n))}),Array.from(r).forEach(e=>{s+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:s}})}}const G=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function U(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function B(e){return e.constructor.name.replace("Array","").toLowerCase()}const j={};function V(e=j){return R({},j,e),e=>{const t=e.getLogger(),n=e.getRoot(),s=e.createExtension(y);if(n.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let o=0,r=0;for(const i of n.listScenes()){const n=new Map;i.traverse(e=>{const t=e.getMesh();t&&n.set(t,(n.get(t)||new Set).add(e))});const a=[];for(const l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(e=>e.getSkin()))continue;const u=D(e,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=e.createNode().setMesh(l).setExtension("EXT_mesh_gpu_instancing",u);i.addChild(d);let h=!1,A=!1,y=!1;for(let e=0;e<g.length;e++){let t,n,s;const o=g[e];f.setElement(e,t=o.getWorldTranslation()),p.setElement(e,n=o.getWorldRotation()),m.setElement(e,s=o.getWorldScale()),c.eq(t,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(y=!0),o.setMesh(null),a.push(o)}h||f.dispose(),A||p.dispose(),y||m.dispose(),W(a,t),o++,r+=g.length}}o>0?t.info(`instance: Created ${o} batches, with ${r} total instances.`):(t.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),t.debug("instance: Complete.")}}function W(e,t){let n,s=0;for(;n=e.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const t=n.getParent();t instanceof l&&e.push(t),n.dispose(),s++}t.debug(`instance: Removed ${s} unused nodes.`)}function D(e,t,n,s){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),r=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*s)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",r).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const X={};function H(e=X){return R({},X,e),async e=>{const t=e.getLogger(),n=T.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes(n))return void t.warn(`metalRough: Extension ${n} not found on given document.`);const s=e.createExtension(E),o=e.createExtension(S),r=e.createExtension(T),i=new Set;for(const t of e.getRoot().listMaterials()){const n=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!n)continue;const r=o.createSpecular().setSpecularFactor(1).setSpecularColorFactor(n.getSpecularFactor());i.add(n.getSpecularGlossinessTexture()),i.add(t.getBaseColorTexture()),i.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(n.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",s.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",r);const a=n.getDiffuseTexture();a&&(t.setBaseColorTexture(a),t.getBaseColorTextureInfo().copy(n.getDiffuseTextureInfo()));const c=n.getSpecularGlossinessTexture();if(c){const s=n.getSpecularGlossinessTextureInfo(),o=e.createTexture();await z(c,o,(e,t,n)=>{e.set(t,n,3,255)}),r.setSpecularTexture(o),r.getSpecularTextureInfo().copy(s);const i=n.getGlossinessFactor(),a=e.createTexture();await z(c,a,(e,t,n)=>{const s=255-Math.round(e.get(t,n,3)*i);e.set(t,n,0,0),e.set(t,n,1,s),e.set(t,n,2,0),e.set(t,n,3,255)}),t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(s)}else r.setSpecularColorFactor(n.getSpecularFactor()),t.setRoughnessFactor(1-n.getGlossinessFactor());t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}r.dispose();for(const e of i)e&&1===e.listParents().length&&e.dispose();t.debug("metalRough: Complete.")}}const K={animations:!0,meshes:!0},Z=(e=K)=>{const t=R({},K,e);return e=>{const n=e.getLogger();!1!==t.meshes&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,r)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(J(o.getName()||"mesh",s));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(e,n,t),!1!==t.animations&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,r)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(J(o.getName()||"animation",s));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(e,n,t),t.meshes||t.animations||n.warn("partition: Select animations or meshes to create a partition."),n.debug("partition: Complete.")}};function J(e,t){let n=`${e}.bin`,s=1;for(;t.has(n);)n=`${e}_${s++}.bin`;return n}const Q={},Y=function(e=Q){return R({},Q,e),e=>{const n=e.getLogger(),s=e.getRoot(),o=e.getGraph(),r={};s.listNodes().forEach(i),s.listSkins().forEach(i),s.listMeshes().forEach(i),s.listCameras().forEach(i),a(o,t.PRIMITIVE),a(o,t.PRIMITIVE_TARGET);for(const e of s.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),c(t));if(e.listChannels().length)e.listSamplers().forEach(i);else{const t=e.listSamplers();i(e),t.forEach(i)}}if(s.listMaterials().forEach(i),s.listTextures().forEach(i),s.listAccessors().forEach(i),s.listBuffers().forEach(i),Object.keys(r).length){const e=Object.keys(r).map(e=>`${e} (${r[e]})`).join(", ");n.info(`prune: Removed types... ${e}`)}else n.info("prune: No unused properties found.");function i(e){e.listParents().filter(e=>!(e instanceof g||e instanceof u)).length||(e.dispose(),c(e))}function a(e,t){e.getLinks().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(i)}function c(e){r[e.propertyType]=r[e.propertyType]||0,r[e.propertyType]++}n.debug("prune: Complete.")}},ee=[Int8Array,Int16Array,Int32Array],te={excludeAttributes:[],quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},ne=(t=te)=>{const n=R({},te,t);return t=>{const s=t.getLogger(),o=t.getRoot();let r;t.createExtension(b).setRequired(!0),"scene"===n.quantizationVolume&&(1!==o.listScenes().length?s.warn("[quantize]: quantizationVolume=scene requires exactly 1 scene."):r=e(o.listScenes().pop()));for(const e of t.getRoot().listMeshes()){if(e.listPrimitives().some(e=>e.getAttribute("JOINTS_0"))){s.warn("quantize: Quantization for skinned mesh not yet implemented.");continue}const o=oe(e,r);o&&re(t,e,o);for(const s of e.listPrimitives()){se(t,s,o,n);for(const e of s.listTargets())se(t,e,o,n)}}s.debug("quantize: Complete.")}};function se(e,t,n,s){const r=e.getRoot(),i=e.getLogger(),a=n?n.nodeRemap:null;for(const n of t.listSemantics()){if(s.excludeAttributes.includes(n))continue;const o=t.getAttribute(n),{bits:c,ctor:l}=ae(n,o,i,s);if(!l)continue;if(c<8||c>16)throw new Error("quantize: Requires bits = 8–16.");if(o.getComponentSize()<=c/8)continue;const g=e.getGraph().listParentLinks(o).filter(e=>e.getParent()!==r).map(e=>e.getName());if(new Set(g).size>1)i.warn(`quantize: Skipping ${n}; attribute usage conflict.`);else{if("POSITION"===n){if(!a)throw new Error("quantize: Failed precondition; missing node transform.");for(let e=0,t=[0,0,0],n=o.getCount();e<n;e++)o.setElement(e,a(o.getElement(e,t)))}ie(o,l,c),o.setNormalized(!0)}}if(t instanceof o&&t.getIndices()&&t.listAttributes().length&&t.listAttributes()[0].getCount()<65535){const e=t.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function oe(e,t){const n=e.listPrimitives().map(e=>e.getAttribute("POSITION"));if(!n.some(e=>!!e))return null;let s=[Infinity,Infinity,Infinity],o=[-Infinity,-Infinity,-Infinity];return t?(s=[...t.min],o=[...t.max]):function(e,t,n){const s=n[0].getElementSize();for(let t=0;t<s;t++)e[t]=Infinity;for(let e=0;e<s;e++)t[e]=-Infinity;const o=[],r=[];for(const i of n){i.getMinNormalized(o),i.getMaxNormalized(r);for(let n=0;n<s;n++)e[n]=Math.min(e[n],o[n]),t[n]=Math.max(t[n],r[n])}}(s,o,n),{nodeRemap:e=>[2*(e[0]-s[0])/(o[0]-s[0])-1,2*(e[1]-s[1])/(o[1]-s[1])-1,2*(e[2]-s[2])/(o[2]-s[2])-1],nodeOffset:[s[0]+(o[0]-s[0])/2,s[1]+(o[1]-s[1])/2,s[2]+(o[2]-s[2])/2],nodeScale:[(o[0]-s[0])/2,(o[1]-s[1])/2,(o[2]-s[2])/2]}}function re(e,t,n){const s=n.nodeOffset||[0,0,0],o=n.nodeScale||[1,1,1];for(const n of t.listParents())if(n instanceof l){const r=n.listChildren().length>0,i=!!n.listParents().find(e=>e instanceof f);let a;r||i?(a=e.createNode("").setMesh(t),n.addChild(a).setMesh(null)):a=n;const c=a.getTranslation(),l=a.getScale();a.setTranslation([c[0]+s[0],c[1]+s[1],c[2]+s[2]]).setScale([l[0]*o[0],l[1]*o[1],l[2]*o[2]])}}function ie(e,t,n){const s=new t(e.getArray().length),o=ee.includes(t)?1:0,r=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,r)-1,c=i-r,l=2*r-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>l,s[n++]=t*Math.sign(o[e])}}e.setArray(s)}function ae(e,t,n,s){const o=t.getMinNormalized([]),r=t.getMinNormalized([]);let i,a;if("POSITION"===e)i=s.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=s.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=s.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}const ce={tolerance:1e-4},le=(e=ce)=>{const t=R({},ce,e);return e=>{const n=new Set,s=e.getRoot().listAccessors().length,o=e.getLogger();for(const s of e.getRoot().listAnimations())for(const e of s.listSamplers())"STEP"!==e.getInterpolation()&&"LINEAR"!==e.getInterpolation()||(n.add(e.getInput()),n.add(e.getOutput()),ge(e,t));for(const e of Array.from(n.values()))e.listParents().find(e=>!(e instanceof g))||e.dispose();e.getRoot().listAccessors().length>s&&o.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),o.debug("resample: Complete.")}};function ge(e,t){if(!["STEP","LINEAR"].includes(e.getInterpolation()))return;const n=e.getInput().clone(),s=e.getOutput().clone(),o=t.tolerance,r=n.getCount()-1,i=[];let a=1;for(let t=1;t<r;++t){const r=n.getScalar(t),l=n.getScalar(t-1),g=n.getScalar(t+1),u=(r-l)/(g-l);let f=!1;if(r!==g&&(1!==t||r!==n.getScalar(0)))for(let n=0;n<s.getElementSize();n++){const r=s.getElement(t,i)[n],a=s.getElement(t-1,i)[n],l=s.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(r-(a*(1-(c=u))+l*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(r!==a||r!==l)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),s.setElement(a,s.getElement(t,i))),a++)}var c;r>0&&(n.setScalar(a,n.getScalar(r)),s.setElement(a,s.getElement(r,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),s.setArray(s.getArray().slice(0,a*s.getElementSize())),e.setInput(n),e.setOutput(s)):(n.dispose(),s.dispose())}const ue={name:"",fps:10,pattern:/.*/,sort:!0};function fe(e=ue){const t=R({},ue,e);return e=>{const n=e.getLogger(),s=e.getRoot(),o=t.fps,r=s.listNodes().filter(e=>e.getName().match(t.pattern));t.sort&&r.sort((e,t)=>e.getName()>t.getName()?1:-1);const i=e.createAnimation(t.name),a=s.listBuffers()[0];r.forEach((t,n)=>{let s,c;0===n?(s=[n/o,(n+1)/o],c=[1,1,1,0,0,0]):n===r.length-1?(s=[(n-1)/o,n/o],c=[0,0,0,1,1,1]):(s=[(n-1)/o,n/o,(n+1)/o],c=[0,0,0,1,1,1,0,0,0]);const l=e.createAccessor().setArray(new Float32Array(s)).setBuffer(a),g=e.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(p.Type.VEC3),f=e.createAnimationSampler().setInterpolation(m.Interpolation.STEP).setInput(l).setOutput(g),d=e.createAnimationChannel().setTargetNode(t).setTargetPath(u.TargetPath.SCALE).setSampler(f);i.addSampler(f).addChannel(d)}),n.debug("sequence: Complete.")}}const pe={overwrite:!1};function me(e=pe){if(!e.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const t=R({},pe,e);return e=>{const n=e.getLogger(),s=new Map,o=new Map;let r=0;for(const i of e.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!de(l,n,a,i,t.overwrite))continue;const g=l.getAttribute("POSITION").getArray(),u=l.getAttribute("NORMAL").getArray(),f=l.getAttribute("TEXCOORD_0").getArray(),p=s.get(g)||d();s.set(g,p);const m=s.get(u)||d();s.set(u,m);const h=s.get(f)||d();s.set(f,h);const A=l.getAttribute("TANGENT");A&&2===A.listParents().length&&A.dispose();const y=`${p}|${m}|${h}`;let E=o.get(y);if(E){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",E),r++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),T=t.generateTangents(g instanceof Float32Array?g:new Float32Array(g),u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f));for(let e=3;e<T.length;e+=4)T[e]*=-1;E=e.createAccessor().setBuffer(S).setArray(T).setType("VEC4"),l.setAttribute("TANGENT",E),o.set(y,E),r++}}r?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")}}function de(e,t,n,s,r){return e.getMode()===o.Mode.TRIANGLES&&e.getAttribute("POSITION")&&e.getAttribute("NORMAL")&&e.getAttribute("TEXCOORD_0")?e.getAttribute("TANGENT")&&!r?(t.debug(`tangents: Skipping primitive ${s} of mesh "${n}": TANGENT found.`),!1):!e.getIndices()||(t.warn(`tangents: Skipping primitive ${s} of mesh "${n}": primitives must be unwelded.`),!1):(t.debug(`tangents: Skipping primitive ${s} of mesh "${n}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const he="textureResize";var Ae;!function(e){e.LANCZOS3="lanczos3",e.LANCZOS2="lanczos2"}(Ae||(Ae={}));const ye={size:[2048,2048],filter:Ae.LANCZOS3,pattern:null};function Ee(e=ye){const t=R({},ye,e);return async e=>{const n=e.getLogger();for(const s of e.getRoot().listTextures()){const e=s.getName(),o=s.getURI();if(t.pattern&&!t.pattern.test(e)&&!t.pattern.test(o))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[r,i]=t.size,[a,c]=s.getSize();if(a<=r&&c<=i){n.debug(`${he}: Skipping "${o||e}", within size range.`);continue}let l=a,g=c;l>r&&(l=r,g=Math.floor(g*(l/a))),g>i&&(g=i,l=Math.floor(l*(g/c)));const u=new Uint8Array(s.getImage()),f=await h(u,s.getMimeType()),p=I(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${he}: Resizing "${o||e}", ${f.shape} → ${p.shape}...`);try{t.filter===Ae.LANCZOS3?N(f,p):w(f,p)}catch(t){n.warn(`${he}: Failed to resize "${o||e}": "${t.message}".`);continue}s.setImage((await A(p,s.getMimeType())).buffer)}n.debug(`${he}: Complete.`)}}const Se={};function Te(e=Se){return R({},Se,e),e=>{const t=e.getLogger(),n=new Map;for(const s of e.getRoot().listMeshes())for(const e of s.listPrimitives()){const s=e.getIndices();if(s){for(const o of e.listAttributes())e.swap(o,be(o,s,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,be(e,s,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===s.listParents().length&&s.dispose()}}t.debug("unweld: Complete.")}}function be(e,t,n,s){if(s.has(e)&&s.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),s.get(e).get(t);const o=e.clone(),r=e.getArray().constructor;o.setArray(new r(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return s.has(e)||s.set(e,new Map),s.get(e).set(t,o),o}const Ie={tolerance:1e-4};function Ne(e=Ie){const t=R({},Ie,e);return e=>{const n=e.getLogger();for(const n of e.getRoot().listMeshes())for(const s of n.listPrimitives())0===t.tolerance?we(e,s):Re(e,s,t);n.debug("weld: Complete.")}}function we(e,t){if(t.getIndices())return;const n=t.listAttributes()[0].getBuffer(),s=e.createAccessor().setBuffer(n).setType(p.Type.SCALAR).setArray(new Uint32Array(3*$(t)));for(let e=0;e<s.getCount();e++)s.setScalar(e,e);t.setIndices(s)}function Re(e,t,n){const s=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/s),r=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),l=new Map;t.listAttributes().forEach(e=>l.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>l.set(e,[]))});const g=[];let u=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,s=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)s.push(~~(e.getElement(n,o)[t]*r));const c=s.join("|");if(c in i)g.push(i[c]);else{for(const e of t.listAttributes())l.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())l.get(t).push(t.getElement(n,[]));i[c]=u,g.push(u),u++}}const f=t.listAttributes()[0].getCount(),p=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())Ce(t,e,l.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())Ce(e,t,l.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=Me(a.getArray(),g.length);e.set(g),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else t.setIndices(e.createAccessor().setArray(new Uint32Array(g)))}function Me(e,t){return new(0,e.constructor)(t)}function Ce(e,t,n){const s=n.length*t.getElementSize(),o=Me(t.getArray(),s),r=t.clone().setArray(o);for(let e=0;e<n.length;e++)r.setElement(e,n[e]);e.swap(t,r)}export{te as QUANTIZE_DEFAULTS,ye as TEXTURE_RESIZE_DEFAULTS,Ae as TextureResizeFilter,C as center,O as colorspace,P as dedup,L as inspect,V as instance,H as metalRough,Z as partition,Y as prune,ne as quantize,le as resample,fe as sequence,me as tangents,Ee as textureResize,Te as unweld,Ne as weld};
import{bounds as e,PropertyType as t,BufferUtils as n,Material as s,Primitive as o,Texture as r,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,Root as g,AnimationChannel as u,Animation as f,Accessor as p,AnimationSampler as m,uuid as d}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as h,savePixels as A}from"ndarray-pixels";import{MeshGPUInstancing as y,MaterialsIOR as E,MaterialsSpecular as S,MaterialsPBRSpecularGlossiness as T,MeshQuantization as b}from"@gltf-transform/extensions";import I from"ndarray";import{lanczos3 as N,lanczos2 as w}from"ndarray-lanczos";function R(){return(R=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e}).apply(this,arguments)}const M={pivot:"center"};function C(t=M){const n=R({},M,t);return t=>{const s=t.getLogger(),o=t.getRoot(),r=o.listAnimations().length>0||o.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${o.listScenes().length}.`),"string"==typeof n.pivot){const t=e(i);c=[(t.max[0]-t.min[0])/2+t.min[0],(t.max[1]-t.min[1])/2+t.min[1],(t.max[2]-t.min[2])/2+t.min[2]],"above"===n.pivot&&(c[1]=t.max[1]),"below"===n.pivot&&(c[1]=t.min[1])}else c=n.pivot;s.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(r){s.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(l);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else s.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(e=>{const t=e.getTranslation();e.setTranslation([t[0]+l[0],t[1]+l[1],t[2]+l[2]])})}),s.debug("center: Complete.")}}function O(e){return t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info("colorspace: Vertex colors already linear. Skipping conversion.");if("sRGB"!==e.inputEncoding)return void n.error(`colorspace: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const s=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function r(e){const t=[0,0,0];let n;for(let r=0;n=e.getAttribute(`COLOR_${r}`);r++)if(!s.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);s.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(r)),n.debug("colorspace: Complete.")}}const x={propertyTypes:[t.ACCESSOR,t.MESH,t.TEXTURE]},P=function(e=x){const o=R({},x,e),r=new Set(o.propertyTypes);for(const e of o.propertyTypes)if(!x.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return e=>{const o=e.getLogger();r.has(t.ACCESSOR)&&function(e,t){const s=new Set,o=new Set,r=t.getRoot().listMeshes();function i(e){const t=new Map;for(let s=0;s<e.length;s++){const o=e[s],r=o.getArray().slice().buffer;if(!t.has(o))for(let s=0;s<e.length;s++){const i=e[s];o!==i&&(t.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&n.equals(r,i.getArray().slice().buffer)&&t.set(i,o))}}return t}r.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&s.add(t)})});const a=i(Array.from(s));e.debug(`dedup: Found ${a.size} duplicates among ${s.size} indices.`);const c=i(Array.from(o));e.debug(`dedup: Found ${c.size} duplicates among ${o.size} attributes.`),r.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{c.has(t)&&e.swap(t,c.get(t))});const t=e.getIndices();t&&a.has(t)&&e.swap(t,a.get(t))})}),Array.from(a.keys()).forEach(e=>e.dispose()),Array.from(c.keys()).forEach(e=>e.dispose())}(o,e),r.has(t.MESH)&&function(e,n){const s=n.getRoot(),o=new Map;s.listAccessors().forEach((e,t)=>{o.set(e,t)});const r=s.listMeshes().length,i=new Map;for(const e of s.listMeshes()){const n=[];for(const t of e.listPrimitives()){const e=[];for(const n of t.listSemantics()){const s=t.getAttribute(n);e.push(n+":"+o.get(s))}const s=t.getIndices();s&&e.push("indices:"+o.get(s)),n.push(e.join(","))}const s=n.join(";");if(i.has(s)){const n=i.get(s);e.listParents().forEach(s=>{s.propertyType!==t.ROOT&&s.swap(e,n)}),e.dispose()}else i.set(s,e)}e.debug(`dedup: Found ${r-i.size} duplicates among ${r} meshes.`)}(o,e),r.has(t.TEXTURE)&&function(e,t){const o=t.getRoot(),r=o.listTextures(),i=new Map;for(let e=0;e<r.length;e++){const t=r[e],s=t.getImage();if(!i.has(t))for(let e=0;e<r.length;e++){const o=r[e],a=o.getImage();if(t===o)continue;if(i.has(o))continue;if(t.getMimeType()!==o.getMimeType())continue;const c=t.getSize(),l=o.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&s&&a&&n.equals(s,a)&&i.set(o,t)}}e.debug(`dedup: Found ${i.size} duplicates among ${o.listTextures().length} textures.`),Array.from(i.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof s&&n.swap(e,t)}),e.dispose()})}(o,e),o.debug("dedup: Complete.")}};async function z(e,t,n){if(!e)return null;const s=e.getImage();if(!s)return null;const o=await h(new Uint8Array(s),e.getMimeType());for(let e=0;e<o.shape[0];++e)for(let t=0;t<o.shape[1];++t)n(o,e,t);const r=(await A(o,"image/png")).buffer;return t.setImage(r).setMimeType("image/png")}function $(e){const t=e.getIndices(),n=e.getAttribute("POSITION");switch(e.getMode()){case o.Mode.POINTS:return n.getCount();case o.Mode.LINES:return t?t.getCount()/2:n.getCount()/2;case o.Mode.LINE_LOOP:return n.getCount();case o.Mode.LINE_STRIP:return n.getCount()-1;case o.Mode.TRIANGLES:return t?t.getCount()/3:n.getCount()/3;case o.Mode.TRIANGLE_STRIP:case o.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+e.getMode())}}function L(e){return{scenes:v(e),meshes:q(e),materials:k(e),textures:F(e),animations:_(e)}}function v(t){return{properties:t.getRoot().listScenes().map(t=>{const n=t.listChildren()[0],s=e(t);return{name:t.getName(),rootName:n?n.getName():"",bboxMin:U(s.min),bboxMax:U(s.max)}})}}function q(e){return{properties:e.getRoot().listMeshes().map(e=>{const t=e.listParents().filter(e=>"Root"!==e.propertyType).length;let n=0,s=0;const o=new Set,r=new Set,i=new Set;e.listPrimitives().forEach(e=>{for(const t of e.listSemantics()){const n=e.getAttribute(t);o.add(t+":"+B(n.getArray())),i.add(n)}for(const t of e.listTargets())t.listAttributes().forEach(e=>i.add(e));const t=e.getIndices();t&&(r.add(B(t.getArray())),i.add(t)),s+=e.listAttributes()[0].getCount(),n+=$(e)});let a=0;Array.from(i).forEach(e=>a+=e.getArray().byteLength);const c=e.listPrimitives().map(e=>G[e.getMode()]);return{name:e.getName(),mode:Array.from(new Set(c)),primitives:e.listPrimitives().length,glPrimitives:n,vertices:s,indices:Array.from(r).sort(),attributes:Array.from(o).sort(),instances:t,size:a}})}}function k(e){return{properties:e.getRoot().listMaterials().map(t=>{const n=t.listParents().filter(e=>"Root"!==e.propertyType).length,s=new Set(t.listExtensions()),o=e.getGraph().getLinks().filter(e=>{const n=e.getChild(),o=e.getParent();return n instanceof r&&o===t||!!(n instanceof r&&o instanceof i&&s.has(o))}).map(e=>e.getName());return{name:t.getName(),instances:n,textures:o,alphaMode:t.getAlphaMode(),doubleSided:t.getDoubleSided()}})}}function F(e){return{properties:e.getRoot().listTextures().map(t=>{const n=t.listParents().filter(e=>"Root"!==e.propertyType).length,s=e.getGraph().listParentLinks(t).map(e=>e.getName()).filter(e=>"texture"!==e),o=a.getSize(t.getImage(),t.getMimeType());return{name:t.getName(),uri:t.getURI(),slots:Array.from(new Set(s)),instances:n,mimeType:t.getMimeType(),resolution:o?o.join("x"):"",size:t.getImage().byteLength,gpuSize:a.getMemSize(t.getImage(),t.getMimeType())}})}}function _(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const s=e.getInput();s&&(t=Math.min(t,s.getMin([])[0]),n=Math.max(n,s.getMax([])[0]))});let s=0,o=0;const r=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),r.add(t),n&&r.add(n))}),Array.from(r).forEach(e=>{s+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:s}})}}const G=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function U(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function B(e){return e.constructor.name.replace("Array","").toLowerCase()}const j={};function V(e=j){return R({},j,e),e=>{const t=e.getLogger(),n=e.getRoot(),s=e.createExtension(y);if(n.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let o=0,r=0;for(const i of n.listScenes()){const n=new Map;i.traverse(e=>{const t=e.getMesh();t&&n.set(t,(n.get(t)||new Set).add(e))});const a=[];for(const l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(e=>e.getSkin()))continue;const u=D(e,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=e.createNode().setMesh(l).setExtension("EXT_mesh_gpu_instancing",u);i.addChild(d);let h=!1,A=!1,y=!1;for(let e=0;e<g.length;e++){let t,n,s;const o=g[e];f.setElement(e,t=o.getWorldTranslation()),p.setElement(e,n=o.getWorldRotation()),m.setElement(e,s=o.getWorldScale()),c.eq(t,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(y=!0),o.setMesh(null),a.push(o)}h||f.dispose(),A||p.dispose(),y||m.dispose(),W(a,t),o++,r+=g.length}}o>0?t.info(`instance: Created ${o} batches, with ${r} total instances.`):(t.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),t.debug("instance: Complete.")}}function W(e,t){let n,s=0;for(;n=e.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const t=n.getParent();t instanceof l&&e.push(t),n.dispose(),s++}t.debug(`instance: Removed ${s} unused nodes.`)}function D(e,t,n,s){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),r=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*s)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",r).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const X={};function H(e=X){return R({},X,e),async e=>{const t=e.getLogger(),n=T.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes(n))return void t.warn(`metalRough: Extension ${n} not found on given document.`);const s=e.createExtension(E),o=e.createExtension(S),r=e.createExtension(T),i=new Set;for(const t of e.getRoot().listMaterials()){const n=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!n)continue;const r=o.createSpecular().setSpecularFactor(1).setSpecularColorFactor(n.getSpecularFactor());i.add(n.getSpecularGlossinessTexture()),i.add(t.getBaseColorTexture()),i.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(n.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",s.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",r);const a=n.getDiffuseTexture();a&&(t.setBaseColorTexture(a),t.getBaseColorTextureInfo().copy(n.getDiffuseTextureInfo()));const c=n.getSpecularGlossinessTexture();if(c){const s=n.getSpecularGlossinessTextureInfo(),o=e.createTexture();await z(c,o,(e,t,n)=>{e.set(t,n,3,255)}),r.setSpecularTexture(o),r.getSpecularTextureInfo().copy(s);const i=n.getGlossinessFactor(),a=e.createTexture();await z(c,a,(e,t,n)=>{const s=255-Math.round(e.get(t,n,3)*i);e.set(t,n,0,0),e.set(t,n,1,s),e.set(t,n,2,0),e.set(t,n,3,255)}),t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(s)}else r.setSpecularColorFactor(n.getSpecularFactor()),t.setRoughnessFactor(1-n.getGlossinessFactor());t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}r.dispose();for(const e of i)e&&1===e.listParents().length&&e.dispose();t.debug("metalRough: Complete.")}}const K={animations:!0,meshes:!0},Z=(e=K)=>{const t=R({},K,e);return e=>{const n=e.getLogger();!1!==t.meshes&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,r)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(J(o.getName()||"mesh",s));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(e,n,t),!1!==t.animations&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,r)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(J(o.getName()||"animation",s));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(e,n,t),t.meshes||t.animations||n.warn("partition: Select animations or meshes to create a partition."),n.debug("partition: Complete.")}};function J(e,t){let n=`${e}.bin`,s=1;for(;t.has(n);)n=`${e}_${s++}.bin`;return n}const Q={},Y=function(e=Q){return R({},Q,e),e=>{const n=e.getLogger(),s=e.getRoot(),o=e.getGraph(),r={};s.listNodes().forEach(i),s.listSkins().forEach(i),s.listMeshes().forEach(i),s.listCameras().forEach(i),a(o,t.PRIMITIVE),a(o,t.PRIMITIVE_TARGET);for(const e of s.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),c(t));if(e.listChannels().length)e.listSamplers().forEach(i);else{const t=e.listSamplers();i(e),t.forEach(i)}}if(s.listMaterials().forEach(i),s.listTextures().forEach(i),s.listAccessors().forEach(i),s.listBuffers().forEach(i),Object.keys(r).length){const e=Object.keys(r).map(e=>`${e} (${r[e]})`).join(", ");n.info(`prune: Removed types... ${e}`)}else n.info("prune: No unused properties found.");function i(e){e.listParents().filter(e=>!(e instanceof g||e instanceof u)).length||(e.dispose(),c(e))}function a(e,t){e.getLinks().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(i)}function c(e){r[e.propertyType]=r[e.propertyType]||0,r[e.propertyType]++}n.debug("prune: Complete.")}},ee=[Int8Array,Int16Array,Int32Array],te={excludeAttributes:[],quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},ne=(t=te)=>{const n=R({},te,t);return t=>{const s=t.getLogger(),o=t.getRoot();let r;t.createExtension(b).setRequired(!0),"scene"===n.quantizationVolume&&(1!==o.listScenes().length?s.warn("[quantize]: quantizationVolume=scene requires exactly 1 scene."):r=e(o.listScenes().pop()));for(const e of t.getRoot().listMeshes()){if(e.listPrimitives().some(e=>e.getAttribute("JOINTS_0"))){s.warn("quantize: Quantization for skinned mesh not yet implemented.");continue}const o=oe(e,r);o&&re(t,e,o);for(const s of e.listPrimitives()){se(t,s,o,n);for(const e of s.listTargets())se(t,e,o,n)}}s.debug("quantize: Complete.")}};function se(e,t,n,s){const r=e.getRoot(),i=e.getLogger(),a=n?n.nodeRemap:null;for(const n of t.listSemantics()){if(s.excludeAttributes.includes(n))continue;const o=t.getAttribute(n),{bits:c,ctor:l}=ae(n,o,i,s);if(!l)continue;if(c<8||c>16)throw new Error("quantize: Requires bits = 8–16.");if(o.getComponentSize()<=c/8)continue;const g=e.getGraph().listParentLinks(o).filter(e=>e.getParent()!==r).map(e=>e.getName());if(new Set(g).size>1)i.warn(`quantize: Skipping ${n}; attribute usage conflict.`);else{if("POSITION"===n){if(!a)throw new Error("quantize: Failed precondition; missing node transform.");for(let e=0,t=[0,0,0],n=o.getCount();e<n;e++)o.setElement(e,a(o.getElement(e,t)))}ie(o,l,c),o.setNormalized(!0)}}if(t instanceof o&&t.getIndices()&&t.listAttributes().length&&t.listAttributes()[0].getCount()<65535){const e=t.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function oe(e,t){const n=e.listPrimitives().map(e=>e.getAttribute("POSITION"));if(!n.some(e=>!!e))return null;let s=[Infinity,Infinity,Infinity],o=[-Infinity,-Infinity,-Infinity];return t?(s=[...t.min],o=[...t.max]):function(e,t,n){const s=n[0].getElementSize();for(let t=0;t<s;t++)e[t]=Infinity;for(let e=0;e<s;e++)t[e]=-Infinity;const o=[],r=[];for(const i of n){i.getMinNormalized(o),i.getMaxNormalized(r);for(let n=0;n<s;n++)e[n]=Math.min(e[n],o[n]),t[n]=Math.max(t[n],r[n])}}(s,o,n),{nodeRemap:e=>[2*(e[0]-s[0])/(o[0]-s[0])-1,2*(e[1]-s[1])/(o[1]-s[1])-1,2*(e[2]-s[2])/(o[2]-s[2])-1],nodeOffset:[s[0]+(o[0]-s[0])/2,s[1]+(o[1]-s[1])/2,s[2]+(o[2]-s[2])/2],nodeScale:[(o[0]-s[0])/2,(o[1]-s[1])/2,(o[2]-s[2])/2]}}function re(e,t,n){const s=n.nodeOffset||[0,0,0],o=n.nodeScale||[1,1,1];for(const n of t.listParents())if(n instanceof l){const r=n.listChildren().length>0,i=!!n.listParents().find(e=>e instanceof f);let a;r||i?(a=e.createNode("").setMesh(t),n.addChild(a).setMesh(null)):a=n;const c=a.getTranslation(),l=a.getScale();a.setTranslation([c[0]+s[0],c[1]+s[1],c[2]+s[2]]).setScale([l[0]*o[0],l[1]*o[1],l[2]*o[2]])}}function ie(e,t,n){const s=new t(e.getArray().length),o=ee.includes(t)?1:0,r=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,r)-1,c=i-r,l=2*r-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>l,s[n++]=t*Math.sign(o[e])}}e.setArray(s)}function ae(e,t,n,s){const o=t.getMinNormalized([]),r=t.getMinNormalized([]);let i,a;if("POSITION"===e)i=s.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=s.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=s.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of supported range.`),{bits:-1};i=s.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}const ce={tolerance:1e-4},le=(e=ce)=>{const t=R({},ce,e);return e=>{const n=new Set,s=e.getRoot().listAccessors().length,o=e.getLogger();for(const s of e.getRoot().listAnimations())for(const e of s.listSamplers())"STEP"!==e.getInterpolation()&&"LINEAR"!==e.getInterpolation()||(n.add(e.getInput()),n.add(e.getOutput()),ge(e,t));for(const e of Array.from(n.values()))e.listParents().find(e=>!(e instanceof g))||e.dispose();e.getRoot().listAccessors().length>s&&o.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),o.debug("resample: Complete.")}};function ge(e,t){if(!["STEP","LINEAR"].includes(e.getInterpolation()))return;const n=e.getInput().clone(),s=e.getOutput().clone(),o=t.tolerance,r=n.getCount()-1,i=[];let a=1;for(let t=1;t<r;++t){const r=n.getScalar(t),l=n.getScalar(t-1),g=n.getScalar(t+1),u=(r-l)/(g-l);let f=!1;if(r!==g&&(1!==t||r!==n.getScalar(0)))for(let n=0;n<s.getElementSize();n++){const r=s.getElement(t,i)[n],a=s.getElement(t-1,i)[n],l=s.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(r-(a*(1-(c=u))+l*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(r!==a||r!==l)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),s.setElement(a,s.getElement(t,i))),a++)}var c;r>0&&(n.setScalar(a,n.getScalar(r)),s.setElement(a,s.getElement(r,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),s.setArray(s.getArray().slice(0,a*s.getElementSize())),e.setInput(n),e.setOutput(s)):(n.dispose(),s.dispose())}const ue={name:"",fps:10,pattern:/.*/,sort:!0};function fe(e=ue){const t=R({},ue,e);return e=>{const n=e.getLogger(),s=e.getRoot(),o=t.fps,r=s.listNodes().filter(e=>e.getName().match(t.pattern));t.sort&&r.sort((e,t)=>e.getName()>t.getName()?1:-1);const i=e.createAnimation(t.name),a=s.listBuffers()[0];r.forEach((t,n)=>{let s,c;0===n?(s=[n/o,(n+1)/o],c=[1,1,1,0,0,0]):n===r.length-1?(s=[(n-1)/o,n/o],c=[0,0,0,1,1,1]):(s=[(n-1)/o,n/o,(n+1)/o],c=[0,0,0,1,1,1,0,0,0]);const l=e.createAccessor().setArray(new Float32Array(s)).setBuffer(a),g=e.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(p.Type.VEC3),f=e.createAnimationSampler().setInterpolation(m.Interpolation.STEP).setInput(l).setOutput(g),d=e.createAnimationChannel().setTargetNode(t).setTargetPath(u.TargetPath.SCALE).setSampler(f);i.addSampler(f).addChannel(d)}),n.debug("sequence: Complete.")}}const pe={overwrite:!1};function me(e=pe){if(!e.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const t=R({},pe,e);return e=>{const n=e.getLogger(),s=new Map,o=new Map;let r=0;for(const i of e.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!de(l,n,a,i,t.overwrite))continue;const g=l.getAttribute("POSITION").getArray(),u=l.getAttribute("NORMAL").getArray(),f=l.getAttribute("TEXCOORD_0").getArray(),p=s.get(g)||d();s.set(g,p);const m=s.get(u)||d();s.set(u,m);const h=s.get(f)||d();s.set(f,h);const A=l.getAttribute("TANGENT");A&&2===A.listParents().length&&A.dispose();const y=`${p}|${m}|${h}`;let E=o.get(y);if(E){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",E),r++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),T=t.generateTangents(g instanceof Float32Array?g:new Float32Array(g),u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f));for(let e=3;e<T.length;e+=4)T[e]*=-1;E=e.createAccessor().setBuffer(S).setArray(T).setType("VEC4"),l.setAttribute("TANGENT",E),o.set(y,E),r++}}r?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")}}function de(e,t,n,s,r){return e.getMode()===o.Mode.TRIANGLES&&e.getAttribute("POSITION")&&e.getAttribute("NORMAL")&&e.getAttribute("TEXCOORD_0")?e.getAttribute("TANGENT")&&!r?(t.debug(`tangents: Skipping primitive ${s} of mesh "${n}": TANGENT found.`),!1):!e.getIndices()||(t.warn(`tangents: Skipping primitive ${s} of mesh "${n}": primitives must be unwelded.`),!1):(t.debug(`tangents: Skipping primitive ${s} of mesh "${n}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const he="textureResize";var Ae;!function(e){e.LANCZOS3="lanczos3",e.LANCZOS2="lanczos2"}(Ae||(Ae={}));const ye={size:[2048,2048],filter:Ae.LANCZOS3,pattern:null};function Ee(e=ye){const t=R({},ye,e);return async e=>{const n=e.getLogger();for(const s of e.getRoot().listTextures()){const e=s.getName(),o=s.getURI();if(t.pattern&&!t.pattern.test(e)&&!t.pattern.test(o))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[r,i]=t.size,[a,c]=s.getSize();if(a<=r&&c<=i){n.debug(`${he}: Skipping "${o||e}", within size range.`);continue}let l=a,g=c;l>r&&(l=r,g=Math.floor(g*(l/a))),g>i&&(g=i,l=Math.floor(l*(g/c)));const u=new Uint8Array(s.getImage()),f=await h(u,s.getMimeType()),p=I(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${he}: Resizing "${o||e}", ${f.shape} → ${p.shape}...`);try{t.filter===Ae.LANCZOS3?N(f,p):w(f,p)}catch(t){n.warn(`${he}: Failed to resize "${o||e}": "${t.message}".`);continue}s.setImage((await A(p,s.getMimeType())).buffer)}n.debug(`${he}: Complete.`)}}const Se={};function Te(e=Se){return R({},Se,e),e=>{const t=e.getLogger(),n=new Map;for(const s of e.getRoot().listMeshes())for(const e of s.listPrimitives()){const s=e.getIndices();if(s){for(const o of e.listAttributes())e.swap(o,be(o,s,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,be(e,s,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===s.listParents().length&&s.dispose()}}t.debug("unweld: Complete.")}}function be(e,t,n,s){if(s.has(e)&&s.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),s.get(e).get(t);const o=e.clone(),r=e.getArray().constructor;o.setArray(new r(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return s.has(e)||s.set(e,new Map),s.get(e).set(t,o),o}const Ie={tolerance:1e-4};function Ne(e=Ie){const t=R({},Ie,e);return e=>{const n=e.getLogger();for(const n of e.getRoot().listMeshes())for(const s of n.listPrimitives())0===t.tolerance?we(e,s):Re(e,s,t);n.debug("weld: Complete.")}}function we(e,t){if(t.getIndices())return;const n=t.listAttributes()[0],s=n.getCount(),o=n.getBuffer(),r=s<=65534?new Uint16Array(3*$(t)):new Uint32Array(3*$(t)),i=e.createAccessor().setBuffer(o).setType(p.Type.SCALAR).setArray(r);for(let e=0;e<i.getCount();e++)i.setScalar(e,e);t.setIndices(i)}function Re(e,t,n){const s=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/s),r=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),l=new Map;t.listAttributes().forEach(e=>l.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>l.set(e,[]))});const g=[];let u=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,s=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)s.push(~~(e.getElement(n,o)[t]*r));const c=s.join("|");if(c in i)g.push(i[c]);else{for(const e of t.listAttributes())l.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())l.get(t).push(t.getElement(n,[]));i[c]=u,g.push(u),u++}}const f=t.listAttributes()[0].getCount(),p=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())Ce(t,e,l.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())Ce(e,t,l.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=Me(a.getArray(),g.length);e.set(g),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(g):new Uint32Array(g);t.setIndices(e.createAccessor().setArray(n))}}function Me(e,t){return new(0,e.constructor)(t)}function Ce(e,t,n){const s=n.length*t.getElementSize(),o=Me(t.getArray(),s),r=t.clone().setArray(o);for(let e=0;e<n.length;e++)r.setElement(e,n[e]);e.swap(t,r)}export{te as QUANTIZE_DEFAULTS,ye as TEXTURE_RESIZE_DEFAULTS,Ae as TextureResizeFilter,C as center,O as colorspace,P as dedup,L as inspect,V as instance,H as metalRough,Z as partition,Y as prune,ne as quantize,le as resample,fe as sequence,me as tangents,Ee as textureResize,Te as unweld,Ne as weld};
//# sourceMappingURL=functions.modern.js.map
{
"name": "@gltf-transform/functions",
"version": "0.12.1",
"version": "0.12.2",
"repository": "github:donmccurdy/glTF-Transform",

@@ -27,4 +27,4 @@ "homepage": "https://gltf-transform.donmccurdy.com/functions.html",

"dependencies": {
"@gltf-transform/core": "^0.12.1",
"@gltf-transform/extensions": "^0.12.1",
"@gltf-transform/core": "^0.12.2",
"@gltf-transform/extensions": "^0.12.2",
"gl-matrix": "^3.3.0",

@@ -42,3 +42,3 @@ "ndarray": "^1.0.19",

],
"gitHead": "9786b58c9a984c8d73cc270e718be0fc5d2cf743",
"gitHead": "cc05ea715fe02fbf0f077f00795aae3bb9ac25c9",
"publishConfig": {

@@ -45,0 +45,0 @@ "access": "public"

@@ -40,7 +40,12 @@ import { Accessor, Document, Primitive, PrimitiveTarget, Transform, TypedArray } from '@gltf-transform/core';

if (prim.getIndices()) return;
const buffer = prim.listAttributes()[0].getBuffer();
const attr = prim.listAttributes()[0];
const numVertices = attr.getCount();
const buffer = attr.getBuffer();
const indicesArray = numVertices <= 65534
? new Uint16Array(getGLPrimitiveCount(prim) * 3)
: new Uint32Array(getGLPrimitiveCount(prim) * 3);
const indices = doc.createAccessor()
.setBuffer(buffer)
.setType(Accessor.Type.SCALAR)
.setArray(new Uint32Array(getGLPrimitiveCount(prim) * 3));
.setArray(indicesArray);
for (let i = 0; i < indices.getCount(); i++) indices.setScalar(i, i);

@@ -135,3 +140,6 @@ prim.setIndices(indices);

} else {
prim.setIndices(doc.createAccessor().setArray(new Uint32Array(dstIndicesArray)));
const indicesArray = srcVertexCount <= 65534
? new Uint16Array(dstIndicesArray)
: new Uint32Array(dstIndicesArray);
prim.setIndices(doc.createAccessor().setArray(indicesArray));
}

@@ -138,0 +146,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc