New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gltf-transform/functions

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/functions - npm Package Compare versions

Comparing version 0.12.14 to 0.12.15

2

dist/functions.js

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

var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),r=require("@gltf-transform/extensions"),n=require("gl-matrix/mat4"),i=require("gl-matrix/vec3"),o=require("ndarray"),a=require("ndarray-lanczos");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=s(o);function l(){return(l=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 f(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 c(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 f(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)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var g="center",p={pivot:"center"},v={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE]},d=function(t){void 0===t&&(t=v);for(var r,n=l({},v,t),i=new Set(n.propertyTypes),o=c(n.propertyTypes);!(r=o()).done;){var a=r.value;if(!v.propertyTypes.includes(a))throw new Error('dedup: Unsupported deduplication on type "'+a+'".')}return function(t){var r=t.getLogger();i.has(e.PropertyType.ACCESSOR)&&function(t,r){var n=new Set,i=new Set,o=r.getRoot().listMeshes();function a(t){for(var r=new Map,n=0;n<t.length;n++){var i=t[n],o=i.getArray().slice().buffer;if(!r.has(i))for(var a=0;a<t.length;a++){var s=t[a];i!==s&&(r.has(s)||i.getType()===s.getType()&&i.getComponentType()===s.getComponentType()&&i.getCount()===s.getCount()&&i.getNormalized()===s.getNormalized()&&e.BufferUtils.equals(o,s.getArray().slice().buffer)&&r.set(s,i))}}return r}o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(e){return i.add(e)});var t=e.getIndices();t&&n.add(t)})});var s=a(Array.from(n));t.debug("dedup: Found "+s.size+" duplicates among "+n.size+" indices.");var u=a(Array.from(i));t.debug("dedup: Found "+u.size+" duplicates among "+i.size+" attributes."),o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(t){u.has(t)&&e.swap(t,u.get(t))});var t=e.getIndices();t&&s.has(t)&&e.swap(t,s.get(t))})}),Array.from(s.keys()).forEach(function(e){return e.dispose()}),Array.from(u.keys()).forEach(function(e){return e.dispose()})}(r,t),i.has(e.PropertyType.MESH)&&function(t,r){var n=r.getRoot(),i=new Map;n.listAccessors().forEach(function(e,t){i.set(e,t)});for(var o,a=n.listMeshes().length,s=new Map,u=function(){for(var t,r=o.value,n=[],a=c(r.listPrimitives());!(t=a()).done;){for(var u,l=t.value,f=[],g=c(l.listSemantics());!(u=g()).done;){var p=u.value,v=l.getAttribute(p);f.push(p+":"+i.get(v))}var d=l.getIndices();d&&f.push("indices:"+i.get(d)),n.push(f.join(","))}var m=n.join(";");if(s.has(m)){var h=s.get(m);r.listParents().forEach(function(t){t.propertyType!==e.PropertyType.ROOT&&t.swap(r,h)}),r.dispose()}else s.set(m,r)},l=c(n.listMeshes());!(o=l()).done;)u();t.debug("dedup: Found "+(a-s.size)+" duplicates among "+a+" meshes.")}(r,t),i.has(e.PropertyType.TEXTURE)&&function(t,r){for(var n=r.getRoot(),i=n.listTextures(),o=new Map,a=0;a<i.length;a++){var s=i[a],u=s.getImage();if(!o.has(s))for(var l=0;l<i.length;l++){var f=i[l],c=f.getImage();if(s!==f&&!o.has(f)&&s.getMimeType()===f.getMimeType()){var g=s.getSize(),p=f.getSize();g&&p&&g[0]===p[0]&&g[1]===p[1]&&u&&c&&e.BufferUtils.equals(u,c)&&o.set(f,s)}}}t.debug("dedup: Found "+o.size+" duplicates among "+n.listTextures().length+" textures."),Array.from(o.entries()).forEach(function(t){var r=t[0],n=t[1];r.listParents().forEach(function(t){t instanceof e.Root||t.swap(r,n)}),r.dispose()})}(r,t),r.debug("dedup: Complete.")}},m=function(e,r,n){try{if(!e)return Promise.resolve(null);var i=e.getImage();return i?Promise.resolve(t.getPixels(new Uint8Array(i),e.getMimeType())).then(function(e){for(var i=0;i<e.shape[0];++i)for(var o=0;o<e.shape[1];++o)n(e,i,o);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return r.setImage(e.buffer).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function h(t){var r=t.getIndices(),n=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return n.getCount();case e.Primitive.Mode.LINES:return r?r.getCount()/2:n.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return n.getCount();case e.Primitive.Mode.LINE_STRIP:return n.getCount()-1;case e.Primitive.Mode.TRIANGLES:return r?r.getCount()/3:n.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}var y=function(){function e(){this._map=new Map}var t,r=e.prototype;return r.has=function(e){return this._map.has(e)},r.add=function(e,t){var r=this._map.get(e);return r||(r=new Set,this._map.set(e,r)),r.add(t),this},r.get=function(e){return this._map.get(e)||new Set},r.keys=function(){return this._map.keys()},(t=[{key:"size",get:function(){return this._map.size}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,t),e}();function A(t){return{properties:t.getRoot().listScenes().map(function(t){var r=t.listChildren()[0],n=e.bounds(t);return{name:t.getName(),rootName:r?r.getName():"",bboxMin:P(n.min),bboxMax:P(n.max)}})}}function T(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=c(e.listSemantics());!(t=s()).done;){var u=t.value,l=e.getAttribute(u);i.add(u+":"+w(l.getArray())),a.add(l)}for(var f,g=c(e.listTargets());!(f=g()).done;)f.value.listAttributes().forEach(function(e){return a.add(e)});var p=e.getIndices();p&&(o.add(w(p.getArray())),a.add(p)),n+=e.listAttributes()[0].getCount(),r+=h(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 E(t){return{properties:t.getRoot().listMaterials().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=new Set(r.listExtensions()),o=t.getGraph().getLinks().filter(function(t){var n=t.getChild(),o=t.getParent();return n instanceof e.Texture&&o===r||!!(n instanceof e.Texture&&o instanceof e.ExtensionProperty&&i.has(o))}).map(function(e){return e.getName()});return{name:r.getName(),instances:n,textures:o,alphaMode:r.getAlphaMode(),doubleSided:r.getDoubleSided()}})}}function S(t){return{properties:t.getRoot().listTextures().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=t.getGraph().listParentLinks(r).map(function(e){return e.getName()}).filter(function(e){return"texture"!==e}),o=e.ImageUtils.getSize(r.getImage(),r.getMimeType());return{name:r.getName(),uri:r.getURI(),slots:Array.from(new Set(i)),instances:n,mimeType:r.getMimeType(),resolution:o?o.join("x"):"",size:r.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(r.getImage(),r.getMimeType())}})}}function b(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 P(e){for(var t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function w(e){return e.constructor.name.replace("Array","").toLowerCase()}var M="instance",R={};function N(t,r){for(var n,i=0;n=t.pop();)if(!(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)){var o=n.getParent();o instanceof e.Node&&t.push(o),n.dispose(),i++}r.debug(M+": Removed "+i+" unused nodes.")}function x(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={},_={propertyTypes:[e.PropertyType.NODE,e.PropertyType.SKIN,e.PropertyType.MESH,e.PropertyType.CAMERA,e.PropertyType.PRIMITIVE,e.PropertyType.PRIMITIVE_TARGET,e.PropertyType.ANIMATION,e.PropertyType.MATERIAL,e.PropertyType.TEXTURE,e.PropertyType.ACCESSOR,e.PropertyType.BUFFER]},F=function(t){void 0===t&&(t=_);var r=l({},_,t).propertyTypes;return function(t){var n=t.getLogger(),i=t.getRoot(),o=t.getGraph(),a={};if(r.includes(e.PropertyType.NODE)&&i.listNodes().forEach(m),r.includes(e.PropertyType.SKIN)&&i.listSkins().forEach(m),r.includes(e.PropertyType.MESH)&&i.listMeshes().forEach(m),r.includes(e.PropertyType.CAMERA)&&i.listCameras().forEach(m),r.includes(e.PropertyType.PRIMITIVE)&&h(o,e.PropertyType.PRIMITIVE),r.includes(e.PropertyType.PRIMITIVE_TARGET)&&h(o,e.PropertyType.PRIMITIVE_TARGET),r.includes(e.PropertyType.ANIMATION))for(var s,u=c(i.listAnimations());!(s=u()).done;){for(var l,f=s.value,g=c(f.listChannels());!(l=g()).done;){var p=l.value;p.getTargetNode()||(p.dispose(),y(p))}if(f.listChannels().length)f.listSamplers().forEach(m);else{var v=f.listSamplers();m(f),v.forEach(m)}}if(r.includes(e.PropertyType.MATERIAL)&&i.listMaterials().forEach(m),r.includes(e.PropertyType.TEXTURE)&&i.listTextures().forEach(m),r.includes(e.PropertyType.ACCESSOR)&&i.listAccessors().forEach(m),r.includes(e.PropertyType.BUFFER)&&i.listBuffers().forEach(m),Object.keys(a).length){var d=Object.keys(a).map(function(e){return e+" ("+a[e]+")"}).join(", ");n.info("prune: Removed types... "+d)}else n.info("prune: No unused properties found.");function m(t){t.listParents().filter(function(t){return!(t instanceof e.Root||t instanceof e.AnimationChannel)}).length||(t.dispose(),y(t))}function h(e,t){e.getLinks().map(function(e){return e.getParent()}).filter(function(e){return e.propertyType===t}).forEach(m)}function y(e){a[e.propertyType]=a[e.propertyType]||0,a[e.propertyType]++}n.debug("prune: Complete.")}},k="partition",q={animations:!0,meshes:!0};function B(e,t){for(var r=e+".bin",n=1;t.has(r);)r=e+"_"+n+++".bin";return r}var G="quantize",j=[Int8Array,Int16Array,Int32Array],D={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12};function V(t,r,o,a){for(var s,u=t.getLogger(),l=c(r.listSemantics());!(s=l()).done;){var f=s.value;if(a.pattern.test(f)){var g=r.getAttribute(f),p=Z(f,g,u,a),v=p.bits,d=p.ctor;if(d){if(v<8||v>16)throw new Error(G+": Requires bits = 8–16.");if(!(g.getComponentSize()<=v/8)){var m=g.clone();if("POSITION"===f){var h=o.scale,y=[];r instanceof e.Primitive?n.invert(y,Y(o)):n.fromScaling(y,[1/h,1/h,1/h]);for(var A=0,T=[0,0,0],E=m.getCount();A<E;A++)m.getElement(A,T),m.setElement(A,i.transformMat4(T,T,y))}K(m,d,v),r.swap(g,m)}}}}if(r instanceof e.Primitive&&r.getIndices()&&r.listAttributes().length&&r.listAttributes()[0].getCount()<65535){var S=r.getIndices();S.setArray(new Uint16Array(S.getArray()))}}function X(e){var t=e.min,r=e.max,n=Math.max((r[0]-t[0])/2,(r[1]-t[1])/2,(r[2]-t[2])/2);return{offset:[t[0]+(r[0]-t[0])/2,t[1]+(r[1]-t[1])/2,t[2]+(r[2]-t[2])/2],scale:n}}function W(t,r,i){for(var o,a=Y(i),s=c(r.listParents());!(o=s()).done;){var u=o.value;if(u instanceof e.Node){var l=u.listChildren().length>0,f=!!u.listParents().find(function(t){return t instanceof e.Animation});if(u.getSkin()){u.setSkin(H(u.getSkin(),i));continue}var g=void 0;l||f?(g=t.createNode("").setMesh(r),u.addChild(g).setMesh(null)):g=u;var p=g.getMatrix();n.multiply(p,p,a),g.setMatrix(p)}}}function H(e,t){e=e.clone();for(var r=Y(t),i=e.getInverseBindMatrices().clone(),o=[],a=0,s=i.getCount();a<s;a++)i.getElement(a,o),n.multiply(o,o,r),i.setElement(a,o);return e.setInverseBindMatrices(i)}function K(e,t,r){for(var n=new t(e.getArray().length),i=j.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 v=Math.round(Math.abs(g[p])*s);n[c++]=(v=v<<u|v>>l)*Math.sign(g[p])}}e.setArray(n).setNormalized(!0)}function Z(e,t,r,n){var i,o,a=t.getMinNormalized([]),s=t.getMaxNormalized([]);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 [0,1] 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 [0,1] 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 [-1,1] 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}}function Q(e){for(var t,r=[],n=[],o=c(e.listPrimitives());!(t=o()).done;){var a=t.value,s=a.getAttribute("POSITION");s&&r.push(s);for(var u,l=c(a.listTargets());!(u=l()).done;){var f=u.value.getAttribute("POSITION");f&&n.push(f)}}if(0===r.length)throw new Error(G+': Missing "POSITION" attribute.');var g=J(r,3);if(n.length>0){var p=J(n,3),v=p.min,d=p.max;i.min(g.min,g.min,i.min(v,i.scale(v,v,2),[0,0,0])),i.max(g.max,g.max,i.max(d,i.scale(d,d,2),[0,0,0]))}return g}function J(e,t){for(var r,n=new Array(t).fill(Infinity),i=new Array(t).fill(-Infinity),o=[],a=[],s=c(e);!(r=s()).done;){var u=r.value;u.getMinNormalized(o),u.getMaxNormalized(a);for(var l=0;l<t;l++)n[l]=Math.min(n[l],o[l]),i[l]=Math.max(i[l],a[l])}return{min:n,max:i}}function Y(e){return n.fromRotationTranslationScale([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}var $={tolerance:1e-4};function ee(e,t){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),v=!1;if(f!==g&&(1!==l||f!==n.getScalar(0)))for(var d=0;d<i.getElementSize();d++){var m=i.getElement(l,s)[d],h=i.getElement(l-1,s)[d],y=i.getElement(l+1,s)[d];if("LINEAR"===e.getInterpolation()){if(Math.abs(m-(h*(1-(r=p))+y*r))>o){v=!0;break}}else if("STEP"===e.getInterpolation()&&(m!==h||m!==y)){v=!0;break}}v&&(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 te={target:"size"};function re(e,t,r){for(var n=e.getElementSize(),i=e.getCount(),o=e.getArray(),a=o.slice(0,r*n),s=0;s<i;s++)for(var u=0;u<n;u++)a[t[s]*n+u]=o[s*n+u];e.setArray(a)}function ne(e){for(var t,r=[],n=c(e.listAttributes());!(t=n()).done;)r.push(t.value);for(var i,o=c(e.listTargets());!(i=o()).done;)for(var a,s=c(i.value.listAttributes());!(a=s()).done;)r.push(a.value);return Array.from(new Set(r))}var ie={name:"",fps:10,pattern:/.*/,sort:!0},oe="tangents",ae={overwrite:!1};function se(e){var t=e.getMaterial();if(!t)return"TEXCOORD_0";var r=t.getNormalTextureInfo();if(!r)return"TEXCOORD_0";var n="TEXCOORD_"+r.getTexCoord();return e.getAttribute(n)?n:"TEXCOORD_0"}function ue(t,r,n,i,o){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!o?(r.debug(oe+": Skipping primitive "+i+' of mesh "'+n+'": TANGENT found.'),!1):!t.getIndices()||(r.warn(oe+": Skipping primitive "+i+' of mesh "'+n+'": primitives must be unwelded.'),!1):(r.debug(oe+": Skipping primitive "+i+' of mesh "'+n+'": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.'),!1)}var le="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function fe(e,t,r){if(!e.s){if(r instanceof ce){if(!r.s)return void(r.o=fe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(fe.bind(null,e,t),fe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ce=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{fe(n,1,o(this.v))}catch(e){fe(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?fe(n,1,t?t(i):i):r?fe(n,1,r(i)):fe(n,2,i)}catch(e){fe(n,2,e)}},n},e}();function ge(e){return e instanceof ce&&1&e.s}var pe,ve="textureResize";(pe=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",pe.LANCZOS2="lanczos2";var de={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},me={};function he(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 ye={tolerance:1e-4};function Ae(t,r){if(!r.getIndices()){for(var n=r.listAttributes()[0],i=n.getCount(),o=n.getBuffer(),a=i<=65534?new Uint16Array(3*h(r)):new Uint32Array(3*h(r)),s=t.createAccessor().setBuffer(o).setType(e.Accessor.Type.SCALAR).setArray(a),u=0;u<s.getCount();u++)s.setScalar(u,u);r.setIndices(s)}}function Te(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 f=[],g=0,p=0;p<u;p++){for(var v,d=s?s.getScalar(p):p,m=[],h=[],y=c(t.listAttributes());!(v=y()).done;)for(var A=v.value,T=0;T<A.getElementSize();T++)m.push(~~(A.getElement(d,h)[T]*o));var E=m.join("|");if(E in a)f.push(a[E]);else{for(var S,b=c(t.listAttributes());!(S=b()).done;){var I=S.value;l.get(I).push(I.getElement(d,[]))}for(var P,w=c(t.listTargets());!(P=w()).done;)for(var M,R=c(P.value.listAttributes());!(M=R()).done;){var N=M.value;l.get(N).push(N.getElement(d,[]))}a[E]=g,f.push(g),g++}}var x=t.listAttributes()[0].getCount(),C=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug("weld: "+x+" → "+C+" vertices.");for(var O,z=c(t.listAttributes());!(O=z()).done;){var L=O.value;Se(t,L,l.get(L)),1===L.listParents().length&&L.dispose()}for(var U,_=c(t.listTargets());!(U=_()).done;)for(var F,k=U.value,q=c(k.listAttributes());!(F=q()).done;){var B=F.value;Se(k,B,l.get(B)),1===B.listParents().length&&B.dispose()}if(s){var G=Ee(s.getArray(),f.length);G.set(f),t.setIndices(s.clone().setArray(G)),1===s.listParents().length&&s.dispose()}else{var j=x<=65534?new Uint16Array(f):new Uint32Array(f);t.setIndices(e.createAccessor().setArray(j))}}function Ee(e,t){return new(0,e.constructor)(t)}function Se(e,t,r){for(var n=r.length*t.getElementSize(),i=Ee(t.getArray(),n),o=t.clone().setArray(i),a=0;a<r.length;a++)o.setElement(a,r[a]);e.swap(t,o)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.QUANTIZE_DEFAULTS=D,exports.TEXTURE_RESIZE_DEFAULTS=de,exports.center=function(t){void 0===t&&(t=p);var r=l({},p,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=i.listAnimations().length>0||i.listSkins().length>0;t.getRoot().listScenes().forEach(function(a,s){var u;if(n.debug(g+": Scene "+(s+1)+" / "+i.listScenes().length+"."),"string"==typeof r.pivot){var l=e.bounds(a);u=[(l.max[0]-l.min[0])/2+l.min[0],(l.max[1]-l.min[1])/2+l.min[1],(l.max[2]-l.min[2])/2+l.min[2]],"above"===r.pivot&&(u[1]=l.max[1]),"below"===r.pivot&&(u[1]=l.min[1])}else u=r.pivot;n.debug(g+': Pivot "'+u.join(", ")+'".');var f=[-1*u[0],-1*u[1],-1*u[2]];if(o){n.debug(g+": Model contains animation or skin. Adding a wrapper node.");var c=t.createNode("Pivot").setTranslation(f);a.listChildren().forEach(function(e){return c.addChild(e)}),a.addChild(c)}else n.debug(g+": Skipping wrapper, offsetting all root nodes."),a.listChildren().forEach(function(e){var t=e.getTranslation();e.setTranslation([t[0]+f[0],t[1]+f[1],t[2]+f[2]])})}),n.debug(g+": 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=d,exports.inspect=function(e){return{scenes:A(e),meshes:T(e),materials:E(e),textures:S(e),animations:b(e)}},exports.instance=function(t){return void 0===t&&(t=R),l({},R,t),function(t){var n=t.getLogger(),i=t.getRoot(),o=t.createExtension(r.MeshGPUInstancing);if(i.listAnimations().length)throw new Error(M+": Instancing is not currently supported for animated models.");for(var a,s=0,u=0,l=function(){var r=a.value,i=new Map;r.traverse(function(e){var t=e.getMesh();t&&i.set(t,(i.get(t)||new Set).add(e))});for(var l=[],f=0,c=Array.from(i.keys());f<c.length;f++){var g=c[f],p=Array.from(i.get(g));if(!(p.length<2||p.some(function(e){return e.getSkin()}))){var v=x(t,o,g,p.length),d=v.getAttribute("TRANSLATION"),m=v.getAttribute("ROTATION"),h=v.getAttribute("SCALE"),y=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",v);r.addChild(y);for(var A=!1,T=!1,E=!1,S=0;S<p.length;S++){var b,I,P,w=p[S];d.setElement(S,b=w.getWorldTranslation()),m.setElement(S,I=w.getWorldRotation()),h.setElement(S,P=w.getWorldScale()),e.MathUtils.eq(b,[0,0,0])||(A=!0),e.MathUtils.eq(I,[0,0,0,1])||(T=!0),e.MathUtils.eq(P,[1,1,1])||(E=!0),w.setMesh(null),l.push(w)}A||d.dispose(),T||m.dispose(),E||h.dispose(),N(l,n),s++,u+=p.length}}},f=c(i.listScenes());!(a=f()).done;)l();s>0?n.info(M+": Created "+s+" batches, with "+u+" total instances."):(n.info(M+": No meshes with multiple parent nodes were found."),o.dispose()),n.debug(M+": Complete.")}},exports.metalRough=function(e){return void 0===e&&(e=U),l({},U,e),function(e){try{var t=function(){s.dispose();for(var e,t=c(u);!(e=t()).done;){var r=e.value;r&&1===r.listParents().length&&r.dispose()}n.debug("metalRough: Complete.")},n=e.getLogger(),i=r.MaterialsPBRSpecularGlossiness.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(function(e){return e.extensionName}).includes(i))return n.warn("metalRough: Extension "+i+" not found on given document."),Promise.resolve();var o=e.createExtension(r.MaterialsIOR),a=e.createExtension(r.MaterialsSpecular),s=e.createExtension(r.MaterialsPBRSpecularGlossiness),u=new Set,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(m(l,o,function(e,t,r){e.set(t,r,3,255)})).then(function(){i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(r),i.getSpecularColorTextureInfo().copy(r);var a=n.getGlossinessFactor(),s=e.createTexture();return Promise.resolve(m(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(t){void 0===t&&(t=q);var r=l({},q,t);return function(t){try{var n=t.getLogger();return!1!==r.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(k+': Creating buffer for mesh "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(B(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(k+": Skipping mesh #"+o+' with name "'+i.getName()+'".')})}(t,n,r),!1!==r.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(k+': Creating buffer for animation "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(B(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(k+": Skipping animation #"+o+' with name "'+i.getName()+'".')})}(t,n,r),r.meshes||r.animations||n.warn(k+": Select animations or meshes to create a partition."),Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.BUFFER]}))).then(function(){n.debug(k+": Complete.")})}catch(e){return Promise.reject(e)}}},exports.prune=F,exports.quantize=function(t){void 0===t&&(t=D);var n=l({},D,t);return function(t){try{var o=t.getLogger(),a=t.getRoot();t.createExtension(r.MeshQuantization).setRequired(!0);var s=void 0;"scene"===n.quantizationVolume&&(s=X(function(e){for(var t,r=e[0],n=c(e);!(t=n()).done;){var o=t.value;i.min(r.min,r.min,o.min),i.max(r.max,r.max,o.max)}return r}(a.listMeshes().map(Q))));for(var u,l=c(t.getRoot().listMeshes());!(u=l()).done;){var f=u.value;"mesh"===n.quantizationVolume&&(s=X(Q(f))),s&&n.pattern.test("POSITION")&&W(t,f,s);for(var g,p=c(f.listPrimitives());!(g=p()).done;){var v=g.value;V(t,v,s,n);for(var m,h=c(v.listTargets());!(m=h()).done;)V(t,m.value,s,n)}}return Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.SKIN]}),d({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){o.debug(G+": Complete.")})}catch(e){return Promise.reject(e)}}},exports.reorder=function(t){void 0===t&&(t=te);var r=l({},te,t),n=r.encoder;return function(t){try{var i=t.getLogger();return Promise.resolve(n.ready).then(function(){for(var o,a=function(e){for(var t,r=new y,n=new Map,i=new y,o=c(e.getRoot().listMeshes());!(t=o()).done;)for(var a,s=c(t.value.listPrimitives());!(a=s()).done;){var u=a.value,l=u.getIndices();if(l){n.set(l,u.getMode());for(var f,g=c(ne(u));!(f=g()).done;){var p=f.value;r.add(l,p),i.add(p,u)}}}return{indicesToAttributes:r,indicesToMode:n,attributesToPrimitives:i}}(t),s=c(a.indicesToAttributes.keys());!(o=s()).done;){var u=o.value,l=u.clone(),f=l.getArray().slice();f instanceof Uint32Array||(f=new Uint32Array(f));var g=n.reorderMesh(f,a.indicesToMode.get(u)===e.Primitive.Mode.TRIANGLES,"size"===r.target),p=g[0],v=g[1];l.setArray(v<=65534?new Uint16Array(f):f);for(var d,m=c(a.indicesToAttributes.get(u));!(d=m()).done;){var h=d.value,A=h.clone();re(A,p,v);for(var T,E=c(a.attributesToPrimitives.get(h));!(T=E()).done;){var S=T.value;if(S.getIndices()===u&&S.swap(u,l),S.getIndices()===l){S.swap(h,A);for(var b,I=c(S.listTargets());!(b=I()).done;)b.value.swap(h,A)}}}}return Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){a.indicesToAttributes.size?i.debug("reorder: Complete."):i.warn("reorder: No qualifying primitives found; may need to weld first.")})})}catch(e){return Promise.reject(e)}}},exports.resample=function(t){void 0===t&&(t=$);var r=l({},$,t);return function(t){for(var n,i=new Set,o=t.getRoot().listAccessors().length,a=t.getLogger(),s=!1,u=c(t.getRoot().listAnimations());!(n=u()).done;){for(var l,f=n.value,g=new Set,p=c(f.listChannels());!(l=p()).done;){var v=l.value;v.getSampler()&&"weights"===v.getTargetPath()&&g.add(v.getSampler())}for(var d,m=c(f.listSamplers());!(d=m()).done;){var h=d.value;g.has(h)?s=!0:"STEP"!==h.getInterpolation()&&"LINEAR"!==h.getInterpolation()||(i.add(h.getInput()),i.add(h.getOutput()),ee(h,r))}}for(var y=0,A=Array.from(i.values());y<A.length;y++){var T=A[y];T.listParents().some(function(t){return!(t instanceof e.Root)})||T.dispose()}t.getRoot().listAccessors().length>o&&a.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),s&&a.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),a.debug("resample: Complete.")}},exports.sequence=function(t){void 0===t&&(t=ie);var r=l({},ie,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=r.fps,a=i.listNodes().filter(function(e){return e.getName().match(r.pattern)});r.sort&&a.sort(function(e,t){return e.getName()>t.getName()?1:-1});var s=t.createAnimation(r.name),u=i.listBuffers()[0];a.forEach(function(r,n){var i,l;0===n?(i=[n/o,(n+1)/o],l=[1,1,1,0,0,0]):n===a.length-1?(i=[(n-1)/o,n/o],l=[0,0,0,1,1,1]):(i=[(n-1)/o,n/o,(n+1)/o],l=[0,0,0,1,1,1,0,0,0]);var f=t.createAccessor().setArray(new Float32Array(i)).setBuffer(u),c=t.createAccessor().setArray(new Float32Array(l)).setBuffer(u).setType(e.Accessor.Type.VEC3),g=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(f).setOutput(c),p=t.createAnimationChannel().setTargetNode(r).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(g);s.addSampler(g).addChannel(p)}),n.debug("sequence: Complete.")}},exports.tangents=function(t){if(void 0===t&&(t=ae),!t.generateTangents)throw new Error(oe+': generateTangents callback required — install "mikktspace".');var r=l({},ae,t);return function(t){for(var n,i=t.getLogger(),o=new Map,a=new Map,s=0,u=c(t.getRoot().listMeshes());!(n=u()).done;)for(var l=n.value,f=l.getName(),g=l.listPrimitives(),p=0;p<g.length;p++){var v=g[p];if(ue(v,i,f,p,r.overwrite)){var d=se(v),m=v.getAttribute("POSITION").getArray(),h=v.getAttribute("NORMAL").getArray(),y=v.getAttribute(d).getArray(),A=o.get(m)||e.uuid();o.set(m,A);var T=o.get(h)||e.uuid();o.set(h,T);var E=o.get(y)||e.uuid();o.set(y,E);var S=v.getAttribute("TANGENT");S&&2===S.listParents().length&&S.dispose();var b=A+"|"+T+"|"+E,I=a.get(b);if(I)i.debug(oe+": Found cache for primitive "+p+' of mesh "'+f+'".'),v.setAttribute("TANGENT",I),s++;else{i.debug(oe+": Generating for primitive "+p+' of mesh "'+f+'".');for(var P=v.getAttribute("POSITION").getBuffer(),w=r.generateTangents(m instanceof Float32Array?m:new Float32Array(m),h instanceof Float32Array?h:new Float32Array(h),y instanceof Float32Array?y:new Float32Array(y)),M=3;M<w.length;M+=4)w[M]*=-1;I=t.createAccessor().setBuffer(P).setArray(w).setType("VEC4"),v.setAttribute("TANGENT",I),a.set(b,I),s++}}}s?i.debug(oe+": Complete."):i.warn(oe+": No qualifying primitives found. See debug output.")}},exports.textureResize=function(e){void 0===e&&(e=de);var r=l({},de,e);return function(e){try{var n=function(e){i.debug(ve+": Complete.")},i=e.getLogger(),o=function(e,t,r){if("function"==typeof e[le]){var n,i,o,a=e[le]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!ge(r))return void r.then(e,o||(o=fe.bind(null,i=new ce,2)));r=r.v}i?fe(i,1,r):i=r}catch(e){fe(i||(i=new ce),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(!ge(a))return void a.then(r,i||(i=fe.bind(null,n=new ce,2)));a=a.v}n?fe(n,1,a):n=a}catch(e){fe(n||(n=new ce),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listTextures(),function(e){var n=e.getName(),o=e.getURI();if(!r.pattern||r.pattern.test(n)||r.pattern.test(o))if("image/png"===e.getMimeType()||"image/jpeg"===e.getMimeType()){var s=r.size,l=s[0],f=s[1],c=e.getSize(),g=c[0],p=c[1];if(!(g<=l&&p<=f)){var v=g,d=p;v>l&&(d=Math.floor(d*(l/v)),v=l),d>f&&(v=Math.floor(v*(f/d)),d=f);var m=new Uint8Array(e.getImage());return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(s){var l=u.default(new Uint8Array(v*d*4),[v,d,4]);i.debug(ve+': Resizing "'+(o||n)+'", '+s.shape+" → "+l.shape+"...");try{r.filter===exports.TextureResizeFilter.LANCZOS3?a.lanczos3(s,l):a.lanczos2(s,l)}catch(e){if(e instanceof Error)return void i.warn(ve+': Failed to resize "'+(o||n)+'": "'+e.message+'".');throw e}var f=e.setImage;return Promise.resolve(t.savePixels(l,e.getMimeType())).then(function(t){f.call(e,t.buffer)})})}i.debug(ve+': Skipping "'+(o||n)+'", within size range.')}else i.warn('Skipping unsupported texture type, "'+e.getMimeType()+'".')});return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}},exports.unweld=function(e){return void 0===e&&(e=me),l({},me,e),function(e){for(var t,r=e.getLogger(),n=new Map,i=c(e.getRoot().listMeshes());!(t=i()).done;)for(var o,a=c(t.value.listPrimitives());!(o=a()).done;){var s=o.value,u=s.getIndices();if(u){for(var l,f=c(s.listAttributes());!(l=f()).done;){var g=l.value;s.swap(g,he(g,u,r,n)),1===g.listParents().length&&g.dispose()}for(var p,v=c(s.listTargets());!(p=v()).done;)for(var d,m=p.value,h=c(m.listAttributes());!(d=h()).done;){var y=d.value;m.swap(y,he(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=ye);var t=l({},ye,e);return function(e){for(var r,n=e.getLogger(),i=c(e.getRoot().listMeshes());!(r=i()).done;)for(var o,a=c(r.value.listPrimitives());!(o=a()).done;){var s=o.value;0===t.tolerance?Ae(e,s):Te(e,s,t)}n.debug("weld: Complete.")}};
var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),r=require("@gltf-transform/extensions"),n=require("gl-matrix/mat4"),i=require("gl-matrix/vec3"),o=require("ndarray"),a=require("ndarray-lanczos");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=s(o);function l(){return(l=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 f(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 c(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 f(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)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var g="center",p={pivot:"center"},v={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE]},d=function(t){void 0===t&&(t=v);for(var r,n=l({},v,t),i=new Set(n.propertyTypes),o=c(n.propertyTypes);!(r=o()).done;){var a=r.value;if(!v.propertyTypes.includes(a))throw new Error('dedup: Unsupported deduplication on type "'+a+'".')}return function(t){var r=t.getLogger();i.has(e.PropertyType.ACCESSOR)&&function(t,r){var n=new Set,i=new Set,o=r.getRoot().listMeshes();function a(t){for(var r=new Map,n=0;n<t.length;n++){var i=t[n],o=i.getArray().slice().buffer;if(!r.has(i))for(var a=0;a<t.length;a++){var s=t[a];i!==s&&(r.has(s)||i.getType()===s.getType()&&i.getComponentType()===s.getComponentType()&&i.getCount()===s.getCount()&&i.getNormalized()===s.getNormalized()&&e.BufferUtils.equals(o,s.getArray().slice().buffer)&&r.set(s,i))}}return r}o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(e){return i.add(e)});var t=e.getIndices();t&&n.add(t)})});var s=a(Array.from(n));t.debug("dedup: Found "+s.size+" duplicates among "+n.size+" indices.");var u=a(Array.from(i));t.debug("dedup: Found "+u.size+" duplicates among "+i.size+" attributes."),o.forEach(function(e){e.listPrimitives().forEach(function(e){e.listAttributes().forEach(function(t){u.has(t)&&e.swap(t,u.get(t))});var t=e.getIndices();t&&s.has(t)&&e.swap(t,s.get(t))})}),Array.from(s.keys()).forEach(function(e){return e.dispose()}),Array.from(u.keys()).forEach(function(e){return e.dispose()})}(r,t),i.has(e.PropertyType.MESH)&&function(t,r){var n=r.getRoot(),i=new Map;n.listAccessors().forEach(function(e,t){i.set(e,t)});for(var o,a=n.listMeshes().length,s=new Map,u=function(){for(var t,r=o.value,n=[],a=c(r.listPrimitives());!(t=a()).done;){for(var u,l=t.value,f=[],g=c(l.listSemantics());!(u=g()).done;){var p=u.value,v=l.getAttribute(p);f.push(p+":"+i.get(v))}var d=l.getIndices();d&&f.push("indices:"+i.get(d)),n.push(f.join(","))}var m=n.join(";");if(s.has(m)){var h=s.get(m);r.listParents().forEach(function(t){t.propertyType!==e.PropertyType.ROOT&&t.swap(r,h)}),r.dispose()}else s.set(m,r)},l=c(n.listMeshes());!(o=l()).done;)u();t.debug("dedup: Found "+(a-s.size)+" duplicates among "+a+" meshes.")}(r,t),i.has(e.PropertyType.TEXTURE)&&function(t,r){for(var n=r.getRoot(),i=n.listTextures(),o=new Map,a=0;a<i.length;a++){var s=i[a],u=s.getImage();if(!o.has(s))for(var l=0;l<i.length;l++){var f=i[l],c=f.getImage();if(s!==f&&!o.has(f)&&s.getMimeType()===f.getMimeType()){var g=s.getSize(),p=f.getSize();g&&p&&g[0]===p[0]&&g[1]===p[1]&&u&&c&&e.BufferUtils.equals(u,c)&&o.set(f,s)}}}t.debug("dedup: Found "+o.size+" duplicates among "+n.listTextures().length+" textures."),Array.from(o.entries()).forEach(function(t){var r=t[0],n=t[1];r.listParents().forEach(function(t){t instanceof e.Root||t.swap(r,n)}),r.dispose()})}(r,t),r.debug("dedup: Complete.")}},m=function(e,r,n){try{if(!e)return Promise.resolve(null);var i=e.getImage();return i?Promise.resolve(t.getPixels(new Uint8Array(i),e.getMimeType())).then(function(e){for(var i=0;i<e.shape[0];++i)for(var o=0;o<e.shape[1];++o)n(e,i,o);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return r.setImage(e.buffer).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function h(t){var r=t.getIndices(),n=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return n.getCount();case e.Primitive.Mode.LINES:return r?r.getCount()/2:n.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return n.getCount();case e.Primitive.Mode.LINE_STRIP:return n.getCount()-1;case e.Primitive.Mode.TRIANGLES:return r?r.getCount()/3:n.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return n.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}var y=function(){function e(){this._map=new Map}var t,r=e.prototype;return r.has=function(e){return this._map.has(e)},r.add=function(e,t){var r=this._map.get(e);return r||(r=new Set,this._map.set(e,r)),r.add(t),this},r.get=function(e){return this._map.get(e)||new Set},r.keys=function(){return this._map.keys()},(t=[{key:"size",get:function(){return this._map.size}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,t),e}();function A(t){return{properties:t.getRoot().listScenes().map(function(t){var r=t.listChildren()[0],n=e.bounds(t);return{name:t.getName(),rootName:r?r.getName():"",bboxMin:P(n.min),bboxMax:P(n.max)}})}}function T(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=c(e.listSemantics());!(t=s()).done;){var u=t.value,l=e.getAttribute(u);i.add(u+":"+w(l.getArray())),a.add(l)}for(var f,g=c(e.listTargets());!(f=g()).done;)f.value.listAttributes().forEach(function(e){return a.add(e)});var p=e.getIndices();p&&(o.add(w(p.getArray())),a.add(p)),n+=e.listAttributes()[0].getCount(),r+=h(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 E(t){return{properties:t.getRoot().listMaterials().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=new Set(r.listExtensions()),o=t.getGraph().getLinks().filter(function(t){var n=t.getChild(),o=t.getParent();return n instanceof e.Texture&&o===r||!!(n instanceof e.Texture&&o instanceof e.ExtensionProperty&&i.has(o))}).map(function(e){return e.getName()});return{name:r.getName(),instances:n,textures:o,alphaMode:r.getAlphaMode(),doubleSided:r.getDoubleSided()}})}}function S(t){return{properties:t.getRoot().listTextures().map(function(r){var n=r.listParents().filter(function(e){return"Root"!==e.propertyType}).length,i=t.getGraph().listParentLinks(r).map(function(e){return e.getName()}).filter(function(e){return"texture"!==e}),o=e.ImageUtils.getSize(r.getImage(),r.getMimeType());return{name:r.getName(),uri:r.getURI(),slots:Array.from(new Set(i)),instances:n,mimeType:r.getMimeType(),resolution:o?o.join("x"):"",size:r.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(r.getImage(),r.getMimeType())}})}}function b(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 P(e){for(var t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function w(e){return e.constructor.name.replace("Array","").toLowerCase()}var R="instance",M={};function N(t,r){for(var n,i=0;n=t.pop();)if(!(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)){var o=n.getParent();o instanceof e.Node&&t.push(o),n.dispose(),i++}r.debug(R+": Removed "+i+" unused nodes.")}function C(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 x="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={},_={propertyTypes:[e.PropertyType.NODE,e.PropertyType.SKIN,e.PropertyType.MESH,e.PropertyType.CAMERA,e.PropertyType.PRIMITIVE,e.PropertyType.PRIMITIVE_TARGET,e.PropertyType.ANIMATION,e.PropertyType.MATERIAL,e.PropertyType.TEXTURE,e.PropertyType.ACCESSOR,e.PropertyType.BUFFER]},F=function(t){void 0===t&&(t=_);var r=l({},_,t).propertyTypes;return function(t){var n=t.getLogger(),i=t.getRoot(),o=t.getGraph(),a={};if(r.includes(e.PropertyType.NODE)&&i.listNodes().forEach(m),r.includes(e.PropertyType.SKIN)&&i.listSkins().forEach(m),r.includes(e.PropertyType.MESH)&&i.listMeshes().forEach(m),r.includes(e.PropertyType.CAMERA)&&i.listCameras().forEach(m),r.includes(e.PropertyType.PRIMITIVE)&&h(o,e.PropertyType.PRIMITIVE),r.includes(e.PropertyType.PRIMITIVE_TARGET)&&h(o,e.PropertyType.PRIMITIVE_TARGET),r.includes(e.PropertyType.ANIMATION))for(var s,u=c(i.listAnimations());!(s=u()).done;){for(var l,f=s.value,g=c(f.listChannels());!(l=g()).done;){var p=l.value;p.getTargetNode()||(p.dispose(),y(p))}if(f.listChannels().length)f.listSamplers().forEach(m);else{var v=f.listSamplers();m(f),v.forEach(m)}}if(r.includes(e.PropertyType.MATERIAL)&&i.listMaterials().forEach(m),r.includes(e.PropertyType.TEXTURE)&&i.listTextures().forEach(m),r.includes(e.PropertyType.ACCESSOR)&&i.listAccessors().forEach(m),r.includes(e.PropertyType.BUFFER)&&i.listBuffers().forEach(m),Object.keys(a).length){var d=Object.keys(a).map(function(e){return e+" ("+a[e]+")"}).join(", ");n.info("prune: Removed types... "+d)}else n.info("prune: No unused properties found.");function m(t){t.listParents().filter(function(t){return!(t instanceof e.Root||t instanceof e.AnimationChannel)}).length||(t.dispose(),y(t))}function h(e,t){e.getLinks().map(function(e){return e.getParent()}).filter(function(e){return e.propertyType===t}).forEach(m)}function y(e){a[e.propertyType]=a[e.propertyType]||0,a[e.propertyType]++}n.debug("prune: Complete.")}},k="partition",G={animations:!0,meshes:!0};function q(e,t){for(var r=e+".bin",n=1;t.has(r);)r=e+"_"+n+++".bin";return r}var B="quantize",j=[Int8Array,Int16Array,Int32Array],D=e.AnimationChannel.TargetPath,V=D.WEIGHTS,W=[D.TRANSLATION,D.ROTATION,D.SCALE],X={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12};function H(t,r,o,a){for(var s,u=t.getLogger(),l=c(r.listSemantics());!(s=l()).done;){var f=s.value;if(a.pattern.test(f)){var g=r.getAttribute(f),p=Y(f,g,u,a),v=p.bits,d=p.ctor;if(d){if(v<8||v>16)throw new Error(B+": Requires bits = 8–16.");if(!(g.getComponentSize()<=v/8)){var m=g.clone();if("POSITION"===f){var h=o.scale,y=[];r instanceof e.Primitive?n.invert(y,te(o)):n.fromScaling(y,[1/h,1/h,1/h]);for(var A=0,T=[0,0,0],E=m.getCount();A<E;A++)m.getElement(A,T),m.setElement(A,i.transformMat4(T,T,y))}J(m,d,v),r.swap(g,m)}}}}if(r.getAttribute("WEIGHTS_0")&&function(e){for(var t=e.getAttribute("POSITION").getCount(),r=[],n=0;n<t;n++){for(var i=0,o=Infinity,a=-1,s=null,u=void 0,l=0;u=e.getAttribute("WEIGHTS_"+l++);){u.getElement(n,r);for(var f=0;f<r.length;f++)i+=r[f],r[f]>0&&r[f]<o&&(s=u,o=r[f],a=f)}s&&1!==i&&(s.getElement(n,r),r[a]+=1-i,s.setElement(n,r))}}(r),r instanceof e.Primitive&&r.getIndices()&&r.listAttributes().length&&r.listAttributes()[0].getCount()<65535){var S=r.getIndices();S.setArray(new Uint16Array(S.getArray()))}}function K(e){var t=e.min,r=e.max,n=Math.max((r[0]-t[0])/2,(r[1]-t[1])/2,(r[2]-t[2])/2);return{offset:[t[0]+(r[0]-t[0])/2,t[1]+(r[1]-t[1])/2,t[2]+(r[2]-t[2])/2],scale:n}}function Z(t,r,i){for(var o,a=te(i),s=c(r.listParents());!(o=s()).done;){var u=o.value;u instanceof e.Node&&function(){var o=u.listParents().filter(function(t){return t instanceof e.AnimationChannel}),s=o.some(function(e){return W.includes(e.getTargetPath())}),l=u.listChildren().length>0;if(u.getSkin())return u.setSkin(Q(u.getSkin(),i)),"continue";var f=void 0;l||s?(f=t.createNode("").setMesh(r),u.addChild(f).setMesh(null),o.filter(function(e){return e.getTargetPath()===V}).forEach(function(e){return e.setTargetNode(f)})):f=u;var c=f.getMatrix();n.multiply(c,c,a),f.setMatrix(c)}()}}function Q(e,t){e=e.clone();for(var r=te(t),i=e.getInverseBindMatrices().clone(),o=[],a=0,s=i.getCount();a<s;a++)i.getElement(a,o),n.multiply(o,o,r),i.setElement(a,o);return e.setInverseBindMatrices(i)}function J(e,t,r){for(var n=new t(e.getArray().length),i=j.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 v=Math.round(Math.abs(g[p])*s);n[c++]=(v=v<<u|v>>l)*Math.sign(g[p])}}e.setArray(n).setNormalized(!0)}function Y(e,t,r,n){var i,o,a=t.getMinNormalized([]),s=t.getMaxNormalized([]);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(B+": Skipping "+e+"; out of [0,1] 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(B+": Skipping "+e+"; out of [0,1] range."),{bits:-1};o=(i=n.quantizeWeight)<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(B+': Unexpected semantic, "'+e+'".');if(a.some(function(e){return e<-1})||s.some(function(e){return e>1}))return r.warn(B+": Skipping "+e+"; out of [-1,1] 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}}function $(e){for(var t,r=[],n=[],o=c(e.listPrimitives());!(t=o()).done;){var a=t.value,s=a.getAttribute("POSITION");s&&r.push(s);for(var u,l=c(a.listTargets());!(u=l()).done;){var f=u.value.getAttribute("POSITION");f&&n.push(f)}}if(0===r.length)throw new Error(B+': Missing "POSITION" attribute.');var g=ee(r,3);if(n.length>0){var p=ee(n,3),v=p.min,d=p.max;i.min(g.min,g.min,i.min(v,i.scale(v,v,2),[0,0,0])),i.max(g.max,g.max,i.max(d,i.scale(d,d,2),[0,0,0]))}return g}function ee(e,t){for(var r,n=new Array(t).fill(Infinity),i=new Array(t).fill(-Infinity),o=[],a=[],s=c(e);!(r=s()).done;){var u=r.value;u.getMinNormalized(o),u.getMaxNormalized(a);for(var l=0;l<t;l++)n[l]=Math.min(n[l],o[l]),i[l]=Math.max(i[l],a[l])}return{min:n,max:i}}function te(e){return n.fromRotationTranslationScale([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}var re={tolerance:1e-4};function ne(e,t){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),v=!1;if(f!==g&&(1!==l||f!==n.getScalar(0)))for(var d=0;d<i.getElementSize();d++){var m=i.getElement(l,s)[d],h=i.getElement(l-1,s)[d],y=i.getElement(l+1,s)[d];if("LINEAR"===e.getInterpolation()){if(Math.abs(m-(h*(1-(r=p))+y*r))>o){v=!0;break}}else if("STEP"===e.getInterpolation()&&(m!==h||m!==y)){v=!0;break}}v&&(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 ie={target:"size"};function oe(e,t,r){for(var n=e.getElementSize(),i=e.getCount(),o=e.getArray(),a=o.slice(0,r*n),s=0;s<i;s++)for(var u=0;u<n;u++)a[t[s]*n+u]=o[s*n+u];e.setArray(a)}function ae(e){for(var t,r=[],n=c(e.listAttributes());!(t=n()).done;)r.push(t.value);for(var i,o=c(e.listTargets());!(i=o()).done;)for(var a,s=c(i.value.listAttributes());!(a=s()).done;)r.push(a.value);return Array.from(new Set(r))}var se={name:"",fps:10,pattern:/.*/,sort:!0},ue="tangents",le={overwrite:!1};function fe(e){var t=e.getMaterial();if(!t)return"TEXCOORD_0";var r=t.getNormalTextureInfo();if(!r)return"TEXCOORD_0";var n="TEXCOORD_"+r.getTexCoord();return e.getAttribute(n)?n:"TEXCOORD_0"}function ce(t,r,n,i,o){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!o?(r.debug(ue+": Skipping primitive "+i+' of mesh "'+n+'": TANGENT found.'),!1):!t.getIndices()||(r.warn(ue+": Skipping primitive "+i+' of mesh "'+n+'": primitives must be unwelded.'),!1):(r.debug(ue+": Skipping primitive "+i+' of mesh "'+n+'": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.'),!1)}var ge="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function pe(e,t,r){if(!e.s){if(r instanceof ve){if(!r.s)return void(r.o=pe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(pe.bind(null,e,t),pe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ve=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{pe(n,1,o(this.v))}catch(e){pe(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?pe(n,1,t?t(i):i):r?pe(n,1,r(i)):pe(n,2,i)}catch(e){pe(n,2,e)}},n},e}();function de(e){return e instanceof ve&&1&e.s}var me,he="textureResize";(me=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",me.LANCZOS2="lanczos2";var ye={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},Ae={};function Te(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 Ee={tolerance:1e-4};function Se(t,r){if(!r.getIndices()){for(var n=r.listAttributes()[0],i=n.getCount(),o=n.getBuffer(),a=i<=65534?new Uint16Array(3*h(r)):new Uint32Array(3*h(r)),s=t.createAccessor().setBuffer(o).setType(e.Accessor.Type.SCALAR).setArray(a),u=0;u<s.getCount();u++)s.setScalar(u,u);r.setIndices(s)}}function be(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 f=[],g=0,p=0;p<u;p++){for(var v,d=s?s.getScalar(p):p,m=[],h=[],y=c(t.listAttributes());!(v=y()).done;)for(var A=v.value,T=0;T<A.getElementSize();T++)m.push(~~(A.getElement(d,h)[T]*o));var E=m.join("|");if(E in a)f.push(a[E]);else{for(var S,b=c(t.listAttributes());!(S=b()).done;){var I=S.value;l.get(I).push(I.getElement(d,[]))}for(var P,w=c(t.listTargets());!(P=w()).done;)for(var R,M=c(P.value.listAttributes());!(R=M()).done;){var N=R.value;l.get(N).push(N.getElement(d,[]))}a[E]=g,f.push(g),g++}}var C=t.listAttributes()[0].getCount(),x=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug("weld: "+C+" → "+x+" vertices.");for(var O,z=c(t.listAttributes());!(O=z()).done;){var L=O.value;Pe(t,L,l.get(L)),1===L.listParents().length&&L.dispose()}for(var U,_=c(t.listTargets());!(U=_()).done;)for(var F,k=U.value,G=c(k.listAttributes());!(F=G()).done;){var q=F.value;Pe(k,q,l.get(q)),1===q.listParents().length&&q.dispose()}if(s){var B=Ie(s.getArray(),f.length);B.set(f),t.setIndices(s.clone().setArray(B)),1===s.listParents().length&&s.dispose()}else{var j=C<=65534?new Uint16Array(f):new Uint32Array(f);t.setIndices(e.createAccessor().setArray(j))}}function Ie(e,t){return new(0,e.constructor)(t)}function Pe(e,t,r){for(var n=r.length*t.getElementSize(),i=Ie(t.getArray(),n),o=t.clone().setArray(i),a=0;a<r.length;a++)o.setElement(a,r[a]);e.swap(t,o)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.QUANTIZE_DEFAULTS=X,exports.TEXTURE_RESIZE_DEFAULTS=ye,exports.center=function(t){void 0===t&&(t=p);var r=l({},p,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=i.listAnimations().length>0||i.listSkins().length>0;t.getRoot().listScenes().forEach(function(a,s){var u;if(n.debug(g+": Scene "+(s+1)+" / "+i.listScenes().length+"."),"string"==typeof r.pivot){var l=e.bounds(a);u=[(l.max[0]-l.min[0])/2+l.min[0],(l.max[1]-l.min[1])/2+l.min[1],(l.max[2]-l.min[2])/2+l.min[2]],"above"===r.pivot&&(u[1]=l.max[1]),"below"===r.pivot&&(u[1]=l.min[1])}else u=r.pivot;n.debug(g+': Pivot "'+u.join(", ")+'".');var f=[-1*u[0],-1*u[1],-1*u[2]];if(o){n.debug(g+": Model contains animation or skin. Adding a wrapper node.");var c=t.createNode("Pivot").setTranslation(f);a.listChildren().forEach(function(e){return c.addChild(e)}),a.addChild(c)}else n.debug(g+": Skipping wrapper, offsetting all root nodes."),a.listChildren().forEach(function(e){var t=e.getTranslation();e.setTranslation([t[0]+f[0],t[1]+f[1],t[2]+f[2]])})}),n.debug(g+": 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=d,exports.inspect=function(e){return{scenes:A(e),meshes:T(e),materials:E(e),textures:S(e),animations:b(e)}},exports.instance=function(t){return void 0===t&&(t=M),l({},M,t),function(t){var n=t.getLogger(),i=t.getRoot(),o=t.createExtension(r.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 r=a.value,i=new Map;r.traverse(function(e){var t=e.getMesh();t&&i.set(t,(i.get(t)||new Set).add(e))});for(var l=[],f=0,c=Array.from(i.keys());f<c.length;f++){var g=c[f],p=Array.from(i.get(g));if(!(p.length<2||p.some(function(e){return e.getSkin()}))){var v=C(t,o,g,p.length),d=v.getAttribute("TRANSLATION"),m=v.getAttribute("ROTATION"),h=v.getAttribute("SCALE"),y=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",v);r.addChild(y);for(var A=!1,T=!1,E=!1,S=0;S<p.length;S++){var b,I,P,w=p[S];d.setElement(S,b=w.getWorldTranslation()),m.setElement(S,I=w.getWorldRotation()),h.setElement(S,P=w.getWorldScale()),e.MathUtils.eq(b,[0,0,0])||(A=!0),e.MathUtils.eq(I,[0,0,0,1])||(T=!0),e.MathUtils.eq(P,[1,1,1])||(E=!0),w.setMesh(null),l.push(w)}A||d.dispose(),T||m.dispose(),E||h.dispose(),N(l,n),s++,u+=p.length}}},f=c(i.listScenes());!(a=f()).done;)l();s>0?n.info(R+": Created "+s+" batches, with "+u+" total instances."):(n.info(R+": No meshes with multiple parent nodes were found."),o.dispose()),n.debug(R+": Complete.")}},exports.metalRough=function(e){return void 0===e&&(e=U),l({},U,e),function(e){try{var t=function(){s.dispose();for(var e,t=c(u);!(e=t()).done;){var r=e.value;r&&1===r.listParents().length&&r.dispose()}n.debug("metalRough: Complete.")},n=e.getLogger(),i=r.MaterialsPBRSpecularGlossiness.EXTENSION_NAME;if(!e.getRoot().listExtensionsUsed().map(function(e){return e.extensionName}).includes(i))return n.warn("metalRough: Extension "+i+" not found on given document."),Promise.resolve();var o=e.createExtension(r.MaterialsIOR),a=e.createExtension(r.MaterialsSpecular),s=e.createExtension(r.MaterialsPBRSpecularGlossiness),u=new Set,l=function(e,t,r){if("function"==typeof e[x]){var n,i,o,a=e[x]();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(m(l,o,function(e,t,r){e.set(t,r,3,255)})).then(function(){i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(r),i.getSpecularColorTextureInfo().copy(r);var a=n.getGlossinessFactor(),s=e.createTexture();return Promise.resolve(m(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(t){void 0===t&&(t=G);var r=l({},G,t);return function(t){try{var n=t.getLogger();return!1!==r.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(k+': Creating buffer for mesh "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(q(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(k+": Skipping mesh #"+o+' with name "'+i.getName()+'".')})}(t,n,r),!1!==r.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(k+': Creating buffer for animation "'+i.getName()+'".');var a=e.createBuffer(i.getName()).setURI(q(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(k+": Skipping animation #"+o+' with name "'+i.getName()+'".')})}(t,n,r),r.meshes||r.animations||n.warn(k+": Select animations or meshes to create a partition."),Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.BUFFER]}))).then(function(){n.debug(k+": Complete.")})}catch(e){return Promise.reject(e)}}},exports.prune=F,exports.quantize=function(t){void 0===t&&(t=X);var n=l({},X,t);return function(t){try{var o=t.getLogger(),a=t.getRoot();t.createExtension(r.MeshQuantization).setRequired(!0);var s=void 0;"scene"===n.quantizationVolume&&(s=K(function(e){for(var t,r=e[0],n=c(e);!(t=n()).done;){var o=t.value;i.min(r.min,r.min,o.min),i.max(r.max,r.max,o.max)}return r}(a.listMeshes().map($))));for(var u,l=c(t.getRoot().listMeshes());!(u=l()).done;){var f=u.value;"mesh"===n.quantizationVolume&&(s=K($(f))),s&&n.pattern.test("POSITION")&&Z(t,f,s);for(var g,p=c(f.listPrimitives());!(g=p()).done;){var v=g.value;H(t,v,s,n);for(var m,h=c(v.listTargets());!(m=h()).done;)H(t,m.value,s,n)}}return Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.SKIN]}),d({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){o.debug(B+": Complete.")})}catch(e){return Promise.reject(e)}}},exports.reorder=function(t){void 0===t&&(t=ie);var r=l({},ie,t),n=r.encoder;return function(t){try{var i=t.getLogger();return Promise.resolve(n.ready).then(function(){for(var o,a=function(e){for(var t,r=new y,n=new Map,i=new y,o=c(e.getRoot().listMeshes());!(t=o()).done;)for(var a,s=c(t.value.listPrimitives());!(a=s()).done;){var u=a.value,l=u.getIndices();if(l){n.set(l,u.getMode());for(var f,g=c(ae(u));!(f=g()).done;){var p=f.value;r.add(l,p),i.add(p,u)}}}return{indicesToAttributes:r,indicesToMode:n,attributesToPrimitives:i}}(t),s=c(a.indicesToAttributes.keys());!(o=s()).done;){var u=o.value,l=u.clone(),f=l.getArray().slice();f instanceof Uint32Array||(f=new Uint32Array(f));var g=n.reorderMesh(f,a.indicesToMode.get(u)===e.Primitive.Mode.TRIANGLES,"size"===r.target),p=g[0],v=g[1];l.setArray(v<=65534?new Uint16Array(f):f);for(var d,m=c(a.indicesToAttributes.get(u));!(d=m()).done;){var h=d.value,A=h.clone();oe(A,p,v);for(var T,E=c(a.attributesToPrimitives.get(h));!(T=E()).done;){var S=T.value;if(S.getIndices()===u&&S.swap(u,l),S.getIndices()===l){S.swap(h,A);for(var b,I=c(S.listTargets());!(b=I()).done;)b.value.swap(h,A)}}}}return Promise.resolve(t.transform(F({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){a.indicesToAttributes.size?i.debug("reorder: Complete."):i.warn("reorder: No qualifying primitives found; may need to weld first.")})})}catch(e){return Promise.reject(e)}}},exports.resample=function(t){void 0===t&&(t=re);var r=l({},re,t);return function(t){for(var n,i=new Set,o=t.getRoot().listAccessors().length,a=t.getLogger(),s=!1,u=c(t.getRoot().listAnimations());!(n=u()).done;){for(var l,f=n.value,g=new Set,p=c(f.listChannels());!(l=p()).done;){var v=l.value;v.getSampler()&&"weights"===v.getTargetPath()&&g.add(v.getSampler())}for(var d,m=c(f.listSamplers());!(d=m()).done;){var h=d.value;g.has(h)?s=!0:"STEP"!==h.getInterpolation()&&"LINEAR"!==h.getInterpolation()||(i.add(h.getInput()),i.add(h.getOutput()),ne(h,r))}}for(var y=0,A=Array.from(i.values());y<A.length;y++){var T=A[y];T.listParents().some(function(t){return!(t instanceof e.Root)})||T.dispose()}t.getRoot().listAccessors().length>o&&a.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),s&&a.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),a.debug("resample: Complete.")}},exports.sequence=function(t){void 0===t&&(t=se);var r=l({},se,t);return function(t){var n=t.getLogger(),i=t.getRoot(),o=r.fps,a=i.listNodes().filter(function(e){return e.getName().match(r.pattern)});r.sort&&a.sort(function(e,t){return e.getName()>t.getName()?1:-1});var s=t.createAnimation(r.name),u=i.listBuffers()[0];a.forEach(function(r,n){var i,l;0===n?(i=[n/o,(n+1)/o],l=[1,1,1,0,0,0]):n===a.length-1?(i=[(n-1)/o,n/o],l=[0,0,0,1,1,1]):(i=[(n-1)/o,n/o,(n+1)/o],l=[0,0,0,1,1,1,0,0,0]);var f=t.createAccessor().setArray(new Float32Array(i)).setBuffer(u),c=t.createAccessor().setArray(new Float32Array(l)).setBuffer(u).setType(e.Accessor.Type.VEC3),g=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(f).setOutput(c),p=t.createAnimationChannel().setTargetNode(r).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(g);s.addSampler(g).addChannel(p)}),n.debug("sequence: Complete.")}},exports.tangents=function(t){if(void 0===t&&(t=le),!t.generateTangents)throw new Error(ue+': generateTangents callback required — install "mikktspace".');var r=l({},le,t);return function(t){for(var n,i=t.getLogger(),o=new Map,a=new Map,s=0,u=c(t.getRoot().listMeshes());!(n=u()).done;)for(var l=n.value,f=l.getName(),g=l.listPrimitives(),p=0;p<g.length;p++){var v=g[p];if(ce(v,i,f,p,r.overwrite)){var d=fe(v),m=v.getAttribute("POSITION").getArray(),h=v.getAttribute("NORMAL").getArray(),y=v.getAttribute(d).getArray(),A=o.get(m)||e.uuid();o.set(m,A);var T=o.get(h)||e.uuid();o.set(h,T);var E=o.get(y)||e.uuid();o.set(y,E);var S=v.getAttribute("TANGENT");S&&2===S.listParents().length&&S.dispose();var b=A+"|"+T+"|"+E,I=a.get(b);if(I)i.debug(ue+": Found cache for primitive "+p+' of mesh "'+f+'".'),v.setAttribute("TANGENT",I),s++;else{i.debug(ue+": Generating for primitive "+p+' of mesh "'+f+'".');for(var P=v.getAttribute("POSITION").getBuffer(),w=r.generateTangents(m instanceof Float32Array?m:new Float32Array(m),h instanceof Float32Array?h:new Float32Array(h),y instanceof Float32Array?y:new Float32Array(y)),R=3;R<w.length;R+=4)w[R]*=-1;I=t.createAccessor().setBuffer(P).setArray(w).setType("VEC4"),v.setAttribute("TANGENT",I),a.set(b,I),s++}}}s?i.debug(ue+": Complete."):i.warn(ue+": No qualifying primitives found. See debug output.")}},exports.textureResize=function(e){void 0===e&&(e=ye);var r=l({},ye,e);return function(e){try{var n=function(e){i.debug(he+": Complete.")},i=e.getLogger(),o=function(e,t,r){if("function"==typeof e[ge]){var n,i,o,a=e[ge]();if(function e(r){try{for(;!(n=a.next()).done;)if((r=t(n.value))&&r.then){if(!de(r))return void r.then(e,o||(o=pe.bind(null,i=new ve,2)));r=r.v}i?pe(i,1,r):i=r}catch(e){pe(i||(i=new ve),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(!de(a))return void a.then(r,i||(i=pe.bind(null,n=new ve,2)));a=a.v}n?pe(n,1,a):n=a}catch(e){pe(n||(n=new ve),2,e)}}(),n}(u,function(e){return t(u[e])})}(e.getRoot().listTextures(),function(e){var n=e.getName(),o=e.getURI();if(!r.pattern||r.pattern.test(n)||r.pattern.test(o))if("image/png"===e.getMimeType()||"image/jpeg"===e.getMimeType()){var s=r.size,l=s[0],f=s[1],c=e.getSize(),g=c[0],p=c[1];if(!(g<=l&&p<=f)){var v=g,d=p;v>l&&(d=Math.floor(d*(l/v)),v=l),d>f&&(v=Math.floor(v*(f/d)),d=f);var m=new Uint8Array(e.getImage());return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(s){var l=u.default(new Uint8Array(v*d*4),[v,d,4]);i.debug(he+': Resizing "'+(o||n)+'", '+s.shape+" → "+l.shape+"...");try{r.filter===exports.TextureResizeFilter.LANCZOS3?a.lanczos3(s,l):a.lanczos2(s,l)}catch(e){if(e instanceof Error)return void i.warn(he+': Failed to resize "'+(o||n)+'": "'+e.message+'".');throw e}var f=e.setImage;return Promise.resolve(t.savePixels(l,e.getMimeType())).then(function(t){f.call(e,t.buffer)})})}i.debug(he+': Skipping "'+(o||n)+'", within size range.')}else i.warn('Skipping unsupported texture type, "'+e.getMimeType()+'".')});return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}},exports.unweld=function(e){return void 0===e&&(e=Ae),l({},Ae,e),function(e){for(var t,r=e.getLogger(),n=new Map,i=c(e.getRoot().listMeshes());!(t=i()).done;)for(var o,a=c(t.value.listPrimitives());!(o=a()).done;){var s=o.value,u=s.getIndices();if(u){for(var l,f=c(s.listAttributes());!(l=f()).done;){var g=l.value;s.swap(g,Te(g,u,r,n)),1===g.listParents().length&&g.dispose()}for(var p,v=c(s.listTargets());!(p=v()).done;)for(var d,m=p.value,h=c(m.listAttributes());!(d=h()).done;){var y=d.value;m.swap(y,Te(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=Ee);var t=l({},Ee,e);return function(e){for(var r,n=e.getLogger(),i=c(e.getRoot().listMeshes());!(r=i()).done;)for(var o,a=c(r.value.listPrimitives());!(o=a()).done;){var s=o.value;0===t.tolerance?Se(e,s):be(e,s,t)}n.debug("weld: Complete.")}};
//# sourceMappingURL=functions.js.map

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

import{bounds as t,PropertyType as e,BufferUtils as n,Root as s,Primitive as r,Texture as o,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,AnimationChannel as g,Animation as u,Accessor as f,AnimationSampler as p,uuid as m}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as d,savePixels as h}from"ndarray-pixels";import{MeshGPUInstancing as A,MaterialsIOR as y,MaterialsSpecular as E,MaterialsPBRSpecularGlossiness as T,MeshQuantization as S}from"@gltf-transform/extensions";import{invert as I,fromRotationTranslationScale as b,fromScaling as w,multiply as M}from"gl-matrix/mat4";import{transformMat4 as N,min as R,scale as C,max as O}from"gl-matrix/vec3";import x from"ndarray";import{lanczos3 as P,lanczos2 as z}from"ndarray-lanczos";function L(){return(L=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 $={pivot:"center"};function v(e=$){const n=L({},$,e);return e=>{const s=e.getLogger(),r=e.getRoot(),o=r.listAnimations().length>0||r.listSkins().length>0;e.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${r.listScenes().length}.`),"string"==typeof n.pivot){const e=t(i);c=[(e.max[0]-e.min[0])/2+e.min[0],(e.max[1]-e.min[1])/2+e.min[1],(e.max[2]-e.min[2])/2+e.min[2]],"above"===n.pivot&&(c[1]=e.max[1]),"below"===n.pivot&&(c[1]=e.min[1])}else c=n.pivot;s.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(o){s.debug("center: Model contains animation or skin. Adding a wrapper node.");const t=e.createNode("Pivot").setTranslation(l);i.listChildren().forEach(e=>t.addChild(e)),i.addChild(t)}else s.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(t=>{const e=t.getTranslation();t.setTranslation([e[0]+l[0],e[1]+l[1],e[2]+l[2]])})}),s.debug("center: Complete.")}}function _(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 k={propertyTypes:[e.ACCESSOR,e.MESH,e.TEXTURE]},F=function(t=k){const r=L({},k,t),o=new Set(r.propertyTypes);for(const t of r.propertyTypes)if(!k.propertyTypes.includes(t))throw new Error(`dedup: Unsupported deduplication on type "${t}".`);return t=>{const r=t.getLogger();o.has(e.ACCESSOR)&&function(t,e){const s=new Set,r=new Set,o=e.getRoot().listMeshes();function i(t){const e=new Map;for(let s=0;s<t.length;s++){const r=t[s],o=r.getArray().slice().buffer;if(!e.has(r))for(let s=0;s<t.length;s++){const i=t[s];r!==i&&(e.has(i)||r.getType()===i.getType()&&r.getComponentType()===i.getComponentType()&&r.getCount()===i.getCount()&&r.getNormalized()===i.getNormalized()&&n.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&&s.add(e)})});const a=i(Array.from(s));t.debug(`dedup: Found ${a.size} duplicates among ${s.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())}(r,t),o.has(e.MESH)&&function(t,n){const s=n.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 n=[];for(const e of t.listPrimitives()){const t=[];for(const n of e.listSemantics()){const s=e.getAttribute(n);t.push(n+":"+r.get(s))}const s=e.getIndices();s&&t.push("indices:"+r.get(s)),n.push(t.join(","))}const s=n.join(";");if(i.has(s)){const n=i.get(s);t.listParents().forEach(s=>{s.propertyType!==e.ROOT&&s.swap(t,n)}),t.dispose()}else i.set(s,t)}t.debug(`dedup: Found ${o-i.size} duplicates among ${o} meshes.`)}(r,t),o.has(e.TEXTURE)&&function(t,e){const r=e.getRoot(),o=r.listTextures(),i=new Map;for(let t=0;t<o.length;t++){const e=o[t],s=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]&&s&&a&&n.equals(s,a)&&i.set(r,e)}}t.debug(`dedup: Found ${i.size} duplicates among ${r.listTextures().length} textures.`),Array.from(i.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof s||n.swap(t,e)}),t.dispose()})}(r,t),r.debug("dedup: Complete.")}};async function U(t,e,n){if(!t)return null;const s=t.getImage();if(!s)return null;const r=await d(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 h(r,"image/png")).buffer;return e.setImage(o).setMimeType("image/png")}function q(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())}}class G{constructor(){this._map=new Map}get size(){return this._map.size}has(t){return this._map.has(t)}add(t,e){let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}get(t){return this._map.get(t)||new Set}keys(){return this._map.keys()}}function B(t){return{scenes:V(t),meshes:D(t),materials:X(t),textures:j(t),animations:W(t)}}function V(e){return{properties:e.getRoot().listScenes().map(e=>{const n=e.listChildren()[0],s=t(e);return{name:e.getName(),rootName:n?n.getName():"",bboxMin:K(s.min),bboxMax:K(s.max)}})}}function D(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+":"+Z(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(Z(e.getArray())),i.add(e)),s+=t.listAttributes()[0].getCount(),n+=q(t)});let a=0;Array.from(i).forEach(t=>a+=t.getArray().byteLength);const c=t.listPrimitives().map(t=>H[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 X(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 o&&r===e||!!(n instanceof o&&r instanceof i&&s.has(r))}).map(t=>t.getName());return{name:e.getName(),instances:n,textures:r,alphaMode:e.getAlphaMode(),doubleSided:e.getDoubleSided()}})}}function j(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=a.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:a.getMemSize(e.getImage(),e.getMimeType())}})}}function W(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 H=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function K(t){for(let e=0;e<t.length;e++)t[e].toFixed&&(t[e]=Number(t[e].toFixed(5)));return t}function Z(t){return t.constructor.name.replace("Array","").toLowerCase()}const J={};function Y(t=J){return L({},J,t),t=>{const e=t.getLogger(),n=t.getRoot(),s=t.createExtension(A);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 l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(t=>t.getSkin()))continue;const u=tt(t,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=t.createNode().setMesh(l).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()),c.eq(e,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(y=!0),r.setMesh(null),a.push(r)}h||f.dispose(),A||p.dispose(),y||m.dispose(),Q(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 Q(t,e){let n,s=0;for(;n=t.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const e=n.getParent();e instanceof l&&t.push(e),n.dispose(),s++}e.debug(`instance: Removed ${s} unused nodes.`)}function tt(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 et={};function nt(t=et){return L({},et,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(y),r=t.createExtension(E),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 U(c,r,(t,e,n)=>{t.set(e,n,3,255)}),o.setSpecularTexture(r),o.setSpecularColorTexture(r),o.getSpecularTextureInfo().copy(s),o.getSpecularColorTextureInfo().copy(s);const i=n.getGlossinessFactor(),a=t.createTexture();await U(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 st={propertyTypes:[e.NODE,e.SKIN,e.MESH,e.CAMERA,e.PRIMITIVE,e.PRIMITIVE_TARGET,e.ANIMATION,e.MATERIAL,e.TEXTURE,e.ACCESSOR,e.BUFFER]},rt=function(t=st){const n=L({},st,t).propertyTypes;return t=>{const r=t.getLogger(),o=t.getRoot(),i=t.getGraph(),a={};if(n.includes(e.NODE)&&o.listNodes().forEach(c),n.includes(e.SKIN)&&o.listSkins().forEach(c),n.includes(e.MESH)&&o.listMeshes().forEach(c),n.includes(e.CAMERA)&&o.listCameras().forEach(c),n.includes(e.PRIMITIVE)&&l(i,e.PRIMITIVE),n.includes(e.PRIMITIVE_TARGET)&&l(i,e.PRIMITIVE_TARGET),n.includes(e.ANIMATION))for(const t of o.listAnimations()){for(const e of t.listChannels())e.getTargetNode()||(e.dispose(),u(e));if(t.listChannels().length)t.listSamplers().forEach(c);else{const e=t.listSamplers();c(t),e.forEach(c)}}if(n.includes(e.MATERIAL)&&o.listMaterials().forEach(c),n.includes(e.TEXTURE)&&o.listTextures().forEach(c),n.includes(e.ACCESSOR)&&o.listAccessors().forEach(c),n.includes(e.BUFFER)&&o.listBuffers().forEach(c),Object.keys(a).length){const t=Object.keys(a).map(t=>`${t} (${a[t]})`).join(", ");r.info(`prune: Removed types... ${t}`)}else r.info("prune: No unused properties found.");function c(t){t.listParents().filter(t=>!(t instanceof s||t instanceof g)).length||(t.dispose(),u(t))}function l(t,e){t.getLinks().map(t=>t.getParent()).filter(t=>t.propertyType===e).forEach(c)}function u(t){a[t.propertyType]=a[t.propertyType]||0,a[t.propertyType]++}r.debug("prune: Complete.")}},ot={animations:!0,meshes:!0},it=(t=ot)=>{const n=L({},ot,t);return async t=>{const s=t.getLogger();!1!==n.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(at(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,s,n),!1!==n.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(at(r.getName()||"animation",s));r.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&e.setBuffer(i),n&&n.setBuffer(i)})})}(t,s,n),n.meshes||n.animations||s.warn("partition: Select animations or meshes to create a partition."),await t.transform(rt({propertyTypes:[e.BUFFER]})),s.debug("partition: Complete.")}};function at(t,e){let n=`${t}.bin`,s=1;for(;e.has(n);)n=`${t}_${s++}.bin`;return n}const ct=[Int8Array,Int16Array,Int32Array],lt={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},gt=(t=lt)=>{const n=L({},lt,t);return async t=>{const s=t.getLogger(),r=t.getRoot();let o;t.createExtension(S).setRequired(!0),"scene"===n.quantizationVolume&&(o=ft(function(t){const e=t[0];for(const n of t)R(e.min,e.min,n.min),O(e.max,e.max,n.max);return e}(r.listMeshes().map(At))));for(const e of t.getRoot().listMeshes()){"mesh"===n.quantizationVolume&&(o=ft(At(e))),o&&n.pattern.test("POSITION")&&pt(t,e,o);for(const s of e.listPrimitives()){ut(t,s,o,n);for(const e of s.listTargets())ut(t,e,o,n)}}await t.transform(rt({propertyTypes:[e.ACCESSOR,e.SKIN]}),F({propertyTypes:[e.ACCESSOR]})),s.debug("quantize: Complete.")}};function ut(t,e,n,s){const o=t.getLogger();for(const t of e.listSemantics()){if(!s.pattern.test(t))continue;const i=e.getAttribute(t),{bits:a,ctor:c}=ht(t,i,o,s);if(!c)continue;if(a<8||a>16)throw new Error("quantize: Requires bits = 8–16.");if(i.getComponentSize()<=a/8)continue;const l=i.clone();if("POSITION"===t){const t=n.scale,s=[];e instanceof r?I(s,Et(n)):w(s,[1/t,1/t,1/t]);for(let t=0,e=[0,0,0],n=l.getCount();t<n;t++)l.getElement(t,e),l.setElement(t,N(e,e,s))}dt(l,c,a),e.swap(i,l)}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 ft(t){const{min:e,max:n}=t,s=Math.max((n[0]-e[0])/2,(n[1]-e[1])/2,(n[2]-e[2])/2);return{offset:[e[0]+(n[0]-e[0])/2,e[1]+(n[1]-e[1])/2,e[2]+(n[2]-e[2])/2],scale:s}}function pt(t,e,n){const s=Et(n);for(const r of e.listParents())if(r instanceof l){const o=r.listChildren().length>0,i=!!r.listParents().find(t=>t instanceof u);if(r.getSkin()){r.setSkin(mt(r.getSkin(),n));continue}let a;o||i?(a=t.createNode("").setMesh(e),r.addChild(a).setMesh(null)):a=r;const c=a.getMatrix();M(c,c,s),a.setMatrix(c)}}function mt(t,e){t=t.clone();const n=Et(e),s=t.getInverseBindMatrices().clone(),r=[];for(let t=0,e=s.getCount();t<e;t++)s.getElement(t,r),M(r,r,n),s.setElement(t,r);return t.setInverseBindMatrices(s)}function dt(t,e,n){const s=new e(t.getArray().length),r=ct.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).setNormalized(!0)}function ht(t,e,n,s){const r=e.getMinNormalized([]),o=e.getMaxNormalized([]);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 [0,1] 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 [0,1] 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 [-1,1] 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}}function At(t){const e=[],n=[];for(const s of t.listPrimitives()){const t=s.getAttribute("POSITION");t&&e.push(t);for(const t of s.listTargets()){const e=t.getAttribute("POSITION");e&&n.push(e)}}if(0===e.length)throw new Error('quantize: Missing "POSITION" attribute.');const s=yt(e,3);if(n.length>0){const{min:t,max:e}=yt(n,3);R(s.min,s.min,R(t,C(t,t,2),[0,0,0])),O(s.max,s.max,O(e,C(e,e,2),[0,0,0]))}return s}function yt(t,e){const n=new Array(e).fill(Infinity),s=new Array(e).fill(-Infinity),r=[],o=[];for(const i of t){i.getMinNormalized(r),i.getMaxNormalized(o);for(let t=0;t<e;t++)n[t]=Math.min(n[t],r[t]),s[t]=Math.max(s[t],o[t])}return{min:n,max:s}}function Et(t){return b([],[0,0,0,1],t.offset,[t.scale,t.scale,t.scale])}const Tt={tolerance:1e-4},St=(t=Tt)=>{const e=L({},Tt,t);return t=>{const n=new Set,r=t.getRoot().listAccessors().length,o=t.getLogger();let i=!1;for(const s of t.getRoot().listAnimations()){const t=new Set;for(const e of s.listChannels())e.getSampler()&&"weights"===e.getTargetPath()&&t.add(e.getSampler());for(const r of s.listSamplers())t.has(r)?i=!0:"STEP"!==r.getInterpolation()&&"LINEAR"!==r.getInterpolation()||(n.add(r.getInput()),n.add(r.getOutput()),It(r,e))}for(const t of Array.from(n.values()))t.listParents().some(t=>!(t instanceof s))||t.dispose();t.getRoot().listAccessors().length>r&&o.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),i&&o.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),o.debug("resample: Complete.")}};function It(t,e){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 bt={target:"size"};function wt(t=bt){const n=L({},bt,t),s=n.encoder;return async t=>{const o=t.getLogger();await s.ready;const i=function(t){const e=new G,n=new Map,s=new G;for(const r of t.getRoot().listMeshes())for(const t of r.listPrimitives()){const r=t.getIndices();if(r){n.set(r,t.getMode());for(const n of Nt(t))e.add(r,n),s.add(n,t)}}return{indicesToAttributes:e,indicesToMode:n,attributesToPrimitives:s}}(t);for(const t of i.indicesToAttributes.keys()){const e=t.clone();let o=e.getArray().slice();o instanceof Uint32Array||(o=new Uint32Array(o));const[a,c]=s.reorderMesh(o,i.indicesToMode.get(t)===r.Mode.TRIANGLES,"size"===n.target);e.setArray(c<=65534?new Uint16Array(o):o);for(const n of i.indicesToAttributes.get(t)){const s=n.clone();Mt(s,a,c);for(const r of i.attributesToPrimitives.get(n))if(r.getIndices()===t&&r.swap(t,e),r.getIndices()===e){r.swap(n,s);for(const t of r.listTargets())t.swap(n,s)}}}await t.transform(rt({propertyTypes:[e.ACCESSOR]})),i.indicesToAttributes.size?o.debug("reorder: Complete."):o.warn("reorder: No qualifying primitives found; may need to weld first.")}}function Mt(t,e,n){const s=t.getElementSize(),r=t.getCount(),o=t.getArray(),i=o.slice(0,n*s);for(let t=0;t<r;t++)for(let n=0;n<s;n++)i[e[t]*s+n]=o[t*s+n];t.setArray(i)}function Nt(t){const e=[];for(const n of t.listAttributes())e.push(n);for(const n of t.listTargets())for(const t of n.listAttributes())e.push(t);return Array.from(new Set(e))}const Rt={name:"",fps:10,pattern:/.*/,sort:!0};function Ct(t=Rt){const e=L({},Rt,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),u=t.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(f.Type.VEC3),m=t.createAnimationSampler().setInterpolation(p.Interpolation.STEP).setInput(l).setOutput(u),d=t.createAnimationChannel().setTargetNode(e).setTargetPath(g.TargetPath.SCALE).setSampler(m);i.addSampler(m).addChannel(d)}),n.debug("sequence: Complete.")}}const Ot={overwrite:!1};function xt(t=Ot){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const e=L({},Ot,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(!zt(l,n,a,i,e.overwrite))continue;const g=Pt(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),p=l.getAttribute(g).getArray(),d=s.get(u)||m();s.set(u,d);const h=s.get(f)||m();s.set(f,h);const A=s.get(p)||m();s.set(p,A);const y=l.getAttribute("TANGENT");y&&2===y.listParents().length&&y.dispose();const E=`${d}|${h}|${A}`;let T=r.get(E);if(T){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",T),o++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),I=e.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p));for(let t=3;t<I.length;t+=4)I[t]*=-1;T=t.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",T),r.set(E,T),o++}}o?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")}}function Pt(t){const e=t.getMaterial();if(!e)return"TEXCOORD_0";const n=e.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const s=`TEXCOORD_${n.getTexCoord()}`;return t.getAttribute(s)?s:"TEXCOORD_0"}function zt(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 Lt="textureResize";var $t;!function(t){t.LANCZOS3="lanczos3",t.LANCZOS2="lanczos2"}($t||($t={}));const vt={size:[2048,2048],filter:$t.LANCZOS3,pattern:null};function _t(t=vt){const e=L({},vt,t);return async t=>{const n=t.getLogger();for(const s of t.getRoot().listTextures()){const t=s.getName(),r=s.getURI();if(e.pattern&&!e.pattern.test(t)&&!e.pattern.test(r))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[o,i]=e.size,[a,c]=s.getSize();if(a<=o&&c<=i){n.debug(`${Lt}: Skipping "${r||t}", within size range.`);continue}let l=a,g=c;l>o&&(g=Math.floor(g*(o/l)),l=o),g>i&&(l=Math.floor(l*(i/g)),g=i);const u=new Uint8Array(s.getImage()),f=await d(u,s.getMimeType()),p=x(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${Lt}: Resizing "${r||t}", ${f.shape} → ${p.shape}...`);try{e.filter===$t.LANCZOS3?P(f,p):z(f,p)}catch(e){if(e instanceof Error){n.warn(`${Lt}: Failed to resize "${r||t}": "${e.message}".`);continue}throw e}s.setImage((await h(p,s.getMimeType())).buffer)}n.debug(`${Lt}: Complete.`)}}const kt={};function Ft(t=kt){return L({},kt,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,Ut(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,Ut(t,s,e,n)),1===t.listParents().length&&t.dispose();t.setIndices(null),1===s.listParents().length&&s.dispose()}}e.debug("unweld: Complete.")}}function Ut(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 qt={tolerance:1e-4};function Gt(t=qt){const e=L({},qt,t);return t=>{const n=t.getLogger();for(const n of t.getRoot().listMeshes())for(const s of n.listPrimitives())0===e.tolerance?Bt(t,s):Vt(t,s,e);n.debug("weld: Complete.")}}function Bt(t,e){if(e.getIndices())return;const n=e.listAttributes()[0],s=n.getCount(),r=n.getBuffer(),o=s<=65534?new Uint16Array(3*q(e)):new Uint32Array(3*q(e)),i=t.createAccessor().setBuffer(r).setType(f.Type.SCALAR).setArray(o);for(let t=0;t<i.getCount();t++)i.setScalar(t,t);e.setIndices(i)}function Vt(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())Xt(e,t,l.get(t)),1===t.listParents().length&&t.dispose();for(const t of e.listTargets())for(const e of t.listAttributes())Xt(t,e,l.get(e)),1===e.listParents().length&&e.dispose();if(a){const t=Dt(a.getArray(),g.length);t.set(g),e.setIndices(a.clone().setArray(t)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(g):new Uint32Array(g);e.setIndices(t.createAccessor().setArray(n))}}function Dt(t,e){return new(0,t.constructor)(e)}function Xt(t,e,n){const s=n.length*e.getElementSize(),r=Dt(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{lt as QUANTIZE_DEFAULTS,vt as TEXTURE_RESIZE_DEFAULTS,$t as TextureResizeFilter,v as center,_ as colorspace,F as dedup,B as inspect,Y as instance,nt as metalRough,it as partition,rt as prune,gt as quantize,wt as reorder,St as resample,Ct as sequence,xt as tangents,_t as textureResize,Ft as unweld,Gt as weld};
import{bounds as t,PropertyType as e,BufferUtils as n,Root as s,Primitive as r,Texture as o,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,AnimationChannel as g,Accessor as u,AnimationSampler as f,uuid as p}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as m,savePixels as d}from"ndarray-pixels";import{MeshGPUInstancing as h,MaterialsIOR as A,MaterialsSpecular as y,MaterialsPBRSpecularGlossiness as T,MeshQuantization as E}from"@gltf-transform/extensions";import{invert as S,fromRotationTranslationScale as I,fromScaling as b,multiply as w}from"gl-matrix/mat4";import{transformMat4 as N,min as M,scale as R,max as C}from"gl-matrix/vec3";import O from"ndarray";import{lanczos3 as x,lanczos2 as P}from"ndarray-lanczos";function z(){return(z=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 L={pivot:"center"};function $(e=L){const n=z({},L,e);return e=>{const s=e.getLogger(),r=e.getRoot(),o=r.listAnimations().length>0||r.listSkins().length>0;e.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${r.listScenes().length}.`),"string"==typeof n.pivot){const e=t(i);c=[(e.max[0]-e.min[0])/2+e.min[0],(e.max[1]-e.min[1])/2+e.min[1],(e.max[2]-e.min[2])/2+e.min[2]],"above"===n.pivot&&(c[1]=e.max[1]),"below"===n.pivot&&(c[1]=e.min[1])}else c=n.pivot;s.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(o){s.debug("center: Model contains animation or skin. Adding a wrapper node.");const t=e.createNode("Pivot").setTranslation(l);i.listChildren().forEach(e=>t.addChild(e)),i.addChild(t)}else s.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(t=>{const e=t.getTranslation();t.setTranslation([e[0]+l[0],e[1]+l[1],e[2]+l[2]])})}),s.debug("center: Complete.")}}function v(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 _={propertyTypes:[e.ACCESSOR,e.MESH,e.TEXTURE]},k=function(t=_){const r=z({},_,t),o=new Set(r.propertyTypes);for(const t of r.propertyTypes)if(!_.propertyTypes.includes(t))throw new Error(`dedup: Unsupported deduplication on type "${t}".`);return t=>{const r=t.getLogger();o.has(e.ACCESSOR)&&function(t,e){const s=new Set,r=new Set,o=e.getRoot().listMeshes();function i(t){const e=new Map;for(let s=0;s<t.length;s++){const r=t[s],o=r.getArray().slice().buffer;if(!e.has(r))for(let s=0;s<t.length;s++){const i=t[s];r!==i&&(e.has(i)||r.getType()===i.getType()&&r.getComponentType()===i.getComponentType()&&r.getCount()===i.getCount()&&r.getNormalized()===i.getNormalized()&&n.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&&s.add(e)})});const a=i(Array.from(s));t.debug(`dedup: Found ${a.size} duplicates among ${s.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())}(r,t),o.has(e.MESH)&&function(t,n){const s=n.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 n=[];for(const e of t.listPrimitives()){const t=[];for(const n of e.listSemantics()){const s=e.getAttribute(n);t.push(n+":"+r.get(s))}const s=e.getIndices();s&&t.push("indices:"+r.get(s)),n.push(t.join(","))}const s=n.join(";");if(i.has(s)){const n=i.get(s);t.listParents().forEach(s=>{s.propertyType!==e.ROOT&&s.swap(t,n)}),t.dispose()}else i.set(s,t)}t.debug(`dedup: Found ${o-i.size} duplicates among ${o} meshes.`)}(r,t),o.has(e.TEXTURE)&&function(t,e){const r=e.getRoot(),o=r.listTextures(),i=new Map;for(let t=0;t<o.length;t++){const e=o[t],s=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]&&s&&a&&n.equals(s,a)&&i.set(r,e)}}t.debug(`dedup: Found ${i.size} duplicates among ${r.listTextures().length} textures.`),Array.from(i.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof s||n.swap(t,e)}),t.dispose()})}(r,t),r.debug("dedup: Complete.")}};async function F(t,e,n){if(!t)return null;const s=t.getImage();if(!s)return null;const r=await m(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 d(r,"image/png")).buffer;return e.setImage(o).setMimeType("image/png")}function U(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())}}class G{constructor(){this._map=new Map}get size(){return this._map.size}has(t){return this._map.has(t)}add(t,e){let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}get(t){return this._map.get(t)||new Set}keys(){return this._map.keys()}}function q(t){return{scenes:B(t),meshes:V(t),materials:W(t),textures:D(t),animations:X(t)}}function B(e){return{properties:e.getRoot().listScenes().map(e=>{const n=e.listChildren()[0],s=t(e);return{name:e.getName(),rootName:n?n.getName():"",bboxMin:j(s.min),bboxMax:j(s.max)}})}}function V(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+":"+K(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(K(e.getArray())),i.add(e)),s+=t.listAttributes()[0].getCount(),n+=U(t)});let a=0;Array.from(i).forEach(t=>a+=t.getArray().byteLength);const c=t.listPrimitives().map(t=>H[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 W(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 o&&r===e||!!(n instanceof o&&r instanceof i&&s.has(r))}).map(t=>t.getName());return{name:e.getName(),instances:n,textures:r,alphaMode:e.getAlphaMode(),doubleSided:e.getDoubleSided()}})}}function D(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=a.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:a.getMemSize(e.getImage(),e.getMimeType())}})}}function X(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 H=["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 K(t){return t.constructor.name.replace("Array","").toLowerCase()}const Z={};function J(t=Z){return z({},Z,t),t=>{const e=t.getLogger(),n=t.getRoot(),s=t.createExtension(h);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 l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(t=>t.getSkin()))continue;const u=Q(t,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=t.createNode().setMesh(l).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()),c.eq(e,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(y=!0),r.setMesh(null),a.push(r)}h||f.dispose(),A||p.dispose(),y||m.dispose(),Y(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 Y(t,e){let n,s=0;for(;n=t.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const e=n.getParent();e instanceof l&&t.push(e),n.dispose(),s++}e.debug(`instance: Removed ${s} unused nodes.`)}function Q(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 tt={};function et(t=tt){return z({},tt,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(A),r=t.createExtension(y),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 F(c,r,(t,e,n)=>{t.set(e,n,3,255)}),o.setSpecularTexture(r),o.setSpecularColorTexture(r),o.getSpecularTextureInfo().copy(s),o.getSpecularColorTextureInfo().copy(s);const i=n.getGlossinessFactor(),a=t.createTexture();await F(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 nt={propertyTypes:[e.NODE,e.SKIN,e.MESH,e.CAMERA,e.PRIMITIVE,e.PRIMITIVE_TARGET,e.ANIMATION,e.MATERIAL,e.TEXTURE,e.ACCESSOR,e.BUFFER]},st=function(t=nt){const n=z({},nt,t).propertyTypes;return t=>{const r=t.getLogger(),o=t.getRoot(),i=t.getGraph(),a={};if(n.includes(e.NODE)&&o.listNodes().forEach(c),n.includes(e.SKIN)&&o.listSkins().forEach(c),n.includes(e.MESH)&&o.listMeshes().forEach(c),n.includes(e.CAMERA)&&o.listCameras().forEach(c),n.includes(e.PRIMITIVE)&&l(i,e.PRIMITIVE),n.includes(e.PRIMITIVE_TARGET)&&l(i,e.PRIMITIVE_TARGET),n.includes(e.ANIMATION))for(const t of o.listAnimations()){for(const e of t.listChannels())e.getTargetNode()||(e.dispose(),u(e));if(t.listChannels().length)t.listSamplers().forEach(c);else{const e=t.listSamplers();c(t),e.forEach(c)}}if(n.includes(e.MATERIAL)&&o.listMaterials().forEach(c),n.includes(e.TEXTURE)&&o.listTextures().forEach(c),n.includes(e.ACCESSOR)&&o.listAccessors().forEach(c),n.includes(e.BUFFER)&&o.listBuffers().forEach(c),Object.keys(a).length){const t=Object.keys(a).map(t=>`${t} (${a[t]})`).join(", ");r.info(`prune: Removed types... ${t}`)}else r.info("prune: No unused properties found.");function c(t){t.listParents().filter(t=>!(t instanceof s||t instanceof g)).length||(t.dispose(),u(t))}function l(t,e){t.getLinks().map(t=>t.getParent()).filter(t=>t.propertyType===e).forEach(c)}function u(t){a[t.propertyType]=a[t.propertyType]||0,a[t.propertyType]++}r.debug("prune: Complete.")}},rt={animations:!0,meshes:!0},ot=(t=rt)=>{const n=z({},rt,t);return async t=>{const s=t.getLogger();!1!==n.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(it(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,s,n),!1!==n.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(it(r.getName()||"animation",s));r.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&e.setBuffer(i),n&&n.setBuffer(i)})})}(t,s,n),n.meshes||n.animations||s.warn("partition: Select animations or meshes to create a partition."),await t.transform(st({propertyTypes:[e.BUFFER]})),s.debug("partition: Complete.")}};function it(t,e){let n=`${t}.bin`,s=1;for(;e.has(n);)n=`${t}_${s++}.bin`;return n}const at=[Int8Array,Int16Array,Int32Array],{TRANSLATION:ct,ROTATION:lt,SCALE:gt,WEIGHTS:ut}=g.TargetPath,ft=[ct,lt,gt],pt={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},mt=(t=pt)=>{const n=z({},pt,t);return async t=>{const s=t.getLogger(),r=t.getRoot();let o;t.createExtension(E).setRequired(!0),"scene"===n.quantizationVolume&&(o=ht(function(t){const e=t[0];for(const n of t)M(e.min,e.min,n.min),C(e.max,e.max,n.max);return e}(r.listMeshes().map(St))));for(const e of t.getRoot().listMeshes()){"mesh"===n.quantizationVolume&&(o=ht(St(e))),o&&n.pattern.test("POSITION")&&At(t,e,o);for(const s of e.listPrimitives()){dt(t,s,o,n);for(const e of s.listTargets())dt(t,e,o,n)}}await t.transform(st({propertyTypes:[e.ACCESSOR,e.SKIN]}),k({propertyTypes:[e.ACCESSOR]})),s.debug("quantize: Complete.")}};function dt(t,e,n,s){const o=t.getLogger();for(const t of e.listSemantics()){if(!s.pattern.test(t))continue;const i=e.getAttribute(t),{bits:a,ctor:c}=Et(t,i,o,s);if(!c)continue;if(a<8||a>16)throw new Error("quantize: Requires bits = 8–16.");if(i.getComponentSize()<=a/8)continue;const l=i.clone();if("POSITION"===t){const t=n.scale,s=[];e instanceof r?S(s,bt(n)):b(s,[1/t,1/t,1/t]);for(let t=0,e=[0,0,0],n=l.getCount();t<n;t++)l.getElement(t,e),l.setElement(t,N(e,e,s))}Tt(l,c,a),e.swap(i,l)}if(e.getAttribute("WEIGHTS_0")&&function(t){const e=t.getAttribute("POSITION").getCount(),n=[];for(let s=0;s<e;s++){let e,r=0,o=Infinity,i=-1,a=null,c=0;for(;e=t.getAttribute("WEIGHTS_"+c++);){e.getElement(s,n);for(let t=0;t<n.length;t++)r+=n[t],n[t]>0&&n[t]<o&&(a=e,o=n[t],i=t)}a&&1!==r&&(a.getElement(s,n),n[i]+=1-r,a.setElement(s,n))}}(e),e instanceof r&&e.getIndices()&&e.listAttributes().length&&e.listAttributes()[0].getCount()<65535){const t=e.getIndices();t.setArray(new Uint16Array(t.getArray()))}}function ht(t){const{min:e,max:n}=t,s=Math.max((n[0]-e[0])/2,(n[1]-e[1])/2,(n[2]-e[2])/2);return{offset:[e[0]+(n[0]-e[0])/2,e[1]+(n[1]-e[1])/2,e[2]+(n[2]-e[2])/2],scale:s}}function At(t,e,n){const s=bt(n);for(const r of e.listParents())if(r instanceof l){const o=r.listParents().filter(t=>t instanceof g),i=o.some(t=>ft.includes(t.getTargetPath())),a=r.listChildren().length>0;if(r.getSkin()){r.setSkin(yt(r.getSkin(),n));continue}let c;a||i?(c=t.createNode("").setMesh(e),r.addChild(c).setMesh(null),o.filter(t=>t.getTargetPath()===ut).forEach(t=>t.setTargetNode(c))):c=r;const l=c.getMatrix();w(l,l,s),c.setMatrix(l)}}function yt(t,e){t=t.clone();const n=bt(e),s=t.getInverseBindMatrices().clone(),r=[];for(let t=0,e=s.getCount();t<e;t++)s.getElement(t,r),w(r,r,n),s.setElement(t,r);return t.setInverseBindMatrices(s)}function Tt(t,e,n){const s=new e(t.getArray().length),r=at.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).setNormalized(!0)}function Et(t,e,n,s){const r=e.getMinNormalized([]),o=e.getMaxNormalized([]);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 [0,1] 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 [0,1] 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 [-1,1] 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}}function St(t){const e=[],n=[];for(const s of t.listPrimitives()){const t=s.getAttribute("POSITION");t&&e.push(t);for(const t of s.listTargets()){const e=t.getAttribute("POSITION");e&&n.push(e)}}if(0===e.length)throw new Error('quantize: Missing "POSITION" attribute.');const s=It(e,3);if(n.length>0){const{min:t,max:e}=It(n,3);M(s.min,s.min,M(t,R(t,t,2),[0,0,0])),C(s.max,s.max,C(e,R(e,e,2),[0,0,0]))}return s}function It(t,e){const n=new Array(e).fill(Infinity),s=new Array(e).fill(-Infinity),r=[],o=[];for(const i of t){i.getMinNormalized(r),i.getMaxNormalized(o);for(let t=0;t<e;t++)n[t]=Math.min(n[t],r[t]),s[t]=Math.max(s[t],o[t])}return{min:n,max:s}}function bt(t){return I([],[0,0,0,1],t.offset,[t.scale,t.scale,t.scale])}const wt={tolerance:1e-4},Nt=(t=wt)=>{const e=z({},wt,t);return t=>{const n=new Set,r=t.getRoot().listAccessors().length,o=t.getLogger();let i=!1;for(const s of t.getRoot().listAnimations()){const t=new Set;for(const e of s.listChannels())e.getSampler()&&"weights"===e.getTargetPath()&&t.add(e.getSampler());for(const r of s.listSamplers())t.has(r)?i=!0:"STEP"!==r.getInterpolation()&&"LINEAR"!==r.getInterpolation()||(n.add(r.getInput()),n.add(r.getOutput()),Mt(r,e))}for(const t of Array.from(n.values()))t.listParents().some(t=>!(t instanceof s))||t.dispose();t.getRoot().listAccessors().length>r&&o.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),i&&o.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),o.debug("resample: Complete.")}};function Mt(t,e){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 Rt={target:"size"};function Ct(t=Rt){const n=z({},Rt,t),s=n.encoder;return async t=>{const o=t.getLogger();await s.ready;const i=function(t){const e=new G,n=new Map,s=new G;for(const r of t.getRoot().listMeshes())for(const t of r.listPrimitives()){const r=t.getIndices();if(r){n.set(r,t.getMode());for(const n of xt(t))e.add(r,n),s.add(n,t)}}return{indicesToAttributes:e,indicesToMode:n,attributesToPrimitives:s}}(t);for(const t of i.indicesToAttributes.keys()){const e=t.clone();let o=e.getArray().slice();o instanceof Uint32Array||(o=new Uint32Array(o));const[a,c]=s.reorderMesh(o,i.indicesToMode.get(t)===r.Mode.TRIANGLES,"size"===n.target);e.setArray(c<=65534?new Uint16Array(o):o);for(const n of i.indicesToAttributes.get(t)){const s=n.clone();Ot(s,a,c);for(const r of i.attributesToPrimitives.get(n))if(r.getIndices()===t&&r.swap(t,e),r.getIndices()===e){r.swap(n,s);for(const t of r.listTargets())t.swap(n,s)}}}await t.transform(st({propertyTypes:[e.ACCESSOR]})),i.indicesToAttributes.size?o.debug("reorder: Complete."):o.warn("reorder: No qualifying primitives found; may need to weld first.")}}function Ot(t,e,n){const s=t.getElementSize(),r=t.getCount(),o=t.getArray(),i=o.slice(0,n*s);for(let t=0;t<r;t++)for(let n=0;n<s;n++)i[e[t]*s+n]=o[t*s+n];t.setArray(i)}function xt(t){const e=[];for(const n of t.listAttributes())e.push(n);for(const n of t.listTargets())for(const t of n.listAttributes())e.push(t);return Array.from(new Set(e))}const Pt={name:"",fps:10,pattern:/.*/,sort:!0};function zt(t=Pt){const e=z({},Pt,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),p=t.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(u.Type.VEC3),m=t.createAnimationSampler().setInterpolation(f.Interpolation.STEP).setInput(l).setOutput(p),d=t.createAnimationChannel().setTargetNode(e).setTargetPath(g.TargetPath.SCALE).setSampler(m);i.addSampler(m).addChannel(d)}),n.debug("sequence: Complete.")}}const Lt={overwrite:!1};function $t(t=Lt){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const e=z({},Lt,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(!_t(l,n,a,i,e.overwrite))continue;const g=vt(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),m=l.getAttribute(g).getArray(),d=s.get(u)||p();s.set(u,d);const h=s.get(f)||p();s.set(f,h);const A=s.get(m)||p();s.set(m,A);const y=l.getAttribute("TANGENT");y&&2===y.listParents().length&&y.dispose();const T=`${d}|${h}|${A}`;let E=r.get(T);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(),I=e.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),m instanceof Float32Array?m:new Float32Array(m));for(let t=3;t<I.length;t+=4)I[t]*=-1;E=t.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",E),r.set(T,E),o++}}o?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")}}function vt(t){const e=t.getMaterial();if(!e)return"TEXCOORD_0";const n=e.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const s=`TEXCOORD_${n.getTexCoord()}`;return t.getAttribute(s)?s:"TEXCOORD_0"}function _t(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 kt="textureResize";var Ft;!function(t){t.LANCZOS3="lanczos3",t.LANCZOS2="lanczos2"}(Ft||(Ft={}));const Ut={size:[2048,2048],filter:Ft.LANCZOS3,pattern:null};function Gt(t=Ut){const e=z({},Ut,t);return async t=>{const n=t.getLogger();for(const s of t.getRoot().listTextures()){const t=s.getName(),r=s.getURI();if(e.pattern&&!e.pattern.test(t)&&!e.pattern.test(r))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[o,i]=e.size,[a,c]=s.getSize();if(a<=o&&c<=i){n.debug(`${kt}: Skipping "${r||t}", within size range.`);continue}let l=a,g=c;l>o&&(g=Math.floor(g*(o/l)),l=o),g>i&&(l=Math.floor(l*(i/g)),g=i);const u=new Uint8Array(s.getImage()),f=await m(u,s.getMimeType()),p=O(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${kt}: Resizing "${r||t}", ${f.shape} → ${p.shape}...`);try{e.filter===Ft.LANCZOS3?x(f,p):P(f,p)}catch(e){if(e instanceof Error){n.warn(`${kt}: Failed to resize "${r||t}": "${e.message}".`);continue}throw e}s.setImage((await d(p,s.getMimeType())).buffer)}n.debug(`${kt}: Complete.`)}}const qt={};function Bt(t=qt){return z({},qt,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,Vt(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,Vt(t,s,e,n)),1===t.listParents().length&&t.dispose();t.setIndices(null),1===s.listParents().length&&s.dispose()}}e.debug("unweld: Complete.")}}function Vt(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 Dt(t=Wt){const e=z({},Wt,t);return t=>{const n=t.getLogger();for(const n of t.getRoot().listMeshes())for(const s of n.listPrimitives())0===e.tolerance?Xt(t,s):Ht(t,s,e);n.debug("weld: Complete.")}}function Xt(t,e){if(e.getIndices())return;const n=e.listAttributes()[0],s=n.getCount(),r=n.getBuffer(),o=s<=65534?new Uint16Array(3*U(e)):new Uint32Array(3*U(e)),i=t.createAccessor().setBuffer(r).setType(u.Type.SCALAR).setArray(o);for(let t=0;t<i.getCount();t++)i.setScalar(t,t);e.setIndices(i)}function Ht(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())Kt(e,t,l.get(t)),1===t.listParents().length&&t.dispose();for(const t of e.listTargets())for(const e of t.listAttributes())Kt(t,e,l.get(e)),1===e.listParents().length&&e.dispose();if(a){const t=jt(a.getArray(),g.length);t.set(g),e.setIndices(a.clone().setArray(t)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(g):new Uint32Array(g);e.setIndices(t.createAccessor().setArray(n))}}function jt(t,e){return new(0,t.constructor)(e)}function Kt(t,e,n){const s=n.length*e.getElementSize(),r=jt(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{pt as QUANTIZE_DEFAULTS,Ut as TEXTURE_RESIZE_DEFAULTS,Ft as TextureResizeFilter,$ as center,v as colorspace,k as dedup,q as inspect,J as instance,et as metalRough,ot as partition,st as prune,mt as quantize,Ct as reorder,Nt as resample,zt as sequence,$t as tangents,Gt as textureResize,Bt as unweld,Dt as weld};
//# sourceMappingURL=functions.modern.js.map
{
"name": "@gltf-transform/functions",
"version": "0.12.14",
"version": "0.12.15",
"repository": "github:donmccurdy/glTF-Transform",

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

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

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

},
"gitHead": "ae7e98b60c0fb214d4f01e130f3d9bc5b6bedb1b"
"gitHead": "214a9df136ebd3aa5c61e364c1aa6d715e0ef59d"
}

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

