recast-navigation 0.15.1 → 0.16.1

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/README.md CHANGED
@@ -41,6 +41,24 @@ export default defineConfig(() => ({
41
41
  )}
42
42
  ```
43
43
 
44
+ ## Documentation
45
+
46
+ <!-- REMOVE-FROM-DOCS-START -->
47
+
48
+ API Documentation can be found at [https://docs.recast-navigation-js.isaacmason.com](https://docs.recast-navigation-js.isaacmason.com).
49
+
50
+ <!-- REMOVE-FROM-DOCS-END -->
51
+
52
+ To get the most out of this library, you should be familiar with the Recast and Detour libraries. This article provides a good overview for the uninitiated: https://www.unrealdoc.com/p/navigation-mesh
53
+
54
+ Documentation for the Recast and Detour c++ libraries can be found here:
55
+
56
+ - [Recast Navigation Website](http://recastnav.com/)
57
+ - [Recast Navigation GitHub](https://github.com/recastnavigation/recastnavigation)
58
+ - [Recast Navigation Google Discussions](https://groups.google.com/g/recastnavigation)
59
+
60
+ The GitHub issues and Google Discussions are a great resources for learning about the library and getting guidance on common issues.
61
+
44
62
  ## Usage
45
63
 
46
64
  ### Initialization
@@ -351,22 +369,6 @@ const { navMesh, tileCache } = importNavMesh(
351
369
  );
352
370
  ```
353
371
 
354
- ## Documentation
355
-
356
- <!-- REMOVE-FROM-DOCS-START -->
357
-
358
- API Documentation can be found at [https://docs.recast-navigation-js.isaacmason.com](https://docs.recast-navigation-js.isaacmason.com).
359
-
360
- <!-- REMOVE-FROM-DOCS-END -->
361
-
362
- Documentation for the Recast and Detour c++ libraries can be found here:
363
-
364
- - [Recast Navigation Website](http://recastnav.com/)
365
- - [Recast Navigation GitHub](https://github.com/recastnavigation/recastnavigation)
366
- - [Recast Navigation Google Discussions](https://groups.google.com/g/recastnavigation)
367
-
368
- The GitHub issues and Google Discussions are a great resources for learning about the library and getting guidance on common issues.
369
-
370
372
  ## Examples
371
373
 
372
374
  Some demonstrations of how to use the library in different environments can be found in the [examples](./examples) directory.
package/generators.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@recast-navigation/core");const t=(t,i)=>{const a={x:1/0,y:1/0,z:1/0},l={x:-1/0,y:-1/0,z:-1/0};for(let e=0;e<i.length;e++){const r=i[e],s=t[3*r],o=t[3*r+1],n=t[3*r+2];a.x=Math.min(a.x,s),a.y=Math.min(a.y,o),a.z=Math.min(a.z,n),l.x=Math.max(l.x,s),l.y=Math.max(l.y,o),l.z=Math.max(l.z,n)}return{bbMin:e.vec3.toArray(a),bbMax:e.vec3.toArray(l)}},i=e=>{let t=0,i=0;return t=Number(e>65535)<<4,e>>=t,i=Number(e>255)<<3,e>>=i,t|=i,i=Number(e>15)<<2,e>>=i,t|=i,i=Number(e>3)<<1,t|=i,t|=(e>>=i)>>1,t},a=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),l={...e.recastConfigDefaults},r={...e.recastConfigDefaults,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},s=()=>new e.TileCacheMeshProcess(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)})),o={...e.recastConfigDefaults};exports.createDefaultTileCacheMeshProcess=s,exports.dtIlog2=i,exports.dtNextPow2=a,exports.generateSoloNavMesh=(i,a,r={},s=!1)=>{const o=new e.RecastBuildContext,n={type:"solo",buildContext:o},d=new e.NavMesh,h=t=>(s||(n.heightfield&&(e.freeHeightfield(n.heightfield),n.heightfield=void 0),n.compactHeightfield&&(e.freeCompactHeightfield(n.compactHeightfield),n.compactHeightfield=void 0),n.contourSet&&(e.freeContourSet(n.contourSet),n.contourSet=void 0)),d.destroy(),{navMesh:void 0,success:!1,intermediates:n,error:t}),c=i,g=a.length,f=new e.Arrays.FloatArray;f.copy(c,c.length);const m=a,u=a.length/3,b=new e.Arrays.IntArray;b.copy(m,m.length);const{bbMin:w,bbMax:C}=t(i,a),R=e.createRcConfig({...l,...r});R.minRegionArea=R.minRegionArea*R.minRegionArea,R.mergeRegionArea=R.mergeRegionArea*R.mergeRegionArea,R.detailSampleDist=R.detailSampleDist<.9?0:R.cs*R.detailSampleDist,R.detailSampleMaxError=R.ch*R.detailSampleMaxError;const S=e.Raw.Recast.calcGridSize(w,C,R.cs);R.width=S.width,R.height=S.height;const y=e.allocHeightfield();if(n.heightfield=y,!e.createHeightfield(o,y,R.width,R.height,w,C,R.cs,R.ch))return h("Could not create heightfield");const M=new e.Arrays.UnsignedCharArray;if(M.resize(u),e.markWalkableTriangles(o,R.walkableSlopeAngle,f,g,b,u,M),!e.rasterizeTriangles(o,f,g,b,M,u,y,R.walkableClimb))return h("Could not rasterize triangles");M.free(),e.filterLowHangingWalkableObstacles(o,R.walkableClimb,y),e.filterLedgeSpans(o,R.walkableHeight,R.walkableClimb,y),e.filterWalkableLowHeightSpans(o,R.walkableHeight,y);const p=e.allocCompactHeightfield();if(n.compactHeightfield=p,!e.buildCompactHeightfield(o,R.walkableHeight,R.walkableClimb,y,p))return h("Failed to build compact data");if(s||(e.freeHeightfield(y),n.heightfield=void 0),!e.erodeWalkableArea(o,R.walkableRadius,p))return h("Failed to erode walkable area");if(!e.buildDistanceField(o,p))return h("Failed to build distance field");if(!e.buildRegions(o,p,R.borderSize,R.minRegionArea,R.mergeRegionArea))return h("Failed to build regions");const x=e.allocContourSet();if(n.contourSet=x,!e.buildContours(o,p,R.maxSimplificationError,R.maxEdgeLen,x,e.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return h("Failed to create contours");const A=e.allocPolyMesh();if(!e.buildPolyMesh(o,x,R.maxVertsPerPoly,A))return h("Failed to triangulate contours");const k=e.allocPolyMeshDetail();if(!e.buildPolyMeshDetail(o,A,p,R.detailSampleDist,R.detailSampleMaxError,k))return h("Failed to build detail mesh");s||(e.freeCompactHeightfield(p),n.compactHeightfield=void 0,e.freeContourSet(x),n.contourSet=void 0);for(let t=0;t<A.npolys();t++)A.areas(t)==e.Raw.Recast.WALKABLE_AREA&&A.setAreas(t,0),0==A.areas(t)&&A.setFlags(t,1);const H=new e.NavMeshCreateParams;H.setPolyMeshCreateParams(A),H.setPolyMeshDetailCreateParams(k),H.setWalkableHeight(R.walkableHeight),H.setWalkableRadius(R.walkableRadius),H.setWalkableClimb(R.walkableClimb),H.setCellSize(R.cs),H.setCellHeight(R.ch),H.setBuildBvTree(!0),r.offMeshConnections&&H.setOffMeshConnections(r.offMeshConnections);const v=e.createNavMeshData(H);if(!v.success)return h("Failed to create Detour navmesh data");const{navMeshData:T}=v;return d.initSolo(T)?{success:!0,navMesh:d,intermediates:n}:h("Failed to create Detour navmesh")},exports.generateTileCache=(l,o,n={},d=!1)=>{const h=new e.RecastBuildContext;let c={type:"tilecache",buildContext:h,chunkyTriMesh:void 0,tileIntermediates:[]};const g=new e.TileCache,f=new e.NavMesh,m=()=>{if(!d)for(let t=0;t<c.tileIntermediates.length;t++){const i=c.tileIntermediates[t];i.heightfield&&(e.freeHeightfield(i.heightfield),i.heightfield=void 0),i.compactHeightfield&&(e.freeCompactHeightfield(i.compactHeightfield),i.compactHeightfield=void 0),i.heightfieldLayerSet&&(e.freeHeightfieldLayerSet(i.heightfieldLayerSet),i.heightfieldLayerSet=void 0)}},u=e=>(m(),g.destroy(),f.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:c,error:e}),b=l,w=o.length,C=new e.Arrays.FloatArray;C.copy(b,b.length);const R=o,S=o.length/3,y=new e.Arrays.IntArray;y.copy(R,R.length);const{bbMin:M,bbMax:p}=t(l,o),{expectedLayersPerTile:x,maxObstacles:A,...k}={...r,...n},H=e.createRcConfig(k),v=e.calcGridSize(M,p,H.cs);H.width=v.width,H.height=v.height,H.minRegionArea=H.minRegionArea*H.minRegionArea,H.mergeRegionArea=H.mergeRegionArea*H.mergeRegionArea,H.detailSampleDist=H.detailSampleDist<.9?0:H.cs*H.detailSampleDist,H.detailSampleMaxError=H.ch*H.detailSampleMaxError;const T=Math.floor(H.tileSize),z=Math.floor((H.width+T-1)/T),_=Math.floor((H.height+T-1)/T);H.borderSize=H.walkableRadius+3,H.width=H.tileSize+2*H.borderSize,H.height=H.tileSize+2*H.borderSize;const L=e.DetourTileCacheParams.create({orig:M,cs:H.cs,ch:H.ch,width:H.tileSize,height:H.tileSize,walkableHeight:H.walkableHeight,walkableRadius:H.walkableRadius,walkableClimb:H.walkableClimb,maxSimplificationError:H.maxSimplificationError,maxTiles:z*_*x,maxObstacles:A}),D=new e.Raw.RecastLinearAllocator(32e3),E=new e.Raw.RecastFastLZCompressor,P=n.tileCacheMeshProcess??s();if(!g.init(L,D,E,P))return u("Failed to initialize tile cache");const F=e.vec3.fromArray(M);let N=Math.min(Math.floor(i(a(z*_*x))),14);N>14&&(N=14);const O=1<<N,W=1<<22-N,I=e.NavMeshParams.create({orig:F,tileWidth:H.tileSize*H.cs,tileHeight:H.tileSize*H.cs,maxTiles:O,maxPolys:W});if(!f.initTiled(I))return u("Failed to initialize tiled navmesh");const G=new e.RecastChunkyTriMesh;if(c.chunkyTriMesh=G,!G.init(C,y,S,256))return u("Failed to build chunky triangle mesh");const $=(t,i)=>{const a={tileX:t,tileY:i},l=H.tileSize*H.cs,r=e.cloneRcConfig(H),s=[M[0]+t*l,M[1],M[2]+i*l],o=[M[0]+(t+1)*l,p[1],M[2]+(i+1)*l];s[0]-=r.borderSize*r.cs,s[2]-=r.borderSize*r.cs,o[0]+=r.borderSize*r.cs,o[2]+=r.borderSize*r.cs,r.set_bmin(0,s[0]),r.set_bmin(1,s[1]),r.set_bmin(2,s[2]),r.set_bmax(0,o[0]),r.set_bmax(1,o[1]),r.set_bmax(2,o[2]);const n=e.allocHeightfield();if(a.heightfield=n,!e.createHeightfield(h,n,r.width,r.height,s,o,r.cs,r.ch))return{n:0};const g=[s[0],s[2]],f=[o[0],o[2]],m=new e.Arrays.IntArray;m.resize(512);const u=G.getChunksOverlappingRect(g,f,m,512);if(0===u)return{n:0};for(let t=0;t<u;++t){const i=m.get_data(t),a=G.nodes(i).n,l=G.getNodeTris(i),s=new e.Arrays.UnsignedCharArray;s.resize(a),e.markWalkableTriangles(h,r.walkableSlopeAngle,C,w,l,a,s);const o=e.rasterizeTriangles(h,C,w,l,s,a,n,r.walkableClimb);if(s.free(),!o)return{n:0}}e.filterLowHangingWalkableObstacles(h,H.walkableClimb,n),e.filterLedgeSpans(h,H.walkableHeight,H.walkableClimb,n),e.filterWalkableLowHeightSpans(h,H.walkableHeight,n);const b=e.allocCompactHeightfield();if(!e.buildCompactHeightfield(h,H.walkableHeight,H.walkableClimb,n,b))return{n:0};if(d||(e.freeHeightfield(a.heightfield),a.heightfield=void 0),!e.erodeWalkableArea(h,H.walkableRadius,b))return{n:0};const R=e.allocHeightfieldLayerSet();if(!e.buildHeightfieldLayers(h,b,H.borderSize,H.walkableHeight,R))return{n:0};d||(e.freeCompactHeightfield(b),a.compactHeightfield=void 0);const S=[];for(let a=0;a<R.nlayers();a++){const l=new e.Arrays.UnsignedCharArray,r=R.layers(a),s=new e.Raw.dtTileCacheLayerHeader;s.magic=e.Raw.Detour.TILECACHE_MAGIC,s.version=e.Raw.Detour.TILECACHE_VERSION,s.tx=t,s.ty=i,s.tlayer=a;const o=r.bmin(),n=r.bmax();s.set_bmin(0,o.x),s.set_bmin(1,o.y),s.set_bmin(2,o.z),s.set_bmax(0,n.x),s.set_bmax(1,n.y),s.set_bmax(2,n.z),s.width=r.width(),s.height=r.height(),s.minx=r.minx(),s.maxx=r.maxx(),s.miny=r.miny(),s.maxy=r.maxy(),s.hmin=r.hmin(),s.hmax=r.hmax();const d=e.getHeightfieldLayerHeights(r),h=e.getHeightfieldLayerAreas(r),c=e.getHeightfieldLayerCons(r),g=e.buildTileCacheLayer(E,s,d,h,c,l);if(e.Raw.Detour.statusFailed(g))return{n:0};S.push(l)}return d||(e.freeHeightfieldLayerSet(R),a.heightfieldLayerSet=void 0),c.tileIntermediates.push(a),{n:S.length,tiles:S}};for(let t=0;t<_;++t)for(let i=0;i<z;++i){const{n:a,tiles:l}=$(i,t);if(a>0&&l)for(let r=0;r<a;r++){const a=l[r],s=g.addTile(a);e.Raw.Detour.statusFailed(s.status)&&h.log(e.Raw.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${i}, ty: ${t}`)}}for(let t=0;t<_;t++)for(let i=0;i<z;i++){const a=g.buildNavMeshTilesAt(i,t,f);if(e.Raw.Detour.statusFailed(a))return u(`Failed to build nav mesh tiles at ${i}, ${t}`)}return m(),{success:!0,tileCache:g,navMesh:f,intermediates:c}},exports.generateTiledNavMesh=(l,r,s={},n=!1)=>{const d=new e.RecastBuildContext,h={type:"tiled",buildContext:d,chunkyTriMesh:void 0,tileIntermediates:[]},c=new e.NavMesh,g=()=>{if(!n){for(let t=0;t<h.tileIntermediates.length;t++){const i=h.tileIntermediates[t];i.compactHeightfield&&e.freeCompactHeightfield(i.compactHeightfield),i.heightfield&&e.freeHeightfield(i.heightfield),i.contourSet&&e.freeContourSet(i.contourSet)}h.chunkyTriMesh&&(h.chunkyTriMesh=void 0)}},f=e=>(g(),c.destroy(),{success:!1,navMesh:void 0,intermediates:h,error:e}),m=e.createRcConfig({...o,...s}),{bbMin:u,bbMax:b}=t(l,r),w=e.calcGridSize(u,b,m.cs);m.width=w.width,m.height=w.height,m.minRegionArea=m.minRegionArea*m.minRegionArea,m.mergeRegionArea=m.mergeRegionArea*m.mergeRegionArea,m.tileSize=Math.floor(m.tileSize),m.borderSize=m.walkableRadius+3,m.width=m.tileSize+2*m.borderSize,m.height=m.tileSize+2*m.borderSize,m.detailSampleDist=m.detailSampleDist<.9?0:m.cs*m.detailSampleDist,m.detailSampleMaxError=m.ch*m.detailSampleMaxError;const C=Math.floor(m.tileSize),R=Math.floor((w.width+C-1)/C),S=Math.floor((w.height+C-1)/C),y=m.tileSize*m.cs,M=l,p=r.length,x=new e.Arrays.FloatArray;x.copy(M,M.length);const A=r,k=r.length/3,H=new e.Arrays.IntArray;H.copy(A,A.length);const v=e.vec3.fromArray(u);let T=Math.min(Math.floor(i(a(R*S))),14);T>14&&(T=14);const z=1<<T,_=1<<22-T,L=e.NavMeshParams.create({orig:v,tileWidth:m.tileSize*m.cs,tileHeight:m.tileSize*m.cs,maxTiles:z,maxPolys:_});if(!c.initTiled(L))return f("Could not init nav mesh for tiled use");const D=new e.RecastChunkyTriMesh;if(h.chunkyTriMesh=D,!D.init(x,H,k,256))return f("Failed to build chunky triangle mesh");const E=(t,i,a,l)=>{const r=t=>(d.log(e.Raw.Module.RC_LOG_ERROR,t),{success:!1,error:t}),o={tileX:t,tileY:i};h.tileIntermediates.push(o);const c=e.cloneRcConfig(m),g=[...a],f=[...l];g[0]-=c.borderSize*c.cs,g[2]-=c.borderSize*c.cs,f[0]+=c.borderSize*c.cs,f[2]+=c.borderSize*c.cs,c.set_bmin(0,g[0]),c.set_bmin(1,g[1]),c.set_bmin(2,g[2]),c.set_bmax(0,f[0]),c.set_bmax(1,f[1]),c.set_bmax(2,f[2]),d.resetTimers(),d.startTimer(e.Raw.Module.RC_TIMER_TOTAL),d.log(e.Raw.Module.RC_LOG_PROGRESS,`Building tile ${h.tileIntermediates.length} at x: ${t}, y: ${i}`),d.log(e.Raw.Module.RC_LOG_PROGRESS,` - ${m.width} x ${m.height} cells`),d.log(e.Raw.Module.RC_LOG_PROGRESS,` - ${p/1e3}fK verts, ${k/1e3}K tris`);const u=e.allocHeightfield();if(o.heightfield=u,!e.createHeightfield(d,u,c.width,c.height,g,f,c.cs,c.ch))return r("Could not create heightfield");(new e.Arrays.UnsignedCharArray).resize(D.maxTrisPerChunk());const b=[g[0],g[2]],w=[f[0],f[2]],C=new e.Arrays.IntArray;C.resize(512);const R=D.getChunksOverlappingRect(b,w,C,512);if(0===R)return{success:!0};for(let t=0;t<R;++t){const i=C.get_data(t),a=D.nodes(i).n,l=D.getNodeTris(i),s=new e.Arrays.UnsignedCharArray;s.resize(a),e.markWalkableTriangles(d,c.walkableSlopeAngle,x,p,l,a,s);const o=e.rasterizeTriangles(d,x,p,l,s,a,u,c.walkableClimb);if(s.free(),!o)return r("Could not rasterize triangles")}e.filterLowHangingWalkableObstacles(d,c.walkableClimb,u),e.filterLedgeSpans(d,c.walkableHeight,c.walkableClimb,u),e.filterWalkableLowHeightSpans(d,c.walkableHeight,u);const S=e.allocCompactHeightfield();if(o.compactHeightfield=S,!e.buildCompactHeightfield(d,c.walkableHeight,c.walkableClimb,u,S))return r("Could not build compact heightfield");if(n||(e.freeHeightfield(o.heightfield),o.heightfield=void 0),!e.erodeWalkableArea(d,c.walkableRadius,S))return r("Could not erode walkable area");if(!e.buildDistanceField(d,S))return r("Failed to build distance field");if(!e.buildRegions(d,S,c.borderSize,c.minRegionArea,c.mergeRegionArea))return r("Failed to build regions");const y=e.allocContourSet();if(o.contourSet=y,!e.buildContours(d,S,c.maxSimplificationError,c.maxEdgeLen,y,e.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const M=e.allocPolyMesh();if(!e.buildPolyMesh(d,y,c.maxVertsPerPoly,M))return r("Failed to triangulate contours");const A=e.allocPolyMeshDetail();if(!e.buildPolyMeshDetail(d,M,S,c.detailSampleDist,c.detailSampleMaxError,A))return r("Failed to build detail mesh");n||(e.freeCompactHeightfield(S),o.compactHeightfield=void 0,e.freeContourSet(y),o.contourSet=void 0);for(let t=0;t<M.npolys();t++)M.areas(t)==e.Raw.Recast.WALKABLE_AREA&&M.setAreas(t,0),0==M.areas(t)&&M.setFlags(t,1);const H=new e.NavMeshCreateParams;H.setPolyMeshCreateParams(M),H.setPolyMeshDetailCreateParams(A),H.setWalkableHeight(c.walkableHeight),H.setWalkableRadius(c.walkableRadius),H.setWalkableClimb(c.walkableClimb),H.setCellSize(c.cs),H.setCellHeight(c.ch),H.setBuildBvTree(!0),s.offMeshConnections&&H.setOffMeshConnections(s.offMeshConnections),H.setTileX(t),H.setTileY(i);const v=e.createNavMeshData(H);return v.success?(d.log(e.Raw.Module.RC_LOG_PROGRESS,`>> Polymesh: ${M.nverts()} vertices ${M.npolys()} polygons`),{success:!0,data:v.navMeshData}):r("Failed to create Detour navmesh data")};d.startTimer(e.Raw.Module.RC_TIMER_TEMP);let P=[0,0,0],F=[0,0,0];for(let t=0;t<S;t++)for(let i=0;i<R;i++){P[0]=u[0]+i*y,P[1]=u[1],P[2]=u[2]+t*y,F[0]=u[0]+(i+1)*y,F[1]=b[1],F[2]=u[2]+(t+1)*y;const a=E(i,t,P,F);if(a.success&&a.data){c.removeTile(c.getTileRefAt(i,t,0));const l=c.addTile(a.data,e.Raw.Module.DT_TILE_FREE_DATA,0);e.Raw.Detour.statusFailed(l.status)&&(d.log(e.Raw.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${i}, ty: ${t},status: ${e.dtStatusToReadableString(l.status)} (${l.status})`),a.data.free())}}return d.stopTimer(e.Raw.Module.RC_TIMER_TEMP),n||g(),{success:!0,navMesh:c,intermediates:h}},exports.getBoundingBox=t,exports.soloNavMeshGeneratorConfigDefaults=l,exports.tileCacheGeneratorConfigDefaults=r,exports.tiledNavMeshGeneratorConfigDefaults=o;
1
+ "use strict";var e=require("@recast-navigation/core");const t=(t,i)=>{const a={x:1/0,y:1/0,z:1/0},l={x:-1/0,y:-1/0,z:-1/0};for(let e=0;e<i.length;e++){const r=i[e],s=t[3*r],o=t[3*r+1],n=t[3*r+2];a.x=Math.min(a.x,s),a.y=Math.min(a.y,o),a.z=Math.min(a.z,n),l.x=Math.max(l.x,s),l.y=Math.max(l.y,o),l.z=Math.max(l.z,n)}return{bbMin:e.vec3.toArray(a),bbMax:e.vec3.toArray(l)}},i=e=>{let t=0,i=0;return t=Number(e>65535)<<4,e>>=t,i=Number(e>255)<<3,e>>=i,t|=i,i=Number(e>15)<<2,e>>=i,t|=i,i=Number(e>3)<<1,t|=i,t|=(e>>=i)>>1,t},a=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),l={...e.recastConfigDefaults},r={...e.recastConfigDefaults,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},s=()=>new e.TileCacheMeshProcess(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)})),o={...e.recastConfigDefaults};exports.createDefaultTileCacheMeshProcess=s,exports.dtIlog2=i,exports.dtNextPow2=a,exports.generateSoloNavMesh=(i,a,r={},s=!1)=>{const o=new e.RecastBuildContext,n={type:"solo",buildContext:o},d=new e.NavMesh,h=t=>(s||(n.heightfield&&(e.freeHeightfield(n.heightfield),n.heightfield=void 0),n.compactHeightfield&&(e.freeCompactHeightfield(n.compactHeightfield),n.compactHeightfield=void 0),n.contourSet&&(e.freeContourSet(n.contourSet),n.contourSet=void 0)),d.destroy(),{navMesh:void 0,success:!1,intermediates:n,error:t}),c=i,g=a.length,f=new e.Arrays.VertsArray;f.copy(c,c.length);const m=a,u=a.length/3,b=new e.Arrays.TrisArray;b.copy(m,m.length);const{bbMin:w,bbMax:C}=t(i,a),R=e.createRcConfig({...l,...r});R.minRegionArea=R.minRegionArea*R.minRegionArea,R.mergeRegionArea=R.mergeRegionArea*R.mergeRegionArea,R.detailSampleDist=R.detailSampleDist<.9?0:R.cs*R.detailSampleDist,R.detailSampleMaxError=R.ch*R.detailSampleMaxError;const S=e.Raw.Recast.calcGridSize(w,C,R.cs);R.width=S.width,R.height=S.height;const y=e.allocHeightfield();if(n.heightfield=y,!e.createHeightfield(o,y,R.width,R.height,w,C,R.cs,R.ch))return h("Could not create heightfield");const M=new e.Arrays.TriAreasArray;if(M.resize(u),e.markWalkableTriangles(o,R.walkableSlopeAngle,f,g,b,u,M),!e.rasterizeTriangles(o,f,g,b,M,u,y,R.walkableClimb))return h("Could not rasterize triangles");M.free(),e.filterLowHangingWalkableObstacles(o,R.walkableClimb,y),e.filterLedgeSpans(o,R.walkableHeight,R.walkableClimb,y),e.filterWalkableLowHeightSpans(o,R.walkableHeight,y);const p=e.allocCompactHeightfield();if(n.compactHeightfield=p,!e.buildCompactHeightfield(o,R.walkableHeight,R.walkableClimb,y,p))return h("Failed to build compact data");if(s||(e.freeHeightfield(y),n.heightfield=void 0),!e.erodeWalkableArea(o,R.walkableRadius,p))return h("Failed to erode walkable area");if(!e.buildDistanceField(o,p))return h("Failed to build distance field");if(!e.buildRegions(o,p,R.borderSize,R.minRegionArea,R.mergeRegionArea))return h("Failed to build regions");const x=e.allocContourSet();if(n.contourSet=x,!e.buildContours(o,p,R.maxSimplificationError,R.maxEdgeLen,x,e.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return h("Failed to create contours");const A=e.allocPolyMesh();if(!e.buildPolyMesh(o,x,R.maxVertsPerPoly,A))return h("Failed to triangulate contours");const k=e.allocPolyMeshDetail();if(!e.buildPolyMeshDetail(o,A,p,R.detailSampleDist,R.detailSampleMaxError,k))return h("Failed to build detail mesh");s||(e.freeCompactHeightfield(p),n.compactHeightfield=void 0,e.freeContourSet(x),n.contourSet=void 0);for(let t=0;t<A.npolys();t++)A.areas(t)==e.Raw.Recast.WALKABLE_AREA&&A.setAreas(t,0),0==A.areas(t)&&A.setFlags(t,1);const H=new e.NavMeshCreateParams;H.setPolyMeshCreateParams(A),H.setPolyMeshDetailCreateParams(k),H.setWalkableHeight(R.walkableHeight),H.setWalkableRadius(R.walkableRadius),H.setWalkableClimb(R.walkableClimb),H.setCellSize(R.cs),H.setCellHeight(R.ch),H.setBuildBvTree(!0),r.offMeshConnections&&H.setOffMeshConnections(r.offMeshConnections);const T=e.createNavMeshData(H);if(!T.success)return h("Failed to create Detour navmesh data");const{navMeshData:v}=T;return d.initSolo(v)?{success:!0,navMesh:d,intermediates:n}:h("Failed to create Detour navmesh")},exports.generateTileCache=(l,o,n={},d=!1)=>{const h=new e.RecastBuildContext,c={type:"tilecache",buildContext:h,chunkyTriMesh:void 0,tileIntermediates:[]},g=new e.TileCache,f=new e.NavMesh,m=()=>{if(!d)for(let t=0;t<c.tileIntermediates.length;t++){const i=c.tileIntermediates[t];i.heightfield&&(e.freeHeightfield(i.heightfield),i.heightfield=void 0),i.compactHeightfield&&(e.freeCompactHeightfield(i.compactHeightfield),i.compactHeightfield=void 0),i.heightfieldLayerSet&&(e.freeHeightfieldLayerSet(i.heightfieldLayerSet),i.heightfieldLayerSet=void 0)}},u=e=>(m(),g.destroy(),f.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:c,error:e}),b=l,w=o.length,C=new e.Arrays.VertsArray;C.copy(b,b.length);const R=o,S=o.length/3,y=new e.Arrays.TrisArray;y.copy(R,R.length);const{bbMin:M,bbMax:p}=t(l,o),{expectedLayersPerTile:x,maxObstacles:A,...k}={...r,...n},H=e.createRcConfig(k),T=e.calcGridSize(M,p,H.cs);H.width=T.width,H.height=T.height,H.minRegionArea=H.minRegionArea*H.minRegionArea,H.mergeRegionArea=H.mergeRegionArea*H.mergeRegionArea,H.detailSampleDist=H.detailSampleDist<.9?0:H.cs*H.detailSampleDist,H.detailSampleMaxError=H.ch*H.detailSampleMaxError;const v=Math.floor(H.tileSize),z=Math.floor((H.width+v-1)/v),_=Math.floor((H.height+v-1)/v);H.borderSize=H.walkableRadius+3,H.width=H.tileSize+2*H.borderSize,H.height=H.tileSize+2*H.borderSize;const L=e.DetourTileCacheParams.create({orig:M,cs:H.cs,ch:H.ch,width:H.tileSize,height:H.tileSize,walkableHeight:H.walkableHeight,walkableRadius:H.walkableRadius,walkableClimb:H.walkableClimb,maxSimplificationError:H.maxSimplificationError,maxTiles:z*_*x,maxObstacles:A}),D=new e.Raw.RecastLinearAllocator(32e3),E=new e.Raw.RecastFastLZCompressor,P=n.tileCacheMeshProcess??s();if(!g.init(L,D,E,P))return u("Failed to initialize tile cache");const F=e.vec3.fromArray(M);let N=Math.min(Math.floor(i(a(z*_*x))),14);N>14&&(N=14);const O=1<<N,W=1<<22-N,G=e.NavMeshParams.create({orig:F,tileWidth:H.tileSize*H.cs,tileHeight:H.tileSize*H.cs,maxTiles:O,maxPolys:W});if(!f.initTiled(G))return u("Failed to initialize tiled navmesh");const I=new e.RecastChunkyTriMesh;if(c.chunkyTriMesh=I,!I.init(C,y,S,256))return u("Failed to build chunky triangle mesh");const $=(t,i)=>{const a={tileX:t,tileY:i},l=H.tileSize*H.cs,r=e.cloneRcConfig(H),s=[M[0]+t*l,M[1],M[2]+i*l],o=[M[0]+(t+1)*l,p[1],M[2]+(i+1)*l];s[0]-=r.borderSize*r.cs,s[2]-=r.borderSize*r.cs,o[0]+=r.borderSize*r.cs,o[2]+=r.borderSize*r.cs,r.set_bmin(0,s[0]),r.set_bmin(1,s[1]),r.set_bmin(2,s[2]),r.set_bmax(0,o[0]),r.set_bmax(1,o[1]),r.set_bmax(2,o[2]);const n=e.allocHeightfield();if(a.heightfield=n,!e.createHeightfield(h,n,r.width,r.height,s,o,r.cs,r.ch))return{n:0};const g=[s[0],s[2]],f=[o[0],o[2]],m=new e.Arrays.ChunkIdsArray;m.resize(512);const u=I.getChunksOverlappingRect(g,f,m,512);if(0===u)return{n:0};for(let t=0;t<u;++t){const i=m.get_data(t),a=I.nodes(i).n,l=I.getNodeTris(i),s=new e.Arrays.TriAreasArray;s.resize(a),e.markWalkableTriangles(h,r.walkableSlopeAngle,C,w,l,a,s);const o=e.rasterizeTriangles(h,C,w,l,s,a,n,r.walkableClimb);if(s.free(),!o)return{n:0}}e.filterLowHangingWalkableObstacles(h,H.walkableClimb,n),e.filterLedgeSpans(h,H.walkableHeight,H.walkableClimb,n),e.filterWalkableLowHeightSpans(h,H.walkableHeight,n);const b=e.allocCompactHeightfield();if(!e.buildCompactHeightfield(h,H.walkableHeight,H.walkableClimb,n,b))return{n:0};if(d||(e.freeHeightfield(a.heightfield),a.heightfield=void 0),!e.erodeWalkableArea(h,H.walkableRadius,b))return{n:0};const R=e.allocHeightfieldLayerSet();if(!e.buildHeightfieldLayers(h,b,H.borderSize,H.walkableHeight,R))return{n:0};d||(e.freeCompactHeightfield(b),a.compactHeightfield=void 0);const S=[];for(let a=0;a<R.nlayers();a++){const l=new e.Arrays.TileCacheData,r=R.layers(a),s=new e.Raw.dtTileCacheLayerHeader;s.magic=e.Raw.Detour.TILECACHE_MAGIC,s.version=e.Raw.Detour.TILECACHE_VERSION,s.tx=t,s.ty=i,s.tlayer=a;const o=r.bmin(),n=r.bmax();s.set_bmin(0,o.x),s.set_bmin(1,o.y),s.set_bmin(2,o.z),s.set_bmax(0,n.x),s.set_bmax(1,n.y),s.set_bmax(2,n.z),s.width=r.width(),s.height=r.height(),s.minx=r.minx(),s.maxx=r.maxx(),s.miny=r.miny(),s.maxy=r.maxy(),s.hmin=r.hmin(),s.hmax=r.hmax();const d=e.getHeightfieldLayerHeights(r),h=e.getHeightfieldLayerAreas(r),c=e.getHeightfieldLayerCons(r),g=e.buildTileCacheLayer(E,s,d,h,c,l);if(e.Raw.Detour.statusFailed(g))return{n:0};S.push(l)}return d||(e.freeHeightfieldLayerSet(R),a.heightfieldLayerSet=void 0),c.tileIntermediates.push(a),{n:S.length,tiles:S}};for(let t=0;t<_;++t)for(let i=0;i<z;++i){const{n:a,tiles:l}=$(i,t);if(a>0&&l)for(let r=0;r<a;r++){const a=l[r],s=g.addTile(a);e.Raw.Detour.statusFailed(s.status)&&h.log(e.Raw.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${i}, ty: ${t}`)}}for(let t=0;t<_;t++)for(let i=0;i<z;i++){const a=g.buildNavMeshTilesAt(i,t,f);if(e.Raw.Detour.statusFailed(a))return u(`Failed to build nav mesh tiles at ${i}, ${t}`)}return m(),{success:!0,tileCache:g,navMesh:f,intermediates:c}},exports.generateTiledNavMesh=(l,r,s={},n=!1)=>{const d=new e.RecastBuildContext,h={type:"tiled",buildContext:d,chunkyTriMesh:void 0,tileIntermediates:[]},c=new e.NavMesh,g=()=>{if(!n){for(let t=0;t<h.tileIntermediates.length;t++){const i=h.tileIntermediates[t];i.compactHeightfield&&e.freeCompactHeightfield(i.compactHeightfield),i.heightfield&&e.freeHeightfield(i.heightfield),i.contourSet&&e.freeContourSet(i.contourSet)}h.chunkyTriMesh&&(h.chunkyTriMesh=void 0)}},f=e=>(g(),c.destroy(),{success:!1,navMesh:void 0,intermediates:h,error:e}),m=e.createRcConfig({...o,...s}),{bbMin:u,bbMax:b}=t(l,r),w=e.calcGridSize(u,b,m.cs);m.width=w.width,m.height=w.height,m.minRegionArea=m.minRegionArea*m.minRegionArea,m.mergeRegionArea=m.mergeRegionArea*m.mergeRegionArea,m.tileSize=Math.floor(m.tileSize),m.borderSize=m.walkableRadius+3,m.width=m.tileSize+2*m.borderSize,m.height=m.tileSize+2*m.borderSize,m.detailSampleDist=m.detailSampleDist<.9?0:m.cs*m.detailSampleDist,m.detailSampleMaxError=m.ch*m.detailSampleMaxError;const C=Math.floor(m.tileSize),R=Math.floor((w.width+C-1)/C),S=Math.floor((w.height+C-1)/C),y=m.tileSize*m.cs,M=l,p=r.length,x=new e.Arrays.VertsArray;x.copy(M,M.length);const A=r,k=r.length/3,H=new e.Arrays.TrisArray;H.copy(A,A.length);const T=e.vec3.fromArray(u);let v=Math.min(Math.floor(i(a(R*S))),14);v>14&&(v=14);const z=1<<v,_=1<<22-v,L=e.NavMeshParams.create({orig:T,tileWidth:m.tileSize*m.cs,tileHeight:m.tileSize*m.cs,maxTiles:z,maxPolys:_});if(!c.initTiled(L))return f("Could not init nav mesh for tiled use");const D=new e.RecastChunkyTriMesh;if(h.chunkyTriMesh=D,!D.init(x,H,k,256))return f("Failed to build chunky triangle mesh");const E=(t,i,a,l)=>{const r=t=>(d.log(e.Raw.Module.RC_LOG_ERROR,t),{success:!1,error:t}),o={tileX:t,tileY:i};h.tileIntermediates.push(o);const c=e.cloneRcConfig(m),g=[...a],f=[...l];g[0]-=c.borderSize*c.cs,g[2]-=c.borderSize*c.cs,f[0]+=c.borderSize*c.cs,f[2]+=c.borderSize*c.cs,c.set_bmin(0,g[0]),c.set_bmin(1,g[1]),c.set_bmin(2,g[2]),c.set_bmax(0,f[0]),c.set_bmax(1,f[1]),c.set_bmax(2,f[2]),d.resetTimers(),d.startTimer(e.Raw.Module.RC_TIMER_TOTAL),d.log(e.Raw.Module.RC_LOG_PROGRESS,`Building tile ${h.tileIntermediates.length} at x: ${t}, y: ${i}`),d.log(e.Raw.Module.RC_LOG_PROGRESS,` - ${m.width} x ${m.height} cells`),d.log(e.Raw.Module.RC_LOG_PROGRESS,` - ${p/1e3}fK verts, ${k/1e3}K tris`);const u=e.allocHeightfield();if(o.heightfield=u,!e.createHeightfield(d,u,c.width,c.height,g,f,c.cs,c.ch))return r("Could not create heightfield");(new e.Arrays.TriAreasArray).resize(D.maxTrisPerChunk());const b=[g[0],g[2]],w=[f[0],f[2]],C=new e.Arrays.ChunkIdsArray;C.resize(512);const R=D.getChunksOverlappingRect(b,w,C,512);if(0===R)return{success:!0};for(let t=0;t<R;++t){const i=C.get_data(t),a=D.nodes(i).n,l=D.getNodeTris(i),s=new e.Arrays.TriAreasArray;s.resize(a),e.markWalkableTriangles(d,c.walkableSlopeAngle,x,p,l,a,s);const o=e.rasterizeTriangles(d,x,p,l,s,a,u,c.walkableClimb);if(s.free(),!o)return r("Could not rasterize triangles")}e.filterLowHangingWalkableObstacles(d,c.walkableClimb,u),e.filterLedgeSpans(d,c.walkableHeight,c.walkableClimb,u),e.filterWalkableLowHeightSpans(d,c.walkableHeight,u);const S=e.allocCompactHeightfield();if(o.compactHeightfield=S,!e.buildCompactHeightfield(d,c.walkableHeight,c.walkableClimb,u,S))return r("Could not build compact heightfield");if(n||(e.freeHeightfield(o.heightfield),o.heightfield=void 0),!e.erodeWalkableArea(d,c.walkableRadius,S))return r("Could not erode walkable area");if(!e.buildDistanceField(d,S))return r("Failed to build distance field");if(!e.buildRegions(d,S,c.borderSize,c.minRegionArea,c.mergeRegionArea))return r("Failed to build regions");const y=e.allocContourSet();if(o.contourSet=y,!e.buildContours(d,S,c.maxSimplificationError,c.maxEdgeLen,y,e.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const M=e.allocPolyMesh();if(!e.buildPolyMesh(d,y,c.maxVertsPerPoly,M))return r("Failed to triangulate contours");const A=e.allocPolyMeshDetail();if(!e.buildPolyMeshDetail(d,M,S,c.detailSampleDist,c.detailSampleMaxError,A))return r("Failed to build detail mesh");n||(e.freeCompactHeightfield(S),o.compactHeightfield=void 0,e.freeContourSet(y),o.contourSet=void 0);for(let t=0;t<M.npolys();t++)M.areas(t)==e.Raw.Recast.WALKABLE_AREA&&M.setAreas(t,0),0==M.areas(t)&&M.setFlags(t,1);const H=new e.NavMeshCreateParams;H.setPolyMeshCreateParams(M),H.setPolyMeshDetailCreateParams(A),H.setWalkableHeight(c.walkableHeight),H.setWalkableRadius(c.walkableRadius),H.setWalkableClimb(c.walkableClimb),H.setCellSize(c.cs),H.setCellHeight(c.ch),H.setBuildBvTree(!0),s.offMeshConnections&&H.setOffMeshConnections(s.offMeshConnections),H.setTileX(t),H.setTileY(i);const T=e.createNavMeshData(H);return T.success?(d.log(e.Raw.Module.RC_LOG_PROGRESS,`>> Polymesh: ${M.nverts()} vertices ${M.npolys()} polygons`),{success:!0,data:T.navMeshData}):r("Failed to create Detour navmesh data")};d.startTimer(e.Raw.Module.RC_TIMER_TEMP);const P=[0,0,0],F=[0,0,0];for(let t=0;t<S;t++)for(let i=0;i<R;i++){P[0]=u[0]+i*y,P[1]=u[1],P[2]=u[2]+t*y,F[0]=u[0]+(i+1)*y,F[1]=b[1],F[2]=u[2]+(t+1)*y;const a=E(i,t,P,F);if(a.success&&a.data){c.removeTile(c.getTileRefAt(i,t,0));const l=c.addTile(a.data,e.Raw.Module.DT_TILE_FREE_DATA,0);e.Raw.Detour.statusFailed(l.status)&&(d.log(e.Raw.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${i}, ty: ${t},status: ${e.dtStatusToReadableString(l.status)} (${l.status})`),a.data.free())}}return d.stopTimer(e.Raw.Module.RC_TIMER_TEMP),n||g(),{success:!0,navMesh:c,intermediates:h}},exports.getBoundingBox=t,exports.soloNavMeshGeneratorConfigDefaults=l,exports.tileCacheGeneratorConfigDefaults=r,exports.tiledNavMeshGeneratorConfigDefaults=o;
2
2
  //# sourceMappingURL=generators.cjs.map
package/generators.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{recastConfigDefaults as e,vec3 as t,RecastBuildContext as i,NavMesh as a,Arrays as l,createRcConfig as r,Raw as s,allocHeightfield as o,createHeightfield as n,markWalkableTriangles as d,rasterizeTriangles as h,filterLowHangingWalkableObstacles as c,filterLedgeSpans as m,filterWalkableLowHeightSpans as g,allocCompactHeightfield as u,buildCompactHeightfield as b,freeHeightfield as f,erodeWalkableArea as S,buildDistanceField as w,buildRegions as M,allocContourSet as C,buildContours as y,allocPolyMesh as R,buildPolyMesh as x,allocPolyMeshDetail as p,buildPolyMeshDetail as A,freeCompactHeightfield as k,freeContourSet as z,NavMeshCreateParams as _,createNavMeshData as v,TileCacheMeshProcess as T,TileCache as E,calcGridSize as H,DetourTileCacheParams as F,NavMeshParams as D,RecastChunkyTriMesh as L,dtStatusToReadableString as P,freeHeightfieldLayerSet as I,cloneRcConfig as O,allocHeightfieldLayerSet as G,buildHeightfieldLayers as N,getHeightfieldLayerHeights as $,getHeightfieldLayerAreas as W,getHeightfieldLayerCons as B,buildTileCacheLayer as U}from"@recast-navigation/core";const K=(e,i)=>{const a={x:1/0,y:1/0,z:1/0},l={x:-1/0,y:-1/0,z:-1/0};for(let t=0;t<i.length;t++){const r=i[t],s=e[3*r],o=e[3*r+1],n=e[3*r+2];a.x=Math.min(a.x,s),a.y=Math.min(a.y,o),a.z=Math.min(a.z,n),l.x=Math.max(l.x,s),l.y=Math.max(l.y,o),l.z=Math.max(l.z,n)}return{bbMin:t.toArray(a),bbMax:t.toArray(l)}},V=e=>{let t=0,i=0;return t=Number(e>65535)<<4,e>>=t,i=Number(e>255)<<3,e>>=i,t|=i,i=Number(e>15)<<2,e>>=i,t|=i,i=Number(e>3)<<1,t|=i,t|=(e>>=i)>>1,t},X=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),Y={...e},Z=(e,t,T={},E=!1)=>{const H=new i,F={type:"solo",buildContext:H},D=new a,L=e=>(E||(F.heightfield&&(f(F.heightfield),F.heightfield=void 0),F.compactHeightfield&&(k(F.compactHeightfield),F.compactHeightfield=void 0),F.contourSet&&(z(F.contourSet),F.contourSet=void 0)),D.destroy(),{navMesh:void 0,success:!1,intermediates:F,error:e}),P=e,I=t.length,O=new l.FloatArray;O.copy(P,P.length);const G=t,N=t.length/3,$=new l.IntArray;$.copy(G,G.length);const{bbMin:W,bbMax:B}=K(e,t),U=r({...Y,...T});U.minRegionArea=U.minRegionArea*U.minRegionArea,U.mergeRegionArea=U.mergeRegionArea*U.mergeRegionArea,U.detailSampleDist=U.detailSampleDist<.9?0:U.cs*U.detailSampleDist,U.detailSampleMaxError=U.ch*U.detailSampleMaxError;const V=s.Recast.calcGridSize(W,B,U.cs);U.width=V.width,U.height=V.height;const X=o();if(F.heightfield=X,!n(H,X,U.width,U.height,W,B,U.cs,U.ch))return L("Could not create heightfield");const Z=new l.UnsignedCharArray;if(Z.resize(N),d(H,U.walkableSlopeAngle,O,I,$,N,Z),!h(H,O,I,$,Z,N,X,U.walkableClimb))return L("Could not rasterize triangles");Z.free(),c(H,U.walkableClimb,X),m(H,U.walkableHeight,U.walkableClimb,X),g(H,U.walkableHeight,X);const j=u();if(F.compactHeightfield=j,!b(H,U.walkableHeight,U.walkableClimb,X,j))return L("Failed to build compact data");if(E||(f(X),F.heightfield=void 0),!S(H,U.walkableRadius,j))return L("Failed to erode walkable area");if(!w(H,j))return L("Failed to build distance field");if(!M(H,j,U.borderSize,U.minRegionArea,U.mergeRegionArea))return L("Failed to build regions");const q=C();if(F.contourSet=q,!y(H,j,U.maxSimplificationError,U.maxEdgeLen,q,s.Module.RC_CONTOUR_TESS_WALL_EDGES))return L("Failed to create contours");const J=R();if(!x(H,q,U.maxVertsPerPoly,J))return L("Failed to triangulate contours");const Q=p();if(!A(H,J,j,U.detailSampleDist,U.detailSampleMaxError,Q))return L("Failed to build detail mesh");E||(k(j),F.compactHeightfield=void 0,z(q),F.contourSet=void 0);for(let e=0;e<J.npolys();e++)J.areas(e)==s.Recast.WALKABLE_AREA&&J.setAreas(e,0),0==J.areas(e)&&J.setFlags(e,1);const ee=new _;ee.setPolyMeshCreateParams(J),ee.setPolyMeshDetailCreateParams(Q),ee.setWalkableHeight(U.walkableHeight),ee.setWalkableRadius(U.walkableRadius),ee.setWalkableClimb(U.walkableClimb),ee.setCellSize(U.cs),ee.setCellHeight(U.ch),ee.setBuildBvTree(!0),T.offMeshConnections&&ee.setOffMeshConnections(T.offMeshConnections);const te=v(ee);if(!te.success)return L("Failed to create Detour navmesh data");const{navMeshData:ie}=te;return D.initSolo(ie)?{success:!0,navMesh:D,intermediates:F}:L("Failed to create Detour navmesh")},j={...e,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},q=()=>new T(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)})),J=(e,w,M={},C=!1)=>{const y=new i;let R={type:"tilecache",buildContext:y,chunkyTriMesh:void 0,tileIntermediates:[]};const x=new E,p=new a,A=()=>{if(!C)for(let e=0;e<R.tileIntermediates.length;e++){const t=R.tileIntermediates[e];t.heightfield&&(f(t.heightfield),t.heightfield=void 0),t.compactHeightfield&&(k(t.compactHeightfield),t.compactHeightfield=void 0),t.heightfieldLayerSet&&(I(t.heightfieldLayerSet),t.heightfieldLayerSet=void 0)}},z=e=>(A(),x.destroy(),p.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:R,error:e}),_=e,v=w.length,T=new l.FloatArray;T.copy(_,_.length);const P=w,Y=w.length/3,Z=new l.IntArray;Z.copy(P,P.length);const{bbMin:J,bbMax:Q}=K(e,w),{expectedLayersPerTile:ee,maxObstacles:te,...ie}={...j,...M},ae=r(ie),le=H(J,Q,ae.cs);ae.width=le.width,ae.height=le.height,ae.minRegionArea=ae.minRegionArea*ae.minRegionArea,ae.mergeRegionArea=ae.mergeRegionArea*ae.mergeRegionArea,ae.detailSampleDist=ae.detailSampleDist<.9?0:ae.cs*ae.detailSampleDist,ae.detailSampleMaxError=ae.ch*ae.detailSampleMaxError;const re=Math.floor(ae.tileSize),se=Math.floor((ae.width+re-1)/re),oe=Math.floor((ae.height+re-1)/re);ae.borderSize=ae.walkableRadius+3,ae.width=ae.tileSize+2*ae.borderSize,ae.height=ae.tileSize+2*ae.borderSize;const ne=F.create({orig:J,cs:ae.cs,ch:ae.ch,width:ae.tileSize,height:ae.tileSize,walkableHeight:ae.walkableHeight,walkableRadius:ae.walkableRadius,walkableClimb:ae.walkableClimb,maxSimplificationError:ae.maxSimplificationError,maxTiles:se*oe*ee,maxObstacles:te}),de=new s.RecastLinearAllocator(32e3),he=new s.RecastFastLZCompressor,ce=M.tileCacheMeshProcess??q();if(!x.init(ne,de,he,ce))return z("Failed to initialize tile cache");const me=t.fromArray(J);let ge=Math.min(Math.floor(V(X(se*oe*ee))),14);ge>14&&(ge=14);const ue=1<<ge,be=1<<22-ge,fe=D.create({orig:me,tileWidth:ae.tileSize*ae.cs,tileHeight:ae.tileSize*ae.cs,maxTiles:ue,maxPolys:be});if(!p.initTiled(fe))return z("Failed to initialize tiled navmesh");const Se=new L;if(R.chunkyTriMesh=Se,!Se.init(T,Z,Y,256))return z("Failed to build chunky triangle mesh");const we=(e,t)=>{const i={tileX:e,tileY:t},a=ae.tileSize*ae.cs,r=O(ae),w=[J[0]+e*a,J[1],J[2]+t*a],M=[J[0]+(e+1)*a,Q[1],J[2]+(t+1)*a];w[0]-=r.borderSize*r.cs,w[2]-=r.borderSize*r.cs,M[0]+=r.borderSize*r.cs,M[2]+=r.borderSize*r.cs,r.set_bmin(0,w[0]),r.set_bmin(1,w[1]),r.set_bmin(2,w[2]),r.set_bmax(0,M[0]),r.set_bmax(1,M[1]),r.set_bmax(2,M[2]);const x=o();if(i.heightfield=x,!n(y,x,r.width,r.height,w,M,r.cs,r.ch))return{n:0};const p=[w[0],w[2]],A=[M[0],M[2]],z=new l.IntArray;z.resize(512);const _=Se.getChunksOverlappingRect(p,A,z,512);if(0===_)return{n:0};for(let e=0;e<_;++e){const t=z.get_data(e),i=Se.nodes(t).n,a=Se.getNodeTris(t),s=new l.UnsignedCharArray;s.resize(i),d(y,r.walkableSlopeAngle,T,v,a,i,s);const o=h(y,T,v,a,s,i,x,r.walkableClimb);if(s.free(),!o)return{n:0}}c(y,ae.walkableClimb,x),m(y,ae.walkableHeight,ae.walkableClimb,x),g(y,ae.walkableHeight,x);const E=u();if(!b(y,ae.walkableHeight,ae.walkableClimb,x,E))return{n:0};if(C||(f(i.heightfield),i.heightfield=void 0),!S(y,ae.walkableRadius,E))return{n:0};const H=G();if(!N(y,E,ae.borderSize,ae.walkableHeight,H))return{n:0};C||(k(E),i.compactHeightfield=void 0);const F=[];for(let i=0;i<H.nlayers();i++){const a=new l.UnsignedCharArray,r=H.layers(i),o=new s.dtTileCacheLayerHeader;o.magic=s.Detour.TILECACHE_MAGIC,o.version=s.Detour.TILECACHE_VERSION,o.tx=e,o.ty=t,o.tlayer=i;const n=r.bmin(),d=r.bmax();o.set_bmin(0,n.x),o.set_bmin(1,n.y),o.set_bmin(2,n.z),o.set_bmax(0,d.x),o.set_bmax(1,d.y),o.set_bmax(2,d.z),o.width=r.width(),o.height=r.height(),o.minx=r.minx(),o.maxx=r.maxx(),o.miny=r.miny(),o.maxy=r.maxy(),o.hmin=r.hmin(),o.hmax=r.hmax();const h=$(r),c=W(r),m=B(r),g=U(he,o,h,c,m,a);if(s.Detour.statusFailed(g))return{n:0};F.push(a)}return C||(I(H),i.heightfieldLayerSet=void 0),R.tileIntermediates.push(i),{n:F.length,tiles:F}};for(let e=0;e<oe;++e)for(let t=0;t<se;++t){const{n:i,tiles:a}=we(t,e);if(i>0&&a)for(let l=0;l<i;l++){const i=a[l],r=x.addTile(i);s.Detour.statusFailed(r.status)&&y.log(s.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${t}, ty: ${e}`)}}for(let e=0;e<oe;e++)for(let t=0;t<se;t++){const i=x.buildNavMeshTilesAt(t,e,p);if(s.Detour.statusFailed(i))return z(`Failed to build nav mesh tiles at ${t}, ${e}`)}return A(),{success:!0,tileCache:x,navMesh:p,intermediates:R}},Q={...e},ee=(e,T,E={},F=!1)=>{const I=new i,G={type:"tiled",buildContext:I,chunkyTriMesh:void 0,tileIntermediates:[]},N=new a,$=()=>{if(!F){for(let e=0;e<G.tileIntermediates.length;e++){const t=G.tileIntermediates[e];t.compactHeightfield&&k(t.compactHeightfield),t.heightfield&&f(t.heightfield),t.contourSet&&z(t.contourSet)}G.chunkyTriMesh&&(G.chunkyTriMesh=void 0)}},W=e=>($(),N.destroy(),{success:!1,navMesh:void 0,intermediates:G,error:e}),B=r({...Q,...E}),{bbMin:U,bbMax:Y}=K(e,T),Z=H(U,Y,B.cs);B.width=Z.width,B.height=Z.height,B.minRegionArea=B.minRegionArea*B.minRegionArea,B.mergeRegionArea=B.mergeRegionArea*B.mergeRegionArea,B.tileSize=Math.floor(B.tileSize),B.borderSize=B.walkableRadius+3,B.width=B.tileSize+2*B.borderSize,B.height=B.tileSize+2*B.borderSize,B.detailSampleDist=B.detailSampleDist<.9?0:B.cs*B.detailSampleDist,B.detailSampleMaxError=B.ch*B.detailSampleMaxError;const j=Math.floor(B.tileSize),q=Math.floor((Z.width+j-1)/j),J=Math.floor((Z.height+j-1)/j),ee=B.tileSize*B.cs,te=e,ie=T.length,ae=new l.FloatArray;ae.copy(te,te.length);const le=T,re=T.length/3,se=new l.IntArray;se.copy(le,le.length);const oe=t.fromArray(U);let ne=Math.min(Math.floor(V(X(q*J))),14);ne>14&&(ne=14);const de=1<<ne,he=1<<22-ne,ce=D.create({orig:oe,tileWidth:B.tileSize*B.cs,tileHeight:B.tileSize*B.cs,maxTiles:de,maxPolys:he});if(!N.initTiled(ce))return W("Could not init nav mesh for tiled use");const me=new L;if(G.chunkyTriMesh=me,!me.init(ae,se,re,256))return W("Failed to build chunky triangle mesh");const ge=(e,t,i,a)=>{const r=e=>(I.log(s.Module.RC_LOG_ERROR,e),{success:!1,error:e}),T={tileX:e,tileY:t};G.tileIntermediates.push(T);const H=O(B),D=[...i],L=[...a];D[0]-=H.borderSize*H.cs,D[2]-=H.borderSize*H.cs,L[0]+=H.borderSize*H.cs,L[2]+=H.borderSize*H.cs,H.set_bmin(0,D[0]),H.set_bmin(1,D[1]),H.set_bmin(2,D[2]),H.set_bmax(0,L[0]),H.set_bmax(1,L[1]),H.set_bmax(2,L[2]),I.resetTimers(),I.startTimer(s.Module.RC_TIMER_TOTAL),I.log(s.Module.RC_LOG_PROGRESS,`Building tile ${G.tileIntermediates.length} at x: ${e}, y: ${t}`),I.log(s.Module.RC_LOG_PROGRESS,` - ${B.width} x ${B.height} cells`),I.log(s.Module.RC_LOG_PROGRESS,` - ${ie/1e3}fK verts, ${re/1e3}K tris`);const P=o();if(T.heightfield=P,!n(I,P,H.width,H.height,D,L,H.cs,H.ch))return r("Could not create heightfield");(new l.UnsignedCharArray).resize(me.maxTrisPerChunk());const N=[D[0],D[2]],$=[L[0],L[2]],W=new l.IntArray;W.resize(512);const U=me.getChunksOverlappingRect(N,$,W,512);if(0===U)return{success:!0};for(let e=0;e<U;++e){const t=W.get_data(e),i=me.nodes(t).n,a=me.getNodeTris(t),s=new l.UnsignedCharArray;s.resize(i),d(I,H.walkableSlopeAngle,ae,ie,a,i,s);const o=h(I,ae,ie,a,s,i,P,H.walkableClimb);if(s.free(),!o)return r("Could not rasterize triangles")}c(I,H.walkableClimb,P),m(I,H.walkableHeight,H.walkableClimb,P),g(I,H.walkableHeight,P);const K=u();if(T.compactHeightfield=K,!b(I,H.walkableHeight,H.walkableClimb,P,K))return r("Could not build compact heightfield");if(F||(f(T.heightfield),T.heightfield=void 0),!S(I,H.walkableRadius,K))return r("Could not erode walkable area");if(!w(I,K))return r("Failed to build distance field");if(!M(I,K,H.borderSize,H.minRegionArea,H.mergeRegionArea))return r("Failed to build regions");const V=C();if(T.contourSet=V,!y(I,K,H.maxSimplificationError,H.maxEdgeLen,V,s.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const X=R();if(!x(I,V,H.maxVertsPerPoly,X))return r("Failed to triangulate contours");const Y=p();if(!A(I,X,K,H.detailSampleDist,H.detailSampleMaxError,Y))return r("Failed to build detail mesh");F||(k(K),T.compactHeightfield=void 0,z(V),T.contourSet=void 0);for(let e=0;e<X.npolys();e++)X.areas(e)==s.Recast.WALKABLE_AREA&&X.setAreas(e,0),0==X.areas(e)&&X.setFlags(e,1);const Z=new _;Z.setPolyMeshCreateParams(X),Z.setPolyMeshDetailCreateParams(Y),Z.setWalkableHeight(H.walkableHeight),Z.setWalkableRadius(H.walkableRadius),Z.setWalkableClimb(H.walkableClimb),Z.setCellSize(H.cs),Z.setCellHeight(H.ch),Z.setBuildBvTree(!0),E.offMeshConnections&&Z.setOffMeshConnections(E.offMeshConnections),Z.setTileX(e),Z.setTileY(t);const j=v(Z);return j.success?(I.log(s.Module.RC_LOG_PROGRESS,`>> Polymesh: ${X.nverts()} vertices ${X.npolys()} polygons`),{success:!0,data:j.navMeshData}):r("Failed to create Detour navmesh data")};I.startTimer(s.Module.RC_TIMER_TEMP);let ue=[0,0,0],be=[0,0,0];for(let e=0;e<J;e++)for(let t=0;t<q;t++){ue[0]=U[0]+t*ee,ue[1]=U[1],ue[2]=U[2]+e*ee,be[0]=U[0]+(t+1)*ee,be[1]=Y[1],be[2]=U[2]+(e+1)*ee;const i=ge(t,e,ue,be);if(i.success&&i.data){N.removeTile(N.getTileRefAt(t,e,0));const a=N.addTile(i.data,s.Module.DT_TILE_FREE_DATA,0);s.Detour.statusFailed(a.status)&&(I.log(s.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${t}, ty: ${e},status: ${P(a.status)} (${a.status})`),i.data.free())}}return I.stopTimer(s.Module.RC_TIMER_TEMP),F||$(),{success:!0,navMesh:N,intermediates:G}};export{q as createDefaultTileCacheMeshProcess,V as dtIlog2,X as dtNextPow2,Z as generateSoloNavMesh,J as generateTileCache,ee as generateTiledNavMesh,K as getBoundingBox,Y as soloNavMeshGeneratorConfigDefaults,j as tileCacheGeneratorConfigDefaults,Q as tiledNavMeshGeneratorConfigDefaults};
1
+ import{recastConfigDefaults as e,vec3 as t,RecastBuildContext as i,NavMesh as a,Arrays as l,createRcConfig as r,Raw as s,allocHeightfield as o,createHeightfield as n,markWalkableTriangles as d,rasterizeTriangles as h,filterLowHangingWalkableObstacles as c,filterLedgeSpans as m,filterWalkableLowHeightSpans as g,allocCompactHeightfield as u,buildCompactHeightfield as b,freeHeightfield as f,erodeWalkableArea as S,buildDistanceField as w,buildRegions as M,allocContourSet as C,buildContours as y,allocPolyMesh as R,buildPolyMesh as x,allocPolyMeshDetail as p,buildPolyMeshDetail as A,freeCompactHeightfield as k,freeContourSet as T,NavMeshCreateParams as z,createNavMeshData as _,TileCacheMeshProcess as v,TileCache as E,calcGridSize as H,DetourTileCacheParams as D,NavMeshParams as F,RecastChunkyTriMesh as L,dtStatusToReadableString as P,freeHeightfieldLayerSet as O,cloneRcConfig as I,allocHeightfieldLayerSet as G,buildHeightfieldLayers as N,getHeightfieldLayerHeights as $,getHeightfieldLayerAreas as W,getHeightfieldLayerCons as B,buildTileCacheLayer as V}from"@recast-navigation/core";const K=(e,i)=>{const a={x:1/0,y:1/0,z:1/0},l={x:-1/0,y:-1/0,z:-1/0};for(let t=0;t<i.length;t++){const r=i[t],s=e[3*r],o=e[3*r+1],n=e[3*r+2];a.x=Math.min(a.x,s),a.y=Math.min(a.y,o),a.z=Math.min(a.z,n),l.x=Math.max(l.x,s),l.y=Math.max(l.y,o),l.z=Math.max(l.z,n)}return{bbMin:t.toArray(a),bbMax:t.toArray(l)}},X=e=>{let t=0,i=0;return t=Number(e>65535)<<4,e>>=t,i=Number(e>255)<<3,e>>=i,t|=i,i=Number(e>15)<<2,e>>=i,t|=i,i=Number(e>3)<<1,t|=i,t|=(e>>=i)>>1,t},Y=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),U={...e},Z=(e,t,v={},E=!1)=>{const H=new i,D={type:"solo",buildContext:H},F=new a,L=e=>(E||(D.heightfield&&(f(D.heightfield),D.heightfield=void 0),D.compactHeightfield&&(k(D.compactHeightfield),D.compactHeightfield=void 0),D.contourSet&&(T(D.contourSet),D.contourSet=void 0)),F.destroy(),{navMesh:void 0,success:!1,intermediates:D,error:e}),P=e,O=t.length,I=new l.VertsArray;I.copy(P,P.length);const G=t,N=t.length/3,$=new l.TrisArray;$.copy(G,G.length);const{bbMin:W,bbMax:B}=K(e,t),V=r({...U,...v});V.minRegionArea=V.minRegionArea*V.minRegionArea,V.mergeRegionArea=V.mergeRegionArea*V.mergeRegionArea,V.detailSampleDist=V.detailSampleDist<.9?0:V.cs*V.detailSampleDist,V.detailSampleMaxError=V.ch*V.detailSampleMaxError;const X=s.Recast.calcGridSize(W,B,V.cs);V.width=X.width,V.height=X.height;const Y=o();if(D.heightfield=Y,!n(H,Y,V.width,V.height,W,B,V.cs,V.ch))return L("Could not create heightfield");const Z=new l.TriAreasArray;if(Z.resize(N),d(H,V.walkableSlopeAngle,I,O,$,N,Z),!h(H,I,O,$,Z,N,Y,V.walkableClimb))return L("Could not rasterize triangles");Z.free(),c(H,V.walkableClimb,Y),m(H,V.walkableHeight,V.walkableClimb,Y),g(H,V.walkableHeight,Y);const j=u();if(D.compactHeightfield=j,!b(H,V.walkableHeight,V.walkableClimb,Y,j))return L("Failed to build compact data");if(E||(f(Y),D.heightfield=void 0),!S(H,V.walkableRadius,j))return L("Failed to erode walkable area");if(!w(H,j))return L("Failed to build distance field");if(!M(H,j,V.borderSize,V.minRegionArea,V.mergeRegionArea))return L("Failed to build regions");const q=C();if(D.contourSet=q,!y(H,j,V.maxSimplificationError,V.maxEdgeLen,q,s.Module.RC_CONTOUR_TESS_WALL_EDGES))return L("Failed to create contours");const J=R();if(!x(H,q,V.maxVertsPerPoly,J))return L("Failed to triangulate contours");const Q=p();if(!A(H,J,j,V.detailSampleDist,V.detailSampleMaxError,Q))return L("Failed to build detail mesh");E||(k(j),D.compactHeightfield=void 0,T(q),D.contourSet=void 0);for(let e=0;e<J.npolys();e++)J.areas(e)==s.Recast.WALKABLE_AREA&&J.setAreas(e,0),0==J.areas(e)&&J.setFlags(e,1);const ee=new z;ee.setPolyMeshCreateParams(J),ee.setPolyMeshDetailCreateParams(Q),ee.setWalkableHeight(V.walkableHeight),ee.setWalkableRadius(V.walkableRadius),ee.setWalkableClimb(V.walkableClimb),ee.setCellSize(V.cs),ee.setCellHeight(V.ch),ee.setBuildBvTree(!0),v.offMeshConnections&&ee.setOffMeshConnections(v.offMeshConnections);const te=_(ee);if(!te.success)return L("Failed to create Detour navmesh data");const{navMeshData:ie}=te;return F.initSolo(ie)?{success:!0,navMesh:F,intermediates:D}:L("Failed to create Detour navmesh")},j={...e,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},q=()=>new v(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)})),J=(e,w,M={},C=!1)=>{const y=new i,R={type:"tilecache",buildContext:y,chunkyTriMesh:void 0,tileIntermediates:[]},x=new E,p=new a,A=()=>{if(!C)for(let e=0;e<R.tileIntermediates.length;e++){const t=R.tileIntermediates[e];t.heightfield&&(f(t.heightfield),t.heightfield=void 0),t.compactHeightfield&&(k(t.compactHeightfield),t.compactHeightfield=void 0),t.heightfieldLayerSet&&(O(t.heightfieldLayerSet),t.heightfieldLayerSet=void 0)}},T=e=>(A(),x.destroy(),p.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:R,error:e}),z=e,_=w.length,v=new l.VertsArray;v.copy(z,z.length);const P=w,U=w.length/3,Z=new l.TrisArray;Z.copy(P,P.length);const{bbMin:J,bbMax:Q}=K(e,w),{expectedLayersPerTile:ee,maxObstacles:te,...ie}={...j,...M},ae=r(ie),le=H(J,Q,ae.cs);ae.width=le.width,ae.height=le.height,ae.minRegionArea=ae.minRegionArea*ae.minRegionArea,ae.mergeRegionArea=ae.mergeRegionArea*ae.mergeRegionArea,ae.detailSampleDist=ae.detailSampleDist<.9?0:ae.cs*ae.detailSampleDist,ae.detailSampleMaxError=ae.ch*ae.detailSampleMaxError;const re=Math.floor(ae.tileSize),se=Math.floor((ae.width+re-1)/re),oe=Math.floor((ae.height+re-1)/re);ae.borderSize=ae.walkableRadius+3,ae.width=ae.tileSize+2*ae.borderSize,ae.height=ae.tileSize+2*ae.borderSize;const ne=D.create({orig:J,cs:ae.cs,ch:ae.ch,width:ae.tileSize,height:ae.tileSize,walkableHeight:ae.walkableHeight,walkableRadius:ae.walkableRadius,walkableClimb:ae.walkableClimb,maxSimplificationError:ae.maxSimplificationError,maxTiles:se*oe*ee,maxObstacles:te}),de=new s.RecastLinearAllocator(32e3),he=new s.RecastFastLZCompressor,ce=M.tileCacheMeshProcess??q();if(!x.init(ne,de,he,ce))return T("Failed to initialize tile cache");const me=t.fromArray(J);let ge=Math.min(Math.floor(X(Y(se*oe*ee))),14);ge>14&&(ge=14);const ue=1<<ge,be=1<<22-ge,fe=F.create({orig:me,tileWidth:ae.tileSize*ae.cs,tileHeight:ae.tileSize*ae.cs,maxTiles:ue,maxPolys:be});if(!p.initTiled(fe))return T("Failed to initialize tiled navmesh");const Se=new L;if(R.chunkyTriMesh=Se,!Se.init(v,Z,U,256))return T("Failed to build chunky triangle mesh");const we=(e,t)=>{const i={tileX:e,tileY:t},a=ae.tileSize*ae.cs,r=I(ae),w=[J[0]+e*a,J[1],J[2]+t*a],M=[J[0]+(e+1)*a,Q[1],J[2]+(t+1)*a];w[0]-=r.borderSize*r.cs,w[2]-=r.borderSize*r.cs,M[0]+=r.borderSize*r.cs,M[2]+=r.borderSize*r.cs,r.set_bmin(0,w[0]),r.set_bmin(1,w[1]),r.set_bmin(2,w[2]),r.set_bmax(0,M[0]),r.set_bmax(1,M[1]),r.set_bmax(2,M[2]);const x=o();if(i.heightfield=x,!n(y,x,r.width,r.height,w,M,r.cs,r.ch))return{n:0};const p=[w[0],w[2]],A=[M[0],M[2]],T=new l.ChunkIdsArray;T.resize(512);const z=Se.getChunksOverlappingRect(p,A,T,512);if(0===z)return{n:0};for(let e=0;e<z;++e){const t=T.get_data(e),i=Se.nodes(t).n,a=Se.getNodeTris(t),s=new l.TriAreasArray;s.resize(i),d(y,r.walkableSlopeAngle,v,_,a,i,s);const o=h(y,v,_,a,s,i,x,r.walkableClimb);if(s.free(),!o)return{n:0}}c(y,ae.walkableClimb,x),m(y,ae.walkableHeight,ae.walkableClimb,x),g(y,ae.walkableHeight,x);const E=u();if(!b(y,ae.walkableHeight,ae.walkableClimb,x,E))return{n:0};if(C||(f(i.heightfield),i.heightfield=void 0),!S(y,ae.walkableRadius,E))return{n:0};const H=G();if(!N(y,E,ae.borderSize,ae.walkableHeight,H))return{n:0};C||(k(E),i.compactHeightfield=void 0);const D=[];for(let i=0;i<H.nlayers();i++){const a=new l.TileCacheData,r=H.layers(i),o=new s.dtTileCacheLayerHeader;o.magic=s.Detour.TILECACHE_MAGIC,o.version=s.Detour.TILECACHE_VERSION,o.tx=e,o.ty=t,o.tlayer=i;const n=r.bmin(),d=r.bmax();o.set_bmin(0,n.x),o.set_bmin(1,n.y),o.set_bmin(2,n.z),o.set_bmax(0,d.x),o.set_bmax(1,d.y),o.set_bmax(2,d.z),o.width=r.width(),o.height=r.height(),o.minx=r.minx(),o.maxx=r.maxx(),o.miny=r.miny(),o.maxy=r.maxy(),o.hmin=r.hmin(),o.hmax=r.hmax();const h=$(r),c=W(r),m=B(r),g=V(he,o,h,c,m,a);if(s.Detour.statusFailed(g))return{n:0};D.push(a)}return C||(O(H),i.heightfieldLayerSet=void 0),R.tileIntermediates.push(i),{n:D.length,tiles:D}};for(let e=0;e<oe;++e)for(let t=0;t<se;++t){const{n:i,tiles:a}=we(t,e);if(i>0&&a)for(let l=0;l<i;l++){const i=a[l],r=x.addTile(i);s.Detour.statusFailed(r.status)&&y.log(s.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${t}, ty: ${e}`)}}for(let e=0;e<oe;e++)for(let t=0;t<se;t++){const i=x.buildNavMeshTilesAt(t,e,p);if(s.Detour.statusFailed(i))return T(`Failed to build nav mesh tiles at ${t}, ${e}`)}return A(),{success:!0,tileCache:x,navMesh:p,intermediates:R}},Q={...e},ee=(e,v,E={},D=!1)=>{const O=new i,G={type:"tiled",buildContext:O,chunkyTriMesh:void 0,tileIntermediates:[]},N=new a,$=()=>{if(!D){for(let e=0;e<G.tileIntermediates.length;e++){const t=G.tileIntermediates[e];t.compactHeightfield&&k(t.compactHeightfield),t.heightfield&&f(t.heightfield),t.contourSet&&T(t.contourSet)}G.chunkyTriMesh&&(G.chunkyTriMesh=void 0)}},W=e=>($(),N.destroy(),{success:!1,navMesh:void 0,intermediates:G,error:e}),B=r({...Q,...E}),{bbMin:V,bbMax:U}=K(e,v),Z=H(V,U,B.cs);B.width=Z.width,B.height=Z.height,B.minRegionArea=B.minRegionArea*B.minRegionArea,B.mergeRegionArea=B.mergeRegionArea*B.mergeRegionArea,B.tileSize=Math.floor(B.tileSize),B.borderSize=B.walkableRadius+3,B.width=B.tileSize+2*B.borderSize,B.height=B.tileSize+2*B.borderSize,B.detailSampleDist=B.detailSampleDist<.9?0:B.cs*B.detailSampleDist,B.detailSampleMaxError=B.ch*B.detailSampleMaxError;const j=Math.floor(B.tileSize),q=Math.floor((Z.width+j-1)/j),J=Math.floor((Z.height+j-1)/j),ee=B.tileSize*B.cs,te=e,ie=v.length,ae=new l.VertsArray;ae.copy(te,te.length);const le=v,re=v.length/3,se=new l.TrisArray;se.copy(le,le.length);const oe=t.fromArray(V);let ne=Math.min(Math.floor(X(Y(q*J))),14);ne>14&&(ne=14);const de=1<<ne,he=1<<22-ne,ce=F.create({orig:oe,tileWidth:B.tileSize*B.cs,tileHeight:B.tileSize*B.cs,maxTiles:de,maxPolys:he});if(!N.initTiled(ce))return W("Could not init nav mesh for tiled use");const me=new L;if(G.chunkyTriMesh=me,!me.init(ae,se,re,256))return W("Failed to build chunky triangle mesh");const ge=(e,t,i,a)=>{const r=e=>(O.log(s.Module.RC_LOG_ERROR,e),{success:!1,error:e}),v={tileX:e,tileY:t};G.tileIntermediates.push(v);const H=I(B),F=[...i],L=[...a];F[0]-=H.borderSize*H.cs,F[2]-=H.borderSize*H.cs,L[0]+=H.borderSize*H.cs,L[2]+=H.borderSize*H.cs,H.set_bmin(0,F[0]),H.set_bmin(1,F[1]),H.set_bmin(2,F[2]),H.set_bmax(0,L[0]),H.set_bmax(1,L[1]),H.set_bmax(2,L[2]),O.resetTimers(),O.startTimer(s.Module.RC_TIMER_TOTAL),O.log(s.Module.RC_LOG_PROGRESS,`Building tile ${G.tileIntermediates.length} at x: ${e}, y: ${t}`),O.log(s.Module.RC_LOG_PROGRESS,` - ${B.width} x ${B.height} cells`),O.log(s.Module.RC_LOG_PROGRESS,` - ${ie/1e3}fK verts, ${re/1e3}K tris`);const P=o();if(v.heightfield=P,!n(O,P,H.width,H.height,F,L,H.cs,H.ch))return r("Could not create heightfield");(new l.TriAreasArray).resize(me.maxTrisPerChunk());const N=[F[0],F[2]],$=[L[0],L[2]],W=new l.ChunkIdsArray;W.resize(512);const V=me.getChunksOverlappingRect(N,$,W,512);if(0===V)return{success:!0};for(let e=0;e<V;++e){const t=W.get_data(e),i=me.nodes(t).n,a=me.getNodeTris(t),s=new l.TriAreasArray;s.resize(i),d(O,H.walkableSlopeAngle,ae,ie,a,i,s);const o=h(O,ae,ie,a,s,i,P,H.walkableClimb);if(s.free(),!o)return r("Could not rasterize triangles")}c(O,H.walkableClimb,P),m(O,H.walkableHeight,H.walkableClimb,P),g(O,H.walkableHeight,P);const K=u();if(v.compactHeightfield=K,!b(O,H.walkableHeight,H.walkableClimb,P,K))return r("Could not build compact heightfield");if(D||(f(v.heightfield),v.heightfield=void 0),!S(O,H.walkableRadius,K))return r("Could not erode walkable area");if(!w(O,K))return r("Failed to build distance field");if(!M(O,K,H.borderSize,H.minRegionArea,H.mergeRegionArea))return r("Failed to build regions");const X=C();if(v.contourSet=X,!y(O,K,H.maxSimplificationError,H.maxEdgeLen,X,s.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const Y=R();if(!x(O,X,H.maxVertsPerPoly,Y))return r("Failed to triangulate contours");const U=p();if(!A(O,Y,K,H.detailSampleDist,H.detailSampleMaxError,U))return r("Failed to build detail mesh");D||(k(K),v.compactHeightfield=void 0,T(X),v.contourSet=void 0);for(let e=0;e<Y.npolys();e++)Y.areas(e)==s.Recast.WALKABLE_AREA&&Y.setAreas(e,0),0==Y.areas(e)&&Y.setFlags(e,1);const Z=new z;Z.setPolyMeshCreateParams(Y),Z.setPolyMeshDetailCreateParams(U),Z.setWalkableHeight(H.walkableHeight),Z.setWalkableRadius(H.walkableRadius),Z.setWalkableClimb(H.walkableClimb),Z.setCellSize(H.cs),Z.setCellHeight(H.ch),Z.setBuildBvTree(!0),E.offMeshConnections&&Z.setOffMeshConnections(E.offMeshConnections),Z.setTileX(e),Z.setTileY(t);const j=_(Z);return j.success?(O.log(s.Module.RC_LOG_PROGRESS,`>> Polymesh: ${Y.nverts()} vertices ${Y.npolys()} polygons`),{success:!0,data:j.navMeshData}):r("Failed to create Detour navmesh data")};O.startTimer(s.Module.RC_TIMER_TEMP);const ue=[0,0,0],be=[0,0,0];for(let e=0;e<J;e++)for(let t=0;t<q;t++){ue[0]=V[0]+t*ee,ue[1]=V[1],ue[2]=V[2]+e*ee,be[0]=V[0]+(t+1)*ee,be[1]=U[1],be[2]=V[2]+(e+1)*ee;const i=ge(t,e,ue,be);if(i.success&&i.data){N.removeTile(N.getTileRefAt(t,e,0));const a=N.addTile(i.data,s.Module.DT_TILE_FREE_DATA,0);s.Detour.statusFailed(a.status)&&(O.log(s.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${t}, ty: ${e},status: ${P(a.status)} (${a.status})`),i.data.free())}}return O.stopTimer(s.Module.RC_TIMER_TEMP),D||$(),{success:!0,navMesh:N,intermediates:G}};export{q as createDefaultTileCacheMeshProcess,X as dtIlog2,Y as dtNextPow2,Z as generateSoloNavMesh,J as generateTileCache,ee as generateTiledNavMesh,K as getBoundingBox,U as soloNavMeshGeneratorConfigDefaults,j as tileCacheGeneratorConfigDefaults,Q as tiledNavMeshGeneratorConfigDefaults};
2
2
  //# sourceMappingURL=generators.mjs.map
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "email": "isaac@isaacmason.com",
19
19
  "url": "https://isaacmason.com/"
