!function t(e,n,r){function s(i,c){if(!n[i]){if(!e[i]){var h="function"==typeof require&&require;if(!c&&h)return h(i,!0);if(o)return o(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var u=n[i]={exports:{}};e[i][0].call(u.exports,function(t){var n=e[i][1][t];return s(n||t)},u,u.exports,t,e,n,r)}return n[i].exports}for(var o="function"==typeof require&&require,i=0;i0;){const e=r.pop();if(e===n){let t=e;const n=[];for(;t.parent;)n.push(t),t=t.parent;return this.cleanUp(n),n.reverse()}e.closed=!0;const s=this.neighbours(t,e);for(let t=0,o=s.length;t0&&(this.content[0]=e,this.bubbleUp(0)),t}remove(t){const e=this.content.indexOf(t),n=this.content.pop();e!==this.content.length-1&&(this.content[e]=n,this.scoreFunction(n)0;){const n=(t+1>>1)-1,r=this.content[n];if(!(this.scoreFunction(e)0)){e.push(s),s=n=s,o=n,c=i=c,h=i,a=i;continue}o=l,h=a}if(r.triarea2(n,s,u)>=0){if(!(r.vequal(n,s)||r.triarea2(n,o,u)<0)){e.push(o),s=n=o,o=n,c=i=h,h=i,a=i;continue}s=u,c=a}}return 0!==e.length&&r.vequal(e[e.length-1],t[t.length-1].left)||e.push(t[t.length-1].left),this.path=e,e}}e.exports=s},{"./utils":6}],5:[function(t,e,n){const r=t("./utils"),s=t("./AStar"),o=t("./Channel");var i=1,c=function(t){console.log("Vertices:",t.vertices.length,"polygons:",t.faces.length);var e=[],n=t.vertices,s=t.faceVertexUvs;t.faces.forEach(t=>{e.push({id:i++,vertexIds:[t.a,t.b,t.c],centroid:t.centroid,normal:t.normal,neighbours:[]})});var o={polygons:e,vertices:n,faceVertexUvs:s};return e.forEach(t=>{!function(t,e){t.neighbours=[];for(var n=0,s=e.polygons.length;n1e4||r.array_intersect(t.vertexIds,e.polygons[n].vertexIds).length>=2&&t.neighbours.push(e.polygons[n])}(t,o)}),o},h=function(t){var e={};t.vertices.forEach(t=>{t.x=r.roundNumber(t.x,2),t.y=r.roundNumber(t.y,2),t.z=r.roundNumber(t.z,2)}),e.vertices=t.vertices;var n=function(t){var e=[],n=0,r=function(t){t.neighbours.forEach(e=>{void 0===e.group&&(e.group=t.group,r(e))})};return t.polygons.forEach(t=>{void 0===t.group&&(t.group=n++,r(t)),e[t.group]||(e[t.group]=[]),e[t.group].push(t)}),console.log("Groups built: ",e.length),e}(t);e.groups=[];var s=function(t,e){for(var n=0;n{var n=[];t.forEach(e=>{var o=[];e.neighbours.forEach(e=>{o.push(s(t,e))});var i=[];e.neighbours.forEach(t=>{i.push(function(t,e){var n=t.vertexIds,r=e.vertexIds,s=[];return n.forEach(t=>{r.includes(t)&&s.push(t)}),s.length<2?[]:(s.includes(n[0])&&s.includes(n[n.length-1])&&n.push(n.shift()),s.includes(r[0])&&s.includes(r[r.length-1])&&r.push(r.shift()),s=[],n.forEach(t=>{r.includes(t)&&s.push(t)}),s)}(e,t))}),e.centroid.x=r.roundNumber(e.centroid.x,2),e.centroid.y=r.roundNumber(e.centroid.y,2),e.centroid.z=r.roundNumber(e.centroid.z,2),n.push({id:s(t,e),neighbours:o,vertexIds:e.vertexIds,centroid:e.centroid,portals:i})}),e.groups.push(n)}),e},a={};e.exports={buildNodes:function(t){var e=function(t){return r.computeCentroids(t),t.mergeVertices(),c(t)}(t);return h(e)},setZoneData:function(t,e){a[t]=e},getGroup:function(t,e){if(!a[t])return null;var n=null,s=Math.pow(50,2);return a[t].groups.forEach((t,o)=>{t.forEach(t=>{var i=r.distanceToSquared(t.centroid,e);i{n&&s?r.distanceToSquared(n,t.centroid){const n=r.distanceToSquared(e.centroid,t);nnew THREE.Vector3(t.x,t.y,t.z));return f.shift(),f}}},{"./AStar":2,"./Channel":4,"./utils":6}],6:[function(t,e,n){class r{static computeCentroids(t){var e,n,r;for(e=0,n=t.faces.length;e{e.indexOf(t)>=0&&n.push(t)}),n.length<2)return[];n.includes(t[0])&&n.includes(t[t.length-1])&&t.push(t.shift()),n.includes(e[0])&&n.includes(e[e.length-1])&&e.push(e.shift()),n=[],t.forEach(t=>{e.includes(t)&&n.push(t)});for(var r=n[1],s=n[0],o=t.slice();o[0]!==r;)o.push(o.shift());for(var i=0,c=e.slice();c[0]!==s;)if(c.push(c.shift()),i++>10)throw new Error("Unexpected state");return c.shift(),c.pop(),o=o.concat(c)}static setPolygonCentroid(t,e){var n=new THREE.Vector3,r=e.vertices;t.vertexIds.forEach(t=>{n.add(r[t])}),n.divideScalar(t.vertexIds.length),t.centroid.copy(n)}static cleanPolygon(t,e){for(var n=[],r=e.vertices,s=0;sMath.PI-.01&&d{e.vertexIds.includes(t.vertexIds[s])||v.push(e)}),t.neighbours=v}else n.push(t.vertexIds[s])}t.vertexIds=n,setPolygonCentroid(t,e)}static isConvex(t,e){var n=e.vertices;if(t.vertexIds.length<3)return!1;for(var r=!0,s=[],o=0;o{0===t&&(r=!1)}),s[0]>0?s.forEach(t=>{t<0&&(r=!1)}):s.forEach(t=>{t>0&&(r=!1)}),r}static distanceToSquared(t,e){var n=t.x-e.x,r=t.y-e.y,s=t.z-e.z;return n*n+r*r+s*s}static isPointInPoly(t,e){for(var n=!1,r=-1,s=t.length,o=s-1;++r{r=Math.min(n[t].y,r),s=Math.max(n[t].y,s),o.push(n[t])}),!!(t.yr-.5&&this.isPointInPoly(o,t))}static triarea2(t,e,n){var r=e.x-t.x,s=e.z-t.z;return(n.x-t.x)*s-r*(n.z-t.z)}static vequal(t,e){return this.distanceToSquared(t,e)<1e-5}static array_intersect(){let t,e,n,r,s,o,i=[],c={};for(o=arguments.length-1,n=arguments[0].length,e=0,t=0;t<=o;t++)(r=arguments[t].length)