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

@gltf-transform/functions

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/functions - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

2

dist/functions.js

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

var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),n=require("@gltf-transform/extensions"),r=require("gl-matrix/mat4"),o=require("gl-matrix/vec3"),s=require("ndarray"),i=require("ndarray-lanczos");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/a(s);const u=function(e,n,r){try{if(!e)return Promise.resolve(null);const o=e.getImage();return o?Promise.resolve(t.getPixels(o,e.getMimeType())).then(function(e){for(let t=0;t<e.shape[0];++t)for(let n=0;n<e.shape[1];++n)r(e,t,n);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return n.setImage(e).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function l(e,t){return Object.defineProperty(t,"name",{value:e}),t}class g{constructor(){this._map=new Map}get size(){return this._map.size}has(e){return this._map.has(e)}add(e,t){let n=this._map.get(e);return n||(n=new Set,this._map.set(e,n)),n.add(t),this}get(e){return this._map.get(e)||new Set}keys(){return this._map.keys()}}function f(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,r=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,r)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}const p={pivot:"center"},m="colorspace",d={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE,e.PropertyType.MATERIAL]},h=function(t=d){const n={...d,...t},r=new Set(n.propertyTypes);for(const e of n.propertyTypes)if(!d.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return l("dedup",t=>{const n=t.getLogger();r.has(e.PropertyType.ACCESSOR)&&function(t,n){const r=new Set,o=new Set,s=new Set,i=new Set,a=n.getRoot().listMeshes();a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&r.add(t)})});for(const e of n.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&s.add(e),n&&i.add(n)}function c(t){const n=new Map;for(let r=0;r<t.length;r++){const o=t[r],s=e.BufferUtils.toView(o.getArray());if(!n.has(o))for(let r=0;r<t.length;r++){const i=t[r];o!==i&&(n.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&e.BufferUtils.equals(s,e.BufferUtils.toView(i.getArray()))&&n.set(i,o))}}return n}const u=c(Array.from(r));t.debug(`dedup: Found ${u.size} duplicates among ${r.size} indices.`);const l=c(Array.from(o));t.debug(`dedup: Found ${l.size} duplicates among ${o.size} attributes.`);const g=c(Array.from(s)),f=c(Array.from(i));t.debug(`dedup: Found ${g.size+f.size} duplicates among ${s.size+i.size} animation accessors.`),a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{l.has(t)&&e.swap(t,l.get(t))});const t=e.getIndices();t&&u.has(t)&&e.swap(t,u.get(t))})}),Array.from(u.keys()).forEach(e=>e.dispose()),Array.from(l.keys()).forEach(e=>e.dispose());for(const e of n.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&g.has(e)&&t.swap(e,g.get(e)),n&&f.has(n)&&t.swap(n,f.get(n))}Array.from(g.keys()).forEach(e=>e.dispose()),Array.from(f.keys()).forEach(e=>e.dispose())}(n,t),r.has(e.PropertyType.MESH)&&function(t,n){const r=n.getRoot(),o=new Map;r.listAccessors().forEach((e,t)=>o.set(e,t)),r.listMaterials().forEach((e,t)=>o.set(e,t));const s=r.listMeshes().length,i=new Map;for(const t of r.listMeshes()){const n=[];for(const e of t.listPrimitives())n.push(y(e,o));const r=n.join(";");if(i.has(r)){const n=i.get(r);t.listParents().forEach(r=>{r.propertyType!==e.PropertyType.ROOT&&r.swap(t,n)}),t.dispose()}else i.set(r,t)}t.debug(`dedup: Found ${s-i.size} duplicates among ${s} meshes.`)}(n,t),r.has(e.PropertyType.TEXTURE)&&function(t,n){const r=n.getRoot(),o=r.listTextures(),s=new Map;for(let t=0;t<o.length;t++){const n=o[t],r=n.getImage();if(!s.has(n))for(let t=0;t<o.length;t++){const i=o[t],a=i.getImage();if(n===i)continue;if(s.has(i))continue;if(n.getMimeType()!==i.getMimeType())continue;const c=n.getSize(),u=i.getSize();c&&u&&c[0]===u[0]&&c[1]===u[1]&&r&&a&&e.BufferUtils.equals(r,a)&&s.set(i,n)}}t.debug(`dedup: Found ${s.size} duplicates among ${r.listTextures().length} textures.`),Array.from(s.entries()).forEach(([t,n])=>{t.listParents().forEach(r=>{r instanceof e.Root||r.swap(t,n)}),t.dispose()})}(n,t),r.has(e.PropertyType.MATERIAL)&&function(t,n){const r=n.getRoot(),o=r.listMaterials(),s=new Map;for(let e=0;e<o.length;e++){const t=o[e];if(!s.has(t))for(let e=0;e<o.length;e++){const n=o[e];t!==n&&(s.has(n)||t.equals(n)&&s.set(n,t))}}t.debug(`dedup: Found ${s.size} duplicates among ${r.listMaterials().length} materials.`),Array.from(s.entries()).forEach(([t,n])=>{t.listParents().forEach(r=>{r instanceof e.Root||r.swap(t,n)}),t.dispose()})}(n,t),n.debug("dedup: Complete.")})};function y(t,n){const r=[];for(const e of t.listSemantics()){const o=t.getAttribute(e);r.push(e+":"+n.get(o))}if(t instanceof e.Primitive){const e=t.getIndices();e&&r.push("indices:"+n.get(e));const o=t.getMaterial();o&&r.push("material:"+n.get(o)),r.push("mode:"+t.getMode());for(const e of t.listTargets())r.push("target:"+y(e,n))}return r.join(",")}const T={pattern:/^((?!JOINTS_).)*$/};function A(e,t){for(const n of e.listSemantics())E(n,e.getAttribute(n),t);for(const n of e.listTargets())for(const e of n.listSemantics())E(e,n.getAttribute(e),t)}function E(e,t,n){if(!t.getArray())return;if(!n.pattern.test(e))return;if(t.getComponentSize()>=4)return;const r=t.getArray(),o=new Float32Array(r.length);for(let e=0,n=t.getCount(),s=[];e<n;e++)s=t.getElement(e,s),t.setArray(o).setElement(e,s).setArray(r);t.setArray(o).setNormalized(!1)}const S={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"};function P(t){return{properties:t.getRoot().listScenes().map(t=>{const n=t.listChildren()[0],r=e.bounds(t);return{name:t.getName(),rootName:n?n.getName():"",bboxMin:w(r.min),bboxMax:w(r.max)}})}}function b(t){return{properties:t.getRoot().listMeshes().map(t=>{const n=t.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length;let r=0,o=0;const s=new Set,i=new Set,a=new Set;t.listPrimitives().forEach(t=>{for(const e of t.listSemantics()){const n=t.getAttribute(e);s.add(e+":"+C(n.getArray())),a.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(e=>a.add(e));const n=t.getIndices();n&&(i.add(C(n.getArray())),a.add(n)),o+=t.listAttributes()[0].getCount(),r+=function(t){const n=t.getIndices(),r=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return r.getCount();case e.Primitive.Mode.LINES:return n?n.getCount()/2:r.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return r.getCount();case e.Primitive.Mode.LINE_STRIP:return r.getCount()-1;case e.Primitive.Mode.TRIANGLES:return n?n.getCount()/3:r.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return r.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}(t)});let c=0;Array.from(a).forEach(e=>c+=e.getArray().byteLength);const u=t.listPrimitives().map(e=>x[e.getMode()]);return{name:t.getName(),mode:Array.from(new Set(u)),primitives:t.listPrimitives().length,glPrimitives:r,vertices:o,indices:Array.from(i).sort(),attributes:Array.from(s).sort(),instances:n,size:c}})}}function I(t){return{properties:t.getRoot().listMaterials().map(n=>{const r=n.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length,o=new Set(n.listExtensions()),s=t.getGraph().listEdges().filter(t=>{const r=t.getChild(),s=t.getParent();return r instanceof e.Texture&&s===n||!!(r instanceof e.Texture&&s instanceof e.ExtensionProperty&&o.has(s))}).map(e=>e.getName());return{name:n.getName(),instances:r,textures:s,alphaMode:n.getAlphaMode(),doubleSided:n.getDoubleSided()}})}}function M(t){return{properties:t.getRoot().listTextures().map(n=>{const r=n.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length,o=t.getGraph().listParentEdges(n).filter(t=>t.getParent().propertyType!==e.PropertyType.ROOT).map(e=>e.getName()),s=e.ImageUtils.getSize(n.getImage(),n.getMimeType());return{name:n.getName(),uri:n.getURI(),slots:Array.from(new Set(o)),instances:r,mimeType:n.getMimeType(),resolution:s?s.join("x"):"",size:n.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(n.getImage(),n.getMimeType())}})}}function R(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const r=e.getInput();r&&(t=Math.min(t,r.getMin([])[0]),n=Math.max(n,r.getMax([])[0]))});let r=0,o=0;const s=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),s.add(t),n&&s.add(n))}),Array.from(s).forEach(e=>{r+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:r}})}}const x=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function w(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function C(e){return e.constructor.name.replace("Array","").toLowerCase()}const N={};function v(t,n){let r,o=0;for(;r=t.pop();){if(r.listChildren().length||r.getCamera()||r.getMesh()||r.getSkin()||r.listExtensions().length)continue;const n=r.getParent();n instanceof e.Node&&t.push(n),r.dispose(),o++}n.debug(`instance: Removed ${o} unused nodes.`)}function O(e,t,n,r){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),s=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*r)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*r)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*r)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",s).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const z={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]},$=function(t=z){const n={...z,...t}.propertyTypes;return l("prune",t=>{const r=t.getLogger(),o=t.getRoot(),s=t.getGraph(),i={};if(n.includes(e.PropertyType.NODE)&&o.listNodes().forEach(a),n.includes(e.PropertyType.SKIN)&&o.listSkins().forEach(a),n.includes(e.PropertyType.MESH)&&o.listMeshes().forEach(a),n.includes(e.PropertyType.CAMERA)&&o.listCameras().forEach(a),n.includes(e.PropertyType.PRIMITIVE)&&c(s,e.PropertyType.PRIMITIVE),n.includes(e.PropertyType.PRIMITIVE_TARGET)&&c(s,e.PropertyType.PRIMITIVE_TARGET),n.includes(e.PropertyType.ANIMATION))for(const e of o.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),u(t));if(e.listChannels().length)e.listSamplers().forEach(a);else{const t=e.listSamplers();a(e),t.forEach(a)}}if(n.includes(e.PropertyType.MATERIAL)&&o.listMaterials().forEach(a),n.includes(e.PropertyType.TEXTURE)&&o.listTextures().forEach(a),n.includes(e.PropertyType.ACCESSOR)&&o.listAccessors().forEach(a),n.includes(e.PropertyType.BUFFER)&&o.listBuffers().forEach(a),Object.keys(i).length){const e=Object.keys(i).map(e=>`${e} (${i[e]})`).join(", ");r.info(`prune: Removed types... ${e}`)}else r.info("prune: No unused properties found.");function a(t){t.listParents().filter(t=>!(t instanceof e.Root||t instanceof e.AnimationChannel)).length||(t.dispose(),u(t))}function c(e,t){e.listEdges().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(a)}function u(e){i[e.propertyType]=i[e.propertyType]||0,i[e.propertyType]++}r.debug("prune: Complete.")})},q={target:"size"};function L(t){const n={...q,...t},r=n.encoder;if(!r)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return l("reorder",function(t){try{const o=t.getLogger();return Promise.resolve(r.ready).then(function(){const s=function(e){const t=new g,n=new Map,r=new g;for(const o of e.getRoot().listMeshes())for(const e of o.listPrimitives()){const o=e.getIndices();if(o){n.set(o,e.getMode());for(const n of U(e))t.add(o,n),r.add(n,e)}}return{indicesToAttributes:t,indicesToMode:n,attributesToPrimitives:r}}(t);for(const t of s.indicesToAttributes.keys()){const o=t.clone();let i=o.getArray().slice();i instanceof Uint32Array||(i=new Uint32Array(i));const[a,c]=r.reorderMesh(i,s.indicesToMode.get(t)===e.Primitive.Mode.TRIANGLES,"size"===n.target);o.setArray(c<=65534?new Uint16Array(i):i);for(const e of s.indicesToAttributes.get(t)){const n=e.clone();_(n,a,c);for(const r of s.attributesToPrimitives.get(e))if(r.getIndices()===t&&r.swap(t,o),r.getIndices()===o){r.swap(e,n);for(const t of r.listTargets())t.swap(e,n)}}}return Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){s.indicesToAttributes.size?o.debug("reorder: Complete."):o.warn("reorder: No qualifying primitives found; may need to weld first.")})})}catch(e){return Promise.reject(e)}})}function _(e,t,n){const r=e.getElementSize(),o=e.getCount(),s=e.getArray(),i=s.slice(0,n*r);for(let e=0;e<o;e++)for(let n=0;n<r;n++)i[t[e]*r+n]=s[e*r+n];e.setArray(i)}function U(e){const t=[];for(const n of e.listAttributes())t.push(n);for(const n of e.listTargets())for(const e of n.listAttributes())t.push(e);return Array.from(new Set(t))}const G=[Int8Array,Int16Array,Int32Array],{TRANSLATION:F,ROTATION:B,SCALE:k,WEIGHTS:j}=e.AnimationChannel.TargetPath,D=[F,B,k],V={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},W=(t=V)=>{const r={...V,...t};return l("quantize",function(t){try{const s=t.getLogger(),i=t.getRoot();let a;t.createExtension(n.MeshQuantization).setRequired(!0),"scene"===r.quantizationVolume&&(a=X(function(e){const t=e[0];for(const n of e)o.min(t.min,t.min,n.min),o.max(t.max,t.max,n.max);return t}(i.listMeshes().map(ee))));for(const e of t.getRoot().listMeshes()){"mesh"===r.quantizationVolume&&(a=X(ee(e))),a&&r.pattern.test("POSITION")&&(K(t,e,a),J(e,1/a.scale));for(const n of e.listPrimitives()){H(t,n,a,r);for(const e of n.listTargets())H(t,e,a,r)}}return Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.SKIN,e.PropertyType.MATERIAL]}),h({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MATERIAL]}))).then(function(){s.debug("quantize: Complete.")})}catch(e){return Promise.reject(e)}})};function H(t,n,s,i){const a=t.getLogger();for(const t of n.listSemantics()){if(!i.pattern.test(t))continue;const c=n.getAttribute(t),{bits:u,ctor:l}=Y(t,c,a,i);if(!l)continue;if(u<8||u>16)throw new Error("quantize: Requires bits = 8–16.");if(c.getComponentSize()<=u/8)continue;const g=c.clone();if("POSITION"===t){const t=s.scale,i=[];n instanceof e.Primitive?r.invert(i,ne(s)):r.fromScaling(i,[1/t,1/t,1/t]);for(let e=0,t=[0,0,0],n=g.getCount();e<n;e++)g.getElement(e,t),g.setElement(e,o.transformMat4(t,t,i))}Q(g,l,u),n.swap(c,g)}if(n.getAttribute("WEIGHTS_0")&&function(e){const t=e.getAttribute("POSITION").getCount(),n=[];for(let r=0;r<t;r++){let t,o=0,s=Infinity,i=-1,a=null,c=0;for(;t=e.getAttribute("WEIGHTS_"+c++);){t.getElement(r,n);for(let e=0;e<n.length;e++)o+=n[e],n[e]>0&&n[e]<s&&(a=t,s=n[e],i=e)}a&&1!==o&&(a.getElement(r,n),n[i]+=1-o,a.setElement(r,n))}}(n),n instanceof e.Primitive&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const e=n.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function X(e){const{min:t,max:n}=e,r=Math.max((n[0]-t[0])/2,(n[1]-t[1])/2,(n[2]-t[2])/2);return{offset:[t[0]+(n[0]-t[0])/2,t[1]+(n[1]-t[1])/2,t[2]+(n[2]-t[2])/2],scale:r}}function K(t,n,o){const s=ne(o);for(const i of n.listParents()){if(!(i instanceof e.Node))continue;const a=i.listParents().filter(t=>t instanceof e.AnimationChannel),c=a.some(e=>D.includes(e.getTargetPath())),u=i.listChildren().length>0;if(i.getSkin()){i.setSkin(Z(i.getSkin(),o));continue}let l;u||c?(l=t.createNode("").setMesh(n),i.addChild(l).setMesh(null),a.filter(e=>e.getTargetPath()===j).forEach(e=>e.setTargetNode(l))):l=i;const g=l.getMatrix();r.multiply(g,g,s),l.setMatrix(g)}}function Z(e,t){e=e.clone();const n=ne(t),o=e.getInverseBindMatrices().clone(),s=[];for(let e=0,t=o.getCount();e<t;e++)o.getElement(e,s),r.multiply(s,s,n),o.setElement(e,s);return e.setInverseBindMatrices(o)}function J(e,t){for(const n of e.listPrimitives()){let e=n.getMaterial();if(!e)continue;let r=e.getExtension("KHR_materials_volume");!r||r.getThicknessFactor()<=0||(r=r.clone().setThicknessFactor(r.getThicknessFactor()*t),e=e.clone().setExtension("KHR_materials_volume",r),n.setMaterial(e))}}function Q(e,t,n){const r=new t(e.getArray().length),o=G.includes(t)?1:0,s=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,s)-1,c=i-s,u=2*s-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>u,r[n++]=t*Math.sign(o[e])}}e.setArray(r).setNormalized(!0)}function Y(e,t,n,r){const o=t.getMinNormalized([]),s=t.getMaxNormalized([]);let i,a;if("POSITION"===e)i=r.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=r.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=r.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=r.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=r.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [-1,1] range.`),{bits:-1};i=r.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function ee(e){const t=[],n=[];for(const r of e.listPrimitives()){const e=r.getAttribute("POSITION");e&&t.push(e);for(const e of r.listTargets()){const t=e.getAttribute("POSITION");t&&n.push(t)}}if(0===t.length)throw new Error('quantize: Missing "POSITION" attribute.');const r=te(t,3);if(n.length>0){const{min:e,max:t}=te(n,3);o.min(r.min,r.min,o.min(e,o.scale(e,e,2),[0,0,0])),o.max(r.max,r.max,o.max(t,o.scale(t,t,2),[0,0,0]))}return r}function te(e,t){const n=new Array(t).fill(Infinity),r=new Array(t).fill(-Infinity),o=[],s=[];for(const i of e){i.getMinNormalized(o),i.getMaxNormalized(s);for(let e=0;e<t;e++)n[e]=Math.min(n[e],o[e]),r[e]=Math.max(r[e],s[e])}return{min:n,max:r}}function ne(e){return r.fromRotationTranslationScale([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}const re={level:"high"},oe=/*#__PURE__*/"undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function se(e,t,n){if(!e.s){if(n instanceof ie){if(!n.s)return void(n.o=se.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(se.bind(null,e,t),se.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}const ie=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{se(r,1,e(this.v))}catch(e){se(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?se(r,1,t?t(o):o):n?se(r,1,n(o)):se(r,2,o)}catch(e){se(r,2,e)}},r},e}();function ae(e){return e instanceof ie&&1&e.s}const ce={},ue={};function le(e=ue){return l("unweld",e=>{const t=e.getLogger(),n=new Map;for(const r of e.getRoot().listMeshes())for(const e of r.listPrimitives()){const r=e.getIndices();if(r){for(const o of e.listAttributes())e.swap(o,ge(o,r,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,ge(e,r,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===r.listParents().length&&r.dispose()}}t.debug("unweld: Complete.")})}function ge(e,t,n,r){if(r.has(e)&&r.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),r.get(e).get(t);const o=e.clone(),s=e.getArray().constructor;o.setArray(new s(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return r.has(e)||r.set(e,new Map),r.get(e).set(t,o),o}const fe={overwrite:!1};function pe(e,t,n){const r=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],s=[n[0]-e[0],n[1]-e[1],n[2]-e[2]];return o.normalize([0,0,0],[r[1]*s[2]-r[2]*s[1],r[2]*s[0]-r[0]*s[2],r[0]*s[1]-r[1]*s[0]])}const me={animations:!0,meshes:!0};function de(e,t){let n=`${e}.bin`,r=1;for(;t.has(n);)n=`${e}_${r++}.bin`;return n}const he={tolerance:1e-4};function ye(e,t){const n=e.getInput().clone(),r=e.getOutput().clone(),o=t.tolerance,s=n.getCount()-1,i=[];let a=1;for(let t=1;t<s;++t){const s=n.getScalar(t),u=n.getScalar(t-1),l=n.getScalar(t+1),g=(s-u)/(l-u);let f=!1;if(s!==l&&(1!==t||s!==n.getScalar(0)))for(let n=0;n<r.getElementSize();n++){const s=r.getElement(t,i)[n],a=r.getElement(t-1,i)[n],u=r.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(s-(a*(1-(c=g))+u*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(s!==a||s!==u)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),r.setElement(a,r.getElement(t,i))),a++)}var c;s>0&&(n.setScalar(a,n.getScalar(s)),r.setElement(a,r.getElement(s,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),r.setArray(r.getArray().slice(0,a*r.getElementSize())),e.setInput(n),e.setOutput(r)):(n.dispose(),r.dispose())}const Te={name:"",fps:10,pattern:/.*/,sort:!0};function Ae(t,n){let r=0;for(const o of t.getGraph().listParentEdges(n)){const n=o.getParent();let{channels:s}=o.getAttributes();s&&"baseColorTexture"===o.getName()&&n instanceof e.Material&&n.getAlphaMode()===e.Material.AlphaMode.OPAQUE&&(s&=~e.TextureChannel.A),s?r|=s:n.propertyType!==e.PropertyType.ROOT&&t.getLogger().warn(`Missing attribute ".channels" on edge, "${o.getName()}".`)}return r}function Ee(e,t){const n=e.getRoot(),r=e.getGraph().listParentEdges(t).filter(e=>e.getParent()!==n).map(e=>e.getName());return Array.from(new Set(r))}var Se;!function(e){e.OXIPNG="oxipng",e.MOZJPEG="mozjpeg",e.WEBP="webp"}(Se||(Se={}));const Pe={[Se.OXIPNG]:"image/png",[Se.MOZJPEG]:"image/jpeg",[Se.WEBP]:"image/webp"},be={formats:/.*/,slots:/.*/,auto:!1},Ie={...be,codec:Se.WEBP},Me={...be,codec:Se.MOZJPEG,formats:/^image\/jpeg$/},Re={...be,codec:Se.OXIPNG,formats:/^image\/png$/},xe=["image/jpeg","image/png","image/webp"];let we=null,Ce=0;const Ne=e=>(we||(we=new e.ImagePool(require("os").cpus().length)),Ce++,we),ve=()=>{0==--Ce&&we.close()},Oe=function(t){const n={...be,...t},r=n.squoosh;if(!r)throw new Error('squoosh: squoosh dependency required — install "@squoosh/lib".');return function(t){try{const o=t.getLogger(),s=t.getRoot().listTextures(),i=Ne(r);return Promise.resolve(Promise.all(s.map(function(r,s){try{const a=Ee(t,r),c=Ae(t,r),u=`squoosh:texture(${r.getURI()||r.getName()||`${s+1}/${t.getRoot().listTextures().length}`})`;if(!xe.includes(r.getMimeType()))return o.debug(`${u}: Skipping, unsupported texture type "${r.getMimeType()}".`),Promise.resolve();if(!n.formats.test(r.getMimeType()))return o.debug(`${u}: Skipping, "${r.getMimeType()}" excluded by "formats" parameter.`),Promise.resolve();if(a.length&&!a.some(e=>n.slots.test(e)))return o.debug(`${u}: Skipping, [${a.join(", ")}] excluded by "slots" parameter.`),Promise.resolve();if(n.codec===Se.MOZJPEG&&c&e.TextureChannel.A)return o.warn(`${u}: Skipping, [${a.join(", ")}] requires alpha channel.`),Promise.resolve();o.debug(`${u}: Slots → [${a.join(", ")}]`);const l=i.ingestImage(r.getImage()),g=r.getImage().byteLength;return Promise.resolve(l.encode({[n.codec]:n.auto?"auto":{}})).then(function(){return Promise.resolve(l.encodedWith[n.codec]).then(function(e){o.debug(`${u}: ${JSON.stringify(e.optionsUsed)}`),r.setImage(e.binary).setMimeType(Pe[n.codec]);const t=e.binary.byteLength;o.debug(`${u}: ${f(g)} → ${f(t)}`)})})}catch(e){return Promise.reject(e)}}))).then(function(){ve(),o.debug("squoosh: Complete.")})}catch(e){return Promise.reject(e)}}},ze={overwrite:!1};function $e(e){const t=e.getMaterial();if(!t)return"TEXCOORD_0";const n=t.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const r=`TEXCOORD_${n.getTexCoord()}`;return e.getAttribute(r)?r:"TEXCOORD_0"}function qe(t,n,r,o,s){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!s?(n.debug(`tangents: Skipping primitive ${o} of mesh "${r}": TANGENT found.`),!1):!t.getIndices()||(n.warn(`tangents: Skipping primitive ${o} of mesh "${r}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${o} of mesh "${r}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const Le=/*#__PURE__*/"undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function _e(e,t,n){if(!e.s){if(n instanceof Ue){if(!n.s)return void(n.o=_e.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(_e.bind(null,e,t),_e.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}const Ue=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{_e(r,1,e(this.v))}catch(e){_e(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?_e(r,1,t?t(o):o):n?_e(r,1,n(o)):_e(r,2,o)}catch(e){_e(r,2,e)}},r},e}();function Ge(e){return e instanceof Ue&&1&e.s}const Fe="textureResize";var Be;(Be=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",Be.LANCZOS2="lanczos2";const ke={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},je={tolerance:1e-4};function De(t,n){if(n.getIndices())return;const r=n.listAttributes()[0],o=r.getCount(),s=r.getBuffer(),i=o<=65534?new Uint16Array(o):new Uint32Array(o),a=t.createAccessor().setBuffer(s).setType(e.Accessor.Type.SCALAR).setArray(i);for(let e=0;e<a.getCount();e++)a.setScalar(e,e);n.setIndices(a)}function Ve(e,t,n){const r=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/r),s=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),u=new Map;t.listAttributes().forEach(e=>u.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>u.set(e,[]))});const l=[];let g=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,r=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)r.push(~~(e.getElement(n,o)[t]*s));const c=r.join("|");if(c in i)l.push(i[c]);else{for(const e of t.listAttributes())u.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())u.get(t).push(t.getElement(n,[]));i[c]=g,l.push(g),g++}}const f=t.listAttributes()[0].getCount(),p=u.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())He(t,e,u.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())He(e,t,u.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=We(a.getArray(),l.length);e.set(l),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(l):new Uint32Array(l);t.setIndices(e.createAccessor().setArray(n))}}function We(e,t){return new(0,e.constructor)(t)}function He(e,t,n){const r=n.length*t.getElementSize(),o=We(t.getArray(),r),s=t.clone().setArray(o);for(let e=0;e<n.length;e++)s.setElement(e,n[e]);e.swap(t,s)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.DRACO_DEFAULTS=S,exports.MESHOPT_DEFAULTS=re,exports.QUANTIZE_DEFAULTS=V,exports.TEXTURE_RESIZE_DEFAULTS=ke,exports.center=function(t=p){const n={...p,...t};return l("center",t=>{const r=t.getLogger(),o=t.getRoot(),s=o.listAnimations().length>0||o.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(r.debug(`center: Scene ${a+1} / ${o.listScenes().length}.`),"string"==typeof n.pivot){const t=e.bounds(i);c=[(t.max[0]-t.min[0])/2+t.min[0],(t.max[1]-t.min[1])/2+t.min[1],(t.max[2]-t.min[2])/2+t.min[2]],"above"===n.pivot&&(c[1]=t.max[1]),"below"===n.pivot&&(c[1]=t.min[1])}else c=n.pivot;r.debug(`center: Pivot "${c.join(", ")}".`);const u=[-1*c[0],-1*c[1],-1*c[2]];if(s){r.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(u);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else r.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(e=>{const t=e.getTranslation();e.setTranslation([t[0]+u[0],t[1]+u[1],t[2]+u[2]])})}),r.debug("center: Complete.")})},exports.colorspace=function(e){return l(m,t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info(`${m}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==e.inputEncoding)return void n.error(`${m}: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const r=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function s(e){const t=[0,0,0];let n;for(let s=0;n=e.getAttribute(`COLOR_${s}`);s++)if(!r.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);r.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(s)),n.debug(`${m}: Complete.`)})},exports.dedup=h,exports.dequantize=function(e=T){const t={...T,...e};return l("dequantize",e=>{const r=e.getLogger();for(const n of e.getRoot().listMeshes())for(const e of n.listPrimitives())A(e,t);e.createExtension(n.MeshQuantization).dispose(),r.debug("dequantize: Complete.")})},exports.draco=e=>{const t={...S,...e};return e=>{e.createExtension(n.DracoMeshCompression).setRequired(!0).setEncoderOptions({method:"edgebreaker"===t.method?n.DracoMeshCompression.EncoderMethod.EDGEBREAKER:n.DracoMeshCompression.EncoderMethod.SEQUENTIAL,encodeSpeed:t.encodeSpeed,decodeSpeed:t.decodeSpeed,quantizationBits:{POSITION:t.quantizePosition,NORMAL:t.quantizeNormal,COLOR:t.quantizeColor,TEX_COORD:t.quantizeTexcoord,GENERIC:t.quantizeGeneric},quantizationVolume:t.quantizationVolume})}},exports.getTextureChannelMask=Ae,exports.inspect=function(e){return{scenes:P(e),meshes:b(e),materials:I(e),textures:M(e),animations:R(e)}},exports.instance=function(t=N){return l("instance",t=>{const r=t.getLogger(),o=t.getRoot(),s=t.createExtension(n.MeshGPUInstancing);if(o.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let i=0,a=0;for(const n of o.listScenes()){const o=new Map;n.traverse(e=>{const t=e.getMesh();t&&o.set(t,(o.get(t)||new Set).add(e))});const c=[];for(const u of Array.from(o.keys())){const l=Array.from(o.get(u));if(l.length<2)continue;if(l.some(e=>e.getSkin()))continue;const g=O(t,s,u,l.length),f=g.getAttribute("TRANSLATION"),p=g.getAttribute("ROTATION"),m=g.getAttribute("SCALE"),d=t.createNode().setMesh(u).setExtension("EXT_mesh_gpu_instancing",g);n.addChild(d);let h=!1,y=!1,T=!1;for(let t=0;t<l.length;t++){let n,r,o;const s=l[t];f.setElement(t,n=s.getWorldTranslation()),p.setElement(t,r=s.getWorldRotation()),m.setElement(t,o=s.getWorldScale()),e.MathUtils.eq(n,[0,0,0])||(h=!0),e.MathUtils.eq(r,[0,0,0,1])||(y=!0),e.MathUtils.eq(o,[1,1,1])||(T=!0),s.setMesh(null),c.push(s)}h||f.dispose(),y||p.dispose(),T||m.dispose(),v(c,r),i++,a+=l.length}}i>0?r.info(`instance: Created ${i} batches, with ${a} total instances.`):(r.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),r.debug("instance: Complete.")})},exports.listTextureChannels=function(t,n){const r=Ae(t,n),o=[];return r&e.TextureChannel.R&&o.push(e.TextureChannel.R),r&e.TextureChannel.G&&o.push(e.TextureChannel.G),r&e.TextureChannel.B&&o.push(e.TextureChannel.B),r&e.TextureChannel.A&&o.push(e.TextureChannel.A),o},exports.listTextureSlots=Ee,exports.meshopt=e=>{const t={...re,...e},r=t.encoder;if(!r)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return function(e){try{return Promise.resolve(e.transform(L({encoder:r,target:"size"}),W({pattern:"medium"===t.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8}))).then(function(){e.createExtension(n.MeshoptCompression).setRequired(!0).setEncoderOptions({method:"medium"===t.level?n.MeshoptCompression.EncoderMethod.QUANTIZE:n.MeshoptCompression.EncoderMethod.FILTER})})}catch(e){return Promise.reject(e)}}},exports.metalRough=function(e=ce){return l("metalRough",function(e){try{function t(){i.dispose();for(const e of a)e&&1===e.listParents().length&&e.dispose();r.debug("metalRough: Complete.")}const r=e.getLogger();if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return r.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document."),Promise.resolve();const o=e.createExtension(n.MaterialsIOR),s=e.createExtension(n.MaterialsSpecular),i=e.createExtension(n.MaterialsPBRSpecularGlossiness),a=new Set,c=function(e,t,n){if("function"==typeof e[oe]){var r,o,s,i=e[oe]();if(function e(n){try{for(;!(r=i.next()).done;)if((n=t(r.value))&&n.then){if(!ae(n))return void n.then(e,s||(s=se.bind(null,o=new ie,2)));n=n.v}o?se(o,1,n):o=n}catch(e){se(o||(o=new ie),2,e)}}(),i.return){var a=function(e){try{r.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u<e.length;u++)c.push(e[u]);return function(e,t,n){var r,o,s=-1;return function n(i){try{for(;++s<e.length;)if((i=t(s))&&i.then){if(!ae(i))return void i.then(n,o||(o=se.bind(null,r=new ie,2)));i=i.v}r?se(r,1,i):r=i}catch(e){se(r||(r=new ie),2,e)}}(),r}(c,function(e){return t(c[e])})}(e.getRoot().listMaterials(),function(t){function n(){t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}const r=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!r)return;const i=s.createSpecular().setSpecularFactor(1).setSpecularColorFactor(r.getSpecularFactor());a.add(r.getSpecularGlossinessTexture()),a.add(t.getBaseColorTexture()),a.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(r.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",o.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const c=r.getDiffuseTexture();c&&(t.setBaseColorTexture(c),t.getBaseColorTextureInfo().copy(r.getDiffuseTextureInfo()));const l=r.getSpecularGlossinessTexture(),g=function(){if(l){const n=r.getSpecularGlossinessTextureInfo(),o=e.createTexture();return Promise.resolve(u(l,o,(e,t,n)=>{e.set(t,n,3,255)})).then(function(){i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const s=r.getGlossinessFactor(),a=e.createTexture();return Promise.resolve(u(l,a,(e,t,n)=>{const r=255-Math.round(e.get(t,n,3)*s);e.set(t,n,0,0),e.set(t,n,1,r),e.set(t,n,2,0),e.set(t,n,3,255)})).then(function(){t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(n)})})}i.setSpecularColorFactor(r.getSpecularFactor()),t.setRoughnessFactor(1-r.getGlossinessFactor())}();return g&&g.then?g.then(n):n()});return Promise.resolve(c&&c.then?c.then(t):t())}catch(e){return Promise.reject(e)}})},exports.mozjpeg=function(e){const t={...Me,...e};return e=>Oe(t)(e)},exports.normals=function(e=fe){const t={...fe,...e};return l("normals",function(e){try{const n=e.getLogger();let r=0;return Promise.resolve(e.transform(le())).then(function(){for(const o of e.getRoot().listMeshes())for(const s of o.listPrimitives()){const o=s.getAttribute("POSITION");let i=s.getAttribute("NORMAL");if(t.overwrite&&i)i.dispose();else if(i)return void n.debug("normals: Skipping primitive: NORMAL found.");i=e.createAccessor().setArray(new Float32Array(3*o.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],u=[0,0,0];for(let e=0;e<o.getCount();e+=3){o.getElement(e+0,a),o.getElement(e+1,c),o.getElement(e+2,u);const t=pe(a,c,u);i.setElement(e+0,t),i.setElement(e+1,t),i.setElement(e+2,t)}s.setAttribute("NORMAL",i),r++}r?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}catch(e){return Promise.reject(e)}})},exports.oxipng=function(e){const t={...Re,...e};return e=>Oe(t)(e)},exports.partition=(t=me)=>{const n={...me,...t};return l("partition",function(t){try{const r=t.getLogger();return!1!==n.meshes&&function(e,t,n){const r=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,s)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${s} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(de(o.getName()||"mesh",r));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(t,r,n),!1!==n.animations&&function(e,t,n){const r=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,s)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${s} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(de(o.getName()||"animation",r));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(t,r,n),n.meshes||n.animations||r.warn("partition: Select animations or meshes to create a partition."),Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.BUFFER]}))).then(function(){r.debug("partition: Complete.")})}catch(e){return Promise.reject(e)}})},exports.prune=$,exports.quantize=W,exports.reorder=L,exports.resample=(t=he)=>{const n={...he,...t};return l("resample",(t,r)=>{const o=new Set,s=t.getRoot().listAccessors().length,i=t.getLogger();let a=!1;for(const e of t.getRoot().listAnimations()){const t=new Set;for(const n of e.listChannels())n.getSampler()&&"weights"===n.getTargetPath()&&t.add(n.getSampler());for(const r of e.listSamplers())t.has(r)?a=!0:"STEP"!==r.getInterpolation()&&"LINEAR"!==r.getInterpolation()||(o.add(r.getInput()),o.add(r.getOutput()),ye(r,n))}for(const t of Array.from(o.values()))t.listParents().some(t=>!(t instanceof e.Root))||t.dispose();t.getRoot().listAccessors().length>s&&!function(e,t,n){return!!e&&e.stack.lastIndexOf("resample")<e.stack.lastIndexOf("dedup")}(r)&&i.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})},exports.sequence=function(t=Te){const n={...Te,...t};return l("sequence",t=>{const r=t.getLogger(),o=t.getRoot(),s=n.fps,i=o.listNodes().filter(e=>e.getName().match(n.pattern));n.sort&&i.sort((e,t)=>e.getName()>t.getName()?1:-1);const a=t.createAnimation(n.name),c=o.listBuffers()[0];i.forEach((n,r)=>{let o,u;0===r?(o=[r/s,(r+1)/s],u=[1,1,1,0,0,0]):r===i.length-1?(o=[(r-1)/s,r/s],u=[0,0,0,1,1,1]):(o=[(r-1)/s,r/s,(r+1)/s],u=[0,0,0,1,1,1,0,0,0]);const l=t.createAccessor().setArray(new Float32Array(o)).setBuffer(c),g=t.createAccessor().setArray(new Float32Array(u)).setBuffer(c).setType(e.Accessor.Type.VEC3),f=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(l).setOutput(g),p=t.createAnimationChannel().setTargetNode(n).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(f);a.addSampler(f).addChannel(p)}),r.debug("sequence: Complete.")})},exports.squoosh=Oe,exports.tangents=function(t=ze){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const n={...ze,...t};return l("tangents",t=>{const r=t.getLogger(),o=new Map,s=new Map;let i=0;for(const a of t.getRoot().listMeshes()){const c=a.getName(),u=a.listPrimitives();for(let a=0;a<u.length;a++){const l=u[a];if(!qe(l,r,c,a,n.overwrite))continue;const g=$e(l),f=l.getAttribute("POSITION").getArray(),p=l.getAttribute("NORMAL").getArray(),m=l.getAttribute(g).getArray(),d=o.get(f)||e.uuid();o.set(f,d);const h=o.get(p)||e.uuid();o.set(p,h);const y=o.get(m)||e.uuid();o.set(m,y);const T=l.getAttribute("TANGENT");T&&2===T.listParents().length&&T.dispose();const A=`${d}|${h}|${y}`;let E=s.get(A);if(E){r.debug(`tangents: Found cache for primitive ${a} of mesh "${c}".`),l.setAttribute("TANGENT",E),i++;continue}r.debug(`tangents: Generating for primitive ${a} of mesh "${c}".`);const S=l.getAttribute("POSITION").getBuffer(),P=n.generateTangents(f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p),m instanceof Float32Array?m:new Float32Array(m));for(let e=3;e<P.length;e+=4)P[e]*=-1;E=t.createAccessor().setBuffer(S).setArray(P).setType("VEC4"),l.setAttribute("TANGENT",E),s.set(A,E),i++}}i?r.debug("tangents: Complete."):r.warn("tangents: No qualifying primitives found. See debug output.")})},exports.textureResize=function(e=ke){const n={...ke,...e};return l(Fe,function(e){try{let o;function r(e){s.debug(`${Fe}: Complete.`)}const s=e.getLogger(),a=function(e,t,n){if("function"==typeof e[Le]){var r,o,s,i=e[Le]();if(function e(a){try{for(;!((r=i.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!Ge(a))return void a.then(e,s||(s=_e.bind(null,o=new Ue,2)));a=a.v}o?_e(o,1,a):o=a}catch(e){_e(o||(o=new Ue),2,e)}}(),i.return){var a=function(e){try{r.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u<e.length;u++)c.push(e[u]);return function(e,t,n){var r,o,s=-1;return function i(a){try{for(;++s<e.length&&(!n||!n());)if((a=t(s))&&a.then){if(!Ge(a))return void a.then(i,o||(o=_e.bind(null,r=new Ue,2)));a=a.v}r?_e(r,1,a):r=a}catch(e){_e(r||(r=new Ue),2,e)}}(),r}(c,function(e){return t(c[e])},n)}(e.getRoot().listTextures(),function(e){const r=e.getName(),o=e.getURI();if(n.pattern&&!n.pattern.test(r)&&!n.pattern.test(o))return;if("image/png"!==e.getMimeType()&&"image/jpeg"!==e.getMimeType())return void s.warn(`Skipping unsupported texture type, "${e.getMimeType()}".`);const[a,u]=n.size,[l,g]=e.getSize();if(l<=a&&g<=u)return void s.debug(`${Fe}: Skipping "${o||r}", within size range.`);let f=l,p=g;f>a&&(p=Math.floor(p*(a/f)),f=a),p>u&&(f=Math.floor(f*(u/p)),p=u);const m=e.getImage();return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(a){const u=c.default(new Uint8Array(f*p*4),[f,p,4]);s.debug(`${Fe}: Resizing "${o||r}", ${a.shape} → ${u.shape}...`);try{n.filter===exports.TextureResizeFilter.LANCZOS3?i.lanczos3(a,u):i.lanczos2(a,u)}catch(e){if(e instanceof Error)return void s.warn(`${Fe}: Failed to resize "${o||r}": "${e.message}".`);throw e}const l=e.setImage;return Promise.resolve(t.savePixels(u,e.getMimeType())).then(function(t){l.call(e,t)})})},function(){return o});return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}})},exports.unlit=()=>e=>{const t=e.createExtension(n.MaterialsUnlit).createUnlit();e.getRoot().listMaterials().forEach(e=>{e.setExtension("KHR_materials_unlit",t)})},exports.unweld=le,exports.webp=function(e){const t={...Ie,...e};return function(e){try{return Promise.resolve(Oe(t)(e)).then(function(){e.getRoot().listTextures().some(e=>e.getMimeType()===Pe[Se.WEBP])&&e.createExtension(n.TextureWebP).setRequired(!0)})}catch(e){return Promise.reject(e)}}},exports.weld=function(t=je){const n={...je,...t};return l("weld",t=>{const r=t.getLogger();for(const r of t.getRoot().listMeshes())for(const o of r.listPrimitives())o.getMode()!==e.Primitive.Mode.POINTS&&(0===n.tolerance?De(t,o):Ve(t,o,n));r.debug("weld: Complete.")})};
var e=require("@gltf-transform/core"),t=require("ndarray-pixels"),n=require("@gltf-transform/extensions"),r=require("gl-matrix/mat4"),o=require("gl-matrix/vec3"),s=require("ndarray"),i=require("ndarray-lanczos");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/a(s);const u=function(e,n,r){try{if(!e)return Promise.resolve(null);const o=e.getImage();return o?Promise.resolve(t.getPixels(o,e.getMimeType())).then(function(e){for(let t=0;t<e.shape[0];++t)for(let n=0;n<e.shape[1];++n)r(e,t,n);return Promise.resolve(t.savePixels(e,"image/png")).then(function(e){return n.setImage(e).setMimeType("image/png")})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}};function l(e,t){return Object.defineProperty(t,"name",{value:e}),t}class g{constructor(){this._map=new Map}get size(){return this._map.size}has(e){return this._map.has(e)}add(e,t){let n=this._map.get(e);return n||(n=new Set,this._map.set(e,n)),n.add(t),this}get(e){return this._map.get(e)||new Set}keys(){return this._map.keys()}}function f(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,r=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,r)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}const p={pivot:"center"},m="colorspace",d={propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MESH,e.PropertyType.TEXTURE,e.PropertyType.MATERIAL]},h=function(t=d){const n={...d,...t},r=new Set(n.propertyTypes);for(const e of n.propertyTypes)if(!d.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return l("dedup",t=>{const n=t.getLogger();r.has(e.PropertyType.ACCESSOR)&&function(t,n){const r=new Set,o=new Set,s=new Set,i=new Set,a=n.getRoot().listMeshes();a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&r.add(t)})});for(const e of n.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&s.add(e),n&&i.add(n)}function c(t){const n=new Map;for(let r=0;r<t.length;r++){const o=t[r],s=e.BufferUtils.toView(o.getArray());if(!n.has(o))for(let r=0;r<t.length;r++){const i=t[r];o!==i&&(n.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&e.BufferUtils.equals(s,e.BufferUtils.toView(i.getArray()))&&n.set(i,o))}}return n}const u=c(Array.from(r));t.debug(`dedup: Found ${u.size} duplicates among ${r.size} indices.`);const l=c(Array.from(o));t.debug(`dedup: Found ${l.size} duplicates among ${o.size} attributes.`);const g=c(Array.from(s)),f=c(Array.from(i));t.debug(`dedup: Found ${g.size+f.size} duplicates among ${s.size+i.size} animation accessors.`),a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{l.has(t)&&e.swap(t,l.get(t))});const t=e.getIndices();t&&u.has(t)&&e.swap(t,u.get(t))})}),Array.from(u.keys()).forEach(e=>e.dispose()),Array.from(l.keys()).forEach(e=>e.dispose());for(const e of n.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&g.has(e)&&t.swap(e,g.get(e)),n&&f.has(n)&&t.swap(n,f.get(n))}Array.from(g.keys()).forEach(e=>e.dispose()),Array.from(f.keys()).forEach(e=>e.dispose())}(n,t),r.has(e.PropertyType.MESH)&&function(t,n){const r=n.getRoot(),o=new Map;r.listAccessors().forEach((e,t)=>o.set(e,t)),r.listMaterials().forEach((e,t)=>o.set(e,t));const s=r.listMeshes().length,i=new Map;for(const t of r.listMeshes()){const n=[];for(const e of t.listPrimitives())n.push(y(e,o));const r=n.join(";");if(i.has(r)){const n=i.get(r);t.listParents().forEach(r=>{r.propertyType!==e.PropertyType.ROOT&&r.swap(t,n)}),t.dispose()}else i.set(r,t)}t.debug(`dedup: Found ${s-i.size} duplicates among ${s} meshes.`)}(n,t),r.has(e.PropertyType.TEXTURE)&&function(t,n){const r=n.getRoot(),o=r.listTextures(),s=new Map;for(let t=0;t<o.length;t++){const n=o[t],r=n.getImage();if(!s.has(n))for(let t=0;t<o.length;t++){const i=o[t],a=i.getImage();if(n===i)continue;if(s.has(i))continue;if(n.getMimeType()!==i.getMimeType())continue;const c=n.getSize(),u=i.getSize();c&&u&&c[0]===u[0]&&c[1]===u[1]&&r&&a&&e.BufferUtils.equals(r,a)&&s.set(i,n)}}t.debug(`dedup: Found ${s.size} duplicates among ${r.listTextures().length} textures.`),Array.from(s.entries()).forEach(([t,n])=>{t.listParents().forEach(r=>{r instanceof e.Root||r.swap(t,n)}),t.dispose()})}(n,t),r.has(e.PropertyType.MATERIAL)&&function(t,n){const r=n.getRoot(),o=r.listMaterials(),s=new Map;for(let e=0;e<o.length;e++){const t=o[e];if(!s.has(t))for(let e=0;e<o.length;e++){const n=o[e];t!==n&&(s.has(n)||t.equals(n)&&s.set(n,t))}}t.debug(`dedup: Found ${s.size} duplicates among ${r.listMaterials().length} materials.`),Array.from(s.entries()).forEach(([t,n])=>{t.listParents().forEach(r=>{r instanceof e.Root||r.swap(t,n)}),t.dispose()})}(n,t),n.debug("dedup: Complete.")})};function y(t,n){const r=[];for(const e of t.listSemantics()){const o=t.getAttribute(e);r.push(e+":"+n.get(o))}if(t instanceof e.Primitive){const e=t.getIndices();e&&r.push("indices:"+n.get(e));const o=t.getMaterial();o&&r.push("material:"+n.get(o)),r.push("mode:"+t.getMode());for(const e of t.listTargets())r.push("target:"+y(e,n))}return r.join(",")}const T={pattern:/^((?!JOINTS_).)*$/};function A(e,t){for(const n of e.listSemantics())E(n,e.getAttribute(n),t);for(const n of e.listTargets())for(const e of n.listSemantics())E(e,n.getAttribute(e),t)}function E(e,t,n){if(!t.getArray())return;if(!n.pattern.test(e))return;if(t.getComponentSize()>=4)return;const r=t.getArray(),o=new Float32Array(r.length);for(let e=0,n=t.getCount(),s=[];e<n;e++)s=t.getElement(e,s),t.setArray(o).setElement(e,s).setArray(r);t.setArray(o).setNormalized(!1)}const S={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"};function P(t){return{properties:t.getRoot().listScenes().map(t=>{const n=t.listChildren()[0],r=e.bounds(t);return{name:t.getName(),rootName:n?n.getName():"",bboxMin:w(r.min),bboxMax:w(r.max)}})}}function b(t){return{properties:t.getRoot().listMeshes().map(t=>{const n=t.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length;let r=0,o=0;const s=new Set,i=new Set,a=new Set;t.listPrimitives().forEach(t=>{for(const e of t.listSemantics()){const n=t.getAttribute(e);s.add(e+":"+C(n.getArray())),a.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(e=>a.add(e));const n=t.getIndices();n&&(i.add(C(n.getArray())),a.add(n)),o+=t.listAttributes()[0].getCount(),r+=function(t){const n=t.getIndices(),r=t.getAttribute("POSITION");switch(t.getMode()){case e.Primitive.Mode.POINTS:return r.getCount();case e.Primitive.Mode.LINES:return n?n.getCount()/2:r.getCount()/2;case e.Primitive.Mode.LINE_LOOP:return r.getCount();case e.Primitive.Mode.LINE_STRIP:return r.getCount()-1;case e.Primitive.Mode.TRIANGLES:return n?n.getCount()/3:r.getCount()/3;case e.Primitive.Mode.TRIANGLE_STRIP:case e.Primitive.Mode.TRIANGLE_FAN:return r.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}(t)});let c=0;Array.from(a).forEach(e=>c+=e.getArray().byteLength);const u=t.listPrimitives().map(e=>x[e.getMode()]);return{name:t.getName(),mode:Array.from(new Set(u)),primitives:t.listPrimitives().length,glPrimitives:r,vertices:o,indices:Array.from(i).sort(),attributes:Array.from(s).sort(),instances:n,size:c}})}}function I(t){return{properties:t.getRoot().listMaterials().map(n=>{const r=n.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length,o=new Set(n.listExtensions()),s=t.getGraph().listEdges().filter(t=>{const r=t.getChild(),s=t.getParent();return r instanceof e.Texture&&s===n||!!(r instanceof e.Texture&&s instanceof e.ExtensionProperty&&o.has(s))}).map(e=>e.getName());return{name:n.getName(),instances:r,textures:s,alphaMode:n.getAlphaMode(),doubleSided:n.getDoubleSided()}})}}function M(t){return{properties:t.getRoot().listTextures().map(n=>{const r=n.listParents().filter(t=>t.propertyType!==e.PropertyType.ROOT).length,o=t.getGraph().listParentEdges(n).filter(t=>t.getParent().propertyType!==e.PropertyType.ROOT).map(e=>e.getName()),s=e.ImageUtils.getSize(n.getImage(),n.getMimeType());return{name:n.getName(),uri:n.getURI(),slots:Array.from(new Set(o)),instances:r,mimeType:n.getMimeType(),resolution:s?s.join("x"):"",size:n.getImage().byteLength,gpuSize:e.ImageUtils.getMemSize(n.getImage(),n.getMimeType())}})}}function R(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const r=e.getInput();r&&(t=Math.min(t,r.getMin([])[0]),n=Math.max(n,r.getMax([])[0]))});let r=0,o=0;const s=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),s.add(t),n&&s.add(n))}),Array.from(s).forEach(e=>{r+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:r}})}}const x=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function w(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function C(e){return e.constructor.name.replace("Array","").toLowerCase()}const N={};function v(t,n){let r,o=0;for(;r=t.pop();){if(r.listChildren().length||r.getCamera()||r.getMesh()||r.getSkin()||r.listExtensions().length)continue;const n=r.getParent();n instanceof e.Node&&t.push(n),r.dispose(),o++}n.debug(`instance: Removed ${o} unused nodes.`)}function O(e,t,n,r){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),s=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*r)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*r)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*r)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",s).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const z={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]},$=function(t=z){const n={...z,...t}.propertyTypes;return l("prune",t=>{const r=t.getLogger(),o=t.getRoot(),s=t.getGraph(),i={};if(n.includes(e.PropertyType.NODE)&&o.listNodes().forEach(a),n.includes(e.PropertyType.SKIN)&&o.listSkins().forEach(a),n.includes(e.PropertyType.MESH)&&o.listMeshes().forEach(a),n.includes(e.PropertyType.CAMERA)&&o.listCameras().forEach(a),n.includes(e.PropertyType.PRIMITIVE)&&c(s,e.PropertyType.PRIMITIVE),n.includes(e.PropertyType.PRIMITIVE_TARGET)&&c(s,e.PropertyType.PRIMITIVE_TARGET),n.includes(e.PropertyType.ANIMATION))for(const e of o.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),u(t));if(e.listChannels().length)e.listSamplers().forEach(a);else{const t=e.listSamplers();a(e),t.forEach(a)}}if(n.includes(e.PropertyType.MATERIAL)&&o.listMaterials().forEach(a),n.includes(e.PropertyType.TEXTURE)&&o.listTextures().forEach(a),n.includes(e.PropertyType.ACCESSOR)&&o.listAccessors().forEach(a),n.includes(e.PropertyType.BUFFER)&&o.listBuffers().forEach(a),Object.keys(i).length){const e=Object.keys(i).map(e=>`${e} (${i[e]})`).join(", ");r.info(`prune: Removed types... ${e}`)}else r.info("prune: No unused properties found.");function a(t){t.listParents().filter(t=>!(t instanceof e.Root||t instanceof e.AnimationChannel)).length||(t.dispose(),u(t))}function c(e,t){e.listEdges().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(a)}function u(e){i[e.propertyType]=i[e.propertyType]||0,i[e.propertyType]++}r.debug("prune: Complete.")})},L={target:"size"};function q(t){const n={...L,...t},r=n.encoder;if(!r)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return l("reorder",function(t){try{const o=t.getLogger();return Promise.resolve(r.ready).then(function(){const s=function(e){const t=new g,n=new Map,r=new g;for(const o of e.getRoot().listMeshes())for(const e of o.listPrimitives()){const o=e.getIndices();if(o){n.set(o,e.getMode());for(const n of U(e))t.add(o,n),r.add(n,e)}}return{indicesToAttributes:t,indicesToMode:n,attributesToPrimitives:r}}(t);for(const t of s.indicesToAttributes.keys()){const o=t.clone();let i=o.getArray().slice();i instanceof Uint32Array||(i=new Uint32Array(i));const[a,c]=r.reorderMesh(i,s.indicesToMode.get(t)===e.Primitive.Mode.TRIANGLES,"size"===n.target);o.setArray(c<=65534?new Uint16Array(i):i);for(const e of s.indicesToAttributes.get(t)){const n=e.clone();_(n,a,c);for(const r of s.attributesToPrimitives.get(e))if(r.getIndices()===t&&r.swap(t,o),r.getIndices()===o){r.swap(e,n);for(const t of r.listTargets())t.swap(e,n)}}}return Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.ACCESSOR]}))).then(function(){s.indicesToAttributes.size?o.debug("reorder: Complete."):o.warn("reorder: No qualifying primitives found; may need to weld first.")})})}catch(e){return Promise.reject(e)}})}function _(e,t,n){const r=e.getElementSize(),o=e.getCount(),s=e.getArray(),i=s.slice(0,n*r);for(let e=0;e<o;e++)for(let n=0;n<r;n++)i[t[e]*r+n]=s[e*r+n];e.setArray(i)}function U(e){const t=[];for(const n of e.listAttributes())t.push(n);for(const n of e.listTargets())for(const e of n.listAttributes())t.push(e);return Array.from(new Set(t))}const G=[Int8Array,Int16Array,Int32Array],{TRANSLATION:F,ROTATION:B,SCALE:k,WEIGHTS:j}=e.AnimationChannel.TargetPath,D=[F,B,k],V={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},W=(t=V)=>{const r={...V,...t};return l("quantize",function(t){try{const s=t.getLogger(),i=t.getRoot();let a;t.createExtension(n.MeshQuantization).setRequired(!0),"scene"===r.quantizationVolume&&(a=X(function(e){const t=e[0];for(const n of e)o.min(t.min,t.min,n.min),o.max(t.max,t.max,n.max);return t}(i.listMeshes().map(ee))));for(const e of t.getRoot().listMeshes()){"mesh"===r.quantizationVolume&&(a=X(ee(e))),a&&r.pattern.test("POSITION")&&(K(t,e,a),J(e,1/a.scale));for(const n of e.listPrimitives()){H(t,n,a,r);for(const e of n.listTargets())H(t,e,a,r)}}return Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.SKIN,e.PropertyType.MATERIAL]}),h({propertyTypes:[e.PropertyType.ACCESSOR,e.PropertyType.MATERIAL]}))).then(function(){s.debug("quantize: Complete.")})}catch(e){return Promise.reject(e)}})};function H(t,n,s,i){const a=t.getLogger();for(const t of n.listSemantics()){if(!i.pattern.test(t))continue;const c=n.getAttribute(t),{bits:u,ctor:l}=Y(t,c,a,i);if(!l)continue;if(u<8||u>16)throw new Error("quantize: Requires bits = 8–16.");if(c.getComponentSize()<=u/8)continue;const g=c.clone();if("POSITION"===t){const t=s.scale,i=[];n instanceof e.Primitive?r.invert(i,ne(s)):r.fromScaling(i,[1/t,1/t,1/t]);for(let e=0,t=[0,0,0],n=g.getCount();e<n;e++)g.getElement(e,t),g.setElement(e,o.transformMat4(t,t,i))}Q(g,l,u),n.swap(c,g)}if(n.getAttribute("WEIGHTS_0")&&function(e){const t=e.getAttribute("POSITION").getCount(),n=[];for(let r=0;r<t;r++){let t,o=0,s=Infinity,i=-1,a=null,c=0;for(;t=e.getAttribute("WEIGHTS_"+c++);){t.getElement(r,n);for(let e=0;e<n.length;e++)o+=n[e],n[e]>0&&n[e]<s&&(a=t,s=n[e],i=e)}a&&1!==o&&(a.getElement(r,n),n[i]+=1-o,a.setElement(r,n))}}(n),n instanceof e.Primitive&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const e=n.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function X(e){const{min:t,max:n}=e,r=Math.max((n[0]-t[0])/2,(n[1]-t[1])/2,(n[2]-t[2])/2);return{offset:[t[0]+(n[0]-t[0])/2,t[1]+(n[1]-t[1])/2,t[2]+(n[2]-t[2])/2],scale:r}}function K(t,n,o){const s=ne(o);for(const i of n.listParents()){if(!(i instanceof e.Node))continue;const a=i.listParents().filter(t=>t instanceof e.AnimationChannel),c=a.some(e=>D.includes(e.getTargetPath())),u=i.listChildren().length>0;if(i.getSkin()){i.setSkin(Z(i.getSkin(),o));continue}let l;u||c?(l=t.createNode("").setMesh(n),i.addChild(l).setMesh(null),a.filter(e=>e.getTargetPath()===j).forEach(e=>e.setTargetNode(l))):l=i;const g=l.getMatrix();r.multiply(g,g,s),l.setMatrix(g)}}function Z(e,t){e=e.clone();const n=ne(t),o=e.getInverseBindMatrices().clone(),s=[];for(let e=0,t=o.getCount();e<t;e++)o.getElement(e,s),r.multiply(s,s,n),o.setElement(e,s);return e.setInverseBindMatrices(o)}function J(e,t){for(const n of e.listPrimitives()){let e=n.getMaterial();if(!e)continue;let r=e.getExtension("KHR_materials_volume");!r||r.getThicknessFactor()<=0||(r=r.clone().setThicknessFactor(r.getThicknessFactor()*t),e=e.clone().setExtension("KHR_materials_volume",r),n.setMaterial(e))}}function Q(e,t,n){const r=new t(e.getArray().length),o=G.includes(t)?1:0,s=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,s)-1,c=i-s,u=2*s-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>u,r[n++]=t*Math.sign(o[e])}}e.setArray(r).setNormalized(!0)}function Y(e,t,n,r){const o=t.getMinNormalized([]),s=t.getMaxNormalized([]);let i,a;if("POSITION"===e)i=r.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=r.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=r.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=r.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=r.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||s.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [-1,1] range.`),{bits:-1};i=r.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function ee(e){const t=[],n=[];for(const r of e.listPrimitives()){const e=r.getAttribute("POSITION");e&&t.push(e);for(const e of r.listTargets()){const t=e.getAttribute("POSITION");t&&n.push(t)}}if(0===t.length)throw new Error('quantize: Missing "POSITION" attribute.');const r=te(t,3);if(n.length>0){const{min:e,max:t}=te(n,3);o.min(r.min,r.min,o.min(e,o.scale(e,e,2),[0,0,0])),o.max(r.max,r.max,o.max(t,o.scale(t,t,2),[0,0,0]))}return r}function te(e,t){const n=new Array(t).fill(Infinity),r=new Array(t).fill(-Infinity),o=[],s=[];for(const i of e){i.getMinNormalized(o),i.getMaxNormalized(s);for(let e=0;e<t;e++)n[e]=Math.min(n[e],o[e]),r[e]=Math.max(r[e],s[e])}return{min:n,max:r}}function ne(e){return r.fromRotationTranslationScale([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}const re={level:"high"},oe=/*#__PURE__*/"undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function se(e,t,n){if(!e.s){if(n instanceof ie){if(!n.s)return void(n.o=se.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(se.bind(null,e,t),se.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}const ie=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{se(r,1,e(this.v))}catch(e){se(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?se(r,1,t?t(o):o):n?se(r,1,n(o)):se(r,2,o)}catch(e){se(r,2,e)}},r},e}();function ae(e){return e instanceof ie&&1&e.s}const ce={},ue={};function le(e=ue){return l("unweld",e=>{const t=e.getLogger(),n=new Map;for(const r of e.getRoot().listMeshes())for(const e of r.listPrimitives()){const r=e.getIndices();if(r){for(const o of e.listAttributes())e.swap(o,ge(o,r,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,ge(e,r,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===r.listParents().length&&r.dispose()}}t.debug("unweld: Complete.")})}function ge(e,t,n,r){if(r.has(e)&&r.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),r.get(e).get(t);const o=e.clone(),s=e.getArray().constructor;o.setArray(new s(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return r.has(e)||r.set(e,new Map),r.get(e).set(t,o),o}const fe={overwrite:!1};function pe(e,t,n){const r=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],s=[n[0]-e[0],n[1]-e[1],n[2]-e[2]];return o.normalize([0,0,0],[r[1]*s[2]-r[2]*s[1],r[2]*s[0]-r[0]*s[2],r[0]*s[1]-r[1]*s[0]])}const me={animations:!0,meshes:!0};function de(e,t){let n=`${e}.bin`,r=1;for(;t.has(n);)n=`${e}_${r++}.bin`;return n}const he={tolerance:1e-4};function ye(e,t){const n=e.getInput().clone(),r=e.getOutput().clone(),o=t.tolerance,s=n.getCount()-1,i=[];let a=1;for(let t=1;t<s;++t){const s=n.getScalar(t),u=n.getScalar(t-1),l=n.getScalar(t+1),g=(s-u)/(l-u);let f=!1;if(s!==l&&(1!==t||s!==n.getScalar(0)))for(let n=0;n<r.getElementSize();n++){const s=r.getElement(t,i)[n],a=r.getElement(t-1,i)[n],u=r.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(s-(a*(1-(c=g))+u*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(s!==a||s!==u)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),r.setElement(a,r.getElement(t,i))),a++)}var c;s>0&&(n.setScalar(a,n.getScalar(s)),r.setElement(a,r.getElement(s,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),r.setArray(r.getArray().slice(0,a*r.getElementSize())),e.setInput(n),e.setOutput(r)):(n.dispose(),r.dispose())}const Te={name:"",fps:10,pattern:/.*/,sort:!0};function Ae(t,n){let r=0;for(const o of t.getGraph().listParentEdges(n)){const n=o.getParent();let{channels:s}=o.getAttributes();s&&"baseColorTexture"===o.getName()&&n instanceof e.Material&&n.getAlphaMode()===e.Material.AlphaMode.OPAQUE&&(s&=~e.TextureChannel.A),s?r|=s:n.propertyType!==e.PropertyType.ROOT&&t.getLogger().warn(`Missing attribute ".channels" on edge, "${o.getName()}".`)}return r}function Ee(e,t){const n=e.getRoot(),r=e.getGraph().listParentEdges(t).filter(e=>e.getParent()!==n).map(e=>e.getName());return Array.from(new Set(r))}var Se;!function(e){e.OXIPNG="oxipng",e.MOZJPEG="mozjpeg",e.WEBP="webp"}(Se||(Se={}));const Pe={[Se.OXIPNG]:"image/png",[Se.MOZJPEG]:"image/jpeg",[Se.WEBP]:"image/webp"},be={formats:/.*/,slots:/.*/,auto:!1},Ie={...be,codec:Se.WEBP},Me={...be,codec:Se.MOZJPEG,formats:/^image\/jpeg$/},Re={...be,codec:Se.OXIPNG,formats:/^image\/png$/},xe=["image/jpeg","image/png","image/webp"];let we=null,Ce=0;const Ne=e=>(we||(we=new e.ImagePool(require("os").cpus().length)),Ce++,we),ve=()=>{Ce--,we&&Ce<=0&&(we.close(),we=null)},Oe=function(t){const n={...be,...t},r=n.squoosh,o=n.codec;if(!r)throw new Error(`${o}: squoosh dependency required — install "@squoosh/lib".`);return function(t){try{const s=t.getLogger(),i=t.getRoot().listTextures(),a=Ne(r);return Promise.resolve(Promise.all(i.map(function(r,i){try{const c=Ee(t,r),u=Ae(t,r),l=r.getURI()||r.getName()||`${i+1}/${t.getRoot().listTextures().length}`,g=`${o}:texture(${l})`;if(!xe.includes(r.getMimeType()))return s.debug(`${g}: Skipping, unsupported texture type "${r.getMimeType()}".`),Promise.resolve();if(!n.formats.test(r.getMimeType()))return s.debug(`${g}: Skipping, "${r.getMimeType()}" excluded by "formats" parameter.`),Promise.resolve();if(c.length&&!c.some(e=>n.slots.test(e)))return s.debug(`${g}: Skipping, [${c.join(", ")}] excluded by "slots" parameter.`),Promise.resolve();if(n.codec===Se.MOZJPEG&&u&e.TextureChannel.A)return s.warn(`${g}: Skipping, [${c.join(", ")}] requires alpha channel.`),Promise.resolve();s.debug(`${g}: Slots → [${c.join(", ")}]`);const p=a.ingestImage(r.getImage()),m=r.getImage().byteLength;return Promise.resolve(p.encode({[n.codec]:n.auto?"auto":{}})).then(function(){return Promise.resolve(p.encodedWith[n.codec]).then(function(e){s.debug(`${g}: ${JSON.stringify(e.optionsUsed)}`),r.setImage(e.binary).setMimeType(Pe[n.codec]);const t=e.binary.byteLength;s.debug(`${g}: ${f(m)} → ${f(t)}`)})})}catch(e){return Promise.reject(e)}}))).then(function(){ve(),s.debug(`${o}: Complete.`)})}catch(e){return Promise.reject(e)}}},ze={overwrite:!1};function $e(e){const t=e.getMaterial();if(!t)return"TEXCOORD_0";const n=t.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const r=`TEXCOORD_${n.getTexCoord()}`;return e.getAttribute(r)?r:"TEXCOORD_0"}function Le(t,n,r,o,s){return t.getMode()===e.Primitive.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!s?(n.debug(`tangents: Skipping primitive ${o} of mesh "${r}": TANGENT found.`),!1):!t.getIndices()||(n.warn(`tangents: Skipping primitive ${o} of mesh "${r}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${o} of mesh "${r}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const qe=/*#__PURE__*/"undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function _e(e,t,n){if(!e.s){if(n instanceof Ue){if(!n.s)return void(n.o=_e.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(_e.bind(null,e,t),_e.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}const Ue=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{_e(r,1,e(this.v))}catch(e){_e(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?_e(r,1,t?t(o):o):n?_e(r,1,n(o)):_e(r,2,o)}catch(e){_e(r,2,e)}},r},e}();function Ge(e){return e instanceof Ue&&1&e.s}const Fe="textureResize";var Be;(Be=exports.TextureResizeFilter||(exports.TextureResizeFilter={})).LANCZOS3="lanczos3",Be.LANCZOS2="lanczos2";const ke={size:[2048,2048],filter:exports.TextureResizeFilter.LANCZOS3,pattern:null},je={tolerance:1e-4};function De(t,n){if(n.getIndices())return;const r=n.listAttributes()[0],o=r.getCount(),s=r.getBuffer(),i=o<=65534?new Uint16Array(o):new Uint32Array(o),a=t.createAccessor().setBuffer(s).setType(e.Accessor.Type.SCALAR).setArray(i);for(let e=0;e<a.getCount();e++)a.setScalar(e,e);n.setIndices(a)}function Ve(e,t,n){const r=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/r),s=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),u=new Map;t.listAttributes().forEach(e=>u.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>u.set(e,[]))});const l=[];let g=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,r=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)r.push(~~(e.getElement(n,o)[t]*s));const c=r.join("|");if(c in i)l.push(i[c]);else{for(const e of t.listAttributes())u.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())u.get(t).push(t.getElement(n,[]));i[c]=g,l.push(g),g++}}const f=t.listAttributes()[0].getCount(),p=u.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())He(t,e,u.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())He(e,t,u.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=We(a.getArray(),l.length);e.set(l),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(l):new Uint32Array(l);t.setIndices(e.createAccessor().setArray(n))}}function We(e,t){return new(0,e.constructor)(t)}function He(e,t,n){const r=n.length*t.getElementSize(),o=We(t.getArray(),r),s=t.clone().setArray(o);for(let e=0;e<n.length;e++)s.setElement(e,n[e]);e.swap(t,s)}Object.defineProperty(exports,"bounds",{enumerable:!0,get:function(){return e.bounds}}),exports.DRACO_DEFAULTS=S,exports.MESHOPT_DEFAULTS=re,exports.QUANTIZE_DEFAULTS=V,exports.TEXTURE_RESIZE_DEFAULTS=ke,exports.center=function(t=p){const n={...p,...t};return l("center",t=>{const r=t.getLogger(),o=t.getRoot(),s=o.listAnimations().length>0||o.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(r.debug(`center: Scene ${a+1} / ${o.listScenes().length}.`),"string"==typeof n.pivot){const t=e.bounds(i);c=[(t.max[0]-t.min[0])/2+t.min[0],(t.max[1]-t.min[1])/2+t.min[1],(t.max[2]-t.min[2])/2+t.min[2]],"above"===n.pivot&&(c[1]=t.max[1]),"below"===n.pivot&&(c[1]=t.min[1])}else c=n.pivot;r.debug(`center: Pivot "${c.join(", ")}".`);const u=[-1*c[0],-1*c[1],-1*c[2]];if(s){r.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(u);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else r.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(e=>{const t=e.getTranslation();e.setTranslation([t[0]+u[0],t[1]+u[1],t[2]+u[2]])})}),r.debug("center: Complete.")})},exports.colorspace=function(e){return l(m,t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info(`${m}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==e.inputEncoding)return void n.error(`${m}: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const r=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function s(e){const t=[0,0,0];let n;for(let s=0;n=e.getAttribute(`COLOR_${s}`);s++)if(!r.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);r.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(s)),n.debug(`${m}: Complete.`)})},exports.dedup=h,exports.dequantize=function(e=T){const t={...T,...e};return l("dequantize",e=>{const r=e.getLogger();for(const n of e.getRoot().listMeshes())for(const e of n.listPrimitives())A(e,t);e.createExtension(n.MeshQuantization).dispose(),r.debug("dequantize: Complete.")})},exports.draco=e=>{const t={...S,...e};return e=>{e.createExtension(n.DracoMeshCompression).setRequired(!0).setEncoderOptions({method:"edgebreaker"===t.method?n.DracoMeshCompression.EncoderMethod.EDGEBREAKER:n.DracoMeshCompression.EncoderMethod.SEQUENTIAL,encodeSpeed:t.encodeSpeed,decodeSpeed:t.decodeSpeed,quantizationBits:{POSITION:t.quantizePosition,NORMAL:t.quantizeNormal,COLOR:t.quantizeColor,TEX_COORD:t.quantizeTexcoord,GENERIC:t.quantizeGeneric},quantizationVolume:t.quantizationVolume})}},exports.getTextureChannelMask=Ae,exports.inspect=function(e){return{scenes:P(e),meshes:b(e),materials:I(e),textures:M(e),animations:R(e)}},exports.instance=function(t=N){return l("instance",t=>{const r=t.getLogger(),o=t.getRoot(),s=t.createExtension(n.MeshGPUInstancing);if(o.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let i=0,a=0;for(const n of o.listScenes()){const o=new Map;n.traverse(e=>{const t=e.getMesh();t&&o.set(t,(o.get(t)||new Set).add(e))});const c=[];for(const u of Array.from(o.keys())){const l=Array.from(o.get(u));if(l.length<2)continue;if(l.some(e=>e.getSkin()))continue;const g=O(t,s,u,l.length),f=g.getAttribute("TRANSLATION"),p=g.getAttribute("ROTATION"),m=g.getAttribute("SCALE"),d=t.createNode().setMesh(u).setExtension("EXT_mesh_gpu_instancing",g);n.addChild(d);let h=!1,y=!1,T=!1;for(let t=0;t<l.length;t++){let n,r,o;const s=l[t];f.setElement(t,n=s.getWorldTranslation()),p.setElement(t,r=s.getWorldRotation()),m.setElement(t,o=s.getWorldScale()),e.MathUtils.eq(n,[0,0,0])||(h=!0),e.MathUtils.eq(r,[0,0,0,1])||(y=!0),e.MathUtils.eq(o,[1,1,1])||(T=!0),s.setMesh(null),c.push(s)}h||f.dispose(),y||p.dispose(),T||m.dispose(),v(c,r),i++,a+=l.length}}i>0?r.info(`instance: Created ${i} batches, with ${a} total instances.`):(r.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),r.debug("instance: Complete.")})},exports.listTextureChannels=function(t,n){const r=Ae(t,n),o=[];return r&e.TextureChannel.R&&o.push(e.TextureChannel.R),r&e.TextureChannel.G&&o.push(e.TextureChannel.G),r&e.TextureChannel.B&&o.push(e.TextureChannel.B),r&e.TextureChannel.A&&o.push(e.TextureChannel.A),o},exports.listTextureSlots=Ee,exports.meshopt=e=>{const t={...re,...e},r=t.encoder;if(!r)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return function(e){try{return Promise.resolve(e.transform(q({encoder:r,target:"size"}),W({pattern:"medium"===t.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8}))).then(function(){e.createExtension(n.MeshoptCompression).setRequired(!0).setEncoderOptions({method:"medium"===t.level?n.MeshoptCompression.EncoderMethod.QUANTIZE:n.MeshoptCompression.EncoderMethod.FILTER})})}catch(e){return Promise.reject(e)}}},exports.metalRough=function(e=ce){return l("metalRough",function(e){try{function t(){i.dispose();for(const e of a)e&&1===e.listParents().length&&e.dispose();r.debug("metalRough: Complete.")}const r=e.getLogger();if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return r.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document."),Promise.resolve();const o=e.createExtension(n.MaterialsIOR),s=e.createExtension(n.MaterialsSpecular),i=e.createExtension(n.MaterialsPBRSpecularGlossiness),a=new Set,c=function(e,t,n){if("function"==typeof e[oe]){var r,o,s,i=e[oe]();if(function e(n){try{for(;!(r=i.next()).done;)if((n=t(r.value))&&n.then){if(!ae(n))return void n.then(e,s||(s=se.bind(null,o=new ie,2)));n=n.v}o?se(o,1,n):o=n}catch(e){se(o||(o=new ie),2,e)}}(),i.return){var a=function(e){try{r.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u<e.length;u++)c.push(e[u]);return function(e,t,n){var r,o,s=-1;return function n(i){try{for(;++s<e.length;)if((i=t(s))&&i.then){if(!ae(i))return void i.then(n,o||(o=se.bind(null,r=new ie,2)));i=i.v}r?se(r,1,i):r=i}catch(e){se(r||(r=new ie),2,e)}}(),r}(c,function(e){return t(c[e])})}(e.getRoot().listMaterials(),function(t){function n(){t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}const r=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!r)return;const i=s.createSpecular().setSpecularFactor(1).setSpecularColorFactor(r.getSpecularFactor());a.add(r.getSpecularGlossinessTexture()),a.add(t.getBaseColorTexture()),a.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(r.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",o.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const c=r.getDiffuseTexture();c&&(t.setBaseColorTexture(c),t.getBaseColorTextureInfo().copy(r.getDiffuseTextureInfo()));const l=r.getSpecularGlossinessTexture(),g=function(){if(l){const n=r.getSpecularGlossinessTextureInfo(),o=e.createTexture();return Promise.resolve(u(l,o,(e,t,n)=>{e.set(t,n,3,255)})).then(function(){i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const s=r.getGlossinessFactor(),a=e.createTexture();return Promise.resolve(u(l,a,(e,t,n)=>{const r=255-Math.round(e.get(t,n,3)*s);e.set(t,n,0,0),e.set(t,n,1,r),e.set(t,n,2,0),e.set(t,n,3,255)})).then(function(){t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(n)})})}i.setSpecularColorFactor(r.getSpecularFactor()),t.setRoughnessFactor(1-r.getGlossinessFactor())}();return g&&g.then?g.then(n):n()});return Promise.resolve(c&&c.then?c.then(t):t())}catch(e){return Promise.reject(e)}})},exports.mozjpeg=function(e){const t={...Me,...e};return e=>Oe(t)(e)},exports.normals=function(e=fe){const t={...fe,...e};return l("normals",function(e){try{const n=e.getLogger();let r=0;return Promise.resolve(e.transform(le())).then(function(){for(const o of e.getRoot().listMeshes())for(const s of o.listPrimitives()){const o=s.getAttribute("POSITION");let i=s.getAttribute("NORMAL");if(t.overwrite&&i)i.dispose();else if(i)return void n.debug("normals: Skipping primitive: NORMAL found.");i=e.createAccessor().setArray(new Float32Array(3*o.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],u=[0,0,0];for(let e=0;e<o.getCount();e+=3){o.getElement(e+0,a),o.getElement(e+1,c),o.getElement(e+2,u);const t=pe(a,c,u);i.setElement(e+0,t),i.setElement(e+1,t),i.setElement(e+2,t)}s.setAttribute("NORMAL",i),r++}r?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}catch(e){return Promise.reject(e)}})},exports.oxipng=function(e){const t={...Re,...e};return e=>Oe(t)(e)},exports.partition=(t=me)=>{const n={...me,...t};return l("partition",function(t){try{const r=t.getLogger();return!1!==n.meshes&&function(e,t,n){const r=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,s)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${s} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(de(o.getName()||"mesh",r));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(t,r,n),!1!==n.animations&&function(e,t,n){const r=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,s)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${s} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(de(o.getName()||"animation",r));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(t,r,n),n.meshes||n.animations||r.warn("partition: Select animations or meshes to create a partition."),Promise.resolve(t.transform($({propertyTypes:[e.PropertyType.BUFFER]}))).then(function(){r.debug("partition: Complete.")})}catch(e){return Promise.reject(e)}})},exports.prune=$,exports.quantize=W,exports.reorder=q,exports.resample=(t=he)=>{const n={...he,...t};return l("resample",(t,r)=>{const o=new Set,s=t.getRoot().listAccessors().length,i=t.getLogger();let a=!1;for(const e of t.getRoot().listAnimations()){const t=new Set;for(const n of e.listChannels())n.getSampler()&&"weights"===n.getTargetPath()&&t.add(n.getSampler());for(const r of e.listSamplers())t.has(r)?a=!0:"STEP"!==r.getInterpolation()&&"LINEAR"!==r.getInterpolation()||(o.add(r.getInput()),o.add(r.getOutput()),ye(r,n))}for(const t of Array.from(o.values()))t.listParents().some(t=>!(t instanceof e.Root))||t.dispose();t.getRoot().listAccessors().length>s&&!function(e,t,n){return!!e&&e.stack.lastIndexOf("resample")<e.stack.lastIndexOf("dedup")}(r)&&i.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})},exports.sequence=function(t=Te){const n={...Te,...t};return l("sequence",t=>{const r=t.getLogger(),o=t.getRoot(),s=n.fps,i=o.listNodes().filter(e=>e.getName().match(n.pattern));n.sort&&i.sort((e,t)=>e.getName()>t.getName()?1:-1);const a=t.createAnimation(n.name),c=o.listBuffers()[0];i.forEach((n,r)=>{let o,u;0===r?(o=[r/s,(r+1)/s],u=[1,1,1,0,0,0]):r===i.length-1?(o=[(r-1)/s,r/s],u=[0,0,0,1,1,1]):(o=[(r-1)/s,r/s,(r+1)/s],u=[0,0,0,1,1,1,0,0,0]);const l=t.createAccessor().setArray(new Float32Array(o)).setBuffer(c),g=t.createAccessor().setArray(new Float32Array(u)).setBuffer(c).setType(e.Accessor.Type.VEC3),f=t.createAnimationSampler().setInterpolation(e.AnimationSampler.Interpolation.STEP).setInput(l).setOutput(g),p=t.createAnimationChannel().setTargetNode(n).setTargetPath(e.AnimationChannel.TargetPath.SCALE).setSampler(f);a.addSampler(f).addChannel(p)}),r.debug("sequence: Complete.")})},exports.squoosh=Oe,exports.tangents=function(t=ze){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const n={...ze,...t};return l("tangents",t=>{const r=t.getLogger(),o=new Map,s=new Map;let i=0;for(const a of t.getRoot().listMeshes()){const c=a.getName(),u=a.listPrimitives();for(let a=0;a<u.length;a++){const l=u[a];if(!Le(l,r,c,a,n.overwrite))continue;const g=$e(l),f=l.getAttribute("POSITION").getArray(),p=l.getAttribute("NORMAL").getArray(),m=l.getAttribute(g).getArray(),d=o.get(f)||e.uuid();o.set(f,d);const h=o.get(p)||e.uuid();o.set(p,h);const y=o.get(m)||e.uuid();o.set(m,y);const T=l.getAttribute("TANGENT");T&&2===T.listParents().length&&T.dispose();const A=`${d}|${h}|${y}`;let E=s.get(A);if(E){r.debug(`tangents: Found cache for primitive ${a} of mesh "${c}".`),l.setAttribute("TANGENT",E),i++;continue}r.debug(`tangents: Generating for primitive ${a} of mesh "${c}".`);const S=l.getAttribute("POSITION").getBuffer(),P=n.generateTangents(f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p),m instanceof Float32Array?m:new Float32Array(m));for(let e=3;e<P.length;e+=4)P[e]*=-1;E=t.createAccessor().setBuffer(S).setArray(P).setType("VEC4"),l.setAttribute("TANGENT",E),s.set(A,E),i++}}i?r.debug("tangents: Complete."):r.warn("tangents: No qualifying primitives found. See debug output.")})},exports.textureResize=function(e=ke){const n={...ke,...e};return l(Fe,function(e){try{let o;function r(e){s.debug(`${Fe}: Complete.`)}const s=e.getLogger(),a=function(e,t,n){if("function"==typeof e[qe]){var r,o,s,i=e[qe]();if(function e(a){try{for(;!((r=i.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!Ge(a))return void a.then(e,s||(s=_e.bind(null,o=new Ue,2)));a=a.v}o?_e(o,1,a):o=a}catch(e){_e(o||(o=new Ue),2,e)}}(),i.return){var a=function(e){try{r.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u<e.length;u++)c.push(e[u]);return function(e,t,n){var r,o,s=-1;return function i(a){try{for(;++s<e.length&&(!n||!n());)if((a=t(s))&&a.then){if(!Ge(a))return void a.then(i,o||(o=_e.bind(null,r=new Ue,2)));a=a.v}r?_e(r,1,a):r=a}catch(e){_e(r||(r=new Ue),2,e)}}(),r}(c,function(e){return t(c[e])},n)}(e.getRoot().listTextures(),function(e){const r=e.getName(),o=e.getURI();if(n.pattern&&!n.pattern.test(r)&&!n.pattern.test(o))return;if("image/png"!==e.getMimeType()&&"image/jpeg"!==e.getMimeType())return void s.warn(`Skipping unsupported texture type, "${e.getMimeType()}".`);const[a,u]=n.size,[l,g]=e.getSize();if(l<=a&&g<=u)return void s.debug(`${Fe}: Skipping "${o||r}", within size range.`);let f=l,p=g;f>a&&(p=Math.floor(p*(a/f)),f=a),p>u&&(f=Math.floor(f*(u/p)),p=u);const m=e.getImage();return Promise.resolve(t.getPixels(m,e.getMimeType())).then(function(a){const u=c.default(new Uint8Array(f*p*4),[f,p,4]);s.debug(`${Fe}: Resizing "${o||r}", ${a.shape} → ${u.shape}...`);try{n.filter===exports.TextureResizeFilter.LANCZOS3?i.lanczos3(a,u):i.lanczos2(a,u)}catch(e){if(e instanceof Error)return void s.warn(`${Fe}: Failed to resize "${o||r}": "${e.message}".`);throw e}const l=e.setImage;return Promise.resolve(t.savePixels(u,e.getMimeType())).then(function(t){l.call(e,t)})})},function(){return o});return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}})},exports.unlit=()=>e=>{const t=e.createExtension(n.MaterialsUnlit).createUnlit();e.getRoot().listMaterials().forEach(e=>{e.setExtension("KHR_materials_unlit",t)})},exports.unweld=le,exports.webp=function(e){const t={...Ie,...e};return function(e){try{return Promise.resolve(Oe(t)(e)).then(function(){e.getRoot().listTextures().some(e=>e.getMimeType()===Pe[Se.WEBP])&&e.createExtension(n.TextureWebP).setRequired(!0)})}catch(e){return Promise.reject(e)}}},exports.weld=function(t=je){const n={...je,...t};return l("weld",t=>{const r=t.getLogger();for(const r of t.getRoot().listMeshes())for(const o of r.listPrimitives())o.getMode()!==e.Primitive.Mode.POINTS&&(0===n.tolerance?De(t,o):Ve(t,o,n));r.debug("weld: Complete.")})};
//# sourceMappingURL=functions.js.map

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

import{Primitive as e,bounds as t,PropertyType as n,BufferUtils as s,Root as o,Texture as r,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,AnimationChannel as g,Accessor as u,AnimationSampler as f,Material as p,TextureChannel as m,uuid as d}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as h,savePixels as A}from"ndarray-pixels";import{MeshQuantization as E,DracoMeshCompression as y,MeshGPUInstancing as T,MeshoptCompression as S,MaterialsIOR as I,MaterialsSpecular as b,MaterialsPBRSpecularGlossiness as M,TextureWebP as w,MaterialsUnlit as R}from"@gltf-transform/extensions";import{invert as N,fromRotationTranslationScale as O,fromScaling as C,multiply as P}from"gl-matrix/mat4";import{transformMat4 as x,min as z,scale as $,max as L,normalize as v}from"gl-matrix/vec3";import q from"ndarray";import{lanczos3 as _,lanczos2 as G}from"ndarray-lanczos";function k(){return(k=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e}).apply(this,arguments)}function B(e,t){return Object.defineProperty(t,"name",{value:e}),t}async function F(e,t,n){if(!e)return null;const s=e.getImage();if(!s)return null;const o=await h(s,e.getMimeType());for(let e=0;e<o.shape[0];++e)for(let t=0;t<o.shape[1];++t)n(o,e,t);const r=await A(o,"image/png");return t.setImage(r).setMimeType("image/png")}class U{constructor(){this._map=new Map}get size(){return this._map.size}has(e){return this._map.has(e)}add(e,t){let n=this._map.get(e);return n||(n=new Set,this._map.set(e,n)),n.add(t),this}get(e){return this._map.get(e)||new Set}keys(){return this._map.keys()}}function V(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,s=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,s)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][s]}const W={pivot:"center"};function j(e=W){const n=k({},W,e);return B("center",e=>{const s=e.getLogger(),o=e.getRoot(),r=o.listAnimations().length>0||o.listSkins().length>0;e.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${o.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(r){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(e=>{const t=e.getTranslation();e.setTranslation([t[0]+l[0],t[1]+l[1],t[2]+l[2]])})}),s.debug("center: Complete.")})}const H="colorspace";function X(e){return B(H,t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info(`${H}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==e.inputEncoding)return void n.error(`${H}: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const s=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function r(e){const t=[0,0,0];let n;for(let r=0;n=e.getAttribute(`COLOR_${r}`);r++)if(!s.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);s.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(r)),n.debug(`${H}: Complete.`)})}const D={propertyTypes:[n.ACCESSOR,n.MESH,n.TEXTURE,n.MATERIAL]},K=function(e=D){const t=k({},D,e),r=new Set(t.propertyTypes);for(const e of t.propertyTypes)if(!D.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return B("dedup",e=>{const t=e.getLogger();r.has(n.ACCESSOR)&&function(e,t){const n=new Set,o=new Set,r=new Set,i=new Set,a=t.getRoot().listMeshes();a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&n.add(t)})});for(const e of t.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&r.add(e),n&&i.add(n)}function c(e){const t=new Map;for(let n=0;n<e.length;n++){const o=e[n],r=s.toView(o.getArray());if(!t.has(o))for(let n=0;n<e.length;n++){const i=e[n];o!==i&&(t.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&s.equals(r,s.toView(i.getArray()))&&t.set(i,o))}}return t}const l=c(Array.from(n));e.debug(`dedup: Found ${l.size} duplicates among ${n.size} indices.`);const g=c(Array.from(o));e.debug(`dedup: Found ${g.size} duplicates among ${o.size} attributes.`);const u=c(Array.from(r)),f=c(Array.from(i));e.debug(`dedup: Found ${u.size+f.size} duplicates among ${r.size+i.size} animation accessors.`),a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{g.has(t)&&e.swap(t,g.get(t))});const t=e.getIndices();t&&l.has(t)&&e.swap(t,l.get(t))})}),Array.from(l.keys()).forEach(e=>e.dispose()),Array.from(g.keys()).forEach(e=>e.dispose());for(const e of t.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&u.has(e)&&t.swap(e,u.get(e)),n&&f.has(n)&&t.swap(n,f.get(n))}Array.from(u.keys()).forEach(e=>e.dispose()),Array.from(f.keys()).forEach(e=>e.dispose())}(t,e),r.has(n.MESH)&&function(e,t){const s=t.getRoot(),o=new Map;s.listAccessors().forEach((e,t)=>o.set(e,t)),s.listMaterials().forEach((e,t)=>o.set(e,t));const r=s.listMeshes().length,i=new Map;for(const e of s.listMeshes()){const t=[];for(const n of e.listPrimitives())t.push(Z(n,o));const s=t.join(";");if(i.has(s)){const t=i.get(s);e.listParents().forEach(s=>{s.propertyType!==n.ROOT&&s.swap(e,t)}),e.dispose()}else i.set(s,e)}e.debug(`dedup: Found ${r-i.size} duplicates among ${r} meshes.`)}(t,e),r.has(n.TEXTURE)&&function(e,t){const n=t.getRoot(),r=n.listTextures(),i=new Map;for(let e=0;e<r.length;e++){const t=r[e],n=t.getImage();if(!i.has(t))for(let e=0;e<r.length;e++){const o=r[e],a=o.getImage();if(t===o)continue;if(i.has(o))continue;if(t.getMimeType()!==o.getMimeType())continue;const c=t.getSize(),l=o.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&n&&a&&s.equals(n,a)&&i.set(o,t)}}e.debug(`dedup: Found ${i.size} duplicates among ${n.listTextures().length} textures.`),Array.from(i.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof o||n.swap(e,t)}),e.dispose()})}(t,e),r.has(n.MATERIAL)&&function(e,t){const n=t.getRoot(),s=n.listMaterials(),r=new Map;for(let e=0;e<s.length;e++){const t=s[e];if(!r.has(t))for(let e=0;e<s.length;e++){const n=s[e];t!==n&&(r.has(n)||t.equals(n)&&r.set(n,t))}}e.debug(`dedup: Found ${r.size} duplicates among ${n.listMaterials().length} materials.`),Array.from(r.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof o||n.swap(e,t)}),e.dispose()})}(t,e),t.debug("dedup: Complete.")})};function Z(t,n){const s=[];for(const e of t.listSemantics()){const o=t.getAttribute(e);s.push(e+":"+n.get(o))}if(t instanceof e){const e=t.getIndices();e&&s.push("indices:"+n.get(e));const o=t.getMaterial();o&&s.push("material:"+n.get(o)),s.push("mode:"+t.getMode());for(const e of t.listTargets())s.push("target:"+Z(e,n))}return s.join(",")}const J={pattern:/^((?!JOINTS_).)*$/};function Q(e=J){const t=k({},J,e);return B("dequantize",e=>{const n=e.getLogger();for(const n of e.getRoot().listMeshes())for(const e of n.listPrimitives())Y(e,t);e.createExtension(E).dispose(),n.debug("dequantize: Complete.")})}function Y(e,t){for(const n of e.listSemantics())ee(n,e.getAttribute(n),t);for(const n of e.listTargets())for(const e of n.listSemantics())ee(e,n.getAttribute(e),t)}function ee(e,t,n){if(!t.getArray())return;if(!n.pattern.test(e))return;if(t.getComponentSize()>=4)return;const s=t.getArray(),o=new Float32Array(s.length);for(let e=0,n=t.getCount(),r=[];e<n;e++)r=t.getElement(e,r),t.setArray(o).setElement(e,r).setArray(s);t.setArray(o).setNormalized(!1)}const te={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"},ne=e=>{const t=k({},te,e);return e=>{e.createExtension(y).setRequired(!0).setEncoderOptions({method:"edgebreaker"===t.method?y.EncoderMethod.EDGEBREAKER:y.EncoderMethod.SEQUENTIAL,encodeSpeed:t.encodeSpeed,decodeSpeed:t.decodeSpeed,quantizationBits:{POSITION:t.quantizePosition,NORMAL:t.quantizeNormal,COLOR:t.quantizeColor,TEX_COORD:t.quantizeTexcoord,GENERIC:t.quantizeGeneric},quantizationVolume:t.quantizationVolume})}};function se(e){return{scenes:oe(e),meshes:re(e),materials:ie(e),textures:ae(e),animations:ce(e)}}function oe(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:ge(s.min),bboxMax:ge(s.max)}})}}function re(t){return{properties:t.getRoot().listMeshes().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length;let o=0,r=0;const i=new Set,a=new Set,c=new Set;t.listPrimitives().forEach(t=>{for(const e of t.listSemantics()){const n=t.getAttribute(e);i.add(e+":"+ue(n.getArray())),c.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(e=>c.add(e));const n=t.getIndices();n&&(a.add(ue(n.getArray())),c.add(n)),r+=t.listAttributes()[0].getCount(),o+=function(t){const n=t.getIndices(),s=t.getAttribute("POSITION");switch(t.getMode()){case e.Mode.POINTS:return s.getCount();case e.Mode.LINES:return n?n.getCount()/2:s.getCount()/2;case e.Mode.LINE_LOOP:return s.getCount();case e.Mode.LINE_STRIP:return s.getCount()-1;case e.Mode.TRIANGLES:return n?n.getCount()/3:s.getCount()/3;case e.Mode.TRIANGLE_STRIP:case e.Mode.TRIANGLE_FAN:return s.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}(t)});let l=0;Array.from(c).forEach(e=>l+=e.getArray().byteLength);const g=t.listPrimitives().map(e=>le[e.getMode()]);return{name:t.getName(),mode:Array.from(new Set(g)),primitives:t.listPrimitives().length,glPrimitives:o,vertices:r,indices:Array.from(a).sort(),attributes:Array.from(i).sort(),instances:s,size:l}})}}function ie(e){return{properties:e.getRoot().listMaterials().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length,o=new Set(t.listExtensions()),a=e.getGraph().listEdges().filter(e=>{const n=e.getChild(),s=e.getParent();return n instanceof r&&s===t||!!(n instanceof r&&s instanceof i&&o.has(s))}).map(e=>e.getName());return{name:t.getName(),instances:s,textures:a,alphaMode:t.getAlphaMode(),doubleSided:t.getDoubleSided()}})}}function ae(e){return{properties:e.getRoot().listTextures().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length,o=e.getGraph().listParentEdges(t).filter(e=>e.getParent().propertyType!==n.ROOT).map(e=>e.getName()),r=a.getSize(t.getImage(),t.getMimeType());return{name:t.getName(),uri:t.getURI(),slots:Array.from(new Set(o)),instances:s,mimeType:t.getMimeType(),resolution:r?r.join("x"):"",size:t.getImage().byteLength,gpuSize:a.getMemSize(t.getImage(),t.getMimeType())}})}}function ce(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const s=e.getInput();s&&(t=Math.min(t,s.getMin([])[0]),n=Math.max(n,s.getMax([])[0]))});let s=0,o=0;const r=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),r.add(t),n&&r.add(n))}),Array.from(r).forEach(e=>{s+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:s}})}}const le=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function ge(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function ue(e){return e.constructor.name.replace("Array","").toLowerCase()}const fe={};function pe(e=fe){return k({},fe,e),B("instance",e=>{const t=e.getLogger(),n=e.getRoot(),s=e.createExtension(T);if(n.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let o=0,r=0;for(const i of n.listScenes()){const n=new Map;i.traverse(e=>{const t=e.getMesh();t&&n.set(t,(n.get(t)||new Set).add(e))});const a=[];for(const l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(e=>e.getSkin()))continue;const u=de(e,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=e.createNode().setMesh(l).setExtension("EXT_mesh_gpu_instancing",u);i.addChild(d);let h=!1,A=!1,E=!1;for(let e=0;e<g.length;e++){let t,n,s;const o=g[e];f.setElement(e,t=o.getWorldTranslation()),p.setElement(e,n=o.getWorldRotation()),m.setElement(e,s=o.getWorldScale()),c.eq(t,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(E=!0),o.setMesh(null),a.push(o)}h||f.dispose(),A||p.dispose(),E||m.dispose(),me(a,t),o++,r+=g.length}}o>0?t.info(`instance: Created ${o} batches, with ${r} total instances.`):(t.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),t.debug("instance: Complete.")})}function me(e,t){let n,s=0;for(;n=e.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const t=n.getParent();t instanceof l&&e.push(t),n.dispose(),s++}t.debug(`instance: Removed ${s} unused nodes.`)}function de(e,t,n,s){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),r=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*s)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",r).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const he={propertyTypes:[n.NODE,n.SKIN,n.MESH,n.CAMERA,n.PRIMITIVE,n.PRIMITIVE_TARGET,n.ANIMATION,n.MATERIAL,n.TEXTURE,n.ACCESSOR,n.BUFFER]},Ae=function(e=he){const t=k({},he,e).propertyTypes;return B("prune",e=>{const s=e.getLogger(),r=e.getRoot(),i=e.getGraph(),a={};if(t.includes(n.NODE)&&r.listNodes().forEach(c),t.includes(n.SKIN)&&r.listSkins().forEach(c),t.includes(n.MESH)&&r.listMeshes().forEach(c),t.includes(n.CAMERA)&&r.listCameras().forEach(c),t.includes(n.PRIMITIVE)&&l(i,n.PRIMITIVE),t.includes(n.PRIMITIVE_TARGET)&&l(i,n.PRIMITIVE_TARGET),t.includes(n.ANIMATION))for(const e of r.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),u(t));if(e.listChannels().length)e.listSamplers().forEach(c);else{const t=e.listSamplers();c(e),t.forEach(c)}}if(t.includes(n.MATERIAL)&&r.listMaterials().forEach(c),t.includes(n.TEXTURE)&&r.listTextures().forEach(c),t.includes(n.ACCESSOR)&&r.listAccessors().forEach(c),t.includes(n.BUFFER)&&r.listBuffers().forEach(c),Object.keys(a).length){const e=Object.keys(a).map(e=>`${e} (${a[e]})`).join(", ");s.info(`prune: Removed types... ${e}`)}else s.info("prune: No unused properties found.");function c(e){e.listParents().filter(e=>!(e instanceof o||e instanceof g)).length||(e.dispose(),u(e))}function l(e,t){e.listEdges().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(c)}function u(e){a[e.propertyType]=a[e.propertyType]||0,a[e.propertyType]++}s.debug("prune: Complete.")})},Ee={target:"size"};function ye(t){const s=k({},Ee,t),o=s.encoder;if(!o)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return B("reorder",async t=>{const r=t.getLogger();await o.ready;const i=function(e){const t=new U,n=new Map,s=new U;for(const o of e.getRoot().listMeshes())for(const e of o.listPrimitives()){const o=e.getIndices();if(o){n.set(o,e.getMode());for(const n of Se(e))t.add(o,n),s.add(n,e)}}return{indicesToAttributes:t,indicesToMode:n,attributesToPrimitives:s}}(t);for(const t of i.indicesToAttributes.keys()){const n=t.clone();let r=n.getArray().slice();r instanceof Uint32Array||(r=new Uint32Array(r));const[a,c]=o.reorderMesh(r,i.indicesToMode.get(t)===e.Mode.TRIANGLES,"size"===s.target);n.setArray(c<=65534?new Uint16Array(r):r);for(const e of i.indicesToAttributes.get(t)){const s=e.clone();Te(s,a,c);for(const o of i.attributesToPrimitives.get(e))if(o.getIndices()===t&&o.swap(t,n),o.getIndices()===n){o.swap(e,s);for(const t of o.listTargets())t.swap(e,s)}}}await t.transform(Ae({propertyTypes:[n.ACCESSOR]})),i.indicesToAttributes.size?r.debug("reorder: Complete."):r.warn("reorder: No qualifying primitives found; may need to weld first.")})}function Te(e,t,n){const s=e.getElementSize(),o=e.getCount(),r=e.getArray(),i=r.slice(0,n*s);for(let e=0;e<o;e++)for(let n=0;n<s;n++)i[t[e]*s+n]=r[e*s+n];e.setArray(i)}function Se(e){const t=[];for(const n of e.listAttributes())t.push(n);for(const n of e.listTargets())for(const e of n.listAttributes())t.push(e);return Array.from(new Set(t))}const Ie=[Int8Array,Int16Array,Int32Array],{TRANSLATION:be,ROTATION:Me,SCALE:we,WEIGHTS:Re}=g.TargetPath,Ne=[be,Me,we],Oe={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},Ce=(e=Oe)=>{const t=k({},Oe,e);return B("quantize",async e=>{const s=e.getLogger(),o=e.getRoot();let r;e.createExtension(E).setRequired(!0),"scene"===t.quantizationVolume&&(r=xe(function(e){const t=e[0];for(const n of e)z(t.min,t.min,n.min),L(t.max,t.max,n.max);return t}(o.listMeshes().map(_e))));for(const n of e.getRoot().listMeshes()){"mesh"===t.quantizationVolume&&(r=xe(_e(n))),r&&t.pattern.test("POSITION")&&(ze(e,n,r),Le(n,1/r.scale));for(const s of n.listPrimitives()){Pe(e,s,r,t);for(const n of s.listTargets())Pe(e,n,r,t)}}await e.transform(Ae({propertyTypes:[n.ACCESSOR,n.SKIN,n.MATERIAL]}),K({propertyTypes:[n.ACCESSOR,n.MATERIAL]})),s.debug("quantize: Complete.")})};function Pe(t,n,s,o){const r=t.getLogger();for(const t of n.listSemantics()){if(!o.pattern.test(t))continue;const i=n.getAttribute(t),{bits:a,ctor:c}=qe(t,i,r,o);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=s.scale,o=[];n instanceof e?N(o,ke(s)):C(o,[1/t,1/t,1/t]);for(let e=0,t=[0,0,0],n=l.getCount();e<n;e++)l.getElement(e,t),l.setElement(e,x(t,t,o))}ve(l,c,a),n.swap(i,l)}if(n.getAttribute("WEIGHTS_0")&&function(e){const t=e.getAttribute("POSITION").getCount(),n=[];for(let s=0;s<t;s++){let t,o=0,r=Infinity,i=-1,a=null,c=0;for(;t=e.getAttribute("WEIGHTS_"+c++);){t.getElement(s,n);for(let e=0;e<n.length;e++)o+=n[e],n[e]>0&&n[e]<r&&(a=t,r=n[e],i=e)}a&&1!==o&&(a.getElement(s,n),n[i]+=1-o,a.setElement(s,n))}}(n),n instanceof e&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const e=n.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function xe(e){const{min:t,max:n}=e,s=Math.max((n[0]-t[0])/2,(n[1]-t[1])/2,(n[2]-t[2])/2);return{offset:[t[0]+(n[0]-t[0])/2,t[1]+(n[1]-t[1])/2,t[2]+(n[2]-t[2])/2],scale:s}}function ze(e,t,n){const s=ke(n);for(const o of t.listParents()){if(!(o instanceof l))continue;const r=o.listParents().filter(e=>e instanceof g),i=r.some(e=>Ne.includes(e.getTargetPath())),a=o.listChildren().length>0;if(o.getSkin()){o.setSkin($e(o.getSkin(),n));continue}let c;a||i?(c=e.createNode("").setMesh(t),o.addChild(c).setMesh(null),r.filter(e=>e.getTargetPath()===Re).forEach(e=>e.setTargetNode(c))):c=o;const u=c.getMatrix();P(u,u,s),c.setMatrix(u)}}function $e(e,t){e=e.clone();const n=ke(t),s=e.getInverseBindMatrices().clone(),o=[];for(let e=0,t=s.getCount();e<t;e++)s.getElement(e,o),P(o,o,n),s.setElement(e,o);return e.setInverseBindMatrices(s)}function Le(e,t){for(const n of e.listPrimitives()){let e=n.getMaterial();if(!e)continue;let s=e.getExtension("KHR_materials_volume");!s||s.getThicknessFactor()<=0||(s=s.clone().setThicknessFactor(s.getThicknessFactor()*t),e=e.clone().setExtension("KHR_materials_volume",s),n.setMaterial(e))}}function ve(e,t,n){const s=new t(e.getArray().length),o=Ie.includes(t)?1:0,r=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,r)-1,c=i-r,l=2*r-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>l,s[n++]=t*Math.sign(o[e])}}e.setArray(s).setNormalized(!0)}function qe(e,t,n,s){const o=t.getMinNormalized([]),r=t.getMaxNormalized([]);let i,a;if("POSITION"===e)i=s.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=s.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=s.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=s.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=s.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [-1,1] range.`),{bits:-1};i=s.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function _e(e){const t=[],n=[];for(const s of e.listPrimitives()){const e=s.getAttribute("POSITION");e&&t.push(e);for(const e of s.listTargets()){const t=e.getAttribute("POSITION");t&&n.push(t)}}if(0===t.length)throw new Error('quantize: Missing "POSITION" attribute.');const s=Ge(t,3);if(n.length>0){const{min:e,max:t}=Ge(n,3);z(s.min,s.min,z(e,$(e,e,2),[0,0,0])),L(s.max,s.max,L(t,$(t,t,2),[0,0,0]))}return s}function Ge(e,t){const n=new Array(t).fill(Infinity),s=new Array(t).fill(-Infinity),o=[],r=[];for(const i of e){i.getMinNormalized(o),i.getMaxNormalized(r);for(let e=0;e<t;e++)n[e]=Math.min(n[e],o[e]),s[e]=Math.max(s[e],r[e])}return{min:n,max:s}}function ke(e){return O([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}const Be={level:"high"},Fe=e=>{const t=k({},Be,e),n=t.encoder;if(!n)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return async e=>{await e.transform(ye({encoder:n,target:"size"}),Ce({pattern:"medium"===t.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8})),e.createExtension(S).setRequired(!0).setEncoderOptions({method:"medium"===t.level?S.EncoderMethod.QUANTIZE:S.EncoderMethod.FILTER})}},Ue={};function Ve(e=Ue){return k({},Ue,e),B("metalRough",async e=>{const t=e.getLogger();if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return void t.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document.");const n=e.createExtension(I),s=e.createExtension(b),o=e.createExtension(M),r=new Set;for(const t of e.getRoot().listMaterials()){const o=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!o)continue;const i=s.createSpecular().setSpecularFactor(1).setSpecularColorFactor(o.getSpecularFactor());r.add(o.getSpecularGlossinessTexture()),r.add(t.getBaseColorTexture()),r.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(o.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",n.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const a=o.getDiffuseTexture();a&&(t.setBaseColorTexture(a),t.getBaseColorTextureInfo().copy(o.getDiffuseTextureInfo()));const c=o.getSpecularGlossinessTexture();if(c){const n=o.getSpecularGlossinessTextureInfo(),s=e.createTexture();await F(c,s,(e,t,n)=>{e.set(t,n,3,255)}),i.setSpecularTexture(s),i.setSpecularColorTexture(s),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const r=o.getGlossinessFactor(),a=e.createTexture();await F(c,a,(e,t,n)=>{const s=255-Math.round(e.get(t,n,3)*r);e.set(t,n,0,0),e.set(t,n,1,s),e.set(t,n,2,0),e.set(t,n,3,255)}),t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(n)}else i.setSpecularColorFactor(o.getSpecularFactor()),t.setRoughnessFactor(1-o.getGlossinessFactor());t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}o.dispose();for(const e of r)e&&1===e.listParents().length&&e.dispose();t.debug("metalRough: Complete.")})}const We={};function je(e=We){return k({},We,e),B("unweld",e=>{const t=e.getLogger(),n=new Map;for(const s of e.getRoot().listMeshes())for(const e of s.listPrimitives()){const s=e.getIndices();if(s){for(const o of e.listAttributes())e.swap(o,He(o,s,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,He(e,s,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===s.listParents().length&&s.dispose()}}t.debug("unweld: Complete.")})}function He(e,t,n,s){if(s.has(e)&&s.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),s.get(e).get(t);const o=e.clone(),r=e.getArray().constructor;o.setArray(new r(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return s.has(e)||s.set(e,new Map),s.get(e).set(t,o),o}const Xe={overwrite:!1};function De(e=Xe){const t=k({},Xe,e);return B("normals",async e=>{const n=e.getLogger();let s=0;await e.transform(je());for(const o of e.getRoot().listMeshes())for(const r of o.listPrimitives()){const o=r.getAttribute("POSITION");let i=r.getAttribute("NORMAL");if(t.overwrite&&i)i.dispose();else if(i){n.debug("normals: Skipping primitive: NORMAL found.");continue}i=e.createAccessor().setArray(new Float32Array(3*o.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],l=[0,0,0];for(let e=0;e<o.getCount();e+=3){o.getElement(e+0,a),o.getElement(e+1,c),o.getElement(e+2,l);const t=Ke(a,c,l);i.setElement(e+0,t),i.setElement(e+1,t),i.setElement(e+2,t)}r.setAttribute("NORMAL",i),s++}s?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}function Ke(e,t,n){const s=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],o=[n[0]-e[0],n[1]-e[1],n[2]-e[2]];return v([0,0,0],[s[1]*o[2]-s[2]*o[1],s[2]*o[0]-s[0]*o[2],s[0]*o[1]-s[1]*o[0]])}const Ze={animations:!0,meshes:!0},Je=(e=Ze)=>{const t=k({},Ze,e);return B("partition",async e=>{const s=e.getLogger();!1!==t.meshes&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,r)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(Qe(o.getName()||"mesh",s));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(e,s,t),!1!==t.animations&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,r)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(Qe(o.getName()||"animation",s));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(e,s,t),t.meshes||t.animations||s.warn("partition: Select animations or meshes to create a partition."),await e.transform(Ae({propertyTypes:[n.BUFFER]})),s.debug("partition: Complete.")})};function Qe(e,t){let n=`${e}.bin`,s=1;for(;t.has(n);)n=`${e}_${s++}.bin`;return n}const Ye={tolerance:1e-4},et=(e=Ye)=>{const t=k({},Ye,e);return B("resample",(e,n)=>{const s=new Set,r=e.getRoot().listAccessors().length,i=e.getLogger();let a=!1;for(const n of e.getRoot().listAnimations()){const e=new Set;for(const t of n.listChannels())t.getSampler()&&"weights"===t.getTargetPath()&&e.add(t.getSampler());for(const o of n.listSamplers())e.has(o)?a=!0:"STEP"!==o.getInterpolation()&&"LINEAR"!==o.getInterpolation()||(s.add(o.getInput()),s.add(o.getOutput()),tt(o,t))}for(const e of Array.from(s.values()))e.listParents().some(e=>!(e instanceof o))||e.dispose();e.getRoot().listAccessors().length>r&&!function(e,t,n){return!!e&&e.stack.lastIndexOf("resample")<e.stack.lastIndexOf("dedup")}(n)&&i.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})};function tt(e,t){const n=e.getInput().clone(),s=e.getOutput().clone(),o=t.tolerance,r=n.getCount()-1,i=[];let a=1;for(let t=1;t<r;++t){const r=n.getScalar(t),l=n.getScalar(t-1),g=n.getScalar(t+1),u=(r-l)/(g-l);let f=!1;if(r!==g&&(1!==t||r!==n.getScalar(0)))for(let n=0;n<s.getElementSize();n++){const r=s.getElement(t,i)[n],a=s.getElement(t-1,i)[n],l=s.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(r-(a*(1-(c=u))+l*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(r!==a||r!==l)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),s.setElement(a,s.getElement(t,i))),a++)}var c;r>0&&(n.setScalar(a,n.getScalar(r)),s.setElement(a,s.getElement(r,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),s.setArray(s.getArray().slice(0,a*s.getElementSize())),e.setInput(n),e.setOutput(s)):(n.dispose(),s.dispose())}const nt={name:"",fps:10,pattern:/.*/,sort:!0};function st(e=nt){const t=k({},nt,e);return B("sequence",e=>{const n=e.getLogger(),s=e.getRoot(),o=t.fps,r=s.listNodes().filter(e=>e.getName().match(t.pattern));t.sort&&r.sort((e,t)=>e.getName()>t.getName()?1:-1);const i=e.createAnimation(t.name),a=s.listBuffers()[0];r.forEach((t,n)=>{let s,c;0===n?(s=[n/o,(n+1)/o],c=[1,1,1,0,0,0]):n===r.length-1?(s=[(n-1)/o,n/o],c=[0,0,0,1,1,1]):(s=[(n-1)/o,n/o,(n+1)/o],c=[0,0,0,1,1,1,0,0,0]);const l=e.createAccessor().setArray(new Float32Array(s)).setBuffer(a),p=e.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(u.Type.VEC3),m=e.createAnimationSampler().setInterpolation(f.Interpolation.STEP).setInput(l).setOutput(p),d=e.createAnimationChannel().setTargetNode(t).setTargetPath(g.TargetPath.SCALE).setSampler(m);i.addSampler(m).addChannel(d)}),n.debug("sequence: Complete.")})}function ot(e,t){const n=rt(e,t),s=[];return n&m.R&&s.push(m.R),n&m.G&&s.push(m.G),n&m.B&&s.push(m.B),n&m.A&&s.push(m.A),s}function rt(e,t){let s=0;for(const o of e.getGraph().listParentEdges(t)){const t=o.getParent();let{channels:r}=o.getAttributes();r&&"baseColorTexture"===o.getName()&&t instanceof p&&t.getAlphaMode()===p.AlphaMode.OPAQUE&&(r&=~m.A),r?s|=r:t.propertyType!==n.ROOT&&e.getLogger().warn(`Missing attribute ".channels" on edge, "${o.getName()}".`)}return s}function it(e,t){const n=e.getRoot(),s=e.getGraph().listParentEdges(t).filter(e=>e.getParent()!==n).map(e=>e.getName());return Array.from(new Set(s))}var at;!function(e){e.OXIPNG="oxipng",e.MOZJPEG="mozjpeg",e.WEBP="webp"}(at||(at={}));const ct={[at.OXIPNG]:"image/png",[at.MOZJPEG]:"image/jpeg",[at.WEBP]:"image/webp"},lt={formats:/.*/,slots:/.*/,auto:!1},gt=k({},lt,{codec:at.WEBP}),ut=k({},lt,{codec:at.MOZJPEG,formats:/^image\/jpeg$/}),ft=k({},lt,{codec:at.OXIPNG,formats:/^image\/png$/}),pt=["image/jpeg","image/png","image/webp"];let mt=null,dt=0;const ht=e=>(mt||(mt=new e.ImagePool(require("os").cpus().length)),dt++,mt),At=()=>{0==--dt&&mt.close()},Et=function(e){const t=k({},lt,e),n=t.squoosh;if(!n)throw new Error('squoosh: squoosh dependency required — install "@squoosh/lib".');return async e=>{const s=e.getLogger(),o=e.getRoot().listTextures(),r=ht(n);await Promise.all(o.map(async(n,o)=>{const i=it(e,n),a=rt(e,n),c=`squoosh:texture(${n.getURI()||n.getName()||`${o+1}/${e.getRoot().listTextures().length}`})`;if(!pt.includes(n.getMimeType()))return void s.debug(`${c}: Skipping, unsupported texture type "${n.getMimeType()}".`);if(!t.formats.test(n.getMimeType()))return void s.debug(`${c}: Skipping, "${n.getMimeType()}" excluded by "formats" parameter.`);if(i.length&&!i.some(e=>t.slots.test(e)))return void s.debug(`${c}: Skipping, [${i.join(", ")}] excluded by "slots" parameter.`);if(t.codec===at.MOZJPEG&&a&m.A)return void s.warn(`${c}: Skipping, [${i.join(", ")}] requires alpha channel.`);s.debug(`${c}: Slots → [${i.join(", ")}]`);const l=r.ingestImage(n.getImage()),g=n.getImage().byteLength;await l.encode({[t.codec]:t.auto?"auto":{}});const u=await l.encodedWith[t.codec];s.debug(`${c}: ${JSON.stringify(u.optionsUsed)}`),n.setImage(u.binary).setMimeType(ct[t.codec]);const f=u.binary.byteLength;s.debug(`${c}: ${V(g)} → ${V(f)}`)})),At(),s.debug("squoosh: Complete.")}},yt=function(e){const t=k({},gt,e);return async e=>{await Et(t)(e),e.getRoot().listTextures().some(e=>e.getMimeType()===ct[at.WEBP])&&e.createExtension(w).setRequired(!0)}},Tt=function(e){const t=k({},ut,e);return e=>Et(t)(e)},St=function(e){const t=k({},ft,e);return e=>Et(t)(e)},It={overwrite:!1};function bt(e=It){if(!e.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const t=k({},It,e);return B("tangents",e=>{const n=e.getLogger(),s=new Map,o=new Map;let r=0;for(const i of e.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!wt(l,n,a,i,t.overwrite))continue;const g=Mt(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),p=l.getAttribute(g).getArray(),m=s.get(u)||d();s.set(u,m);const h=s.get(f)||d();s.set(f,h);const A=s.get(p)||d();s.set(p,A);const E=l.getAttribute("TANGENT");E&&2===E.listParents().length&&E.dispose();const y=`${m}|${h}|${A}`;let T=o.get(y);if(T){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",T),r++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),I=t.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p));for(let e=3;e<I.length;e+=4)I[e]*=-1;T=e.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",T),o.set(y,T),r++}}r?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")})}function Mt(e){const t=e.getMaterial();if(!t)return"TEXCOORD_0";const n=t.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const s=`TEXCOORD_${n.getTexCoord()}`;return e.getAttribute(s)?s:"TEXCOORD_0"}function wt(t,n,s,o,r){return t.getMode()===e.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!r?(n.debug(`tangents: Skipping primitive ${o} of mesh "${s}": TANGENT found.`),!1):!t.getIndices()||(n.warn(`tangents: Skipping primitive ${o} of mesh "${s}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${o} of mesh "${s}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const Rt="textureResize";var Nt;!function(e){e.LANCZOS3="lanczos3",e.LANCZOS2="lanczos2"}(Nt||(Nt={}));const Ot={size:[2048,2048],filter:Nt.LANCZOS3,pattern:null};function Ct(e=Ot){const t=k({},Ot,e);return B(Rt,async e=>{const n=e.getLogger();for(const s of e.getRoot().listTextures()){const e=s.getName(),o=s.getURI();if(t.pattern&&!t.pattern.test(e)&&!t.pattern.test(o))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[r,i]=t.size,[a,c]=s.getSize();if(a<=r&&c<=i){n.debug(`${Rt}: Skipping "${o||e}", within size range.`);continue}let l=a,g=c;l>r&&(g=Math.floor(g*(r/l)),l=r),g>i&&(l=Math.floor(l*(i/g)),g=i);const u=s.getImage(),f=await h(u,s.getMimeType()),p=q(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${Rt}: Resizing "${o||e}", ${f.shape} → ${p.shape}...`);try{t.filter===Nt.LANCZOS3?_(f,p):G(f,p)}catch(t){if(t instanceof Error){n.warn(`${Rt}: Failed to resize "${o||e}": "${t.message}".`);continue}throw t}s.setImage(await A(p,s.getMimeType()))}n.debug(`${Rt}: Complete.`)})}const Pt=()=>e=>{const t=e.createExtension(R).createUnlit();e.getRoot().listMaterials().forEach(e=>{e.setExtension("KHR_materials_unlit",t)})},xt={tolerance:1e-4};function zt(t=xt){const n=k({},xt,t);return B("weld",t=>{const s=t.getLogger();for(const s of t.getRoot().listMeshes())for(const o of s.listPrimitives())o.getMode()!==e.Mode.POINTS&&(0===n.tolerance?$t(t,o):Lt(t,o,n));s.debug("weld: Complete.")})}function $t(e,t){if(t.getIndices())return;const n=t.listAttributes()[0],s=n.getCount(),o=n.getBuffer(),r=s<=65534?new Uint16Array(s):new Uint32Array(s),i=e.createAccessor().setBuffer(o).setType(u.Type.SCALAR).setArray(r);for(let e=0;e<i.getCount();e++)i.setScalar(e,e);t.setIndices(i)}function Lt(e,t,n){const s=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/s),r=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),l=new Map;t.listAttributes().forEach(e=>l.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>l.set(e,[]))});const g=[];let u=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,s=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)s.push(~~(e.getElement(n,o)[t]*r));const c=s.join("|");if(c in i)g.push(i[c]);else{for(const e of t.listAttributes())l.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())l.get(t).push(t.getElement(n,[]));i[c]=u,g.push(u),u++}}const f=t.listAttributes()[0].getCount(),p=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())qt(t,e,l.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())qt(e,t,l.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=vt(a.getArray(),g.length);e.set(g),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(g):new Uint32Array(g);t.setIndices(e.createAccessor().setArray(n))}}function vt(e,t){return new(0,e.constructor)(t)}function qt(e,t,n){const s=n.length*t.getElementSize(),o=vt(t.getArray(),s),r=t.clone().setArray(o);for(let e=0;e<n.length;e++)r.setElement(e,n[e]);e.swap(t,r)}export{te as DRACO_DEFAULTS,Be as MESHOPT_DEFAULTS,Oe as QUANTIZE_DEFAULTS,Ot as TEXTURE_RESIZE_DEFAULTS,Nt as TextureResizeFilter,j as center,X as colorspace,K as dedup,Q as dequantize,ne as draco,rt as getTextureChannelMask,se as inspect,pe as instance,ot as listTextureChannels,it as listTextureSlots,Fe as meshopt,Ve as metalRough,Tt as mozjpeg,De as normals,St as oxipng,Je as partition,Ae as prune,Ce as quantize,ye as reorder,et as resample,st as sequence,Et as squoosh,bt as tangents,Ct as textureResize,Pt as unlit,je as unweld,yt as webp,zt as weld};
import{Primitive as e,bounds as t,PropertyType as n,BufferUtils as s,Root as o,Texture as r,ExtensionProperty as i,ImageUtils as a,MathUtils as c,Node as l,AnimationChannel as g,Accessor as u,AnimationSampler as f,Material as p,TextureChannel as m,uuid as d}from"@gltf-transform/core";export{bounds}from"@gltf-transform/core";import{getPixels as h,savePixels as A}from"ndarray-pixels";import{MeshQuantization as E,DracoMeshCompression as y,MeshGPUInstancing as T,MeshoptCompression as S,MaterialsIOR as I,MaterialsSpecular as b,MaterialsPBRSpecularGlossiness as M,TextureWebP as w,MaterialsUnlit as R}from"@gltf-transform/extensions";import{invert as N,fromRotationTranslationScale as O,fromScaling as C,multiply as P}from"gl-matrix/mat4";import{transformMat4 as x,min as z,scale as $,max as L,normalize as v}from"gl-matrix/vec3";import q from"ndarray";import{lanczos3 as _,lanczos2 as G}from"ndarray-lanczos";function k(){return(k=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e}).apply(this,arguments)}function B(e,t){return Object.defineProperty(t,"name",{value:e}),t}async function F(e,t,n){if(!e)return null;const s=e.getImage();if(!s)return null;const o=await h(s,e.getMimeType());for(let e=0;e<o.shape[0];++e)for(let t=0;t<o.shape[1];++t)n(o,e,t);const r=await A(o,"image/png");return t.setImage(r).setMimeType("image/png")}class U{constructor(){this._map=new Map}get size(){return this._map.size}has(e){return this._map.has(e)}add(e,t){let n=this._map.get(e);return n||(n=new Set,this._map.set(e,n)),n.add(t),this}get(e){return this._map.get(e)||new Set}keys(){return this._map.keys()}}function V(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,s=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,s)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][s]}const W={pivot:"center"};function j(e=W){const n=k({},W,e);return B("center",e=>{const s=e.getLogger(),o=e.getRoot(),r=o.listAnimations().length>0||o.listSkins().length>0;e.getRoot().listScenes().forEach((i,a)=>{let c;if(s.debug(`center: Scene ${a+1} / ${o.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(r){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(e=>{const t=e.getTranslation();e.setTranslation([t[0]+l[0],t[1]+l[1],t[2]+l[2]])})}),s.debug("center: Complete.")})}const H="colorspace";function X(e){return B(H,t=>{const n=t.getLogger();if("linear"===e.inputEncoding)return void n.info(`${H}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==e.inputEncoding)return void n.error(`${H}: Unknown input encoding "${e.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const s=new Set;function o(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function r(e){const t=[0,0,0];let n;for(let r=0;n=e.getAttribute(`COLOR_${r}`);r++)if(!s.has(n)){for(let e=0;e<n.getCount();e++)n.getElement(e,t),t[0]=o(t[0]),t[1]=o(t[1]),t[2]=o(t[2]),n.setElement(e,t);s.add(n)}}t.getRoot().listMeshes().forEach(e=>e.listPrimitives().forEach(r)),n.debug(`${H}: Complete.`)})}const D={propertyTypes:[n.ACCESSOR,n.MESH,n.TEXTURE,n.MATERIAL]},K=function(e=D){const t=k({},D,e),r=new Set(t.propertyTypes);for(const e of t.propertyTypes)if(!D.propertyTypes.includes(e))throw new Error(`dedup: Unsupported deduplication on type "${e}".`);return B("dedup",e=>{const t=e.getLogger();r.has(n.ACCESSOR)&&function(e,t){const n=new Set,o=new Set,r=new Set,i=new Set,a=t.getRoot().listMeshes();a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(e=>o.add(e));const t=e.getIndices();t&&n.add(t)})});for(const e of t.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&r.add(e),n&&i.add(n)}function c(e){const t=new Map;for(let n=0;n<e.length;n++){const o=e[n],r=s.toView(o.getArray());if(!t.has(o))for(let n=0;n<e.length;n++){const i=e[n];o!==i&&(t.has(i)||o.getType()===i.getType()&&o.getComponentType()===i.getComponentType()&&o.getCount()===i.getCount()&&o.getNormalized()===i.getNormalized()&&s.equals(r,s.toView(i.getArray()))&&t.set(i,o))}}return t}const l=c(Array.from(n));e.debug(`dedup: Found ${l.size} duplicates among ${n.size} indices.`);const g=c(Array.from(o));e.debug(`dedup: Found ${g.size} duplicates among ${o.size} attributes.`);const u=c(Array.from(r)),f=c(Array.from(i));e.debug(`dedup: Found ${u.size+f.size} duplicates among ${r.size+i.size} animation accessors.`),a.forEach(e=>{e.listPrimitives().forEach(e=>{e.listAttributes().forEach(t=>{g.has(t)&&e.swap(t,g.get(t))});const t=e.getIndices();t&&l.has(t)&&e.swap(t,l.get(t))})}),Array.from(l.keys()).forEach(e=>e.dispose()),Array.from(g.keys()).forEach(e=>e.dispose());for(const e of t.getRoot().listAnimations())for(const t of e.listSamplers()){const e=t.getInput(),n=t.getOutput();e&&u.has(e)&&t.swap(e,u.get(e)),n&&f.has(n)&&t.swap(n,f.get(n))}Array.from(u.keys()).forEach(e=>e.dispose()),Array.from(f.keys()).forEach(e=>e.dispose())}(t,e),r.has(n.MESH)&&function(e,t){const s=t.getRoot(),o=new Map;s.listAccessors().forEach((e,t)=>o.set(e,t)),s.listMaterials().forEach((e,t)=>o.set(e,t));const r=s.listMeshes().length,i=new Map;for(const e of s.listMeshes()){const t=[];for(const n of e.listPrimitives())t.push(Z(n,o));const s=t.join(";");if(i.has(s)){const t=i.get(s);e.listParents().forEach(s=>{s.propertyType!==n.ROOT&&s.swap(e,t)}),e.dispose()}else i.set(s,e)}e.debug(`dedup: Found ${r-i.size} duplicates among ${r} meshes.`)}(t,e),r.has(n.TEXTURE)&&function(e,t){const n=t.getRoot(),r=n.listTextures(),i=new Map;for(let e=0;e<r.length;e++){const t=r[e],n=t.getImage();if(!i.has(t))for(let e=0;e<r.length;e++){const o=r[e],a=o.getImage();if(t===o)continue;if(i.has(o))continue;if(t.getMimeType()!==o.getMimeType())continue;const c=t.getSize(),l=o.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&n&&a&&s.equals(n,a)&&i.set(o,t)}}e.debug(`dedup: Found ${i.size} duplicates among ${n.listTextures().length} textures.`),Array.from(i.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof o||n.swap(e,t)}),e.dispose()})}(t,e),r.has(n.MATERIAL)&&function(e,t){const n=t.getRoot(),s=n.listMaterials(),r=new Map;for(let e=0;e<s.length;e++){const t=s[e];if(!r.has(t))for(let e=0;e<s.length;e++){const n=s[e];t!==n&&(r.has(n)||t.equals(n)&&r.set(n,t))}}e.debug(`dedup: Found ${r.size} duplicates among ${n.listMaterials().length} materials.`),Array.from(r.entries()).forEach(([e,t])=>{e.listParents().forEach(n=>{n instanceof o||n.swap(e,t)}),e.dispose()})}(t,e),t.debug("dedup: Complete.")})};function Z(t,n){const s=[];for(const e of t.listSemantics()){const o=t.getAttribute(e);s.push(e+":"+n.get(o))}if(t instanceof e){const e=t.getIndices();e&&s.push("indices:"+n.get(e));const o=t.getMaterial();o&&s.push("material:"+n.get(o)),s.push("mode:"+t.getMode());for(const e of t.listTargets())s.push("target:"+Z(e,n))}return s.join(",")}const J={pattern:/^((?!JOINTS_).)*$/};function Q(e=J){const t=k({},J,e);return B("dequantize",e=>{const n=e.getLogger();for(const n of e.getRoot().listMeshes())for(const e of n.listPrimitives())Y(e,t);e.createExtension(E).dispose(),n.debug("dequantize: Complete.")})}function Y(e,t){for(const n of e.listSemantics())ee(n,e.getAttribute(n),t);for(const n of e.listTargets())for(const e of n.listSemantics())ee(e,n.getAttribute(e),t)}function ee(e,t,n){if(!t.getArray())return;if(!n.pattern.test(e))return;if(t.getComponentSize()>=4)return;const s=t.getArray(),o=new Float32Array(s.length);for(let e=0,n=t.getCount(),r=[];e<n;e++)r=t.getElement(e,r),t.setArray(o).setElement(e,r).setArray(s);t.setArray(o).setNormalized(!1)}const te={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"},ne=e=>{const t=k({},te,e);return e=>{e.createExtension(y).setRequired(!0).setEncoderOptions({method:"edgebreaker"===t.method?y.EncoderMethod.EDGEBREAKER:y.EncoderMethod.SEQUENTIAL,encodeSpeed:t.encodeSpeed,decodeSpeed:t.decodeSpeed,quantizationBits:{POSITION:t.quantizePosition,NORMAL:t.quantizeNormal,COLOR:t.quantizeColor,TEX_COORD:t.quantizeTexcoord,GENERIC:t.quantizeGeneric},quantizationVolume:t.quantizationVolume})}};function se(e){return{scenes:oe(e),meshes:re(e),materials:ie(e),textures:ae(e),animations:ce(e)}}function oe(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:ge(s.min),bboxMax:ge(s.max)}})}}function re(t){return{properties:t.getRoot().listMeshes().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length;let o=0,r=0;const i=new Set,a=new Set,c=new Set;t.listPrimitives().forEach(t=>{for(const e of t.listSemantics()){const n=t.getAttribute(e);i.add(e+":"+ue(n.getArray())),c.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(e=>c.add(e));const n=t.getIndices();n&&(a.add(ue(n.getArray())),c.add(n)),r+=t.listAttributes()[0].getCount(),o+=function(t){const n=t.getIndices(),s=t.getAttribute("POSITION");switch(t.getMode()){case e.Mode.POINTS:return s.getCount();case e.Mode.LINES:return n?n.getCount()/2:s.getCount()/2;case e.Mode.LINE_LOOP:return s.getCount();case e.Mode.LINE_STRIP:return s.getCount()-1;case e.Mode.TRIANGLES:return n?n.getCount()/3:s.getCount()/3;case e.Mode.TRIANGLE_STRIP:case e.Mode.TRIANGLE_FAN:return s.getCount()-2;default:throw new Error("Unexpected mode: "+t.getMode())}}(t)});let l=0;Array.from(c).forEach(e=>l+=e.getArray().byteLength);const g=t.listPrimitives().map(e=>le[e.getMode()]);return{name:t.getName(),mode:Array.from(new Set(g)),primitives:t.listPrimitives().length,glPrimitives:o,vertices:r,indices:Array.from(a).sort(),attributes:Array.from(i).sort(),instances:s,size:l}})}}function ie(e){return{properties:e.getRoot().listMaterials().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length,o=new Set(t.listExtensions()),a=e.getGraph().listEdges().filter(e=>{const n=e.getChild(),s=e.getParent();return n instanceof r&&s===t||!!(n instanceof r&&s instanceof i&&o.has(s))}).map(e=>e.getName());return{name:t.getName(),instances:s,textures:a,alphaMode:t.getAlphaMode(),doubleSided:t.getDoubleSided()}})}}function ae(e){return{properties:e.getRoot().listTextures().map(t=>{const s=t.listParents().filter(e=>e.propertyType!==n.ROOT).length,o=e.getGraph().listParentEdges(t).filter(e=>e.getParent().propertyType!==n.ROOT).map(e=>e.getName()),r=a.getSize(t.getImage(),t.getMimeType());return{name:t.getName(),uri:t.getURI(),slots:Array.from(new Set(o)),instances:s,mimeType:t.getMimeType(),resolution:r?r.join("x"):"",size:t.getImage().byteLength,gpuSize:a.getMemSize(t.getImage(),t.getMimeType())}})}}function ce(e){return{properties:e.getRoot().listAnimations().map(e=>{let t=Infinity,n=-Infinity;e.listSamplers().forEach(e=>{const s=e.getInput();s&&(t=Math.min(t,s.getMin([])[0]),n=Math.max(n,s.getMax([])[0]))});let s=0,o=0;const r=new Set;return e.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&(o+=t.getCount(),r.add(t),n&&r.add(n))}),Array.from(r).forEach(e=>{s+=e.getArray().byteLength}),{name:e.getName(),channels:e.listChannels().length,samplers:e.listSamplers().length,duration:Math.round(1e3*(n-t))/1e3,keyframes:o,size:s}})}}const le=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];function ge(e){for(let t=0;t<e.length;t++)e[t].toFixed&&(e[t]=Number(e[t].toFixed(5)));return e}function ue(e){return e.constructor.name.replace("Array","").toLowerCase()}const fe={};function pe(e=fe){return k({},fe,e),B("instance",e=>{const t=e.getLogger(),n=e.getRoot(),s=e.createExtension(T);if(n.listAnimations().length)throw new Error("instance: Instancing is not currently supported for animated models.");let o=0,r=0;for(const i of n.listScenes()){const n=new Map;i.traverse(e=>{const t=e.getMesh();t&&n.set(t,(n.get(t)||new Set).add(e))});const a=[];for(const l of Array.from(n.keys())){const g=Array.from(n.get(l));if(g.length<2)continue;if(g.some(e=>e.getSkin()))continue;const u=de(e,s,l,g.length),f=u.getAttribute("TRANSLATION"),p=u.getAttribute("ROTATION"),m=u.getAttribute("SCALE"),d=e.createNode().setMesh(l).setExtension("EXT_mesh_gpu_instancing",u);i.addChild(d);let h=!1,A=!1,E=!1;for(let e=0;e<g.length;e++){let t,n,s;const o=g[e];f.setElement(e,t=o.getWorldTranslation()),p.setElement(e,n=o.getWorldRotation()),m.setElement(e,s=o.getWorldScale()),c.eq(t,[0,0,0])||(h=!0),c.eq(n,[0,0,0,1])||(A=!0),c.eq(s,[1,1,1])||(E=!0),o.setMesh(null),a.push(o)}h||f.dispose(),A||p.dispose(),E||m.dispose(),me(a,t),o++,r+=g.length}}o>0?t.info(`instance: Created ${o} batches, with ${r} total instances.`):(t.info("instance: No meshes with multiple parent nodes were found."),s.dispose()),t.debug("instance: Complete.")})}function me(e,t){let n,s=0;for(;n=e.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const t=n.getParent();t instanceof l&&e.push(t),n.dispose(),s++}t.debug(`instance: Removed ${s} unused nodes.`)}function de(e,t,n,s){const o=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),r=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o),i=e.createAccessor().setType("VEC4").setArray(new Float32Array(4*s)).setBuffer(o),a=e.createAccessor().setType("VEC3").setArray(new Float32Array(3*s)).setBuffer(o);return t.createInstancedMesh().setAttribute("TRANSLATION",r).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const he={propertyTypes:[n.NODE,n.SKIN,n.MESH,n.CAMERA,n.PRIMITIVE,n.PRIMITIVE_TARGET,n.ANIMATION,n.MATERIAL,n.TEXTURE,n.ACCESSOR,n.BUFFER]},Ae=function(e=he){const t=k({},he,e).propertyTypes;return B("prune",e=>{const s=e.getLogger(),r=e.getRoot(),i=e.getGraph(),a={};if(t.includes(n.NODE)&&r.listNodes().forEach(c),t.includes(n.SKIN)&&r.listSkins().forEach(c),t.includes(n.MESH)&&r.listMeshes().forEach(c),t.includes(n.CAMERA)&&r.listCameras().forEach(c),t.includes(n.PRIMITIVE)&&l(i,n.PRIMITIVE),t.includes(n.PRIMITIVE_TARGET)&&l(i,n.PRIMITIVE_TARGET),t.includes(n.ANIMATION))for(const e of r.listAnimations()){for(const t of e.listChannels())t.getTargetNode()||(t.dispose(),u(t));if(e.listChannels().length)e.listSamplers().forEach(c);else{const t=e.listSamplers();c(e),t.forEach(c)}}if(t.includes(n.MATERIAL)&&r.listMaterials().forEach(c),t.includes(n.TEXTURE)&&r.listTextures().forEach(c),t.includes(n.ACCESSOR)&&r.listAccessors().forEach(c),t.includes(n.BUFFER)&&r.listBuffers().forEach(c),Object.keys(a).length){const e=Object.keys(a).map(e=>`${e} (${a[e]})`).join(", ");s.info(`prune: Removed types... ${e}`)}else s.info("prune: No unused properties found.");function c(e){e.listParents().filter(e=>!(e instanceof o||e instanceof g)).length||(e.dispose(),u(e))}function l(e,t){e.listEdges().map(e=>e.getParent()).filter(e=>e.propertyType===t).forEach(c)}function u(e){a[e.propertyType]=a[e.propertyType]||0,a[e.propertyType]++}s.debug("prune: Complete.")})},Ee={target:"size"};function ye(t){const s=k({},Ee,t),o=s.encoder;if(!o)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return B("reorder",async t=>{const r=t.getLogger();await o.ready;const i=function(e){const t=new U,n=new Map,s=new U;for(const o of e.getRoot().listMeshes())for(const e of o.listPrimitives()){const o=e.getIndices();if(o){n.set(o,e.getMode());for(const n of Se(e))t.add(o,n),s.add(n,e)}}return{indicesToAttributes:t,indicesToMode:n,attributesToPrimitives:s}}(t);for(const t of i.indicesToAttributes.keys()){const n=t.clone();let r=n.getArray().slice();r instanceof Uint32Array||(r=new Uint32Array(r));const[a,c]=o.reorderMesh(r,i.indicesToMode.get(t)===e.Mode.TRIANGLES,"size"===s.target);n.setArray(c<=65534?new Uint16Array(r):r);for(const e of i.indicesToAttributes.get(t)){const s=e.clone();Te(s,a,c);for(const o of i.attributesToPrimitives.get(e))if(o.getIndices()===t&&o.swap(t,n),o.getIndices()===n){o.swap(e,s);for(const t of o.listTargets())t.swap(e,s)}}}await t.transform(Ae({propertyTypes:[n.ACCESSOR]})),i.indicesToAttributes.size?r.debug("reorder: Complete."):r.warn("reorder: No qualifying primitives found; may need to weld first.")})}function Te(e,t,n){const s=e.getElementSize(),o=e.getCount(),r=e.getArray(),i=r.slice(0,n*s);for(let e=0;e<o;e++)for(let n=0;n<s;n++)i[t[e]*s+n]=r[e*s+n];e.setArray(i)}function Se(e){const t=[];for(const n of e.listAttributes())t.push(n);for(const n of e.listTargets())for(const e of n.listAttributes())t.push(e);return Array.from(new Set(t))}const Ie=[Int8Array,Int16Array,Int32Array],{TRANSLATION:be,ROTATION:Me,SCALE:we,WEIGHTS:Re}=g.TargetPath,Ne=[be,Me,we],Oe={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12},Ce=(e=Oe)=>{const t=k({},Oe,e);return B("quantize",async e=>{const s=e.getLogger(),o=e.getRoot();let r;e.createExtension(E).setRequired(!0),"scene"===t.quantizationVolume&&(r=xe(function(e){const t=e[0];for(const n of e)z(t.min,t.min,n.min),L(t.max,t.max,n.max);return t}(o.listMeshes().map(_e))));for(const n of e.getRoot().listMeshes()){"mesh"===t.quantizationVolume&&(r=xe(_e(n))),r&&t.pattern.test("POSITION")&&(ze(e,n,r),Le(n,1/r.scale));for(const s of n.listPrimitives()){Pe(e,s,r,t);for(const n of s.listTargets())Pe(e,n,r,t)}}await e.transform(Ae({propertyTypes:[n.ACCESSOR,n.SKIN,n.MATERIAL]}),K({propertyTypes:[n.ACCESSOR,n.MATERIAL]})),s.debug("quantize: Complete.")})};function Pe(t,n,s,o){const r=t.getLogger();for(const t of n.listSemantics()){if(!o.pattern.test(t))continue;const i=n.getAttribute(t),{bits:a,ctor:c}=qe(t,i,r,o);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=s.scale,o=[];n instanceof e?N(o,ke(s)):C(o,[1/t,1/t,1/t]);for(let e=0,t=[0,0,0],n=l.getCount();e<n;e++)l.getElement(e,t),l.setElement(e,x(t,t,o))}ve(l,c,a),n.swap(i,l)}if(n.getAttribute("WEIGHTS_0")&&function(e){const t=e.getAttribute("POSITION").getCount(),n=[];for(let s=0;s<t;s++){let t,o=0,r=Infinity,i=-1,a=null,c=0;for(;t=e.getAttribute("WEIGHTS_"+c++);){t.getElement(s,n);for(let e=0;e<n.length;e++)o+=n[e],n[e]>0&&n[e]<r&&(a=t,r=n[e],i=e)}a&&1!==o&&(a.getElement(s,n),n[i]+=1-o,a.setElement(s,n))}}(n),n instanceof e&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const e=n.getIndices();e.setArray(new Uint16Array(e.getArray()))}}function xe(e){const{min:t,max:n}=e,s=Math.max((n[0]-t[0])/2,(n[1]-t[1])/2,(n[2]-t[2])/2);return{offset:[t[0]+(n[0]-t[0])/2,t[1]+(n[1]-t[1])/2,t[2]+(n[2]-t[2])/2],scale:s}}function ze(e,t,n){const s=ke(n);for(const o of t.listParents()){if(!(o instanceof l))continue;const r=o.listParents().filter(e=>e instanceof g),i=r.some(e=>Ne.includes(e.getTargetPath())),a=o.listChildren().length>0;if(o.getSkin()){o.setSkin($e(o.getSkin(),n));continue}let c;a||i?(c=e.createNode("").setMesh(t),o.addChild(c).setMesh(null),r.filter(e=>e.getTargetPath()===Re).forEach(e=>e.setTargetNode(c))):c=o;const u=c.getMatrix();P(u,u,s),c.setMatrix(u)}}function $e(e,t){e=e.clone();const n=ke(t),s=e.getInverseBindMatrices().clone(),o=[];for(let e=0,t=s.getCount();e<t;e++)s.getElement(e,o),P(o,o,n),s.setElement(e,o);return e.setInverseBindMatrices(s)}function Le(e,t){for(const n of e.listPrimitives()){let e=n.getMaterial();if(!e)continue;let s=e.getExtension("KHR_materials_volume");!s||s.getThicknessFactor()<=0||(s=s.clone().setThicknessFactor(s.getThicknessFactor()*t),e=e.clone().setExtension("KHR_materials_volume",s),n.setMaterial(e))}}function ve(e,t,n){const s=new t(e.getArray().length),o=Ie.includes(t)?1:0,r=n-o,i=8*t.BYTES_PER_ELEMENT-o,a=Math.pow(2,r)-1,c=i-r,l=2*r-i;for(let t=0,n=0,o=[];t<e.getCount();t++){e.getElement(t,o);for(let e=0;e<o.length;e++){let t=Math.round(Math.abs(o[e])*a);t=t<<c|t>>l,s[n++]=t*Math.sign(o[e])}}e.setArray(s).setNormalized(!0)}function qe(e,t,n,s){const o=t.getMinNormalized([]),r=t.getMaxNormalized([]);let i,a;if("POSITION"===e)i=s.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===e||"TANGENT"===e)i=s.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(e.startsWith("COLOR_"))i=s.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(e.startsWith("TEXCOORD_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=s.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(e.startsWith("JOINTS_"))return i=Math.max(...t.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,t.getComponentSize()>i/8&&t.setArray(new a(t.getArray())),{bits:-1};if(e.startsWith("WEIGHTS_")){if(o.some(e=>e<0)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [0,1] range.`),{bits:-1};i=s.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!e.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${e}".`);if(o.some(e=>e<-1)||r.some(e=>e>1))return n.warn(`quantize: Skipping ${e}; out of [-1,1] range.`),{bits:-1};i=s.quantizeGeneric,a=a=o.some(e=>e<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function _e(e){const t=[],n=[];for(const s of e.listPrimitives()){const e=s.getAttribute("POSITION");e&&t.push(e);for(const e of s.listTargets()){const t=e.getAttribute("POSITION");t&&n.push(t)}}if(0===t.length)throw new Error('quantize: Missing "POSITION" attribute.');const s=Ge(t,3);if(n.length>0){const{min:e,max:t}=Ge(n,3);z(s.min,s.min,z(e,$(e,e,2),[0,0,0])),L(s.max,s.max,L(t,$(t,t,2),[0,0,0]))}return s}function Ge(e,t){const n=new Array(t).fill(Infinity),s=new Array(t).fill(-Infinity),o=[],r=[];for(const i of e){i.getMinNormalized(o),i.getMaxNormalized(r);for(let e=0;e<t;e++)n[e]=Math.min(n[e],o[e]),s[e]=Math.max(s[e],r[e])}return{min:n,max:s}}function ke(e){return O([],[0,0,0,1],e.offset,[e.scale,e.scale,e.scale])}const Be={level:"high"},Fe=e=>{const t=k({},Be,e),n=t.encoder;if(!n)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return async e=>{await e.transform(ye({encoder:n,target:"size"}),Ce({pattern:"medium"===t.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8})),e.createExtension(S).setRequired(!0).setEncoderOptions({method:"medium"===t.level?S.EncoderMethod.QUANTIZE:S.EncoderMethod.FILTER})}},Ue={};function Ve(e=Ue){return k({},Ue,e),B("metalRough",async e=>{const t=e.getLogger();if(!e.getRoot().listExtensionsUsed().map(e=>e.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return void t.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document.");const n=e.createExtension(I),s=e.createExtension(b),o=e.createExtension(M),r=new Set;for(const t of e.getRoot().listMaterials()){const o=t.getExtension("KHR_materials_pbrSpecularGlossiness");if(!o)continue;const i=s.createSpecular().setSpecularFactor(1).setSpecularColorFactor(o.getSpecularFactor());r.add(o.getSpecularGlossinessTexture()),r.add(t.getBaseColorTexture()),r.add(t.getMetallicRoughnessTexture()),t.setBaseColorFactor(o.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",n.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const a=o.getDiffuseTexture();a&&(t.setBaseColorTexture(a),t.getBaseColorTextureInfo().copy(o.getDiffuseTextureInfo()));const c=o.getSpecularGlossinessTexture();if(c){const n=o.getSpecularGlossinessTextureInfo(),s=e.createTexture();await F(c,s,(e,t,n)=>{e.set(t,n,3,255)}),i.setSpecularTexture(s),i.setSpecularColorTexture(s),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const r=o.getGlossinessFactor(),a=e.createTexture();await F(c,a,(e,t,n)=>{const s=255-Math.round(e.get(t,n,3)*r);e.set(t,n,0,0),e.set(t,n,1,s),e.set(t,n,2,0),e.set(t,n,3,255)}),t.setMetallicRoughnessTexture(a),t.getMetallicRoughnessTextureInfo().copy(n)}else i.setSpecularColorFactor(o.getSpecularFactor()),t.setRoughnessFactor(1-o.getGlossinessFactor());t.setExtension("KHR_materials_pbrSpecularGlossiness",null)}o.dispose();for(const e of r)e&&1===e.listParents().length&&e.dispose();t.debug("metalRough: Complete.")})}const We={};function je(e=We){return k({},We,e),B("unweld",e=>{const t=e.getLogger(),n=new Map;for(const s of e.getRoot().listMeshes())for(const e of s.listPrimitives()){const s=e.getIndices();if(s){for(const o of e.listAttributes())e.swap(o,He(o,s,t,n)),1===o.listParents().length&&o.dispose();for(const o of e.listTargets())for(const e of o.listAttributes())o.swap(e,He(e,s,t,n)),1===e.listParents().length&&e.dispose();e.setIndices(null),1===s.listParents().length&&s.dispose()}}t.debug("unweld: Complete.")})}function He(e,t,n,s){if(s.has(e)&&s.get(e).has(t))return n.debug(`unweld: Cache hit for reused attribute, "${e.getName()}".`),s.get(e).get(t);const o=e.clone(),r=e.getArray().constructor;o.setArray(new r(t.getCount()*e.getElementSize()));const i=[];for(let n=0;n<t.getCount();n++)o.setElement(n,e.getElement(t.getScalar(n),i));return s.has(e)||s.set(e,new Map),s.get(e).set(t,o),o}const Xe={overwrite:!1};function De(e=Xe){const t=k({},Xe,e);return B("normals",async e=>{const n=e.getLogger();let s=0;await e.transform(je());for(const o of e.getRoot().listMeshes())for(const r of o.listPrimitives()){const o=r.getAttribute("POSITION");let i=r.getAttribute("NORMAL");if(t.overwrite&&i)i.dispose();else if(i){n.debug("normals: Skipping primitive: NORMAL found.");continue}i=e.createAccessor().setArray(new Float32Array(3*o.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],l=[0,0,0];for(let e=0;e<o.getCount();e+=3){o.getElement(e+0,a),o.getElement(e+1,c),o.getElement(e+2,l);const t=Ke(a,c,l);i.setElement(e+0,t),i.setElement(e+1,t),i.setElement(e+2,t)}r.setAttribute("NORMAL",i),s++}s?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}function Ke(e,t,n){const s=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],o=[n[0]-e[0],n[1]-e[1],n[2]-e[2]];return v([0,0,0],[s[1]*o[2]-s[2]*o[1],s[2]*o[0]-s[0]*o[2],s[0]*o[1]-s[1]*o[0]])}const Ze={animations:!0,meshes:!0},Je=(e=Ze)=>{const t=k({},Ze,e);return B("partition",async e=>{const s=e.getLogger();!1!==t.meshes&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listMeshes().forEach((o,r)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(o.getName()))return void t.debug(`partition: Skipping mesh #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for mesh "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(Qe(o.getName()||"mesh",s));o.listPrimitives().forEach(e=>{const t=e.getIndices();t&&t.setBuffer(i),e.listAttributes().forEach(e=>e.setBuffer(i)),e.listTargets().forEach(e=>{e.listAttributes().forEach(e=>e.setBuffer(i))})})})}(e,s,t),!1!==t.animations&&function(e,t,n){const s=new Set(e.getRoot().listBuffers().map(e=>e.getURI()));e.getRoot().listAnimations().forEach((o,r)=>{if(Array.isArray(n.animations)&&!n.animations.includes(o.getName()))return void t.debug(`partition: Skipping animation #${r} with name "${o.getName()}".`);t.debug(`partition: Creating buffer for animation "${o.getName()}".`);const i=e.createBuffer(o.getName()).setURI(Qe(o.getName()||"animation",s));o.listSamplers().forEach(e=>{const t=e.getInput(),n=e.getOutput();t&&t.setBuffer(i),n&&n.setBuffer(i)})})}(e,s,t),t.meshes||t.animations||s.warn("partition: Select animations or meshes to create a partition."),await e.transform(Ae({propertyTypes:[n.BUFFER]})),s.debug("partition: Complete.")})};function Qe(e,t){let n=`${e}.bin`,s=1;for(;t.has(n);)n=`${e}_${s++}.bin`;return n}const Ye={tolerance:1e-4},et=(e=Ye)=>{const t=k({},Ye,e);return B("resample",(e,n)=>{const s=new Set,r=e.getRoot().listAccessors().length,i=e.getLogger();let a=!1;for(const n of e.getRoot().listAnimations()){const e=new Set;for(const t of n.listChannels())t.getSampler()&&"weights"===t.getTargetPath()&&e.add(t.getSampler());for(const o of n.listSamplers())e.has(o)?a=!0:"STEP"!==o.getInterpolation()&&"LINEAR"!==o.getInterpolation()||(s.add(o.getInput()),s.add(o.getOutput()),tt(o,t))}for(const e of Array.from(s.values()))e.listParents().some(e=>!(e instanceof o))||e.dispose();e.getRoot().listAccessors().length>r&&!function(e,t,n){return!!e&&e.stack.lastIndexOf("resample")<e.stack.lastIndexOf("dedup")}(n)&&i.warn('resample: Resampling required copying accessors, some of which may be duplicates. Consider using "dedup" to consolidate any duplicates.'),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})};function tt(e,t){const n=e.getInput().clone(),s=e.getOutput().clone(),o=t.tolerance,r=n.getCount()-1,i=[];let a=1;for(let t=1;t<r;++t){const r=n.getScalar(t),l=n.getScalar(t-1),g=n.getScalar(t+1),u=(r-l)/(g-l);let f=!1;if(r!==g&&(1!==t||r!==n.getScalar(0)))for(let n=0;n<s.getElementSize();n++){const r=s.getElement(t,i)[n],a=s.getElement(t-1,i)[n],l=s.getElement(t+1,i)[n];if("LINEAR"===e.getInterpolation()){if(Math.abs(r-(a*(1-(c=u))+l*c))>o){f=!0;break}}else if("STEP"===e.getInterpolation()&&(r!==a||r!==l)){f=!0;break}}f&&(t!==a&&(n.setScalar(a,n.getScalar(t)),s.setElement(a,s.getElement(t,i))),a++)}var c;r>0&&(n.setScalar(a,n.getScalar(r)),s.setElement(a,s.getElement(r,i)),a++),a!==n.getCount()?(n.setArray(n.getArray().slice(0,a)),s.setArray(s.getArray().slice(0,a*s.getElementSize())),e.setInput(n),e.setOutput(s)):(n.dispose(),s.dispose())}const nt={name:"",fps:10,pattern:/.*/,sort:!0};function st(e=nt){const t=k({},nt,e);return B("sequence",e=>{const n=e.getLogger(),s=e.getRoot(),o=t.fps,r=s.listNodes().filter(e=>e.getName().match(t.pattern));t.sort&&r.sort((e,t)=>e.getName()>t.getName()?1:-1);const i=e.createAnimation(t.name),a=s.listBuffers()[0];r.forEach((t,n)=>{let s,c;0===n?(s=[n/o,(n+1)/o],c=[1,1,1,0,0,0]):n===r.length-1?(s=[(n-1)/o,n/o],c=[0,0,0,1,1,1]):(s=[(n-1)/o,n/o,(n+1)/o],c=[0,0,0,1,1,1,0,0,0]);const l=e.createAccessor().setArray(new Float32Array(s)).setBuffer(a),p=e.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(u.Type.VEC3),m=e.createAnimationSampler().setInterpolation(f.Interpolation.STEP).setInput(l).setOutput(p),d=e.createAnimationChannel().setTargetNode(t).setTargetPath(g.TargetPath.SCALE).setSampler(m);i.addSampler(m).addChannel(d)}),n.debug("sequence: Complete.")})}function ot(e,t){const n=rt(e,t),s=[];return n&m.R&&s.push(m.R),n&m.G&&s.push(m.G),n&m.B&&s.push(m.B),n&m.A&&s.push(m.A),s}function rt(e,t){let s=0;for(const o of e.getGraph().listParentEdges(t)){const t=o.getParent();let{channels:r}=o.getAttributes();r&&"baseColorTexture"===o.getName()&&t instanceof p&&t.getAlphaMode()===p.AlphaMode.OPAQUE&&(r&=~m.A),r?s|=r:t.propertyType!==n.ROOT&&e.getLogger().warn(`Missing attribute ".channels" on edge, "${o.getName()}".`)}return s}function it(e,t){const n=e.getRoot(),s=e.getGraph().listParentEdges(t).filter(e=>e.getParent()!==n).map(e=>e.getName());return Array.from(new Set(s))}var at;!function(e){e.OXIPNG="oxipng",e.MOZJPEG="mozjpeg",e.WEBP="webp"}(at||(at={}));const ct={[at.OXIPNG]:"image/png",[at.MOZJPEG]:"image/jpeg",[at.WEBP]:"image/webp"},lt={formats:/.*/,slots:/.*/,auto:!1},gt=k({},lt,{codec:at.WEBP}),ut=k({},lt,{codec:at.MOZJPEG,formats:/^image\/jpeg$/}),ft=k({},lt,{codec:at.OXIPNG,formats:/^image\/png$/}),pt=["image/jpeg","image/png","image/webp"];let mt=null,dt=0;const ht=e=>(mt||(mt=new e.ImagePool(require("os").cpus().length)),dt++,mt),At=()=>{dt--,mt&&dt<=0&&(mt.close(),mt=null)},Et=function(e){const t=k({},lt,e),n=t.squoosh,s=t.codec;if(!n)throw new Error(`${s}: squoosh dependency required — install "@squoosh/lib".`);return async e=>{const o=e.getLogger(),r=e.getRoot().listTextures(),i=ht(n);await Promise.all(r.map(async(n,r)=>{const a=it(e,n),c=rt(e,n),l=n.getURI()||n.getName()||`${r+1}/${e.getRoot().listTextures().length}`,g=`${s}:texture(${l})`;if(!pt.includes(n.getMimeType()))return void o.debug(`${g}: Skipping, unsupported texture type "${n.getMimeType()}".`);if(!t.formats.test(n.getMimeType()))return void o.debug(`${g}: Skipping, "${n.getMimeType()}" excluded by "formats" parameter.`);if(a.length&&!a.some(e=>t.slots.test(e)))return void o.debug(`${g}: Skipping, [${a.join(", ")}] excluded by "slots" parameter.`);if(t.codec===at.MOZJPEG&&c&m.A)return void o.warn(`${g}: Skipping, [${a.join(", ")}] requires alpha channel.`);o.debug(`${g}: Slots → [${a.join(", ")}]`);const u=i.ingestImage(n.getImage()),f=n.getImage().byteLength;await u.encode({[t.codec]:t.auto?"auto":{}});const p=await u.encodedWith[t.codec];o.debug(`${g}: ${JSON.stringify(p.optionsUsed)}`),n.setImage(p.binary).setMimeType(ct[t.codec]);const d=p.binary.byteLength;o.debug(`${g}: ${V(f)} → ${V(d)}`)})),At(),o.debug(`${s}: Complete.`)}},yt=function(e){const t=k({},gt,e);return async e=>{await Et(t)(e),e.getRoot().listTextures().some(e=>e.getMimeType()===ct[at.WEBP])&&e.createExtension(w).setRequired(!0)}},Tt=function(e){const t=k({},ut,e);return e=>Et(t)(e)},St=function(e){const t=k({},ft,e);return e=>Et(t)(e)},It={overwrite:!1};function bt(e=It){if(!e.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const t=k({},It,e);return B("tangents",e=>{const n=e.getLogger(),s=new Map,o=new Map;let r=0;for(const i of e.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!wt(l,n,a,i,t.overwrite))continue;const g=Mt(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),p=l.getAttribute(g).getArray(),m=s.get(u)||d();s.set(u,m);const h=s.get(f)||d();s.set(f,h);const A=s.get(p)||d();s.set(p,A);const E=l.getAttribute("TANGENT");E&&2===E.listParents().length&&E.dispose();const y=`${m}|${h}|${A}`;let T=o.get(y);if(T){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",T),r++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),I=t.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p));for(let e=3;e<I.length;e+=4)I[e]*=-1;T=e.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",T),o.set(y,T),r++}}r?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")})}function Mt(e){const t=e.getMaterial();if(!t)return"TEXCOORD_0";const n=t.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const s=`TEXCOORD_${n.getTexCoord()}`;return e.getAttribute(s)?s:"TEXCOORD_0"}function wt(t,n,s,o,r){return t.getMode()===e.Mode.TRIANGLES&&t.getAttribute("POSITION")&&t.getAttribute("NORMAL")&&t.getAttribute("TEXCOORD_0")?t.getAttribute("TANGENT")&&!r?(n.debug(`tangents: Skipping primitive ${o} of mesh "${s}": TANGENT found.`),!1):!t.getIndices()||(n.warn(`tangents: Skipping primitive ${o} of mesh "${s}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${o} of mesh "${s}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const Rt="textureResize";var Nt;!function(e){e.LANCZOS3="lanczos3",e.LANCZOS2="lanczos2"}(Nt||(Nt={}));const Ot={size:[2048,2048],filter:Nt.LANCZOS3,pattern:null};function Ct(e=Ot){const t=k({},Ot,e);return B(Rt,async e=>{const n=e.getLogger();for(const s of e.getRoot().listTextures()){const e=s.getName(),o=s.getURI();if(t.pattern&&!t.pattern.test(e)&&!t.pattern.test(o))continue;if("image/png"!==s.getMimeType()&&"image/jpeg"!==s.getMimeType()){n.warn(`Skipping unsupported texture type, "${s.getMimeType()}".`);continue}const[r,i]=t.size,[a,c]=s.getSize();if(a<=r&&c<=i){n.debug(`${Rt}: Skipping "${o||e}", within size range.`);continue}let l=a,g=c;l>r&&(g=Math.floor(g*(r/l)),l=r),g>i&&(l=Math.floor(l*(i/g)),g=i);const u=s.getImage(),f=await h(u,s.getMimeType()),p=q(new Uint8Array(l*g*4),[l,g,4]);n.debug(`${Rt}: Resizing "${o||e}", ${f.shape} → ${p.shape}...`);try{t.filter===Nt.LANCZOS3?_(f,p):G(f,p)}catch(t){if(t instanceof Error){n.warn(`${Rt}: Failed to resize "${o||e}": "${t.message}".`);continue}throw t}s.setImage(await A(p,s.getMimeType()))}n.debug(`${Rt}: Complete.`)})}const Pt=()=>e=>{const t=e.createExtension(R).createUnlit();e.getRoot().listMaterials().forEach(e=>{e.setExtension("KHR_materials_unlit",t)})},xt={tolerance:1e-4};function zt(t=xt){const n=k({},xt,t);return B("weld",t=>{const s=t.getLogger();for(const s of t.getRoot().listMeshes())for(const o of s.listPrimitives())o.getMode()!==e.Mode.POINTS&&(0===n.tolerance?$t(t,o):Lt(t,o,n));s.debug("weld: Complete.")})}function $t(e,t){if(t.getIndices())return;const n=t.listAttributes()[0],s=n.getCount(),o=n.getBuffer(),r=s<=65534?new Uint16Array(s):new Uint32Array(s),i=e.createAccessor().setBuffer(o).setType(u.Type.SCALAR).setArray(r);for(let e=0;e<i.getCount();e++)i.setScalar(e,e);t.setIndices(i)}function Lt(e,t,n){const s=Math.max(n.tolerance,Number.EPSILON),o=Math.log10(1/s),r=Math.pow(10,o),i={},a=t.getIndices(),c=a?a.getCount():t.listAttributes()[0].getCount(),l=new Map;t.listAttributes().forEach(e=>l.set(e,[])),t.listTargets().forEach(e=>{e.listAttributes().forEach(e=>l.set(e,[]))});const g=[];let u=0;for(let e=0;e<c;e++){const n=a?a.getScalar(e):e,s=[],o=[];for(const e of t.listAttributes())for(let t=0;t<e.getElementSize();t++)s.push(~~(e.getElement(n,o)[t]*r));const c=s.join("|");if(c in i)g.push(i[c]);else{for(const e of t.listAttributes())l.get(e).push(e.getElement(n,[]));for(const e of t.listTargets())for(const t of e.listAttributes())l.get(t).push(t.getElement(n,[]));i[c]=u,g.push(u),u++}}const f=t.listAttributes()[0].getCount(),p=l.get(t.getAttribute("POSITION")).length;e.getLogger().debug(`weld: ${f} → ${p} vertices.`);for(const e of t.listAttributes())qt(t,e,l.get(e)),1===e.listParents().length&&e.dispose();for(const e of t.listTargets())for(const t of e.listAttributes())qt(e,t,l.get(t)),1===t.listParents().length&&t.dispose();if(a){const e=vt(a.getArray(),g.length);e.set(g),t.setIndices(a.clone().setArray(e)),1===a.listParents().length&&a.dispose()}else{const n=f<=65534?new Uint16Array(g):new Uint32Array(g);t.setIndices(e.createAccessor().setArray(n))}}function vt(e,t){return new(0,e.constructor)(t)}function qt(e,t,n){const s=n.length*t.getElementSize(),o=vt(t.getArray(),s),r=t.clone().setArray(o);for(let e=0;e<n.length;e++)r.setElement(e,n[e]);e.swap(t,r)}export{te as DRACO_DEFAULTS,Be as MESHOPT_DEFAULTS,Oe as QUANTIZE_DEFAULTS,Ot as TEXTURE_RESIZE_DEFAULTS,Nt as TextureResizeFilter,j as center,X as colorspace,K as dedup,Q as dequantize,ne as draco,rt as getTextureChannelMask,se as inspect,pe as instance,ot as listTextureChannels,it as listTextureSlots,Fe as meshopt,Ve as metalRough,Tt as mozjpeg,De as normals,St as oxipng,Je as partition,Ae as prune,Ce as quantize,ye as reorder,et as resample,st as sequence,Et as squoosh,bt as tangents,Ct as textureResize,Pt as unlit,je as unweld,yt as webp,zt as weld};
//# sourceMappingURL=functions.modern.js.map
{
"name": "@gltf-transform/functions",
"version": "2.1.2",
"version": "2.1.3",
"repository": "github:donmccurdy/glTF-Transform",

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

"dependencies": {
"@gltf-transform/core": "^2.1.2",
"@gltf-transform/extensions": "^2.1.2",
"@gltf-transform/core": "^2.1.3",
"@gltf-transform/extensions": "^2.1.3",
"gl-matrix": "~3.4.3",

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

},
"gitHead": "025bd91d69789b531226b0a5bffa206ca9ae0711"
"gitHead": "ec6a85af4b588ad07b3482a5b341463329cc5a6d"
}

@@ -8,4 +8,2 @@ import { Document, TextureChannel, Transform } from '@gltf-transform/core';

const NAME = 'squoosh';
enum Codec {

@@ -70,8 +68,10 @@ OXIPNG = 'oxipng',

poolUsers++;
return pool!;
return pool;
};
const releaseImagePool = (): void => {
if (--poolUsers === 0) {
pool!.close(); // Required for process to exit.
poolUsers--;
if (pool && poolUsers <= 0) {
pool.close(); // Required for process to exit.
pool = null;
}

@@ -84,5 +84,6 @@ };

const squoosh = options.squoosh as typeof SquooshLib | null;
const codec = options.codec;
if (!squoosh) {
throw new Error(`${NAME}: squoosh dependency required — install "@squoosh/lib".`);
throw new Error(`${codec}: squoosh dependency required — install "@squoosh/lib".`);
}

@@ -103,3 +104,3 @@

`${textureIndex + 1}/${document.getRoot().listTextures().length}`;
const prefix = `${NAME}:texture(${textureLabel})`;
const prefix = `${codec}:texture(${textureLabel})`;

@@ -144,3 +145,3 @@ // FILTER: Exclude textures that don't match (a) 'slots' or (b) expected formats.

logger.debug(`${NAME}: Complete.`);
logger.debug(`${codec}: Complete.`);
};

@@ -147,0 +148,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc