@woosh/meep-engine 2.118.0 → 2.118.2
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.
- package/build/bundle-worker-terrain.js +1 -1
- package/package.json +1 -1
- package/src/core/geom/3d/topology/struct/TopoMesh.d.ts +22 -2
- package/src/core/geom/3d/topology/struct/TopoMesh.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/TopoMesh.js +92 -29
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts +4 -4
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts.map +1 -1
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js +32 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e){const n=t.length;if(n!==e.length)return!1;for(let r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}class e{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,n,r){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,n,r){throw new Error("Not Implemented")}}class n{describeTo(t){throw new Error("Not Implemented")}}class r extends n{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class i{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new r(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,r){return this.appendList(t,e,n,new i(r)),this}appendList(t,e,n,r){let i=!1;this.appendText(t);const s=r[Symbol.iterator]();for(let t=s.next();!0!==t.done;t=s.next())i&&this.appendText(e),this.appendDescriptionOf(t.value),i=!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,r,i){let s,o,a;for(a=0;a<i;a++)s=e+a,o=r+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){const r=`${t} !== ${e}`;throw new Error(void 0!==n&&""!==n?`${n}. ${r}`:r)}},a.logicalyEqual=function(t,e,n){},a.ok=a,a.greaterThan=function(t,e,n){if(!(t>e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} > ${e}.`,new Error(r)}},a.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} >= ${e}.`,new Error(r)}},a.lessThan=function(t,e,n){if(!(t<e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} < ${e}.`,new Error(r)}},a.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} <= ${e}.`,new Error(r)}},a.typeOf=function(t,e,n="value"){const r=typeof t;if(r!==e)throw new Error(`expected ${n} to be ${e}, instead was '${r}'(=${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,r="Arrays are not equal"){if(!t(e,n))throw new Error(r)},a.isInstanceOf=function(t,e,n="value",r=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.isObject=function(t,e="value"){const n=typeof t;if("object"!==n)throw new Error(`expected ${e} to be an object, 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)&&!function(t){if("object"!=typeof t)return!1;if(null===t)return!1;const e=t.constructor;return e===Uint8Array||e===Uint16Array||e===Uint32Array||e===Int8Array||e===Int16Array||e===Int32Array||e===Float32Array||e===Float64Array||e===BigUint64Array||e===BigInt64Array}(t))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`)},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 r=new o;throw r.appendText(`Expected ${e} to be `),n.describeTo(r),r.appendText(" instead "),n.describeMismatch(t,r),new Error(r.value)};const c=new Uint32Array(781250);function u(t,e){return t<e?e:t}function d(t,e){return t<e?t:e}function l(t,e,n,r,i,s){const o=n[r+0],a=n[r+1],h=n[r+2],c=n[r+3],l=n[r+4],f=n[r+5],g=i[s+0],_=i[s+1],p=i[s+2],y=i[s+3],m=i[s+4],w=i[s+5],v=d(o,g),x=d(a,_),b=d(h,p),A=u(c,y),E=u(l,m),$=u(f,w);t[e+0]=v,t[e+1]=x,t[e+2]=b,t[e+3]=A,t[e+4]=E,t[e+5]=$}function f(t,e,n,r,i,s,o,a){t[e]=n,t[e+1]=r,t[e+2]=i,t[e+3]=s,t[e+4]=o,t[e+5]=a}function g(t,e,n,r,i,s){const o=r-t,a=s-n;return(i-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 r=t;return r<e&&(r=e),r<n&&(r=n),r}function y(t,e,n){let r=t;return r>e&&(r=e),r>n&&(r=n),r}function m(t,e,n){const r=t[n],i=t[n+1],s=t[n+2];f(t,e,r,i,s,r,i,s)}function w(t,e,n){const r=t[e],i=t[e+1],s=t[e+2];return function(t,e,n,r){const i=r[0],s=r[1],o=r[2],a=1023*(t-i)/(r[3]-i),h=1023*(e-s)/(r[4]-s),c=1023*(n-o)/(r[5]-o);return function(t,e,n){return _(t)|_(e)<<1|_(n)<<2}(Math.round(a),Math.round(h),Math.round(c))}(.5*(r+t[e+3]),.5*(i+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}getLeafAddress(t){return 7*t+6*this.__node_count_binary}setLeafData(t,e,n,r,i,s,o,a){const h=this.getLeafAddress(t);f(this.__data_float32,h,n,r,i,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 r;r=n<this.__node_count_binary?6*n:7*(n-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(r,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 r=this.__data_float32;return g(y(r[t+0],r[e+0],r[n+0]),y(r[t+1],r[e+1],r[n+1]),y(r[t+2],r[e+2],r[n+2]),p(r[t+3],r[e+3],r[n+3]),p(r[t+4],r[e+4],r[n+4]),p(r[t+5],r[e+5],r[n+5]))}__fitness_function_should_swap_leaves_sah(t,e){const n=u(t-1,0),r=d(t+1,this.__node_count_leaf-1),i=this.getLeafBlockAddress(),s=7*t+i,o=7*n+i,a=7*r+i,h=7*e+i,c=7*u(e-1,0)+i,l=7*d(e+1,this.__node_count_leaf-1)+i;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,r,i=2;v[0]=0,v[1]=this.__node_count_leaf-1;const s=this.__data_float32;for(;i>0;){i-=2;const o=v[i+1],a=v[i];n=a,r=o;const h=w(s,7*(a+o>>1)+e,t);for(;n<=r;){for(;w(s,7*n+e,t)<h;)n++;for(;w(s,7*r+e,t)>h;)r--;n<=r&&(n!==r&&this.__swap_leaves(n,r),n++,r--)}a<r&&(v[i++]=a,v[i++]=r),n<o&&(v[i++]=n,v[i++]=o)}}__swap_leaves(t,e){const n=this.getLeafBlockAddress(),r=7*t+n,i=7*e+n;!function(t,e,n,r,i){for(let i=0;i<7;i++){const s=e+i,o=r+i,a=n[o];n[o]=t[s],t[s]=a}}(this.__data_float32,r,this.__data_float32,i)}build(){const t=this.__node_count_binary,e=6*t;let n,r,i,s,o=Math.floor(Math.log(t)/Math.log(2));i=Math.pow(2,o),r=6*(i-1);const a=this.__node_count_leaf,c=this.__data_float32;for(n=0;n<i;n++){const t=n<<1,i=t+1,s=e+7*t;i<a?l(c,r,c,s,c,e+7*i):t<a?h(c,s,c,r,6):m(this.__data_float32,r,r-6),r+=6}for(o--;o>=0;o--)for(i=1<<o,s=i-1,n=0;n<i;n++){const t=6*(1+(s<<1));l(c,6*s,c,t,c,t+6),s++}}}function b(t,e,n,r,i,s){const o=t.getLeafAddress(e);!function(t,e,n,r,i,s){const o=3*r,a=3*i,h=3*s,c=n[o],u=n[o+1],d=n[o+2],l=n[a],f=n[a+1],g=n[a+2],_=n[h],m=n[h+1],w=n[h+2];t[e]=y(c,l,_),t[e+1]=y(u,f,m),t[e+2]=y(d,g,w),t[e+3]=p(c,l,_),t[e+4]=p(u,f,m),t[e+5]=p(d,g,w)}(t.__data_float32,o,n,r,i,s),t.__data_uint32[o+6]=e}function A(t){return 1===t.faces.length}function E(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}var $,S="undefined"!=typeof Float32Array?Float32Array:Array;function F(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function U(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function z(){}function C(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}function B(t,e){t.__edges.delete(e)}function V(t,e,n=0,r=t.length){const i=n+r;for(let r=n;r<i;r++)if(t[r]===e)return t.splice(r,1),!0;return!1}function L(t,e){return t.v0===e||t.v1===e}function M(t,e,n){const r=t.v0,i=t.v1;return!(r!==e&&r!==n||i!==e&&i!==n)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),$=new S(3),S!=Float32Array&&($[0]=0,$[1]=0,$[2]=0);let q=0;class T{index=q++;v0=null;v1=null;faces=[];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 T;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,r=n.length;for(let i=0;i<r;i++)n[i].containsEdge(this)||(t(`Missing back-link from face[${i}]`),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,r=n.length;for(let t=0;t<r;t++)n[t].removeEdge(this)}isDegenerateEdge(){return this.v0===this.v1}isTopologyBorder(){return A(this)}get length(){return this.lengthSqr<0&&this.computeSquaredLength(),Math.sqrt(this.lengthSqr)}computeSquaredLength(){const t=this.v0,e=this.v1,n=t.x,r=t.y,i=t.z,s=n-e.x,o=r-e.y,a=i-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,r=e.length;for(let i=0;i<r;i++){const r=e[i];r.removeEdge(t),-1===n.indexOf(r)&&(n.push(r),r.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){U(this.faces,t)}removeFace(t){V(this.faces,t)}getOtherVertex(t){return E(this,t)}containsVertex(t){return L(this,t)}containsBothVertices(t,e){return M(this,t,e)}containsSameVerticesAs(t){return M(this,t.v0,t.v1)}}function I(t,e,n){const r=t.length;for(let i=0;i<r;i++)t[i]===e&&(t[i]=n);return t}function N(t,e,n,r,i,s,o,a,h,c,u){const d=h-s,l=c-o,f=u-a,g=n-s,_=r-o,p=i-a,y=l*p-f*_,m=f*g-d*p,w=d*_-l*g,v=function(t,e,n){return t*t+e*e+n*n}(y,m,w);if(0===v)return t[e]=0,t[e+1]=1,void(t[e+2]=0);const x=1/Math.sqrt(v),b=y*x,A=m*x,E=w*x;t[e]=b,t[e+1]=A,t[e+2]=E}T.prototype.isTopoEdge=!0;let k=0;class O{index=k++;vertices=[];edges=[];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(),F(this.normal,t.normal)}clone(){const t=new O;return t.copy(this),t}validate(t){let e=!0;const n=this.vertices,r=n.length;3!==r&&(t(`Expected number of vertices is 3, instead got ${r}`),e=!1);for(let i=0;i<r;i++)n[i].containsFace(this)||(t(`Missing back-link from vertex[${i}]`),e=!1);const i=this.edges,s=i.length;3!==s&&(t(`Expected number of edges is 3, instead got ${s}`),e=!1);for(let n=0;n<s;n++)i[n].containsFace(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}isLinked(){return this.vertices[0].containsFace(this)}replaceEdge(t,e){I(this.edges,t,e)}replaceVertex(t,e){I(this.vertices,t,e)}isDegenerateTopology(){const t=this.vertices,e=t[0],n=t[1],r=t[2];return e===n||e===r||n===r}unlink(){const t=this.vertices,e=t.length;for(let n=0;n<e;n++)t[n].removeFace(this);const n=this.edges,r=n.length;for(let t=0;t<r;t++)n[t].removeFace(this)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return U(this.edges,t)}removeEdge(t){V(this.edges,t)}containsEdge(t){return-1!==this.edges.indexOf(t)}computeNormal(){const t=this.vertices,e=t[0],n=t[1],r=t[2];!function(t,e,n,r){N(t,0,e[0],e[1],e[2],n[0],n[1],n[2],r[0],r[1],r[2])}(this.normal,e,n,r)}setVertexAt(t,e){this.vertices[t]=e}containsVertex(t){return-1!==this.vertices.indexOf(t)}getEdgeNeighbours(t,e){let n=0;const r=this.edges,i=r.length;for(let s=0;s<i;s++){const i=r[s].faces,o=i.length;for(let r=0;r<o;r++){const s=i[r];s!==this&&(t[e+n]=s,n++)}}return n}}function j(t,e,n){return Math.sqrt(t*t+e*e+n*n)}O.prototype.isTopoFace=!0;class D{index=0;edges=[];faces=[];x=0;y=0;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 D;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,r=n.length;for(let i=0;i<r;i++)n[i].containsVertex(this)||(t(`Missing back-link from face[${i}]`),e=!1);const i=this.edges,s=i.length;for(let n=0;n<s;n++)L(i[n],this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}distanceTo(t){return e=this.x,n=this.y,r=this.z,j(t.x-e,t.y-n,t.z-r);var e,n,r}addFace(t){this.faces.push(t)}addUniqueFace(t){return U(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){V(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return U(this.edges,t)}replaceEdge(t,e){const n=this.edges,r=n.indexOf(t);n[r]=e}containsEdge(t){return-1!==this.edges.indexOf(t)}removeEdge(t){return V(this.edges,t)}replaceAnotherVertex(t){throw new Error('deprecated, use "tm_vert_splice" instead')}computeNeighbourVertices(t,e){let n=0;const r=this.edges,i=r.length;for(let s=0;s<i;s++){const i=r[s].getOtherVertex(this);t[e+n]=i,n++}return n}}D.prototype.isTopoVertex=!0;class R{vertices=[];__edges=new Set;__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=z){let e=!0,n="",r=0;function i(i){t(`${n}[${r}]: ${i}`),e=!1}n="Edge",r=0;const s=this.getEdges();for(let t of s){t.validate(i),this.containsVertex(t.v0)||i("Link to off-mesh vertex v0"),this.containsVertex(t.v1)||i("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)||i(`Link to off-mesh face[${t}]`)}r++}const o=this.getFaces();n="Face",r=0;for(let t of o){t.validate(i);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsEdge(n)||i(`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)||i(`Link to off-mesh vertex[${t}]`)}r++}const a=this.vertices,h=a.length;n="Vertex";for(let t=0;t<h;t++){r=t;const e=a[t];e.validate(i);const n=e.edges,s=n.length;for(let t=0;t<s;t++){const e=n[t];this.containsEdge(e)||i(`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)||i(`Link to off-mesh face[${t}]`)}}return e}clone(){const t=new R;return t.add(this),t}buildVertexMapping(){const t=new Map,e=this.vertices,n=e.length;for(let r=0;r<n;r++){const n=e[r];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 O;F(n.normal,t.normal);const r=t.vertices;for(let t=0;t<3;t++){const i=r[t];let s=e.get(i.index);void 0===s&&(s=new D,s.index=i.index,s.x=i.x,s.y=i.y,s.z=i.z,e.set(i.index,s),this.addVertex(s)),n.setVertexAt(t,s),s.addUniqueFace(n)}this.addFace(n),this.patchFaceEdges(n)}patchFaceEdges(t){const e=t.vertices,n=e[0],r=e[1],i=e[2],s=this.ensureEdge(n,r),o=this.ensureEdge(r,i),a=this.ensureEdge(i,n);s.addUniqueFace(t),o.addUniqueFace(t),a.addUniqueFace(t),t.addUniqueEdge(s),t.addUniqueEdge(o),t.addUniqueEdge(a)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){U(this.vertices,t)}removeVertex(t){var e;e=t,V(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){B(this,t)}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 r=t.vertices,i=r.length;for(let t=0;t<i;t++){const e=r[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,r=n.length;for(let i=0;i<r;i++){const r=n[i];if(E(r,t)===e)return r}const i=new T;return i.v0=t,i.v1=e,t.edges.push(i),e.edges.push(i),this.__edges.add(i),i}mergeEdges(){const t=this.getEdges();for(let e of t){const n=e.v0,r=e.v1;for(let i of t){if(e===i)continue;const t=i.v0,s=i.v1;if(n===t){if(r!==s)continue}else{if(n!==s)continue;if(r!==t)continue}B(this,i),e.merge(i)}}}computeEdgeSquaredLengths(){const t=this.getEdges();for(let e of t)e.computeSquaredLength()}build(t,e){const n=e.length,r=t.length/3,i=this.vertices;for(let e=0;e<r;e++){const n=3*e,r=new D;r.index=e,r.x=t[n],r.y=t[n+1],r.z=t[n+2],i[e]=r}const s=n/3,o=this.getFaces();for(let t=0;t<s;t++){const n=3*t,r=e[n],s=e[n+1],a=e[n+2],h=i[r],c=i[s],u=i[a],d=new O;d.index=t;const l=this.ensureEdge(h,c),f=this.ensureEdge(c,u),g=this.ensureEdge(u,h);l.faces.push(d),f.faces.push(d),g.faces.push(d),d.vertices.push(h,c,u),d.edges.push(l,f,g),h.faces.push(d),c.faces.push(d),u.faces.push(d),o.add(d)}}toString(){return`TopoMesh{ vertices: ${C(this.vertices.length)}, edges: ${C(this.getEdges().size)}, faces: ${C(this.getFaces().size)} }`}}R.prototype.isTopoMesh=!0;const J=[],P=[],H="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)J[t]=H[t],P[H.charCodeAt(t)]=t;function W(t,e,n){const r=[];for(let s=e;s<n;s+=3){const e=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]);r.push(J[(i=e)>>18&63]+J[i>>12&63]+J[i>>6&63]+J[63&i])}var i;return r.join("")}P["-".charCodeAt(0)]=62,P["_".charCodeAt(0)]=63;const G=16383;class Y{static encode(t){return function(t){const e=t.length,n=e%3,r=[],i=e-n;for(let e=0;e<i;e+=G){const n=W(t,e,e+G>i?i:e+G);r.push(n)}if(1===n){const n=t[e-1];r.push(J[n>>2]+J[n<<4&63]+"==")}else if(2===n){const n=(t[e-2]<<8)+t[e-1];r.push(J[n>>10]+J[n>>4&63]+J[n<<2&63]+"=")}return r.join("")}(new Uint8Array(t))}static decode(t){return function(t){let e;const n=function(t){const e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");let n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}(t),r=n[0],i=n[1],s=new Uint8Array(function(t,e){return 3*(t+e)/4-e}(r,i));let o=0;const a=i>0?r-4:r;let h=0;for(;h<a;h+=4){const n=t.charCodeAt(h),r=t.charCodeAt(h+1),i=t.charCodeAt(h+2),a=t.charCodeAt(h+3);e=P[n]<<18|P[r]<<12|P[i]<<6|P[a],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=255&e}if(2===i){const n=t.charCodeAt(h),r=t.charCodeAt(h+1);e=P[n]<<2|P[r]>>4,s[o++]=255&e}if(1===i){const n=t.charCodeAt(h),r=t.charCodeAt(h+1),i=t.charCodeAt(h+2);e=P[n]<<10|P[r]<<4|P[i]>>2,s[o++]=e>>8&255,s[o++]=255&e}return s}(t).buffer}}const K="uint8",Q="uint16",X="uint32",Z="int8",tt="int16",et="int32",nt="float32",rt="float64",it={[K]:Uint8Array,[Q]:Uint16Array,[X]:Uint32Array,[Z]:Int8Array,[tt]:Int16Array,[et]:Int32Array,float16:Uint16Array,[nt]:Float32Array,[rt]:Float64Array};function st(t){const e=Object.getPrototypeOf(t).constructor;switch(e){case Uint8Array:case Uint8ClampedArray:return K;case Uint16Array:return Q;case Uint32Array:return X;case Int8Array:return Z;case Int16Array:return tt;case Int32Array:return et;case Float32Array:return nt;case Float64Array:return rt;default:throw new Error(`unsupported constructor type ${e.name}`)}}function ot(t,e,n){return t<e?e:t>n?n:t}function at(t,e,n){return(e-t)*n+t}function ht(t,e,n,r,i){return.5*(r-e+(2*e-5*n+4*r-i+(3*(n-r)+i-e)*t)*t)*t+n}class ct{constructor(t=[],e=1,n=0,r=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(r)||n<0)throw new Error(`height must be a non-negative integer, instead was ${r}`);if(void 0===t)throw new Error("data was undefined");if(t.length<n*r*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${n*r*e}`);this.width=n,this.height=r,this.itemSize=e,this.data=t,this.version=0}get(t,e,n){throw new Error("Deprecated method, use sampleBilinear instead")}sampleCatmullRomUV(t,e,n){const r=this.itemSize;for(let i=0;i<r;i++)n[i]=this.sampleChannelCatmullRomUV(t,e,i)}sampleChannelCatmullRomUV(t,e,n){const r=t*this.width-.5,i=e*this.height-.5;return this.sampleChannelCatmullRom(r,i,n)}sampleChannelCatmullRom(t,e,n){const r=Math.floor(t),i=Math.floor(e),s=t-r,o=e-i,a=s*(s*(1-.5*s)-.5),h=o*(o*(1-.5*o)-.5),c=s*(.5+s*(2-1.5*s)),u=o*(.5+o*(2-1.5*o)),d=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)+u,_=r-1,p=i-1,y=r+2,m=i+2,w=r+c/f,v=i+u/g;let x=0;return x+=this.sampleChannelBilinear(_,p,n)*a*h,x+=this.sampleChannelBilinear(w,p,n)*f*h,x+=this.sampleChannelBilinear(y,p,n)*d*h,x+=this.sampleChannelBilinear(_,v,n)*a*g,x+=this.sampleChannelBilinear(w,v,n)*f*g,x+=this.sampleChannelBilinear(y,v,n)*d*g,x+=this.sampleChannelBilinear(_,m,n)*a*l,x+=this.sampleChannelBilinear(w,m,n)*f*l,x+=this.sampleChannelBilinear(y,m,n)*d*l,x}sampleBicubicUV(t,e,n){const r=this.itemSize;for(let i=0;i<r;i++)n[i]=this.sampleChannelBicubicUV(t,e,i)}sampleBicubic(t,e,n,r){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBicubic(t,e,s)}sampleChannelBicubicUV(t,e,n){const r=t*this.width,i=e*this.height;return this.sampleChannelBicubic(r-.5,i-.5,n)}sampleChannelBicubic(t,e,n){const r=this.itemSize,i=this.width,s=this.height,o=this.data,a=i*r,h=i-1,c=s-1,l=ot(t,0,h),f=ot(e,0,c),g=0|l,_=0|f,p=l-g,y=f-_,m=u(0,g-1),w=u(0,_-1),v=d(h,g+1),x=d(c,_+1),b=d(h,v+1),A=w*a+n,E=_*a+n,$=x*a+n,S=d(c,x+1)*a+n,F=m*r,U=g*r,z=v*r,C=b*r,B=o[A+F],V=o[A+U],L=o[A+z],M=o[A+C],q=o[E+F],T=o[E+U],I=o[E+z],N=o[E+C],k=o[$+F],O=o[$+U],j=o[$+z],D=o[$+C],R=o[S+F],J=o[S+U],P=o[S+z],H=o[S+C],W=ht(p,B,V,L,M),G=ht(p,q,T,I,N),Y=ht(p,k,O,j,D),K=ht(p,R,J,P,H);return ht(y,W,G,Y,K)}sampleBilinearUV(t,e,n,r=0){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBilinearUV(t,e,s)}sampleBilinear(t,e,n,r=0){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBilinear(t,e,s)}sampleChannelBilinearUV(t,e,n){const r=t*this.width-.5,i=e*this.height-.5;return this.sampleChannelBilinear(r,i,n)}sampleChannelBilinear(t,e,n){const r=this.itemSize,i=this.width,s=i*r,o=this.height-1,a=ot(t,0,i-1),h=ot(e,0,o),c=a>>>0,u=h>>>0,d=u*s,l=c*r+n,f=d+l;let g,_;g=a===c?c:c+1,_=h===u?u:u+1;const p=this.data,y=p[f];if(c===g&&u===_)return y;const m=a-c,w=h-u,v=g*r+n,x=_*s,b=x+l,A=x+v,E=p[d+v],$=p[b],S=p[A],F=at(y,E,m),U=at($,S,m);return at(F,U,w)}sampleNearestUV(t,e,n){const r=this.width,i=this.height,s=Math.round(t*r-.5),o=Math.round(e*i-.5);this.read(ot(s,0,r-1),ot(o,0,i-1),n)}readChannel(t,e,n){const r=(e*this.width+t)*this.itemSize+n;return this.data[r]}read(t,e,n){const r=this.width,i=this.itemSize,s=(e*r+t)*i;for(let t=0;t<i;t++)n[t]=this.data[s+t]}write(t,e,n){const r=this.width,i=this.itemSize,s=(e*r+t)*i;for(let t=0;t<i;t++)this.data[s+t]=n[t]}sample(t,e,n){const r=[];return this.sampleBilinear(t*(this.width-1),e*(this.height-1),r,0),n.readFromArray(r),r[0]}point2index(t,e){return t+e*this.width}index2point(t,e){const n=this.width,r=t%n,i=t/n|0;e.set(r,i)}copy(t,e,n,r,i,s,o){const a=Math.min(s,t.width-e,this.width-r),h=Math.min(o,t.height-n,this.height-i),c=this.itemSize,u=t.itemSize,d=Math.min(c,u),l=c*this.width,f=u*t.width,g=t.data,_=this.data;let p,y,m;for(y=0;y<h;y++){const t=(y+i)*l,s=(y+n)*f;for(p=0;p<a;p++){const n=t+(p+r)*c,i=s+(p+e)*u;for(m=0;m<d;m++)_[n+m]=g[i+m]}}this.version++}zeroFill(t,e,n,r){const i=ot(t,0,this.width),s=ot(e,0,this.height),o=ot(t+n,0,this.width),a=ot(e+r,0,this.height),h=this.data,c=this.itemSize,u=c*this.width,d=i*c,l=o*c;let f;for(f=s;f<a;f++){const t=f*u;h.fill(0,t+d,t+l)}this.version++}channelFill(t,e){const n=this.itemSize,r=this.data,i=r.length;for(let s=t;s<i;s+=n)r[s]=e;this.version++}fill(t,e,n,r,i){const s=this.width,o=this.height,a=ot(t,0,s),h=ot(e,0,o),c=ot(t+n,0,s),u=ot(e+r,0,o),d=this.data,l=this.itemSize,f=l*s;let g,_,p;for(g=h;g<u;g++){const t=g*f;for(_=a;_<c;_++){const e=t+_*l;for(p=0;p<l;p++)d[e+p]=i[p]}}this.version++}writeChannel(t,e,n,r){const i=(e*this.width+t)*this.itemSize+n;this.data[i]=r,this.version++}set(t,e,n){const r=this.data,i=this.itemSize,s=i*this.width*e+t*i;for(let t=0;t<i;t++)r[s+t]=n[t];this.version++}traverseCircle(t,e,n,r){let i,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(i=-c;i<=c;i++)i*i+t<=h&&r(o+i,a+s,this)}}resize(t,e,n=!0){const r=this.width,i=this.height;if(r===t&&i===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===r)h.set(a.subarray(0,Math.min(a.length,o)));else{const n=d(e,i),o=d(t,r);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const i=(e*t+n)*s,o=(e*r+n)*s;for(let t=0;t<s;t++)h[i+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}equals(e){return this.width===e.width&&this.height===e.height&&this.itemSize===e.itemSize&&function(e,n){if(e===n)return!0;const r=e.length;if(r!==n.length)return!1;const i=e.constructor;if(i!==n.constructor)return!1;if(0===r)return!0;if(r<128)return t(e,n);const s=e.byteLength;if(s!==n.byteLength)return!1;const o=e.buffer,a=n.buffer,h=e.byteOffset,c=n.byteOffset;if(o===a&&h===c)return!0;let u=e,d=n;const l=i.BYTES_PER_ELEMENT,f=function(t,e,n){const r=t|e|n;return 0==(3&r)?4:0==(1&r)?2:1}(h,c,s);return l<4&&4===f?(u=new Uint32Array(o,h,s>>>2),d=new Uint32Array(a,c,s>>>2)):l<2&&2===f&&(u=new Uint16Array(o,h,s>>>1),d=new Uint16Array(a,c,s>>>1)),t(u,d)}(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,r){let i=n;for(let e=0;e<n;e+=r)i=(i<<5)-i+(t[e]>>>0);return i>>>0}(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 ct(t,this.itemSize,this.width,this.height)}toJSON(){const t=Y.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:st(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:r,data:i}){const s=function(t){const e=it[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(r);if("string"==typeof i){const t=Y.decode(i);this.data=new s(t)}else{if(!Array.isArray(i))throw new Error("Unsupported data format");this.data=new s(i)}this.height=t,this.width=e,this.itemSize=n}static uint8clamped(t,e,n){const r=new Uint8ClampedArray(e*n*t);return new ct(r,t,e,n)}static uint8(t,e,n){const r=new Uint8Array(e*n*t);return new ct(r,t,e,n)}static uint16(t,e,n){const r=new Uint16Array(e*n*t);return new ct(r,t,e,n)}static uint32(t,e,n){const r=new Uint32Array(e*n*t);return new ct(r,t,e,n)}static int8(t,e,n){const r=new Int8Array(e*n*t);return new ct(r,t,e,n)}static int16(t,e,n){const r=new Int16Array(e*n*t);return new ct(r,t,e,n)}static int32(t,e,n){const r=new Int32Array(e*n*t);return new ct(r,t,e,n)}static float32(t,e,n){const r=new Float32Array(e*n*t);return new ct(r,t,e,n)}static float64(t,e,n){const r=new Float64Array(e*n*t);return new ct(r,t,e,n)}}function ut(t,e,n,r){const i=n[r],s=n[r+1],o=n[r+2];t[e]+=i,t[e+1]+=s,t[e+2]+=o}function dt(t,e,n,r,i,s){const o=3*n,a=3*r,h=3*i;N(t,e,s[o],s[o+1],s[o+2],s[a],s[a+1],s[a+2],s[h],s[h+1],s[h+2])}function lt(t,e,n,r){const i=n[r],s=n[r+1],o=n[r+2],a=1/j(i,s,o);t[e]=i*a,t[e+1]=s*a,t[e+2]=o*a}ct.prototype.isSampler2D=!0,ct.typeName="Sampler2D";const ft=new Float64Array(3),gt={build:function(t,e,n,r,i,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let u=0,d=0;const l=o*a,f=new Float32Array(3*l),g=new Float32Array(3*l),_=new Float32Array(2*l);let p,y;const m=n.y/i.y/c,w=n.x/i.x/h,v=e.y/i.y,x=e.x/i.x,b=i.x*r.x,A=i.y*r.y;let E,$,S;for(p=0;p<a;p++){const e=p*m+v;for(S=e*A,y=0;y<o;y++){const n=y*w+x;E=n*b,$=t.sampleChannelBicubicUV(n,e,0),f[u]=E,f[u+1]=$,f[u+2]=S,_[d]=n,_[d+1]=e,u+=3,d+=2}}u=0;const F=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(p=0;p<c;p++)for(y=0;y<h;y++){const t=y+o*p,e=y+o*(p+1),n=y+1+o*(p+1),r=y+1+o*p;F[u]=t,F[u+1]=e,F[u+2]=r,F[u+3]=e,F[u+4]=n,F[u+5]=r,u+=6}return function(t,e,n){const r=n.length;for(let i=0;i<r;i+=3){const r=n[i],s=n[i+1],o=n[i+2];dt(ft,0,r,s,o,t),ut(e,3*r,ft,0),ut(e,3*s,ft,0),ut(e,3*o,ft,0)}!function(t,e=0,n=t.length-e){const r=e+n;for(let n=e;n<r;n+=3)lt(t,n,t,n)}(e)}(f,g,F),{indices:F,vertices:f,normals:g,uvs:_}}};self.Lib={build_bvh(t,e){const n=new x;return function(t,e,n){const r=n.length/3;t.setLeafCount(r),t.initialize_structure();for(let i=0;i<r;i++){const r=3*i;b(t,i,e,n[r],n[r+1],n[r+2])}t.build()}(n,t,e),n},Sampler2D:ct,BufferedGeometryArraysBuilder:gt,tensionOptimizeUV:function(t,e,n,r=3){const i=new R;i.build(t,n),i.computeEdgeSquaredLengths();const s=t.length/3;for(let t=0;t<r;t++)t:for(let t=0;t<s;t++){const n=i.vertices[t],r=n.edges,s=r.length;if(0===s)continue;let o=0,a=0,h=0;for(let t=0;t<s;t++){const i=r[t];if(A(i))continue t;const s=2*E(i,n).index,c=e[s],u=e[s+1],d=1/i.lengthSqr;o+=c*d,a+=u*d,h+=d}const c=o/h,u=a/h,d=2*n.index;e[d]=c,e[d+1]=u}},sampler2d_channel_compute_min:function(t,e=0){const n=t.itemSize,r=t.data,i=r.length;if(0===i)return;let s=r[e],o=e;for(let t=e+n;t<i;t+=n){const e=r[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,r=t.data,i=r.length;if(0===i)return;let s=r[e],o=e;for(let t=e+n;t<i;t+=n){const e=r[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;for(let r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}class e{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,n,r){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,n,r){throw new Error("Not Implemented")}}class n{describeTo(t){throw new Error("Not Implemented")}}class r extends n{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class i{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new r(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,r){return this.appendList(t,e,n,new i(r)),this}appendList(t,e,n,r){let i=!1;this.appendText(t);const s=r[Symbol.iterator]();for(let t=s.next();!0!==t.done;t=s.next())i&&this.appendText(e),this.appendDescriptionOf(t.value),i=!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,r,i){let s,o,a;for(a=0;a<i;a++)s=e+a,o=r+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){const r=`${t} !== ${e}`;throw new Error(void 0!==n&&""!==n?`${n}. ${r}`:r)}},a.logicalyEqual=function(t,e,n){},a.ok=a,a.greaterThan=function(t,e,n){if(!(t>e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} > ${e}.`,new Error(r)}},a.greaterThanOrEqual=function(t,e,n){if(!(t>=e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} >= ${e}.`,new Error(r)}},a.lessThan=function(t,e,n){if(!(t<e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} < ${e}.`,new Error(r)}},a.lessThanOrEqual=function(t,e,n){if(!(t<=e)){let r="";throw void 0!==n&&(r+=n+". "),r+=`Expected ${t} <= ${e}.`,new Error(r)}},a.typeOf=function(t,e,n="value"){const r=typeof t;if(r!==e)throw new Error(`expected ${n} to be ${e}, instead was '${r}'(=${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,r="Arrays are not equal"){if(!t(e,n))throw new Error(r)},a.isInstanceOf=function(t,e,n="value",r=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.isObject=function(t,e="value"){const n=typeof t;if("object"!==n)throw new Error(`expected ${e} to be an object, 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)&&!function(t){if("object"!=typeof t)return!1;if(null===t)return!1;const e=t.constructor;return e===Uint8Array||e===Uint16Array||e===Uint32Array||e===Int8Array||e===Int16Array||e===Int32Array||e===Float32Array||e===Float64Array||e===BigUint64Array||e===BigInt64Array}(t))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`)},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 r=new o;throw r.appendText(`Expected ${e} to be `),n.describeTo(r),r.appendText(" instead "),n.describeMismatch(t,r),new Error(r.value)};const c=new Uint32Array(781250);function u(t,e){return t<e?e:t}function d(t,e){return t<e?t:e}function l(t,e,n,r,i,s){const o=n[r+0],a=n[r+1],h=n[r+2],c=n[r+3],l=n[r+4],f=n[r+5],g=i[s+0],_=i[s+1],p=i[s+2],y=i[s+3],m=i[s+4],w=i[s+5],v=d(o,g),x=d(a,_),b=d(h,p),A=u(c,y),E=u(l,m),F=u(f,w);t[e+0]=v,t[e+1]=x,t[e+2]=b,t[e+3]=A,t[e+4]=E,t[e+5]=F}function f(t,e,n,r,i,s,o,a){t[e]=n,t[e+1]=r,t[e+2]=i,t[e+3]=s,t[e+4]=o,t[e+5]=a}function g(t,e,n,r,i,s){const o=r-t,a=s-n;return(i-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 r=t;return r<e&&(r=e),r<n&&(r=n),r}function y(t,e,n){let r=t;return r>e&&(r=e),r>n&&(r=n),r}function m(t,e,n){const r=t[n],i=t[n+1],s=t[n+2];f(t,e,r,i,s,r,i,s)}function w(t,e,n){const r=t[e],i=t[e+1],s=t[e+2];return function(t,e,n,r){const i=r[0],s=r[1],o=r[2],a=1023*(t-i)/(r[3]-i),h=1023*(e-s)/(r[4]-s),c=1023*(n-o)/(r[5]-o);return function(t,e,n){return _(t)|_(e)<<1|_(n)<<2}(Math.round(a),Math.round(h),Math.round(c))}(.5*(r+t[e+3]),.5*(i+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}getLeafAddress(t){return 7*t+6*this.__node_count_binary}setLeafData(t,e,n,r,i,s,o,a){const h=this.getLeafAddress(t);f(this.__data_float32,h,n,r,i,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 r;r=n<this.__node_count_binary?6*n:7*(n-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(r,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 r=this.__data_float32;return g(y(r[t+0],r[e+0],r[n+0]),y(r[t+1],r[e+1],r[n+1]),y(r[t+2],r[e+2],r[n+2]),p(r[t+3],r[e+3],r[n+3]),p(r[t+4],r[e+4],r[n+4]),p(r[t+5],r[e+5],r[n+5]))}__fitness_function_should_swap_leaves_sah(t,e){const n=u(t-1,0),r=d(t+1,this.__node_count_leaf-1),i=this.getLeafBlockAddress(),s=7*t+i,o=7*n+i,a=7*r+i,h=7*e+i,c=7*u(e-1,0)+i,l=7*d(e+1,this.__node_count_leaf-1)+i;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,r,i=2;v[0]=0,v[1]=this.__node_count_leaf-1;const s=this.__data_float32;for(;i>0;){i-=2;const o=v[i+1],a=v[i];n=a,r=o;const h=w(s,7*(a+o>>1)+e,t);for(;n<=r;){for(;w(s,7*n+e,t)<h;)n++;for(;w(s,7*r+e,t)>h;)r--;n<=r&&(n!==r&&this.__swap_leaves(n,r),n++,r--)}a<r&&(v[i++]=a,v[i++]=r),n<o&&(v[i++]=n,v[i++]=o)}}__swap_leaves(t,e){const n=this.getLeafBlockAddress(),r=7*t+n,i=7*e+n;!function(t,e,n,r,i){for(let i=0;i<7;i++){const s=e+i,o=r+i,a=n[o];n[o]=t[s],t[s]=a}}(this.__data_float32,r,this.__data_float32,i)}build(){const t=this.__node_count_binary,e=6*t;let n,r,i,s,o=Math.floor(Math.log(t)/Math.log(2));i=Math.pow(2,o),r=6*(i-1);const a=this.__node_count_leaf,c=this.__data_float32;for(n=0;n<i;n++){const t=n<<1,i=t+1,s=e+7*t;i<a?l(c,r,c,s,c,e+7*i):t<a?h(c,s,c,r,6):m(this.__data_float32,r,r-6),r+=6}for(o--;o>=0;o--)for(i=1<<o,s=i-1,n=0;n<i;n++){const t=6*(1+(s<<1));l(c,6*s,c,t,c,t+6),s++}}}function b(t,e,n,r,i,s){const o=t.getLeafAddress(e);!function(t,e,n,r,i,s){const o=3*r,a=3*i,h=3*s,c=n[o],u=n[o+1],d=n[o+2],l=n[a],f=n[a+1],g=n[a+2],_=n[h],m=n[h+1],w=n[h+2];t[e]=y(c,l,_),t[e+1]=y(u,f,m),t[e+2]=y(d,g,w),t[e+3]=p(c,l,_),t[e+4]=p(u,f,m),t[e+5]=p(d,g,w)}(t.__data_float32,o,n,r,i,s),t.__data_uint32[o+6]=e}function A(t){return 1===t.faces.length}function E(t,e){return t.v0===e?t.v1:t.v1===e?t.v0:null}var F,$="undefined"!=typeof Float32Array?Float32Array:Array;function S(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function U(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function z(){}function C(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}function B(t,e){t.__edges.delete(e)}function V(t,e,n=0,r=t.length){const i=n+r;for(let r=n;r<i;r++)if(t[r]===e)return t.splice(r,1),!0;return!1}function L(t,e){return t.v0===e||t.v1===e}function M(t,e,n){const r=t.v0,i=t.v1;return!(r!==e&&r!==n||i!==e&&i!==n)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),F=new $(3),$!=Float32Array&&(F[0]=0,F[1]=0,F[2]=0);let T=0;class q{index=T++;v0=null;v1=null;faces=[];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 q;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,r=n.length;for(let i=0;i<r;i++)n[i].containsEdge(this)||(t(`Missing back-link from face[${i}]`),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,r=n.length;for(let t=0;t<r;t++)n[t].removeEdge(this)}isDegenerateEdge(){return this.v0===this.v1}isTopologyBorder(){return A(this)}get length(){return this.lengthSqr<0&&this.computeSquaredLength(),Math.sqrt(this.lengthSqr)}computeSquaredLength(){const t=this.v0,e=this.v1,n=t.x,r=t.y,i=t.z,s=n-e.x,o=r-e.y,a=i-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,r=e.length;for(let i=0;i<r;i++){const r=e[i];r.removeEdge(t),-1===n.indexOf(r)&&(n.push(r),r.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){U(this.faces,t)}removeFace(t){V(this.faces,t)}getOtherVertex(t){return E(this,t)}containsVertex(t){return L(this,t)}containsBothVertices(t,e){return M(this,t,e)}containsSameVerticesAs(t){return M(this,t.v0,t.v1)}}function I(t,e,n){const r=t.length;for(let i=0;i<r;i++)t[i]===e&&(t[i]=n);return t}function N(t,e,n,r,i,s,o,a,h,c,u){const d=h-s,l=c-o,f=u-a,g=n-s,_=r-o,p=i-a,y=l*p-f*_,m=f*g-d*p,w=d*_-l*g,v=function(t,e,n){return t*t+e*e+n*n}(y,m,w);if(0===v)return t[e]=0,t[e+1]=1,void(t[e+2]=0);const x=1/Math.sqrt(v),b=y*x,A=m*x,E=w*x;t[e]=b,t[e+1]=A,t[e+2]=E}q.prototype.isTopoEdge=!0;let k=0;class O{index=k++;vertices=[];edges=[];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(),S(this.normal,t.normal)}clone(){const t=new O;return t.copy(this),t}validate(t){let e=!0;const n=this.vertices,r=n.length;3!==r&&(t(`Expected number of vertices is 3, instead got ${r}`),e=!1);for(let i=0;i<r;i++)n[i].containsFace(this)||(t(`Missing back-link from vertex[${i}]`),e=!1);const i=this.edges,s=i.length;3!==s&&(t(`Expected number of edges is 3, instead got ${s}`),e=!1);for(let n=0;n<s;n++)i[n].containsFace(this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}isLinked(){return this.vertices[0].containsFace(this)}replaceEdge(t,e){I(this.edges,t,e)}replaceVertex(t,e){I(this.vertices,t,e)}isDegenerateTopology(){const t=this.vertices,e=t[0],n=t[1],r=t[2];return e===n||e===r||n===r}unlink(){const t=this.vertices,e=t.length;for(let n=0;n<e;n++)t[n].removeFace(this);const n=this.edges,r=n.length;for(let t=0;t<r;t++)n[t].removeFace(this)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return U(this.edges,t)}removeEdge(t){V(this.edges,t)}containsEdge(t){return-1!==this.edges.indexOf(t)}computeNormal(){const t=this.vertices,e=t[0],n=t[1],r=t[2];!function(t,e,n,r){N(t,0,e[0],e[1],e[2],n[0],n[1],n[2],r[0],r[1],r[2])}(this.normal,e,n,r)}setVertexAt(t,e){this.vertices[t]=e}containsVertex(t){return-1!==this.vertices.indexOf(t)}getEdgeNeighbours(t,e){let n=0;const r=this.edges,i=r.length;for(let s=0;s<i;s++){const i=r[s].faces,o=i.length;for(let r=0;r<o;r++){const s=i[r];s!==this&&(t[e+n]=s,n++)}}return n}}function j(t,e,n){return Math.sqrt(t*t+e*e+n*n)}O.prototype.isTopoFace=!0;class D{index=0;edges=[];faces=[];x=0;y=0;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 D;return t.copy(this),t}validate(t){let e=!0;const n=this.faces,r=n.length;for(let i=0;i<r;i++)n[i].containsVertex(this)||(t(`Missing back-link from face[${i}]`),e=!1);const i=this.edges,s=i.length;for(let n=0;n<s;n++)L(i[n],this)||(t(`Missing back-link from edge[${n}]`),e=!1);return e}distanceTo(t){return e=this.x,n=this.y,r=this.z,j(t.x-e,t.y-n,t.z-r);var e,n,r}addFace(t){this.faces.push(t)}addUniqueFace(t){return U(this.faces,t)}containsFace(t){return-1!==this.faces.indexOf(t)}removeFace(t){V(this.faces,t)}addEdge(t){this.edges.push(t)}addUniqueEdge(t){return U(this.edges,t)}replaceEdge(t,e){const n=this.edges,r=n.indexOf(t);n[r]=e}containsEdge(t){return-1!==this.edges.indexOf(t)}removeEdge(t){return V(this.edges,t)}replaceAnotherVertex(t){throw new Error('deprecated, use "tm_vert_splice" instead')}computeNeighbourVertices(t,e){let n=0;const r=this.edges,i=r.length;for(let s=0;s<i;s++){const i=r[s].getOtherVertex(this);t[e+n]=i,n++}return n}}D.prototype.isTopoVertex=!0;class R{vertices=[];__edges=new Set;__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=z){let e=!0,n="",r=0;function i(i){t(`${n}[${r}]: ${i}`),e=!1}n="Edge",r=0;const s=this.getEdges();for(let t of s){t.validate(i),this.containsVertex(t.v0)||i("Link to off-mesh vertex v0"),this.containsVertex(t.v1)||i("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)||i(`Link to off-mesh face[${t}]`)}r++}const o=this.getFaces();n="Face",r=0;for(let t of o){t.validate(i);const e=t.edges,n=e.length;for(let t=0;t<n;t++){const n=e[t];this.containsEdge(n)||i(`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)||i(`Link to off-mesh vertex[${t}]`)}r++}const a=this.vertices,h=a.length;n="Vertex";for(let t=0;t<h;t++){r=t;const e=a[t];e.validate(i);const n=e.edges,s=n.length;for(let t=0;t<s;t++){const e=n[t];this.containsEdge(e)||i(`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)||i(`Link to off-mesh face[${t}]`)}}return e}clone(){const t=new R;return t.add(this),t}buildVertexMapping(){const t=new Map,e=this.vertices,n=e.length;for(let r=0;r<n;r++){const n=e[r];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 O;S(n.normal,t.normal);const r=t.vertices;for(let t=0;t<3;t++){const i=r[t];let s=e.get(i.index);void 0===s&&(s=new D,s.index=i.index,s.x=i.x,s.y=i.y,s.z=i.z,e.set(i.index,s),this.addVertex(s)),n.setVertexAt(t,s),s.addUniqueFace(n)}this.addFace(n),this.patchFaceEdges(n)}patchFaceEdges(t){const e=t.vertices,n=e[0],r=e[1],i=e[2],s=this.ensureEdge(n,r),o=this.ensureEdge(r,i),a=this.ensureEdge(i,n);s.addUniqueFace(t),o.addUniqueFace(t),a.addUniqueFace(t),t.addUniqueEdge(s),t.addUniqueEdge(o),t.addUniqueEdge(a)}add(t){const e=this.buildVertexMapping();this._addWithVertexMap(t,e)}addVertex(t){this.vertices.push(t)}addUniqueVertex(t){U(this.vertices,t)}removeVertex(t){var e;e=t,V(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){B(this,t)}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 r=t.vertices,i=r.length;for(let t=0;t<i;t++){const e=r[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,r=n.length;for(let i=0;i<r;i++){const r=n[i];if(E(r,t)===e)return r}const i=new q;return i.v0=t,i.v1=e,t.edges.push(i),e.edges.push(i),this.__edges.add(i),i}mergeEdges(){const t=this.getEdges();for(let e of t){const n=e.v0,r=e.v1;for(let i of t){if(e===i)continue;const t=i.v0,s=i.v1;if(n===t){if(r!==s)continue}else{if(n!==s)continue;if(r!==t)continue}B(this,i),e.merge(i)}}}computeEdgeSquaredLengths(){const t=this.getEdges();for(let e of t)e.computeSquaredLength()}setVerticesFromArray(t){const e=t.length/3,n=this.vertices;for(let r=0;r<e;r++){const e=3*r,i=new D;i.index=r,i.x=t[e],i.y=t[e+1],i.z=t[e+2],n[r]=i}}setFacesFromIndexArray(t){const e=t.length,n=this.vertices,r=e/3;for(let e=0;e<r;e++){const r=3*e,i=t[r],s=t[r+1],o=t[r+2];this.createTriangle(e,n[i],n[s],n[o])}}setFacedUnindexed(){const t=this.vertices,e=t.length/3;for(let n=0;n<e;n++){const e=3*n;this.createTriangle(n,t[e],t[e+1],t[e+2])}}build(t,e){this.setVerticesFromArray(t),null==e?this.setFacedUnindexed():this.setFacesFromIndexArray(e)}createTriangle(t,e,n,r){const i=new O;i.index=t;const s=this.ensureEdge(e,n),o=this.ensureEdge(n,r),a=this.ensureEdge(r,e);return s.faces.push(i),o.faces.push(i),a.faces.push(i),i.vertices.push(e,n,r),i.edges.push(s,o,a),e.faces.push(i),n.faces.push(i),r.faces.push(i),this.__faces.add(i),i}toString(){return`TopoMesh{ vertices: ${C(this.vertices.length)}, edges: ${C(this.getEdges().size)}, faces: ${C(this.getFaces().size)} }`}}R.prototype.isTopoMesh=!0;const J=[],P=[],H="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)J[t]=H[t],P[H.charCodeAt(t)]=t;function W(t,e,n){const r=[];for(let s=e;s<n;s+=3){const e=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]);r.push(J[(i=e)>>18&63]+J[i>>12&63]+J[i>>6&63]+J[63&i])}var i;return r.join("")}P["-".charCodeAt(0)]=62,P["_".charCodeAt(0)]=63;const G=16383;class Y{static encode(t){return function(t){const e=t.length,n=e%3,r=[],i=e-n;for(let e=0;e<i;e+=G){const n=W(t,e,e+G>i?i:e+G);r.push(n)}if(1===n){const n=t[e-1];r.push(J[n>>2]+J[n<<4&63]+"==")}else if(2===n){const n=(t[e-2]<<8)+t[e-1];r.push(J[n>>10]+J[n>>4&63]+J[n<<2&63]+"=")}return r.join("")}(new Uint8Array(t))}static decode(t){return function(t){let e;const n=function(t){const e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");let n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}(t),r=n[0],i=n[1],s=new Uint8Array(function(t,e){return 3*(t+e)/4-e}(r,i));let o=0;const a=i>0?r-4:r;let h=0;for(;h<a;h+=4){const n=t.charCodeAt(h),r=t.charCodeAt(h+1),i=t.charCodeAt(h+2),a=t.charCodeAt(h+3);e=P[n]<<18|P[r]<<12|P[i]<<6|P[a],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=255&e}if(2===i){const n=t.charCodeAt(h),r=t.charCodeAt(h+1);e=P[n]<<2|P[r]>>4,s[o++]=255&e}if(1===i){const n=t.charCodeAt(h),r=t.charCodeAt(h+1),i=t.charCodeAt(h+2);e=P[n]<<10|P[r]<<4|P[i]>>2,s[o++]=e>>8&255,s[o++]=255&e}return s}(t).buffer}}const K="uint8",Q="uint16",X="uint32",Z="int8",tt="int16",et="int32",nt="float32",rt="float64",it={[K]:Uint8Array,[Q]:Uint16Array,[X]:Uint32Array,[Z]:Int8Array,[tt]:Int16Array,[et]:Int32Array,float16:Uint16Array,[nt]:Float32Array,[rt]:Float64Array};function st(t){const e=Object.getPrototypeOf(t).constructor;switch(e){case Uint8Array:case Uint8ClampedArray:return K;case Uint16Array:return Q;case Uint32Array:return X;case Int8Array:return Z;case Int16Array:return tt;case Int32Array:return et;case Float32Array:return nt;case Float64Array:return rt;default:throw new Error(`unsupported constructor type ${e.name}`)}}function ot(t,e,n){return t<e?e:t>n?n:t}function at(t,e,n){return(e-t)*n+t}function ht(t,e,n,r,i){return.5*(r-e+(2*e-5*n+4*r-i+(3*(n-r)+i-e)*t)*t)*t+n}class ct{constructor(t=[],e=1,n=0,r=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(r)||n<0)throw new Error(`height must be a non-negative integer, instead was ${r}`);if(void 0===t)throw new Error("data was undefined");if(t.length<n*r*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${n*r*e}`);this.width=n,this.height=r,this.itemSize=e,this.data=t,this.version=0}get(t,e,n){throw new Error("Deprecated method, use sampleBilinear instead")}sampleCatmullRomUV(t,e,n){const r=this.itemSize;for(let i=0;i<r;i++)n[i]=this.sampleChannelCatmullRomUV(t,e,i)}sampleChannelCatmullRomUV(t,e,n){const r=t*this.width-.5,i=e*this.height-.5;return this.sampleChannelCatmullRom(r,i,n)}sampleChannelCatmullRom(t,e,n){const r=Math.floor(t),i=Math.floor(e),s=t-r,o=e-i,a=s*(s*(1-.5*s)-.5),h=o*(o*(1-.5*o)-.5),c=s*(.5+s*(2-1.5*s)),u=o*(.5+o*(2-1.5*o)),d=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)+u,_=r-1,p=i-1,y=r+2,m=i+2,w=r+c/f,v=i+u/g;let x=0;return x+=this.sampleChannelBilinear(_,p,n)*a*h,x+=this.sampleChannelBilinear(w,p,n)*f*h,x+=this.sampleChannelBilinear(y,p,n)*d*h,x+=this.sampleChannelBilinear(_,v,n)*a*g,x+=this.sampleChannelBilinear(w,v,n)*f*g,x+=this.sampleChannelBilinear(y,v,n)*d*g,x+=this.sampleChannelBilinear(_,m,n)*a*l,x+=this.sampleChannelBilinear(w,m,n)*f*l,x+=this.sampleChannelBilinear(y,m,n)*d*l,x}sampleBicubicUV(t,e,n){const r=this.itemSize;for(let i=0;i<r;i++)n[i]=this.sampleChannelBicubicUV(t,e,i)}sampleBicubic(t,e,n,r){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBicubic(t,e,s)}sampleChannelBicubicUV(t,e,n){const r=t*this.width,i=e*this.height;return this.sampleChannelBicubic(r-.5,i-.5,n)}sampleChannelBicubic(t,e,n){const r=this.itemSize,i=this.width,s=this.height,o=this.data,a=i*r,h=i-1,c=s-1,l=ot(t,0,h),f=ot(e,0,c),g=0|l,_=0|f,p=l-g,y=f-_,m=u(0,g-1),w=u(0,_-1),v=d(h,g+1),x=d(c,_+1),b=d(h,v+1),A=w*a+n,E=_*a+n,F=x*a+n,$=d(c,x+1)*a+n,S=m*r,U=g*r,z=v*r,C=b*r,B=o[A+S],V=o[A+U],L=o[A+z],M=o[A+C],T=o[E+S],q=o[E+U],I=o[E+z],N=o[E+C],k=o[F+S],O=o[F+U],j=o[F+z],D=o[F+C],R=o[$+S],J=o[$+U],P=o[$+z],H=o[$+C],W=ht(p,B,V,L,M),G=ht(p,T,q,I,N),Y=ht(p,k,O,j,D),K=ht(p,R,J,P,H);return ht(y,W,G,Y,K)}sampleBilinearUV(t,e,n,r=0){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBilinearUV(t,e,s)}sampleBilinear(t,e,n,r=0){const i=this.itemSize;for(let s=0;s<i;s++)n[s+r]=this.sampleChannelBilinear(t,e,s)}sampleChannelBilinearUV(t,e,n){const r=t*this.width-.5,i=e*this.height-.5;return this.sampleChannelBilinear(r,i,n)}sampleChannelBilinear(t,e,n){const r=this.itemSize,i=this.width,s=i*r,o=this.height-1,a=ot(t,0,i-1),h=ot(e,0,o),c=a>>>0,u=h>>>0,d=u*s,l=c*r+n,f=d+l;let g,_;g=a===c?c:c+1,_=h===u?u:u+1;const p=this.data,y=p[f];if(c===g&&u===_)return y;const m=a-c,w=h-u,v=g*r+n,x=_*s,b=x+l,A=x+v,E=p[d+v],F=p[b],$=p[A],S=at(y,E,m),U=at(F,$,m);return at(S,U,w)}sampleNearestUV(t,e,n){const r=this.width,i=this.height,s=Math.round(t*r-.5),o=Math.round(e*i-.5);this.read(ot(s,0,r-1),ot(o,0,i-1),n)}readChannel(t,e,n){const r=(e*this.width+t)*this.itemSize+n;return this.data[r]}read(t,e,n){const r=this.width,i=this.itemSize,s=(e*r+t)*i;for(let t=0;t<i;t++)n[t]=this.data[s+t]}write(t,e,n){const r=this.width,i=this.itemSize,s=(e*r+t)*i;for(let t=0;t<i;t++)this.data[s+t]=n[t]}sample(t,e,n){const r=[];return this.sampleBilinear(t*(this.width-1),e*(this.height-1),r,0),n.readFromArray(r),r[0]}point2index(t,e){return t+e*this.width}index2point(t,e){const n=this.width,r=t%n,i=t/n|0;e.set(r,i)}copy(t,e,n,r,i,s,o){const a=Math.min(s,t.width-e,this.width-r),h=Math.min(o,t.height-n,this.height-i),c=this.itemSize,u=t.itemSize,d=Math.min(c,u),l=c*this.width,f=u*t.width,g=t.data,_=this.data;let p,y,m;for(y=0;y<h;y++){const t=(y+i)*l,s=(y+n)*f;for(p=0;p<a;p++){const n=t+(p+r)*c,i=s+(p+e)*u;for(m=0;m<d;m++)_[n+m]=g[i+m]}}this.version++}zeroFill(t,e,n,r){const i=ot(t,0,this.width),s=ot(e,0,this.height),o=ot(t+n,0,this.width),a=ot(e+r,0,this.height),h=this.data,c=this.itemSize,u=c*this.width,d=i*c,l=o*c;let f;for(f=s;f<a;f++){const t=f*u;h.fill(0,t+d,t+l)}this.version++}channelFill(t,e){const n=this.itemSize,r=this.data,i=r.length;for(let s=t;s<i;s+=n)r[s]=e;this.version++}fill(t,e,n,r,i){const s=this.width,o=this.height,a=ot(t,0,s),h=ot(e,0,o),c=ot(t+n,0,s),u=ot(e+r,0,o),d=this.data,l=this.itemSize,f=l*s;let g,_,p;for(g=h;g<u;g++){const t=g*f;for(_=a;_<c;_++){const e=t+_*l;for(p=0;p<l;p++)d[e+p]=i[p]}}this.version++}writeChannel(t,e,n,r){const i=(e*this.width+t)*this.itemSize+n;this.data[i]=r,this.version++}set(t,e,n){const r=this.data,i=this.itemSize,s=i*this.width*e+t*i;for(let t=0;t<i;t++)r[s+t]=n[t];this.version++}traverseCircle(t,e,n,r){let i,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(i=-c;i<=c;i++)i*i+t<=h&&r(o+i,a+s,this)}}resize(t,e,n=!0){const r=this.width,i=this.height;if(r===t&&i===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===r)h.set(a.subarray(0,Math.min(a.length,o)));else{const n=d(e,i),o=d(t,r);for(let e=0;e<n;e++)for(let n=0;n<o;n++){const i=(e*t+n)*s,o=(e*r+n)*s;for(let t=0;t<s;t++)h[i+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}equals(e){return this.width===e.width&&this.height===e.height&&this.itemSize===e.itemSize&&function(e,n){if(e===n)return!0;const r=e.length;if(r!==n.length)return!1;const i=e.constructor;if(i!==n.constructor)return!1;if(0===r)return!0;if(r<128)return t(e,n);const s=e.byteLength;if(s!==n.byteLength)return!1;const o=e.buffer,a=n.buffer,h=e.byteOffset,c=n.byteOffset;if(o===a&&h===c)return!0;let u=e,d=n;const l=i.BYTES_PER_ELEMENT,f=function(t,e,n){const r=t|e|n;return 0==(3&r)?4:0==(1&r)?2:1}(h,c,s);return l<4&&4===f?(u=new Uint32Array(o,h,s>>>2),d=new Uint32Array(a,c,s>>>2)):l<2&&2===f&&(u=new Uint16Array(o,h,s>>>1),d=new Uint16Array(a,c,s>>>1)),t(u,d)}(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,r){let i=n;for(let e=0;e<n;e+=r)i=(i<<5)-i+(t[e]>>>0);return i>>>0}(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 ct(t,this.itemSize,this.width,this.height)}toJSON(){const t=Y.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:st(this.data),data:t}}fromJSON({height:t,width:e,itemSize:n,type:r,data:i}){const s=function(t){const e=it[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(r);if("string"==typeof i){const t=Y.decode(i);this.data=new s(t)}else{if(!Array.isArray(i))throw new Error("Unsupported data format");this.data=new s(i)}this.height=t,this.width=e,this.itemSize=n}static uint8clamped(t,e,n){const r=new Uint8ClampedArray(e*n*t);return new ct(r,t,e,n)}static uint8(t,e,n){const r=new Uint8Array(e*n*t);return new ct(r,t,e,n)}static uint16(t,e,n){const r=new Uint16Array(e*n*t);return new ct(r,t,e,n)}static uint32(t,e,n){const r=new Uint32Array(e*n*t);return new ct(r,t,e,n)}static int8(t,e,n){const r=new Int8Array(e*n*t);return new ct(r,t,e,n)}static int16(t,e,n){const r=new Int16Array(e*n*t);return new ct(r,t,e,n)}static int32(t,e,n){const r=new Int32Array(e*n*t);return new ct(r,t,e,n)}static float32(t,e,n){const r=new Float32Array(e*n*t);return new ct(r,t,e,n)}static float64(t,e,n){const r=new Float64Array(e*n*t);return new ct(r,t,e,n)}}function ut(t,e,n,r){const i=n[r],s=n[r+1],o=n[r+2];t[e]+=i,t[e+1]+=s,t[e+2]+=o}function dt(t,e,n,r,i,s){const o=3*n,a=3*r,h=3*i;N(t,e,s[o],s[o+1],s[o+2],s[a],s[a+1],s[a+2],s[h],s[h+1],s[h+2])}function lt(t,e,n,r){const i=n[r],s=n[r+1],o=n[r+2],a=1/j(i,s,o);t[e]=i*a,t[e+1]=s*a,t[e+2]=o*a}ct.prototype.isSampler2D=!0,ct.typeName="Sampler2D";const ft=new Float64Array(3),gt={build:function(t,e,n,r,i,s){const o=n.x*s,a=n.y*s,h=o-1,c=a-1;let u=0,d=0;const l=o*a,f=new Float32Array(3*l),g=new Float32Array(3*l),_=new Float32Array(2*l);let p,y;const m=n.y/i.y/c,w=n.x/i.x/h,v=e.y/i.y,x=e.x/i.x,b=i.x*r.x,A=i.y*r.y;let E,F,$;for(p=0;p<a;p++){const e=p*m+v;for($=e*A,y=0;y<o;y++){const n=y*w+x;E=n*b,F=t.sampleChannelBicubicUV(n,e,0),f[u]=E,f[u+1]=F,f[u+2]=$,_[d]=n,_[d+1]=e,u+=3,d+=2}}u=0;const S=new(f.length/3>65535?Uint32Array:Uint16Array)(h*c*6);for(p=0;p<c;p++)for(y=0;y<h;y++){const t=y+o*p,e=y+o*(p+1),n=y+1+o*(p+1),r=y+1+o*p;S[u]=t,S[u+1]=e,S[u+2]=r,S[u+3]=e,S[u+4]=n,S[u+5]=r,u+=6}return function(t,e,n){const r=n.length;for(let i=0;i<r;i+=3){const r=n[i],s=n[i+1],o=n[i+2];dt(ft,0,r,s,o,t),ut(e,3*r,ft,0),ut(e,3*s,ft,0),ut(e,3*o,ft,0)}!function(t,e=0,n=t.length-e){const r=e+n;for(let n=e;n<r;n+=3)lt(t,n,t,n)}(e)}(f,g,S),{indices:S,vertices:f,normals:g,uvs:_}}};self.Lib={build_bvh(t,e){const n=new x;return function(t,e,n){const r=n.length/3;t.setLeafCount(r),t.initialize_structure();for(let i=0;i<r;i++){const r=3*i;b(t,i,e,n[r],n[r+1],n[r+2])}t.build()}(n,t,e),n},Sampler2D:ct,BufferedGeometryArraysBuilder:gt,tensionOptimizeUV:function(t,e,n,r=3){const i=new R;i.build(t,n),i.computeEdgeSquaredLengths();const s=t.length/3;for(let t=0;t<r;t++)t:for(let t=0;t<s;t++){const n=i.vertices[t],r=n.edges,s=r.length;if(0===s)continue;let o=0,a=0,h=0;for(let t=0;t<s;t++){const i=r[t];if(A(i))continue t;const s=2*E(i,n).index,c=e[s],u=e[s+1],d=1/i.lengthSqr;o+=c*d,a+=u*d,h+=d}const c=o/h,u=a/h,d=2*n.index;e[d]=c,e[d+1]=u}},sampler2d_channel_compute_min:function(t,e=0){const n=t.itemSize,r=t.data,i=r.length;if(0===i)return;let s=r[e],o=e;for(let t=e+n;t<i;t+=n){const e=r[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,r=t.data,i=r.length;if(0===i)return;let s=r[e],o=e;for(let t=e+n;t<i;t+=n){const e=r[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/package.json
CHANGED
|
@@ -154,9 +154,29 @@ export class TopoMesh {
|
|
|
154
154
|
/**
|
|
155
155
|
*
|
|
156
156
|
* @param {Float32Array} vertices
|
|
157
|
-
* @param {Uint32Array|Uint16Array|Uint8Array|number[]} faces
|
|
158
157
|
*/
|
|
159
|
-
|
|
158
|
+
setVerticesFromArray(vertices: Float32Array): void;
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param {Uint16Array|Uint32Array|number[]} faces
|
|
162
|
+
*/
|
|
163
|
+
setFacesFromIndexArray(faces: Uint16Array | Uint32Array | number[]): void;
|
|
164
|
+
setFacedUnindexed(): void;
|
|
165
|
+
/**
|
|
166
|
+
*
|
|
167
|
+
* @param {Float64Array|Float32Array|number[]} vertices
|
|
168
|
+
* @param {Uint32Array|Uint16Array|Uint8Array|number[]} [faces]
|
|
169
|
+
*/
|
|
170
|
+
build(vertices: Float64Array | Float32Array | number[], faces?: Uint32Array | Uint16Array | Uint8Array | number[]): void;
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param {number} index
|
|
174
|
+
* @param {TopoVertex} v0
|
|
175
|
+
* @param {TopoVertex} v1
|
|
176
|
+
* @param {TopoVertex} v2
|
|
177
|
+
* @returns {TopoTriangle}
|
|
178
|
+
*/
|
|
179
|
+
createTriangle(index: number, v0: TopoVertex, v1: TopoVertex, v2: TopoVertex): TopoTriangle;
|
|
160
180
|
toString(): string;
|
|
161
181
|
/**
|
|
162
182
|
* @readonly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TopoMesh.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/struct/TopoMesh.js"],"names":[],"mappings":"AAcA;IAEI;;;OAGG;IACH,UAFU,UAAU,EAAE,CAER;IAEd;;;;OAIG;IACH,gBAAoB;IAGpB;;;;OAIG;IACH,gBAAoB;IAEpB;;;;OAIG;IACH,uBAkBC;IAED;;;OAGG;IACH,YAFa,IAAI,QAAQ,CAAC,CAIzB;IAED;;;OAGG;IACH,YAFa,IAAI,YAAY,CAAC,CAI7B;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACL,SAAS,GAAC,YAAY,CAYjC;IAED;;;;OAIG;IACH,wCAFa,OAAO,CA0GnB;IAED,kBAMC;IAED;;;OAGG;IACH,sBAFa,IAAI,MAAM,EAAE,UAAU,CAAC,CAoBnC;IAED;;;;OAIG;IACH,yBAHW,QAAQ,cACR,IAAI,MAAM,EAAE,UAAU,CAAC,QAYjC;IAED;;;;OAIG;IACH,kBAHW,YAAY,cACZ,IAAI,MAAM,EAAC,UAAU,CAAC,QAqChC;IAED;;;;OAIG;IACH,qBAFW,YAAY,QAsBtB;IAED;;;OAGG;IACH,WAFW,QAAQ,QAclB;IAED;;;OAGG;IACH,aAFW,UAAU,QAKpB;IAED;;;OAGG;IACH,mBAFW,UAAU,QAMpB;IAED;;;OAGG;IACH,gBAFW,UAAU,QAIpB;IAED;;;;OAIG;IACH,kBAHW,UAAU,GACR,OAAO,CAKnB;IAGD;;;OAGG;IACH,WAFW,QAAQ,QAKlB;IAED;;;OAGG;IACH,iBAFW,QAAQ,QAMlB;IAED;;;OAGG;IACH,cAFW,QAAQ,QAIlB;IAED;;;;OAIG;IACH,gBAHW,QAAQ,GACN,OAAO,CAKnB;IAED;;;OAGG;IACH,WAFW,YAAY,QAUtB;IAED;;;OAGG;IACH,uBAFW,SAAS,YAAY,CAAC,QAMhC;IAED;;;OAGG;IACH,cAFW,YAAY,QAwBtB;IAED;;;OAGG;IACH,cAFW,YAAY,QAItB;IAED;;;;OAIG;IACH,gBAHW,YAAY,GACV,OAAO,CAKnB;IAED;;;;;;OAMG;IACH,cALW,UAAU,KACV,UAAU,GAER,QAAQ,CAoCpB;IAED,mBAsCC;IAED,kCAQC;IAED;;;;OAIG;IACH,gBAHW,YAAY,
|
|
1
|
+
{"version":3,"file":"TopoMesh.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/struct/TopoMesh.js"],"names":[],"mappings":"AAcA;IAEI;;;OAGG;IACH,UAFU,UAAU,EAAE,CAER;IAEd;;;;OAIG;IACH,gBAAoB;IAGpB;;;;OAIG;IACH,gBAAoB;IAEpB;;;;OAIG;IACH,uBAkBC;IAED;;;OAGG;IACH,YAFa,IAAI,QAAQ,CAAC,CAIzB;IAED;;;OAGG;IACH,YAFa,IAAI,YAAY,CAAC,CAI7B;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACL,SAAS,GAAC,YAAY,CAYjC;IAED;;;;OAIG;IACH,wCAFa,OAAO,CA0GnB;IAED,kBAMC;IAED;;;OAGG;IACH,sBAFa,IAAI,MAAM,EAAE,UAAU,CAAC,CAoBnC;IAED;;;;OAIG;IACH,yBAHW,QAAQ,cACR,IAAI,MAAM,EAAE,UAAU,CAAC,QAYjC;IAED;;;;OAIG;IACH,kBAHW,YAAY,cACZ,IAAI,MAAM,EAAC,UAAU,CAAC,QAqChC;IAED;;;;OAIG;IACH,qBAFW,YAAY,QAsBtB;IAED;;;OAGG;IACH,WAFW,QAAQ,QAclB;IAED;;;OAGG;IACH,aAFW,UAAU,QAKpB;IAED;;;OAGG;IACH,mBAFW,UAAU,QAMpB;IAED;;;OAGG;IACH,gBAFW,UAAU,QAIpB;IAED;;;;OAIG;IACH,kBAHW,UAAU,GACR,OAAO,CAKnB;IAGD;;;OAGG;IACH,WAFW,QAAQ,QAKlB;IAED;;;OAGG;IACH,iBAFW,QAAQ,QAMlB;IAED;;;OAGG;IACH,cAFW,QAAQ,QAIlB;IAED;;;;OAIG;IACH,gBAHW,QAAQ,GACN,OAAO,CAKnB;IAED;;;OAGG;IACH,WAFW,YAAY,QAUtB;IAED;;;OAGG;IACH,uBAFW,SAAS,YAAY,CAAC,QAMhC;IAED;;;OAGG;IACH,cAFW,YAAY,QAwBtB;IAED;;;OAGG;IACH,cAFW,YAAY,QAItB;IAED;;;;OAIG;IACH,gBAHW,YAAY,GACV,OAAO,CAKnB;IAED;;;;;;OAMG;IACH,cALW,UAAU,KACV,UAAU,GAER,QAAQ,CAoCpB;IAED,mBAsCC;IAED,kCAQC;IAED;;;OAGG;IACH,+BAFW,YAAY,QA6BtB;IAED;;;OAGG;IACH,8BAFW,WAAW,GAAC,WAAW,GAAC,MAAM,EAAE,QA4B1C;IAED,0BAiBC;IAED;;;;OAIG;IACH,gBAHW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,UAClC,WAAW,GAAC,WAAW,GAAC,UAAU,GAAC,MAAM,EAAE,QAYrD;IAED;;;;;;;OAOG;IACH,sBANW,MAAM,MACN,UAAU,MACV,UAAU,MACV,UAAU,GACR,YAAY,CA0BxB;IAED,mBAEC;IAIL;;;OAGG;IACH,qBAFU,OAAO,CAEY;CAP5B;2BAlsB0B,iBAAiB;yBAFnB,eAAe;6BACX,mBAAmB;qBAR3B,8BAA8B"}
|
|
@@ -581,22 +581,20 @@ export class TopoMesh {
|
|
|
581
581
|
/**
|
|
582
582
|
*
|
|
583
583
|
* @param {Float32Array} vertices
|
|
584
|
-
* @param {Uint32Array|Uint16Array|Uint8Array|number[]} faces
|
|
585
584
|
*/
|
|
586
|
-
|
|
585
|
+
setVerticesFromArray(vertices) {
|
|
586
|
+
assert.defined(vertices, 'vertices');
|
|
587
587
|
|
|
588
|
-
const face_array_size = faces.length;
|
|
589
588
|
const vertex_array_size = vertices.length;
|
|
590
589
|
|
|
591
|
-
assert.equal(face_array_size % 3, 0, `Face array size must be multiple of 3, instead was ${face_array_size}`)
|
|
592
590
|
assert.equal(vertex_array_size % 3, 0, `Vertex array size must be multiple of 3, instead was ${vertex_array_size}`)
|
|
593
591
|
|
|
594
|
-
const
|
|
592
|
+
const vertex_count = vertex_array_size / 3;
|
|
595
593
|
|
|
596
594
|
//populate vertices
|
|
597
|
-
const
|
|
595
|
+
const topo_vertices = this.vertices;
|
|
598
596
|
|
|
599
|
-
for (let i = 0; i <
|
|
597
|
+
for (let i = 0; i < vertex_count; i++) {
|
|
600
598
|
|
|
601
599
|
const i3 = i * 3;
|
|
602
600
|
|
|
@@ -608,46 +606,111 @@ export class TopoMesh {
|
|
|
608
606
|
v.y = vertices[i3 + 1];
|
|
609
607
|
v.z = vertices[i3 + 2];
|
|
610
608
|
|
|
611
|
-
|
|
609
|
+
topo_vertices[i] = v;
|
|
612
610
|
}
|
|
613
611
|
|
|
614
|
-
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
*
|
|
616
|
+
* @param {Uint16Array|Uint32Array|number[]} faces
|
|
617
|
+
*/
|
|
618
|
+
setFacesFromIndexArray(faces) {
|
|
619
|
+
const face_array_size = faces.length;
|
|
620
|
+
|
|
621
|
+
assert.equal(face_array_size % 3, 0, `Face array size must be multiple of 3, instead was ${face_array_size}`)
|
|
622
|
+
|
|
623
|
+
//populate vertices
|
|
624
|
+
const topo_vertices = this.vertices;
|
|
625
|
+
|
|
626
|
+
const face_count = face_array_size / 3;
|
|
615
627
|
|
|
616
628
|
// populate faces
|
|
617
|
-
const topoFaces = this.getFaces();
|
|
618
629
|
|
|
619
|
-
for (let i = 0; i <
|
|
630
|
+
for (let i = 0; i < face_count; i++) {
|
|
620
631
|
const i3 = i * 3;
|
|
621
632
|
|
|
622
633
|
const a = faces[i3];
|
|
623
634
|
const b = faces[i3 + 1];
|
|
624
635
|
const c = faces[i3 + 2];
|
|
625
636
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
637
|
+
this.createTriangle(
|
|
638
|
+
i,
|
|
639
|
+
topo_vertices[a],
|
|
640
|
+
topo_vertices[b],
|
|
641
|
+
topo_vertices[c]
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
setFacedUnindexed() {
|
|
647
|
+
const topo_vertices = this.vertices;
|
|
629
648
|
|
|
630
|
-
|
|
631
|
-
f.index = i;
|
|
649
|
+
const face_count = topo_vertices.length / 3;
|
|
632
650
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const eCA = this.ensureEdge(vC, vA);
|
|
651
|
+
// populate faces
|
|
652
|
+
for (let i = 0; i < face_count; i++) {
|
|
636
653
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
654
|
+
const offset = i * 3;
|
|
655
|
+
|
|
656
|
+
this.createTriangle(
|
|
657
|
+
i,
|
|
658
|
+
topo_vertices[offset],
|
|
659
|
+
topo_vertices[offset + 1],
|
|
660
|
+
topo_vertices[offset + 2]
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
641
664
|
|
|
642
|
-
|
|
643
|
-
|
|
665
|
+
/**
|
|
666
|
+
*
|
|
667
|
+
* @param {Float64Array|Float32Array|number[]} vertices
|
|
668
|
+
* @param {Uint32Array|Uint16Array|Uint8Array|number[]} [faces]
|
|
669
|
+
*/
|
|
670
|
+
build(vertices, faces) {
|
|
644
671
|
|
|
645
|
-
|
|
646
|
-
vB.faces.push(f);
|
|
647
|
-
vC.faces.push(f);
|
|
672
|
+
this.setVerticesFromArray(vertices);
|
|
648
673
|
|
|
649
|
-
|
|
674
|
+
if (faces === undefined || faces === null) {
|
|
675
|
+
this.setFacedUnindexed();
|
|
676
|
+
} else {
|
|
677
|
+
this.setFacesFromIndexArray(faces);
|
|
650
678
|
}
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
*
|
|
684
|
+
* @param {number} index
|
|
685
|
+
* @param {TopoVertex} v0
|
|
686
|
+
* @param {TopoVertex} v1
|
|
687
|
+
* @param {TopoVertex} v2
|
|
688
|
+
* @returns {TopoTriangle}
|
|
689
|
+
*/
|
|
690
|
+
createTriangle(index, v0, v1, v2) {
|
|
691
|
+
const f = new TopoTriangle();
|
|
692
|
+
|
|
693
|
+
f.index = index;
|
|
694
|
+
|
|
695
|
+
const e01 = this.ensureEdge(v0, v1);
|
|
696
|
+
const e12 = this.ensureEdge(v1, v2);
|
|
697
|
+
const e20 = this.ensureEdge(v2, v0);
|
|
698
|
+
|
|
699
|
+
//link primitives
|
|
700
|
+
e01.faces.push(f);
|
|
701
|
+
e12.faces.push(f);
|
|
702
|
+
e20.faces.push(f);
|
|
703
|
+
|
|
704
|
+
f.vertices.push(v0, v1, v2);
|
|
705
|
+
f.edges.push(e01, e12, e20);
|
|
706
|
+
|
|
707
|
+
v0.faces.push(f);
|
|
708
|
+
v1.faces.push(f);
|
|
709
|
+
v2.faces.push(f);
|
|
710
|
+
|
|
711
|
+
this.__faces.add(f);
|
|
712
|
+
|
|
713
|
+
return f;
|
|
651
714
|
}
|
|
652
715
|
|
|
653
716
|
toString() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Move UVs to reduce stretching
|
|
3
3
|
*
|
|
4
|
-
* @param {Float32Array} positions
|
|
5
|
-
* @param {Float32Array} uvs
|
|
6
|
-
* @param {Uint16Array} faces
|
|
4
|
+
* @param {Float64Array|Float32Array|number[]} positions
|
|
5
|
+
* @param {Float64Array|Float32Array|number[]} uvs
|
|
6
|
+
* @param {Uint16Array|Uint32Array|number[]|undefined} faces
|
|
7
7
|
* @param {number} [steps] Number of optimization passes to perform
|
|
8
8
|
*/
|
|
9
|
-
export function geometry_optimize_uv_tension(positions: Float32Array, uvs: Float32Array, faces: Uint16Array, steps?: number): void;
|
|
9
|
+
export function geometry_optimize_uv_tension(positions: Float64Array | Float32Array | number[], uvs: Float64Array | Float32Array | number[], faces: Uint16Array | Uint32Array | number[] | undefined, steps?: number): void;
|
|
10
10
|
//# sourceMappingURL=geometry_optimize_uv_tension.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry_optimize_uv_tension.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wDALW,YAAY,
|
|
1
|
+
{"version":3,"file":"geometry_optimize_uv_tension.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wDALW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,OAClC,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,SAClC,WAAW,GAAC,WAAW,GAAC,MAAM,EAAE,GAAC,SAAS,UAC1C,MAAM,QA0EhB"}
|
|
@@ -5,9 +5,9 @@ import { TopoMesh } from "../../../../core/geom/3d/topology/struct/TopoMesh.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Move UVs to reduce stretching
|
|
7
7
|
*
|
|
8
|
-
* @param {Float32Array} positions
|
|
9
|
-
* @param {Float32Array} uvs
|
|
10
|
-
* @param {Uint16Array} faces
|
|
8
|
+
* @param {Float64Array|Float32Array|number[]} positions
|
|
9
|
+
* @param {Float64Array|Float32Array|number[]} uvs
|
|
10
|
+
* @param {Uint16Array|Uint32Array|number[]|undefined} faces
|
|
11
11
|
* @param {number} [steps] Number of optimization passes to perform
|
|
12
12
|
*/
|
|
13
13
|
export function geometry_optimize_uv_tension(
|
|
@@ -23,61 +23,63 @@ export function geometry_optimize_uv_tension(
|
|
|
23
23
|
topo.build(positions, faces);
|
|
24
24
|
topo.computeEdgeSquaredLengths();
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const vertex_count = positions.length / 3;
|
|
27
27
|
|
|
28
28
|
for (let i = 0; i < steps; i++) {
|
|
29
29
|
|
|
30
|
-
loop_vertices: for (let j = 0; j <
|
|
30
|
+
loop_vertices: for (let j = 0; j < vertex_count; j++) {
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const v0 = topo.vertices[j];
|
|
33
33
|
|
|
34
34
|
// 1) get attached edges
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const attached_edges = v0.edges;
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const attached_edge_count = attached_edges.length;
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (attached_edge_count === 0) {
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Compute neighbour UV weight based on edge length
|
|
45
45
|
|
|
46
|
-
let
|
|
47
|
-
let
|
|
46
|
+
let sum_u = 0;
|
|
47
|
+
let sum_v = 0;
|
|
48
48
|
|
|
49
|
-
let
|
|
49
|
+
let weight_sum = 0;
|
|
50
50
|
|
|
51
|
-
for (let k = 0; k <
|
|
52
|
-
const attachedEdge = attachedEdges[k];
|
|
51
|
+
for (let k = 0; k < attached_edge_count; k++) {
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const edge = attached_edges[k];
|
|
54
|
+
|
|
55
|
+
if (query_edge_is_boundary(edge)) {
|
|
56
|
+
// edge vertex, no adjustment possible
|
|
56
57
|
continue loop_vertices;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
const
|
|
60
|
+
const v1 = query_edge_other_vertex(edge, v0);
|
|
60
61
|
|
|
61
|
-
const
|
|
62
|
+
const other_uv_address = v1.index * 2;
|
|
62
63
|
|
|
63
|
-
const u = uvs[
|
|
64
|
-
const v = uvs[
|
|
64
|
+
const u = uvs[other_uv_address];
|
|
65
|
+
const v = uvs[other_uv_address + 1];
|
|
65
66
|
|
|
66
|
-
const weight = 1 /
|
|
67
|
+
const weight = 1 / edge.lengthSqr;
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
sum_u += u * weight;
|
|
70
|
+
sum_v += v * weight;
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
weight_sum += weight;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
//compute new UV position to equalize the vertex distance
|
|
75
|
-
const u =
|
|
76
|
-
const v =
|
|
75
|
+
// compute new UV position to equalize the vertex distance
|
|
76
|
+
const u = sum_u / weight_sum;
|
|
77
|
+
const v = sum_v / weight_sum;
|
|
78
|
+
|
|
79
|
+
const uv_address = v0.index * 2;
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
uvs[
|
|
80
|
-
uvs[uvAddress + 1] = v;
|
|
81
|
+
uvs[uv_address] = u;
|
|
82
|
+
uvs[uv_address + 1] = v;
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|