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.11.1 to 0.11.2

dist/texture-resize.d.ts

2

dist/functions.js

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

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

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

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

@@ -40,3 +40,4 @@ /**

export * from './tangents';
export * from './texture-resize';
export * from './unweld';
export * from './weld';
{
"name": "@gltf-transform/functions",
"version": "0.11.1",
"version": "0.11.2",
"repository": "github:donmccurdy/glTF-Transform",

@@ -26,6 +26,7 @@ "description": "Functions for common glTF modifications, written using the core API",

"dependencies": {
"@gltf-transform/core": "^0.11.1",
"@gltf-transform/extensions": "^0.11.1",
"@gltf-transform/core": "^0.11.2",
"@gltf-transform/extensions": "^0.11.2",
"gl-matrix": "^3.3.0",
"ndarray": "^1.0.19",
"ndarray-lanczos": "^0.1.1",
"ndarray-pixels": "^0.1.6"

@@ -40,3 +41,3 @@ },

],
"gitHead": "f2a08efc41f51586ad5ec53a864913d2c4415cba",
"gitHead": "33a91aff3bfa281ee8fab60fd1d233b41bafd749",
"publishConfig": {

@@ -43,0 +44,0 @@ "access": "public"

@@ -41,3 +41,4 @@ /**

export * from './tangents';
export * from './texture-resize';
export * from './unweld';
export * from './weld';

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