import { Accessor, Animation, bbox, Document, Logger, mat4, Mesh, Node, Primitive, PrimitiveTarget, PropertyType, Skin, Transform, vec2, vec3, vec4 } from '@gltf-transform/core';
import { Accessor, AnimationChannel, bbox, Document, Logger, mat4, Mesh, Node, Primitive, PrimitiveTarget, PropertyType, Skin, Transform, vec2, vec3, vec4 } from '@gltf-transform/core';
import { dedup } from './dedup';

@@ -16,2 +16,4 @@ import { fromRotationTranslationScale, fromScaling, invert, multiply as multiplyMat4 } from 'gl-matrix/mat4';

const { TRANSLATION, ROTATION, SCALE, WEIGHTS } = AnimationChannel.TargetPath;
const TRS_CHANNELS = [TRANSLATION, ROTATION, SCALE];

@@ -145,2 +147,7 @@ /** Options for the {@link quantize} function. */

// Normalize skinning weights.
if (prim.getAttribute('WEIGHTS_0')) {
normalizeWeights(prim);
}
if (prim instanceof Primitive

@@ -186,4 +193,7 @@ && prim.getIndices()

if (parent instanceof Node) {
const animChannels = parent.listParents()
.filter((p) => p instanceof AnimationChannel) as AnimationChannel[];
const isAnimated = animChannels
.some((channel) => TRS_CHANNELS.includes(channel.getTargetPath()!));
const isParentNode = parent.listChildren().length > 0;
const isAnimated = !!parent.listParents().find((p) => p instanceof Animation);

@@ -199,2 +209,5 @@ if (parent.getSkin()) {

parent.addChild(targetNode).setMesh(null);
animChannels
.filter((channel) => channel.getTargetPath() === WEIGHTS)
.forEach((channel) => channel.setTargetNode(targetNode));
} else {

@@ -398,2 +411,38 @@ targetNode = parent;

function normalizeWeights(prim: Primitive | PrimitiveTarget): void {
const vertexCount = prim.getAttribute('POSITION')!.getCount();
const weightsEl: number[] = [];
for (let i = 0; i < vertexCount; i++) {
let vertexWeightsSum = 0;
let leastWeight = Infinity;
let leastIndex = -1;
let leastAttribute: Accessor | null = null;
let weights: Accessor | null;
let attributeIndex = 0;
// Find sum of weights and the joint with the lowest non-zero weight.
while ((weights = prim.getAttribute(`WEIGHTS_${attributeIndex++}`))) {
weights.getElement(i, weightsEl);
for (let j = 0; j < weightsEl.length; j++) {
vertexWeightsSum += weightsEl[j];
if (weightsEl[j] > 0 && weightsEl[j] < leastWeight) {
leastAttribute = weights;
leastWeight = weightsEl[j];
leastIndex = j;
}
}
}
// Normalize by updating least-significant joint weight.
if (leastAttribute && vertexWeightsSum !== 1) {
leastAttribute.getElement(i, weightsEl);
weightsEl[leastIndex] += 1 - vertexWeightsSum;
leastAttribute.setElement(i, weightsEl);
}
}
}
export { quantize };

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