@woosh/meep-engine 2.47.34 → 2.47.35

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.
Files changed (59) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +43 -21
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +43 -21
  5. package/editor/tools/FoliagePaintTool.js +3 -3
  6. package/editor/tools/GridPaintTool.js +2 -2
  7. package/package.json +1 -1
  8. package/src/core/binary/dec2hex.js +9 -0
  9. package/src/core/binary/hex2dec.js +8 -0
  10. package/src/core/color/Color.js +8 -0
  11. package/src/core/color/ColorUtils.js +2 -2
  12. package/src/core/color/{parseHex.js → hex2rgb.js} +3 -5
  13. package/src/core/color/rgb2hex.js +1 -4
  14. package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.js +1 -1
  15. package/src/core/geom/3d/topology/struct/TopoMesh.js +9 -3
  16. package/src/core/geom/AABB2.js +1 -1
  17. package/src/core/geom/Rectangle.js +2 -2
  18. package/src/core/math/computeGreatestCommonDivisor.js +30 -3
  19. package/src/core/math/{intersects1D.js → interval/intersects1D.js} +1 -1
  20. package/src/core/math/{overlap1D.js → interval/overlap1D.js} +1 -1
  21. package/src/core/math/mix.js +5 -7
  22. package/src/core/math/random/randomUint8.js +10 -0
  23. package/src/core/math/spline/spline_bezier3.js +26 -0
  24. package/src/core/math/spline/spline_bezier3_bounds.js +87 -0
  25. package/src/core/model/node-graph/node/NodeInstance.js +1 -0
  26. package/src/core/process/task/Task.js +8 -6
  27. package/src/engine/achievements/AchievementManager.js +1 -1
  28. package/src/engine/animation/TransitionFunctions.js +1 -1
  29. package/src/engine/animation/curve/AnimationCurve.js +93 -1
  30. package/src/engine/animation/curve/Keyframe.js +20 -0
  31. package/src/engine/animation/curve/compression/prototypeCurveCompression.js +3 -1
  32. package/src/engine/ecs/components/MeshCollider.js +5 -0
  33. package/src/engine/ecs/components/MonsterAI.js +5 -0
  34. package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
  35. package/src/engine/ecs/guid/GUID.js +257 -0
  36. package/src/engine/ecs/guid/GUID.spec.js +41 -0
  37. package/src/engine/ecs/guid/GUIDSerializationAdapter.js +25 -0
  38. package/src/engine/ecs/storage/binary/BinaryClassSerializationAdapter.js +11 -12
  39. package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +23 -9
  40. package/src/engine/graphics/camera/CameraShake.js +1 -1
  41. package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
  42. package/src/engine/graphics/ecs/decal/v2/Decal.js +8 -6
  43. package/src/engine/intelligence/behavior/behavior_to_dot.js +11 -1
  44. package/src/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +6 -0
  45. package/src/engine/intelligence/behavior/util/behavior_traverse_tree.js +35 -0
  46. package/src/engine/scene/transitionToScene.js +4 -1
  47. package/src/view/elements/radial/RadialText.js +1 -1
  48. package/src/core/math/bezierCurve.js +0 -22
  49. /package/src/core/math/{isValueBetween.js → interval/isValueBetween.js} +0 -0
  50. /package/src/core/math/{isValueBetween.spec.js → interval/isValueBetween.spec.js} +0 -0
  51. /package/src/core/math/{isValueBetweenInclusive.js → interval/isValueBetweenInclusive.js} +0 -0
  52. /package/src/core/math/{isValueBetweenInclusive.spec.js → interval/isValueBetweenInclusive.spec.js} +0 -0
  53. /package/src/core/math/{overlap1D.spec.js → interval/overlap1D.spec.js} +0 -0
  54. /package/src/core/math/{cubicCurve.js → spline/cubicCurve.js} +0 -0
  55. /package/src/core/math/{cubicCurve.spec.js → spline/cubicCurve.spec.js} +0 -0
  56. /package/src/core/math/{makeCubicCurve.js → spline/makeCubicCurve.js} +0 -0
  57. /package/src/core/math/{makeCubicCurve.spec.js → spline/makeCubicCurve.spec.js} +0 -0
  58. /package/src/core/math/{quadraticCurve.js → spline/quadraticCurve.js} +0 -0
  59. /package/src/core/math/{quadraticCurve.spec.js → spline/quadraticCurve.spec.js} +0 -0
@@ -1 +1 @@
1
- function t(t,e){return t<e?e:t}function e(t,e){return t<e?t:e}class n{visit(t,e){}}function i(){}const r=Math.abs;function s(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]}const o=new Float32Array(6);class a{constructor(){this.leafNodeCount=0,this.binaryNodeCount=0,this.boxCount=0,this.data=new Float32Array(16)}estimateByteSize(){return this.data.buffer.byteLength+248}initialize(t){const e=Math.log(t)/Math.log(2),n=Math.pow(2,Math.ceil(e))-1;this.leafNodeCount=t,this.binaryNodeCount=n,this.boxCount=this.leafNodeCount+this.binaryNodeCount;const i=6*this.boxCount;this.data.length<i?this.data=new Float32Array(i):this.data.fill(0)}unsortedBuiltIntermediate(){const t=this.data,e=this.binaryNodeCount,n=6*this.binaryNodeCount;let i,r,a,h,d,u,f=Math.floor(Math.log(e)/Math.log(2));for(a=Math.pow(2,f),r=6*(a-1),i=0;i<a;i++){const e=2*i,o=e+1,a=n+6*e,h=n+6*o;o<this.leafNodeCount?l(t,r,a,h):e<this.leafNodeCount?s(g=t,a,g,r,6):c(r-6,r,t),r+=6}var g;for(f--;f>=0;f--)for(a=Math.pow(2,f),h=a-1,i=0;i<a;i++)d=1+(h<<1),u=d+1,l(t,6*h,6*d,6*u),h++;s(t,0,o,0,6),this.x0=o[0],this.y0=o[1],this.z0=o[2],this.x1=o[3],this.y1=o[4],this.z1=o[5]}writeLeaf(t,e,n,i,r,s,o){const a=6*this.binaryNodeCount+6*t;h(this.data,a,e,n,i,r,s,o)}setLeafs(t){let e=6*this.binaryNodeCount;const n=this.data;let i=0;const r=this.leafNodeCount;for(;i<r;i++)t(i,e,n,h),e+=6;this.unsortedBuiltIntermediate()}traversePreOrderStack(t,e){const n=u;d[u++]=e;const i=6*this.binaryNodeCount,r=6*this.boxCount;for(;u-- >n;){const e=d[u],n=6*e;if(t.visit(n,1)){const n=1+(e<<1),s=n+1,o=6*n,a=6*s;a<r&&(a<i?d[u++]=s:t.visit(a,0)),o<r&&(o<i?d[u++]=n:t.visit(o,0))}}u=n}traversePreOrder(t,e,n){const i=t(6*e,n),r=6*this.binaryNodeCount,s=6*this.boxCount;if(!1!==i){const n=1+(e<<1),i=n+1,o=6*n,a=6*i;o<s&&(o<r?this.traversePreOrder(t,n,1):t(o,0)),a<s&&(a<r?this.traversePreOrder(t,i,1):t(a,0))}}traverseRayLeafIntersections(t,e,n,i,r,s,o,a){f.originX=t,f.originY=e,f.originZ=n,f.directionX=i,f.directionY=r,f.directionZ=s,f.root=this,f.callback=o,f.callbackThisArg=a,this.traversePreOrderStack(f,0)}}function h(t,e,n,i,r,s,o,a){t[e]=n,t[e+1]=i,t[e+2]=r,t[e+3]=s,t[e+4]=o,t[e+5]=a}function c(t,e,n){s(n,t,o,0,3),o[3]=o[0],o[4]=o[1],o[5]=o[2],s(o,0,n,e,6)}function l(n,i,r,s){!function(n,i,r,s,o){const a=n[i],h=n[i+1],c=n[i+2],l=n[i+3],d=n[i+4],u=n[i+5],f=n[r],g=n[r+1],m=n[r+2],y=n[r+3],w=n[r+4],p=n[r+5],v=e(a,f),x=e(h,g),A=e(c,m),E=t(l,y),b=t(d,w),U=t(u,p);s[o]=v,s[o+1]=x,s[o+2]=A,s[o+3]=E,s[o+4]=b,s[o+5]=U}(n,r,s,n,i)}const d=[];let u=0;const f=new class extends n{constructor(){super(),this.callback=i,this.callbackThisArg=null,this.originX=0,this.originY=0,this.originZ=0,this.directionX=0,this.directionY=0,this.directionZ=0,this.root=null}visit(t,e){const n=this.root,i=n.data,s=n.binaryNodeCount;if(!function(t,e,n,i,s,o,a,h,c,l,d,u){const f=.5*(i-t),g=a-(t+f);if(g*l>=0&&r(g)>f)return!1;const m=.5*(s-e),y=h-(e+m);if(y*d>=0&&r(y)>m)return!1;const w=.5*(o-n),p=c-(n+w);if(p*u>=0&&r(p)>w)return!1;const v=r(d),x=r(u);if(r(d*p-u*y)>m*x+w*v)return!1;const A=r(l);return!(r(u*g-l*p)>f*x+w*A)&&r(l*y-d*g)<=f*v+m*A}(i[t],i[t+1],i[t+2],i[t+3],i[t+4],i[t+5],this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ))return!1;if(0===e){const n=t/6-s;return this.callback.call(this.callbackThisArg,n,t,e),!1}return!0}};function g(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}var y=Object.freeze({__proto__:null,buildUnsorted:function(t,e){const n=e.length/3,i=new a;i.initialize(n);for(let r=0;r<n;r++){const n=3*r,s=3*e[n],o=3*e[n+1],a=3*e[n+2],h=t[s],c=t[s+1],l=t[s+2],d=t[o],u=t[o+1],f=t[o+2],y=t[a],w=t[a+1],p=t[a+2],v=g(h,d,y),x=g(c,u,w),A=g(l,f,p),E=m(h,d,y),b=m(c,u,w),U=m(l,f,p);i.writeLeaf(r,v,x,A,E,b,U)}return i.unsortedBuiltIntermediate(),i},buildUnsortedUnindexed:function(t){const e=t.length/9,n=new a;n.initialize(e);for(let i=0;i<e;i++){const e=3*i,r=3*e,s=3*(e+1),o=3*(e+2),a=t[r],h=t[r+1],c=t[r+2],l=t[s],d=t[s+1],u=t[s+2],f=t[o],y=t[o+1],w=t[o+2],p=g(a,l,f),v=g(h,d,y),x=g(c,u,w),A=m(a,l,f),E=m(h,d,y),b=m(c,u,w);n.writeLeaf(i,p,v,x,A,E,b)}return n.unsortedBuiltIntermediate(),n}});function w(t,e,n){return t<e?e:t>n?n:t}function p(t,e,n){return t*(1-n)+e*n}function v(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}function x(t,e){if(!t)throw new Error(e||"AssertionError")}x.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(", ")}]`)},x.notEqual=function(t,e,n){x(t!==e,n)},x.notOk=function(t,e){x(!t,e)},x.equal=function(t,e,n){x(t===e,n)},x.logicalyEqual=function(t,e,n){},x.ok=x,x.greaterThan=function(t,e,n){if(!(t>e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} > ${e}.`,new Error(i)}},x.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} >= ${e}.`,new Error(i)}},x.lessThan=function(t,e,n){if(!(t<e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} < ${e}.`,new Error(i)}},x.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} <= ${e}.`,new Error(i)}},x.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})`)},x.arrayHas=function(t,e,n="Array does not contain the item"){},x.arrayHasNo=function(t,e,n="Array contains the item"){},x.arrayEqual=function(t,e,n="Arrays are not equal"){if(!v(t,e))throw new Error(n)},x.isInstanceOf=function(t,e,n="value",i=e.name){},x.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})`)},x.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})`)},x.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})`)},x.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})`)},x.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},x.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},x.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}')`)},x.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},x.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},x.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},x.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},x.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},x.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)};const A={Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Int8:"int8",Int16:"int16",Int32:"int32",Int64:"int64",Float16:"float16",Float32:"float32",Float64:"float64"};function E(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return A.Uint8;case Uint16Array:return A.Uint16;case Uint32Array:return A.Uint32;case Int8Array:return A.Int8;case Int16Array:return A.Int16;case Int32Array:return A.Int32;case Float32Array:return A.Float32;case Float64Array:return A.Float64;default:throw new Error("unsupported constructor type")}}const b={[A.Uint8]:Uint8Array,[A.Uint16]:Uint16Array,[A.Uint32]:Uint32Array,[A.Int8]:Int8Array,[A.Int16]:Int16Array,[A.Int32]:Int32Array,[A.Float16]:Uint16Array,[A.Float32]:Float32Array,[A.Float64]:Float64Array},U=[],F=[],S="undefined"!=typeof Uint8Array?Uint8Array:Array,M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=M.length;t<e;++t)U[t]=M[t],F[M.charCodeAt(t)]=t;function C(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(U[(r=e)>>18&63]+U[r>>12&63]+U[r>>6&63]+U[63&r])}var r;return i.join("")}F["-".charCodeAt(0)]=62,F["_".charCodeAt(0)]=63;class z{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=C(t,e,e+s>o?o:e+s);r.push(n)}return 1===i?(e=t[n-1],r.push(U[e>>2]+U[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(U[e>>10]+U[e>>4&63]+U[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 S(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=F[t.charCodeAt(n)]<<18|F[t.charCodeAt(n+1)]<<12|F[t.charCodeAt(n+2)]<<6|F[t.charCodeAt(n+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=F[t.charCodeAt(n)]<<2|F[t.charCodeAt(n+1)]>>4,o[a++]=255&e),1===s&&(e=F[t.charCodeAt(n)]<<10|F[t.charCodeAt(n+1)]<<4|F[t.charCodeAt(n+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o}(t).buffer}}class ${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)||e<0)throw new Error(`width must be a non-negative integer, instead was ${n}`);if(!Number.isInteger(i)||e<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){const n=this.itemSize,i=this.data,r=i.length;if(0===r)return;let s=i[e],o=0;for(let a=e+n;a<r;a+=n){const e=i[a];s>e?(s=e,o=1,t[0]=a):e===s&&(t[o++]=a)}o<t.length&&t.splice(o,t.length-o)}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-1),r=e*(this.height-1);return this.sampleChannelCatmullRom(i,r,n)}sampleChannelCatmullRom(t,e,n){const i=Math.floor(t-.5)+.5,r=Math.floor(e-.5)+.5,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)),l=o*(.5+o*(2-1.5*o)),d=s*s*(.5*s-.5),u=o*o*(.5*o-.5),f=1+s*s*(1.5*s-2.5)+c,g=1+o*o*(1.5*o-2.5)+l,m=i-1,y=r-1,w=i+2,p=r+2,v=i+c/f,x=r+l/g;let A=0;return A+=this.sampleChannelBilinear(m,y,n)*a*h,A+=this.sampleChannelBilinear(v,y,n)*f*h,A+=this.sampleChannelBilinear(w,y,n)*d*h,A+=this.sampleChannelBilinear(m,x,n)*a*g,A+=this.sampleChannelBilinear(v,x,n)*f*g,A+=this.sampleChannelBilinear(w,x,n)*d*g,A+=this.sampleChannelBilinear(m,p,n)*a*u,A+=this.sampleChannelBilinear(v,p,n)*f*u,A+=this.sampleChannelBilinear(w,p,n)*d*u,A}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-1),r=e*(this.height-1);return this.sampleChannelBicubic(i-.5,r-.5,n)}sampleChannelBicubic(n,i,r){const s=this.itemSize,o=this.width,a=this.height,h=this.data,c=o*s,l=o-1,d=a-1,u=w(n,0,l),f=w(i,0,d),g=0|u,m=0|f,y=u-g,p=f-m,v=t(0,g-1),x=t(0,m-1),A=e(l,g+1),E=e(d,m+1),b=e(l,A+1),U=x*c+r,F=m*c+r,S=E*c+r,M=e(d,E+1)*c+r,C=v*s,z=g*s,$=A*s,B=b*s,V=h[U+C],I=h[U+z],N=h[U+$],q=h[U+B],O=h[F+C],k=h[F+z],L=h[F+$],T=h[F+B],j=h[S+C],D=h[S+z],P=h[S+$],R=h[S+B],Y=h[M+C],X=h[M+z],Z=h[M+$],H=h[M+B],W=_(y,V,I,N,q),G=_(y,O,k,L,T),J=_(y,j,D,P,R),K=_(y,Y,X,Z,H);return _(p,W,G,J,K)}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-1),r=e*(this.height-1);return this.sampleChannelBilinear(i,r,n)}sampleChannelBilinear(t,e,n){const i=this.itemSize,r=this.width,s=r*i,o=r-1,a=this.height-1,h=w(t,0,o),c=w(e,0,a),l=0|h,d=0|c,u=d*s,f=l*i+n,g=u+f;let m,y;m=h===l||l>=o?l:l+1,y=c===d||d>=a?d:d+1;const v=this.data,x=v[g];if(l===m&&d===y)return x;const A=h-l,E=c-d,b=m*i+n,U=y*s,F=U+f,S=U+b,M=v[u+b],C=v[F],z=v[S],$=p(x,M,A),_=p(C,z,A);return p($,_,E)}sampleNearestUV(t,n,i){const r=Math.round(t*(this.width-1)),s=Math.round(n*(this.height-1));this.read(e(r,this.width-1),e(s,this.height-1),i)}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]}computeNeighbors(t,e){const n=this.width,i=this.height,r=t%n,s=t/n|0;r>0&&e.push(t-1),r<n-1&&e.push(t+1),s>0&&e.push(t-n),s<i-1&&e.push(t+n)}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,l){const d=this.itemSize,u=t.itemSize,f=Math.min(d,u),g=d*this.width,m=u*t.width,y=t.data,w=this.data;let p,v,x,A,E,b,U,F,S;for(S=n*m+e*d,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(U=n*m,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=0;p<s;p++)for(F=b+(p+i)*d,S=U+(p+e)*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=n*m+(e+s-1)*d,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(v=0;v<o;v++)for(b=(v+r)*g,U=(v+n)*m,S=U+e*d,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(this.copy(t,e,n,i,r,s,o),v=0;v<o;v++)for(b=(v+r)*g,U=(v+n)*m,S=U+(e+s-1)*d,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=(n+o-1)*m+e*d,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(U=(n+o-1)*m,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=0;p<s;p++)for(F=b+(p+i)*d,S=U+(p+e)*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=(n+o-1)*m+(e+s-1)*d,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];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,l=t.itemSize,d=Math.min(c,l),u=c*this.width,f=l*t.width,g=t.data,m=this.data;let y,w,p;for(w=0;w<h;w++){const t=(w+r)*u,s=(w+n)*f;for(y=0;y<a;y++){const n=t+(y+i)*c,r=s+(y+e)*l;for(p=0;p<d;p++)m[n+p]=g[r+p]}}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),l=a*this.width,d=a*t.width,u=t.data,f=this.data,g=h*a;let m,y;for(m=0;m<c;m++){const t=(m+r)*l+i*a,s=(m+n)*d+e*a;for(y=0;y<g;y++)f[t+y]=u[s+y]}this.version++}paint(t,e,n,i,r,s,o,a=0){let h;if(0!==a)throw new Error(`Unsupported blendType(=${a})`);h=B;const c=Math.min(s,t.width-e,this.width-i),l=Math.min(o,t.height-n,this.height-r),d=Math.max(0,-i),u=[0,0,0,255],f=[0,0,0,255],g=[];let m,y;for(y=Math.max(0,-r);y<l;y++)for(m=d;m<c;m++){const e=Math.round(m+i),s=Math.round(y+r);this.read(e,s,u);const o=Math.round(m+n),a=Math.round(y+n);t.read(o,a,f),h(f,u,g),this.set(e,s,g)}}zeroFill(t,e,n,i){const r=w(t,0,this.width),s=w(e,0,this.height),o=w(t+n,0,this.width),a=w(e+i,0,this.height),h=this.data,c=this.itemSize,l=c*this.width,d=r*c,u=o*c;let f;for(f=s;f<a;f++){const t=f*l;h.fill(0,t+d,t+u)}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=w(t,0,s),h=w(e,0,o),c=w(t+n,0,s),l=w(e+i,0,o),d=this.data,u=this.itemSize,f=u*s;let g,m,y;for(g=h;g<l;g++){const t=g*f;for(m=a;m<c;m++){const e=t+m*u;for(y=0;y<u;y++)d[e+y]=r[y]}}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,n,i=!0){const r=this.width,s=this.height;if(r===t&&s===n)return;const o=this.itemSize,a=t*n*o,h=this.data,c=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")}(h))(a);if(i)if(t===r)c.set(h.subarray(0,Math.min(h.length,a)));else{const i=e(n,s),a=e(t,r);for(let e=0;e<i;e++)for(let n=0;n<a;n++){const i=(e*t+n)*o,s=(e*r+n)*o;for(let t=0;t<o;t++)c[i+t]=h[s+t]}}this.width=t,this.height=n,this.data=c,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")}traverseOrthogonalNeighbours(t,e,n,i){const r=this.width,s=this.height,o=this.point2index(t,e);let a=0;const h=this.data;t>0&&(a=o-1,n.call(i,t-1,e,h[a],a)),t<r-1&&(a=o+1,n.call(i,t+1,e,h[a],a)),e>0&&(a=o-r,n.call(i,t,e-1,h[a],a)),e<s-1&&(a=o+r,n.call(i,t,e+1,h[a],a))}equals(t){return this.width===t.width&&this.height===t.height&&this.itemSize===t.itemSize&&function(t,e){const n=t.length;if(n!==e.length)return!1;if(n<128)return v(t,e);const i=t.byteLength;if(i!==e.byteLength)return!1;const r=t.constructor.BYTES_PER_ELEMENT;if(r!==e.constructor.BYTES_PER_ELEMENT)return!1;const s=t.buffer,o=e.buffer;if(s===o&&t.byteOffset===e.byteOffset)return!0;let a=t,h=e;return r<4&&i%4==0?(a=new Uint32Array(s,t.byteOffset,i/4),h=new Uint32Array(o,e.byteOffset,i/4)):r<2&&i%2==0&&(a=new Uint16Array(s,t.byteOffset,i/2),h=new Uint16Array(o,e.byteOffset,i/2)),v(a,h)}(this.data,t.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 $(t,this.itemSize,this.width,this.height)}toJSON(){const t=z.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:E(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:i,data:r}){const s=function(t){const e=b[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(i);if("string"==typeof r){const t=z.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 $(i,t,e,n)}static uint8(t,e,n){const i=new Uint8Array(e*n*t);return new $(i,t,e,n)}static uint16(t,e,n){const i=new Uint16Array(e*n*t);return new $(i,t,e,n)}static uint32(t,e,n){const i=new Uint32Array(e*n*t);return new $(i,t,e,n)}static int8(t,e,n){const i=new Int8Array(e*n*t);return new $(i,t,e,n)}static int16(t,e,n){const i=new Int16Array(e*n*t);return new $(i,t,e,n)}static int32(t,e,n){const i=new Int32Array(e*n*t);return new $(i,t,e,n)}static float32(t,e,n){const i=new Float32Array(e*n*t);return new $(i,t,e,n)}static float64(t,e,n){const i=new Float64Array(e*n*t);return new $(i,t,e,n)}}function _(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 B(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))}$.prototype.isSampler2D=!0;const V={build:function(t,e,n,i,r,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let l=0,d=0;const u=o*a,f=new Float32Array(3*u),g=new Float32Array(3*u),m=new Float32Array(2*u);let y,w;const p=n.y/r.y/c,v=n.x/r.x/h,x=e.y/r.y,A=e.x/r.x,E=r.x*i.x,b=r.y*i.y;let U,F,S;for(y=0;y<a;y++){const e=y*p+x;for(S=e*b,w=0;w<o;w++){const n=w*v+A;U=n*E,F=t.sampleChannelBicubicUV(n,e,0),f[l]=U,f[l+1]=F,f[l+2]=S,m[d]=n,m[d+1]=e,l+=3,d+=2}}l=0;const M=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(y=0;y<c;y++)for(w=0;w<h;w++){const t=w+o*y,e=w+o*(y+1),n=w+1+o*(y+1),i=w+1+o*y;M[l]=t,M[l+1]=e,M[l+2]=i,M[l+3]=e,M[l+4]=n,M[l+5]=i,l+=6}return function(t,e,n){let i,r,s,o,a,h,c,l,d,u,f,g,m,y,w,p,v,x,A,E,b,U=0;const F=n.length;for(;U<F;U+=3)i=3*n[U],r=3*n[U+1],s=3*n[U+2],o=t[i],a=t[i+1],h=t[i+2],c=t[r],l=t[r+1],d=t[r+2],u=t[s],f=t[s+1],g=t[s+2],m=u-c,y=f-l,w=g-d,p=o-c,v=a-l,x=h-d,A=y*x-w*v,E=w*p-m*x,b=m*v-y*p,e[i]+=A,e[i+1]+=E,e[i+2]+=b,e[r]+=A,e[r+1]+=E,e[r+2]+=b,e[s]+=A,e[s+1]+=E,e[s+2]+=b;!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,M),{indices:M,vertices:f,normals:g,uvs:m}}};function I(t,e){const n=t.indexOf(e);return-1!==n&&(t.splice(n,1),!0)}function N(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function q(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}let O=0;class k{constructor(){this.index=O++,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){N(this.faces,t)}removeFace(t){I(this.faces,t)}getOtherVertex(t){return q(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 L(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 T,j="undefined"!=typeof Float32Array?Float32Array:Array;function D(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)}),T=new j(3),j!=Float32Array&&(T[0]=0,T[1]=0,T[2]=0);let P=0;class R{constructor(){this.index=P++,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(),D(this.normal,t.normal)}clone(){const t=new R;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){L(this.edges,t,e)}replaceVertex(t,e){L(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 N(this.edges,t)}removeEdge(t){I(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,l){const d=h-s,u=c-o,f=l-a,g=n-s,m=i-o,y=r-a,w=u*y-f*m,p=f*g-d*y,v=d*m-u*g,x=function(t,e,n){return t*t+e*e+n*n}(w,p,v);if(0===x)return t[0]=0,t[1]=1,void(t[2]=0);const A=1/Math.sqrt(x),E=w*A,b=p*A,U=v*A;t[0]=E,t[1]=b,t[2]=U}(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}}R.prototype.isTopoFace=!0;class Y{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 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].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 N(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){I(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return N(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 I(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 X(t,e){return void 0===e&&(e=","),t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}Y.prototype.isTopoVertex=!0;class Z{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 Z;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 R;D(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 Y,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),l=this.ensureEdge(a,s);h.addUniqueFace(n),c.addUniqueFace(n),l.addUniqueFace(n),n.addUniqueEdge(h),n.addUniqueEdge(c),n.addUniqueEdge(l)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){N(this.vertices,t)}removeVertex(t){var e;e=t,I(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(q(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=t.length/3,i=this.vertices;for(let e=0;e<n;e++){const n=3*e,r=new Y;r.index=e,r.x=t[n],r.y=t[n+1],r.z=t[n+2],i[e]=r}const r=e.length/3,s=this.getFaces();for(let t=0;t<r;t++){const n=3*t,r=e[n],o=e[n+1],a=e[n+2],h=i[r],c=i[o],l=i[a],d=new R;d.index=t;const u=this.ensureEdge(h,c),f=this.ensureEdge(c,l),g=this.ensureEdge(l,h);u.faces.push(d),f.faces.push(d),g.faces.push(d),d.vertices.push(h,c,l),d.edges.push(u,f,g),h.faces.push(d),c.faces.push(d),l.faces.push(d),s.add(d)}}toString(){return`TopoMesh{ vertices: ${X(this.vertices.length)}, edges: ${X(this.getEdges().size)}, faces: ${X(this.getFaces().size)} }`}}Z.prototype.isTopoMesh=!0,self.Lib={BinaryBVHFromBufferGeometry:y,Sampler2D:$,BufferedGeometryArraysBuilder:V,tensionOptimizeUV:function(t,e,n,i){const r=new Z;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],l=e[s+1],d=1/r.lengthSqr;o+=c*d,a+=l*d,h+=d}const c=o/h,l=a/h,d=2*n.index;e[d]=c,e[d+1]=l}},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){return t<e?e:t}function e(t,e){return t<e?t:e}class n{visit(t,e){}}function i(){}const r=Math.abs;function s(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]}const o=new Float32Array(6);class a{constructor(){this.leafNodeCount=0,this.binaryNodeCount=0,this.boxCount=0,this.data=new Float32Array(16)}estimateByteSize(){return this.data.buffer.byteLength+248}initialize(t){const e=Math.log(t)/Math.log(2),n=Math.pow(2,Math.ceil(e))-1;this.leafNodeCount=t,this.binaryNodeCount=n,this.boxCount=this.leafNodeCount+this.binaryNodeCount;const i=6*this.boxCount;this.data.length<i?this.data=new Float32Array(i):this.data.fill(0)}unsortedBuiltIntermediate(){const t=this.data,e=this.binaryNodeCount,n=6*this.binaryNodeCount;let i,r,a,h,d,u,f=Math.floor(Math.log(e)/Math.log(2));for(a=Math.pow(2,f),r=6*(a-1),i=0;i<a;i++){const e=2*i,o=e+1,a=n+6*e,h=n+6*o;o<this.leafNodeCount?l(t,r,a,h):e<this.leafNodeCount?s(g=t,a,g,r,6):c(r-6,r,t),r+=6}var g;for(f--;f>=0;f--)for(a=Math.pow(2,f),h=a-1,i=0;i<a;i++)d=1+(h<<1),u=d+1,l(t,6*h,6*d,6*u),h++;s(t,0,o,0,6),this.x0=o[0],this.y0=o[1],this.z0=o[2],this.x1=o[3],this.y1=o[4],this.z1=o[5]}writeLeaf(t,e,n,i,r,s,o){const a=6*this.binaryNodeCount+6*t;h(this.data,a,e,n,i,r,s,o)}setLeafs(t){let e=6*this.binaryNodeCount;const n=this.data;let i=0;const r=this.leafNodeCount;for(;i<r;i++)t(i,e,n,h),e+=6;this.unsortedBuiltIntermediate()}traversePreOrderStack(t,e){const n=u;d[u++]=e;const i=6*this.binaryNodeCount,r=6*this.boxCount;for(;u-- >n;){const e=d[u],n=6*e;if(t.visit(n,1)){const n=1+(e<<1),s=n+1,o=6*n,a=6*s;a<r&&(a<i?d[u++]=s:t.visit(a,0)),o<r&&(o<i?d[u++]=n:t.visit(o,0))}}u=n}traversePreOrder(t,e,n){const i=t(6*e,n),r=6*this.binaryNodeCount,s=6*this.boxCount;if(!1!==i){const n=1+(e<<1),i=n+1,o=6*n,a=6*i;o<s&&(o<r?this.traversePreOrder(t,n,1):t(o,0)),a<s&&(a<r?this.traversePreOrder(t,i,1):t(a,0))}}traverseRayLeafIntersections(t,e,n,i,r,s,o,a){f.originX=t,f.originY=e,f.originZ=n,f.directionX=i,f.directionY=r,f.directionZ=s,f.root=this,f.callback=o,f.callbackThisArg=a,this.traversePreOrderStack(f,0)}}function h(t,e,n,i,r,s,o,a){t[e]=n,t[e+1]=i,t[e+2]=r,t[e+3]=s,t[e+4]=o,t[e+5]=a}function c(t,e,n){s(n,t,o,0,3),o[3]=o[0],o[4]=o[1],o[5]=o[2],s(o,0,n,e,6)}function l(n,i,r,s){!function(n,i,r,s,o){const a=n[i],h=n[i+1],c=n[i+2],l=n[i+3],d=n[i+4],u=n[i+5],f=n[r],g=n[r+1],m=n[r+2],y=n[r+3],w=n[r+4],p=n[r+5],v=e(a,f),x=e(h,g),A=e(c,m),E=t(l,y),b=t(d,w),U=t(u,p);s[o]=v,s[o+1]=x,s[o+2]=A,s[o+3]=E,s[o+4]=b,s[o+5]=U}(n,r,s,n,i)}const d=[];let u=0;const f=new class extends n{constructor(){super(),this.callback=i,this.callbackThisArg=null,this.originX=0,this.originY=0,this.originZ=0,this.directionX=0,this.directionY=0,this.directionZ=0,this.root=null}visit(t,e){const n=this.root,i=n.data,s=n.binaryNodeCount;if(!function(t,e,n,i,s,o,a,h,c,l,d,u){const f=.5*(i-t),g=a-(t+f);if(g*l>=0&&r(g)>f)return!1;const m=.5*(s-e),y=h-(e+m);if(y*d>=0&&r(y)>m)return!1;const w=.5*(o-n),p=c-(n+w);if(p*u>=0&&r(p)>w)return!1;const v=r(d),x=r(u);if(r(d*p-u*y)>m*x+w*v)return!1;const A=r(l);return!(r(u*g-l*p)>f*x+w*A)&&r(l*y-d*g)<=f*v+m*A}(i[t],i[t+1],i[t+2],i[t+3],i[t+4],i[t+5],this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ))return!1;if(0===e){const n=t/6-s;return this.callback.call(this.callbackThisArg,n,t,e),!1}return!0}};function g(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}var y=Object.freeze({__proto__:null,buildUnsorted:function(t,e){const n=e.length/3,i=new a;i.initialize(n);for(let r=0;r<n;r++){const n=3*r,s=3*e[n],o=3*e[n+1],a=3*e[n+2],h=t[s],c=t[s+1],l=t[s+2],d=t[o],u=t[o+1],f=t[o+2],y=t[a],w=t[a+1],p=t[a+2],v=g(h,d,y),x=g(c,u,w),A=g(l,f,p),E=m(h,d,y),b=m(c,u,w),U=m(l,f,p);i.writeLeaf(r,v,x,A,E,b,U)}return i.unsortedBuiltIntermediate(),i},buildUnsortedUnindexed:function(t){const e=t.length/9,n=new a;n.initialize(e);for(let i=0;i<e;i++){const e=3*i,r=3*e,s=3*(e+1),o=3*(e+2),a=t[r],h=t[r+1],c=t[r+2],l=t[s],d=t[s+1],u=t[s+2],f=t[o],y=t[o+1],w=t[o+2],p=g(a,l,f),v=g(h,d,y),x=g(c,u,w),A=m(a,l,f),E=m(h,d,y),b=m(c,u,w);n.writeLeaf(i,p,v,x,A,E,b)}return n.unsortedBuiltIntermediate(),n}});function w(t,e,n){return t<e?e:t>n?n:t}const p=function(t,e,n){return(e-t)*n+t};function v(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}function x(t,e){if(!t)throw new Error(e||"AssertionError")}x.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(", ")}]`)},x.notEqual=function(t,e,n){x(t!==e,n)},x.notOk=function(t,e){x(!t,e)},x.equal=function(t,e,n){x(t===e,n)},x.logicalyEqual=function(t,e,n){},x.ok=x,x.greaterThan=function(t,e,n){if(!(t>e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} > ${e}.`,new Error(i)}},x.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} >= ${e}.`,new Error(i)}},x.lessThan=function(t,e,n){if(!(t<e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} < ${e}.`,new Error(i)}},x.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let i="";throw void 0!==n&&(i+=n+". "),i+=`Expected ${t} <= ${e}.`,new Error(i)}},x.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})`)},x.arrayHas=function(t,e,n="Array does not contain the item"){},x.arrayHasNo=function(t,e,n="Array contains the item"){},x.arrayEqual=function(t,e,n="Arrays are not equal"){if(!v(t,e))throw new Error(n)},x.isInstanceOf=function(t,e,n="value",i=e.name){},x.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})`)},x.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})`)},x.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})`)},x.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})`)},x.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},x.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},x.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}')`)},x.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},x.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},x.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},x.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},x.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},x.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)};const A={Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Int8:"int8",Int16:"int16",Int32:"int32",Int64:"int64",Float16:"float16",Float32:"float32",Float64:"float64"};function E(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return A.Uint8;case Uint16Array:return A.Uint16;case Uint32Array:return A.Uint32;case Int8Array:return A.Int8;case Int16Array:return A.Int16;case Int32Array:return A.Int32;case Float32Array:return A.Float32;case Float64Array:return A.Float64;default:throw new Error("unsupported constructor type")}}const b={[A.Uint8]:Uint8Array,[A.Uint16]:Uint16Array,[A.Uint32]:Uint32Array,[A.Int8]:Int8Array,[A.Int16]:Int16Array,[A.Int32]:Int32Array,[A.Float16]:Uint16Array,[A.Float32]:Float32Array,[A.Float64]:Float64Array},U=[],F=[],S="undefined"!=typeof Uint8Array?Uint8Array:Array,M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=M.length;t<e;++t)U[t]=M[t],F[M.charCodeAt(t)]=t;function C(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(U[(r=e)>>18&63]+U[r>>12&63]+U[r>>6&63]+U[63&r])}var r;return i.join("")}F["-".charCodeAt(0)]=62,F["_".charCodeAt(0)]=63;class z{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=C(t,e,e+s>o?o:e+s);r.push(n)}return 1===i?(e=t[n-1],r.push(U[e>>2]+U[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(U[e>>10]+U[e>>4&63]+U[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 S(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=F[t.charCodeAt(n)]<<18|F[t.charCodeAt(n+1)]<<12|F[t.charCodeAt(n+2)]<<6|F[t.charCodeAt(n+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=F[t.charCodeAt(n)]<<2|F[t.charCodeAt(n+1)]>>4,o[a++]=255&e),1===s&&(e=F[t.charCodeAt(n)]<<10|F[t.charCodeAt(n+1)]<<4|F[t.charCodeAt(n+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o}(t).buffer}}class ${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)||e<0)throw new Error(`width must be a non-negative integer, instead was ${n}`);if(!Number.isInteger(i)||e<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){const n=this.itemSize,i=this.data,r=i.length;if(0===r)return;let s=i[e],o=0;for(let a=e+n;a<r;a+=n){const e=i[a];s>e?(s=e,o=1,t[0]=a):e===s&&(t[o++]=a)}o<t.length&&t.splice(o,t.length-o)}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-1),r=e*(this.height-1);return this.sampleChannelCatmullRom(i,r,n)}sampleChannelCatmullRom(t,e,n){const i=Math.floor(t-.5)+.5,r=Math.floor(e-.5)+.5,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)),l=o*(.5+o*(2-1.5*o)),d=s*s*(.5*s-.5),u=o*o*(.5*o-.5),f=1+s*s*(1.5*s-2.5)+c,g=1+o*o*(1.5*o-2.5)+l,m=i-1,y=r-1,w=i+2,p=r+2,v=i+c/f,x=r+l/g;let A=0;return A+=this.sampleChannelBilinear(m,y,n)*a*h,A+=this.sampleChannelBilinear(v,y,n)*f*h,A+=this.sampleChannelBilinear(w,y,n)*d*h,A+=this.sampleChannelBilinear(m,x,n)*a*g,A+=this.sampleChannelBilinear(v,x,n)*f*g,A+=this.sampleChannelBilinear(w,x,n)*d*g,A+=this.sampleChannelBilinear(m,p,n)*a*u,A+=this.sampleChannelBilinear(v,p,n)*f*u,A+=this.sampleChannelBilinear(w,p,n)*d*u,A}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-1),r=e*(this.height-1);return this.sampleChannelBicubic(i-.5,r-.5,n)}sampleChannelBicubic(n,i,r){const s=this.itemSize,o=this.width,a=this.height,h=this.data,c=o*s,l=o-1,d=a-1,u=w(n,0,l),f=w(i,0,d),g=0|u,m=0|f,y=u-g,p=f-m,v=t(0,g-1),x=t(0,m-1),A=e(l,g+1),E=e(d,m+1),b=e(l,A+1),U=x*c+r,F=m*c+r,S=E*c+r,M=e(d,E+1)*c+r,C=v*s,z=g*s,$=A*s,B=b*s,V=h[U+C],I=h[U+z],N=h[U+$],q=h[U+B],O=h[F+C],k=h[F+z],L=h[F+$],T=h[F+B],j=h[S+C],D=h[S+z],P=h[S+$],R=h[S+B],Y=h[M+C],X=h[M+z],Z=h[M+$],H=h[M+B],W=_(y,V,I,N,q),G=_(y,O,k,L,T),J=_(y,j,D,P,R),K=_(y,Y,X,Z,H);return _(p,W,G,J,K)}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-1),r=e*(this.height-1);return this.sampleChannelBilinear(i,r,n)}sampleChannelBilinear(t,e,n){const i=this.itemSize,r=this.width,s=r*i,o=r-1,a=this.height-1,h=w(t,0,o),c=w(e,0,a),l=0|h,d=0|c,u=d*s,f=l*i+n,g=u+f;let m,y;m=h===l||l>=o?l:l+1,y=c===d||d>=a?d:d+1;const v=this.data,x=v[g];if(l===m&&d===y)return x;const A=h-l,E=c-d,b=m*i+n,U=y*s,F=U+f,S=U+b,M=v[u+b],C=v[F],z=v[S],$=p(x,M,A),_=p(C,z,A);return p($,_,E)}sampleNearestUV(t,n,i){const r=Math.round(t*(this.width-1)),s=Math.round(n*(this.height-1));this.read(e(r,this.width-1),e(s,this.height-1),i)}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]}computeNeighbors(t,e){const n=this.width,i=this.height,r=t%n,s=t/n|0;r>0&&e.push(t-1),r<n-1&&e.push(t+1),s>0&&e.push(t-n),s<i-1&&e.push(t+n)}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,l){const d=this.itemSize,u=t.itemSize,f=Math.min(d,u),g=d*this.width,m=u*t.width,y=t.data,w=this.data;let p,v,x,A,E,b,U,F,S;for(S=n*m+e*d,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(U=n*m,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=0;p<s;p++)for(F=b+(p+i)*d,S=U+(p+e)*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=n*m+(e+s-1)*d,v=Math.max(0,r-c),E=r;v<E;v++)for(b=v*g,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(v=0;v<o;v++)for(b=(v+r)*g,U=(v+n)*m,S=U+e*d,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(this.copy(t,e,n,i,r,s,o),v=0;v<o;v++)for(b=(v+r)*g,U=(v+n)*m,S=U+(e+s-1)*d,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=(n+o-1)*m+e*d,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=Math.max(0,i-a),A=i;p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];for(U=(n+o-1)*m,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=0;p<s;p++)for(F=b+(p+i)*d,S=U+(p+e)*d,x=0;x<f;x++)w[F+x]=y[S+x];for(S=(n+o-1)*m+(e+s-1)*d,v=r+s,E=Math.min(this.height,v+l);v<E;v++)for(b=v*g,p=i+s,A=Math.min(this.width,p+h);p<A;p++)for(F=b+p*d,x=0;x<f;x++)w[F+x]=y[S+x];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,l=t.itemSize,d=Math.min(c,l),u=c*this.width,f=l*t.width,g=t.data,m=this.data;let y,w,p;for(w=0;w<h;w++){const t=(w+r)*u,s=(w+n)*f;for(y=0;y<a;y++){const n=t+(y+i)*c,r=s+(y+e)*l;for(p=0;p<d;p++)m[n+p]=g[r+p]}}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),l=a*this.width,d=a*t.width,u=t.data,f=this.data,g=h*a;let m,y;for(m=0;m<c;m++){const t=(m+r)*l+i*a,s=(m+n)*d+e*a;for(y=0;y<g;y++)f[t+y]=u[s+y]}this.version++}paint(t,e,n,i,r,s,o,a=0){let h;if(0!==a)throw new Error(`Unsupported blendType(=${a})`);h=B;const c=Math.min(s,t.width-e,this.width-i),l=Math.min(o,t.height-n,this.height-r),d=Math.max(0,-i),u=[0,0,0,255],f=[0,0,0,255],g=[];let m,y;for(y=Math.max(0,-r);y<l;y++)for(m=d;m<c;m++){const e=Math.round(m+i),s=Math.round(y+r);this.read(e,s,u);const o=Math.round(m+n),a=Math.round(y+n);t.read(o,a,f),h(f,u,g),this.set(e,s,g)}}zeroFill(t,e,n,i){const r=w(t,0,this.width),s=w(e,0,this.height),o=w(t+n,0,this.width),a=w(e+i,0,this.height),h=this.data,c=this.itemSize,l=c*this.width,d=r*c,u=o*c;let f;for(f=s;f<a;f++){const t=f*l;h.fill(0,t+d,t+u)}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=w(t,0,s),h=w(e,0,o),c=w(t+n,0,s),l=w(e+i,0,o),d=this.data,u=this.itemSize,f=u*s;let g,m,y;for(g=h;g<l;g++){const t=g*f;for(m=a;m<c;m++){const e=t+m*u;for(y=0;y<u;y++)d[e+y]=r[y]}}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,n,i=!0){const r=this.width,s=this.height;if(r===t&&s===n)return;const o=this.itemSize,a=t*n*o,h=this.data,c=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")}(h))(a);if(i)if(t===r)c.set(h.subarray(0,Math.min(h.length,a)));else{const i=e(n,s),a=e(t,r);for(let e=0;e<i;e++)for(let n=0;n<a;n++){const i=(e*t+n)*o,s=(e*r+n)*o;for(let t=0;t<o;t++)c[i+t]=h[s+t]}}this.width=t,this.height=n,this.data=c,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")}traverseOrthogonalNeighbours(t,e,n,i){const r=this.width,s=this.height,o=this.point2index(t,e);let a=0;const h=this.data;t>0&&(a=o-1,n.call(i,t-1,e,h[a],a)),t<r-1&&(a=o+1,n.call(i,t+1,e,h[a],a)),e>0&&(a=o-r,n.call(i,t,e-1,h[a],a)),e<s-1&&(a=o+r,n.call(i,t,e+1,h[a],a))}equals(t){return this.width===t.width&&this.height===t.height&&this.itemSize===t.itemSize&&function(t,e){const n=t.length;if(n!==e.length)return!1;if(n<128)return v(t,e);const i=t.byteLength;if(i!==e.byteLength)return!1;const r=t.constructor.BYTES_PER_ELEMENT;if(r!==e.constructor.BYTES_PER_ELEMENT)return!1;const s=t.buffer,o=e.buffer;if(s===o&&t.byteOffset===e.byteOffset)return!0;let a=t,h=e;return r<4&&i%4==0?(a=new Uint32Array(s,t.byteOffset,i/4),h=new Uint32Array(o,e.byteOffset,i/4)):r<2&&i%2==0&&(a=new Uint16Array(s,t.byteOffset,i/2),h=new Uint16Array(o,e.byteOffset,i/2)),v(a,h)}(this.data,t.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 $(t,this.itemSize,this.width,this.height)}toJSON(){const t=z.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:E(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:i,data:r}){const s=function(t){const e=b[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(i);if("string"==typeof r){const t=z.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 $(i,t,e,n)}static uint8(t,e,n){const i=new Uint8Array(e*n*t);return new $(i,t,e,n)}static uint16(t,e,n){const i=new Uint16Array(e*n*t);return new $(i,t,e,n)}static uint32(t,e,n){const i=new Uint32Array(e*n*t);return new $(i,t,e,n)}static int8(t,e,n){const i=new Int8Array(e*n*t);return new $(i,t,e,n)}static int16(t,e,n){const i=new Int16Array(e*n*t);return new $(i,t,e,n)}static int32(t,e,n){const i=new Int32Array(e*n*t);return new $(i,t,e,n)}static float32(t,e,n){const i=new Float32Array(e*n*t);return new $(i,t,e,n)}static float64(t,e,n){const i=new Float64Array(e*n*t);return new $(i,t,e,n)}}function _(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 B(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))}$.prototype.isSampler2D=!0;const V={build:function(t,e,n,i,r,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let l=0,d=0;const u=o*a,f=new Float32Array(3*u),g=new Float32Array(3*u),m=new Float32Array(2*u);let y,w;const p=n.y/r.y/c,v=n.x/r.x/h,x=e.y/r.y,A=e.x/r.x,E=r.x*i.x,b=r.y*i.y;let U,F,S;for(y=0;y<a;y++){const e=y*p+x;for(S=e*b,w=0;w<o;w++){const n=w*v+A;U=n*E,F=t.sampleChannelBicubicUV(n,e,0),f[l]=U,f[l+1]=F,f[l+2]=S,m[d]=n,m[d+1]=e,l+=3,d+=2}}l=0;const M=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(y=0;y<c;y++)for(w=0;w<h;w++){const t=w+o*y,e=w+o*(y+1),n=w+1+o*(y+1),i=w+1+o*y;M[l]=t,M[l+1]=e,M[l+2]=i,M[l+3]=e,M[l+4]=n,M[l+5]=i,l+=6}return function(t,e,n){let i,r,s,o,a,h,c,l,d,u,f,g,m,y,w,p,v,x,A,E,b,U=0;const F=n.length;for(;U<F;U+=3)i=3*n[U],r=3*n[U+1],s=3*n[U+2],o=t[i],a=t[i+1],h=t[i+2],c=t[r],l=t[r+1],d=t[r+2],u=t[s],f=t[s+1],g=t[s+2],m=u-c,y=f-l,w=g-d,p=o-c,v=a-l,x=h-d,A=y*x-w*v,E=w*p-m*x,b=m*v-y*p,e[i]+=A,e[i+1]+=E,e[i+2]+=b,e[r]+=A,e[r+1]+=E,e[r+2]+=b,e[s]+=A,e[s+1]+=E,e[s+2]+=b;!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,M),{indices:M,vertices:f,normals:g,uvs:m}}};function I(t,e){const n=t.indexOf(e);return-1!==n&&(t.splice(n,1),!0)}function N(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function q(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}let O=0;class k{constructor(){this.index=O++,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){N(this.faces,t)}removeFace(t){I(this.faces,t)}getOtherVertex(t){return q(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 L(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 T,j="undefined"!=typeof Float32Array?Float32Array:Array;function D(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)}),T=new j(3),j!=Float32Array&&(T[0]=0,T[1]=0,T[2]=0);let P=0;class R{constructor(){this.index=P++,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(),D(this.normal,t.normal)}clone(){const t=new R;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){L(this.edges,t,e)}replaceVertex(t,e){L(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 N(this.edges,t)}removeEdge(t){I(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,l){const d=h-s,u=c-o,f=l-a,g=n-s,m=i-o,y=r-a,w=u*y-f*m,p=f*g-d*y,v=d*m-u*g,x=function(t,e,n){return t*t+e*e+n*n}(w,p,v);if(0===x)return t[0]=0,t[1]=1,void(t[2]=0);const A=1/Math.sqrt(x),E=w*A,b=p*A,U=v*A;t[0]=E,t[1]=b,t[2]=U}(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}}R.prototype.isTopoFace=!0;class Y{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 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].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 N(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){I(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return N(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 I(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 X(t,e){return void 0===e&&(e=","),t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}Y.prototype.isTopoVertex=!0;class Z{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 Z;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 R;D(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 Y,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),l=this.ensureEdge(a,s);h.addUniqueFace(n),c.addUniqueFace(n),l.addUniqueFace(n),n.addUniqueEdge(h),n.addUniqueEdge(c),n.addUniqueEdge(l)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){N(this.vertices,t)}removeVertex(t){var e;e=t,I(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(q(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 Y;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],l=r[a],d=new R;d.index=t;const u=this.ensureEdge(h,c),f=this.ensureEdge(c,l),g=this.ensureEdge(l,h);u.faces.push(d),f.faces.push(d),g.faces.push(d),d.vertices.push(h,c,l),d.edges.push(u,f,g),h.faces.push(d),c.faces.push(d),l.faces.push(d),o.add(d)}}toString(){return`TopoMesh{ vertices: ${X(this.vertices.length)}, edges: ${X(this.getEdges().size)}, faces: ${X(this.getFaces().size)} }`}}Z.prototype.isTopoMesh=!0,self.Lib={BinaryBVHFromBufferGeometry:y,Sampler2D:$,BufferedGeometryArraysBuilder:V,tensionOptimizeUV:function(t,e,n,i){const r=new Z;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],l=e[s+1],d=1/r.lengthSqr;o+=c*d,a+=l*d,h+=d}const c=o/h,l=a/h,d=2*n.index;e[d]=c,e[d+1]=l}},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
@@ -47693,15 +47693,11 @@ function max2(a, b) {
47693
47693
  }
47694
47694
 
47695
47695
  /**
47696
+ *
47696
47697
  * Produces a proportional mix of 2 values, a*(1-portion) + b*portion
47697
- * @param {number} a
47698
- * @param {number} b
47699
- * @param {number} portion
47700
- * @returns {number}
47698
+ * Same as lerp
47701
47699
  */
47702
- function mix(a, b, portion) {
47703
- return a * (1 - portion) + b * portion;
47704
- }
47700
+ const mix = lerp$1;
47705
47701
 
47706
47702
  /**
47707
47703
  * Color blending modes
@@ -57878,16 +57874,21 @@ function hsv2rgb(h, s, v) {
57878
57874
  };
57879
57875
  }
57880
57876
 
57877
+ /**
57878
+ * Converts string hex representation to a decimal integer
57879
+ * @param {string} v
57880
+ * @returns {number}
57881
+ */
57881
57882
  function hex2dec(v) {
57882
57883
  return parseInt(v, 16)
57883
- }
57884
-
57884
+ }
57885
+
57885
57886
  /**
57886
57887
  *
57887
- * @param {string} hex
57888
+ * @param {string} hex expect form #FFFFFF or #FFFFFFFF for RGBA
57888
57889
  * @returns {{r: number, g: number, b: number, a:number}} rgb
57889
57890
  */
57890
- function parseHex(hex) {
57891
+ function hex2rgb(hex) {
57891
57892
 
57892
57893
 
57893
57894
  const result = {
@@ -57959,7 +57960,7 @@ function parseColor(c) {
57959
57960
 
57960
57961
  } else if (cL.startsWith('#')) {
57961
57962
 
57962
- const rgb = parseHex(cL);
57963
+ const rgb = hex2rgb(cL);
57963
57964
 
57964
57965
  r = rgb.r;
57965
57966
  g = rgb.g;
@@ -58074,11 +58075,16 @@ function rgb2uint24(r, g, b) {
58074
58075
  ;
58075
58076
  }
58076
58077
 
58078
+ /**
58079
+ * Convert a decimal value to hex
58080
+ * @param {number} c generally expects b byte value, 0-255
58081
+ * @returns {string}
58082
+ */
58077
58083
  function dec2hex(c) {
58078
58084
  const hex = Math.round(c).toString(16);
58079
58085
  return hex.length === 1 ? "0" + hex : hex;
58080
- }
58081
-
58086
+ }
58087
+
58082
58088
  /**
58083
58089
  *
58084
58090
  * @param {number} r
@@ -58250,6 +58256,14 @@ class Color {
58250
58256
  this.set(r, g, b, this.a);
58251
58257
  }
58252
58258
 
58259
+ /**
58260
+ * set alpha
58261
+ * @param {number} a
58262
+ */
58263
+ setA(a) {
58264
+ this.set(this.r, this.g, this.b, a);
58265
+ }
58266
+
58253
58267
  /**
58254
58268
  *
58255
58269
  * @param {number} r
@@ -63946,17 +63960,17 @@ const TaskState = {
63946
63960
  class Task {
63947
63961
  /**
63948
63962
  *
63949
- * @param {string} name
63950
- * @param {function(Task, executor:ConcurrentExecutor)} [initializer]
63963
+ * @param {string} [name] useful for identifying the task later on, for various UI and debug purposes
63964
+ * @param {function(Task, executor:ConcurrentExecutor)} [initializer] function to be executed just before task starts
63951
63965
  * @param {function():TaskSignal} cycleFunction
63952
63966
  * @param {function():number} [computeProgress]
63953
63967
  * @param {Task[]} [dependencies=[]]
63954
- * @param {number} [estimatedDuration=1]
63968
+ * @param {number} [estimatedDuration=1] in seconds
63955
63969
  * @constructor
63956
63970
  */
63957
63971
  constructor(
63958
63972
  {
63959
- name,
63973
+ name = "Unnamed",
63960
63974
  initializer = noop,
63961
63975
  cycleFunction,
63962
63976
  computeProgress,
@@ -64110,6 +64124,8 @@ class Task {
64110
64124
  executeSync() {
64111
64125
  this.initialize();
64112
64126
 
64127
+ this.on.started.send0();
64128
+
64113
64129
  let s = this.cycle();
64114
64130
 
64115
64131
  for (; s !== TaskSignal.EndSuccess && s !== TaskSignal.EndFailure; s = this.cycle()) {
@@ -64117,9 +64133,9 @@ class Task {
64117
64133
  }
64118
64134
 
64119
64135
  if (s === TaskSignal.EndSuccess) {
64120
- this.on.completed.dispatch();
64136
+ this.on.completed.send0();
64121
64137
  } else if (s === TaskSignal.EndFailure) {
64122
- this.on.failed.dispatch();
64138
+ this.on.failed.send0();
64123
64139
  }
64124
64140
 
64125
64141
  return s;
@@ -100149,7 +100165,13 @@ class AbstractDecoratorBehavior extends Behavior {
100149
100165
 
100150
100166
  this.__source.finalize();
100151
100167
  }
100152
- }
100168
+ }
100169
+
100170
+ /**
100171
+ * @readonly
100172
+ * @type {boolean}
100173
+ */
100174
+ AbstractDecoratorBehavior.prototype.isDecoratorBehavior = true;
100153
100175
 
100154
100176
  /**
100155
100177
  * @extends {Behavior}