@woosh/meep-engine 2.71.0 → 2.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function t(t,e){const n=t.length;if(n!==e.length)return!1;let i=0;for(;i<n;i++)if(t[i]!==e[i])return!1;return!0}class e{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,n,i){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,n,i){throw new Error("Not Implemented")}}class n{describeTo(t){throw new Error("Not Implemented")}}class i extends n{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class r{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new i(t)}}class s extends e{appendDescriptionOf(t){return t.describeTo(this),this}#e(t){this.appendText('"'),this.appendText(t),this.appendText('"')}appendValue(t){return null==t?this.appendText("null"):void 0===t?this.appendText("undefined"):"string"==typeof t?this.#e(t):"number"==typeof t?this.appendText(function(t){return String(t)}(t)):Array.isArray(t)?this.appendValueList("[",", ","]",t):(this.appendText("<"),this.appendText(function(t){try{return String(t)}catch(t){return"VALUE@0"}}(t)),this.appendText(">")),this}appendValueList(t,e,n,i){return this.appendList(t,e,n,new r(i)),this}appendList(t,e,n,i){let r=!1;this.appendText(t);const s=i[Symbol.iterator]();for(let t=s.next();!0!==t.done;t=s.next())r&&this.appendText(e),this.appendDescriptionOf(t.value),r=!0;return this.appendText(n),this}}class o extends s{value="";appendText(t){return this.value+=t,this}}function a(t,e){if(!t)throw new Error(e||"AssertionError")}function h(t,e,n,i,r){let s,o,a;for(a=0;a<r;a++)s=e+a,o=i+a,n[o]=t[s]}a.enum=function(t,e,n="value"){for(let n in e)if(e[n]===t)return;throw new Error(`${n}(=${t}) is not a valid enumerable value, valid values are: [${Object.values(e).join(", ")}]`)},a.notEqual=function(t,e,n){a(t!==e,n)},a.notOk=function(t,e){a(!t,e)},a.equal=function(t,e,n){if(t!==e)throw new Error(void 0!==n?n:`${t} !== ${e}`)},a.logicalyEqual=function(t,e,n){},a.ok=a,a.greaterThan=function(t,e,n){if(!(t>e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} > ${e}.`,new Error(i)}},a.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} >= ${e}.`,new Error(i)}},a.lessThan=function(t,e,n){if(!(t<e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} < ${e}.`,new Error(i)}},a.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} <= ${e}.`,new Error(i)}},a.typeOf=function(t,e,n="value"){const i=typeof t;if(i!==e)throw new Error(`expected ${n} to be ${e}, instead was '${i}'(=${t})`)},a.arrayHas=function(t,e,n="Array does not contain the item"){},a.arrayHasNo=function(t,e,n="Array contains the item"){},a.arrayEqual=function(e,n,i="Arrays are not equal"){if(!t(e,n))throw new Error(i)},a.isInstanceOf=function(t,e,n="value",i=e.name){},a.isNumber=function(t,e="value"){const n=typeof t;if("number"!==n)throw new Error(`expected ${e} to be a number, instead was '${n}'(=${t})`)},a.isString=function(t,e="value"){const n=typeof t;if("string"!==n)throw new Error(`expected ${e} to be a string, instead was '${n}'(=${t})`)},a.isBoolean=function(t,e="value"){const n=typeof t;if("boolean"!==n)throw new Error(`expected ${e} to be a boolean, instead was '${n}'(=${t})`)},a.isFunction=function(t,e="value"){const n=typeof t;if("function"!==n)throw new Error(`expected ${e} to be a function, instead was '${n}'(=${t})`)},a.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},a.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},a.isArray=function(t,e="value"){if(!Array.isArray(t))throw new Error(`expected ${e} to be an array, instead was something else (typeof ='${typeof t}')`)},a.isArrayLike=function(t,e="value"){if(!(Array.isArray(t)||(n=t,n instanceof Int8Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray||n instanceof Int16Array||n instanceof Uint16Array||n instanceof Int32Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array)))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`);var n},a.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},a.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},a.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},a.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},a.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)},a.that=function(t,e,n){if(n.matches(t))return;const i=new o;throw i.appendText(`Expected ${e} to be `),n.describeTo(i),i.appendText(" instead "),n.describeMismatch(t,i),new Error(i.value)};const c=new Uint32Array(781250);function d(t,e){return t<e?e:t}function u(t,e){return t<e?t:e}function l(t,e,n,i,r,s){t[e+0]=u(n[i+0],r[s+0]),t[e+1]=u(n[i+1],r[s+1]),t[e+2]=u(n[i+2],r[s+2]),t[e+3]=d(n[i+3],r[s+3]),t[e+4]=d(n[i+4],r[s+4]),t[e+5]=d(n[i+5],r[s+5])}function f(t,e,n,i,r,s,o,a){t[e+0]=n,t[e+1]=i,t[e+2]=r,t[e+3]=s,t[e+4]=o,t[e+5]=a}function g(t,e,n,i,r,s){const o=i-t,a=s-n;return(r-e)*(o+a)+a*o}function _(t){let e=t;return e=50331903&(e|e<<16),e=50393103&(e|e<<8),e=51130563&(e|e<<4),e=153391689&(e|e<<2),e}function p(t,e,n){let i=t;return i<e&&(i=e),i<n&&(i=n),i}function m(t,e,n){let i=t;return i>e&&(i=e),i>n&&(i=n),i}function w(t,e,n){const i=t[n],r=t[n+1],s=t[n+2];f(t,e,i,r,s,i,r,s)}function y(t,e,n){const i=t[e],r=t[e+1],s=t[e+2];return function(t,e,n,i){const r=i[0],s=i[1],o=i[2],a=1023*(t-r)/(i[3]-r),h=1023*(e-s)/(i[4]-s),c=1023*(n-o)/(i[5]-o);return function(t,e,n){return _(t)|_(e)<<1|_(n)<<2}(Math.round(a),Math.round(h),Math.round(c))}(.5*(i+t[e+3]),.5*(r+t[e+4]),.5*(s+t[e+5]),n)}c.pointer=0;const v=c;class x{__data_buffer;__data_float32;__data_uint32;__node_count_binary=0;__node_count_leaf=0;constructor(){this.data=new ArrayBuffer(320)}estimateByteSize(){return this.data.byteLength+248}getTotalBoxCount(){return this.__node_count_binary+this.__node_count_leaf}get binary_node_count(){return this.__node_count_binary}get leaf_node_count(){return this.__node_count_leaf}getLeafBlockAddress(){return 6*this.__node_count_binary}get float32(){return this.__data_float32}get uint32(){return this.__data_uint32}set data(t){this.__data_buffer=t,this.__data_float32=new Float32Array(this.__data_buffer),this.__data_uint32=new Uint32Array(this.__data_buffer)}get data(){return this.__data_buffer}getNodeAddress(t){const e=this.__node_count_binary,n=t-e;return n<0?6*t:6*e+7*n}initialize_structure(){const t=4*(6*this.__node_count_binary+7*this.__node_count_leaf);this.__data_buffer.byteLength<t&&(this.data=new ArrayBuffer(t))}setLeafCount(t){this.__node_count_leaf=t;const e=function(t){let e=t-1;return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e}(t);this.__node_count_binary=t<=1?e:e-1}setLeafData(t,e,n,i,r,s,o,a){const h=7*t+6*this.__node_count_binary;f(this.__data_float32,h,n,i,r,s,o,a),this.__data_uint32[h+6]=e}readBounds(t,e,n){h(this.__data_float32,t,e,n,6)}readLeafPayload(t){const e=this.getLeafBlockAddress()+7*t+6;return this.__data_uint32[e]}compute_total_surface_area(){let t=0;const e=new Float32Array(6);for(let n=0;n<this.getTotalBoxCount();n++){let i;i=n<this.__node_count_binary?6*n:7*(n-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(i,e,0),t+=g(e[0],e[1],e[2],e[3],e[4],e[5])}return t}__compute_bounds_area_of_3_boxes(t,e,n){const i=this.__data_float32;return g(m(i[t+0],i[e+0],i[n+0]),m(i[t+1],i[e+1],i[n+1]),m(i[t+2],i[e+2],i[n+2]),p(i[t+3],i[e+3],i[n+3]),p(i[t+4],i[e+4],i[n+4]),p(i[t+5],i[e+5],i[n+5]))}__fitness_function_should_swap_leaves_sah(t,e){const n=d(t-1,0),i=u(t+1,this.__node_count_leaf-1),r=this.getLeafBlockAddress(),s=7*t+r,o=7*n+r,a=7*i+r,h=7*e+r,c=7*d(e-1,0)+r,l=7*u(e+1,this.__node_count_leaf-1)+r;return this.__compute_bounds_area_of_3_boxes(o,s,a)+this.__compute_bounds_area_of_3_boxes(c,h,l)-(this.__compute_bounds_area_of_3_boxes(o,h,a)+this.__compute_bounds_area_of_3_boxes(c,s,l))}sort_bubble_sah(){const t=this.__node_count_leaf;for(let e=0;e<t;e++)for(let n=e+1;n<t;n++)this.__fitness_function_should_swap_leaves_sah(e,n)>0&&this.__swap_leaves(e,n)}sort_morton(t){const e=6*this.__node_count_binary;if(this.__node_count_leaf<2)return;let n,i,r=2;v[0]=0,v[1]=this.__node_count_leaf-1;const s=this.__data_float32;for(;r>0;){r-=2;const o=v[r+1],a=v[r];n=a,i=o;const h=y(s,7*(a+o>>1)+e,t);for(;n<=i;){for(;y(s,7*n+e,t)<h;)n++;for(;y(s,7*i+e,t)>h;)i--;n<=i&&(n!==i&&this.__swap_leaves(n,i),n++,i--)}a<i&&(v[r++]=a,v[r++]=i),n<o&&(v[r++]=n,v[r++]=o)}}__swap_leaves(t,e){const n=this.getLeafBlockAddress(),i=7*t+n,r=7*e+n;!function(t,e,n,i,r){let s,o,a;for(a=0;a<7;a++){s=e+a,o=i+a;const r=n[o];n[o]=t[s],t[s]=r}}(this.__data_float32,i,this.__data_float32,r)}build(){const t=this.__node_count_binary,e=6*t;let n,i,r,s,o=Math.floor(Math.log(t)/Math.log(2));r=Math.pow(2,o),i=6*(r-1);const a=this.__node_count_leaf,c=this.__data_float32;for(n=0;n<r;n++){const t=2*n,r=t+1,s=e+7*t;r<a?l(c,i,c,s,c,e+7*r):t<a?h(c,s,c,i,6):w(this.__data_float32,i,i-6),i+=6}for(o--;o>=0;o--)for(r=Math.pow(2,o),s=r-1,n=0;n<r;n++){const t=1+(s<<1);l(c,6*s,c,6*t,c,6*(t+1)),s++}}}function b(t,e,n,i,r,s){const o=3*i,a=3*r,h=3*s,c=n[o],d=n[o+1],u=n[o+2],l=n[a],f=n[a+1],g=n[a+2],_=n[h],w=n[h+1],y=n[h+2],v=m(c,l,_),x=m(d,f,w),b=m(u,g,y),A=p(c,l,_),E=p(d,f,w),S=p(u,g,y);t.setLeafData(e,e,v,x,b,A,E,S)}function A(t,e,n){return t<e?e:t>n?n:t}const E=function(t,e,n){return(e-t)*n+t},S="uint8",M="uint16",U="uint32",$="int8",F="int16",z="int32",C="float32",B="float64";function V(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return S;case Uint16Array:return M;case Uint32Array:return U;case Int8Array:return $;case Int16Array:return F;case Int32Array:return z;case Float32Array:return C;case Float64Array:return B;default:throw new Error("unsupported constructor type")}}const q={[S]:Uint8Array,[M]:Uint16Array,[U]:Uint32Array,[$]:Int8Array,[F]:Int16Array,[z]:Int32Array,float16:Uint16Array,[C]:Float32Array,[B]:Float64Array},L=[],T=[],I="undefined"!=typeof Uint8Array?Uint8Array:Array,N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)L[t]=N[t],T[N.charCodeAt(t)]=t;function k(t,e,n){const i=[];for(let s=e;s<n;s+=3){const e=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]);i.push(L[(r=e)>>18&63]+L[r>>12&63]+L[r>>6&63]+L[63&r])}var r;return i.join("")}T["-".charCodeAt(0)]=62,T["_".charCodeAt(0)]=63;class O{static encode(t){return function(t){let e;const n=t.length,i=n%3,r=[],s=16383,o=n-i;for(let e=0;e<o;e+=s){const n=k(t,e,e+s>o?o:e+s);r.push(n)}return 1===i?(e=t[n-1],r.push(L[e>>2]+L[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(L[e>>10]+L[e>>4&63]+L[e<<2&63]+"=")),r.join("")}(new Uint8Array(t))}static decode(t){return function(t){var e,n,i=function(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}(t),r=i[0],s=i[1],o=new I(function(t,e,n){return 3*(e+n)/4-n}(0,r,s)),a=0,h=s>0?r-4:r;for(n=0;n<h;n+=4)e=T[t.charCodeAt(n)]<<18|T[t.charCodeAt(n+1)]<<12|T[t.charCodeAt(n+2)]<<6|T[t.charCodeAt(n+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=T[t.charCodeAt(n)]<<2|T[t.charCodeAt(n+1)]>>4,o[a++]=255&e),1===s&&(e=T[t.charCodeAt(n)]<<10|T[t.charCodeAt(n+1)]<<4|T[t.charCodeAt(n+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o}(t).buffer}}class D{constructor(t=[],e=1,n=0,i=0){if(!Number.isInteger(e)||e<0)throw new Error(`itemSize must be a non-negative integer, instead was ${e}`);if(!Number.isInteger(n)||n<0)throw new Error(`width must be a non-negative integer, instead was ${n}`);if(!Number.isInteger(i)||n<0)throw new Error(`height must be a non-negative integer, instead was ${i}`);if(void 0===t)throw new Error("data was undefined");if(t.length<n*i*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${n*i*e}`);this.width=n,this.height=i,this.itemSize=e,this.data=t,this.version=0}computeMax(t=0){throw new Error("deprecated, use sampler2d_channel_compute_max")}computeMinIndices(t,e=0,n=0){throw new Error("deprecated, use sampler2d_channel_compute_min_indices")}computeMin(t=0){throw new Error("deprecated, use sampler2d_channel_compute_min")}get(t,e,n){const i=[];return this.sampleBilinear(t,e,i,0),void 0!==n?(n.readFromArray(i,0),n):i[0]}sampleCatmullRomUV(t,e,n){const i=this.itemSize;for(let r=0;r<i;r++)n[r]=this.sampleChannelCatmullRomUV(t,e,r)}sampleChannelCatmullRomUV(t,e,n){const i=t*this.width-.5,r=e*this.height-.5;return this.sampleChannelCatmullRom(i,r,n)}sampleChannelCatmullRom(t,e,n){const i=Math.floor(t),r=Math.floor(e),s=t-i,o=e-r,a=s*(s*(1-.5*s)-.5),h=o*(o*(1-.5*o)-.5),c=s*(.5+s*(2-1.5*s)),d=o*(.5+o*(2-1.5*o)),u=s*s*(.5*s-.5),l=o*o*(.5*o-.5),f=1+s*s*(1.5*s-2.5)+c,g=1+o*o*(1.5*o-2.5)+d,_=i-1,p=r-1,m=i+2,w=r+2,y=i+c/f,v=r+d/g;let x=0;return x+=this.sampleChannelBilinear(_,p,n)*a*h,x+=this.sampleChannelBilinear(y,p,n)*f*h,x+=this.sampleChannelBilinear(m,p,n)*u*h,x+=this.sampleChannelBilinear(_,v,n)*a*g,x+=this.sampleChannelBilinear(y,v,n)*f*g,x+=this.sampleChannelBilinear(m,v,n)*u*g,x+=this.sampleChannelBilinear(_,w,n)*a*l,x+=this.sampleChannelBilinear(y,w,n)*f*l,x+=this.sampleChannelBilinear(m,w,n)*u*l,x}sampleBicubicUV(t,e,n){const i=this.itemSize;for(let r=0;r<i;r++)n[r]=this.sampleChannelBicubicUV(t,e,r)}sampleChannelBicubicUV(t,e,n){const i=t*this.width,r=e*this.height;return this.sampleChannelBicubic(i-.5,r-.5,n)}sampleChannelBicubic(t,e,n){const i=this.itemSize,r=this.width,s=this.height,o=this.data,a=r*i,h=r-1,c=s-1,l=A(t,0,h),f=A(e,0,c),g=0|l,_=0|f,p=l-g,m=f-_,w=d(0,g-1),y=d(0,_-1),v=u(h,g+1),x=u(c,_+1),b=u(h,v+1),E=y*a+n,S=_*a+n,M=x*a+n,U=u(c,x+1)*a+n,$=w*i,F=g*i,z=v*i,C=b*i,B=o[E+$],V=o[E+F],q=o[E+z],L=o[E+C],T=o[S+$],I=o[S+F],N=o[S+z],k=o[S+C],O=o[M+$],D=o[M+F],R=o[M+z],J=o[M+C],P=o[U+$],W=o[U+F],H=o[U+z],G=o[U+C],Y=j(p,B,V,q,L),K=j(p,T,I,N,k),Q=j(p,O,D,R,J),X=j(p,P,W,H,G);return j(m,Y,K,Q,X)}sampleBilinearUV(t,e,n,i=0){const r=this.itemSize;for(let s=0;s<r;s++)n[s+i]=this.sampleChannelBilinearUV(t,e,s)}sampleBilinear(t,e,n,i=0){const r=this.itemSize;for(let s=0;s<r;s++)n[s+i]=this.sampleChannelBilinear(t,e,s)}sampleChannelBilinearUV(t,e,n){const i=t*this.width-.5,r=e*this.height-.5;return this.sampleChannelBilinear(i,r,n)}sampleChannelBilinear(t,e,n){const i=this.itemSize,r=this.width,s=r*i,o=this.height-1,a=A(t,0,r-1),h=A(e,0,o),c=0|a,d=0|h,u=d*s,l=c*i+n,f=u+l;let g,_;g=a===c?c:c+1,_=h===d?d:d+1;const p=this.data,m=p[f];if(c===g&&d===_)return m;const w=a-c,y=h-d,v=g*i+n,x=_*s,b=x+l,S=x+v,M=p[u+v],U=p[b],$=p[S],F=E(m,M,w),z=E(U,$,w);return E(F,z,y)}sampleNearestUV(t,e,n){const i=this.width,r=this.height,s=Math.round(t*i-.5),o=Math.round(e*r-.5);this.read(A(s,0,i-1),A(o,0,r-1),n)}readChannel(t,e,n){const i=(e*this.width+t)*this.itemSize+n;return this.data[i]}read(t,e,n){const i=this.width,r=this.itemSize,s=(e*i+t)*r;for(let t=0;t<r;t++){const e=this.data[s+t];n[t]=e}}sample(t,e,n){const i=[];return this.sampleBilinear(t*(this.width-1),e*(this.height-1),i,0),n.readFromArray(i),i[0]}point2index(t,e){return t+e*this.width}index2point(t,e){const n=this.width,i=t%n,r=t/n|0;e.set(i,r)}copyWithMargin(t,e,n,i,r,s,o,a,h,c,d){const u=this.itemSize,l=t.itemSize,f=Math.min(u,l),g=u*this.width,_=l*t.width,p=t.data,m=this.data;let w,y,v,x,b,A,E,S,M;for(M=n*_+e*u,y=Math.max(0,r-c),b=r;y<b;y++)for(A=y*g,w=Math.max(0,i-a),x=i;w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];for(E=n*_,y=Math.max(0,r-c),b=r;y<b;y++)for(A=y*g,w=0;w<s;w++)for(S=A+(w+i)*u,M=E+(w+e)*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=n*_+(e+s-1)*u,y=Math.max(0,r-c),b=r;y<b;y++)for(A=y*g,w=i+s,x=Math.min(this.width,w+h);w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];for(y=0;y<o;y++)for(A=(y+r)*g,E=(y+n)*_,M=E+e*u,w=Math.max(0,i-a),x=i;w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];for(this.copy(t,e,n,i,r,s,o),y=0;y<o;y++)for(A=(y+r)*g,E=(y+n)*_,M=E+(e+s-1)*u,w=i+s,x=Math.min(this.width,w+h);w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=(n+o-1)*_+e*u,y=r+s,b=Math.min(this.height,y+d);y<b;y++)for(A=y*g,w=Math.max(0,i-a),x=i;w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];for(E=(n+o-1)*_,y=r+s,b=Math.min(this.height,y+d);y<b;y++)for(A=y*g,w=0;w<s;w++)for(S=A+(w+i)*u,M=E+(w+e)*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=(n+o-1)*_+(e+s-1)*u,y=r+s,b=Math.min(this.height,y+d);y<b;y++)for(A=y*g,w=i+s,x=Math.min(this.width,w+h);w<x;w++)for(S=A+w*u,v=0;v<f;v++)m[S+v]=p[M+v];this.version++}copy(t,e,n,i,r,s,o){const a=Math.min(s,t.width-e,this.width-i),h=Math.min(o,t.height-n,this.height-r),c=this.itemSize,d=t.itemSize,u=Math.min(c,d),l=c*this.width,f=d*t.width,g=t.data,_=this.data;let p,m,w;for(m=0;m<h;m++){const t=(m+r)*l,s=(m+n)*f;for(p=0;p<a;p++){const n=t+(p+i)*c,r=s+(p+e)*d;for(w=0;w<u;w++)_[n+w]=g[r+w]}}this.version++}copy_sameItemSize(t,e,n,i,r,s,o){const a=this.itemSize;t.itemSize;const h=Math.min(s,t.width-e,this.width-i),c=Math.min(o,t.height-n,this.height-r),d=a*this.width,u=a*t.width,l=t.data,f=this.data,g=h*a;let _,p;for(_=0;_<c;_++){const t=(_+r)*d+i*a,s=(_+n)*u+e*a;for(p=0;p<g;p++)f[t+p]=l[s+p]}this.version++}paint(t,e,n,i,r,s,o,a=0){let h;if(0!==a)throw new Error(`Unsupported blendType(=${a})`);h=R;const c=Math.min(s,t.width-e,this.width-i),d=Math.min(o,t.height-n,this.height-r),u=Math.max(0,-i),l=[0,0,0,255],f=[0,0,0,255],g=[];let _,p;for(p=Math.max(0,-r);p<d;p++)for(_=u;_<c;_++){const e=Math.round(_+i),s=Math.round(p+r);this.read(e,s,l);const o=Math.round(_+n),a=Math.round(p+n);t.read(o,a,f),h(f,l,g),this.set(e,s,g)}}zeroFill(t,e,n,i){const r=A(t,0,this.width),s=A(e,0,this.height),o=A(t+n,0,this.width),a=A(e+i,0,this.height),h=this.data,c=this.itemSize,d=c*this.width,u=r*c,l=o*c;let f;for(f=s;f<a;f++){const t=f*d;h.fill(0,t+u,t+l)}this.version++}fill_channel(t,e){const n=this.itemSize,i=this.data,r=i.length;for(let s=t;s<r;s+=n)i[s]=e;this.version++}fill(t,e,n,i,r){const s=this.width,o=this.height,a=A(t,0,s),h=A(e,0,o),c=A(t+n,0,s),d=A(e+i,0,o),u=this.data,l=this.itemSize,f=l*s;let g,_,p;for(g=h;g<d;g++){const t=g*f;for(_=a;_<c;_++){const e=t+_*l;for(p=0;p<l;p++)u[e+p]=r[p]}}this.version++}writeChannel(t,e,n,i){const r=(e*this.width+t)*this.itemSize+n;this.data[r]=i,this.version++}set(t,e,n){const i=this.data,r=this.itemSize,s=r*this.width*e+t*r;for(let t=0;t<r;t++)i[s+t]=n[t];this.version++}traverseCircle(t,e,n,i){let r,s;const o=0|t,a=0|e,h=n*n,c=Math.ceil(n);for(s=-c;s<=c;s++){const t=s*s;for(r=-c;r<=c;r++)r*r+t<=h&&i(o+r,a+s,this)}}resize(t,e,n=!0){const i=this.width,r=this.height;if(i===t&&r===e)return;const s=this.itemSize,o=t*e*s,a=this.data,h=new(function(t){if(t instanceof Int8Array)return Int8Array;if(t instanceof Int16Array)return Int16Array;if(t instanceof Int32Array)return Int32Array;if(t instanceof Uint8Array)return Uint8Array;if(t instanceof Uint8ClampedArray)return Uint8ClampedArray;if(t instanceof Uint16Array)return Uint16Array;if(t instanceof Uint32Array)return Uint32Array;if(t instanceof Float32Array)return Float32Array;if(t instanceof Float64Array)return Float64Array;if(Array.isArray(t))return Array;throw new TypeError("Unsupported array type")}(a))(o);if(n)if(t===i)h.set(a.subarray(0,Math.min(a.length,o)));else{const n=u(e,r),o=u(t,i);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const r=(e*t+n)*s,o=(e*i+n)*s;for(let t=0;t<s;t++)h[r+t]=a[o+t]}}this.width=t,this.height=e,this.data=h,this.version++}computeByteSize(){let t;return t=Array.isArray(this.data)?8*this.data.length:this.data.buffer.byteLength,t+280}toBinaryBuffer(t){throw new Error("Deprecated, use Sampler2DSerializationAdapter instead")}fromBinaryBuffer(t){throw new Error("Deprecated, use Sampler2DSerializationAdapter instead")}equals(e){return this.width===e.width&&this.height===e.height&&this.itemSize===e.itemSize&&function(e,n){if(e===n)return!0;const i=e.length;if(i!==n.length)return!1;if(i<128)return t(e,n);const r=e.byteLength;if(r!==n.byteLength)return!1;const s=e.constructor;if(s!==n.constructor)return!1;const o=e.buffer,a=n.buffer;if(o===a&&e.byteOffset===n.byteOffset)return!0;let h=e,c=n;const d=s.BYTES_PER_ELEMENT;return d<4&&r%4==0?(h=new Uint32Array(o,e.byteOffset,r/4),c=new Uint32Array(a,n.byteOffset,r/4)):d<2&&r%2==0&&(h=new Uint16Array(o,e.byteOffset,r/2),c=new Uint16Array(a,n.byteOffset,r/2)),t(h,c)}(this.data,e.data)}hash(){let t=((65535&this.width)<<16|65535&this.height)^this.itemSize;const e=this.data.length,n=Math.max(1,Math.ceil(e/509));return t^=function(t,e,n,i){let r=n;for(let e=0;e<n;e+=i)r=31*r+t[e]|0;return r}(this.data,0,e,n),t}clone(){let t;return t=Array.isArray(this.data)?this.data.slice():new(0,this.data.constructor)(this.data),new D(t,this.itemSize,this.width,this.height)}toJSON(){const t=O.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:V(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:i,data:r}){const s=function(t){const e=q[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(i);if("string"==typeof r){const t=O.decode(r);this.data=new s(t)}else{if(!Array.isArray(r))throw new Error("Unsupported data format");this.data=new s(r)}this.height=t,this.width=e,this.itemSize=n}static uint8clamped(t,e,n){const i=new Uint8ClampedArray(e*n*t);return new D(i,t,e,n)}static uint8(t,e,n){const i=new Uint8Array(e*n*t);return new D(i,t,e,n)}static uint16(t,e,n){const i=new Uint16Array(e*n*t);return new D(i,t,e,n)}static uint32(t,e,n){const i=new Uint32Array(e*n*t);return new D(i,t,e,n)}static int8(t,e,n){const i=new Int8Array(e*n*t);return new D(i,t,e,n)}static int16(t,e,n){const i=new Int16Array(e*n*t);return new D(i,t,e,n)}static int32(t,e,n){const i=new Int32Array(e*n*t);return new D(i,t,e,n)}static float32(t,e,n){const i=new Float32Array(e*n*t);return new D(i,t,e,n)}static float64(t,e,n){const i=new Float64Array(e*n*t);return new D(i,t,e,n)}}function j(t,e,n,i,r){return.5*(i-e+(2*e-5*n+4*i-r+(3*(n-i)+r-e)*t)*t)*t+n}function R(t,e,n){const i=t[3]/255,r=e[3]/255;n[0]=t[0]*i+e[0]*(1-i),n[1]=t[1]*i+e[1]*(1-i),n[2]=t[2]*i+e[2]*(1-i),n[3]=255*(i+r*(1-i))}D.prototype.isSampler2D=!0,D.typeName="Sampler2D";const J={build:function(t,e,n,i,r,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let d=0,u=0;const l=o*a,f=new Float32Array(3*l),g=new Float32Array(3*l),_=new Float32Array(2*l);let p,m;const w=n.y/r.y/c,y=n.x/r.x/h,v=e.y/r.y,x=e.x/r.x,b=r.x*i.x,A=r.y*i.y;let E,S,M;for(p=0;p<a;p++){const e=p*w+v;for(M=e*A,m=0;m<o;m++){const n=m*y+x;E=n*b,S=t.sampleChannelBicubicUV(n,e,0),f[d]=E,f[d+1]=S,f[d+2]=M,_[u]=n,_[u+1]=e,d+=3,u+=2}}d=0;const U=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(p=0;p<c;p++)for(m=0;m<h;m++){const t=m+o*p,e=m+o*(p+1),n=m+1+o*(p+1),i=m+1+o*p;U[d]=t,U[d+1]=e,U[d+2]=i,U[d+3]=e,U[d+4]=n,U[d+5]=i,d+=6}return function(t,e,n){let i,r,s,o,a,h,c,d,u,l,f,g,_,p,m,w,y,v,x,b,A,E=0;const S=n.length;for(;E<S;E+=3)i=3*n[E],r=3*n[E+1],s=3*n[E+2],o=t[i],a=t[i+1],h=t[i+2],c=t[r],d=t[r+1],u=t[r+2],l=t[s],f=t[s+1],g=t[s+2],_=l-c,p=f-d,m=g-u,w=o-c,y=a-d,v=h-u,x=p*v-m*y,b=m*w-_*v,A=_*y-p*w,e[i]+=x,e[i+1]+=b,e[i+2]+=A,e[r]+=x,e[r+1]+=b,e[r+2]+=A,e[s]+=x,e[s+1]+=b,e[s+2]+=A;!function(t){let e,n,i,r,s=0;const o=t.length;for(;s<o;s+=3)e=t[s],n=t[s+1],i=t[s+2],r=1/Math.sqrt(e*e+n*n+i*i),t[s]*=r,t[s+1]*=r,t[s+2]*=r}(e)}(f,g,U),{indices:U,vertices:f,normals:g,uvs:_}}};function P(t,e,n=0,i=t.length){const r=n+i;for(let i=n;i<r;i++)if(t[i]===e)return t.splice(i,1),!0;return!1}function W(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function H(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}let G=0;class Y{constructor(){this.index=G++,this.v0=null,this.v1=null,this.faces=[],this.lengthSqr=-1}get byteSize(){return 128+8*this.faces.length+10}getVertexByIndex(t){if(0===t)return this.v0;if(1===t)return this.v1;throw new Error("Index out of bounds")}copy(t){this.v0=t.v0,this.v1=t.v1,this.lengthSqr=t.lengthSqr,this.faces=t.faces.slice()}clone(){const t=new Y;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,i=n.length;for(let r=0;r<i;r++)n[r].containsEdge(this)||(t(`Missing back-link from face[${r}]`),e=!1);return this.v0.containsEdge(this)||(t("Missing back-link from vertex v0"),e=!1),this.v1.containsEdge(this)||(t("Missing back-link from vertex v1"),e=!1),e}isLinked(){return this.v0.containsEdge(this)}unlink(){const t=this.v0,e=this.v1;t.removeEdge(this),t!==e&&e.removeEdge(this);const n=this.faces,i=n.length;for(let t=0;t<i;t++)n[t].removeEdge(this)}isDegenerateEdge(){return this.v0===this.v1}isTopologyBorder(){return 1===this.faces.length}get length(){return this.lengthSqr<0&&this.computeSquaredLength(),Math.sqrt(this.lengthSqr)}computeSquaredLength(){const t=this.v0,e=this.v1,n=t.x,i=t.y,r=t.z,s=n-e.x,o=i-e.y,a=r-e.z;this.lengthSqr=s*s+o*o+a*a}replaceVertex(t,e){t===this.v0&&(this.v0=e),t===this.v1&&(this.v1=e)}merge(t){const e=t.faces,n=this.faces,i=e.length;for(let r=0;r<i;r++){const i=e[r];i.removeEdge(t),-1===n.indexOf(i)&&(n.push(i),i.addUniqueEdge(this))}t.v0.removeEdge(t),t.v1.removeEdge(t)}containsFace(t){return-1!==this.faces.indexOf(t)}addFace(t){this.faces.push(t)}addUniqueFace(t){W(this.faces,t)}removeFace(t){P(this.faces,t)}getOtherVertex(t){return H(this,t)}containsVertex(t){return e=t,this.v0===e||this.v1===e;var e}containsBothVertices(t,e){return function(t,e,n){const i=t.v0,r=t.v1;return!(i!==e&&i!==n||r!==e&&r!==n)}(this,t,e)}containsSameVerticesAs(t){return this.containsBothVertices(t.v0,t.v1)}}function K(t,e,n){const i=t.length;for(let r=0;r<i;r++)t[r]===e&&(t[r]=n)}Y.prototype.isTopoEdge=!0;var Q,X="undefined"!=typeof Float32Array?Float32Array:Array;function Z(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),Q=new X(3),X!=Float32Array&&(Q[0]=0,Q[1]=0,Q[2]=0);let tt=0;class et{constructor(){this.index=tt++,this.vertices=[],this.edges=[],this.normal=[0,0,0]}get byteSize(){return 100+8*this.vertices.length+10+8*this.edges.length+10+24+10}copy(t){this.index=t.index,this.vertices=t.vertices.slice(),this.edges=t.edges.slice(),Z(this.normal,t.normal)}clone(){const t=new et;return t.copy(this),t}validate(t){let e=!0;const n=this.vertices,i=n.length;3!==i&&(t(`Expected number of vertices is 3, instead got ${i}`),e=!1);for(let r=0;r<i;r++)n[r].containsFace(this)||(t(`Missing back-link from vertex[${r}]`),e=!1);const r=this.edges,s=r.length;3!==s&&(t(`Expected number of edges is 3, instead got ${s}`),e=!1);for(let n=0;n<s;n++)r[n].containsFace(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}isLinked(){return this.vertices[0].containsFace(this)}replaceEdge(t,e){K(this.edges,t,e)}replaceVertex(t,e){K(this.vertices,t,e)}isDegenerateTopology(){const t=this.vertices,e=t[0],n=t[1],i=t[2];return e===n||e===i||n===i}unlink(){const t=this.vertices,e=t.length;for(let n=0;n<e;n++)t[n].removeFace(this);const n=this.edges,i=n.length;for(let t=0;t<i;t++)n[t].removeFace(this)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return W(this.edges,t)}removeEdge(t){P(this.edges,t)}containsEdge(t){return-1!==this.edges.indexOf(t)}computeNormal(){const t=this.vertices,e=t[0],n=t[1],i=t[2];!function(t,e,n,i){!function(t,e,n,i,r,s,o,a,h,c,d){const u=h-s,l=c-o,f=d-a,g=n-s,_=i-o,p=r-a,m=l*p-f*_,w=f*g-u*p,y=u*_-l*g,v=function(t,e,n){return t*t+e*e+n*n}(m,w,y);if(0===v)return t[0]=0,t[1]=1,void(t[2]=0);const x=1/Math.sqrt(v),b=m*x,A=w*x,E=y*x;t[0]=b,t[1]=A,t[2]=E}(t,0,e[0],e[1],e[2],n[0],n[1],n[2],i[0],i[1],i[2])}(this.normal,e,n,i)}setVertexAt(t,e){this.vertices[t]=e}containsVertex(t){return-1!==this.vertices.indexOf(t)}getEdgeNeighbours(t,e){let n=0;const i=this.edges,r=i.length;for(let s=0;s<r;s++){const r=i[s].faces,o=r.length;for(let i=0;i<o;i++){const s=r[i];s!==this&&(t[e+n]=s,n++)}}return n}}et.prototype.isTopoFace=!0;class nt{constructor(){this.index=0,this.edges=[],this.faces=[],this.x=0,this.y=0,this.z=0}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get byteSize(){return 112+8*this.edges.length+10+8*this.faces.length+10}copy(t){this.x=t.x,this.y=t.y,this.z=t.z,this.index=t.index,this.faces=t.faces.slice(),this.edges=t.edges.slice()}clone(){const t=new nt;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,i=n.length;for(let r=0;r<i;r++)n[r].containsVertex(this)||(t(`Missing back-link from face[${r}]`),e=!1);const r=this.edges,s=r.length;for(let n=0;n<s;n++)r[n].containsVertex(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}distanceTo(t){return e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z,Math.sqrt(function(t,e,n,i,r,s){const o=t-i,a=e-r,h=n-s;return o*o+a*a+h*h}(e,n,i,r,s,o));var e,n,i,r,s,o}addFace(t){this.faces.push(t)}addUniqueFace(t){return W(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){P(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return W(this.edges,t)}replaceEdge(t,e){const n=this.edges,i=n.indexOf(t);n[i]=e}containsEdge(t){return-1!==this.edges.indexOf(t)}removeEdge(t){return P(this.edges,t)}replaceAnotherVertex(t){const e=t.faces,n=e.length;let i=0;for(;i<n;i++){const n=e[i];n.replaceVertex(t,this),this.addUniqueFace(n)}const r=t.edges,s=r.length;for(i=0;i<s;i++){const e=r[i];e.replaceVertex(t,this),this.addUniqueEdge(e)}}computeNeighbourVertices(t,e){let n=0;const i=this.edges,r=i.length;for(let s=0;s<r;s++){const r=i[s].getOtherVertex(this);t[e+n]=r,n++}return n}}function it(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}nt.prototype.isTopoVertex=!0;class rt{constructor(){this.vertices=[],this.__edges=new Set,this.__faces=new Set}get byteSize(){let t=0;for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e].byteSize;for(const e of this.__edges)t+=e.byteSize;for(const e of this.__faces)t+=e.byteSize;return t}getEdges(){return this.__edges}getFaces(){return this.__faces}getFaceByIndex(t){for(const e of this.__faces)if(e.index===t)return e}validate(t){let e=!0,n="",i=0;function r(r){t(`${n}[${i}]: ${r}`),e=!1}n="Edge",i=0;const s=this.getEdges();for(let t of s){t.validate(r),this.containsVertex(t.v0)||r("Link to off-mesh vertex v0"),this.containsVertex(t.v1)||r("Link to off-mesh vertex v1");const e=t.faces,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsFace(n)||r(`Link to off-mesh face[${t}]`)}i++}const o=this.getFaces();n="Face",i=0;for(let t of o){t.validate(r);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsEdge(n)||r(`Link to off-mesh edge[${t}]`)}const s=t.vertices,o=s.length;for(let t=0;t<o;t++){const e=s[t];this.containsVertex(e)||r(`Link to off-mesh vertex[${t}]`)}i++}const a=this.vertices,h=a.length;n="Vertex";for(let t=0;t<h;t++){i=t;const e=a[t];e.validate(r);const n=e.edges,s=n.length;for(let t=0;t<s;t++){const e=n[t];this.containsEdge(e)||r(`Link to off-mesh edge[${t}]`)}const o=e.faces,h=o.length;for(let t=0;t<h;t++){const e=o[t];this.containsFace(e)||r(`Link to off-mesh face[${t}]`)}}return e}clone(){const t=new rt;return t.add(this),t}buildVertexMapping(){const t=new Map,e=this.vertices,n=e.length;for(let i=0;i<n;i++){const n=e[i];t.set(n.index,n)}return t}_addWithVertexMap(t,e){const n=t.getFaces();for(let t of n)this.addFaceCopy(t,e)}addFaceCopy(t,e){const n=new et;Z(n.normal,t.normal);const i=t.vertices;for(let t=0;t<3;t++){const r=i[t];let s=e.get(r.index);void 0===s&&(s=new nt,s.index=r.index,s.x=r.x,s.y=r.y,s.z=r.z,e.set(r.index,s),this.addVertex(s)),n.setVertexAt(t,s),s.addUniqueFace(n)}this.addFace(n);const r=n.vertices,s=r[0],o=r[1],a=r[2],h=this.ensureEdge(s,o),c=this.ensureEdge(o,a),d=this.ensureEdge(a,s);h.addUniqueFace(n),c.addUniqueFace(n),d.addUniqueFace(n),n.addUniqueEdge(h),n.addUniqueEdge(c),n.addUniqueEdge(d)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){W(this.vertices,t)}removeVertex(t){var e;e=t,P(this.vertices,e)}containsVertex(t){return-1!==this.vertices.indexOf(t)}addEdge(t){this.__edges.add(t)}addUniqueEdge(t){this.__edges.add(t)}removeEdge(t){var e;e=t,this.__edges.delete(e)}containsEdge(t){return this.__edges.has(t)}addFace(t){this.__faces.add(t)}injectManyFaces(t){for(let e of t)this.injectFace(e)}injectFace(t){this.addFace(t);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.addUniqueEdge(n)}const i=t.vertices,r=i.length;for(let t=0;t<r;t++){const e=i[t];this.addUniqueVertex(e)}}removeFace(t){var e;e=t,this.__faces.delete(e)}containsFace(t){return this.__faces.has(t)}ensureEdge(t,e){const n=t.edges,i=n.length;for(let r=0;r<i;r++){const i=n[r];if(H(i,t)===e)return i}const r=new Y;return r.v0=t,r.v1=e,t.edges.push(r),e.edges.push(r),this.__edges.add(r),r}mergeEdges(){const t=this.getEdges();for(let e of t){const n=e.v0,i=e.v1;for(let r of t){if(e===r)continue;const t=r.v0,s=r.v1;if(n===t){if(i!==s)continue}else{if(n!==s)continue;if(i!==t)continue}this.removeEdge(r),e.merge(r)}}}computeEdgeSquaredLengths(){const t=this.getEdges();for(let e of t)e.computeSquaredLength()}build(t,e){const n=e.length,i=t.length/3,r=this.vertices;for(let e=0;e<i;e++){const n=3*e,i=new nt;i.index=e,i.x=t[n],i.y=t[n+1],i.z=t[n+2],r[e]=i}const s=n/3,o=this.getFaces();for(let t=0;t<s;t++){const n=3*t,i=e[n],s=e[n+1],a=e[n+2],h=r[i],c=r[s],d=r[a],u=new et;u.index=t;const l=this.ensureEdge(h,c),f=this.ensureEdge(c,d),g=this.ensureEdge(d,h);l.faces.push(u),f.faces.push(u),g.faces.push(u),u.vertices.push(h,c,d),u.edges.push(l,f,g),h.faces.push(u),c.faces.push(u),d.faces.push(u),o.add(u)}}toString(){return`TopoMesh{ vertices: ${it(this.vertices.length)}, edges: ${it(this.getEdges().size)}, faces: ${it(this.getFaces().size)} }`}}rt.prototype.isTopoMesh=!0,self.Lib={build_bvh(t,e){const n=new x;return function(t,e,n){const i=n.length/3;t.setLeafCount(i),t.initialize_structure();for(let r=0;r<i;r++){const i=3*r;b(t,r,e,n[i],n[i+1],n[i+2])}t.build()}(n,t,e),n},Sampler2D:D,BufferedGeometryArraysBuilder:J,tensionOptimizeUV:function(t,e,n,i){const r=new rt;r.build(t,n),r.computeEdgeSquaredLengths();const s=t.length/3;for(let t=0;t<i;t++)t:for(let t=0;t<s;t++){const n=r.vertices[t],i=n.edges,s=i.length;if(0===s)continue;let o=0,a=0,h=0;for(let t=0;t<s;t++){const r=i[t];if(r.isTopologyBorder())continue t;const s=2*r.getOtherVertex(n).index,c=e[s],d=e[s+1],u=1/r.lengthSqr;o+=c*u,a+=d*u,h+=u}const c=o/h,d=a/h,u=2*n.index;e[u]=c,e[u+1]=d}},sampler2d_channel_compute_min:function(t,e=0){const n=t.itemSize,i=t.data,r=i.length;if(0===r)return;let s=i[e],o=e;for(let t=e+n;t<r;t+=n){const e=i[t];s>e&&(s=e,o=t)}const a=t.width,h=o/n|0;return{index:o,value:s,x:h%a,y:h/a|0}},sampler2d_channel_compute_max:function(t,e=0){const n=t.itemSize,i=t.data,r=i.length;if(0===r)return;let s=i[e],o=e;for(let t=e+n;t<r;t+=n){const e=i[t];s<e&&(s=e,o=t)}const a=t.width,h=o/n|0;return{index:o,value:s,x:h%a,y:h/a|0}}};
1
+ function t(t,e){const n=t.length;if(n!==e.length)return!1;let i=0;for(;i<n;i++)if(t[i]!==e[i])return!1;return!0}class e{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,n,i){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,n,i){throw new Error("Not Implemented")}}class n{describeTo(t){throw new Error("Not Implemented")}}class i extends n{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class r{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new i(t)}}class s extends e{appendDescriptionOf(t){return t.describeTo(this),this}#e(t){this.appendText('"'),this.appendText(t),this.appendText('"')}appendValue(t){return null==t?this.appendText("null"):void 0===t?this.appendText("undefined"):"string"==typeof t?this.#e(t):"number"==typeof t?this.appendText(function(t){return String(t)}(t)):Array.isArray(t)?this.appendValueList("[",", ","]",t):(this.appendText("<"),this.appendText(function(t){try{return String(t)}catch(t){return"VALUE@0"}}(t)),this.appendText(">")),this}appendValueList(t,e,n,i){return this.appendList(t,e,n,new r(i)),this}appendList(t,e,n,i){let r=!1;this.appendText(t);const s=i[Symbol.iterator]();for(let t=s.next();!0!==t.done;t=s.next())r&&this.appendText(e),this.appendDescriptionOf(t.value),r=!0;return this.appendText(n),this}}class o extends s{value="";appendText(t){return this.value+=t,this}}function a(t,e){if(!t)throw new Error(e||"AssertionError")}function h(t,e,n,i,r){let s,o,a;for(a=0;a<r;a++)s=e+a,o=i+a,n[o]=t[s]}a.enum=function(t,e,n="value"){for(let n in e)if(e[n]===t)return;throw new Error(`${n}(=${t}) is not a valid enumerable value, valid values are: [${Object.values(e).join(", ")}]`)},a.notEqual=function(t,e,n){a(t!==e,n)},a.notOk=function(t,e){a(!t,e)},a.equal=function(t,e,n){if(t!==e)throw new Error(void 0!==n?n:`${t} !== ${e}`)},a.logicalyEqual=function(t,e,n){},a.ok=a,a.greaterThan=function(t,e,n){if(!(t>e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} > ${e}.`,new Error(i)}},a.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} >= ${e}.`,new Error(i)}},a.lessThan=function(t,e,n){if(!(t<e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} < ${e}.`,new Error(i)}},a.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} <= ${e}.`,new Error(i)}},a.typeOf=function(t,e,n="value"){const i=typeof t;if(i!==e)throw new Error(`expected ${n} to be ${e}, instead was '${i}'(=${t})`)},a.arrayHas=function(t,e,n="Array does not contain the item"){},a.arrayHasNo=function(t,e,n="Array contains the item"){},a.arrayEqual=function(e,n,i="Arrays are not equal"){if(!t(e,n))throw new Error(i)},a.isInstanceOf=function(t,e,n="value",i=e.name){},a.isNumber=function(t,e="value"){const n=typeof t;if("number"!==n)throw new Error(`expected ${e} to be a number, instead was '${n}'(=${t})`)},a.isString=function(t,e="value"){const n=typeof t;if("string"!==n)throw new Error(`expected ${e} to be a string, instead was '${n}'(=${t})`)},a.isBoolean=function(t,e="value"){const n=typeof t;if("boolean"!==n)throw new Error(`expected ${e} to be a boolean, instead was '${n}'(=${t})`)},a.isFunction=function(t,e="value"){const n=typeof t;if("function"!==n)throw new Error(`expected ${e} to be a function, instead was '${n}'(=${t})`)},a.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},a.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},a.isArray=function(t,e="value"){if(!Array.isArray(t))throw new Error(`expected ${e} to be an array, instead was something else (typeof ='${typeof t}')`)},a.isArrayLike=function(t,e="value"){if(!(Array.isArray(t)||(n=t,n instanceof Int8Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray||n instanceof Int16Array||n instanceof Uint16Array||n instanceof Int32Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array)))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`);var n},a.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},a.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},a.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},a.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},a.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)},a.that=function(t,e,n){if(n.matches(t))return;const i=new o;throw i.appendText(`Expected ${e} to be `),n.describeTo(i),i.appendText(" instead "),n.describeMismatch(t,i),new Error(i.value)};const c=new Uint32Array(781250);function d(t,e){return t<e?e:t}function u(t,e){return t<e?t:e}function l(t,e,n,i,r,s){t[e+0]=u(n[i+0],r[s+0]),t[e+1]=u(n[i+1],r[s+1]),t[e+2]=u(n[i+2],r[s+2]),t[e+3]=d(n[i+3],r[s+3]),t[e+4]=d(n[i+4],r[s+4]),t[e+5]=d(n[i+5],r[s+5])}function f(t,e,n,i,r,s,o,a){t[e+0]=n,t[e+1]=i,t[e+2]=r,t[e+3]=s,t[e+4]=o,t[e+5]=a}function g(t,e,n,i,r,s){const o=i-t,a=s-n;return(r-e)*(o+a)+a*o}function _(t){let e=t;return e=50331903&(e|e<<16),e=50393103&(e|e<<8),e=51130563&(e|e<<4),e=153391689&(e|e<<2),e}function p(t,e,n){let i=t;return i<e&&(i=e),i<n&&(i=n),i}function m(t,e,n){let i=t;return i>e&&(i=e),i>n&&(i=n),i}function y(t,e,n){const i=t[n],r=t[n+1],s=t[n+2];f(t,e,i,r,s,i,r,s)}function w(t,e,n){const i=t[e],r=t[e+1],s=t[e+2];return function(t,e,n,i){const r=i[0],s=i[1],o=i[2],a=1023*(t-r)/(i[3]-r),h=1023*(e-s)/(i[4]-s),c=1023*(n-o)/(i[5]-o);return function(t,e,n){return _(t)|_(e)<<1|_(n)<<2}(Math.round(a),Math.round(h),Math.round(c))}(.5*(i+t[e+3]),.5*(r+t[e+4]),.5*(s+t[e+5]),n)}c.pointer=0;const v=c;class x{__data_buffer;__data_float32;__data_uint32;__node_count_binary=0;__node_count_leaf=0;constructor(){this.data=new ArrayBuffer(320)}estimateByteSize(){return this.data.byteLength+248}getTotalBoxCount(){return this.__node_count_binary+this.__node_count_leaf}get binary_node_count(){return this.__node_count_binary}get leaf_node_count(){return this.__node_count_leaf}getLeafBlockAddress(){return 6*this.__node_count_binary}get float32(){return this.__data_float32}get uint32(){return this.__data_uint32}set data(t){this.__data_buffer=t,this.__data_float32=new Float32Array(this.__data_buffer),this.__data_uint32=new Uint32Array(this.__data_buffer)}get data(){return this.__data_buffer}getNodeAddress(t){const e=this.__node_count_binary,n=t-e;return n<0?6*t:6*e+7*n}initialize_structure(){const t=4*(6*this.__node_count_binary+7*this.__node_count_leaf);this.__data_buffer.byteLength<t&&(this.data=new ArrayBuffer(t))}setLeafCount(t){this.__node_count_leaf=t;const e=function(t){let e=t-1;return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e}(t);this.__node_count_binary=t<=1?e:e-1}setLeafData(t,e,n,i,r,s,o,a){const h=7*t+6*this.__node_count_binary;f(this.__data_float32,h,n,i,r,s,o,a),this.__data_uint32[h+6]=e}readBounds(t,e,n){h(this.__data_float32,t,e,n,6)}readLeafPayload(t){const e=this.getLeafBlockAddress()+7*t+6;return this.__data_uint32[e]}compute_total_surface_area(){let t=0;const e=new Float32Array(6);for(let n=0;n<this.getTotalBoxCount();n++){let i;i=n<this.__node_count_binary?6*n:7*(n-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(i,e,0),t+=g(e[0],e[1],e[2],e[3],e[4],e[5])}return t}__compute_bounds_area_of_3_boxes(t,e,n){const i=this.__data_float32;return g(m(i[t+0],i[e+0],i[n+0]),m(i[t+1],i[e+1],i[n+1]),m(i[t+2],i[e+2],i[n+2]),p(i[t+3],i[e+3],i[n+3]),p(i[t+4],i[e+4],i[n+4]),p(i[t+5],i[e+5],i[n+5]))}__fitness_function_should_swap_leaves_sah(t,e){const n=d(t-1,0),i=u(t+1,this.__node_count_leaf-1),r=this.getLeafBlockAddress(),s=7*t+r,o=7*n+r,a=7*i+r,h=7*e+r,c=7*d(e-1,0)+r,l=7*u(e+1,this.__node_count_leaf-1)+r;return this.__compute_bounds_area_of_3_boxes(o,s,a)+this.__compute_bounds_area_of_3_boxes(c,h,l)-(this.__compute_bounds_area_of_3_boxes(o,h,a)+this.__compute_bounds_area_of_3_boxes(c,s,l))}sort_bubble_sah(){const t=this.__node_count_leaf;for(let e=0;e<t;e++)for(let n=e+1;n<t;n++)this.__fitness_function_should_swap_leaves_sah(e,n)>0&&this.__swap_leaves(e,n)}sort_morton(t){const e=6*this.__node_count_binary;if(this.__node_count_leaf<2)return;let n,i,r=2;v[0]=0,v[1]=this.__node_count_leaf-1;const s=this.__data_float32;for(;r>0;){r-=2;const o=v[r+1],a=v[r];n=a,i=o;const h=w(s,7*(a+o>>1)+e,t);for(;n<=i;){for(;w(s,7*n+e,t)<h;)n++;for(;w(s,7*i+e,t)>h;)i--;n<=i&&(n!==i&&this.__swap_leaves(n,i),n++,i--)}a<i&&(v[r++]=a,v[r++]=i),n<o&&(v[r++]=n,v[r++]=o)}}__swap_leaves(t,e){const n=this.getLeafBlockAddress(),i=7*t+n,r=7*e+n;!function(t,e,n,i,r){let s,o,a;for(a=0;a<7;a++){s=e+a,o=i+a;const r=n[o];n[o]=t[s],t[s]=r}}(this.__data_float32,i,this.__data_float32,r)}build(){const t=this.__node_count_binary,e=6*t;let n,i,r,s,o=Math.floor(Math.log(t)/Math.log(2));r=Math.pow(2,o),i=6*(r-1);const a=this.__node_count_leaf,c=this.__data_float32;for(n=0;n<r;n++){const t=2*n,r=t+1,s=e+7*t;r<a?l(c,i,c,s,c,e+7*r):t<a?h(c,s,c,i,6):y(this.__data_float32,i,i-6),i+=6}for(o--;o>=0;o--)for(r=Math.pow(2,o),s=r-1,n=0;n<r;n++){const t=1+(s<<1);l(c,6*s,c,6*t,c,6*(t+1)),s++}}}function b(t,e,n,i,r,s){const o=3*i,a=3*r,h=3*s,c=n[o],d=n[o+1],u=n[o+2],l=n[a],f=n[a+1],g=n[a+2],_=n[h],y=n[h+1],w=n[h+2],v=m(c,l,_),x=m(d,f,y),b=m(u,g,w),A=p(c,l,_),E=p(d,f,y),S=p(u,g,w);t.setLeafData(e,e,v,x,b,A,E,S)}function A(t,e,n){return t<e?e:t>n?n:t}const E=function(t,e,n){return(e-t)*n+t},S="uint8",M="uint16",U="uint32",$="int8",F="int16",z="int32",C="float32",B="float64";function V(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return S;case Uint16Array:return M;case Uint32Array:return U;case Int8Array:return $;case Int16Array:return F;case Int32Array:return z;case Float32Array:return C;case Float64Array:return B;default:throw new Error("unsupported constructor type")}}const q={[S]:Uint8Array,[M]:Uint16Array,[U]:Uint32Array,[$]:Int8Array,[F]:Int16Array,[z]:Int32Array,float16:Uint16Array,[C]:Float32Array,[B]:Float64Array},L=[],T=[],I="undefined"!=typeof Uint8Array?Uint8Array:Array,N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)L[t]=N[t],T[N.charCodeAt(t)]=t;function k(t,e,n){const i=[];for(let s=e;s<n;s+=3){const e=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]);i.push(L[(r=e)>>18&63]+L[r>>12&63]+L[r>>6&63]+L[63&r])}var r;return i.join("")}T["-".charCodeAt(0)]=62,T["_".charCodeAt(0)]=63;class O{static encode(t){return function(t){let e;const n=t.length,i=n%3,r=[],s=16383,o=n-i;for(let e=0;e<o;e+=s){const n=k(t,e,e+s>o?o:e+s);r.push(n)}return 1===i?(e=t[n-1],r.push(L[e>>2]+L[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(L[e>>10]+L[e>>4&63]+L[e<<2&63]+"=")),r.join("")}(new Uint8Array(t))}static decode(t){return function(t){var e,n,i=function(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}(t),r=i[0],s=i[1],o=new I(function(t,e,n){return 3*(e+n)/4-n}(0,r,s)),a=0,h=s>0?r-4:r;for(n=0;n<h;n+=4)e=T[t.charCodeAt(n)]<<18|T[t.charCodeAt(n+1)]<<12|T[t.charCodeAt(n+2)]<<6|T[t.charCodeAt(n+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=T[t.charCodeAt(n)]<<2|T[t.charCodeAt(n+1)]>>4,o[a++]=255&e),1===s&&(e=T[t.charCodeAt(n)]<<10|T[t.charCodeAt(n+1)]<<4|T[t.charCodeAt(n+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o}(t).buffer}}class D{constructor(t=[],e=1,n=0,i=0){if(!Number.isInteger(e)||e<0)throw new Error(`itemSize must be a non-negative integer, instead was ${e}`);if(!Number.isInteger(n)||n<0)throw new Error(`width must be a non-negative integer, instead was ${n}`);if(!Number.isInteger(i)||n<0)throw new Error(`height must be a non-negative integer, instead was ${i}`);if(void 0===t)throw new Error("data was undefined");if(t.length<n*i*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${n*i*e}`);this.width=n,this.height=i,this.itemSize=e,this.data=t,this.version=0}computeMax(t=0){throw new Error("deprecated, use sampler2d_channel_compute_max")}computeMinIndices(t,e=0,n=0){throw new Error("deprecated, use sampler2d_channel_compute_min_indices")}computeMin(t=0){throw new Error("deprecated, use sampler2d_channel_compute_min")}get(t,e,n){const i=[];return this.sampleBilinear(t,e,i,0),void 0!==n?(n.readFromArray(i,0),n):i[0]}sampleCatmullRomUV(t,e,n){const i=this.itemSize;for(let r=0;r<i;r++)n[r]=this.sampleChannelCatmullRomUV(t,e,r)}sampleChannelCatmullRomUV(t,e,n){const i=t*this.width-.5,r=e*this.height-.5;return this.sampleChannelCatmullRom(i,r,n)}sampleChannelCatmullRom(t,e,n){const i=Math.floor(t),r=Math.floor(e),s=t-i,o=e-r,a=s*(s*(1-.5*s)-.5),h=o*(o*(1-.5*o)-.5),c=s*(.5+s*(2-1.5*s)),d=o*(.5+o*(2-1.5*o)),u=s*s*(.5*s-.5),l=o*o*(.5*o-.5),f=1+s*s*(1.5*s-2.5)+c,g=1+o*o*(1.5*o-2.5)+d,_=i-1,p=r-1,m=i+2,y=r+2,w=i+c/f,v=r+d/g;let x=0;return x+=this.sampleChannelBilinear(_,p,n)*a*h,x+=this.sampleChannelBilinear(w,p,n)*f*h,x+=this.sampleChannelBilinear(m,p,n)*u*h,x+=this.sampleChannelBilinear(_,v,n)*a*g,x+=this.sampleChannelBilinear(w,v,n)*f*g,x+=this.sampleChannelBilinear(m,v,n)*u*g,x+=this.sampleChannelBilinear(_,y,n)*a*l,x+=this.sampleChannelBilinear(w,y,n)*f*l,x+=this.sampleChannelBilinear(m,y,n)*u*l,x}sampleBicubicUV(t,e,n){const i=this.itemSize;for(let r=0;r<i;r++)n[r]=this.sampleChannelBicubicUV(t,e,r)}sampleChannelBicubicUV(t,e,n){const i=t*this.width,r=e*this.height;return this.sampleChannelBicubic(i-.5,r-.5,n)}sampleChannelBicubic(t,e,n){const i=this.itemSize,r=this.width,s=this.height,o=this.data,a=r*i,h=r-1,c=s-1,l=A(t,0,h),f=A(e,0,c),g=0|l,_=0|f,p=l-g,m=f-_,y=d(0,g-1),w=d(0,_-1),v=u(h,g+1),x=u(c,_+1),b=u(h,v+1),E=w*a+n,S=_*a+n,M=x*a+n,U=u(c,x+1)*a+n,$=y*i,F=g*i,z=v*i,C=b*i,B=o[E+$],V=o[E+F],q=o[E+z],L=o[E+C],T=o[S+$],I=o[S+F],N=o[S+z],k=o[S+C],O=o[M+$],D=o[M+F],R=o[M+z],J=o[M+C],P=o[U+$],W=o[U+F],H=o[U+z],G=o[U+C],Y=j(p,B,V,q,L),K=j(p,T,I,N,k),Q=j(p,O,D,R,J),X=j(p,P,W,H,G);return j(m,Y,K,Q,X)}sampleBilinearUV(t,e,n,i=0){const r=this.itemSize;for(let s=0;s<r;s++)n[s+i]=this.sampleChannelBilinearUV(t,e,s)}sampleBilinear(t,e,n,i=0){const r=this.itemSize;for(let s=0;s<r;s++)n[s+i]=this.sampleChannelBilinear(t,e,s)}sampleChannelBilinearUV(t,e,n){const i=t*this.width-.5,r=e*this.height-.5;return this.sampleChannelBilinear(i,r,n)}sampleChannelBilinear(t,e,n){const i=this.itemSize,r=this.width,s=r*i,o=this.height-1,a=A(t,0,r-1),h=A(e,0,o),c=0|a,d=0|h,u=d*s,l=c*i+n,f=u+l;let g,_;g=a===c?c:c+1,_=h===d?d:d+1;const p=this.data,m=p[f];if(c===g&&d===_)return m;const y=a-c,w=h-d,v=g*i+n,x=_*s,b=x+l,S=x+v,M=p[u+v],U=p[b],$=p[S],F=E(m,M,y),z=E(U,$,y);return E(F,z,w)}sampleNearestUV(t,e,n){const i=this.width,r=this.height,s=Math.round(t*i-.5),o=Math.round(e*r-.5);this.read(A(s,0,i-1),A(o,0,r-1),n)}readChannel(t,e,n){const i=(e*this.width+t)*this.itemSize+n;return this.data[i]}read(t,e,n){const i=this.width,r=this.itemSize,s=(e*i+t)*r;for(let t=0;t<r;t++){const e=this.data[s+t];n[t]=e}}sample(t,e,n){const i=[];return this.sampleBilinear(t*(this.width-1),e*(this.height-1),i,0),n.readFromArray(i),i[0]}point2index(t,e){return t+e*this.width}index2point(t,e){const n=this.width,i=t%n,r=t/n|0;e.set(i,r)}copyWithMargin(t,e,n,i,r,s,o,a,h,c,d){const u=this.itemSize,l=t.itemSize,f=Math.min(u,l),g=u*this.width,_=l*t.width,p=t.data,m=this.data;let y,w,v,x,b,A,E,S,M;for(M=n*_+e*u,w=Math.max(0,r-c),b=r;w<b;w++)for(A=w*g,y=Math.max(0,i-a),x=i;y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];for(E=n*_,w=Math.max(0,r-c),b=r;w<b;w++)for(A=w*g,y=0;y<s;y++)for(S=A+(y+i)*u,M=E+(y+e)*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=n*_+(e+s-1)*u,w=Math.max(0,r-c),b=r;w<b;w++)for(A=w*g,y=i+s,x=Math.min(this.width,y+h);y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];for(w=0;w<o;w++)for(A=(w+r)*g,E=(w+n)*_,M=E+e*u,y=Math.max(0,i-a),x=i;y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];for(this.copy(t,e,n,i,r,s,o),w=0;w<o;w++)for(A=(w+r)*g,E=(w+n)*_,M=E+(e+s-1)*u,y=i+s,x=Math.min(this.width,y+h);y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=(n+o-1)*_+e*u,w=r+s,b=Math.min(this.height,w+d);w<b;w++)for(A=w*g,y=Math.max(0,i-a),x=i;y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];for(E=(n+o-1)*_,w=r+s,b=Math.min(this.height,w+d);w<b;w++)for(A=w*g,y=0;y<s;y++)for(S=A+(y+i)*u,M=E+(y+e)*u,v=0;v<f;v++)m[S+v]=p[M+v];for(M=(n+o-1)*_+(e+s-1)*u,w=r+s,b=Math.min(this.height,w+d);w<b;w++)for(A=w*g,y=i+s,x=Math.min(this.width,y+h);y<x;y++)for(S=A+y*u,v=0;v<f;v++)m[S+v]=p[M+v];this.version++}copy(t,e,n,i,r,s,o){const a=Math.min(s,t.width-e,this.width-i),h=Math.min(o,t.height-n,this.height-r),c=this.itemSize,d=t.itemSize,u=Math.min(c,d),l=c*this.width,f=d*t.width,g=t.data,_=this.data;let p,m,y;for(m=0;m<h;m++){const t=(m+r)*l,s=(m+n)*f;for(p=0;p<a;p++){const n=t+(p+i)*c,r=s+(p+e)*d;for(y=0;y<u;y++)_[n+y]=g[r+y]}}this.version++}copy_sameItemSize(t,e,n,i,r,s,o){const a=this.itemSize;t.itemSize;const h=Math.min(s,t.width-e,this.width-i),c=Math.min(o,t.height-n,this.height-r),d=a*this.width,u=a*t.width,l=t.data,f=this.data,g=h*a;let _,p;for(_=0;_<c;_++){const t=(_+r)*d+i*a,s=(_+n)*u+e*a;for(p=0;p<g;p++)f[t+p]=l[s+p]}this.version++}paint(t,e,n,i,r,s,o,a=0){let h;if(0!==a)throw new Error(`Unsupported blendType(=${a})`);h=R;const c=Math.min(s,t.width-e,this.width-i),d=Math.min(o,t.height-n,this.height-r),u=Math.max(0,-i),l=[0,0,0,255],f=[0,0,0,255],g=[];let _,p;for(p=Math.max(0,-r);p<d;p++)for(_=u;_<c;_++){const e=Math.round(_+i),s=Math.round(p+r);this.read(e,s,l);const o=Math.round(_+n),a=Math.round(p+n);t.read(o,a,f),h(f,l,g),this.set(e,s,g)}}zeroFill(t,e,n,i){const r=A(t,0,this.width),s=A(e,0,this.height),o=A(t+n,0,this.width),a=A(e+i,0,this.height),h=this.data,c=this.itemSize,d=c*this.width,u=r*c,l=o*c;let f;for(f=s;f<a;f++){const t=f*d;h.fill(0,t+u,t+l)}this.version++}fill_channel(t,e){const n=this.itemSize,i=this.data,r=i.length;for(let s=t;s<r;s+=n)i[s]=e;this.version++}fill(t,e,n,i,r){const s=this.width,o=this.height,a=A(t,0,s),h=A(e,0,o),c=A(t+n,0,s),d=A(e+i,0,o),u=this.data,l=this.itemSize,f=l*s;let g,_,p;for(g=h;g<d;g++){const t=g*f;for(_=a;_<c;_++){const e=t+_*l;for(p=0;p<l;p++)u[e+p]=r[p]}}this.version++}writeChannel(t,e,n,i){const r=(e*this.width+t)*this.itemSize+n;this.data[r]=i,this.version++}set(t,e,n){const i=this.data,r=this.itemSize,s=r*this.width*e+t*r;for(let t=0;t<r;t++)i[s+t]=n[t];this.version++}traverseCircle(t,e,n,i){let r,s;const o=0|t,a=0|e,h=n*n,c=Math.ceil(n);for(s=-c;s<=c;s++){const t=s*s;for(r=-c;r<=c;r++)r*r+t<=h&&i(o+r,a+s,this)}}resize(t,e,n=!0){const i=this.width,r=this.height;if(i===t&&r===e)return;const s=this.itemSize,o=t*e*s,a=this.data,h=new(function(t){if(t instanceof Int8Array)return Int8Array;if(t instanceof Int16Array)return Int16Array;if(t instanceof Int32Array)return Int32Array;if(t instanceof Uint8Array)return Uint8Array;if(t instanceof Uint8ClampedArray)return Uint8ClampedArray;if(t instanceof Uint16Array)return Uint16Array;if(t instanceof Uint32Array)return Uint32Array;if(t instanceof Float32Array)return Float32Array;if(t instanceof Float64Array)return Float64Array;if(Array.isArray(t))return Array;throw new TypeError("Unsupported array type")}(a))(o);if(n)if(t===i)h.set(a.subarray(0,Math.min(a.length,o)));else{const n=u(e,r),o=u(t,i);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const r=(e*t+n)*s,o=(e*i+n)*s;for(let t=0;t<s;t++)h[r+t]=a[o+t]}}this.width=t,this.height=e,this.data=h,this.version++}computeByteSize(){let t;return t=Array.isArray(this.data)?8*this.data.length:this.data.buffer.byteLength,t+280}toBinaryBuffer(t){throw new Error("Deprecated, use Sampler2DSerializationAdapter instead")}fromBinaryBuffer(t){throw new Error("Deprecated, use Sampler2DSerializationAdapter instead")}equals(e){return this.width===e.width&&this.height===e.height&&this.itemSize===e.itemSize&&function(e,n){if(e===n)return!0;const i=e.length;if(i!==n.length)return!1;if(i<128)return t(e,n);const r=e.byteLength;if(r!==n.byteLength)return!1;const s=e.constructor;if(s!==n.constructor)return!1;const o=e.buffer,a=n.buffer;if(o===a&&e.byteOffset===n.byteOffset)return!0;let h=e,c=n;const d=s.BYTES_PER_ELEMENT;return d<4&&r%4==0?(h=new Uint32Array(o,e.byteOffset,r/4),c=new Uint32Array(a,n.byteOffset,r/4)):d<2&&r%2==0&&(h=new Uint16Array(o,e.byteOffset,r/2),c=new Uint16Array(a,n.byteOffset,r/2)),t(h,c)}(this.data,e.data)}hash(){let t=((65535&this.width)<<16|65535&this.height)^this.itemSize;const e=this.data.length,n=Math.max(1,Math.ceil(e/509));return t^=function(t,e,n,i){let r=n;for(let e=0;e<n;e+=i)r=31*r+t[e]|0;return r}(this.data,0,e,n),t}clone(){let t;return t=Array.isArray(this.data)?this.data.slice():new(0,this.data.constructor)(this.data),new D(t,this.itemSize,this.width,this.height)}toJSON(){const t=O.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:V(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:i,data:r}){const s=function(t){const e=q[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(i);if("string"==typeof r){const t=O.decode(r);this.data=new s(t)}else{if(!Array.isArray(r))throw new Error("Unsupported data format");this.data=new s(r)}this.height=t,this.width=e,this.itemSize=n}static uint8clamped(t,e,n){const i=new Uint8ClampedArray(e*n*t);return new D(i,t,e,n)}static uint8(t,e,n){const i=new Uint8Array(e*n*t);return new D(i,t,e,n)}static uint16(t,e,n){const i=new Uint16Array(e*n*t);return new D(i,t,e,n)}static uint32(t,e,n){const i=new Uint32Array(e*n*t);return new D(i,t,e,n)}static int8(t,e,n){const i=new Int8Array(e*n*t);return new D(i,t,e,n)}static int16(t,e,n){const i=new Int16Array(e*n*t);return new D(i,t,e,n)}static int32(t,e,n){const i=new Int32Array(e*n*t);return new D(i,t,e,n)}static float32(t,e,n){const i=new Float32Array(e*n*t);return new D(i,t,e,n)}static float64(t,e,n){const i=new Float64Array(e*n*t);return new D(i,t,e,n)}}function j(t,e,n,i,r){return.5*(i-e+(2*e-5*n+4*i-r+(3*(n-i)+r-e)*t)*t)*t+n}function R(t,e,n){const i=t[3]/255,r=e[3]/255;n[0]=t[0]*i+e[0]*(1-i),n[1]=t[1]*i+e[1]*(1-i),n[2]=t[2]*i+e[2]*(1-i),n[3]=255*(i+r*(1-i))}function J(t,e,n,i){const r=t[e],s=t[e+1],o=t[e+2],a=1/Math.hypot(r,s,o);n[i]=r*a,n[i+1]=s*a,n[i+2]=o*a}D.prototype.isSampler2D=!0,D.typeName="Sampler2D";const P={build:function(t,e,n,i,r,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let d=0,u=0;const l=o*a,f=new Float32Array(3*l),g=new Float32Array(3*l),_=new Float32Array(2*l);let p,m;const y=n.y/r.y/c,w=n.x/r.x/h,v=e.y/r.y,x=e.x/r.x,b=r.x*i.x,A=r.y*i.y;let E,S,M;for(p=0;p<a;p++){const e=p*y+v;for(M=e*A,m=0;m<o;m++){const n=m*w+x;E=n*b,S=t.sampleChannelBicubicUV(n,e,0),f[d]=E,f[d+1]=S,f[d+2]=M,_[u]=n,_[u+1]=e,d+=3,u+=2}}d=0;const U=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(p=0;p<c;p++)for(m=0;m<h;m++){const t=m+o*p,e=m+o*(p+1),n=m+1+o*(p+1),i=m+1+o*p;U[d]=t,U[d+1]=e,U[d+2]=i,U[d+3]=e,U[d+4]=n,U[d+5]=i,d+=6}return function(t,e,n){let i,r,s,o,a,h,c,d,u,l,f,g,_,p,m,y,w,v,x,b,A,E=0;const S=n.length;for(;E<S;E+=3)i=3*n[E],r=3*n[E+1],s=3*n[E+2],o=t[i],a=t[i+1],h=t[i+2],c=t[r],d=t[r+1],u=t[r+2],l=t[s],f=t[s+1],g=t[s+2],_=l-c,p=f-d,m=g-u,y=o-c,w=a-d,v=h-u,x=p*v-m*w,b=m*y-_*v,A=_*w-p*y,e[i]+=x,e[i+1]+=b,e[i+2]+=A,e[r]+=x,e[r+1]+=b,e[r+2]+=A,e[s]+=x,e[s+1]+=b,e[s+2]+=A;!function(t){const e=t.length;for(let n=0;n<e;n+=3)J(t,n,t,n)}(e)}(f,g,U),{indices:U,vertices:f,normals:g,uvs:_}}};function W(t,e,n=0,i=t.length){const r=n+i;for(let i=n;i<r;i++)if(t[i]===e)return t.splice(i,1),!0;return!1}function H(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function G(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}let Y=0;class K{constructor(){this.index=Y++,this.v0=null,this.v1=null,this.faces=[],this.lengthSqr=-1}get byteSize(){return 128+8*this.faces.length+10}getVertexByIndex(t){if(0===t)return this.v0;if(1===t)return this.v1;throw new Error("Index out of bounds")}copy(t){this.v0=t.v0,this.v1=t.v1,this.lengthSqr=t.lengthSqr,this.faces=t.faces.slice()}clone(){const t=new K;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,i=n.length;for(let r=0;r<i;r++)n[r].containsEdge(this)||(t(`Missing back-link from face[${r}]`),e=!1);return this.v0.containsEdge(this)||(t("Missing back-link from vertex v0"),e=!1),this.v1.containsEdge(this)||(t("Missing back-link from vertex v1"),e=!1),e}isLinked(){return this.v0.containsEdge(this)}unlink(){const t=this.v0,e=this.v1;t.removeEdge(this),t!==e&&e.removeEdge(this);const n=this.faces,i=n.length;for(let t=0;t<i;t++)n[t].removeEdge(this)}isDegenerateEdge(){return this.v0===this.v1}isTopologyBorder(){return 1===this.faces.length}get length(){return this.lengthSqr<0&&this.computeSquaredLength(),Math.sqrt(this.lengthSqr)}computeSquaredLength(){const t=this.v0,e=this.v1,n=t.x,i=t.y,r=t.z,s=n-e.x,o=i-e.y,a=r-e.z;this.lengthSqr=s*s+o*o+a*a}replaceVertex(t,e){t===this.v0&&(this.v0=e),t===this.v1&&(this.v1=e)}merge(t){const e=t.faces,n=this.faces,i=e.length;for(let r=0;r<i;r++){const i=e[r];i.removeEdge(t),-1===n.indexOf(i)&&(n.push(i),i.addUniqueEdge(this))}t.v0.removeEdge(t),t.v1.removeEdge(t)}containsFace(t){return-1!==this.faces.indexOf(t)}addFace(t){this.faces.push(t)}addUniqueFace(t){H(this.faces,t)}removeFace(t){W(this.faces,t)}getOtherVertex(t){return G(this,t)}containsVertex(t){return e=t,this.v0===e||this.v1===e;var e}containsBothVertices(t,e){return function(t,e,n){const i=t.v0,r=t.v1;return!(i!==e&&i!==n||r!==e&&r!==n)}(this,t,e)}containsSameVerticesAs(t){return this.containsBothVertices(t.v0,t.v1)}}function Q(t,e,n){const i=t.length;for(let r=0;r<i;r++)t[r]===e&&(t[r]=n)}K.prototype.isTopoEdge=!0;var X,Z="undefined"!=typeof Float32Array?Float32Array:Array;function tt(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),X=new Z(3),Z!=Float32Array&&(X[0]=0,X[1]=0,X[2]=0);let et=0;class nt{constructor(){this.index=et++,this.vertices=[],this.edges=[],this.normal=[0,0,0]}get byteSize(){return 100+8*this.vertices.length+10+8*this.edges.length+10+24+10}copy(t){this.index=t.index,this.vertices=t.vertices.slice(),this.edges=t.edges.slice(),tt(this.normal,t.normal)}clone(){const t=new nt;return t.copy(this),t}validate(t){let e=!0;const n=this.vertices,i=n.length;3!==i&&(t(`Expected number of vertices is 3, instead got ${i}`),e=!1);for(let r=0;r<i;r++)n[r].containsFace(this)||(t(`Missing back-link from vertex[${r}]`),e=!1);const r=this.edges,s=r.length;3!==s&&(t(`Expected number of edges is 3, instead got ${s}`),e=!1);for(let n=0;n<s;n++)r[n].containsFace(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}isLinked(){return this.vertices[0].containsFace(this)}replaceEdge(t,e){Q(this.edges,t,e)}replaceVertex(t,e){Q(this.vertices,t,e)}isDegenerateTopology(){const t=this.vertices,e=t[0],n=t[1],i=t[2];return e===n||e===i||n===i}unlink(){const t=this.vertices,e=t.length;for(let n=0;n<e;n++)t[n].removeFace(this);const n=this.edges,i=n.length;for(let t=0;t<i;t++)n[t].removeFace(this)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return H(this.edges,t)}removeEdge(t){W(this.edges,t)}containsEdge(t){return-1!==this.edges.indexOf(t)}computeNormal(){const t=this.vertices,e=t[0],n=t[1],i=t[2];!function(t,e,n,i){!function(t,e,n,i,r,s,o,a,h,c,d){const u=h-s,l=c-o,f=d-a,g=n-s,_=i-o,p=r-a,m=l*p-f*_,y=f*g-u*p,w=u*_-l*g,v=function(t,e,n){return t*t+e*e+n*n}(m,y,w);if(0===v)return t[0]=0,t[1]=1,void(t[2]=0);const x=1/Math.sqrt(v),b=m*x,A=y*x,E=w*x;t[0]=b,t[1]=A,t[2]=E}(t,0,e[0],e[1],e[2],n[0],n[1],n[2],i[0],i[1],i[2])}(this.normal,e,n,i)}setVertexAt(t,e){this.vertices[t]=e}containsVertex(t){return-1!==this.vertices.indexOf(t)}getEdgeNeighbours(t,e){let n=0;const i=this.edges,r=i.length;for(let s=0;s<r;s++){const r=i[s].faces,o=r.length;for(let i=0;i<o;i++){const s=r[i];s!==this&&(t[e+n]=s,n++)}}return n}}nt.prototype.isTopoFace=!0;class it{constructor(){this.index=0,this.edges=[],this.faces=[],this.x=0,this.y=0,this.z=0}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get byteSize(){return 112+8*this.edges.length+10+8*this.faces.length+10}copy(t){this.x=t.x,this.y=t.y,this.z=t.z,this.index=t.index,this.faces=t.faces.slice(),this.edges=t.edges.slice()}clone(){const t=new it;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,i=n.length;for(let r=0;r<i;r++)n[r].containsVertex(this)||(t(`Missing back-link from face[${r}]`),e=!1);const r=this.edges,s=r.length;for(let n=0;n<s;n++)r[n].containsVertex(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}distanceTo(t){return e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z,Math.sqrt(function(t,e,n,i,r,s){const o=t-i,a=e-r,h=n-s;return o*o+a*a+h*h}(e,n,i,r,s,o));var e,n,i,r,s,o}addFace(t){this.faces.push(t)}addUniqueFace(t){return H(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){W(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return H(this.edges,t)}replaceEdge(t,e){const n=this.edges,i=n.indexOf(t);n[i]=e}containsEdge(t){return-1!==this.edges.indexOf(t)}removeEdge(t){return W(this.edges,t)}replaceAnotherVertex(t){const e=t.faces,n=e.length;let i=0;for(;i<n;i++){const n=e[i];n.replaceVertex(t,this),this.addUniqueFace(n)}const r=t.edges,s=r.length;for(i=0;i<s;i++){const e=r[i];e.replaceVertex(t,this),this.addUniqueEdge(e)}}computeNeighbourVertices(t,e){let n=0;const i=this.edges,r=i.length;for(let s=0;s<r;s++){const r=i[s].getOtherVertex(this);t[e+n]=r,n++}return n}}function rt(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}it.prototype.isTopoVertex=!0;class st{constructor(){this.vertices=[],this.__edges=new Set,this.__faces=new Set}get byteSize(){let t=0;for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e].byteSize;for(const e of this.__edges)t+=e.byteSize;for(const e of this.__faces)t+=e.byteSize;return t}getEdges(){return this.__edges}getFaces(){return this.__faces}getFaceByIndex(t){for(const e of this.__faces)if(e.index===t)return e}validate(t){let e=!0,n="",i=0;function r(r){t(`${n}[${i}]: ${r}`),e=!1}n="Edge",i=0;const s=this.getEdges();for(let t of s){t.validate(r),this.containsVertex(t.v0)||r("Link to off-mesh vertex v0"),this.containsVertex(t.v1)||r("Link to off-mesh vertex v1");const e=t.faces,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsFace(n)||r(`Link to off-mesh face[${t}]`)}i++}const o=this.getFaces();n="Face",i=0;for(let t of o){t.validate(r);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsEdge(n)||r(`Link to off-mesh edge[${t}]`)}const s=t.vertices,o=s.length;for(let t=0;t<o;t++){const e=s[t];this.containsVertex(e)||r(`Link to off-mesh vertex[${t}]`)}i++}const a=this.vertices,h=a.length;n="Vertex";for(let t=0;t<h;t++){i=t;const e=a[t];e.validate(r);const n=e.edges,s=n.length;for(let t=0;t<s;t++){const e=n[t];this.containsEdge(e)||r(`Link to off-mesh edge[${t}]`)}const o=e.faces,h=o.length;for(let t=0;t<h;t++){const e=o[t];this.containsFace(e)||r(`Link to off-mesh face[${t}]`)}}return e}clone(){const t=new st;return t.add(this),t}buildVertexMapping(){const t=new Map,e=this.vertices,n=e.length;for(let i=0;i<n;i++){const n=e[i];t.set(n.index,n)}return t}_addWithVertexMap(t,e){const n=t.getFaces();for(let t of n)this.addFaceCopy(t,e)}addFaceCopy(t,e){const n=new nt;tt(n.normal,t.normal);const i=t.vertices;for(let t=0;t<3;t++){const r=i[t];let s=e.get(r.index);void 0===s&&(s=new it,s.index=r.index,s.x=r.x,s.y=r.y,s.z=r.z,e.set(r.index,s),this.addVertex(s)),n.setVertexAt(t,s),s.addUniqueFace(n)}this.addFace(n);const r=n.vertices,s=r[0],o=r[1],a=r[2],h=this.ensureEdge(s,o),c=this.ensureEdge(o,a),d=this.ensureEdge(a,s);h.addUniqueFace(n),c.addUniqueFace(n),d.addUniqueFace(n),n.addUniqueEdge(h),n.addUniqueEdge(c),n.addUniqueEdge(d)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){H(this.vertices,t)}removeVertex(t){var e;e=t,W(this.vertices,e)}containsVertex(t){return-1!==this.vertices.indexOf(t)}addEdge(t){this.__edges.add(t)}addUniqueEdge(t){this.__edges.add(t)}removeEdge(t){var e;e=t,this.__edges.delete(e)}containsEdge(t){return this.__edges.has(t)}addFace(t){this.__faces.add(t)}injectManyFaces(t){for(let e of t)this.injectFace(e)}injectFace(t){this.addFace(t);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.addUniqueEdge(n)}const i=t.vertices,r=i.length;for(let t=0;t<r;t++){const e=i[t];this.addUniqueVertex(e)}}removeFace(t){var e;e=t,this.__faces.delete(e)}containsFace(t){return this.__faces.has(t)}ensureEdge(t,e){const n=t.edges,i=n.length;for(let r=0;r<i;r++){const i=n[r];if(G(i,t)===e)return i}const r=new K;return r.v0=t,r.v1=e,t.edges.push(r),e.edges.push(r),this.__edges.add(r),r}mergeEdges(){const t=this.getEdges();for(let e of t){const n=e.v0,i=e.v1;for(let r of t){if(e===r)continue;const t=r.v0,s=r.v1;if(n===t){if(i!==s)continue}else{if(n!==s)continue;if(i!==t)continue}this.removeEdge(r),e.merge(r)}}}computeEdgeSquaredLengths(){const t=this.getEdges();for(let e of t)e.computeSquaredLength()}build(t,e){const n=e.length,i=t.length/3,r=this.vertices;for(let e=0;e<i;e++){const n=3*e,i=new it;i.index=e,i.x=t[n],i.y=t[n+1],i.z=t[n+2],r[e]=i}const s=n/3,o=this.getFaces();for(let t=0;t<s;t++){const n=3*t,i=e[n],s=e[n+1],a=e[n+2],h=r[i],c=r[s],d=r[a],u=new nt;u.index=t;const l=this.ensureEdge(h,c),f=this.ensureEdge(c,d),g=this.ensureEdge(d,h);l.faces.push(u),f.faces.push(u),g.faces.push(u),u.vertices.push(h,c,d),u.edges.push(l,f,g),h.faces.push(u),c.faces.push(u),d.faces.push(u),o.add(u)}}toString(){return`TopoMesh{ vertices: ${rt(this.vertices.length)}, edges: ${rt(this.getEdges().size)}, faces: ${rt(this.getFaces().size)} }`}}st.prototype.isTopoMesh=!0,self.Lib={build_bvh(t,e){const n=new x;return function(t,e,n){const i=n.length/3;t.setLeafCount(i),t.initialize_structure();for(let r=0;r<i;r++){const i=3*r;b(t,r,e,n[i],n[i+1],n[i+2])}t.build()}(n,t,e),n},Sampler2D:D,BufferedGeometryArraysBuilder:P,tensionOptimizeUV:function(t,e,n,i){const r=new st;r.build(t,n),r.computeEdgeSquaredLengths();const s=t.length/3;for(let t=0;t<i;t++)t:for(let t=0;t<s;t++){const n=r.vertices[t],i=n.edges,s=i.length;if(0===s)continue;let o=0,a=0,h=0;for(let t=0;t<s;t++){const r=i[t];if(r.isTopologyBorder())continue t;const s=2*r.getOtherVertex(n).index,c=e[s],d=e[s+1],u=1/r.lengthSqr;o+=c*u,a+=d*u,h+=u}const c=o/h,d=a/h,u=2*n.index;e[u]=c,e[u+1]=d}},sampler2d_channel_compute_min:function(t,e=0){const n=t.itemSize,i=t.data,r=i.length;if(0===r)return;let s=i[e],o=e;for(let t=e+n;t<r;t+=n){const e=i[t];s>e&&(s=e,o=t)}const a=t.width,h=o/n|0;return{index:o,value:s,x:h%a,y:h/a|0}},sampler2d_channel_compute_max:function(t,e=0){const n=t.itemSize,i=t.data,r=i.length;if(0===r)return;let s=i[e],o=e;for(let t=e+n;t<r;t+=n){const e=i[t];s<e&&(s=e,o=t)}const a=t.width,h=o/n|0;return{index:o,value:s,x:h%a,y:h/a|0}}};
package/build/meep.cjs CHANGED
@@ -56720,9 +56720,9 @@ function ceilPowerOfTwo(v) {
56720
56720
 
56721
56721
  /**
56722
56722
  * @template T
56723
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} a
56723
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} a
56724
56724
  * @param {number} a_offset
56725
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} b
56725
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} b
56726
56726
  * @param {number} b_offset
56727
56727
  * @param {number} length How many elements should be moved
56728
56728
  */
@@ -56718,9 +56718,9 @@ function ceilPowerOfTwo(v) {
56718
56718
 
56719
56719
  /**
56720
56720
  * @template T
56721
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} a
56721
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} a
56722
56722
  * @param {number} a_offset
56723
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} b
56723
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} b
56724
56724
  * @param {number} b_offset
56725
56725
  * @param {number} length How many elements should be moved
56726
56726
  */
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.71.0",
8
+ "version": "2.72.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -2,7 +2,7 @@ import { assert } from "../../assert.js";
2
2
 
3
3
  /**
4
4
  * @template T
5
- * @param {T[]} array
5
+ * @param {T[]|Uint32Array} array
6
6
  * @param {T} needle
7
7
  * @param {number} min_index
8
8
  * @param {number} max_index
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @template T
3
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} a
3
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} a
4
4
  * @param {number} a_offset
5
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} b
5
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} b
6
6
  * @param {number} b_offset
7
7
  * @param {number} length How many elements should be moved
8
8
  */
@@ -14,7 +14,13 @@ import { v3_length_sqr } from "../vec3/v3_length_sqr.js";
14
14
  * @param {number} vCy
15
15
  * @param {number} vCz
16
16
  */
17
- export function v3_compute_triangle_normal(result, result_offset, vAx, vAy, vAz, vBx, vBy, vBz, vCx, vCy, vCz) {
17
+ export function v3_compute_triangle_normal(
18
+ result, result_offset,
19
+ vAx, vAy, vAz,
20
+ vBx, vBy, vBz,
21
+ vCx, vCy, vCz
22
+ ) {
23
+
18
24
  //compute CB and AB vectors
19
25
  const vCBx = vCx - vBx;
20
26
  const vCBy = vCy - vBy;
@@ -0,0 +1,27 @@
1
+ /**
2
+ *
3
+ * @param {number[]} input
4
+ * @param {number} input_offset
5
+ * @param {number[]} output
6
+ * @param {number} output_offset
7
+ */
8
+ export function v3_normalize_array(
9
+ input, input_offset,
10
+ output, output_offset
11
+ ) {
12
+
13
+
14
+ // extract vector components
15
+ const x = input[input_offset];
16
+ const y = input[input_offset + 1];
17
+ const z = input[input_offset + 2];
18
+
19
+ // compute vector inverse magnitude
20
+ const n = 1.0 / Math.hypot(x, y, z);
21
+
22
+ // write back
23
+ output[output_offset] = x * n;
24
+ output[output_offset + 1] = y * n;
25
+ output[output_offset + 2] = z * n;
26
+
27
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
 
6
- import ComputeNormals from '../../graphics/geometry/buffered/ComputeNormals.js';
6
+ import { computeVertexNormals } from '../../graphics/geometry/buffered/ComputeNormals.js';
7
7
 
8
8
  /**
9
9
  *
@@ -108,7 +108,7 @@ function buildBufferGeometry(samplerHeight, position, size, scale, totalSize, re
108
108
  }
109
109
  }
110
110
 
111
- ComputeNormals.computeNormals(vertices, normals, indices);
111
+ computeVertexNormals(vertices, normals, indices);
112
112
 
113
113
  //CleanupGeometry(geometry);
114
114
  return {
@@ -3,28 +3,17 @@
3
3
  */
4
4
 
5
5
 
6
+ import { v3_normalize_array } from "../../../../core/geom/vec3/v3_normalize_array.js";
7
+
6
8
  /**
7
9
  *
8
- * @param {Array.<Number>} normals
10
+ * @param {Array.<number>} normals
9
11
  */
10
12
  function normalizeVectors(normals) {
11
- let x, y, z, n;
12
-
13
- let i = 0;
14
- const il = normals.length;
15
- for (; i < il; i += 3) {
13
+ const count = normals.length;
14
+ for (let i = 0; i < count; i += 3) {
16
15
 
17
- // extract vector components
18
- x = normals[i];
19
- y = normals[i + 1];
20
- z = normals[i + 2];
21
-
22
- // compute vector inverse magnitude
23
- n = 1.0 / Math.sqrt(x * x + y * y + z * z);
24
-
25
- normals[i] *= n;
26
- normals[i + 1] *= n;
27
- normals[i + 2] *= n;
16
+ v3_normalize_array(normals, i, normals, i);
28
17
 
29
18
  }
30
19
  }
@@ -32,11 +21,11 @@ function normalizeVectors(normals) {
32
21
  /**
33
22
  * based on code from THREE.js
34
23
  * normals need to be set to 0
35
- * @param {Array.<Number>} vertices
36
- * @param {Array.<Number>} normals
37
- * @param {Array.<Number>} indices
24
+ * @param {Array.<number>|Float32Array} vertices
25
+ * @param {Array.<number>|Float32Array} normals
26
+ * @param {Array.<number>|Uint32Array} indices
38
27
  */
39
- function computeVertexNormals(vertices, normals, indices) {
28
+ export function computeVertexNormals(vertices, normals, indices) {
40
29
  let vA, vB, vC;
41
30
 
42
31
  let vAx, vAy, vAz, vBx, vBy, vBz, vCx, vCy, vCz;
@@ -94,8 +83,4 @@ function computeVertexNormals(vertices, normals, indices) {
94
83
  }
95
84
 
96
85
  normalizeVectors(normals);
97
- }
98
-
99
- export default {
100
- computeNormals: computeVertexNormals
101
- };
86
+ }
@@ -0,0 +1,17 @@
1
+ # Sparse Virtual Texture
2
+
3
+ This tech is based on popular Megatexture technique developed for Rage by John Carmack, working at id software.
4
+
5
+ The key idea boils down to having a very large texture that is impractical to keep in memory, and only load and keep in memory pieces of it that are relevant to the current view.
6
+
7
+ There are 2 parts to this technique, offline and online.
8
+
9
+ ## Offline
10
+
11
+ The original texture is mip-mapped, down to the size of a single tile, for the sake of this document let it be 128x128 pixels. Each mip level is then cut into tiles and stored on disk. A good intuition for this is to think of each tile as a separate pixel, representing non-color data.
12
+
13
+ ## Online
14
+
15
+ This is achieved by pre-rendering the scene with a special shader that records UV and mip-level information, which we call `Usage`, this is then analysed to build a list of used tiles (mip level, x, y) and by counting occurrence of this tile in the `Usage` texture we get a much more useful data structure.
16
+
17
+ Based on the `Usage` data, we populate our `Physical` texture of pages, and based on what's currently in the `Physical` texture - we populate the `Reference` texture that stores information about the entire mip pyramid, and for each tile contains a pointer to the `Physical` texture, where representative tile can be found.
@@ -1,6 +1,15 @@
1
1
  function vertex() {
2
2
  return `
3
- varying vec2 vUv;
3
+ precision mediump float;
4
+ precision mediump int;
5
+
6
+ uniform mat4 modelViewMatrix;
7
+ uniform mat4 projectionMatrix;
8
+
9
+ in vec2 uv;
10
+ in vec3 position;
11
+
12
+ out vec2 vUv;
4
13
  void main()
5
14
  {
6
15
  vUv = uv;
@@ -13,32 +22,46 @@ function vertex() {
13
22
 
14
23
  function fragment() {
15
24
  return `
16
- uniform vec4 u_mt_tex; // [ width, height, tileSize, id ]
17
- uniform vec2 u_mt_params; // [ bias, maxLevel, xx, xx ]
18
- varying vec2 vUv;
19
-
20
- float MTCalculateMipLevel( const in vec2 uv, const in float bias ) {
21
- vec2 dx = dFdx( uv * u_mt_tex.x );
22
- vec2 dy = dFdy( uv * u_mt_tex.y );
23
- return log2( max( dot( dx, dx ), dot( dy, dy ) ) ) / 2.0 + bias;
24
- }
25
-
26
- vec4 MTCalculateTileKeyRGBA( const in vec2 uv ) {
27
- float level = clamp( floor( MTCalculateMipLevel( uv, u_mt_params.x ) ), 0.0, u_mt_params.y );
28
- vec2 texIS = uv.xy * u_mt_tex.xy; // [0-1]x[0-1] -> [0-texwidth]x[0-texheight]
29
- vec2 texLS = texIS / exp2( level ); // -> [0-levelwidth]x[0-levelheight]
30
- vec2 texTS = floor( texLS / u_mt_tex.z ); // -> [0->tileswide]x[0-tileshigh]
31
- return vec4( u_mt_params.y - level, texTS.xy, u_mt_tex.w ) / 255.0; // [ level, tileX, tileY, texId ] -> RGBA
32
- }
33
-
25
+ precision highp float;
26
+ precision highp int;
34
27
 
35
- void main(){
36
- vec4 tile = MTCalculateTileKeyRGBA(vUv);
37
- // gl_FragColor = tile;
38
- gl_FragColor = vec4(mix(0.1,1.0,tile.x*255.0/u_mt_params.y), tile.yz*64.0, 1.0);
39
- // gl_FragColor = MTCalculateTileKeyRGBA(vUv);
40
- // gl_FragColor = vec4(1.0);
41
- }
28
+ uniform uvec4 u_mt_tex; // [ width, height, tileSize, id ]
29
+ uniform vec2 u_mt_params; // [ bias, maxLevel ]
30
+ uniform vec2 u_mt_viewport_size;
31
+ in vec2 vUv;
32
+
33
+ out uvec4 out_decoded;
34
+
35
+ float MTCalculateMipLevel( const in vec2 uv, const in float bias ) {
36
+
37
+ float scale_x = float(u_mt_tex.x) / u_mt_viewport_size.x;
38
+ float scale_y = float(u_mt_tex.y) / u_mt_viewport_size.y;
39
+
40
+ vec2 dx = dFdx( uv * scale_x);
41
+ vec2 dy = dFdy( uv * scale_y);
42
+
43
+ return log2( max( dot( dx, dx ), dot( dy, dy ) ) ) * 0.5 + bias;
44
+ }
45
+
46
+ uvec4 MTCalculateTileKeyRGBA( const in vec2 uv ) {
47
+ uint level = clamp( uint( floor( MTCalculateMipLevel( uv, u_mt_params.x ) ) ), 0u, uint(u_mt_params.y) );
48
+
49
+ uint mip_resolution_in_tiles = 1u << level;
50
+
51
+ uint mip_resolution_in_texels = mip_resolution_in_tiles * u_mt_tex.z;
52
+
53
+ vec2 texel_position = fract(uv.xy) * vec2(u_mt_tex.xy);
54
+
55
+ uvec2 tile_position = uvec2( texel_position / float(mip_resolution_in_texels) );
56
+
57
+ // [ level, tileX, tileY, texId ] -> RGBA
58
+ return uvec4( uint(u_mt_params.y) - level, tile_position, u_mt_tex.w );
59
+ }
60
+
61
+
62
+ void main(){
63
+ out_decoded = MTCalculateTileKeyRGBA(vUv);
64
+ }
42
65
  `;
43
66
  }
44
67
 
@@ -0,0 +1,51 @@
1
+ import LabelView from "../../../../../view/common/LabelView.js";
2
+ import EmptyView from "../../../../../view/elements/EmptyView.js";
3
+
4
+ export class UsageDebugView extends EmptyView {
5
+ #tileCount = new LabelView("")
6
+ #tiles = new EmptyView();
7
+
8
+
9
+ constructor(opt) {
10
+ super(opt);
11
+
12
+ this.addChild(this.#tileCount);
13
+ this.addChild(this.#tiles);
14
+
15
+ this.css({
16
+ position: "absolute",
17
+ left: "0",
18
+ top: "0",
19
+ background: "rgba(255,255,255,0.5)",
20
+ fontFamily: "monospace",
21
+ fontSize: "10px"
22
+ });
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {UsageMetadata} usage
28
+ */
29
+ set usage(usage) {
30
+
31
+ const tileCount = usage.tile_count;
32
+
33
+ this.#tileCount.updateText(`Tile Count: ${tileCount}`);
34
+
35
+ this.#tiles.removeAllChildren();
36
+
37
+ for (let i = 0; i < tileCount; i++) {
38
+ const finger_print = usage.getTile(i);
39
+ const count = usage.getCount(i);
40
+
41
+ const level = (finger_print >> 24) & 0xFF;
42
+ const x = (finger_print >> 16) & 0xFF;
43
+ const y = (finger_print >> 8) & 0xFF;
44
+ const texture_id = (finger_print) & 0xFF;
45
+
46
+ this.#tiles.addChild(new LabelView(`ID: ${texture_id} Level: ${level} X: ${x} Y: ${y} USAGE: ${count}`));
47
+ }
48
+ }
49
+
50
+
51
+ }