20
20
  },
21
- "version": "0.15.1",
21
+ "version": "0.16.1",
22
22
  "license": "MIT",
23
23
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
24
24
  "bugs": {
@@ -62,46 +62,45 @@
62
62
  "build": "yarn clean && rollup --config rollup.config.js --bundleConfigAsCjs",
63
63
  "storybook": "storybook dev -p 6006",
64
64
  "build-storybook": "storybook build",
65
- "test": "vitest run"
65
+ "test": "tsc && vitest run"
66
66
  },
67
67
  "dependencies": {
68
- "@recast-navigation/core": "0.15.1",
69
- "@recast-navigation/generators": "0.15.1",
70
- "@recast-navigation/three": "0.15.1"
68
+ "@recast-navigation/core": "0.16.1",
69
+ "@recast-navigation/generators": "0.16.1",
70
+ "@recast-navigation/three": "0.16.1"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@babel/core": "^7.22.11",
74
74
  "@mdx-js/react": "^2.3.0",
75
75
  "@pmndrs/assets": "^1.6.0",
76
76
  "@react-three/csg": "^3.1.0",
77
- "@react-three/drei": "^9.87.1",
78
- "@react-three/fiber": "^8.14.5",
77
+ "@react-three/drei": "^9.92.3",
78
+ "@react-three/fiber": "^8.15.12",
79
79
  "@rollup/plugin-commonjs": "^25.0.7",
80
- "@rollup/plugin-multi-entry": "^6.0.0",
81
80
  "@rollup/plugin-node-resolve": "^15.0.1",
82
81
  "@rollup/plugin-terser": "^0.4.3",
83
82
  "@rollup/plugin-typescript": "^11.1.5",
84
- "@storybook/addon-actions": "^7.4.5",
85
- "@storybook/addon-essentials": "^7.4.5",
86
- "@storybook/addon-interactions": "^7.4.5",
87
- "@storybook/addon-links": "^7.4.5",
88
- "@storybook/addon-mdx-gfm": "^7.5.1",
89
- "@storybook/react": "^7.4.5",
90
- "@storybook/react-vite": "^7.5.1",
83
+ "@storybook/addon-actions": "^7.5.3",
84
+ "@storybook/addon-essentials": "^7.5.3",
85
+ "@storybook/addon-interactions": "^7.5.3",
86
+ "@storybook/addon-links": "^7.5.3",
87
+ "@storybook/addon-mdx-gfm": "^7.5.3",
88
+ "@storybook/react": "^7.5.3",
89
+ "@storybook/react-vite": "^7.5.3",
91
90
  "@types/react": "^18.2.11",
92
91
  "@types/react-dom": "^18.2.8",
93
- "@types/three": "^0.155.0",
94
- "babel-loader": "^9.1.3",
92
+ "@types/three": "^0.159.0",
95
93
  "leva": "^0.9.35",
96
94
  "react": "^18.2.0",
97
95
  "react-dom": "^18.2.0",
98
- "rollup": "^3.26.3",
96
+ "rollup": "^4.6.0",
99
97
  "rollup-plugin-copy": "^3.4.0",
100
98
  "rollup-plugin-filesize": "^10.0.0",
101
- "storybook": "^7.4.5",
99
+ "storybook": "^7.5.3",
102
100
  "suspend-react": "^0.1.3",
103
- "three": "^0.156.1",
101
+ "three": "^0.159.0",
104
102
  "three-pathfinding": "^1.2.0",
103
+ "typescript": "^5.3.2",
105
104
  "vitest": "^0.34.6"
106
105
  },
107
106
  "packageManager": "yarn@3.2.2"