@gltf-transform/functions
Advanced tools
Comparing version 3.1.6 to 3.1.7
@@ -1,2 +0,2 @@ | ||
import{Primitive as t,PropertyType as e,Document as n,getBounds as o,Scene as r,PrimitiveTarget as s,MathUtils as i,BufferUtils as a,Root as c,AnimationChannel as l,Texture as g,TextureInfo as u,ExtensionProperty as f,ImageUtils as p,ComponentTypeToTypedArray as m,Material as d,TextureChannel as h,Node as A,Accessor as y,AnimationSampler as E,uuid as T}from"@gltf-transform/core";import{getPixels as S,savePixels as I}from"ndarray-pixels";import{KHRMeshQuantization as w,KHRDracoMeshCompression as M,EXTMeshGPUInstancing as N,EXTMeshoptCompression as b,KHRMaterialsIOR as R,KHRMaterialsSpecular as O,KHRMaterialsPBRSpecularGlossiness as C,EXTTextureWebP as v,EXTTextureAVIF as P,KHRMaterialsUnlit as $}from"@gltf-transform/extensions";import{read as x,KHR_DF_MODEL_ETC1S as z,KHR_DF_MODEL_UASTC as L}from"ktx-parse";import _ from"ndarray";import{lanczos3 as q,lanczos2 as k}from"ndarray-lanczos";function G(){return(G=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function F(t,e){return Object.defineProperty(e,"name",{value:t}),e}function B(t,e,n){return!!t&&t.stack.lastIndexOf(e)<t.stack.lastIndexOf(n)}async function U(t,e,n){if(!t)return null;const o=t.getImage();if(!o)return null;const r=await S(o,t.getMimeType());for(let t=0;t<r.shape[0];++t)for(let e=0;e<r.shape[1];++e)n(r,t,e);const s=await I(r,"image/png");return e.setImage(s).setMimeType("image/png")}function W(e){const n=e.getIndices(),o=e.getAttribute("POSITION");switch(e.getMode()){case t.Mode.POINTS:return o.getCount();case t.Mode.LINES:return n?n.getCount()/2:o.getCount()/2;case t.Mode.LINE_LOOP:return o.getCount();case t.Mode.LINE_STRIP:return o.getCount()-1;case t.Mode.TRIANGLES:return n?n.getCount()/3:o.getCount()/3;case t.Mode.TRIANGLE_STRIP:case t.Mode.TRIANGLE_FAN:return o.getCount()-2;default:throw new Error("Unexpected mode: "+e.getMode())}}class H{constructor(){this._map=new Map}get size(){return this._map.size}has(t){return this._map.has(t)}add(t,e){let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}get(t){return this._map.get(t)||new Set}keys(){return this._map.keys()}}function j(t,e=2){if(0===t)return"0 Bytes";const n=e<0?0:e,o=Math.floor(Math.log(t)/Math.log(1e3));return parseFloat((t/Math.pow(1e3,o)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][o]}function D(t){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function V(t,e){return`${D(t)} → ${D(e)} (${function(t,e,n=2){return(t>e?"–":"+")+(Math.abs(t-e)/t*100).toFixed(n)+"%"}(t,e)})`}function X(t){const e=[];for(const n of t.listAttributes())e.push(n);for(const n of t.listTargets())for(const t of n.listAttributes())e.push(t);return Array.from(new Set(e))}function K(t,e,n){t.swap(e,n);for(const o of t.listTargets())o.swap(e,n)}function J(t,e,n){const o=t.getElementSize(),r=t.getCount(),s=t.getArray(),i=s.slice(0,n*o);for(let t=0;t<r;t++)for(let n=0;n<o;n++)i[e[t]*o+n]=s[t*o+n];t.setArray(i)}function Z(t,e=t){const n=e<=65534?new Uint16Array(t):new Uint32Array(t);for(let t=0;t<n.length;t++)n[t]=t;return n}function Q(t){const e=n.fromGraph(t.getGraph()),o=t.getMaterial();return`${e.getRoot().listMaterials().indexOf(o)}|${t.getMode()}|${!!t.getIndices()}|${t.listSemantics().sort().map(e=>{const n=t.getAttribute(e);return`${e}:${n.getElementSize()}:${n.getComponentType()}`}).join("+")}|${t.listTargets().map(e=>e.listSemantics().sort().map(e=>{const n=t.getAttribute(e);return`${e}:${n.getElementSize()}:${n.getComponentType()}`}).join("+")).join("~")}`}const Y={pivot:"center"};function tt(t=Y){const e=G({},Y,t);return F("center",t=>{const n=t.getLogger(),r=t.getRoot(),s=r.listAnimations().length>0||r.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(n.debug(`center: Scene ${a+1} / ${r.listScenes().length}.`),"string"==typeof e.pivot){const t=o(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"===e.pivot&&(c[1]=t.max[1]),"below"===e.pivot&&(c[1]=t.min[1])}else c=e.pivot;n.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(s){n.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(l);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else n.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(t=>{const e=t.getTranslation();t.setTranslation([e[0]+l[0],e[1]+l[1],e[2]+l[2]])})}),n.debug("center: Complete.")})}function et(t){const e=new Set;let n,o=t;for(;n=o.getParentNode();){if(e.has(n))throw new Error("Circular dependency in scene graph.");e.add(n),o=n}return o.listParents().filter(t=>t instanceof r)}function nt(t){const e=et(t),n=t.getParentNode();if(!n)return t;t.setMatrix(t.getWorldMatrix()),n.removeChild(t);for(const n of e)n.addChild(t);return t}var ot="undefined"!=typeof Float32Array?Float32Array:Array;function rt(t,e){var n=e[0],o=e[1],r=e[2],s=e[3],i=e[4],a=e[5],c=e[6],l=e[7],g=e[8],u=e[9],f=e[10],p=e[11],m=e[12],d=e[13],h=e[14],A=e[15],y=n*a-o*i,E=n*c-r*i,T=n*l-s*i,S=o*c-r*a,I=o*l-s*a,w=r*l-s*c,M=g*d-u*m,N=g*h-f*m,b=g*A-p*m,R=u*h-f*d,O=u*A-p*d,C=f*A-p*h,v=y*C-E*O+T*R+S*b-I*N+w*M;return v?(t[0]=(a*C-c*O+l*R)*(v=1/v),t[1]=(r*O-o*C-s*R)*v,t[2]=(d*w-h*I+A*S)*v,t[3]=(f*I-u*w-p*S)*v,t[4]=(c*b-i*C-l*N)*v,t[5]=(n*C-r*b+s*N)*v,t[6]=(h*T-m*w-A*E)*v,t[7]=(g*w-f*T+p*E)*v,t[8]=(i*O-a*b+l*M)*v,t[9]=(o*b-n*O-s*M)*v,t[10]=(m*I-d*T+A*y)*v,t[11]=(u*T-g*I-p*y)*v,t[12]=(a*N-i*R-c*M)*v,t[13]=(n*R-o*N+r*M)*v,t[14]=(d*E-m*S-h*y)*v,t[15]=(g*S-u*E+f*y)*v,t):null}function st(t,e,n){var o=e[0],r=e[1],s=e[2],i=e[3],a=e[4],c=e[5],l=e[6],g=e[7],u=e[8],f=e[9],p=e[10],m=e[11],d=e[12],h=e[13],A=e[14],y=e[15],E=n[0],T=n[1],S=n[2],I=n[3];return t[0]=E*o+T*a+S*u+I*d,t[1]=E*r+T*c+S*f+I*h,t[2]=E*s+T*l+S*p+I*A,t[3]=E*i+T*g+S*m+I*y,t[4]=(E=n[4])*o+(T=n[5])*a+(S=n[6])*u+(I=n[7])*d,t[5]=E*r+T*c+S*f+I*h,t[6]=E*s+T*l+S*p+I*A,t[7]=E*i+T*g+S*m+I*y,t[8]=(E=n[8])*o+(T=n[9])*a+(S=n[10])*u+(I=n[11])*d,t[9]=E*r+T*c+S*f+I*h,t[10]=E*s+T*l+S*p+I*A,t[11]=E*i+T*g+S*m+I*y,t[12]=(E=n[12])*o+(T=n[13])*a+(S=n[14])*u+(I=n[15])*d,t[13]=E*r+T*c+S*f+I*h,t[14]=E*s+T*l+S*p+I*A,t[15]=E*i+T*g+S*m+I*y,t}function it(){var t=new ot(9);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function at(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ct(t,e,n){var o=new ot(3);return o[0]=t,o[1]=e,o[2]=n,o}function lt(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t}function gt(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t}function ut(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function ft(t,e){var n=e[0],o=e[1],r=e[2],s=n*n+o*o+r*r;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function pt(t,e,n){var o=e[0],r=e[1],s=e[2],i=n[3]*o+n[7]*r+n[11]*s+n[15];return t[0]=(n[0]*o+n[4]*r+n[8]*s+n[12])/(i=i||1),t[1]=(n[1]*o+n[5]*r+n[9]*s+n[13])/i,t[2]=(n[2]*o+n[6]*r+n[10]*s+n[14])/i,t}function mt(t,e,n){var o=e[0],r=e[1],s=e[2];return t[0]=o*n[0]+r*n[3]+s*n[6],t[1]=o*n[1]+r*n[4]+s*n[7],t[2]=o*n[2]+r*n[5]+s*n[8],t}function dt(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function ht(t,e,n=new Set){var o;const r=t.getAttribute("POSITION"),s=(null==(o=t.getIndices())?void 0:o.getArray())||Z(r.getCount());r&&At(e,r,s,new Set(n));const i=t.getAttribute("NORMAL");i&&yt(e,i,s,new Set(n));const a=t.getAttribute("TANGENT");a&&Et(e,a,s,new Set(n));for(const o of t.listTargets()){const t=o.getAttribute("POSITION");t&&At(e,t,s,new Set(n));const r=o.getAttribute("NORMAL");r&&yt(e,r,s,new Set(n));const i=o.getAttribute("TANGENT");i&&Et(e,i,s,new Set(n))}for(let t=0;t<s.length;t++)n.add(s[t])}function At(t,e,n,o){const r=new Float32Array(3*e.getCount()),s=e.getElementSize();for(let t=0,n=[],o=e.getCount();t<o;t++)r.set(e.getElement(t,n),t*s);const i=at();for(let s=0;s<n.length;s++){const a=n[s];o.has(a)||(e.getElement(a,i),pt(i,i,t),r.set(i,3*a),o.add(a))}e.setArray(r).setNormalized(!1)}function yt(t,e,n,o){const r=it();var s,i;(s=r)[0]=(i=t)[0],s[1]=i[1],s[2]=i[2],s[3]=i[4],s[4]=i[5],s[5]=i[6],s[6]=i[8],s[7]=i[9],s[8]=i[10],function(t,e){var n=e[0],o=e[1],r=e[2],s=e[3],i=e[4],a=e[5],c=e[6],l=e[7],g=e[8],u=g*i-a*l,f=-g*s+a*c,p=l*s-i*c,m=n*u+o*f+r*p;m&&(t[0]=u*(m=1/m),t[1]=(-g*o+r*l)*m,t[2]=(a*o-r*i)*m,t[3]=f*m,t[4]=(g*n-r*c)*m,t[5]=(-a*n+r*s)*m,t[6]=p*m,t[7]=(-l*n+o*c)*m,t[8]=(i*n-o*s)*m)}(r,r),function(t,e){if(t===e){var n=e[1],o=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=o,t[7]=r}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8]}(r,r);const a=at();for(let t=0;t<n.length;t++){const s=n[t];o.has(s)||(e.getElement(s,a),mt(a,a,r),ft(a,a),e.setElement(s,a),o.add(s))}}function Et(t,e,n,o){const r=at(),s=dt();for(let i=0;i<n.length;i++){const a=n[i];if(o.has(a))continue;e.getElement(a,s);const[c,l,g]=s;r[0]=t[0]*c+t[4]*l+t[8]*g,r[1]=t[1]*c+t[5]*l+t[9]*g,r[2]=t[2]*c+t[6]*l+t[10]*g,ft(r,r),s[0]=r[0],s[1]=r[1],s[2]=r[2],e.setElement(a,s),o.add(a)}}function Tt(n,o,r=!1,i){for(const t of n.listPrimitives())if(t.listParents().some(t=>t.propertyType===e.MESH&&t!==n)){const e=t.clone();n.swap(t,e);for(const t of e.listTargets()){const n=t.clone();e.swap(t,n)}}if(!r){const e=new Set([...n.listPrimitives(),...n.listPrimitives().flatMap(t=>t.listTargets())]),o=new Map;for(const r of n.listPrimitives())for(const n of X(r))n.listParents().some(n=>(n instanceof t||n instanceof s)&&!e.has(n))&&!o.has(n)&&o.set(n,n.clone());for(const t of e)for(const[e,n]of o)t.swap(e,n)}i=i||new Set;for(const t of n.listPrimitives())ht(t,o,i)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),at(),dt();const St=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function It(t){const e=t.getMesh(),n=t.getMatrix();e&&!i.eq(n,St)&&Tt(e,n);for(const e of t.listChildren()){const t=e.getMatrix();st(t,t,n),e.setMatrix(t)}return t.setMatrix(St)}const wt="colorspace";function Mt(t){return F(wt,e=>{const n=e.getLogger();if("linear"===t.inputEncoding)return void n.info(`${wt}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==t.inputEncoding)return void n.error(`${wt}: Unknown input encoding "${t.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const o=new Set;function r(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function s(t){const e=[0,0,0];let n;for(let s=0;n=t.getAttribute(`COLOR_${s}`);s++)if(!o.has(n)){for(let t=0;t<n.getCount();t++)n.getElement(t,e),e[0]=r(e[0]),e[1]=r(e[1]),e[2]=r(e[2]),n.setElement(t,e);o.add(n)}}e.getRoot().listMeshes().forEach(t=>t.listPrimitives().forEach(s)),n.debug(`${wt}: Complete.`)})}const Nt={propertyTypes:[e.ACCESSOR,e.MESH,e.TEXTURE,e.MATERIAL,e.SKIN]},bt=function(t=Nt){const n=G({},Nt,t),o=new Set(n.propertyTypes);for(const t of n.propertyTypes)if(!Nt.propertyTypes.includes(t))throw new Error(`dedup: Unsupported deduplication on type "${t}".`);return F("dedup",t=>{const n=t.getLogger();o.has(e.ACCESSOR)&&function(t){const e=t.getLogger(),n=new Set,o=new Set,r=new Set,s=new Set,i=t.getRoot().listMeshes();i.forEach(t=>{t.listPrimitives().forEach(t=>{t.listAttributes().forEach(t=>o.add(t));const e=t.getIndices();e&&n.add(e)})});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&&s.add(n)}function c(t){const e=new Map;for(let n=0;n<t.length;n++){const o=t[n],r=a.toView(o.getArray());if(!e.has(o))for(let n=0;n<t.length;n++){const s=t[n];o!==s&&(e.has(s)||o.getType()===s.getType()&&o.getComponentType()===s.getComponentType()&&o.getCount()===s.getCount()&&o.getNormalized()===s.getNormalized()&&a.equals(r,a.toView(s.getArray()))&&e.set(s,o))}}return e}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(s));e.debug(`dedup: Found ${u.size+f.size} duplicates among ${r.size+s.size} animation accessors.`),i.forEach(t=>{t.listPrimitives().forEach(t=>{t.listAttributes().forEach(e=>{g.has(e)&&t.swap(e,g.get(e))});const e=t.getIndices();e&&l.has(e)&&t.swap(e,l.get(e))})}),Array.from(l.keys()).forEach(t=>t.dispose()),Array.from(g.keys()).forEach(t=>t.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(t=>t.dispose()),Array.from(f.keys()).forEach(t=>t.dispose())}(t),o.has(e.TEXTURE)&&function(t){const e=t.getLogger(),n=t.getRoot(),o=n.listTextures(),r=new Map;for(let t=0;t<o.length;t++){const e=o[t],n=e.getImage();if(!r.has(e))for(let t=0;t<o.length;t++){const s=o[t],i=s.getImage();if(e===s)continue;if(r.has(s))continue;if(e.getMimeType()!==s.getMimeType())continue;const c=e.getSize(),l=s.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&n&&i&&a.equals(n,i)&&r.set(s,e)}}e.debug(`dedup: Found ${r.size} duplicates among ${n.listTextures().length} textures.`),Array.from(r.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),o.has(e.MATERIAL)&&function(t){const e=t.getLogger(),n=t.getRoot().listMaterials(),o=new Map,r=new Set(["name"]);for(let t=0;t<n.length;t++){const e=n[t];if(!o.has(e))for(let s=t+1;s<n.length;s++){const t=n[s];o.has(t)||e.equals(t,r)&&o.set(t,e)}}e.debug(`dedup: Found ${o.size} duplicates among ${n.length} materials.`),Array.from(o.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),o.has(e.MESH)&&function(t){const n=t.getLogger(),o=t.getRoot(),r=new Map;o.listAccessors().forEach((t,e)=>r.set(t,e)),o.listMaterials().forEach((t,e)=>r.set(t,e));const s=o.listMeshes().length,i=new Map;for(const t of o.listMeshes()){const n=[];for(const e of t.listPrimitives())n.push(Rt(e,r));const o=n.join(";");if(i.has(o)){const n=i.get(o);t.listParents().forEach(o=>{o.propertyType!==e.ROOT&&o.swap(t,n)}),t.dispose()}else i.set(o,t)}n.debug(`dedup: Found ${s-i.size} duplicates among ${s} meshes.`)}(t),o.has(e.SKIN)&&function(t){const e=t.getLogger(),n=t.getRoot().listSkins(),o=new Map,r=new Set(["name"]);for(let t=0;t<n.length;t++){const e=n[t];if(!o.has(e))for(let s=t+1;s<n.length;s++){const t=n[s];o.has(t)||e.equals(t,r)&&o.set(t,e)}}e.debug(`dedup: Found ${o.size} duplicates among ${n.length} skins.`),Array.from(o.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),n.debug("dedup: Complete.")})};function Rt(e,n){const o=[];for(const t of e.listSemantics()){const r=e.getAttribute(t);o.push(t+":"+n.get(r))}if(e instanceof t){const t=e.getIndices();t&&o.push("indices:"+n.get(t));const r=e.getMaterial();r&&o.push("material:"+n.get(r)),o.push("mode:"+e.getMode());for(const t of e.listTargets())o.push("target:"+Rt(t,n))}return o.join(",")}const Ot={pattern:/^((?!JOINTS_).)*$/};function Ct(t=Ot){const e=G({},Ot,t);return F("dequantize",t=>{const n=t.getLogger();for(const n of t.getRoot().listMeshes())for(const t of n.listPrimitives())vt(t,e);t.createExtension(w).dispose(),n.debug("dequantize: Complete.")})}function vt(t,e){for(const n of t.listSemantics())Pt(n,t.getAttribute(n),e);for(const n of t.listTargets())for(const t of n.listSemantics())Pt(t,n.getAttribute(t),e)}function Pt(t,e,n){if(!e.getArray())return;if(!n.pattern.test(t))return;if(e.getComponentSize()>=4)return;const o=e.getArray(),r=new Float32Array(o.length);for(let t=0,n=e.getCount(),s=[];t<n;t++)s=e.getElement(t,s),e.setArray(r).setElement(t,s).setArray(o);e.setArray(r).setNormalized(!1)}const $t={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"},xt=(t=$t)=>{const e=G({},$t,t);return F("draco",t=>{t.createExtension(M).setRequired(!0).setEncoderOptions({method:"edgebreaker"===e.method?M.EncoderMethod.EDGEBREAKER:M.EncoderMethod.SEQUENTIAL,encodeSpeed:e.encodeSpeed,decodeSpeed:e.decodeSpeed,quantizationBits:{POSITION:e.quantizePosition,NORMAL:e.quantizeNormal,COLOR:e.quantizeColor,TEX_COORD:e.quantizeTexcoord,GENERIC:e.quantizeGeneric},quantizationVolume:e.quantizationVolume})})},zt={propertyTypes:[e.NODE,e.SKIN,e.MESH,e.CAMERA,e.PRIMITIVE,e.PRIMITIVE_TARGET,e.ANIMATION,e.MATERIAL,e.TEXTURE,e.ACCESSOR,e.BUFFER],keepLeaves:!1,keepAttributes:!0},Lt=function(t=zt){const n=G({},zt,t),o=new Set(n.propertyTypes);return F("prune",t=>{const s=t.getLogger(),i=t.getRoot(),a=t.getGraph(),g={};if(o.has(e.MESH))for(const t of i.listMeshes())t.listPrimitives().length>0||(t.dispose(),m(t));if(o.has(e.NODE)&&!n.keepLeaves&&i.listScenes().forEach(function t(n){if(n.listChildren().forEach(t),n instanceof r)return;const o=a.listParentEdges(n).some(t=>{const n=t.getParent().propertyType;return n!==e.ROOT&&n!==e.SCENE&&n!==e.NODE});0!==a.listChildren(n).length||o||(n.dispose(),m(n))}),o.has(e.NODE)&&i.listNodes().forEach(u),o.has(e.SKIN)&&i.listSkins().forEach(u),o.has(e.MESH)&&i.listMeshes().forEach(u),o.has(e.CAMERA)&&i.listCameras().forEach(u),o.has(e.PRIMITIVE)&&f(a,e.PRIMITIVE),o.has(e.PRIMITIVE_TARGET)&&f(a,e.PRIMITIVE_TARGET),!n.keepAttributes&&o.has(e.ACCESSOR))for(const e of i.listMeshes())for(const n of e.listPrimitives()){const e=qt(t,n.getMaterial()),o=_t(n,e);p(n,o),n.listTargets().forEach(t=>p(t,o))}if(o.has(e.ANIMATION))for(const t of i.listAnimations()){for(const e of t.listChannels())e.getTargetNode()||(e.dispose(),m(e));if(t.listChannels().length)t.listSamplers().forEach(u);else{const e=t.listSamplers();u(t),e.forEach(u)}}if(o.has(e.MATERIAL)&&i.listMaterials().forEach(u),o.has(e.TEXTURE)&&i.listTextures().forEach(u),o.has(e.ACCESSOR)&&i.listAccessors().forEach(u),o.has(e.BUFFER)&&i.listBuffers().forEach(u),Object.keys(g).length){const t=Object.keys(g).map(t=>`${t} (${g[t]})`).join(", ");s.info(`prune: Removed types... ${t}`)}else s.info("prune: No unused properties found.");function u(t){t.listParents().filter(t=>!(t instanceof c||t instanceof l)).length||(t.dispose(),m(t))}function f(t,e){t.listEdges().map(t=>t.getParent()).filter(t=>t.propertyType===e).forEach(u)}function p(t,e){for(const n of e)t.setAttribute(n,null)}function m(t){g[t.propertyType]=g[t.propertyType]||0,g[t.propertyType]++}s.debug("prune: Complete.")})};function _t(t,e){const n=[];for(const o of t.listSemantics())"TANGENT"!==o||e.has(o)?(o.startsWith("TEXCOORD_")&&!e.has(o)||o.startsWith("COLOR_")&&"COLOR_0"!==o)&&n.push(o):n.push(o);return n}function qt(t,e,n=new Set){if(!e)return n;const o=t.getGraph().listChildEdges(e),r=new Set;for(const t of o)t.getChild()instanceof g&&r.add(t.getName());for(const e of o){const o=e.getName(),s=e.getChild();s instanceof u&&r.has(o.replace(/Info$/,""))&&n.add(`TEXCOORD_${s.getTexCoord()}`),s instanceof g&&o.match(/normalTexture/i)&&n.add("TANGENT"),s instanceof f&&qt(t,s,n)}return n}const kt={};function Gt(t=kt){return G({},kt,t),F("flatten",async t=>{const n=t.getRoot(),o=t.getLogger(),r=new Set;for(const t of n.listSkins())for(const e of t.listJoints())r.add(e);const s=new Set;for(const t of n.listAnimations())for(const e of t.listChannels()){const t=e.getTargetNode();t&&s.add(t)}const i=new Set,a=new Set;for(const t of n.listScenes())t.traverse(t=>{const e=t.getParentNode();e&&((r.has(e)||i.has(e))&&i.add(t),(s.has(e)||a.has(e))&&a.add(t))});for(const t of n.listScenes())t.traverse(t=>{s.has(t)||i.has(t)||a.has(t)||nt(t)});s.size&&o.debug("flatten: Flattening node hierarchies with TRS animation not yet supported."),await t.transform(Lt({propertyTypes:[e.NODE],keepLeaves:!1})),o.debug("flatten: Complete.")})}function Ft(t){return et(t)[0]||null}function Bt(t){return{scenes:Ut(t),meshes:Wt(t),materials:Ht(t),textures:jt(t),animations:Dt(t)}}function Ut(t){return{properties:t.getRoot().listScenes().map(t=>{const e=t.listChildren()[0],n=o(t);return{name:t.getName(),rootName:e?e.getName():"",bboxMin:Kt(n.min),bboxMax:Kt(n.max)}})}}function Wt(t){return{properties:t.getRoot().listMeshes().map(t=>{const n=t.listParents().filter(t=>t.propertyType!==e.ROOT).length;let o=0,r=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+":"+Jt(n)),a.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(t=>a.add(t));const e=t.getIndices();e&&(i.add(Jt(e)),a.add(e)),r+=t.listAttributes()[0].getCount(),o+=W(t)});let c=0;Array.from(a).forEach(t=>c+=t.getArray().byteLength);const l=t.listPrimitives().map(t=>Vt[t.getMode()]);return{name:t.getName(),mode:Array.from(new Set(l)),primitives:t.listPrimitives().length,glPrimitives:o,vertices:r,indices:Array.from(i).sort(),attributes:Array.from(s).sort(),instances:n,size:c}})}}function Ht(t){return{properties:t.getRoot().listMaterials().map(n=>{const o=n.listParents().filter(t=>t.propertyType!==e.ROOT).length,r=new Set(n.listExtensions()),s=t.getGraph().listEdges().filter(t=>{const e=t.getChild(),o=t.getParent();return e instanceof g&&o===n||!!(e instanceof g&&o instanceof f&&r.has(o))}).map(t=>t.getName());return{name:n.getName(),instances:o,textures:s,alphaMode:n.getAlphaMode(),doubleSided:n.getDoubleSided()}})}}function jt(t){return{properties:t.getRoot().listTextures().map(n=>{const o=n.listParents().filter(t=>t.propertyType!==e.ROOT).length,r=t.getGraph().listParentEdges(n).filter(t=>t.getParent().propertyType!==e.ROOT).map(t=>t.getName()),s=p.getSize(n.getImage(),n.getMimeType());let i="";if("image/ktx2"===n.getMimeType()){const t=x(n.getImage()).dataFormatDescriptor[0];t.colorModel===z?i="ETC1S":t.colorModel===L&&(i="UASTC")}return{name:n.getName(),uri:n.getURI(),slots:Array.from(new Set(r)),instances:o,mimeType:n.getMimeType(),compression:i,resolution:s?s.join("x"):"",size:n.getImage().byteLength,gpuSize:p.getVRAMByteLength(n.getImage(),n.getMimeType())}})}}function Dt(t){return{properties:t.getRoot().listAnimations().map(t=>{let e=Infinity,n=-Infinity;t.listSamplers().forEach(t=>{const o=t.getInput();o&&(e=Math.min(e,o.getMin([])[0]),n=Math.max(n,o.getMax([])[0]))});let o=0,r=0;const s=new Set;return t.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&(r+=e.getCount(),s.add(e),n&&s.add(n))}),Array.from(s).forEach(t=>{o+=t.getArray().byteLength}),{name:t.getName(),channels:t.listChannels().length,samplers:t.listSamplers().length,duration:Math.round(1e3*(n-e))/1e3,keyframes:r,size:o}})}}const Vt=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"],Xt={Float32Array:"f32",Uint32Array:"u32",Uint16Array:"u16",Uint8Array:"u8",Int32Array:"i32",Int16Array:"i16",Int8Array:"i8"};function Kt(t){for(let e=0;e<t.length;e++)t[e].toFixed&&(t[e]=Number(t[e].toFixed(5)));return t}function Jt(t){const e=t.getArray();return(Xt[e.constructor.name]||"?")+(t.getNormalized()?"_norm":"")}const Zt={min:2};function Qt(t=Zt){const e=G({},Zt,t);return F("instance",t=>{const n=t.getLogger(),o=t.getRoot(),r=t.createExtension(N);if(o.listAnimations().length)return n.warn("instance: Instancing is not currently supported for animated models."),void n.debug("instance: Complete.");let s=0,a=0;for(const c of o.listScenes()){const o=new Map;c.traverse(t=>{const e=t.getMesh();e&&o.set(e,(o.get(e)||new Set).add(t))});const l=[];for(const g of Array.from(o.keys())){const u=Array.from(o.get(g));if(u.length<e.min)continue;if(u.some(t=>t.getSkin()))continue;const f=te(t,r,g,u.length),p=f.getAttribute("TRANSLATION"),m=f.getAttribute("ROTATION"),d=f.getAttribute("SCALE"),h=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",f);c.addChild(h);let A=!1,y=!1,E=!1;for(let t=0;t<u.length;t++){let e,n,o;const r=u[t];p.setElement(t,e=r.getWorldTranslation()),m.setElement(t,n=r.getWorldRotation()),d.setElement(t,o=r.getWorldScale()),i.eq(e,[0,0,0])||(A=!0),i.eq(n,[0,0,0,1])||(y=!0),i.eq(o,[1,1,1])||(E=!0),r.setMesh(null),l.push(r)}A||p.dispose(),y||m.dispose(),E||d.dispose(),Yt(l,n),s++,a+=u.length}}n.info(s>0?`instance: Created ${s} batches, with ${a} total instances.`:`instance: No meshes with ≥${e.min} parent nodes were found.`),0===r.listProperties().length&&r.dispose(),n.debug("instance: Complete.")})}function Yt(t,e){let n,o=0;for(;n=t.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const e=n.getParentNode();e&&t.push(e),n.dispose(),o++}e.debug(`instance: Removed ${o} unused nodes.`)}function te(t,e,n,o){const r=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),s=t.createAccessor().setType("VEC3").setArray(new Float32Array(3*o)).setBuffer(r),i=t.createAccessor().setType("VEC4").setArray(new Float32Array(4*o)).setBuffer(r),a=t.createAccessor().setType("VEC3").setArray(new Float32Array(3*o)).setBuffer(r);return e.createInstancedMesh().setAttribute("TRANSLATION",s).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const ee={skipValidation:!1};function ne(t,e={}){e=G({},ee,e);const o=t[0],r=n.fromGraph(o.getGraph());if(!e.skipValidation&&new Set(t.map(Q)).size>1)throw new Error("Requires ≥2 Primitives, sharing the same Material and Mode, with compatible vertex attributes and indices.");const s=[],i=[];let a=0,c=0;for(const e of t){const t=oe(e),n=[];for(let e=0;e<t.length;e++){const o=t[e];void 0===n[o]&&(n[o]=a++),c++}s.push(new Uint32Array(n)),i.push(t)}const l=r.createPrimitive().setMode(o.getMode()).setMaterial(o.getMaterial());for(const t of o.listSemantics()){const e=o.getAttribute(t),n=m[e.getComponentType()],s=r.createAccessor().setType(e.getType()).setBuffer(e.getBuffer()).setNormalized(e.getNormalized()).setArray(new n(a*e.getElementSize()));l.setAttribute(t,s)}const g=(o.getIndices()?Z(a):null)&&r.createAccessor().setBuffer(o.getIndices().getBuffer()).setArray(Z(c,a));l.setIndices(g);let u=0;for(let e=0;e<s.length;e++){const n=t[e],o=s[e],r=i[e],a=u;let c=a;for(const t of l.listSemantics()){const e=n.getAttribute(t),s=l.getAttribute(t),i=[];c=a;for(let t=0;t<r.length;t++){const n=r[t];e.getElement(n,i),s.setElement(o[n],i),g&&g.setScalar(c++,o[n])}}u=c}return l}function oe(t){const e=t.getIndices();return e?e.getArray():Z(t.getAttribute("POSITION").getCount())}const{ROOT:re,NODE:se,MESH:ie,PRIMITIVE:ae,ACCESSOR:ce}=e,le=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],ge={keepMeshes:!1,keepNamed:!1};function ue(t=ge){const e=G({},ge,t);return F("join",async t=>{const n=t.getRoot(),o=t.getLogger();for(const o of n.listScenes())fe(t,o,e),o.traverse(n=>fe(t,n,e));await t.transform(Lt({propertyTypes:[se,ie,ae,ce],keepLeaves:!1,keepAttributes:!0})),o.debug("join: Complete.")})}function fe(t,n,o){const r=t.getLogger(),s={},i=n.listChildren();for(let t=0;t<i.length;t++){const e=i[t];if(e.listParents().some(t=>t instanceof l))continue;const n=e.getMesh();if(n&&!e.getExtension("EXT_mesh_gpu_instancing")&&!e.getSkin())for(const r of n.listPrimitives()){if(r.listTargets().length>0)continue;const i=r.getMaterial();if(i&&i.getExtension("KHR_materials_volume"))continue;let a=Q(r);const c=n.getName()||e.getName();(o.keepMeshes||o.keepNamed&&c)&&(a+=`|${t}`),a in s||(s[a]={prims:[],primMeshes:[],primNodes:[],dstNode:e,dstMesh:void 0});const l=s[a];l.prims.push(r),l.primNodes.push(e)}}const a=Object.values(s).filter(({prims:t})=>t.length>1),c=new Set(a.flatMap(t=>t.primNodes));for(const t of c){const e=t.getMesh();e.listParents().some(e=>e.propertyType!==re&&t!==e)&&t.setMesh(e.clone())}for(const t of a){const{dstNode:e,primNodes:n}=t;t.dstMesh=e.getMesh(),t.primMeshes=n.map(t=>t.getMesh())}for(const t of a){const{prims:n,primNodes:o,primMeshes:s,dstNode:i,dstMesh:a}=t,c=i.getMatrix();for(let t=0;t<n.length;t++){const r=o[t];let a=n[t];s[t].removePrimitive(a),(a.listParents().some(t=>t.propertyType!==e.ROOT)||me(a))&&(a=n[t]=pe(n[t])),r!==i&&(st(le,rt(le,c),r.getMatrix()),ht(a,le))}const l=ne(n),g=l.listAttributes()[0].getCount();a.addPrimitive(l),r.debug(`join: Joined Primitives (${n.length}) containing ${D(g)} vertices under Node "${i.getName()}".`)}}function pe(t){const e=t.clone();for(const t of e.listSemantics())e.setAttribute(t,e.getAttribute(t).clone());const n=e.getIndices();return n&&e.setIndices(n.clone()),e}function me(t){for(const e of t.listAttributes())for(const n of e.listParents())if(n!==t&&n.propertyType!==re)return!0;return!1}function de(t){const e=he(t),n=[];return e&h.R&&n.push(h.R),e&h.G&&n.push(h.G),e&h.B&&n.push(h.B),e&h.A&&n.push(h.A),n}function he(t){const o=n.fromGraph(t.getGraph());let r=0;for(const n of o.getGraph().listParentEdges(t)){const t=n.getParent();let{channels:s}=n.getAttributes();s&&"baseColorTexture"===n.getName()&&t instanceof d&&t.getAlphaMode()===d.AlphaMode.OPAQUE&&(s&=~h.A),s?r|=s:t.propertyType!==e.ROOT&&o.getLogger().warn(`Missing attribute ".channels" on edge, "${n.getName()}".`)}return r}function Ae(t){const e=t.getGraph(),n=[];for(const o of e.listParentEdges(t)){const t=o.getParent(),r=o.getName()+"Info";for(const o of e.listChildEdges(t)){const t=o.getChild();t instanceof u&&o.getName()===r&&n.push(t)}}return n}function ye(t){const e=n.fromGraph(t.getGraph()).getRoot(),o=t.getGraph().listParentEdges(t).filter(t=>t.getParent()!==e).map(t=>t.getName());return Array.from(new Set(o))}const Ee={target:"size"};function Te(n){const o=G({},Ee,n),r=o.encoder;if(!r)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return F("reorder",async n=>{const s=n.getLogger();await r.ready;const i=Se(n);for(const e of i.indicesToAttributes.keys()){const n=e.clone();let s=n.getArray().slice();s instanceof Uint32Array||(s=new Uint32Array(s));const[a,c]=r.reorderMesh(s,i.indicesToMode.get(e)===t.Mode.TRIANGLES,"size"===o.target);n.setArray(c<=65534?new Uint16Array(s):s);for(const t of i.indicesToAttributes.get(e)){const o=t.clone();J(o,a,c);for(const r of i.attributesToPrimitives.get(t))if(r.getIndices()===e&&r.swap(e,n),r.getIndices()===n){r.swap(t,o);for(const e of r.listTargets())e.swap(t,o)}}}await n.transform(Lt({propertyTypes:[e.ACCESSOR]})),i.indicesToAttributes.size?s.debug("reorder: Complete."):s.warn("reorder: No qualifying primitives found; may need to weld first.")})}function Se(t){const e=new H,n=new Map,o=new H;for(const r of t.getRoot().listMeshes())for(const t of r.listPrimitives()){const r=t.getIndices();if(r){n.set(r,t.getMode());for(const n of X(t))e.add(r,n),o.add(n,t)}}return{indicesToAttributes:e,indicesToMode:n,attributesToPrimitives:o}}function Ie(t,e=Infinity){if(Number.isFinite(e)&&e%4||e<=0)throw new Error("Limit must be positive multiple of four.");const n=t.getAttribute("POSITION").getCount(),o=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).length,r=new Uint16Array(4*o),s=new Float32Array(4*o),a=new Float32Array(4*o),c=new Uint32Array(4*o),l=new Uint32Array(4*o);for(let e=0;e<n;e++){we(t,e,"WEIGHTS",s),we(t,e,"JOINTS",c);for(let t=0;t<4*o;t++)r[t]=t;r.sort((t,e)=>s[t]>s[e]?-1:1);for(let t=0;t<r.length;t++)a[t]=s[r[t]],l[t]=c[r[t]];Me(t,e,"WEIGHTS",a),Me(t,e,"JOINTS",l)}for(let n=o;4*n>e;n--){const e=t.getAttribute("WEIGHTS_"+(n-1)),o=t.getAttribute("JOINTS_"+(n-1));t.setAttribute("WEIGHTS_"+(n-1),null),t.setAttribute("JOINTS_"+(n-1),null),1===e.listParents().length&&e.dispose(),1===o.listParents().length&&o.dispose()}!function(t){if(!function(t){const e=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).map(e=>t.getAttribute(e)),n=e.map(t=>t.getNormalized()),o=e.map(t=>t.getComponentType());return 1===new Set(n).size&&1===new Set(o).size}(t))return;const e=t.getAttribute("POSITION").getCount(),n=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).length,o=t.getAttribute("WEIGHTS_0"),r=o.getArray(),s=o.getComponentType(),a=o.getNormalized(),c=a?s:void 0,l=a?i.decodeNormalizedInt(1,s):Number.EPSILON,g=new Uint32Array(4*n).fill(0),u=r.slice(0,4*n).fill(0);for(let n=0;n<e;n++){we(t,n,"JOINTS",g),we(t,n,"WEIGHTS",u,c);let e=Ne(u,c);if(0!==e){if(Math.abs(1-e)>l)for(let t=0;t<u.length;t++)if(a){const n=i.encodeNormalizedInt(u[t]/e,s);u[t]=i.decodeNormalizedInt(n,s)}else u[t]/=e;if(e=Ne(u,c),a&&1!==e)for(let t=u.length-1;t>=0;t--)if(u[t]>0){u[t]+=i.encodeNormalizedInt(1-e,s);break}for(let t=u.length-1;t>=0;t--)0===u[t]&&(g[t]=0);Me(t,n,"JOINTS",g),Me(t,n,"WEIGHTS",u,c)}}}(t)}function we(t,e,n,o,r){let s;const a=[0,0,0,0];for(let c=0;s=t.getAttribute(`${n}_${c}`);c++){s.getElement(e,a);for(let t=0;t<4;t++)o[4*c+t]=r?i.encodeNormalizedInt(a[t],r):a[t]}return o}function Me(t,e,n,o,r){let s;const a=[0,0,0,0];for(let c=0;s=t.getAttribute(`${n}_${c}`);c++){for(let t=0;t<4;t++)a[t]=r?i.decodeNormalizedInt(o[4*c+t],r):o[4*c+t];s.setElement(e,a)}}function Ne(t,e){let n=0;for(let o=0;o<t.length;o++)n+=e?i.decodeNormalizedInt(t[o],e):t[o];return n}const be=[Int8Array,Int16Array,Int32Array],{TRANSLATION:Re,ROTATION:Oe,SCALE:Ce,WEIGHTS:ve}=l.TargetPath,Pe=[Re,Oe,Ce],$e={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12,normalizeWeights:!0},xe=(t=$e)=>{const n=G({},$e,t);return F("quantize",async t=>{const o=t.getLogger(),r=t.getRoot();let s;t.createExtension(w).setRequired(!0),"scene"===n.quantizationVolume&&(s=Le(function(t){const e=t[0];for(const n of t)lt(e.min,e.min,n.min),gt(e.max,e.max,n.max);return e}(r.listMeshes().map(Ue))));for(const e of t.getRoot().listMeshes()){"mesh"===n.quantizationVolume&&(s=Le(Ue(e))),s&&n.pattern.test("POSITION")&&(_e(t,e,s),Ge(e,1/s.scale));for(const o of e.listPrimitives()){ze(t,o,s,n);for(const e of o.listTargets())ze(t,e,s,n)}}await t.transform(Lt({propertyTypes:[e.ACCESSOR,e.SKIN,e.MATERIAL]}),bt({propertyTypes:[e.ACCESSOR,e.MATERIAL,e.SKIN]})),o.debug("quantize: Complete.")})};function ze(e,n,o,r){const s=e.getLogger();for(const e of n.listSemantics()){if(!r.pattern.test(e))continue;const c=n.getAttribute(e),{bits:l,ctor:g}=Be(e,c,s,r);if(!g)continue;if(l<8||l>16)throw new Error("quantize: Requires bits = 8–16.");if(c.getComponentSize()<=l/8)continue;const u=c.clone();if("POSITION"===e){const e=o.scale,r=[];n instanceof t?rt(r,He(o)):((i=r)[0]=(a=[1/e,1/e,1/e])[0],i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=a[1],i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=a[2],i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1);for(let t=0,e=[0,0,0],n=u.getCount();t<n;t++)u.getElement(t,e),u.setElement(t,pt(e,e,r))}Fe(u,g,l),n.swap(c,u)}var i,a;if(r.normalizeWeights&&n.getAttribute("WEIGHTS_0")&&Ie(n,Infinity),n instanceof t&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const t=n.getIndices();t.setArray(new Uint16Array(t.getArray()))}}function Le(t){const{min:e,max:n}=t,o=Math.max((n[0]-e[0])/2,(n[1]-e[1])/2,(n[2]-e[2])/2);return{offset:[e[0]+(n[0]-e[0])/2,e[1]+(n[1]-e[1])/2,e[2]+(n[2]-e[2])/2],scale:o}}function _e(t,e,n){const o=He(n);for(const r of e.listParents()){if(!(r instanceof A))continue;const s=r.listParents().filter(t=>t instanceof l),i=s.some(t=>Pe.includes(t.getTargetPath())),a=r.listChildren().length>0,c=r.getSkin();if(c){r.setSkin(qe(c,n));continue}const g=r.getExtension("EXT_mesh_gpu_instancing");if(g){r.setExtension("EXT_mesh_gpu_instancing",ke(g,n));continue}let u;a||i?(u=t.createNode("").setMesh(e),r.addChild(u).setMesh(null),s.filter(t=>t.getTargetPath()===ve).forEach(t=>t.setTargetNode(u))):u=r;const f=u.getMatrix();st(f,f,o),u.setMatrix(f)}}function qe(t,e){t=t.clone();const n=He(e),o=t.getInverseBindMatrices().clone(),r=[];for(let t=0,e=o.getCount();t<e;t++)o.getElement(t,r),st(r,r,n),o.setElement(t,r);return t.setInverseBindMatrices(o)}function ke(t,e){var n,o,r;if(!t.getAttribute("TRANSLATION")&&!t.getAttribute("ROTATION")&&!t.getAttribute("SCALE"))return t;const s=null==(n=(t=t.clone()).getAttribute("TRANSLATION"))?void 0:n.clone(),a=null==(o=t.getAttribute("ROTATION"))?void 0:o.clone(),c=null==(r=t.getAttribute("SCALE"))?void 0:r.clone(),l=s||a||c,g=[0,0,0],u=[0,0,0,1],f=[1,1,1],p=[0,0,0],m=[0,0,0,1],d=[1,1,1],h=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],A=He(e);for(let t=0,e=l.getCount();t<e;t++)i.compose(s?s.getElement(t,p):g,a?a.getElement(t,m):u,c?c.getElement(t,d):f,h),st(h,h,A),i.decompose(h,p,m,d),s&&s.setElement(t,p),a&&a.setElement(t,m),c&&c.setElement(t,d);return s&&t.setAttribute("TRANSLATION",s),a&&t.setAttribute("ROTATION",a),c&&t.setAttribute("SCALE",c),t}function Ge(t,e){for(const n of t.listPrimitives()){let t=n.getMaterial();if(!t)continue;let o=t.getExtension("KHR_materials_volume");!o||o.getThicknessFactor()<=0||(o=o.clone().setThicknessFactor(o.getThicknessFactor()*e),t=t.clone().setExtension("KHR_materials_volume",o),n.setMaterial(t))}}function Fe(t,e,n){const o=new e(t.getArray().length),r=be.includes(e)?1:0,s=n-r,i=8*e.BYTES_PER_ELEMENT-r,a=Math.pow(2,s)-1,c=i-s,l=2*s-i;for(let e=0,n=0,r=[];e<t.getCount();e++){t.getElement(e,r);for(let t=0;t<r.length;t++){let e=Math.round(Math.abs(r[t])*a);e=e<<c|e>>l,o[n++]=e*Math.sign(r[t])}}t.setArray(o).setNormalized(!0).setSparse(!1)}function Be(t,e,n,o){const r=e.getMinNormalized([]),s=e.getMaxNormalized([]);let i,a;if("POSITION"===t)i=o.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===t||"TANGENT"===t)i=o.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(t.startsWith("COLOR_"))i=o.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(t.startsWith("TEXCOORD_")){if(r.some(t=>t<0)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [0,1] range.`),{bits:-1};i=o.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(t.startsWith("JOINTS_"))return i=Math.max(...e.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,e.getComponentSize()>i/8&&e.setArray(new a(e.getArray())),{bits:-1};if(t.startsWith("WEIGHTS_")){if(r.some(t=>t<0)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [0,1] range.`),{bits:-1};i=o.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!t.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${t}".`);if(r.some(t=>t<-1)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [-1,1] range.`),{bits:-1};i=o.quantizeGeneric,a=a=r.some(t=>t<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function Ue(t){const e=[],n=[];for(const o of t.listPrimitives()){const t=o.getAttribute("POSITION");t&&e.push(t);for(const t of o.listTargets()){const e=t.getAttribute("POSITION");e&&n.push(e)}}if(0===e.length)throw new Error('quantize: Missing "POSITION" attribute.');const o=We(e,3);if(n.length>0){const{min:t,max:e}=We(n,3);lt(o.min,o.min,lt(t,ut(t,t,2),[0,0,0])),gt(o.max,o.max,gt(e,ut(e,e,2),[0,0,0]))}return o}function We(t,e){const n=new Array(e).fill(Infinity),o=new Array(e).fill(-Infinity),r=[],s=[];for(const i of t){i.getMinNormalized(r),i.getMaxNormalized(s);for(let t=0;t<e;t++)n[t]=Math.min(n[t],r[t]),o[t]=Math.max(o[t],s[t])}return{min:n,max:o}}function He(t){return o=t.offset,f=(s=(n=[0,0,0,1])[0])*(l=s+s),p=s*(g=(i=n[1])+i),m=s*(u=(a=n[2])+a),h=i*u,y=(c=n[3])*l,E=c*g,T=c*u,I=(r=[t.scale,t.scale,t.scale])[1],w=r[2],(e=[])[0]=(1-((d=i*g)+(A=a*u)))*(S=r[0]),e[1]=(p+T)*S,e[2]=(m-E)*S,e[3]=0,e[4]=(p-T)*I,e[5]=(1-(f+A))*I,e[6]=(h+y)*I,e[7]=0,e[8]=(m+E)*w,e[9]=(h-y)*w,e[10]=(1-(f+d))*w,e[11]=0,e[12]=o[0],e[13]=o[1],e[14]=o[2],e[15]=1,e;var e,n,o,r,s,i,a,c,l,g,u,f,p,m,d,h,A,y,E,T,S,I,w}const je={level:"high"},De=t=>{const e=G({},je,t),n=e.encoder;if(!n)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return F("meshopt",async t=>{await t.transform(Te({encoder:n,target:"size"}),xe({pattern:"medium"===e.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8})),t.createExtension(b).setRequired(!0).setEncoderOptions({method:"medium"===e.level?b.EncoderMethod.QUANTIZE:b.EncoderMethod.FILTER})})},Ve={};function Xe(t=Ve){return G({},Ve,t),F("metalRough",async t=>{const e=t.getLogger();if(!t.getRoot().listExtensionsUsed().map(t=>t.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return void e.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document.");const n=t.createExtension(R),o=t.createExtension(O),r=t.createExtension(C),s=new Set;for(const e of t.getRoot().listMaterials()){const r=e.getExtension("KHR_materials_pbrSpecularGlossiness");if(!r)continue;const i=o.createSpecular().setSpecularFactor(1).setSpecularColorFactor(r.getSpecularFactor());s.add(r.getSpecularGlossinessTexture()),s.add(e.getBaseColorTexture()),s.add(e.getMetallicRoughnessTexture()),e.setBaseColorFactor(r.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",n.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const a=r.getDiffuseTexture();a&&(e.setBaseColorTexture(a),e.getBaseColorTextureInfo().copy(r.getDiffuseTextureInfo()));const c=r.getSpecularGlossinessTexture();if(c){const n=r.getSpecularGlossinessTextureInfo(),o=t.createTexture();await U(c,o,(t,e,n)=>{t.set(e,n,3,255)}),i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const s=r.getGlossinessFactor(),a=t.createTexture();await U(c,a,(t,e,n)=>{const o=255-Math.round(t.get(e,n,3)*s);t.set(e,n,0,0),t.set(e,n,1,o),t.set(e,n,2,0),t.set(e,n,3,255)}),e.setMetallicRoughnessTexture(a),e.getMetallicRoughnessTextureInfo().copy(n)}else i.setSpecularColorFactor(r.getSpecularFactor()),e.setRoughnessFactor(1-r.getGlossinessFactor());e.setExtension("KHR_materials_pbrSpecularGlossiness",null)}r.dispose();for(const t of s)t&&1===t.listParents().length&&t.dispose();e.debug("metalRough: Complete.")})}const Ke={};function Je(t=Ke){return G({},Ke,t),F("unweld",t=>{const e=t.getLogger(),n=new Map;for(const o of t.getRoot().listMeshes())for(const t of o.listPrimitives()){const o=t.getIndices();if(!o)continue;const r=t.getAttribute("POSITION").getCount();for(const r of t.listAttributes())t.swap(r,Ze(r,o,e,n)),1===r.listParents().length&&r.dispose();for(const r of t.listTargets())for(const t of r.listAttributes())r.swap(t,Ze(t,o,e,n)),1===t.listParents().length&&t.dispose();const s=t.getAttribute("POSITION").getCount();e.debug(`unweld: ${V(r,s)} vertices.`),t.setIndices(null),1===o.listParents().length&&o.dispose()}e.debug("unweld: Complete.")})}function Ze(t,e,n,o){if(o.has(t)&&o.get(t).has(e))return n.debug(`unweld: Cache hit for reused attribute, "${t.getName()}".`),o.get(t).get(e);const r=t.clone(),s=t.getArray().constructor;r.setArray(new s(e.getCount()*t.getElementSize()));const i=[];for(let n=0;n<e.getCount();n++)r.setElement(n,t.getElement(e.getScalar(n),i));return o.has(t)||o.set(t,new Map),o.get(t).set(e,r),r}const Qe={overwrite:!1};function Ye(t=Qe){const e=G({},Qe,t);return F("normals",async t=>{const n=t.getLogger();let o=0;await t.transform(Je());for(const r of t.getRoot().listMeshes())for(const s of r.listPrimitives()){const r=s.getAttribute("POSITION");let i=s.getAttribute("NORMAL");if(e.overwrite&&i)i.dispose();else if(i){n.debug("normals: Skipping primitive: NORMAL found.");continue}i=t.createAccessor().setArray(new Float32Array(3*r.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],l=[0,0,0];for(let t=0;t<r.getCount();t+=3){r.getElement(t+0,a),r.getElement(t+1,c),r.getElement(t+2,l);const e=tn(a,c,l);i.setElement(t+0,e),i.setElement(t+1,e),i.setElement(t+2,e)}s.setAttribute("NORMAL",i),o++}o?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}function tn(t,e,n){const o=[e[0]-t[0],e[1]-t[1],e[2]-t[2]],r=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];return ft([0,0,0],[o[1]*r[2]-o[2]*r[1],o[2]*r[0]-o[0]*r[2],o[0]*r[1]-o[1]*r[0]])}const en={animations:!0,meshes:!0},nn=(t=en)=>{const n=G({},en,t);return F("partition",async t=>{const o=t.getLogger();!1!==n.meshes&&function(t,e,n){const o=new Set(t.getRoot().listBuffers().map(t=>t.getURI()));t.getRoot().listMeshes().forEach((r,s)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(r.getName()))return void e.debug(`partition: Skipping mesh #${s} with name "${r.getName()}".`);e.debug(`partition: Creating buffer for mesh "${r.getName()}".`);const i=t.createBuffer(r.getName()).setURI(on(r.getName()||"mesh",o));r.listPrimitives().forEach(t=>{const e=t.getIndices();e&&e.setBuffer(i),t.listAttributes().forEach(t=>t.setBuffer(i)),t.listTargets().forEach(t=>{t.listAttributes().forEach(t=>t.setBuffer(i))})})})}(t,o,n),!1!==n.animations&&function(t,e,n){const o=new Set(t.getRoot().listBuffers().map(t=>t.getURI()));t.getRoot().listAnimations().forEach((r,s)=>{if(Array.isArray(n.animations)&&!n.animations.includes(r.getName()))return void e.debug(`partition: Skipping animation #${s} with name "${r.getName()}".`);e.debug(`partition: Creating buffer for animation "${r.getName()}".`);const i=t.createBuffer(r.getName()).setURI(on(r.getName()||"animation",o));r.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&e.setBuffer(i),n&&n.setBuffer(i)})})}(t,o,n),n.meshes||n.animations||o.warn("partition: Select animations or meshes to create a partition."),await t.transform(Lt({propertyTypes:[e.BUFFER]})),o.debug("partition: Complete.")})};function on(t,e){let n=`${t}.bin`,o=1;for(;e.has(n);)n=`${t}_${o++}.bin`;return n}function rn(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function sn(t,e){var n=cn(t,e);return Math.acos(2*n*n-1)}function an(t,e,n,o){var r,s,i,a,c,l=e[0],g=e[1],u=e[2],f=e[3],p=n[0],m=n[1],d=n[2],h=n[3];return(s=l*p+g*m+u*d+f*h)<0&&(s=-s,p=-p,m=-m,d=-d,h=-h),1-s>1e-6?(r=Math.acos(s),i=Math.sin(r),a=Math.sin((1-o)*r)/i,c=Math.sin(o*r)/i):(a=1-o,c=o),t[0]=a*l+c*p,t[1]=a*g+c*m,t[2]=a*u+c*d,t[3]=a*f+c*h,t}var cn=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]};at(),ct(1,0,0),ct(0,1,0),rn(),rn(),it();const ln={tolerance:1e-4},gn=(t=ln)=>{const n=G({},ln,t);return F("resample",async(t,o)=>{const r=new Set,s=t.getRoot().listAccessors().length,i=t.getLogger();let a=!1;for(const e of t.getRoot().listAnimations()){const t=new Map;for(const n of e.listChannels())t.set(n.getSampler(),n.getTargetPath());for(const o of e.listSamplers())"weights"!==t.get(o)?"STEP"!==o.getInterpolation()&&"LINEAR"!==o.getInterpolation()||(r.add(o.getInput()),r.add(o.getOutput()),un(o,t.get(o),n)):a=!0}for(const t of Array.from(r.values()))t.listParents().some(t=>!(t instanceof c))||t.dispose();t.getRoot().listAccessors().length>s&&!B(o,"resample","dedup")&&await t.transform(bt({propertyTypes:[e.ACCESSOR]})),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})};function un(t,e,n){const o=t.getInput().clone().setSparse(!1),r=t.getOutput().clone().setSparse(!1),s=n.tolerance,a=t.getInterpolation(),c=o.getCount()-1,l=[],g=[],u=[],f=[];let p=1;for(let t=1;t<c;++t){const n=o.getScalar(p-1),c=o.getScalar(t),m=o.getScalar(t+1),d=(c-n)/(m-n);let h=!1;if(c!==m&&(1!==t||c!==o.getScalar(0)))if(r.getElement(p-1,f),r.getElement(t,g),r.getElement(t+1,u),"LINEAR"===a&&"rotation"===e){const t=an(l,f,u,d),e=sn(f,g)+sn(g,u);h=!i.eq(g,t,s)||e+Number.EPSILON>=Math.PI}else if("LINEAR"===a){const t=pn(l,f,u,d);h=!i.eq(g,t,s)}else"STEP"===a&&(h=!i.eq(g,f)||!i.eq(g,u));h&&(t!==p&&(o.setScalar(p,o.getScalar(t)),r.setElement(p,r.getElement(t,l))),p++)}c>0&&(o.setScalar(p,o.getScalar(c)),r.setElement(p,r.getElement(c,l)),p++),p!==o.getCount()?(o.setArray(o.getArray().slice(0,p)),r.setArray(r.getArray().slice(0,p*r.getElementSize())),t.setInput(o),t.setOutput(r)):(o.dispose(),r.dispose())}function fn(t,e,n){return t*(1-n)+e*n}function pn(t,e,n,o){for(let r=0;r<e.length;r++)t[r]=fn(e[r],n[r],o);return t}const mn={name:"",fps:10,pattern:/.*/,sort:!0};function dn(t=mn){const e=G({},mn,t);return F("sequence",t=>{const n=t.getLogger(),o=t.getRoot(),r=e.fps,s=o.listNodes().filter(t=>t.getName().match(e.pattern));e.sort&&s.sort((t,e)=>t.getName()>e.getName()?1:-1);const i=t.createAnimation(e.name),a=o.listBuffers()[0];s.forEach((e,n)=>{let o,c;0===n?(o=[n/r,(n+1)/r],c=[1,1,1,0,0,0]):n===s.length-1?(o=[(n-1)/r,n/r],c=[0,0,0,1,1,1]):(o=[(n-1)/r,n/r,(n+1)/r],c=[0,0,0,1,1,1,0,0,0]);const g=t.createAccessor().setArray(new Float32Array(o)).setBuffer(a),u=t.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(y.Type.VEC3),f=t.createAnimationSampler().setInterpolation(E.Interpolation.STEP).setInput(g).setOutput(u),p=t.createAnimationChannel().setTargetNode(e).setTargetPath(l.TargetPath.SCALE).setSampler(f);i.addSampler(f).addChannel(p)}),n.debug("sequence: Complete.")})}const hn={tolerance:1e-4,overwrite:!0,exhaustive:!0};function An(t=hn){const n=G({},hn,t);if(n.tolerance>.1||n.tolerance<0)throw new Error("weld: Requires 0 ≤ tolerance ≤ 0.1");return F("weld",async t=>{const o=t.getLogger();for(const e of t.getRoot().listMeshes()){for(const o of e.listPrimitives())yn(t,o,n),0===o.getIndices().getCount()&&o.dispose();0===e.listPrimitives().length&&e.dispose()}await t.transform(Lt({propertyTypes:[e.ACCESSOR,e.NODE]})),await t.transform(bt({propertyTypes:[e.ACCESSOR]})),o.debug("weld: Complete.")})}function yn(e,n,o){n.getIndices()&&!o.overwrite||n.getMode()!==t.Mode.POINTS&&(0===o.tolerance?function(t,e){if(e.getIndices())return;const n=e.listAttributes()[0],o=n.getCount(),r=n.getBuffer(),s=t.createAccessor().setBuffer(r).setType(y.Type.SCALAR).setArray(Z(o));e.setIndices(s)}(e,n):function(t,e,n){const o=t.getLogger(),r=e.getAttribute("POSITION"),s=e.getIndices()||t.createAccessor().setArray(Z(r.getCount())),i=new Uint32Array(new Set(s.getArray())).sort(),a=Math.max(n.tolerance,Number.EPSILON),c={};for(const t of e.listSemantics()){const n=e.getAttribute(t);c[t]=In(t,n,a)}var l;o.debug(`weld: Tolerance thresholds: ${l=c,Object.entries(l).map(([t,e])=>`${t}=${e}`).join(", ")}`);const g=[0,0,0],u=[0,0,0],f={},p=c.POSITION;for(let t=0;t<i.length;t++){r.getElement(i[t],g);const e=bn(g,p);f[e]=f[e]||[],f[e].push(i[t])}const m=Z(i.length),d=new Array(i.length).fill(-1),h=r.getCount();let A=0;for(let t=0;t<i.length;t++){const o=i[t];r.getElement(o,g);const s=n.exhaustive?Nn(g,p):[bn(g,p)];t:for(const t of s)if(f[t])e:for(const n of f[t]){const t=m[n];if(o<=t)continue e;r.getElement(t,u);const s=e.listSemantics().every(n=>wn(e.getAttribute(n),o,t,c[n])),i=e.listTargets().every(e=>e.listSemantics().every(n=>wn(e.getAttribute(n),o,t,c[n])));if(s&&i){m[o]=t;break t}}d[o]=m[o]===o?A++:d[m[o]]}o.debug(`weld: ${V(h,A)} vertices.`);const y=s.getCount(),E=Z(y,i.length);for(let t=0;t<y;t++)E[t]=d[s.getScalar(t)];e.setIndices(s.clone().setArray(E)),1===s.listParents().length&&s.dispose();for(const t of e.listAttributes())En(e,t,d,A);for(const t of e.listTargets())for(const e of t.listAttributes())En(t,e,d,A);!function(t){const e=t.getIndices();if(!e)return;const n=[];let o=-Infinity;for(let t=0,r=e.getCount();t<r;t+=3){const r=e.getScalar(t),s=e.getScalar(t+1),i=e.getScalar(t+2);r!==s&&r!==i&&s!==i&&(n.push(r,s,i),o=Math.max(o,r,s,i))}const r=Z(n.length,o);r.set(n),e.setArray(r)}(e)}(e,n,o))}function En(t,e,n,o){const r=(a=e.getArray(),c=o*e.getElementSize(),new(0,a.constructor)(c)),s=e.clone().setArray(r),i=new Uint8Array(o);var a,c;for(let t=0,o=[];t<n.length;t++)i[n[t]]||(s.setElement(n[t],e.getElement(t,o)),i[n[t]]=1);t.swap(e,s),1===e.listParents().length&&e.dispose()}const Tn=[],Sn=[];function In(t,e,n){return"NORMAL"===t||"TANGENT"===t?.5:t.startsWith("COLOR_")?.01:t.startsWith("TEXCOORD_")?1e-4:t.startsWith("JOINTS_")?0:t.startsWith("WEIGHTS_")?.01:(Tn.length=Sn.length=0,e.getMinNormalized(Tn),e.getMaxNormalized(Sn),n*(Math.max(...Sn)-Math.min(...Tn)||1))}function wn(t,e,n,o,r){t.getElement(e,Tn),t.getElement(n,Sn);for(let e=0,n=t.getElementSize();e<n;e++)if(Math.abs(Tn[e]-Sn[e])>o)return!1;return!0}const Mn=[0,-1,1];function Nn(t,e){const n=[],o=[0,0,0];for(const r of Mn)for(const s of Mn)for(const i of Mn)o[0]=t[0]+r*e,o[1]=t[1]+s*e,o[2]=t[2]+i*e,n.push(bn(o,e));return n}function bn(t,e){return Math.round(t[0]/e)+":"+Math.round(t[1]/e)+":"+Math.round(t[2]/e)}const Rn={ratio:.5,error:.001,lockBorder:!1},On=n=>{const o=G({},Rn,n),r=o.simplifier;if(!r)throw new Error('simplify: simplifier dependency required — install "meshoptimizer".');return F("simplify",async(n,s)=>{const i=n.getLogger();await r.ready,await n.transform(An({overwrite:!1}));for(const e of n.getRoot().listMeshes())for(const r of e.listPrimitives())r.getMode()===t.Mode.TRIANGLES?Cn(n,r,o):i.warn(`simplify: Skipping primitive of mesh "${e.getName()}": Requires TRIANGLES draw mode.`);B(s,"simplify","dedup")||await n.transform(bt({propertyTypes:[e.ACCESSOR]})),i.debug("simplify: Complete.")})};function Cn(t,e,n){const o=G({},Rn,n),r=o.simplifier,s=t.getLogger(),i=e.getAttribute("POSITION"),a=e.getIndices(),c=i.getCount();let l=i.getArray(),g=a.getArray();if(i.getComponentType()!==y.ComponentType.FLOAT)if(i.getNormalized()){const t=l,e=new Float32Array(t.length);for(let n=0,o=i.getCount(),r=[];n<o;n++)r=i.getElement(n,r),i.setArray(e).setElement(n,r).setArray(t);l=e}else l=new Float32Array(l);a.getComponentType()!==y.ComponentType.UNSIGNED_INT&&(g=new Uint32Array(g));const u=3*Math.floor(o.ratio*c/3),[f,p]=r.simplify(g,l,3,u,o.error,o.lockBorder?["LockBorder"]:[]),[m,d]=r.compactMesh(f);s.debug(`simplify: ${V(i.getCount(),d)} vertices, error: ${p.toFixed(4)}.`);for(const t of X(e)){const n=t.clone();J(n,m,d),K(e,t,n),1===t.listParents().length&&t.dispose()}const h=a.clone();return h.setArray(c<=65534?new Uint16Array(f):f),e.setIndices(h),1===a.listParents().length&&a.dispose(),e}const vn={ratio:1/3};function Pn(t=vn){const e=G({},vn,t).ratio;if(e<0||e>1)throw new Error("sparse: Ratio must be between 0 and 1.");return F("sparse",t=>{const n=t.getRoot(),o=t.getLogger();let r=0;for(const t of n.listAccessors()){const n=t.getCount(),o=Array(t.getElementSize()).fill(0),s=Array(t.getElementSize()).fill(0);let a=0;for(let r=0;r<n&&(t.getElement(r,s),i.eq(s,o,0)||a++,!(a/n>=e));r++);const c=a/n<e;c!==t.getSparse()&&(t.setSparse(c),r++)}o.debug(`sparse: Updated ${r} accessors.`),o.debug("sparse: Complete.")})}const $n="textureResize";var xn;!function(t){t.LANCZOS3="lanczos3",t.LANCZOS2="lanczos2"}(xn||(xn={}));const zn={size:[2048,2048],filter:xn.LANCZOS3,pattern:null,slots:null};function Ln(t=zn){const e=G({},zn,t);return F($n,async t=>{const n=t.getLogger();for(const o of t.getRoot().listTextures()){const t=o.getName(),r=o.getURI();if(e.pattern&&!e.pattern.test(t)&&!e.pattern.test(r)){n.debug(`${$n}: Skipping, excluded by "pattern" parameter.`);continue}if("image/png"!==o.getMimeType()&&"image/jpeg"!==o.getMimeType()){n.warn(`${$n}: Skipping, unsupported texture type "${o.getMimeType()}".`);continue}const s=ye(o);if(e.slots&&!s.some(t=>{var n;return null==(n=e.slots)?void 0:n.test(t)})){n.debug(`${$n}: Skipping, [${s.join(", ")}] excluded by "slots" parameter.`);continue}const[i,a]=e.size,[c,l]=o.getSize();if(c<=i&&l<=a){n.debug(`${$n}: Skipping, not within size range.`);continue}let g=c,u=l;g>i&&(u=Math.floor(u*(i/g)),g=i),u>a&&(g=Math.floor(g*(a/u)),u=a);const f=o.getImage(),p=await S(f,o.getMimeType()),m=_(new Uint8Array(g*u*4),[g,u,4]);n.debug(`${$n}: Resizing "${r||t}", ${p.shape} → ${m.shape}...`),n.debug(`${$n}: Slots → [${s.join(", ")}]`);try{e.filter===xn.LANCZOS3?q(p,m):k(p,m)}catch(e){if(e instanceof Error){n.warn(`${$n}: Failed to resize "${r||t}": "${e.message}".`);continue}throw e}o.setImage(await I(m,o.getMimeType()))}n.debug(`${$n}: Complete.`)})}const _n="textureCompress",qn=["jpeg","png","webp","avif"],kn=["image/jpeg","image/png","image/webp","image/avif"],Gn={resizeFilter:xn.LANCZOS3,pattern:null,formats:null,slots:null,quality:null,effort:null,lossless:!1,nearLossless:!1},Fn=function(t){const e=G({},Gn,t),n=e.targetFormat,o=e.pattern,r=e.formats,s=e.slots;if(!e.encoder)throw new Error(`${n}: encoder dependency required — install "sharp".`);return F(_n,async t=>{const i=t.getLogger(),a=t.getRoot().listTextures();await Promise.all(a.map(async(a,c)=>{const l=ye(a),g=he(a),u=a.getURI()||a.getName()||`${c+1}/${t.getRoot().listTextures().length}`,f=`${_n}(${u})`;if(!kn.includes(a.getMimeType()))return void i.debug(`${f}: Skipping, unsupported texture type "${a.getMimeType()}".`);if(o&&!o.test(a.getName())&&!o.test(a.getURI()))return void i.debug(`${f}: Skipping, excluded by "pattern" parameter.`);if(r&&!r.test(a.getMimeType()))return void i.debug(`${f}: Skipping, "${a.getMimeType()}" excluded by "formats" parameter.`);if(s&&l.length&&!l.some(t=>s.test(t)))return void i.debug(`${f}: Skipping, [${l.join(", ")}] excluded by "slots" parameter.`);if("jpeg"===e.targetFormat&&g&h.A)return void i.warn(`${f}: Skipping, [${l.join(", ")}] requires alpha channel.`);const p=Un(a);i.debug(`${f}: Format = ${p} → ${n||p}`),i.debug(`${f}: Slots = [${l.join(", ")}]`);const m=a.getImage(),d=m.byteLength;await Bn(a,e);const A=a.getImage(),y=A.byteLength,E=m===A?" (SKIPPED":"";i.debug(`${f}: Size = ${j(d)} → ${j(y)}${E}`)}));const c=t.createExtension(v);a.some(t=>"image/webp"===t.getMimeType())?c.setRequired(!0):c.dispose();const l=t.createExtension(P);a.some(t=>"image/avif"===t.getMimeType())?l.setRequired(!0):l.dispose(),i.debug(`${_n}: Complete.`)})};async function Bn(t,e){const n=G({},Gn,e),o=n.encoder;if(!o)throw new Error(`${n.targetFormat}: encoder dependency required — install "sharp".`);const r=Un(t),s=n.targetFormat||r,i=t.getMimeType(),c=`image/${s}`;let l={};switch(s){case"jpeg":l={quality:n.quality};break;case"png":l={quality:n.quality,effort:Wn(n.effort,100,10)};break;case"webp":l={quality:n.quality,effort:Wn(n.effort,100,6),lossless:n.lossless,nearLossless:n.nearLossless};break;case"avif":l={quality:n.quality,effort:Wn(n.effort,100,9),lossless:n.lossless}}const g=t.getImage(),u=o(g).toFormat(s,l);n.resize&&u.resize(n.resize[0],n.resize[1],{fit:"inside",kernel:n.resizeFilter,withoutEnlargement:!0});const f=a.toView(await u.toBuffer());if(!(i===c&&f.byteLength>=g.byteLength))if(i===c)t.setImage(f);else{const e=p.mimeTypeToExtension(i),n=p.mimeTypeToExtension(c),o=t.getURI().replace(new RegExp(`\\.${e}$`),`.${n}`);t.setImage(f).setMimeType(c).setURI(o)}}function Un(t){const e=t.getMimeType(),n=e.split("/").pop();if(!n||!qn.includes(n))throw new Error(`Unknown MIME type "${e}".`);return n}function Wn(t,e,n){return null==t?null:Math.round(t/e*n)}const Hn={overwrite:!1};function jn(t=Hn){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const e=G({},Hn,t);return F("tangents",t=>{const n=t.getLogger(),o=new Map,r=new Map;let s=0;for(const i of t.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!Vn(l,n,a,i,e.overwrite))continue;const g=Dn(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),p=l.getAttribute(g).getArray(),m=o.get(u)||T();o.set(u,m);const d=o.get(f)||T();o.set(f,d);const h=o.get(p)||T();o.set(p,h);const A=l.getAttribute("TANGENT");A&&2===A.listParents().length&&A.dispose();const y=`${m}|${d}|${h}`;let E=r.get(y);if(E){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",E),s++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),I=e.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p));for(let t=3;t<I.length;t+=4)I[t]*=-1;E=t.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",E),r.set(y,E),s++}}s?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")})}function Dn(t){const e=t.getMaterial();if(!e)return"TEXCOORD_0";const n=e.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const o=`TEXCOORD_${n.getTexCoord()}`;return t.getAttribute(o)?o:"TEXCOORD_0"}function Vn(e,n,o,r,s){return e.getMode()===t.Mode.TRIANGLES&&e.getAttribute("POSITION")&&e.getAttribute("NORMAL")&&e.getAttribute("TEXCOORD_0")?e.getAttribute("TANGENT")&&!s?(n.debug(`tangents: Skipping primitive ${r} of mesh "${o}": TANGENT found.`),!1):!e.getIndices()||(n.warn(`tangents: Skipping primitive ${r} of mesh "${o}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${r} of mesh "${o}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const Xn=()=>t=>{const e=t.createExtension($).createUnlit();t.getRoot().listMaterials().forEach(t=>{t.setExtension("KHR_materials_unlit",e)})},Kn={},Jn=(t=Kn)=>(G({},Kn,t),F("unpartition",async t=>{const e=t.getLogger(),n=t.getRoot().listBuffers()[0];t.getRoot().listAccessors().forEach(t=>t.setBuffer(n)),t.getRoot().listBuffers().forEach((t,e)=>e>0?t.dispose():null),e.debug("unpartition: Complete.")}));export{$t as DRACO_DEFAULTS,kt as FLATTEN_DEFAULTS,ge as JOIN_DEFAULTS,je as MESHOPT_DEFAULTS,$e as QUANTIZE_DEFAULTS,Rn as SIMPLIFY_DEFAULTS,Gn as TEXTURE_COMPRESS_DEFAULTS,zn as TEXTURE_RESIZE_DEFAULTS,xn as TextureResizeFilter,hn as WELD_DEFAULTS,tt as center,nt as clearNodeParent,It as clearNodeTransform,Mt as colorspace,Bn as compressTexture,Se as createLayoutPlan,F as createTransform,bt as dedup,Ct as dequantize,xt as draco,Gt as flatten,W as getGLPrimitiveCount,Ft as getNodeScene,he as getTextureChannelMask,Bt as inspect,Qt as instance,B as isTransformPending,ue as join,ne as joinPrimitives,et as listNodeScenes,de as listTextureChannels,Ae as listTextureInfo,ye as listTextureSlots,De as meshopt,Xe as metalRough,Ye as normals,nn as partition,Lt as prune,xe as quantize,Te as reorder,gn as resample,dn as sequence,On as simplify,Cn as simplifyPrimitive,Ie as sortPrimitiveWeights,Pn as sparse,jn as tangents,Fn as textureCompress,Ln as textureResize,Tt as transformMesh,ht as transformPrimitive,Xn as unlit,Jn as unpartition,Je as unweld,An as weld,yn as weldPrimitive}; | ||
import{Primitive as t,PropertyType as e,Document as n,getBounds as o,Scene as r,PrimitiveTarget as s,MathUtils as i,BufferUtils as a,Root as c,AnimationChannel as l,Texture as g,TextureInfo as u,ExtensionProperty as f,ImageUtils as p,ComponentTypeToTypedArray as m,Material as d,TextureChannel as h,Node as A,Accessor as y,AnimationSampler as E,uuid as T}from"@gltf-transform/core";import{getPixels as S,savePixels as I}from"ndarray-pixels";import{KHRMeshQuantization as w,KHRDracoMeshCompression as M,EXTMeshGPUInstancing as N,EXTMeshoptCompression as b,KHRMaterialsIOR as R,KHRMaterialsSpecular as O,KHRMaterialsPBRSpecularGlossiness as C,EXTTextureWebP as v,EXTTextureAVIF as P,KHRMaterialsUnlit as $}from"@gltf-transform/extensions";import{read as x,KHR_DF_MODEL_ETC1S as z,KHR_DF_MODEL_UASTC as L}from"ktx-parse";import _ from"ndarray";import{lanczos3 as q,lanczos2 as k}from"ndarray-lanczos";function G(){return(G=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function F(t,e){return Object.defineProperty(e,"name",{value:t}),e}function B(t,e,n){return!!t&&t.stack.lastIndexOf(e)<t.stack.lastIndexOf(n)}async function U(t,e,n){if(!t)return null;const o=t.getImage();if(!o)return null;const r=await S(o,t.getMimeType());for(let t=0;t<r.shape[0];++t)for(let e=0;e<r.shape[1];++e)n(r,t,e);const s=await I(r,"image/png");return e.setImage(s).setMimeType("image/png")}function W(e){const n=e.getIndices(),o=e.getAttribute("POSITION");switch(e.getMode()){case t.Mode.POINTS:return o.getCount();case t.Mode.LINES:return n?n.getCount()/2:o.getCount()/2;case t.Mode.LINE_LOOP:return o.getCount();case t.Mode.LINE_STRIP:return o.getCount()-1;case t.Mode.TRIANGLES:return n?n.getCount()/3:o.getCount()/3;case t.Mode.TRIANGLE_STRIP:case t.Mode.TRIANGLE_FAN:return o.getCount()-2;default:throw new Error("Unexpected mode: "+e.getMode())}}class H{constructor(){this._map=new Map}get size(){return this._map.size}has(t){return this._map.has(t)}add(t,e){let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}get(t){return this._map.get(t)||new Set}keys(){return this._map.keys()}}function j(t,e=2){if(0===t)return"0 Bytes";const n=e<0?0:e,o=Math.floor(Math.log(t)/Math.log(1e3));return parseFloat((t/Math.pow(1e3,o)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][o]}function D(t){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function V(t,e){return`${D(t)} → ${D(e)} (${function(t,e,n=2){return(t>e?"–":"+")+(Math.abs(t-e)/t*100).toFixed(n)+"%"}(t,e)})`}function X(t){const e=[];for(const n of t.listAttributes())e.push(n);for(const n of t.listTargets())for(const t of n.listAttributes())e.push(t);return Array.from(new Set(e))}function K(t,e,n){t.swap(e,n);for(const o of t.listTargets())o.swap(e,n)}function J(t,e,n){const o=t.getElementSize(),r=t.getCount(),s=t.getArray(),i=s.slice(0,n*o);for(let t=0;t<r;t++)for(let n=0;n<o;n++)i[e[t]*o+n]=s[t*o+n];t.setArray(i)}function Z(t,e=t){const n=e<=65534?new Uint16Array(t):new Uint32Array(t);for(let t=0;t<n.length;t++)n[t]=t;return n}function Q(t){const e=n.fromGraph(t.getGraph()),o=t.getMaterial();return`${e.getRoot().listMaterials().indexOf(o)}|${t.getMode()}|${!!t.getIndices()}|${t.listSemantics().sort().map(e=>{const n=t.getAttribute(e);return`${e}:${n.getElementSize()}:${n.getComponentType()}`}).join("+")}|${t.listTargets().map(e=>e.listSemantics().sort().map(e=>{const n=t.getAttribute(e);return`${e}:${n.getElementSize()}:${n.getComponentType()}`}).join("+")).join("~")}`}const Y={pivot:"center"};function tt(t=Y){const e=G({},Y,t);return F("center",t=>{const n=t.getLogger(),r=t.getRoot(),s=r.listAnimations().length>0||r.listSkins().length>0;t.getRoot().listScenes().forEach((i,a)=>{let c;if(n.debug(`center: Scene ${a+1} / ${r.listScenes().length}.`),"string"==typeof e.pivot){const t=o(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"===e.pivot&&(c[1]=t.max[1]),"below"===e.pivot&&(c[1]=t.min[1])}else c=e.pivot;n.debug(`center: Pivot "${c.join(", ")}".`);const l=[-1*c[0],-1*c[1],-1*c[2]];if(s){n.debug("center: Model contains animation or skin. Adding a wrapper node.");const e=t.createNode("Pivot").setTranslation(l);i.listChildren().forEach(t=>e.addChild(t)),i.addChild(e)}else n.debug("center: Skipping wrapper, offsetting all root nodes."),i.listChildren().forEach(t=>{const e=t.getTranslation();t.setTranslation([e[0]+l[0],e[1]+l[1],e[2]+l[2]])})}),n.debug("center: Complete.")})}function et(t){const e=new Set;let n,o=t;for(;n=o.getParentNode();){if(e.has(n))throw new Error("Circular dependency in scene graph.");e.add(n),o=n}return o.listParents().filter(t=>t instanceof r)}function nt(t){const e=et(t),n=t.getParentNode();if(!n)return t;t.setMatrix(t.getWorldMatrix()),n.removeChild(t);for(const n of e)n.addChild(t);return t}var ot="undefined"!=typeof Float32Array?Float32Array:Array;function rt(t,e){var n=e[0],o=e[1],r=e[2],s=e[3],i=e[4],a=e[5],c=e[6],l=e[7],g=e[8],u=e[9],f=e[10],p=e[11],m=e[12],d=e[13],h=e[14],A=e[15],y=n*a-o*i,E=n*c-r*i,T=n*l-s*i,S=o*c-r*a,I=o*l-s*a,w=r*l-s*c,M=g*d-u*m,N=g*h-f*m,b=g*A-p*m,R=u*h-f*d,O=u*A-p*d,C=f*A-p*h,v=y*C-E*O+T*R+S*b-I*N+w*M;return v?(t[0]=(a*C-c*O+l*R)*(v=1/v),t[1]=(r*O-o*C-s*R)*v,t[2]=(d*w-h*I+A*S)*v,t[3]=(f*I-u*w-p*S)*v,t[4]=(c*b-i*C-l*N)*v,t[5]=(n*C-r*b+s*N)*v,t[6]=(h*T-m*w-A*E)*v,t[7]=(g*w-f*T+p*E)*v,t[8]=(i*O-a*b+l*M)*v,t[9]=(o*b-n*O-s*M)*v,t[10]=(m*I-d*T+A*y)*v,t[11]=(u*T-g*I-p*y)*v,t[12]=(a*N-i*R-c*M)*v,t[13]=(n*R-o*N+r*M)*v,t[14]=(d*E-m*S-h*y)*v,t[15]=(g*S-u*E+f*y)*v,t):null}function st(t,e,n){var o=e[0],r=e[1],s=e[2],i=e[3],a=e[4],c=e[5],l=e[6],g=e[7],u=e[8],f=e[9],p=e[10],m=e[11],d=e[12],h=e[13],A=e[14],y=e[15],E=n[0],T=n[1],S=n[2],I=n[3];return t[0]=E*o+T*a+S*u+I*d,t[1]=E*r+T*c+S*f+I*h,t[2]=E*s+T*l+S*p+I*A,t[3]=E*i+T*g+S*m+I*y,t[4]=(E=n[4])*o+(T=n[5])*a+(S=n[6])*u+(I=n[7])*d,t[5]=E*r+T*c+S*f+I*h,t[6]=E*s+T*l+S*p+I*A,t[7]=E*i+T*g+S*m+I*y,t[8]=(E=n[8])*o+(T=n[9])*a+(S=n[10])*u+(I=n[11])*d,t[9]=E*r+T*c+S*f+I*h,t[10]=E*s+T*l+S*p+I*A,t[11]=E*i+T*g+S*m+I*y,t[12]=(E=n[12])*o+(T=n[13])*a+(S=n[14])*u+(I=n[15])*d,t[13]=E*r+T*c+S*f+I*h,t[14]=E*s+T*l+S*p+I*A,t[15]=E*i+T*g+S*m+I*y,t}function it(){var t=new ot(9);return ot!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function at(){var t=new ot(3);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ct(t,e,n){var o=new ot(3);return o[0]=t,o[1]=e,o[2]=n,o}function lt(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t}function gt(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t}function ut(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function ft(t,e){var n=e[0],o=e[1],r=e[2],s=n*n+o*o+r*r;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function pt(t,e,n){var o=e[0],r=e[1],s=e[2],i=n[3]*o+n[7]*r+n[11]*s+n[15];return t[0]=(n[0]*o+n[4]*r+n[8]*s+n[12])/(i=i||1),t[1]=(n[1]*o+n[5]*r+n[9]*s+n[13])/i,t[2]=(n[2]*o+n[6]*r+n[10]*s+n[14])/i,t}function mt(t,e,n){var o=e[0],r=e[1],s=e[2];return t[0]=o*n[0]+r*n[3]+s*n[6],t[1]=o*n[1]+r*n[4]+s*n[7],t[2]=o*n[2]+r*n[5]+s*n[8],t}function dt(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function ht(t,e,n=new Set){var o;const r=t.getAttribute("POSITION"),s=(null==(o=t.getIndices())?void 0:o.getArray())||Z(r.getCount());r&&At(e,r,s,new Set(n));const i=t.getAttribute("NORMAL");i&&yt(e,i,s,new Set(n));const a=t.getAttribute("TANGENT");a&&Et(e,a,s,new Set(n));for(const o of t.listTargets()){const t=o.getAttribute("POSITION");t&&At(e,t,s,new Set(n));const r=o.getAttribute("NORMAL");r&&yt(e,r,s,new Set(n));const i=o.getAttribute("TANGENT");i&&Et(e,i,s,new Set(n))}for(let t=0;t<s.length;t++)n.add(s[t])}function At(t,e,n,o){const r=new Float32Array(3*e.getCount()),s=e.getElementSize();for(let t=0,n=[],o=e.getCount();t<o;t++)r.set(e.getElement(t,n),t*s);const i=at();for(let s=0;s<n.length;s++){const a=n[s];o.has(a)||(e.getElement(a,i),pt(i,i,t),r.set(i,3*a),o.add(a))}e.setArray(r).setNormalized(!1)}function yt(t,e,n,o){const r=it();var s,i;(s=r)[0]=(i=t)[0],s[1]=i[1],s[2]=i[2],s[3]=i[4],s[4]=i[5],s[5]=i[6],s[6]=i[8],s[7]=i[9],s[8]=i[10],function(t,e){var n=e[0],o=e[1],r=e[2],s=e[3],i=e[4],a=e[5],c=e[6],l=e[7],g=e[8],u=g*i-a*l,f=-g*s+a*c,p=l*s-i*c,m=n*u+o*f+r*p;m&&(t[0]=u*(m=1/m),t[1]=(-g*o+r*l)*m,t[2]=(a*o-r*i)*m,t[3]=f*m,t[4]=(g*n-r*c)*m,t[5]=(-a*n+r*s)*m,t[6]=p*m,t[7]=(-l*n+o*c)*m,t[8]=(i*n-o*s)*m)}(r,r),function(t,e){if(t===e){var n=e[1],o=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=o,t[7]=r}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8]}(r,r);const a=at();for(let t=0;t<n.length;t++){const s=n[t];o.has(s)||(e.getElement(s,a),mt(a,a,r),ft(a,a),e.setElement(s,a),o.add(s))}}function Et(t,e,n,o){const r=at(),s=dt();for(let i=0;i<n.length;i++){const a=n[i];if(o.has(a))continue;e.getElement(a,s);const[c,l,g]=s;r[0]=t[0]*c+t[4]*l+t[8]*g,r[1]=t[1]*c+t[5]*l+t[9]*g,r[2]=t[2]*c+t[6]*l+t[10]*g,ft(r,r),s[0]=r[0],s[1]=r[1],s[2]=r[2],e.setElement(a,s),o.add(a)}}function Tt(n,o,r=!1,i){for(const t of n.listPrimitives())if(t.listParents().some(t=>t.propertyType===e.MESH&&t!==n)){const e=t.clone();n.swap(t,e);for(const t of e.listTargets()){const n=t.clone();e.swap(t,n)}}if(!r){const e=new Set([...n.listPrimitives(),...n.listPrimitives().flatMap(t=>t.listTargets())]),o=new Map;for(const r of n.listPrimitives())for(const n of X(r))n.listParents().some(n=>(n instanceof t||n instanceof s)&&!e.has(n))&&!o.has(n)&&o.set(n,n.clone());for(const t of e)for(const[e,n]of o)t.swap(e,n)}i=i||new Set;for(const t of n.listPrimitives())ht(t,o,i)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),at(),dt();const St=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function It(t){const e=t.getMesh(),n=t.getMatrix();e&&!i.eq(n,St)&&Tt(e,n);for(const e of t.listChildren()){const t=e.getMatrix();st(t,t,n),e.setMatrix(t)}return t.setMatrix(St)}const wt="colorspace";function Mt(t){return F(wt,e=>{const n=e.getLogger();if("linear"===t.inputEncoding)return void n.info(`${wt}: Vertex colors already linear. Skipping conversion.`);if("sRGB"!==t.inputEncoding)return void n.error(`${wt}: Unknown input encoding "${t.inputEncoding}" – should be "sRGB" or "linear". Skipping conversion.`);const o=new Set;function r(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function s(t){const e=[0,0,0];let n;for(let s=0;n=t.getAttribute(`COLOR_${s}`);s++)if(!o.has(n)){for(let t=0;t<n.getCount();t++)n.getElement(t,e),e[0]=r(e[0]),e[1]=r(e[1]),e[2]=r(e[2]),n.setElement(t,e);o.add(n)}}e.getRoot().listMeshes().forEach(t=>t.listPrimitives().forEach(s)),n.debug(`${wt}: Complete.`)})}const Nt={propertyTypes:[e.ACCESSOR,e.MESH,e.TEXTURE,e.MATERIAL,e.SKIN]},bt=function(t=Nt){const n=G({},Nt,t),o=new Set(n.propertyTypes);for(const t of n.propertyTypes)if(!Nt.propertyTypes.includes(t))throw new Error(`dedup: Unsupported deduplication on type "${t}".`);return F("dedup",t=>{const n=t.getLogger();o.has(e.ACCESSOR)&&function(t){const e=t.getLogger(),n=new Set,o=new Set,r=new Set,s=new Set,i=t.getRoot().listMeshes();i.forEach(t=>{t.listPrimitives().forEach(t=>{t.listAttributes().forEach(t=>o.add(t));const e=t.getIndices();e&&n.add(e)})});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&&s.add(n)}function c(t){const e=new Map;for(let n=0;n<t.length;n++){const o=t[n],r=a.toView(o.getArray());if(!e.has(o))for(let s=n+1;s<t.length;s++){const n=t[s];e.has(n)||o.getType()===n.getType()&&o.getComponentType()===n.getComponentType()&&o.getCount()===n.getCount()&&o.getNormalized()===n.getNormalized()&&a.equals(r,a.toView(n.getArray()))&&e.set(n,o)}}return e}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(s));e.debug(`dedup: Found ${u.size+f.size} duplicates among ${r.size+s.size} animation accessors.`),i.forEach(t=>{t.listPrimitives().forEach(t=>{t.listAttributes().forEach(e=>{g.has(e)&&t.swap(e,g.get(e))});const e=t.getIndices();e&&l.has(e)&&t.swap(e,l.get(e))})}),Array.from(l.keys()).forEach(t=>t.dispose()),Array.from(g.keys()).forEach(t=>t.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(t=>t.dispose()),Array.from(f.keys()).forEach(t=>t.dispose())}(t),o.has(e.TEXTURE)&&function(t){const e=t.getLogger(),n=t.getRoot(),o=n.listTextures(),r=new Map;for(let t=0;t<o.length;t++){const e=o[t],n=e.getImage();if(!r.has(e))for(let s=t+1;s<o.length;s++){const t=o[s],i=t.getImage();if(r.has(t))continue;if(e.getMimeType()!==t.getMimeType())continue;const c=e.getSize(),l=t.getSize();c&&l&&c[0]===l[0]&&c[1]===l[1]&&n&&i&&a.equals(n,i)&&r.set(t,e)}}e.debug(`dedup: Found ${r.size} duplicates among ${n.listTextures().length} textures.`),Array.from(r.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),o.has(e.MATERIAL)&&function(t){const e=t.getLogger(),n=t.getRoot().listMaterials(),o=new Map,r=new Set(["name"]);for(let t=0;t<n.length;t++){const e=n[t];if(!o.has(e))for(let s=t+1;s<n.length;s++){const t=n[s];o.has(t)||e.equals(t,r)&&o.set(t,e)}}e.debug(`dedup: Found ${o.size} duplicates among ${n.length} materials.`),Array.from(o.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),o.has(e.MESH)&&function(t){const n=t.getLogger(),o=t.getRoot(),r=new Map;o.listAccessors().forEach((t,e)=>r.set(t,e)),o.listMaterials().forEach((t,e)=>r.set(t,e));const s=o.listMeshes().length,i=new Map;for(const t of o.listMeshes()){const n=[];for(const e of t.listPrimitives())n.push(Rt(e,r));const o=n.join(";");if(i.has(o)){const n=i.get(o);t.listParents().forEach(o=>{o.propertyType!==e.ROOT&&o.swap(t,n)}),t.dispose()}else i.set(o,t)}n.debug(`dedup: Found ${s-i.size} duplicates among ${s} meshes.`)}(t),o.has(e.SKIN)&&function(t){const e=t.getLogger(),n=t.getRoot().listSkins(),o=new Map,r=new Set(["name"]);for(let t=0;t<n.length;t++){const e=n[t];if(!o.has(e))for(let s=t+1;s<n.length;s++){const t=n[s];o.has(t)||e.equals(t,r)&&o.set(t,e)}}e.debug(`dedup: Found ${o.size} duplicates among ${n.length} skins.`),Array.from(o.entries()).forEach(([t,e])=>{t.listParents().forEach(n=>{n instanceof c||n.swap(t,e)}),t.dispose()})}(t),n.debug("dedup: Complete.")})};function Rt(e,n){const o=[];for(const t of e.listSemantics()){const r=e.getAttribute(t);o.push(t+":"+n.get(r))}if(e instanceof t){const t=e.getIndices();t&&o.push("indices:"+n.get(t));const r=e.getMaterial();r&&o.push("material:"+n.get(r)),o.push("mode:"+e.getMode());for(const t of e.listTargets())o.push("target:"+Rt(t,n))}return o.join(",")}const Ot={pattern:/^((?!JOINTS_).)*$/};function Ct(t=Ot){const e=G({},Ot,t);return F("dequantize",t=>{const n=t.getLogger();for(const n of t.getRoot().listMeshes())for(const t of n.listPrimitives())vt(t,e);t.createExtension(w).dispose(),n.debug("dequantize: Complete.")})}function vt(t,e){for(const n of t.listSemantics())Pt(n,t.getAttribute(n),e);for(const n of t.listTargets())for(const t of n.listSemantics())Pt(t,n.getAttribute(t),e)}function Pt(t,e,n){if(!e.getArray())return;if(!n.pattern.test(t))return;if(e.getComponentSize()>=4)return;const o=e.getArray(),r=new Float32Array(o.length);for(let t=0,n=e.getCount(),s=[];t<n;t++)s=e.getElement(t,s),e.setArray(r).setElement(t,s).setArray(o);e.setArray(r).setNormalized(!1)}const $t={method:"edgebreaker",encodeSpeed:5,decodeSpeed:5,quantizePosition:14,quantizeNormal:10,quantizeColor:8,quantizeTexcoord:12,quantizeGeneric:12,quantizationVolume:"mesh"},xt=(t=$t)=>{const e=G({},$t,t);return F("draco",t=>{t.createExtension(M).setRequired(!0).setEncoderOptions({method:"edgebreaker"===e.method?M.EncoderMethod.EDGEBREAKER:M.EncoderMethod.SEQUENTIAL,encodeSpeed:e.encodeSpeed,decodeSpeed:e.decodeSpeed,quantizationBits:{POSITION:e.quantizePosition,NORMAL:e.quantizeNormal,COLOR:e.quantizeColor,TEX_COORD:e.quantizeTexcoord,GENERIC:e.quantizeGeneric},quantizationVolume:e.quantizationVolume})})},zt={propertyTypes:[e.NODE,e.SKIN,e.MESH,e.CAMERA,e.PRIMITIVE,e.PRIMITIVE_TARGET,e.ANIMATION,e.MATERIAL,e.TEXTURE,e.ACCESSOR,e.BUFFER],keepLeaves:!1,keepAttributes:!0},Lt=function(t=zt){const n=G({},zt,t),o=new Set(n.propertyTypes);return F("prune",t=>{const s=t.getLogger(),i=t.getRoot(),a=t.getGraph(),g={};if(o.has(e.MESH))for(const t of i.listMeshes())t.listPrimitives().length>0||(t.dispose(),m(t));if(o.has(e.NODE)&&!n.keepLeaves&&i.listScenes().forEach(function t(n){if(n.listChildren().forEach(t),n instanceof r)return;const o=a.listParentEdges(n).some(t=>{const n=t.getParent().propertyType;return n!==e.ROOT&&n!==e.SCENE&&n!==e.NODE});0!==a.listChildren(n).length||o||(n.dispose(),m(n))}),o.has(e.NODE)&&i.listNodes().forEach(u),o.has(e.SKIN)&&i.listSkins().forEach(u),o.has(e.MESH)&&i.listMeshes().forEach(u),o.has(e.CAMERA)&&i.listCameras().forEach(u),o.has(e.PRIMITIVE)&&f(a,e.PRIMITIVE),o.has(e.PRIMITIVE_TARGET)&&f(a,e.PRIMITIVE_TARGET),!n.keepAttributes&&o.has(e.ACCESSOR))for(const e of i.listMeshes())for(const n of e.listPrimitives()){const e=qt(t,n.getMaterial()),o=_t(n,e);p(n,o),n.listTargets().forEach(t=>p(t,o))}if(o.has(e.ANIMATION))for(const t of i.listAnimations()){for(const e of t.listChannels())e.getTargetNode()||(e.dispose(),m(e));if(t.listChannels().length)t.listSamplers().forEach(u);else{const e=t.listSamplers();u(t),e.forEach(u)}}if(o.has(e.MATERIAL)&&i.listMaterials().forEach(u),o.has(e.TEXTURE)&&i.listTextures().forEach(u),o.has(e.ACCESSOR)&&i.listAccessors().forEach(u),o.has(e.BUFFER)&&i.listBuffers().forEach(u),Object.keys(g).length){const t=Object.keys(g).map(t=>`${t} (${g[t]})`).join(", ");s.info(`prune: Removed types... ${t}`)}else s.info("prune: No unused properties found.");function u(t){t.listParents().filter(t=>!(t instanceof c||t instanceof l)).length||(t.dispose(),m(t))}function f(t,e){t.listEdges().map(t=>t.getParent()).filter(t=>t.propertyType===e).forEach(u)}function p(t,e){for(const n of e)t.setAttribute(n,null)}function m(t){g[t.propertyType]=g[t.propertyType]||0,g[t.propertyType]++}s.debug("prune: Complete.")})};function _t(t,e){const n=[];for(const o of t.listSemantics())"TANGENT"!==o||e.has(o)?(o.startsWith("TEXCOORD_")&&!e.has(o)||o.startsWith("COLOR_")&&"COLOR_0"!==o)&&n.push(o):n.push(o);return n}function qt(t,e,n=new Set){if(!e)return n;const o=t.getGraph().listChildEdges(e),r=new Set;for(const t of o)t.getChild()instanceof g&&r.add(t.getName());for(const e of o){const o=e.getName(),s=e.getChild();s instanceof u&&r.has(o.replace(/Info$/,""))&&n.add(`TEXCOORD_${s.getTexCoord()}`),s instanceof g&&o.match(/normalTexture/i)&&n.add("TANGENT"),s instanceof f&&qt(t,s,n)}return n}const kt={};function Gt(t=kt){return G({},kt,t),F("flatten",async t=>{const n=t.getRoot(),o=t.getLogger(),r=new Set;for(const t of n.listSkins())for(const e of t.listJoints())r.add(e);const s=new Set;for(const t of n.listAnimations())for(const e of t.listChannels()){const t=e.getTargetNode();t&&s.add(t)}const i=new Set,a=new Set;for(const t of n.listScenes())t.traverse(t=>{const e=t.getParentNode();e&&((r.has(e)||i.has(e))&&i.add(t),(s.has(e)||a.has(e))&&a.add(t))});for(const t of n.listScenes())t.traverse(t=>{s.has(t)||i.has(t)||a.has(t)||nt(t)});s.size&&o.debug("flatten: Flattening node hierarchies with TRS animation not yet supported."),await t.transform(Lt({propertyTypes:[e.NODE],keepLeaves:!1})),o.debug("flatten: Complete.")})}function Ft(t){return et(t)[0]||null}function Bt(t){return{scenes:Ut(t),meshes:Wt(t),materials:Ht(t),textures:jt(t),animations:Dt(t)}}function Ut(t){return{properties:t.getRoot().listScenes().map(t=>{const e=t.listChildren()[0],n=o(t);return{name:t.getName(),rootName:e?e.getName():"",bboxMin:Kt(n.min),bboxMax:Kt(n.max)}})}}function Wt(t){return{properties:t.getRoot().listMeshes().map(t=>{const n=t.listParents().filter(t=>t.propertyType!==e.ROOT).length;let o=0,r=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+":"+Jt(n)),a.add(n)}for(const e of t.listTargets())e.listAttributes().forEach(t=>a.add(t));const e=t.getIndices();e&&(i.add(Jt(e)),a.add(e)),r+=t.listAttributes()[0].getCount(),o+=W(t)});let c=0;Array.from(a).forEach(t=>c+=t.getArray().byteLength);const l=t.listPrimitives().map(t=>Vt[t.getMode()]);return{name:t.getName(),mode:Array.from(new Set(l)),primitives:t.listPrimitives().length,glPrimitives:o,vertices:r,indices:Array.from(i).sort(),attributes:Array.from(s).sort(),instances:n,size:c}})}}function Ht(t){return{properties:t.getRoot().listMaterials().map(n=>{const o=n.listParents().filter(t=>t.propertyType!==e.ROOT).length,r=new Set(n.listExtensions()),s=t.getGraph().listEdges().filter(t=>{const e=t.getChild(),o=t.getParent();return e instanceof g&&o===n||!!(e instanceof g&&o instanceof f&&r.has(o))}).map(t=>t.getName());return{name:n.getName(),instances:o,textures:s,alphaMode:n.getAlphaMode(),doubleSided:n.getDoubleSided()}})}}function jt(t){return{properties:t.getRoot().listTextures().map(n=>{const o=n.listParents().filter(t=>t.propertyType!==e.ROOT).length,r=t.getGraph().listParentEdges(n).filter(t=>t.getParent().propertyType!==e.ROOT).map(t=>t.getName()),s=p.getSize(n.getImage(),n.getMimeType());let i="";if("image/ktx2"===n.getMimeType()){const t=x(n.getImage()).dataFormatDescriptor[0];t.colorModel===z?i="ETC1S":t.colorModel===L&&(i="UASTC")}return{name:n.getName(),uri:n.getURI(),slots:Array.from(new Set(r)),instances:o,mimeType:n.getMimeType(),compression:i,resolution:s?s.join("x"):"",size:n.getImage().byteLength,gpuSize:p.getVRAMByteLength(n.getImage(),n.getMimeType())}})}}function Dt(t){return{properties:t.getRoot().listAnimations().map(t=>{let e=Infinity,n=-Infinity;t.listSamplers().forEach(t=>{const o=t.getInput();o&&(e=Math.min(e,o.getMin([])[0]),n=Math.max(n,o.getMax([])[0]))});let o=0,r=0;const s=new Set;return t.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&(r+=e.getCount(),s.add(e),n&&s.add(n))}),Array.from(s).forEach(t=>{o+=t.getArray().byteLength}),{name:t.getName(),channels:t.listChannels().length,samplers:t.listSamplers().length,duration:Math.round(1e3*(n-e))/1e3,keyframes:r,size:o}})}}const Vt=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"],Xt={Float32Array:"f32",Uint32Array:"u32",Uint16Array:"u16",Uint8Array:"u8",Int32Array:"i32",Int16Array:"i16",Int8Array:"i8"};function Kt(t){for(let e=0;e<t.length;e++)t[e].toFixed&&(t[e]=Number(t[e].toFixed(5)));return t}function Jt(t){const e=t.getArray();return(Xt[e.constructor.name]||"?")+(t.getNormalized()?"_norm":"")}const Zt={min:2};function Qt(t=Zt){const e=G({},Zt,t);return F("instance",t=>{const n=t.getLogger(),o=t.getRoot(),r=t.createExtension(N);if(o.listAnimations().length)return n.warn("instance: Instancing is not currently supported for animated models."),void n.debug("instance: Complete.");let s=0,a=0;for(const c of o.listScenes()){const o=new Map;c.traverse(t=>{const e=t.getMesh();e&&o.set(e,(o.get(e)||new Set).add(t))});const l=[];for(const g of Array.from(o.keys())){const u=Array.from(o.get(g));if(u.length<e.min)continue;if(u.some(t=>t.getSkin()))continue;const f=te(t,r,g,u.length),p=f.getAttribute("TRANSLATION"),m=f.getAttribute("ROTATION"),d=f.getAttribute("SCALE"),h=t.createNode().setMesh(g).setExtension("EXT_mesh_gpu_instancing",f);c.addChild(h);let A=!1,y=!1,E=!1;for(let t=0;t<u.length;t++){let e,n,o;const r=u[t];p.setElement(t,e=r.getWorldTranslation()),m.setElement(t,n=r.getWorldRotation()),d.setElement(t,o=r.getWorldScale()),i.eq(e,[0,0,0])||(A=!0),i.eq(n,[0,0,0,1])||(y=!0),i.eq(o,[1,1,1])||(E=!0),r.setMesh(null),l.push(r)}A||p.dispose(),y||m.dispose(),E||d.dispose(),Yt(l,n),s++,a+=u.length}}n.info(s>0?`instance: Created ${s} batches, with ${a} total instances.`:`instance: No meshes with ≥${e.min} parent nodes were found.`),0===r.listProperties().length&&r.dispose(),n.debug("instance: Complete.")})}function Yt(t,e){let n,o=0;for(;n=t.pop();){if(n.listChildren().length||n.getCamera()||n.getMesh()||n.getSkin()||n.listExtensions().length)continue;const e=n.getParentNode();e&&t.push(e),n.dispose(),o++}e.debug(`instance: Removed ${o} unused nodes.`)}function te(t,e,n,o){const r=n.listPrimitives()[0].getAttribute("POSITION").getBuffer(),s=t.createAccessor().setType("VEC3").setArray(new Float32Array(3*o)).setBuffer(r),i=t.createAccessor().setType("VEC4").setArray(new Float32Array(4*o)).setBuffer(r),a=t.createAccessor().setType("VEC3").setArray(new Float32Array(3*o)).setBuffer(r);return e.createInstancedMesh().setAttribute("TRANSLATION",s).setAttribute("ROTATION",i).setAttribute("SCALE",a)}const ee={skipValidation:!1};function ne(t,e={}){e=G({},ee,e);const o=t[0],r=n.fromGraph(o.getGraph());if(!e.skipValidation&&new Set(t.map(Q)).size>1)throw new Error("Requires ≥2 Primitives, sharing the same Material and Mode, with compatible vertex attributes and indices.");const s=[],i=[];let a=0,c=0;for(const e of t){const t=oe(e),n=[];for(let e=0;e<t.length;e++){const o=t[e];void 0===n[o]&&(n[o]=a++),c++}s.push(new Uint32Array(n)),i.push(t)}const l=r.createPrimitive().setMode(o.getMode()).setMaterial(o.getMaterial());for(const t of o.listSemantics()){const e=o.getAttribute(t),n=m[e.getComponentType()],s=r.createAccessor().setType(e.getType()).setBuffer(e.getBuffer()).setNormalized(e.getNormalized()).setArray(new n(a*e.getElementSize()));l.setAttribute(t,s)}const g=(o.getIndices()?Z(a):null)&&r.createAccessor().setBuffer(o.getIndices().getBuffer()).setArray(Z(c,a));l.setIndices(g);let u=0;for(let e=0;e<s.length;e++){const n=t[e],o=s[e],r=i[e],a=u;let c=a;for(const t of l.listSemantics()){const e=n.getAttribute(t),s=l.getAttribute(t),i=[];c=a;for(let t=0;t<r.length;t++){const n=r[t];e.getElement(n,i),s.setElement(o[n],i),g&&g.setScalar(c++,o[n])}}u=c}return l}function oe(t){const e=t.getIndices();return e?e.getArray():Z(t.getAttribute("POSITION").getCount())}const{ROOT:re,NODE:se,MESH:ie,PRIMITIVE:ae,ACCESSOR:ce}=e,le=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],ge={keepMeshes:!1,keepNamed:!1};function ue(t=ge){const e=G({},ge,t);return F("join",async t=>{const n=t.getRoot(),o=t.getLogger();for(const o of n.listScenes())fe(t,o,e),o.traverse(n=>fe(t,n,e));await t.transform(Lt({propertyTypes:[se,ie,ae,ce],keepLeaves:!1,keepAttributes:!0})),o.debug("join: Complete.")})}function fe(t,n,o){const r=t.getLogger(),s={},i=n.listChildren();for(let t=0;t<i.length;t++){const e=i[t];if(e.listParents().some(t=>t instanceof l))continue;const n=e.getMesh();if(n&&!e.getExtension("EXT_mesh_gpu_instancing")&&!e.getSkin())for(const r of n.listPrimitives()){if(r.listTargets().length>0)continue;const i=r.getMaterial();if(i&&i.getExtension("KHR_materials_volume"))continue;let a=Q(r);const c=n.getName()||e.getName();(o.keepMeshes||o.keepNamed&&c)&&(a+=`|${t}`),a in s||(s[a]={prims:[],primMeshes:[],primNodes:[],dstNode:e,dstMesh:void 0});const l=s[a];l.prims.push(r),l.primNodes.push(e)}}const a=Object.values(s).filter(({prims:t})=>t.length>1),c=new Set(a.flatMap(t=>t.primNodes));for(const t of c){const e=t.getMesh();e.listParents().some(e=>e.propertyType!==re&&t!==e)&&t.setMesh(e.clone())}for(const t of a){const{dstNode:e,primNodes:n}=t;t.dstMesh=e.getMesh(),t.primMeshes=n.map(t=>t.getMesh())}for(const t of a){const{prims:n,primNodes:o,primMeshes:s,dstNode:i,dstMesh:a}=t,c=i.getMatrix();for(let t=0;t<n.length;t++){const r=o[t];let a=n[t];s[t].removePrimitive(a),(a.listParents().some(t=>t.propertyType!==e.ROOT)||me(a))&&(a=n[t]=pe(n[t])),r!==i&&(st(le,rt(le,c),r.getMatrix()),ht(a,le))}const l=ne(n),g=l.listAttributes()[0].getCount();a.addPrimitive(l),r.debug(`join: Joined Primitives (${n.length}) containing ${D(g)} vertices under Node "${i.getName()}".`)}}function pe(t){const e=t.clone();for(const t of e.listSemantics())e.setAttribute(t,e.getAttribute(t).clone());const n=e.getIndices();return n&&e.setIndices(n.clone()),e}function me(t){for(const e of t.listAttributes())for(const n of e.listParents())if(n!==t&&n.propertyType!==re)return!0;return!1}function de(t){const e=he(t),n=[];return e&h.R&&n.push(h.R),e&h.G&&n.push(h.G),e&h.B&&n.push(h.B),e&h.A&&n.push(h.A),n}function he(t){const o=n.fromGraph(t.getGraph());let r=0;for(const n of o.getGraph().listParentEdges(t)){const t=n.getParent();let{channels:s}=n.getAttributes();s&&"baseColorTexture"===n.getName()&&t instanceof d&&t.getAlphaMode()===d.AlphaMode.OPAQUE&&(s&=~h.A),s?r|=s:t.propertyType!==e.ROOT&&o.getLogger().warn(`Missing attribute ".channels" on edge, "${n.getName()}".`)}return r}function Ae(t){const e=t.getGraph(),n=[];for(const o of e.listParentEdges(t)){const t=o.getParent(),r=o.getName()+"Info";for(const o of e.listChildEdges(t)){const t=o.getChild();t instanceof u&&o.getName()===r&&n.push(t)}}return n}function ye(t){const e=n.fromGraph(t.getGraph()).getRoot(),o=t.getGraph().listParentEdges(t).filter(t=>t.getParent()!==e).map(t=>t.getName());return Array.from(new Set(o))}const Ee={target:"size"};function Te(n){const o=G({},Ee,n),r=o.encoder;if(!r)throw new Error('reorder: encoder dependency required — install "meshoptimizer".');return F("reorder",async n=>{const s=n.getLogger();await r.ready;const i=Se(n);for(const e of i.indicesToAttributes.keys()){const n=e.clone();let s=n.getArray().slice();s instanceof Uint32Array||(s=new Uint32Array(s));const[a,c]=r.reorderMesh(s,i.indicesToMode.get(e)===t.Mode.TRIANGLES,"size"===o.target);n.setArray(c<=65534?new Uint16Array(s):s);for(const t of i.indicesToAttributes.get(e)){const o=t.clone();J(o,a,c);for(const r of i.attributesToPrimitives.get(t))if(r.getIndices()===e&&r.swap(e,n),r.getIndices()===n){r.swap(t,o);for(const e of r.listTargets())e.swap(t,o)}}}await n.transform(Lt({propertyTypes:[e.ACCESSOR]})),i.indicesToAttributes.size?s.debug("reorder: Complete."):s.warn("reorder: No qualifying primitives found; may need to weld first.")})}function Se(t){const e=new H,n=new Map,o=new H;for(const r of t.getRoot().listMeshes())for(const t of r.listPrimitives()){const r=t.getIndices();if(r){n.set(r,t.getMode());for(const n of X(t))e.add(r,n),o.add(n,t)}}return{indicesToAttributes:e,indicesToMode:n,attributesToPrimitives:o}}function Ie(t,e=Infinity){if(Number.isFinite(e)&&e%4||e<=0)throw new Error("Limit must be positive multiple of four.");const n=t.getAttribute("POSITION").getCount(),o=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).length,r=new Uint16Array(4*o),s=new Float32Array(4*o),a=new Float32Array(4*o),c=new Uint32Array(4*o),l=new Uint32Array(4*o);for(let e=0;e<n;e++){we(t,e,"WEIGHTS",s),we(t,e,"JOINTS",c);for(let t=0;t<4*o;t++)r[t]=t;r.sort((t,e)=>s[t]>s[e]?-1:1);for(let t=0;t<r.length;t++)a[t]=s[r[t]],l[t]=c[r[t]];Me(t,e,"WEIGHTS",a),Me(t,e,"JOINTS",l)}for(let n=o;4*n>e;n--){const e=t.getAttribute("WEIGHTS_"+(n-1)),o=t.getAttribute("JOINTS_"+(n-1));t.setAttribute("WEIGHTS_"+(n-1),null),t.setAttribute("JOINTS_"+(n-1),null),1===e.listParents().length&&e.dispose(),1===o.listParents().length&&o.dispose()}!function(t){if(!function(t){const e=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).map(e=>t.getAttribute(e)),n=e.map(t=>t.getNormalized()),o=e.map(t=>t.getComponentType());return 1===new Set(n).size&&1===new Set(o).size}(t))return;const e=t.getAttribute("POSITION").getCount(),n=t.listSemantics().filter(t=>t.startsWith("WEIGHTS_")).length,o=t.getAttribute("WEIGHTS_0"),r=o.getArray(),s=o.getComponentType(),a=o.getNormalized(),c=a?s:void 0,l=a?i.decodeNormalizedInt(1,s):Number.EPSILON,g=new Uint32Array(4*n).fill(0),u=r.slice(0,4*n).fill(0);for(let n=0;n<e;n++){we(t,n,"JOINTS",g),we(t,n,"WEIGHTS",u,c);let e=Ne(u,c);if(0!==e){if(Math.abs(1-e)>l)for(let t=0;t<u.length;t++)if(a){const n=i.encodeNormalizedInt(u[t]/e,s);u[t]=i.decodeNormalizedInt(n,s)}else u[t]/=e;if(e=Ne(u,c),a&&1!==e)for(let t=u.length-1;t>=0;t--)if(u[t]>0){u[t]+=i.encodeNormalizedInt(1-e,s);break}for(let t=u.length-1;t>=0;t--)0===u[t]&&(g[t]=0);Me(t,n,"JOINTS",g),Me(t,n,"WEIGHTS",u,c)}}}(t)}function we(t,e,n,o,r){let s;const a=[0,0,0,0];for(let c=0;s=t.getAttribute(`${n}_${c}`);c++){s.getElement(e,a);for(let t=0;t<4;t++)o[4*c+t]=r?i.encodeNormalizedInt(a[t],r):a[t]}return o}function Me(t,e,n,o,r){let s;const a=[0,0,0,0];for(let c=0;s=t.getAttribute(`${n}_${c}`);c++){for(let t=0;t<4;t++)a[t]=r?i.decodeNormalizedInt(o[4*c+t],r):o[4*c+t];s.setElement(e,a)}}function Ne(t,e){let n=0;for(let o=0;o<t.length;o++)n+=e?i.decodeNormalizedInt(t[o],e):t[o];return n}const be=[Int8Array,Int16Array,Int32Array],{TRANSLATION:Re,ROTATION:Oe,SCALE:Ce,WEIGHTS:ve}=l.TargetPath,Pe=[Re,Oe,Ce],$e={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12,normalizeWeights:!0},xe=(t=$e)=>{const n=G({},$e,t);return F("quantize",async t=>{const o=t.getLogger(),r=t.getRoot();let s;t.createExtension(w).setRequired(!0),"scene"===n.quantizationVolume&&(s=Le(function(t){const e=t[0];for(const n of t)lt(e.min,e.min,n.min),gt(e.max,e.max,n.max);return e}(r.listMeshes().map(Ue))));for(const e of t.getRoot().listMeshes()){"mesh"===n.quantizationVolume&&(s=Le(Ue(e))),s&&n.pattern.test("POSITION")&&(_e(t,e,s),Ge(e,1/s.scale));for(const o of e.listPrimitives()){ze(t,o,s,n);for(const e of o.listTargets())ze(t,e,s,n)}}await t.transform(Lt({propertyTypes:[e.ACCESSOR,e.SKIN,e.MATERIAL]}),bt({propertyTypes:[e.ACCESSOR,e.MATERIAL,e.SKIN]})),o.debug("quantize: Complete.")})};function ze(e,n,o,r){const s=e.getLogger();for(const e of n.listSemantics()){if(!r.pattern.test(e))continue;const c=n.getAttribute(e),{bits:l,ctor:g}=Be(e,c,s,r);if(!g)continue;if(l<8||l>16)throw new Error("quantize: Requires bits = 8–16.");if(c.getComponentSize()<=l/8)continue;const u=c.clone();if("POSITION"===e){const e=o.scale,r=[];n instanceof t?rt(r,He(o)):((i=r)[0]=(a=[1/e,1/e,1/e])[0],i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=a[1],i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=a[2],i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1);for(let t=0,e=[0,0,0],n=u.getCount();t<n;t++)u.getElement(t,e),u.setElement(t,pt(e,e,r))}Fe(u,g,l),n.swap(c,u)}var i,a;if(r.normalizeWeights&&n.getAttribute("WEIGHTS_0")&&Ie(n,Infinity),n instanceof t&&n.getIndices()&&n.listAttributes().length&&n.listAttributes()[0].getCount()<65535){const t=n.getIndices();t.setArray(new Uint16Array(t.getArray()))}}function Le(t){const{min:e,max:n}=t,o=Math.max((n[0]-e[0])/2,(n[1]-e[1])/2,(n[2]-e[2])/2);return{offset:[e[0]+(n[0]-e[0])/2,e[1]+(n[1]-e[1])/2,e[2]+(n[2]-e[2])/2],scale:o}}function _e(t,e,n){const o=He(n);for(const r of e.listParents()){if(!(r instanceof A))continue;const s=r.listParents().filter(t=>t instanceof l),i=s.some(t=>Pe.includes(t.getTargetPath())),a=r.listChildren().length>0,c=r.getSkin();if(c){r.setSkin(qe(c,n));continue}const g=r.getExtension("EXT_mesh_gpu_instancing");if(g){r.setExtension("EXT_mesh_gpu_instancing",ke(g,n));continue}let u;a||i?(u=t.createNode("").setMesh(e),r.addChild(u).setMesh(null),s.filter(t=>t.getTargetPath()===ve).forEach(t=>t.setTargetNode(u))):u=r;const f=u.getMatrix();st(f,f,o),u.setMatrix(f)}}function qe(t,e){t=t.clone();const n=He(e),o=t.getInverseBindMatrices().clone(),r=[];for(let t=0,e=o.getCount();t<e;t++)o.getElement(t,r),st(r,r,n),o.setElement(t,r);return t.setInverseBindMatrices(o)}function ke(t,e){var n,o,r;if(!t.getAttribute("TRANSLATION")&&!t.getAttribute("ROTATION")&&!t.getAttribute("SCALE"))return t;const s=null==(n=(t=t.clone()).getAttribute("TRANSLATION"))?void 0:n.clone(),a=null==(o=t.getAttribute("ROTATION"))?void 0:o.clone(),c=null==(r=t.getAttribute("SCALE"))?void 0:r.clone(),l=s||a||c,g=[0,0,0],u=[0,0,0,1],f=[1,1,1],p=[0,0,0],m=[0,0,0,1],d=[1,1,1],h=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],A=He(e);for(let t=0,e=l.getCount();t<e;t++)i.compose(s?s.getElement(t,p):g,a?a.getElement(t,m):u,c?c.getElement(t,d):f,h),st(h,h,A),i.decompose(h,p,m,d),s&&s.setElement(t,p),a&&a.setElement(t,m),c&&c.setElement(t,d);return s&&t.setAttribute("TRANSLATION",s),a&&t.setAttribute("ROTATION",a),c&&t.setAttribute("SCALE",c),t}function Ge(t,e){for(const n of t.listPrimitives()){let t=n.getMaterial();if(!t)continue;let o=t.getExtension("KHR_materials_volume");!o||o.getThicknessFactor()<=0||(o=o.clone().setThicknessFactor(o.getThicknessFactor()*e),t=t.clone().setExtension("KHR_materials_volume",o),n.setMaterial(t))}}function Fe(t,e,n){const o=new e(t.getArray().length),r=be.includes(e)?1:0,s=n-r,i=8*e.BYTES_PER_ELEMENT-r,a=Math.pow(2,s)-1,c=i-s,l=2*s-i;for(let e=0,n=0,r=[];e<t.getCount();e++){t.getElement(e,r);for(let t=0;t<r.length;t++){let e=Math.round(Math.abs(r[t])*a);e=e<<c|e>>l,o[n++]=e*Math.sign(r[t])}}t.setArray(o).setNormalized(!0).setSparse(!1)}function Be(t,e,n,o){const r=e.getMinNormalized([]),s=e.getMaxNormalized([]);let i,a;if("POSITION"===t)i=o.quantizePosition,a=i<=8?Int8Array:Int16Array;else if("NORMAL"===t||"TANGENT"===t)i=o.quantizeNormal,a=i<=8?Int8Array:Int16Array;else if(t.startsWith("COLOR_"))i=o.quantizeColor,a=i<=8?Uint8Array:Uint16Array;else if(t.startsWith("TEXCOORD_")){if(r.some(t=>t<0)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [0,1] range.`),{bits:-1};i=o.quantizeTexcoord,a=i<=8?Uint8Array:Uint16Array}else{if(t.startsWith("JOINTS_"))return i=Math.max(...e.getMax([]))<=255?8:16,a=i<=8?Uint8Array:Uint16Array,e.getComponentSize()>i/8&&e.setArray(new a(e.getArray())),{bits:-1};if(t.startsWith("WEIGHTS_")){if(r.some(t=>t<0)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [0,1] range.`),{bits:-1};i=o.quantizeWeight,a=i<=8?Uint8Array:Uint16Array}else{if(!t.startsWith("_"))throw new Error(`quantize: Unexpected semantic, "${t}".`);if(r.some(t=>t<-1)||s.some(t=>t>1))return n.warn(`quantize: Skipping ${t}; out of [-1,1] range.`),{bits:-1};i=o.quantizeGeneric,a=a=r.some(t=>t<0)?i<=8?Int8Array:Int16Array:i<=8?Uint8Array:Uint16Array}}return{bits:i,ctor:a}}function Ue(t){const e=[],n=[];for(const o of t.listPrimitives()){const t=o.getAttribute("POSITION");t&&e.push(t);for(const t of o.listTargets()){const e=t.getAttribute("POSITION");e&&n.push(e)}}if(0===e.length)throw new Error('quantize: Missing "POSITION" attribute.');const o=We(e,3);if(n.length>0){const{min:t,max:e}=We(n,3);lt(o.min,o.min,lt(t,ut(t,t,2),[0,0,0])),gt(o.max,o.max,gt(e,ut(e,e,2),[0,0,0]))}return o}function We(t,e){const n=new Array(e).fill(Infinity),o=new Array(e).fill(-Infinity),r=[],s=[];for(const i of t){i.getMinNormalized(r),i.getMaxNormalized(s);for(let t=0;t<e;t++)n[t]=Math.min(n[t],r[t]),o[t]=Math.max(o[t],s[t])}return{min:n,max:o}}function He(t){return o=t.offset,f=(s=(n=[0,0,0,1])[0])*(l=s+s),p=s*(g=(i=n[1])+i),m=s*(u=(a=n[2])+a),h=i*u,y=(c=n[3])*l,E=c*g,T=c*u,I=(r=[t.scale,t.scale,t.scale])[1],w=r[2],(e=[])[0]=(1-((d=i*g)+(A=a*u)))*(S=r[0]),e[1]=(p+T)*S,e[2]=(m-E)*S,e[3]=0,e[4]=(p-T)*I,e[5]=(1-(f+A))*I,e[6]=(h+y)*I,e[7]=0,e[8]=(m+E)*w,e[9]=(h-y)*w,e[10]=(1-(f+d))*w,e[11]=0,e[12]=o[0],e[13]=o[1],e[14]=o[2],e[15]=1,e;var e,n,o,r,s,i,a,c,l,g,u,f,p,m,d,h,A,y,E,T,S,I,w}const je={level:"high"},De=t=>{const e=G({},je,t),n=e.encoder;if(!n)throw new Error('meshopt: encoder dependency required — install "meshoptimizer".');return F("meshopt",async t=>{await t.transform(Te({encoder:n,target:"size"}),xe({pattern:"medium"===e.level?/.*/:/^(POSITION|TEXCOORD|JOINTS|WEIGHTS)(_\d+)?$/,quantizePosition:14,quantizeTexcoord:12,quantizeColor:8,quantizeNormal:8})),t.createExtension(b).setRequired(!0).setEncoderOptions({method:"medium"===e.level?b.EncoderMethod.QUANTIZE:b.EncoderMethod.FILTER})})},Ve={};function Xe(t=Ve){return G({},Ve,t),F("metalRough",async t=>{const e=t.getLogger();if(!t.getRoot().listExtensionsUsed().map(t=>t.extensionName).includes("KHR_materials_pbrSpecularGlossiness"))return void e.warn("metalRough: KHR_materials_pbrSpecularGlossiness not found on document.");const n=t.createExtension(R),o=t.createExtension(O),r=t.createExtension(C),s=new Set;for(const e of t.getRoot().listMaterials()){const r=e.getExtension("KHR_materials_pbrSpecularGlossiness");if(!r)continue;const i=o.createSpecular().setSpecularFactor(1).setSpecularColorFactor(r.getSpecularFactor());s.add(r.getSpecularGlossinessTexture()),s.add(e.getBaseColorTexture()),s.add(e.getMetallicRoughnessTexture()),e.setBaseColorFactor(r.getDiffuseFactor()).setMetallicFactor(0).setRoughnessFactor(1).setExtension("KHR_materials_ior",n.createIOR().setIOR(1e3)).setExtension("KHR_materials_specular",i);const a=r.getDiffuseTexture();a&&(e.setBaseColorTexture(a),e.getBaseColorTextureInfo().copy(r.getDiffuseTextureInfo()));const c=r.getSpecularGlossinessTexture();if(c){const n=r.getSpecularGlossinessTextureInfo(),o=t.createTexture();await U(c,o,(t,e,n)=>{t.set(e,n,3,255)}),i.setSpecularTexture(o),i.setSpecularColorTexture(o),i.getSpecularTextureInfo().copy(n),i.getSpecularColorTextureInfo().copy(n);const s=r.getGlossinessFactor(),a=t.createTexture();await U(c,a,(t,e,n)=>{const o=255-Math.round(t.get(e,n,3)*s);t.set(e,n,0,0),t.set(e,n,1,o),t.set(e,n,2,0),t.set(e,n,3,255)}),e.setMetallicRoughnessTexture(a),e.getMetallicRoughnessTextureInfo().copy(n)}else i.setSpecularColorFactor(r.getSpecularFactor()),e.setRoughnessFactor(1-r.getGlossinessFactor());e.setExtension("KHR_materials_pbrSpecularGlossiness",null)}r.dispose();for(const t of s)t&&1===t.listParents().length&&t.dispose();e.debug("metalRough: Complete.")})}const Ke={};function Je(t=Ke){return G({},Ke,t),F("unweld",t=>{const e=t.getLogger(),n=new Map;for(const o of t.getRoot().listMeshes())for(const t of o.listPrimitives()){const o=t.getIndices();if(!o)continue;const r=t.getAttribute("POSITION").getCount();for(const r of t.listAttributes())t.swap(r,Ze(r,o,e,n)),1===r.listParents().length&&r.dispose();for(const r of t.listTargets())for(const t of r.listAttributes())r.swap(t,Ze(t,o,e,n)),1===t.listParents().length&&t.dispose();const s=t.getAttribute("POSITION").getCount();e.debug(`unweld: ${V(r,s)} vertices.`),t.setIndices(null),1===o.listParents().length&&o.dispose()}e.debug("unweld: Complete.")})}function Ze(t,e,n,o){if(o.has(t)&&o.get(t).has(e))return n.debug(`unweld: Cache hit for reused attribute, "${t.getName()}".`),o.get(t).get(e);const r=t.clone(),s=t.getArray().constructor;r.setArray(new s(e.getCount()*t.getElementSize()));const i=[];for(let n=0;n<e.getCount();n++)r.setElement(n,t.getElement(e.getScalar(n),i));return o.has(t)||o.set(t,new Map),o.get(t).set(e,r),r}const Qe={overwrite:!1};function Ye(t=Qe){const e=G({},Qe,t);return F("normals",async t=>{const n=t.getLogger();let o=0;await t.transform(Je());for(const r of t.getRoot().listMeshes())for(const s of r.listPrimitives()){const r=s.getAttribute("POSITION");let i=s.getAttribute("NORMAL");if(e.overwrite&&i)i.dispose();else if(i){n.debug("normals: Skipping primitive: NORMAL found.");continue}i=t.createAccessor().setArray(new Float32Array(3*r.getCount())).setType("VEC3");const a=[0,0,0],c=[0,0,0],l=[0,0,0];for(let t=0;t<r.getCount();t+=3){r.getElement(t+0,a),r.getElement(t+1,c),r.getElement(t+2,l);const e=tn(a,c,l);i.setElement(t+0,e),i.setElement(t+1,e),i.setElement(t+2,e)}s.setAttribute("NORMAL",i),o++}o?n.debug("normals: Complete."):n.warn("normals: No qualifying primitives found. See debug output.")})}function tn(t,e,n){const o=[e[0]-t[0],e[1]-t[1],e[2]-t[2]],r=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];return ft([0,0,0],[o[1]*r[2]-o[2]*r[1],o[2]*r[0]-o[0]*r[2],o[0]*r[1]-o[1]*r[0]])}const en={animations:!0,meshes:!0},nn=(t=en)=>{const n=G({},en,t);return F("partition",async t=>{const o=t.getLogger();!1!==n.meshes&&function(t,e,n){const o=new Set(t.getRoot().listBuffers().map(t=>t.getURI()));t.getRoot().listMeshes().forEach((r,s)=>{if(Array.isArray(n.meshes)&&!n.meshes.includes(r.getName()))return void e.debug(`partition: Skipping mesh #${s} with name "${r.getName()}".`);e.debug(`partition: Creating buffer for mesh "${r.getName()}".`);const i=t.createBuffer(r.getName()).setURI(on(r.getName()||"mesh",o));r.listPrimitives().forEach(t=>{const e=t.getIndices();e&&e.setBuffer(i),t.listAttributes().forEach(t=>t.setBuffer(i)),t.listTargets().forEach(t=>{t.listAttributes().forEach(t=>t.setBuffer(i))})})})}(t,o,n),!1!==n.animations&&function(t,e,n){const o=new Set(t.getRoot().listBuffers().map(t=>t.getURI()));t.getRoot().listAnimations().forEach((r,s)=>{if(Array.isArray(n.animations)&&!n.animations.includes(r.getName()))return void e.debug(`partition: Skipping animation #${s} with name "${r.getName()}".`);e.debug(`partition: Creating buffer for animation "${r.getName()}".`);const i=t.createBuffer(r.getName()).setURI(on(r.getName()||"animation",o));r.listSamplers().forEach(t=>{const e=t.getInput(),n=t.getOutput();e&&e.setBuffer(i),n&&n.setBuffer(i)})})}(t,o,n),n.meshes||n.animations||o.warn("partition: Select animations or meshes to create a partition."),await t.transform(Lt({propertyTypes:[e.BUFFER]})),o.debug("partition: Complete.")})};function on(t,e){let n=`${t}.bin`,o=1;for(;e.has(n);)n=`${t}_${o++}.bin`;return n}function rn(){var t=new ot(4);return ot!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function sn(t,e){var n=cn(t,e);return Math.acos(2*n*n-1)}function an(t,e,n,o){var r,s,i,a,c,l=e[0],g=e[1],u=e[2],f=e[3],p=n[0],m=n[1],d=n[2],h=n[3];return(s=l*p+g*m+u*d+f*h)<0&&(s=-s,p=-p,m=-m,d=-d,h=-h),1-s>1e-6?(r=Math.acos(s),i=Math.sin(r),a=Math.sin((1-o)*r)/i,c=Math.sin(o*r)/i):(a=1-o,c=o),t[0]=a*l+c*p,t[1]=a*g+c*m,t[2]=a*u+c*d,t[3]=a*f+c*h,t}var cn=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]};at(),ct(1,0,0),ct(0,1,0),rn(),rn(),it();const ln={tolerance:1e-4},gn=(t=ln)=>{const n=G({},ln,t);return F("resample",async(t,o)=>{const r=new Set,s=t.getRoot().listAccessors().length,i=t.getLogger();let a=!1;for(const e of t.getRoot().listAnimations()){const t=new Map;for(const n of e.listChannels())t.set(n.getSampler(),n.getTargetPath());for(const o of e.listSamplers())"weights"!==t.get(o)?"STEP"!==o.getInterpolation()&&"LINEAR"!==o.getInterpolation()||(r.add(o.getInput()),r.add(o.getOutput()),un(o,t.get(o),n)):a=!0}for(const t of Array.from(r.values()))t.listParents().some(t=>!(t instanceof c))||t.dispose();t.getRoot().listAccessors().length>s&&!B(o,"resample","dedup")&&await t.transform(bt({propertyTypes:[e.ACCESSOR]})),a&&i.warn("resample: Skipped optimizing morph target keyframes, not yet supported."),i.debug("resample: Complete.")})};function un(t,e,n){const o=t.getInput().clone().setSparse(!1),r=t.getOutput().clone().setSparse(!1),s=n.tolerance,a=t.getInterpolation(),c=o.getCount()-1,l=[],g=[],u=[],f=[];let p=1;for(let t=1;t<c;++t){const n=o.getScalar(p-1),c=o.getScalar(t),m=o.getScalar(t+1),d=(c-n)/(m-n);let h=!1;if(c!==m&&(1!==t||c!==o.getScalar(0)))if(r.getElement(p-1,f),r.getElement(t,g),r.getElement(t+1,u),"LINEAR"===a&&"rotation"===e){const t=an(l,f,u,d),e=sn(f,g)+sn(g,u);h=!i.eq(g,t,s)||e+Number.EPSILON>=Math.PI}else if("LINEAR"===a){const t=pn(l,f,u,d);h=!i.eq(g,t,s)}else"STEP"===a&&(h=!i.eq(g,f)||!i.eq(g,u));h&&(t!==p&&(o.setScalar(p,o.getScalar(t)),r.setElement(p,r.getElement(t,l))),p++)}c>0&&(o.setScalar(p,o.getScalar(c)),r.setElement(p,r.getElement(c,l)),p++),p!==o.getCount()?(o.setArray(o.getArray().slice(0,p)),r.setArray(r.getArray().slice(0,p*r.getElementSize())),t.setInput(o),t.setOutput(r)):(o.dispose(),r.dispose())}function fn(t,e,n){return t*(1-n)+e*n}function pn(t,e,n,o){for(let r=0;r<e.length;r++)t[r]=fn(e[r],n[r],o);return t}const mn={name:"",fps:10,pattern:/.*/,sort:!0};function dn(t=mn){const e=G({},mn,t);return F("sequence",t=>{const n=t.getLogger(),o=t.getRoot(),r=e.fps,s=o.listNodes().filter(t=>t.getName().match(e.pattern));e.sort&&s.sort((t,e)=>t.getName()>e.getName()?1:-1);const i=t.createAnimation(e.name),a=o.listBuffers()[0];s.forEach((e,n)=>{let o,c;0===n?(o=[n/r,(n+1)/r],c=[1,1,1,0,0,0]):n===s.length-1?(o=[(n-1)/r,n/r],c=[0,0,0,1,1,1]):(o=[(n-1)/r,n/r,(n+1)/r],c=[0,0,0,1,1,1,0,0,0]);const g=t.createAccessor().setArray(new Float32Array(o)).setBuffer(a),u=t.createAccessor().setArray(new Float32Array(c)).setBuffer(a).setType(y.Type.VEC3),f=t.createAnimationSampler().setInterpolation(E.Interpolation.STEP).setInput(g).setOutput(u),p=t.createAnimationChannel().setTargetNode(e).setTargetPath(l.TargetPath.SCALE).setSampler(f);i.addSampler(f).addChannel(p)}),n.debug("sequence: Complete.")})}const hn={tolerance:1e-4,overwrite:!0,exhaustive:!1};function An(t=hn){const n=G({},hn,t);if(n.tolerance>.1||n.tolerance<0)throw new Error("weld: Requires 0 ≤ tolerance ≤ 0.1");return F("weld",async t=>{const o=t.getLogger();for(const e of t.getRoot().listMeshes()){for(const o of e.listPrimitives())yn(t,o,n),0===o.getIndices().getCount()&&o.dispose();0===e.listPrimitives().length&&e.dispose()}await t.transform(Lt({propertyTypes:[e.ACCESSOR,e.NODE]})),await t.transform(bt({propertyTypes:[e.ACCESSOR]})),o.debug("weld: Complete.")})}function yn(e,n,o){n.getIndices()&&!o.overwrite||n.getMode()!==t.Mode.POINTS&&(0===o.tolerance?function(t,e){if(e.getIndices())return;const n=e.listAttributes()[0],o=n.getCount(),r=n.getBuffer(),s=t.createAccessor().setBuffer(r).setType(y.Type.SCALAR).setArray(Z(o));e.setIndices(s)}(e,n):function(t,e,n){const o=t.getLogger(),r=e.getAttribute("POSITION"),s=e.getIndices()||t.createAccessor().setArray(Z(r.getCount())),i=new Uint32Array(new Set(s.getArray())).sort(),a=Math.max(n.tolerance,Number.EPSILON),c={};for(const t of e.listSemantics()){const n=e.getAttribute(t);c[t]=In(t,n,a)}var l;o.debug(`weld: Tolerance thresholds: ${l=c,Object.entries(l).map(([t,e])=>`${t}=${e}`).join(", ")}`);const g=[0,0,0],u=[0,0,0],f={},p=c.POSITION;for(let t=0;t<i.length;t++){r.getElement(i[t],g);const e=bn(g,p);f[e]=f[e]||[],f[e].push(i[t])}const m=Z(i.length),d=new Array(i.length).fill(-1),h=r.getCount();let A=0;for(let t=0;t<i.length;t++){const o=i[t];r.getElement(o,g);const s=n.exhaustive?Nn(g,p):[bn(g,p)];t:for(const t of s)if(f[t])e:for(const n of f[t]){const t=m[n];if(o<=t)continue e;r.getElement(t,u);const s=e.listSemantics().every(n=>wn(e.getAttribute(n),o,t,c[n])),i=e.listTargets().every(e=>e.listSemantics().every(n=>wn(e.getAttribute(n),o,t,c[n])));if(s&&i){m[o]=t;break t}}d[o]=m[o]===o?A++:d[m[o]]}o.debug(`weld: ${V(h,A)} vertices.`);const y=s.getCount(),E=Z(y,i.length);for(let t=0;t<y;t++)E[t]=d[s.getScalar(t)];e.setIndices(s.clone().setArray(E)),1===s.listParents().length&&s.dispose();for(const t of e.listAttributes())En(e,t,d,A);for(const t of e.listTargets())for(const e of t.listAttributes())En(t,e,d,A);!function(t){const e=t.getIndices();if(!e)return;const n=[];let o=-Infinity;for(let t=0,r=e.getCount();t<r;t+=3){const r=e.getScalar(t),s=e.getScalar(t+1),i=e.getScalar(t+2);r!==s&&r!==i&&s!==i&&(n.push(r,s,i),o=Math.max(o,r,s,i))}const r=Z(n.length,o);r.set(n),e.setArray(r)}(e)}(e,n,o))}function En(t,e,n,o){const r=(a=e.getArray(),c=o*e.getElementSize(),new(0,a.constructor)(c)),s=e.clone().setArray(r),i=new Uint8Array(o);var a,c;for(let t=0,o=[];t<n.length;t++)i[n[t]]||(s.setElement(n[t],e.getElement(t,o)),i[n[t]]=1);t.swap(e,s),1===e.listParents().length&&e.dispose()}const Tn=[],Sn=[];function In(t,e,n){return"NORMAL"===t||"TANGENT"===t?.5:t.startsWith("COLOR_")?.01:t.startsWith("TEXCOORD_")?1e-4:t.startsWith("JOINTS_")?0:t.startsWith("WEIGHTS_")?.01:(Tn.length=Sn.length=0,e.getMinNormalized(Tn),e.getMaxNormalized(Sn),n*(Math.max(...Sn)-Math.min(...Tn)||1))}function wn(t,e,n,o,r){t.getElement(e,Tn),t.getElement(n,Sn);for(let e=0,n=t.getElementSize();e<n;e++)if(Math.abs(Tn[e]-Sn[e])>o)return!1;return!0}const Mn=[0,-1,1];function Nn(t,e){const n=[],o=[0,0,0];for(const r of Mn)for(const s of Mn)for(const i of Mn)o[0]=t[0]+r*e,o[1]=t[1]+s*e,o[2]=t[2]+i*e,n.push(bn(o,e));return n}function bn(t,e){return Math.round(t[0]/e)+":"+Math.round(t[1]/e)+":"+Math.round(t[2]/e)}const Rn={ratio:.5,error:.001,lockBorder:!1},On=n=>{const o=G({},Rn,n),r=o.simplifier;if(!r)throw new Error('simplify: simplifier dependency required — install "meshoptimizer".');return F("simplify",async(n,s)=>{const i=n.getLogger();await r.ready,await n.transform(An({overwrite:!1}));for(const e of n.getRoot().listMeshes())for(const r of e.listPrimitives())r.getMode()===t.Mode.TRIANGLES?Cn(n,r,o):i.warn(`simplify: Skipping primitive of mesh "${e.getName()}": Requires TRIANGLES draw mode.`);B(s,"simplify","dedup")||await n.transform(bt({propertyTypes:[e.ACCESSOR]})),i.debug("simplify: Complete.")})};function Cn(t,e,n){const o=G({},Rn,n),r=o.simplifier,s=t.getLogger(),i=e.getAttribute("POSITION"),a=e.getIndices(),c=i.getCount();let l=i.getArray(),g=a.getArray();if(i.getComponentType()!==y.ComponentType.FLOAT)if(i.getNormalized()){const t=l,e=new Float32Array(t.length);for(let n=0,o=i.getCount(),r=[];n<o;n++)r=i.getElement(n,r),i.setArray(e).setElement(n,r).setArray(t);l=e}else l=new Float32Array(l);a.getComponentType()!==y.ComponentType.UNSIGNED_INT&&(g=new Uint32Array(g));const u=3*Math.floor(o.ratio*c/3),[f,p]=r.simplify(g,l,3,u,o.error,o.lockBorder?["LockBorder"]:[]),[m,d]=r.compactMesh(f);s.debug(`simplify: ${V(i.getCount(),d)} vertices, error: ${p.toFixed(4)}.`);for(const t of X(e)){const n=t.clone();J(n,m,d),K(e,t,n),1===t.listParents().length&&t.dispose()}const h=a.clone();return h.setArray(c<=65534?new Uint16Array(f):f),e.setIndices(h),1===a.listParents().length&&a.dispose(),e}const vn={ratio:1/3};function Pn(t=vn){const e=G({},vn,t).ratio;if(e<0||e>1)throw new Error("sparse: Ratio must be between 0 and 1.");return F("sparse",t=>{const n=t.getRoot(),o=t.getLogger();let r=0;for(const t of n.listAccessors()){const n=t.getCount(),o=Array(t.getElementSize()).fill(0),s=Array(t.getElementSize()).fill(0);let a=0;for(let r=0;r<n&&(t.getElement(r,s),i.eq(s,o,0)||a++,!(a/n>=e));r++);const c=a/n<e;c!==t.getSparse()&&(t.setSparse(c),r++)}o.debug(`sparse: Updated ${r} accessors.`),o.debug("sparse: Complete.")})}const $n="textureResize";var xn;!function(t){t.LANCZOS3="lanczos3",t.LANCZOS2="lanczos2"}(xn||(xn={}));const zn={size:[2048,2048],filter:xn.LANCZOS3,pattern:null,slots:null};function Ln(t=zn){const e=G({},zn,t);return F($n,async t=>{const n=t.getLogger();for(const o of t.getRoot().listTextures()){const t=o.getName(),r=o.getURI();if(e.pattern&&!e.pattern.test(t)&&!e.pattern.test(r)){n.debug(`${$n}: Skipping, excluded by "pattern" parameter.`);continue}if("image/png"!==o.getMimeType()&&"image/jpeg"!==o.getMimeType()){n.warn(`${$n}: Skipping, unsupported texture type "${o.getMimeType()}".`);continue}const s=ye(o);if(e.slots&&!s.some(t=>{var n;return null==(n=e.slots)?void 0:n.test(t)})){n.debug(`${$n}: Skipping, [${s.join(", ")}] excluded by "slots" parameter.`);continue}const[i,a]=e.size,[c,l]=o.getSize();if(c<=i&&l<=a){n.debug(`${$n}: Skipping, not within size range.`);continue}let g=c,u=l;g>i&&(u=Math.floor(u*(i/g)),g=i),u>a&&(g=Math.floor(g*(a/u)),u=a);const f=o.getImage(),p=await S(f,o.getMimeType()),m=_(new Uint8Array(g*u*4),[g,u,4]);n.debug(`${$n}: Resizing "${r||t}", ${p.shape} → ${m.shape}...`),n.debug(`${$n}: Slots → [${s.join(", ")}]`);try{e.filter===xn.LANCZOS3?q(p,m):k(p,m)}catch(e){if(e instanceof Error){n.warn(`${$n}: Failed to resize "${r||t}": "${e.message}".`);continue}throw e}o.setImage(await I(m,o.getMimeType()))}n.debug(`${$n}: Complete.`)})}const _n="textureCompress",qn=["jpeg","png","webp","avif"],kn=["image/jpeg","image/png","image/webp","image/avif"],Gn={resizeFilter:xn.LANCZOS3,pattern:null,formats:null,slots:null,quality:null,effort:null,lossless:!1,nearLossless:!1},Fn=function(t){const e=G({},Gn,t),n=e.targetFormat,o=e.pattern,r=e.formats,s=e.slots;if(!e.encoder)throw new Error(`${n}: encoder dependency required — install "sharp".`);return F(_n,async t=>{const i=t.getLogger(),a=t.getRoot().listTextures();await Promise.all(a.map(async(a,c)=>{const l=ye(a),g=he(a),u=a.getURI()||a.getName()||`${c+1}/${t.getRoot().listTextures().length}`,f=`${_n}(${u})`;if(!kn.includes(a.getMimeType()))return void i.debug(`${f}: Skipping, unsupported texture type "${a.getMimeType()}".`);if(o&&!o.test(a.getName())&&!o.test(a.getURI()))return void i.debug(`${f}: Skipping, excluded by "pattern" parameter.`);if(r&&!r.test(a.getMimeType()))return void i.debug(`${f}: Skipping, "${a.getMimeType()}" excluded by "formats" parameter.`);if(s&&l.length&&!l.some(t=>s.test(t)))return void i.debug(`${f}: Skipping, [${l.join(", ")}] excluded by "slots" parameter.`);if("jpeg"===e.targetFormat&&g&h.A)return void i.warn(`${f}: Skipping, [${l.join(", ")}] requires alpha channel.`);const p=Un(a);i.debug(`${f}: Format = ${p} → ${n||p}`),i.debug(`${f}: Slots = [${l.join(", ")}]`);const m=a.getImage(),d=m.byteLength;await Bn(a,e);const A=a.getImage(),y=A.byteLength,E=m===A?" (SKIPPED":"";i.debug(`${f}: Size = ${j(d)} → ${j(y)}${E}`)}));const c=t.createExtension(v);a.some(t=>"image/webp"===t.getMimeType())?c.setRequired(!0):c.dispose();const l=t.createExtension(P);a.some(t=>"image/avif"===t.getMimeType())?l.setRequired(!0):l.dispose(),i.debug(`${_n}: Complete.`)})};async function Bn(t,e){const n=G({},Gn,e),o=n.encoder;if(!o)throw new Error(`${n.targetFormat}: encoder dependency required — install "sharp".`);const r=Un(t),s=n.targetFormat||r,i=t.getMimeType(),c=`image/${s}`;let l={};switch(s){case"jpeg":l={quality:n.quality};break;case"png":l={quality:n.quality,effort:Wn(n.effort,100,10)};break;case"webp":l={quality:n.quality,effort:Wn(n.effort,100,6),lossless:n.lossless,nearLossless:n.nearLossless};break;case"avif":l={quality:n.quality,effort:Wn(n.effort,100,9),lossless:n.lossless}}const g=t.getImage(),u=o(g).toFormat(s,l);n.resize&&u.resize(n.resize[0],n.resize[1],{fit:"inside",kernel:n.resizeFilter,withoutEnlargement:!0});const f=a.toView(await u.toBuffer());if(!(i===c&&f.byteLength>=g.byteLength))if(i===c)t.setImage(f);else{const e=p.mimeTypeToExtension(i),n=p.mimeTypeToExtension(c),o=t.getURI().replace(new RegExp(`\\.${e}$`),`.${n}`);t.setImage(f).setMimeType(c).setURI(o)}}function Un(t){const e=t.getMimeType(),n=e.split("/").pop();if(!n||!qn.includes(n))throw new Error(`Unknown MIME type "${e}".`);return n}function Wn(t,e,n){return null==t?null:Math.round(t/e*n)}const Hn={overwrite:!1};function jn(t=Hn){if(!t.generateTangents)throw new Error('tangents: generateTangents callback required — install "mikktspace".');const e=G({},Hn,t);return F("tangents",t=>{const n=t.getLogger(),o=new Map,r=new Map;let s=0;for(const i of t.getRoot().listMeshes()){const a=i.getName(),c=i.listPrimitives();for(let i=0;i<c.length;i++){const l=c[i];if(!Vn(l,n,a,i,e.overwrite))continue;const g=Dn(l),u=l.getAttribute("POSITION").getArray(),f=l.getAttribute("NORMAL").getArray(),p=l.getAttribute(g).getArray(),m=o.get(u)||T();o.set(u,m);const d=o.get(f)||T();o.set(f,d);const h=o.get(p)||T();o.set(p,h);const A=l.getAttribute("TANGENT");A&&2===A.listParents().length&&A.dispose();const y=`${m}|${d}|${h}`;let E=r.get(y);if(E){n.debug(`tangents: Found cache for primitive ${i} of mesh "${a}".`),l.setAttribute("TANGENT",E),s++;continue}n.debug(`tangents: Generating for primitive ${i} of mesh "${a}".`);const S=l.getAttribute("POSITION").getBuffer(),I=e.generateTangents(u instanceof Float32Array?u:new Float32Array(u),f instanceof Float32Array?f:new Float32Array(f),p instanceof Float32Array?p:new Float32Array(p));for(let t=3;t<I.length;t+=4)I[t]*=-1;E=t.createAccessor().setBuffer(S).setArray(I).setType("VEC4"),l.setAttribute("TANGENT",E),r.set(y,E),s++}}s?n.debug("tangents: Complete."):n.warn("tangents: No qualifying primitives found. See debug output.")})}function Dn(t){const e=t.getMaterial();if(!e)return"TEXCOORD_0";const n=e.getNormalTextureInfo();if(!n)return"TEXCOORD_0";const o=`TEXCOORD_${n.getTexCoord()}`;return t.getAttribute(o)?o:"TEXCOORD_0"}function Vn(e,n,o,r,s){return e.getMode()===t.Mode.TRIANGLES&&e.getAttribute("POSITION")&&e.getAttribute("NORMAL")&&e.getAttribute("TEXCOORD_0")?e.getAttribute("TANGENT")&&!s?(n.debug(`tangents: Skipping primitive ${r} of mesh "${o}": TANGENT found.`),!1):!e.getIndices()||(n.warn(`tangents: Skipping primitive ${r} of mesh "${o}": primitives must be unwelded.`),!1):(n.debug(`tangents: Skipping primitive ${r} of mesh "${o}": primitives must have attributes=[POSITION, NORMAL, TEXCOORD_0] and mode=TRIANGLES.`),!1)}const Xn=()=>t=>{const e=t.createExtension($).createUnlit();t.getRoot().listMaterials().forEach(t=>{t.setExtension("KHR_materials_unlit",e)})},Kn={},Jn=(t=Kn)=>(G({},Kn,t),F("unpartition",async t=>{const e=t.getLogger(),n=t.getRoot().listBuffers()[0];t.getRoot().listAccessors().forEach(t=>t.setBuffer(n)),t.getRoot().listBuffers().forEach((t,e)=>e>0?t.dispose():null),e.debug("unpartition: Complete.")}));export{$t as DRACO_DEFAULTS,kt as FLATTEN_DEFAULTS,ge as JOIN_DEFAULTS,je as MESHOPT_DEFAULTS,$e as QUANTIZE_DEFAULTS,Rn as SIMPLIFY_DEFAULTS,Gn as TEXTURE_COMPRESS_DEFAULTS,zn as TEXTURE_RESIZE_DEFAULTS,xn as TextureResizeFilter,hn as WELD_DEFAULTS,tt as center,nt as clearNodeParent,It as clearNodeTransform,Mt as colorspace,Bn as compressTexture,Se as createLayoutPlan,F as createTransform,bt as dedup,Ct as dequantize,xt as draco,Gt as flatten,W as getGLPrimitiveCount,Ft as getNodeScene,he as getTextureChannelMask,Bt as inspect,Qt as instance,B as isTransformPending,ue as join,ne as joinPrimitives,et as listNodeScenes,de as listTextureChannels,Ae as listTextureInfo,ye as listTextureSlots,De as meshopt,Xe as metalRough,Ye as normals,nn as partition,Lt as prune,xe as quantize,Te as reorder,gn as resample,dn as sequence,On as simplify,Cn as simplifyPrimitive,Ie as sortPrimitiveWeights,Pn as sparse,jn as tangents,Fn as textureCompress,Ln as textureResize,Tt as transformMesh,ht as transformPrimitive,Xn as unlit,Jn as unpartition,Je as unweld,An as weld,yn as weldPrimitive}; | ||
//# sourceMappingURL=functions.modern.js.map |
@@ -8,2 +8,3 @@ import { Document, Primitive, Transform } from '@gltf-transform/core'; | ||
overwrite?: boolean; | ||
/** Enables a more thorough, but slower, search for vertices to weld. */ | ||
exhaustive?: boolean; | ||
@@ -10,0 +11,0 @@ } |
{ | ||
"name": "@gltf-transform/functions", | ||
"version": "3.1.6", | ||
"version": "3.1.7", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -38,4 +38,4 @@ "homepage": "https://gltf-transform.donmccurdy.com/functions.html", | ||
"dependencies": { | ||
"@gltf-transform/core": "^3.1.6", | ||
"@gltf-transform/extensions": "^3.1.6", | ||
"@gltf-transform/core": "^3.1.7", | ||
"@gltf-transform/extensions": "^3.1.7", | ||
"ktx-parse": "^0.5.0", | ||
@@ -56,3 +56,3 @@ "ndarray": "^1.0.19", | ||
}, | ||
"gitHead": "e6fdb68c4df9051967df111a31c417c9d112566d" | ||
"gitHead": "a40c8a2c490cf873a04562c6cba74f27087f63bc" | ||
} |
@@ -73,4 +73,4 @@ import { | ||
function dedupAccessors(doc: Document): void { | ||
const logger = doc.getLogger(); | ||
function dedupAccessors(document: Document): void { | ||
const logger = document.getLogger(); | ||
@@ -83,3 +83,3 @@ // Find all accessors used for mesh data. | ||
const meshes = doc.getRoot().listMeshes(); | ||
const meshes = document.getRoot().listMeshes(); | ||
meshes.forEach((mesh) => { | ||
@@ -93,3 +93,3 @@ mesh.listPrimitives().forEach((primitive) => { | ||
for (const animation of doc.getRoot().listAnimations()) { | ||
for (const animation of document.getRoot().listAnimations()) { | ||
for (const sampler of animation.listSamplers()) { | ||
@@ -113,6 +113,5 @@ const input = sampler.getInput(); | ||
for (let j = 0; j < accessors.length; j++) { | ||
for (let j = i + 1; j < accessors.length; j++) { | ||
const b = accessors[j]; | ||
if (a === b) continue; | ||
if (duplicateAccessors.has(b)) continue; | ||
@@ -166,3 +165,3 @@ | ||
// Dissolve duplicate animation sampler inputs and outputs. | ||
for (const animation of doc.getRoot().listAnimations()) { | ||
for (const animation of document.getRoot().listAnimations()) { | ||
for (const sampler of animation.listSamplers()) { | ||
@@ -183,5 +182,5 @@ const input = sampler.getInput(); | ||
function dedupMeshes(doc: Document): void { | ||
const logger = doc.getLogger(); | ||
const root = doc.getRoot(); | ||
function dedupMeshes(document: Document): void { | ||
const logger = document.getLogger(); | ||
const root = document.getRoot(); | ||
@@ -222,5 +221,5 @@ // Create Reference -> ID lookup table. | ||
function dedupImages(doc: Document): void { | ||
const logger = doc.getLogger(); | ||
const root = doc.getRoot(); | ||
function dedupImages(document: Document): void { | ||
const logger = document.getLogger(); | ||
const root = document.getRoot(); | ||
const textures = root.listTextures(); | ||
@@ -236,7 +235,6 @@ const duplicates: Map<Texture, Texture> = new Map(); | ||
for (let j = 0; j < textures.length; j++) { | ||
for (let j = i + 1; j < textures.length; j++) { | ||
const b = textures[j]; | ||
const bData = b.getImage(); | ||
if (a === b) continue; | ||
if (duplicates.has(b)) continue; | ||
@@ -269,5 +267,5 @@ | ||
function dedupMaterials(doc: Document): void { | ||
const logger = doc.getLogger(); | ||
const root = doc.getRoot(); | ||
function dedupMaterials(document: Document): void { | ||
const logger = document.getLogger(); | ||
const root = document.getRoot(); | ||
const materials = root.listMaterials(); | ||
@@ -274,0 +272,0 @@ const duplicates = new Map<Material, Material>(); |
@@ -62,2 +62,3 @@ import { | ||
overwrite?: boolean; | ||
/** Enables a more thorough, but slower, search for vertices to weld. */ | ||
exhaustive?: boolean; | ||
@@ -69,3 +70,3 @@ } | ||
overwrite: true, | ||
exhaustive: true, | ||
exhaustive: false, // donmccurdy/glTF-Transform#886 | ||
}; | ||
@@ -72,0 +73,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1183872