@recast-navigation/generators 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/generators/common.d.ts +10 -0
- package/dist/generators/generate-solo-nav-mesh.d.ts +33 -0
- package/dist/generators/generate-tile-cache.d.ts +57 -0
- package/dist/generators/generate-tiled-nav-mesh.d.ts +38 -0
- package/dist/generators/index.d.ts +4 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.ts +3 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2022 Isaac Mason
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @recast-navigation/generators
|
|
2
|
+
|
|
3
|
+
This package contains "Preset" NavMesh generators for @recast-navigation/core that make getting started easy.
|
|
4
|
+
|
|
5
|
+
These can also be used as a basis for your own generator.
|
|
6
|
+
|
|
7
|
+
Please refer to the [main package's README](https://github.com/isaac-mason/recast-navigation-js/tree/main/packages/recast-navigation/README.md) for usage information.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OffMeshConnectionParams } from '@recast-navigation/core';
|
|
2
|
+
export declare const getBoundingBox: (positions: ArrayLike<number>, indices: ArrayLike<number>) => {
|
|
3
|
+
bbMin: import("@recast-navigation/core").Vector3Tuple;
|
|
4
|
+
bbMax: import("@recast-navigation/core").Vector3Tuple;
|
|
5
|
+
};
|
|
6
|
+
export declare const dtIlog2: (v: number) => number;
|
|
7
|
+
export declare const dtNextPow2: (v: number) => number;
|
|
8
|
+
export type OffMeshConnectionGeneratorParams = {
|
|
9
|
+
offMeshConnections?: OffMeshConnectionParams[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NavMesh, RecastBuildContext, RecastCompactHeightfield, RecastConfigType, RecastContourSet, RecastHeightfield } from '@recast-navigation/core';
|
|
2
|
+
import { Pretty } from '../types';
|
|
3
|
+
import { OffMeshConnectionGeneratorParams } from './common';
|
|
4
|
+
export type SoloNavMeshGeneratorConfig = Pretty<Omit<RecastConfigType, 'tileSize'> & OffMeshConnectionGeneratorParams>;
|
|
5
|
+
export declare const soloNavMeshGeneratorConfigDefaults: SoloNavMeshGeneratorConfig;
|
|
6
|
+
export type SoloNavMeshGeneratorIntermediates = {
|
|
7
|
+
type: 'solo';
|
|
8
|
+
buildContext: RecastBuildContext;
|
|
9
|
+
heightfield?: RecastHeightfield;
|
|
10
|
+
compactHeightfield?: RecastCompactHeightfield;
|
|
11
|
+
contourSet?: RecastContourSet;
|
|
12
|
+
};
|
|
13
|
+
type SoloNavMeshGeneratorSuccessResult = {
|
|
14
|
+
navMesh: NavMesh;
|
|
15
|
+
success: true;
|
|
16
|
+
intermediates: SoloNavMeshGeneratorIntermediates;
|
|
17
|
+
};
|
|
18
|
+
type SoloNavMeshGeneratorFailResult = {
|
|
19
|
+
navMesh: undefined;
|
|
20
|
+
success: false;
|
|
21
|
+
intermediates: SoloNavMeshGeneratorIntermediates;
|
|
22
|
+
error: string;
|
|
23
|
+
};
|
|
24
|
+
export type SoloNavMeshGeneratorResult = SoloNavMeshGeneratorSuccessResult | SoloNavMeshGeneratorFailResult;
|
|
25
|
+
/**
|
|
26
|
+
* Builds a Solo NavMesh from the given positions and indices.
|
|
27
|
+
* @param positions a flat array of positions
|
|
28
|
+
* @param indices a flat array of indices
|
|
29
|
+
* @param navMeshGeneratorConfig optional configuration for the NavMesh generator
|
|
30
|
+
* @param keepIntermediates if true intermediates will be returned
|
|
31
|
+
*/
|
|
32
|
+
export declare const generateSoloNavMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<SoloNavMeshGeneratorConfig>, keepIntermediates?: boolean) => SoloNavMeshGeneratorResult;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { NavMesh, RecastBuildContext, RecastChunkyTriMesh, RecastCompactHeightfield, RecastConfigType, RecastHeightfield, RecastHeightfieldLayerSet, TileCache, TileCacheMeshProcess } from '@recast-navigation/core';
|
|
2
|
+
import { Pretty } from '../types';
|
|
3
|
+
export type TileCacheGeneratorConfig = Pretty<RecastConfigType & {
|
|
4
|
+
/**
|
|
5
|
+
* How many layers (or "floors") each navmesh tile is expected to have.
|
|
6
|
+
*/
|
|
7
|
+
expectedLayersPerTile: number;
|
|
8
|
+
/**
|
|
9
|
+
* The max number of obstacles
|
|
10
|
+
*/
|
|
11
|
+
maxObstacles: number;
|
|
12
|
+
/**
|
|
13
|
+
* The tile cache mesh process implementation.
|
|
14
|
+
* If not provided, a default one is created via `createDefaultTileCacheMeshProcess()`
|
|
15
|
+
* @default createDefaultTileCacheMeshProcess()
|
|
16
|
+
*/
|
|
17
|
+
tileCacheMeshProcess?: TileCacheMeshProcess;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const tileCacheGeneratorConfigDefaults: TileCacheGeneratorConfig;
|
|
20
|
+
export type TileCacheGeneratorTileIntermediates = {
|
|
21
|
+
tileX: number;
|
|
22
|
+
tileY: number;
|
|
23
|
+
heightfield?: RecastHeightfield;
|
|
24
|
+
compactHeightfield?: RecastCompactHeightfield;
|
|
25
|
+
heightfieldLayerSet?: RecastHeightfieldLayerSet;
|
|
26
|
+
};
|
|
27
|
+
export type TileCacheGeneratorIntermediates = {
|
|
28
|
+
type: 'tilecache';
|
|
29
|
+
buildContext: RecastBuildContext;
|
|
30
|
+
chunkyTriMesh?: RecastChunkyTriMesh;
|
|
31
|
+
tileIntermediates: TileCacheGeneratorTileIntermediates[];
|
|
32
|
+
};
|
|
33
|
+
type TileCacheGeneratorSuccessResult = {
|
|
34
|
+
tileCache: TileCache;
|
|
35
|
+
navMesh: NavMesh;
|
|
36
|
+
success: true;
|
|
37
|
+
intermediates: TileCacheGeneratorIntermediates;
|
|
38
|
+
};
|
|
39
|
+
type TileCacheGeneratorFailResult = {
|
|
40
|
+
tileCache: undefined;
|
|
41
|
+
navMesh: undefined;
|
|
42
|
+
success: false;
|
|
43
|
+
error: string;
|
|
44
|
+
intermediates: TileCacheGeneratorIntermediates;
|
|
45
|
+
};
|
|
46
|
+
export type TileCacheGeneratorResult = TileCacheGeneratorSuccessResult | TileCacheGeneratorFailResult;
|
|
47
|
+
export declare const createDefaultTileCacheMeshProcess: () => TileCacheMeshProcess;
|
|
48
|
+
/**
|
|
49
|
+
* Builds a TileCache and NavMesh from the given positions and indices.
|
|
50
|
+
* TileCache assumes small tiles (around 32-64 squared) and does some tricks to make the update fast.
|
|
51
|
+
* @param positions a flat array of positions
|
|
52
|
+
* @param indices a flat array of indices
|
|
53
|
+
* @param navMeshConfig optional configuration for the NavMesh
|
|
54
|
+
* @param keepIntermediates if true intermediates will be returned
|
|
55
|
+
*/
|
|
56
|
+
export declare const generateTileCache: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TileCacheGeneratorConfig>, keepIntermediates?: boolean) => TileCacheGeneratorResult;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NavMesh, RecastBuildContext, RecastChunkyTriMesh, RecastCompactHeightfield, RecastConfigType, RecastContourSet, RecastHeightfield } from '@recast-navigation/core';
|
|
2
|
+
import { Pretty } from '../types';
|
|
3
|
+
import { OffMeshConnectionGeneratorParams } from './common';
|
|
4
|
+
export type TiledNavMeshGeneratorConfig = Pretty<RecastConfigType & OffMeshConnectionGeneratorParams>;
|
|
5
|
+
export declare const tiledNavMeshGeneratorConfigDefaults: TiledNavMeshGeneratorConfig;
|
|
6
|
+
export type TiledNavMeshGeneratorIntermediates = {
|
|
7
|
+
type: 'tiled';
|
|
8
|
+
buildContext: RecastBuildContext;
|
|
9
|
+
chunkyTriMesh?: RecastChunkyTriMesh;
|
|
10
|
+
tileIntermediates: {
|
|
11
|
+
tileX: number;
|
|
12
|
+
tileY: number;
|
|
13
|
+
heightfield?: RecastHeightfield;
|
|
14
|
+
compactHeightfield?: RecastCompactHeightfield;
|
|
15
|
+
contourSet?: RecastContourSet;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
type TiledNavMeshGeneratorSuccessResult = {
|
|
19
|
+
navMesh: NavMesh;
|
|
20
|
+
success: true;
|
|
21
|
+
intermediates: TiledNavMeshGeneratorIntermediates;
|
|
22
|
+
};
|
|
23
|
+
type TiledNavMeshGeneratorFailResult = {
|
|
24
|
+
navMesh: undefined;
|
|
25
|
+
success: false;
|
|
26
|
+
intermediates: TiledNavMeshGeneratorIntermediates;
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
export type TiledNavMeshGeneratorResult = TiledNavMeshGeneratorSuccessResult | TiledNavMeshGeneratorFailResult;
|
|
30
|
+
/**
|
|
31
|
+
* Builds a Tiled NavMesh
|
|
32
|
+
* @param positions a flat array of positions
|
|
33
|
+
* @param indices a flat array of indices
|
|
34
|
+
* @param navMeshGeneratorConfig optional configuration for the NavMesh generator
|
|
35
|
+
* @param keepIntermediates if true intermediates will be returned
|
|
36
|
+
*/
|
|
37
|
+
export declare const generateTiledNavMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TiledNavMeshGeneratorConfig>, keepIntermediates?: boolean) => TiledNavMeshGeneratorResult;
|
|
38
|
+
export {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +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),{raw:R}=e.RecastConfig.create({...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},{raw:H}=e.RecastConfig.create(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,{raw:r}=new e.RecastConfig(H).clone(),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.RecastConfig.create({...o,...s}),{raw:u}=m,{bbMin:b,bbMax:w}=t(l,r),C=e.calcGridSize(b,w,u.cs);u.width=C.width,u.height=C.height,u.minRegionArea=u.minRegionArea*u.minRegionArea,u.mergeRegionArea=u.mergeRegionArea*u.mergeRegionArea,u.tileSize=Math.floor(u.tileSize),u.borderSize=u.walkableRadius+3,u.width=u.tileSize+2*u.borderSize,u.height=u.tileSize+2*u.borderSize,u.detailSampleDist=u.detailSampleDist<.9?0:u.cs*u.detailSampleDist,u.detailSampleMaxError=u.ch*u.detailSampleMaxError;const R=Math.floor(u.tileSize),S=Math.floor((C.width+R-1)/R),y=Math.floor((C.height+R-1)/R),M=u.tileSize*u.cs,p=l,x=r.length,A=new e.Arrays.FloatArray;A.copy(p,p.length);const k=r,H=r.length/3,v=new e.Arrays.IntArray;v.copy(k,k.length);const T=e.vec3.fromArray(b);let z=Math.min(Math.floor(i(a(S*y))),14);z>14&&(z=14);const _=1<<z,L=1<<22-z,D=e.NavMeshParams.create({orig:T,tileWidth:u.tileSize*u.cs,tileHeight:u.tileSize*u.cs,maxTiles:_,maxPolys:L});if(!c.initTiled(D))return f("Could not init nav mesh for tiled use");const E=new e.RecastChunkyTriMesh;if(h.chunkyTriMesh=E,!E.init(A,v,H,256))return f("Failed to build chunky triangle mesh");const P=(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{raw:c}=m.clone(),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,` - ${u.width} x ${u.height} cells`),d.log(e.Raw.Module.RC_LOG_PROGRESS,` - ${x/1e3}fK verts, ${H/1e3}K tris`);const b=e.allocHeightfield();if(o.heightfield=b,!e.createHeightfield(d,b,c.width,c.height,g,f,c.cs,c.ch))return r("Could not create heightfield");(new e.Arrays.UnsignedCharArray).resize(E.maxTrisPerChunk());const w=[g[0],g[2]],C=[f[0],f[2]],R=new e.Arrays.IntArray;R.resize(512);const S=E.getChunksOverlappingRect(w,C,R,512);if(0===S)return{success:!0};for(let t=0;t<S;++t){const i=R.get_data(t),a=E.nodes(i).n,l=E.getNodeTris(i),s=new e.Arrays.UnsignedCharArray;s.resize(a),e.markWalkableTriangles(d,c.walkableSlopeAngle,A,x,l,a,s);const o=e.rasterizeTriangles(d,A,x,l,s,a,b,c.walkableClimb);if(s.free(),!o)return r("Could not rasterize triangles")}e.filterLowHangingWalkableObstacles(d,c.walkableClimb,b),e.filterLedgeSpans(d,c.walkableHeight,c.walkableClimb,b),e.filterWalkableLowHeightSpans(d,c.walkableHeight,b);const y=e.allocCompactHeightfield();if(o.compactHeightfield=y,!e.buildCompactHeightfield(d,c.walkableHeight,c.walkableClimb,b,y))return r("Could not build compact heightfield");if(n||(e.freeHeightfield(o.heightfield),o.heightfield=void 0),!e.erodeWalkableArea(d,c.walkableRadius,y))return r("Could not erode walkable area");if(!e.buildDistanceField(d,y))return r("Failed to build distance field");if(!e.buildRegions(d,y,c.borderSize,c.minRegionArea,c.mergeRegionArea))return r("Failed to build regions");const M=e.allocContourSet();if(o.contourSet=M,!e.buildContours(d,y,c.maxSimplificationError,c.maxEdgeLen,M,e.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const p=e.allocPolyMesh();if(!e.buildPolyMesh(d,M,c.maxVertsPerPoly,p))return r("Failed to triangulate contours");const k=e.allocPolyMeshDetail();if(!e.buildPolyMeshDetail(d,p,y,c.detailSampleDist,c.detailSampleMaxError,k))return r("Failed to build detail mesh");n||(e.freeCompactHeightfield(y),o.compactHeightfield=void 0,e.freeContourSet(M),o.contourSet=void 0);for(let t=0;t<p.npolys();t++)p.areas(t)==e.Raw.Recast.WALKABLE_AREA&&p.setAreas(t,0),0==p.areas(t)&&p.setFlags(t,1);const v=new e.NavMeshCreateParams;v.setPolyMeshCreateParams(p),v.setPolyMeshDetailCreateParams(k),v.setWalkableHeight(c.walkableHeight),v.setWalkableRadius(c.walkableRadius),v.setWalkableClimb(c.walkableClimb),v.setCellSize(c.cs),v.setCellHeight(c.ch),v.setBuildBvTree(!0),s.offMeshConnections&&v.setOffMeshConnections(s.offMeshConnections),v.setTileX(t),v.setTileY(i);const T=e.createNavMeshData(v);return T.success?(d.log(e.Raw.Module.RC_LOG_PROGRESS,`>> Polymesh: ${p.nverts()} vertices ${p.npolys()} polygons`),{success:!0,data:T.navMeshData}):r("Failed to create Detour navmesh data")};d.startTimer(e.Raw.Module.RC_TIMER_TEMP);let F=[0,0,0],N=[0,0,0];for(let t=0;t<y;t++)for(let i=0;i<S;i++){F[0]=b[0]+i*M,F[1]=b[1],F[2]=b[2]+t*M,N[0]=b[0]+(i+1)*M,N[1]=w[1],N[2]=b[2]+(t+1)*M;const a=P(i,t,F,N);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
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/generators/common.ts","../src/generators/generate-solo-nav-mesh.ts","../src/generators/generate-tile-cache.ts","../src/generators/generate-tiled-nav-mesh.ts"],"sourcesContent":["import { OffMeshConnectionParams, vec3 } from '@recast-navigation/core';\n\nexport const getBoundingBox = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>\n) => {\n const bbMin = { x: Infinity, y: Infinity, z: Infinity };\n const bbMax = { x: -Infinity, y: -Infinity, z: -Infinity };\n\n for (let i = 0; i < indices.length; i++) {\n const ind = indices[i];\n\n const x = positions[ind * 3];\n const y = positions[ind * 3 + 1];\n const z = positions[ind * 3 + 2];\n\n bbMin.x = Math.min(bbMin.x, x);\n bbMin.y = Math.min(bbMin.y, y);\n bbMin.z = Math.min(bbMin.z, z);\n\n bbMax.x = Math.max(bbMax.x, x);\n bbMax.y = Math.max(bbMax.y, y);\n bbMax.z = Math.max(bbMax.z, z);\n }\n\n return {\n bbMin: vec3.toArray(bbMin),\n bbMax: vec3.toArray(bbMax),\n };\n};\n\nexport const dtIlog2 = (v: number) => {\n let r = 0;\n let shift = 0;\n\n r = Number(v > 0xffff) << 4;\n v >>= r;\n\n shift = Number(v > 0xff) << 3;\n v >>= shift;\n r |= shift;\n\n shift = Number(v > 0xf) << 2;\n v >>= shift;\n r |= shift;\n\n shift = Number(v > 0x3) << 1;\n v >>= shift;\n r |= shift;\n r |= v >> 1;\n\n return r;\n};\n\nexport const dtNextPow2 = (v: number) => {\n v--;\n v |= v >> 1;\n v |= v >> 2;\n v |= v >> 4;\n v |= v >> 8;\n v |= v >> 16;\n v++;\n return v;\n};\n\nexport type OffMeshConnectionGeneratorParams = {\n offMeshConnections?: OffMeshConnectionParams[];\n};\n","import {\n Arrays,\n NavMesh,\n NavMeshCreateParams,\n Raw,\n RecastBuildContext,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastContourSet,\n RecastHeightfield,\n allocCompactHeightfield,\n allocContourSet,\n allocHeightfield,\n allocPolyMesh,\n allocPolyMeshDetail,\n buildCompactHeightfield,\n buildContours,\n buildDistanceField,\n buildPolyMesh,\n buildPolyMeshDetail,\n buildRegions,\n createHeightfield,\n createNavMeshData,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeContourSet,\n freeHeightfield,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n} from '@recast-navigation/core';\nimport { Pretty } from '../types';\nimport { OffMeshConnectionGeneratorParams, getBoundingBox } from './common';\n\nexport type SoloNavMeshGeneratorConfig = Pretty<\n Omit<RecastConfigType, 'tileSize'> & OffMeshConnectionGeneratorParams\n>;\n\nexport const soloNavMeshGeneratorConfigDefaults: SoloNavMeshGeneratorConfig = {\n ...recastConfigDefaults,\n};\n\nexport type SoloNavMeshGeneratorIntermediates = {\n type: 'solo';\n buildContext: RecastBuildContext;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n};\n\ntype SoloNavMeshGeneratorSuccessResult = {\n navMesh: NavMesh;\n success: true;\n intermediates: SoloNavMeshGeneratorIntermediates;\n};\n\ntype SoloNavMeshGeneratorFailResult = {\n navMesh: undefined;\n success: false;\n intermediates: SoloNavMeshGeneratorIntermediates;\n error: string;\n};\n\nexport type SoloNavMeshGeneratorResult =\n | SoloNavMeshGeneratorSuccessResult\n | SoloNavMeshGeneratorFailResult;\n\n/**\n * Builds a Solo NavMesh from the given positions and indices.\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshGeneratorConfig optional configuration for the NavMesh generator\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateSoloNavMesh = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<SoloNavMeshGeneratorConfig> = {},\n keepIntermediates = false\n): SoloNavMeshGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n const intermediates: SoloNavMeshGeneratorIntermediates = {\n type: 'solo',\n buildContext,\n };\n\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (keepIntermediates) return;\n\n if (intermediates.heightfield) {\n freeHeightfield(intermediates.heightfield);\n intermediates.heightfield = undefined;\n }\n if (intermediates.compactHeightfield) {\n freeCompactHeightfield(intermediates.compactHeightfield);\n intermediates.compactHeightfield = undefined;\n }\n if (intermediates.contourSet) {\n freeContourSet(intermediates.contourSet);\n intermediates.contourSet = undefined;\n }\n };\n\n const fail = (error: string): SoloNavMeshGeneratorFailResult => {\n cleanup();\n\n navMesh.destroy();\n\n return {\n navMesh: undefined,\n success: false,\n intermediates,\n error,\n };\n };\n\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n //\n // Step 1. Initialize build config.\n //\n const { raw: config } = RecastConfig.create({\n ...soloNavMeshGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n });\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n const gridSize = Raw.Recast.calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n //\n // Step 2. Rasterize input polygon soup.\n //\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n intermediates.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n config.width,\n config.height,\n bbMin,\n bbMax,\n config.cs,\n config.ch\n )\n ) {\n return fail('Could not create heightfield');\n }\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nTris);\n\n markWalkableTriangles(\n buildContext,\n config.walkableSlopeAngle,\n vertsArray,\n nVerts,\n trisArray,\n nTris,\n triAreasArray\n );\n\n if (\n !rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n trisArray,\n triAreasArray,\n nTris,\n heightfield,\n config.walkableClimb\n )\n ) {\n return fail('Could not rasterize triangles');\n }\n\n triAreasArray.free();\n\n //\n // Step 3. Filter walkables surfaces.\n //\n // Once all geoemtry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n config.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n config.walkableHeight,\n heightfield\n );\n\n //\n // Step 4. Partition walkable surface to simple regions.\n //\n // Compact the heightfield so that it is faster to handle from now on.\n // This will result more cache coherent data as well as the neighbours\n // between walkable cells will be calculated.\n const compactHeightfield = allocCompactHeightfield();\n intermediates.compactHeightfield = compactHeightfield;\n\n if (\n !buildCompactHeightfield(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return fail('Failed to build compact data');\n }\n\n if (!keepIntermediates) {\n freeHeightfield(heightfield);\n intermediates.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius.\n if (\n !erodeWalkableArea(buildContext, config.walkableRadius, compactHeightfield)\n ) {\n return fail('Failed to erode walkable area');\n }\n\n // (Optional) Mark areas\n // markConvexPolyArea(...)\n\n // Prepare for region partitioning, by calculating Distance field along the walkable surface.\n if (!buildDistanceField(buildContext, compactHeightfield)) {\n return fail('Failed to build distance field');\n }\n\n // Partition the walkable surface into simple regions without holes.\n if (\n !buildRegions(\n buildContext,\n compactHeightfield,\n config.borderSize,\n config.minRegionArea,\n config.mergeRegionArea\n )\n ) {\n return fail('Failed to build regions');\n }\n\n //\n // Step 5. Trace and simplify region contours.\n //\n const contourSet = allocContourSet();\n intermediates.contourSet = contourSet;\n\n if (\n !buildContours(\n buildContext,\n compactHeightfield,\n config.maxSimplificationError,\n config.maxEdgeLen,\n contourSet,\n Raw.Module.RC_CONTOUR_TESS_WALL_EDGES\n )\n ) {\n return fail('Failed to create contours');\n }\n\n //\n // Step 6. Build polygons mesh from contours.\n //\n const polyMesh = allocPolyMesh();\n if (\n !buildPolyMesh(buildContext, contourSet, config.maxVertsPerPoly, polyMesh)\n ) {\n return fail('Failed to triangulate contours');\n }\n\n //\n // Step 7. Create detail mesh which allows to access approximate height on each polygon.\n //\n const polyMeshDetail = allocPolyMeshDetail();\n if (\n !buildPolyMeshDetail(\n buildContext,\n polyMesh,\n compactHeightfield,\n config.detailSampleDist,\n config.detailSampleMaxError,\n polyMeshDetail\n )\n ) {\n return fail('Failed to build detail mesh');\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n intermediates.compactHeightfield = undefined;\n\n freeContourSet(contourSet);\n intermediates.contourSet = undefined;\n }\n\n //\n // Step 8. Create Detour data from Recast poly mesh.\n //\n for (let i = 0; i < polyMesh.npolys(); i++) {\n if (polyMesh.areas(i) == Raw.Recast.WALKABLE_AREA) {\n polyMesh.setAreas(i, 0);\n }\n if (polyMesh.areas(i) == 0) {\n polyMesh.setFlags(i, 1);\n }\n }\n\n const navMeshCreateParams = new NavMeshCreateParams();\n\n navMeshCreateParams.setPolyMeshCreateParams(polyMesh);\n navMeshCreateParams.setPolyMeshDetailCreateParams(polyMeshDetail);\n\n navMeshCreateParams.setWalkableHeight(config.walkableHeight);\n navMeshCreateParams.setWalkableRadius(config.walkableRadius);\n navMeshCreateParams.setWalkableClimb(config.walkableClimb);\n\n navMeshCreateParams.setCellSize(config.cs);\n navMeshCreateParams.setCellHeight(config.ch);\n\n navMeshCreateParams.setBuildBvTree(true);\n\n if (navMeshGeneratorConfig.offMeshConnections) {\n navMeshCreateParams.setOffMeshConnections(\n navMeshGeneratorConfig.offMeshConnections\n );\n }\n\n const createNavMeshDataResult = createNavMeshData(navMeshCreateParams);\n\n if (!createNavMeshDataResult.success) {\n return fail('Failed to create Detour navmesh data');\n }\n\n const { navMeshData } = createNavMeshDataResult;\n\n if (!navMesh.initSolo(navMeshData)) {\n return fail('Failed to create Detour navmesh');\n }\n\n return {\n success: true,\n navMesh,\n intermediates,\n };\n};\n","import {\n Arrays,\n DetourTileCacheParams,\n NavMesh,\n NavMeshParams,\n Raw,\n RecastBuildContext,\n RecastChunkyTriMesh,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastHeightfield,\n RecastHeightfieldLayerSet,\n TileCache,\n TileCacheMeshProcess,\n Vector2Tuple,\n Vector3Tuple,\n allocCompactHeightfield,\n allocHeightfield,\n allocHeightfieldLayerSet,\n buildCompactHeightfield,\n buildHeightfieldLayers,\n buildTileCacheLayer,\n calcGridSize,\n createHeightfield,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeHeightfield,\n freeHeightfieldLayerSet,\n getHeightfieldLayerAreas,\n getHeightfieldLayerCons,\n getHeightfieldLayerHeights,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n vec3,\n} from '@recast-navigation/core';\nimport type R from '@recast-navigation/wasm';\nimport { Pretty } from '../types';\nimport { dtIlog2, dtNextPow2, getBoundingBox } from './common';\n\nexport type TileCacheGeneratorConfig = Pretty<\n RecastConfigType & {\n /**\n * How many layers (or \"floors\") each navmesh tile is expected to have.\n */\n expectedLayersPerTile: number;\n\n /**\n * The max number of obstacles\n */\n maxObstacles: number;\n\n /**\n * The tile cache mesh process implementation.\n * If not provided, a default one is created via `createDefaultTileCacheMeshProcess()`\n * @default createDefaultTileCacheMeshProcess()\n */\n tileCacheMeshProcess?: TileCacheMeshProcess;\n }\n>;\n\nexport const tileCacheGeneratorConfigDefaults: TileCacheGeneratorConfig = {\n ...recastConfigDefaults,\n tileSize: 32,\n expectedLayersPerTile: 4,\n maxObstacles: 128,\n};\n\nexport type TileCacheGeneratorTileIntermediates = {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n heightfieldLayerSet?: RecastHeightfieldLayerSet;\n};\n\nexport type TileCacheGeneratorIntermediates = {\n type: 'tilecache';\n buildContext: RecastBuildContext;\n chunkyTriMesh?: RecastChunkyTriMesh;\n tileIntermediates: TileCacheGeneratorTileIntermediates[];\n};\n\ntype TileCacheGeneratorSuccessResult = {\n tileCache: TileCache;\n navMesh: NavMesh;\n success: true;\n intermediates: TileCacheGeneratorIntermediates;\n};\n\ntype TileCacheGeneratorFailResult = {\n tileCache: undefined;\n navMesh: undefined;\n success: false;\n error: string;\n intermediates: TileCacheGeneratorIntermediates;\n};\n\nexport type TileCacheGeneratorResult =\n | TileCacheGeneratorSuccessResult\n | TileCacheGeneratorFailResult;\n\nexport const createDefaultTileCacheMeshProcess = () =>\n new TileCacheMeshProcess((navMeshCreateParams, polyAreas, polyFlags) => {\n for (let i = 0; i < navMeshCreateParams.polyCount(); ++i) {\n polyAreas.set(i, 0);\n polyFlags.set(i, 1);\n }\n });\n\n/**\n * Builds a TileCache and NavMesh from the given positions and indices.\n * TileCache assumes small tiles (around 32-64 squared) and does some tricks to make the update fast.\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshConfig optional configuration for the NavMesh\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateTileCache = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<TileCacheGeneratorConfig> = {},\n keepIntermediates = false\n): TileCacheGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n let intermediates: TileCacheGeneratorIntermediates = {\n type: 'tilecache',\n buildContext,\n chunkyTriMesh: undefined,\n tileIntermediates: [],\n };\n\n const tileCache = new TileCache();\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (!keepIntermediates) {\n for (let i = 0; i < intermediates.tileIntermediates.length; i++) {\n const tileIntermediate = intermediates.tileIntermediates[i];\n\n if (tileIntermediate.heightfield) {\n freeHeightfield(tileIntermediate.heightfield);\n tileIntermediate.heightfield = undefined;\n }\n\n if (tileIntermediate.compactHeightfield) {\n freeCompactHeightfield(tileIntermediate.compactHeightfield);\n tileIntermediate.compactHeightfield = undefined;\n }\n\n if (tileIntermediate.heightfieldLayerSet) {\n freeHeightfieldLayerSet(tileIntermediate.heightfieldLayerSet);\n tileIntermediate.heightfieldLayerSet = undefined;\n }\n }\n }\n };\n\n const fail = (error: string): TileCacheGeneratorFailResult => {\n cleanup();\n\n tileCache.destroy();\n navMesh.destroy();\n\n return {\n success: false,\n navMesh: undefined,\n tileCache: undefined,\n intermediates,\n error,\n };\n };\n\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n const { expectedLayersPerTile, maxObstacles, ...recastConfig } = {\n ...tileCacheGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n };\n\n //\n // Step 1. Initialize build config.\n //\n const { raw: config } = RecastConfig.create(recastConfig);\n\n const gridSize = calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n const tileSize = Math.floor(config.tileSize);\n const tileWidth = Math.floor((config.width + tileSize - 1) / tileSize);\n const tileHeight = Math.floor((config.height + tileSize - 1) / tileSize);\n\n // Generation params\n config.borderSize = config.walkableRadius + 3; // Reserve enough padding.\n config.width = config.tileSize + config.borderSize * 2;\n config.height = config.tileSize + config.borderSize * 2;\n\n // Tile cache params\n const tileCacheParams = DetourTileCacheParams.create({\n orig: bbMin,\n cs: config.cs,\n ch: config.ch,\n width: config.tileSize,\n height: config.tileSize,\n walkableHeight: config.walkableHeight,\n walkableRadius: config.walkableRadius,\n walkableClimb: config.walkableClimb,\n maxSimplificationError: config.maxSimplificationError,\n maxTiles: tileWidth * tileHeight * expectedLayersPerTile,\n maxObstacles,\n });\n\n const allocator = new Raw.RecastLinearAllocator(32000);\n const compressor = new Raw.RecastFastLZCompressor();\n\n const tileCacheMeshProcess =\n navMeshGeneratorConfig.tileCacheMeshProcess ??\n createDefaultTileCacheMeshProcess();\n\n if (\n !tileCache.init(\n tileCacheParams,\n allocator,\n compressor,\n tileCacheMeshProcess\n )\n ) {\n return fail('Failed to initialize tile cache');\n }\n\n const orig = vec3.fromArray(bbMin);\n\n // Max tiles and max polys affect how the tile IDs are caculated.\n // There are 22 bits available for identifying a tile and a polygon.\n let tileBits = Math.min(\n Math.floor(\n dtIlog2(dtNextPow2(tileWidth * tileHeight * expectedLayersPerTile))\n ),\n 14\n );\n if (tileBits > 14) {\n tileBits = 14;\n }\n const polyBits = 22 - tileBits;\n\n const maxTiles = 1 << tileBits;\n const maxPolysPerTile = 1 << polyBits;\n\n const navMeshParams = NavMeshParams.create({\n orig,\n tileWidth: config.tileSize * config.cs,\n tileHeight: config.tileSize * config.cs,\n maxTiles,\n maxPolys: maxPolysPerTile,\n });\n\n if (!navMesh.initTiled(navMeshParams)) {\n return fail('Failed to initialize tiled navmesh');\n }\n\n const chunkyTriMesh = new RecastChunkyTriMesh();\n intermediates.chunkyTriMesh = chunkyTriMesh;\n\n if (!chunkyTriMesh.init(vertsArray, trisArray, nTris, 256)) {\n return fail('Failed to build chunky triangle mesh');\n }\n\n const rasterizeTileLayers = (tileX: number, tileY: number) => {\n // Tile intermediates\n const tileIntermediates: TileCacheGeneratorTileIntermediates = {\n tileX,\n tileY,\n };\n\n // Tile bounds\n const tcs = config.tileSize * config.cs;\n\n const { raw: tileConfig } = new RecastConfig(config).clone();\n\n const tileBoundsMin: Vector3Tuple = [\n bbMin[0] + tileX * tcs,\n bbMin[1],\n bbMin[2] + tileY * tcs,\n ];\n\n const tileBoundsMax: Vector3Tuple = [\n bbMin[0] + (tileX + 1) * tcs,\n bbMax[1],\n bbMin[2] + (tileY + 1) * tcs,\n ];\n\n tileBoundsMin[0] -= tileConfig.borderSize * tileConfig.cs;\n tileBoundsMin[2] -= tileConfig.borderSize * tileConfig.cs;\n tileBoundsMax[0] += tileConfig.borderSize * tileConfig.cs;\n tileBoundsMax[2] += tileConfig.borderSize * tileConfig.cs;\n\n tileConfig.set_bmin(0, tileBoundsMin[0]);\n tileConfig.set_bmin(1, tileBoundsMin[1]);\n tileConfig.set_bmin(2, tileBoundsMin[2]);\n\n tileConfig.set_bmax(0, tileBoundsMax[0]);\n tileConfig.set_bmax(1, tileBoundsMax[1]);\n tileConfig.set_bmax(2, tileBoundsMax[2]);\n\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n tileIntermediates.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n tileConfig.width,\n tileConfig.height,\n tileBoundsMin,\n tileBoundsMax,\n tileConfig.cs,\n tileConfig.ch\n )\n ) {\n return { n: 0 };\n }\n\n const tbmin: Vector2Tuple = [tileBoundsMin[0], tileBoundsMin[2]];\n const tbmax: Vector2Tuple = [tileBoundsMax[0], tileBoundsMax[2]];\n\n // TODO: Make grow when returning too many items.\n const maxChunkIds = 512;\n const chunkIdsArray = new Arrays.IntArray();\n chunkIdsArray.resize(maxChunkIds);\n\n const nChunksOverlapping = chunkyTriMesh.getChunksOverlappingRect(\n tbmin,\n tbmax,\n chunkIdsArray,\n maxChunkIds\n );\n\n if (nChunksOverlapping === 0) {\n return { n: 0 };\n }\n\n for (let i = 0; i < nChunksOverlapping; ++i) {\n const nodeId = chunkIdsArray.get_data(i);\n const node = chunkyTriMesh.nodes(nodeId);\n const nNodeTris = node.n;\n\n const nodeTrisArray = chunkyTriMesh.getNodeTris(nodeId);\n\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nNodeTris);\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n markWalkableTriangles(\n buildContext,\n tileConfig.walkableSlopeAngle,\n vertsArray,\n nVerts,\n nodeTrisArray,\n nNodeTris,\n triAreasArray\n );\n\n const success = rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n nodeTrisArray,\n triAreasArray,\n nNodeTris,\n heightfield,\n tileConfig.walkableClimb\n );\n\n triAreasArray.free();\n\n if (!success) {\n return { n: 0 };\n }\n }\n\n // Once all geometry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n config.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n config.walkableHeight,\n heightfield\n );\n\n const compactHeightfield = allocCompactHeightfield();\n if (\n !buildCompactHeightfield(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return { n: 0 };\n }\n\n if (!keepIntermediates) {\n freeHeightfield(tileIntermediates.heightfield);\n tileIntermediates.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius\n if (\n !erodeWalkableArea(\n buildContext,\n config.walkableRadius,\n compactHeightfield\n )\n ) {\n return { n: 0 };\n }\n\n const heightfieldLayerSet = allocHeightfieldLayerSet();\n if (\n !buildHeightfieldLayers(\n buildContext,\n compactHeightfield,\n config.borderSize,\n config.walkableHeight,\n heightfieldLayerSet\n )\n ) {\n return { n: 0 };\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n tileIntermediates.compactHeightfield = undefined;\n }\n\n const tiles: R.UnsignedCharArray[] = [];\n\n for (let i = 0; i < heightfieldLayerSet.nlayers(); i++) {\n const tile = new Arrays.UnsignedCharArray();\n const heightfieldLayer = heightfieldLayerSet.layers(i);\n\n // Store header\n const header = new Raw.dtTileCacheLayerHeader();\n header.magic = Raw.Detour.TILECACHE_MAGIC;\n header.version = Raw.Detour.TILECACHE_VERSION;\n\n // Tile layer location in the navmesh\n header.tx = tileX;\n header.ty = tileY;\n header.tlayer = i;\n\n const heightfieldLayerBin = heightfieldLayer.bmin();\n const heightfieldLayerBmax = heightfieldLayer.bmax();\n header.set_bmin(0, heightfieldLayerBin.x);\n header.set_bmin(1, heightfieldLayerBin.y);\n header.set_bmin(2, heightfieldLayerBin.z);\n\n header.set_bmax(0, heightfieldLayerBmax.x);\n header.set_bmax(1, heightfieldLayerBmax.y);\n header.set_bmax(2, heightfieldLayerBmax.z);\n\n // Tile info\n header.width = heightfieldLayer.width();\n header.height = heightfieldLayer.height();\n header.minx = heightfieldLayer.minx();\n header.maxx = heightfieldLayer.maxx();\n header.miny = heightfieldLayer.miny();\n header.maxy = heightfieldLayer.maxy();\n header.hmin = heightfieldLayer.hmin();\n header.hmax = heightfieldLayer.hmax();\n\n const heights = getHeightfieldLayerHeights(heightfieldLayer);\n const areas = getHeightfieldLayerAreas(heightfieldLayer);\n const cons = getHeightfieldLayerCons(heightfieldLayer);\n\n const status = buildTileCacheLayer(\n compressor,\n header,\n heights,\n areas,\n cons,\n tile\n );\n\n if (Raw.Detour.statusFailed(status)) {\n return { n: 0 };\n }\n\n tiles.push(tile);\n }\n\n if (!keepIntermediates) {\n freeHeightfieldLayerSet(heightfieldLayerSet);\n tileIntermediates.heightfieldLayerSet = undefined;\n }\n\n intermediates.tileIntermediates.push(tileIntermediates);\n\n return { n: tiles.length, tiles };\n };\n\n // Preprocess tiles\n for (let y = 0; y < tileHeight; ++y) {\n for (let x = 0; x < tileWidth; ++x) {\n const { n, tiles: newTiles } = rasterizeTileLayers(x, y);\n\n if (n > 0 && newTiles) {\n for (let i = 0; i < n; i++) {\n const tileCacheData = newTiles[i];\n\n const addResult = tileCache.addTile(tileCacheData);\n\n if (Raw.Detour.statusFailed(addResult.status)) {\n buildContext.log(\n Raw.Module.RC_LOG_WARNING,\n `Failed to add tile to tile cache - tx: ${x}, ty: ${y}`\n );\n continue;\n }\n }\n }\n }\n }\n\n // Build initial meshes\n for (let y = 0; y < tileHeight; y++) {\n for (let x = 0; x < tileWidth; x++) {\n const dtStatus = tileCache.buildNavMeshTilesAt(x, y, navMesh);\n\n if (Raw.Detour.statusFailed(dtStatus)) {\n return fail(`Failed to build nav mesh tiles at ${x}, ${y}`);\n }\n }\n }\n\n cleanup();\n\n return {\n success: true,\n tileCache,\n navMesh,\n intermediates,\n };\n};\n","import {\n Arrays,\n NavMesh,\n NavMeshCreateParams,\n NavMeshParams,\n Raw,\n RecastBuildContext,\n RecastChunkyTriMesh,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastContourSet,\n RecastHeightfield,\n Vector2Tuple,\n Vector3Tuple,\n allocCompactHeightfield,\n allocContourSet,\n allocHeightfield,\n allocPolyMesh,\n allocPolyMeshDetail,\n buildCompactHeightfield,\n buildContours,\n buildDistanceField,\n buildPolyMesh,\n buildPolyMeshDetail,\n buildRegions,\n calcGridSize,\n createHeightfield,\n createNavMeshData,\n dtStatusToReadableString,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeContourSet,\n freeHeightfield,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n vec3,\n} from '@recast-navigation/core';\nimport type R from '@recast-navigation/wasm';\nimport { Pretty } from '../types';\nimport {\n OffMeshConnectionGeneratorParams,\n dtIlog2,\n dtNextPow2,\n getBoundingBox,\n} from './common';\n\nexport type TiledNavMeshGeneratorConfig = Pretty<\n RecastConfigType & OffMeshConnectionGeneratorParams\n>;\n\nexport const tiledNavMeshGeneratorConfigDefaults: TiledNavMeshGeneratorConfig =\n {\n ...recastConfigDefaults,\n };\n\nexport type TiledNavMeshGeneratorIntermediates = {\n type: 'tiled';\n buildContext: RecastBuildContext;\n chunkyTriMesh?: RecastChunkyTriMesh;\n tileIntermediates: {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n }[];\n};\n\ntype TiledNavMeshGeneratorSuccessResult = {\n navMesh: NavMesh;\n success: true;\n intermediates: TiledNavMeshGeneratorIntermediates;\n};\n\ntype TiledNavMeshGeneratorFailResult = {\n navMesh: undefined;\n success: false;\n intermediates: TiledNavMeshGeneratorIntermediates;\n error: string;\n};\n\nexport type TiledNavMeshGeneratorResult =\n | TiledNavMeshGeneratorSuccessResult\n | TiledNavMeshGeneratorFailResult;\n\n/**\n * Builds a Tiled NavMesh\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshGeneratorConfig optional configuration for the NavMesh generator\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateTiledNavMesh = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<TiledNavMeshGeneratorConfig> = {},\n keepIntermediates = false\n): TiledNavMeshGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n const intermediates: TiledNavMeshGeneratorIntermediates = {\n type: 'tiled',\n buildContext,\n chunkyTriMesh: undefined,\n tileIntermediates: [],\n };\n\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (keepIntermediates) return;\n\n for (let i = 0; i < intermediates.tileIntermediates.length; i++) {\n const tileIntermediate = intermediates.tileIntermediates[i];\n\n if (tileIntermediate.compactHeightfield) {\n freeCompactHeightfield(tileIntermediate.compactHeightfield);\n }\n\n if (tileIntermediate.heightfield) {\n freeHeightfield(tileIntermediate.heightfield);\n }\n\n if (tileIntermediate.contourSet) {\n freeContourSet(tileIntermediate.contourSet);\n }\n }\n\n if (intermediates.chunkyTriMesh) {\n intermediates.chunkyTriMesh = undefined;\n }\n };\n\n const fail = (error: string): TiledNavMeshGeneratorFailResult => {\n cleanup();\n\n navMesh.destroy();\n\n return {\n success: false,\n navMesh: undefined,\n intermediates,\n error,\n };\n };\n\n //\n // Initialize build config.\n //\n const recastConfig = RecastConfig.create({\n ...tiledNavMeshGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n });\n const { raw: config } = recastConfig;\n\n /* get input bounding box */\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n /* grid size */\n const gridSize = calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.tileSize = Math.floor(config.tileSize);\n config.borderSize = config.walkableRadius + 3; // Reserve enough padding.\n config.width = config.tileSize + config.borderSize * 2;\n config.height = config.tileSize + config.borderSize * 2;\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n // tile size\n const tileSize = Math.floor(config.tileSize);\n const tileWidth = Math.floor((gridSize.width + tileSize - 1) / tileSize);\n const tileHeight = Math.floor((gridSize.height + tileSize - 1) / tileSize);\n const tcs = config.tileSize * config.cs;\n\n /* verts */\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n /* tris */\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n /* Create dtNavMeshParams, initialise nav mesh for tiled use */\n const orig = vec3.fromArray(bbMin);\n\n // Max tiles and max polys affect how the tile IDs are caculated.\n // There are 22 bits available for identifying a tile and a polygon.\n let tileBits = Math.min(\n Math.floor(dtIlog2(dtNextPow2(tileWidth * tileHeight))),\n 14\n );\n if (tileBits > 14) tileBits = 14;\n const polyBits = 22 - tileBits;\n\n const maxTiles = 1 << tileBits;\n const maxPolysPerTile = 1 << polyBits;\n\n const navMeshParams = NavMeshParams.create({\n orig,\n tileWidth: config.tileSize * config.cs,\n tileHeight: config.tileSize * config.cs,\n maxTiles,\n maxPolys: maxPolysPerTile,\n });\n\n if (!navMesh.initTiled(navMeshParams)) {\n return fail('Could not init nav mesh for tiled use');\n }\n\n /* create chunky tri mesh */\n const chunkyTriMesh = new RecastChunkyTriMesh();\n intermediates.chunkyTriMesh = chunkyTriMesh;\n\n if (!chunkyTriMesh.init(vertsArray, trisArray, nTris, 256)) {\n return fail('Failed to build chunky triangle mesh');\n }\n\n /** @internal */\n const buildTileMesh = (\n tileX: number,\n tileY: number,\n tileBoundsMin: Vector3Tuple,\n tileBoundsMax: Vector3Tuple\n ):\n | { success: true; data?: R.UnsignedCharArray }\n | { success: false; error: string } => {\n const failTileMesh = (error: string) => {\n buildContext.log(Raw.Module.RC_LOG_ERROR, error);\n\n return { success: false as const, error };\n };\n\n const tileIntermediate: {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n } = { tileX, tileY };\n\n intermediates.tileIntermediates.push(tileIntermediate);\n\n const { raw: tileConfig } = recastConfig.clone();\n\n // Expand the heightfield bounding box by border size to find the extents of geometry we need to build this tile.\n //\n // This is done in order to make sure that the navmesh tiles connect correctly at the borders,\n // and the obstacles close to the border work correctly with the dilation process.\n // No polygons (or contours) will be created on the border area.\n //\n // IMPORTANT!\n //\n // :''''''''':\n // : +-----+ :\n // : | | :\n // : | |<--- tile to build\n // : | | :\n // : +-----+ :<-- geometry needed\n // :.........:\n //\n // You should use this bounding box to query your input geometry.\n //\n // For example if you build a navmesh for terrain, and want the navmesh tiles to match the terrain tile size\n // you will need to pass in data from neighbour terrain tiles too! In a simple case, just pass in all the 8 neighbours,\n // or use the bounding box below to only pass in a sliver of each of the 8 neighbours.\n\n const expandedTileBoundsMin = [...tileBoundsMin] as Vector3Tuple;\n const expandedTileBoundsMax = [...tileBoundsMax] as Vector3Tuple;\n\n expandedTileBoundsMin[0] -= tileConfig.borderSize * tileConfig.cs;\n expandedTileBoundsMin[2] -= tileConfig.borderSize * tileConfig.cs;\n\n expandedTileBoundsMax[0] += tileConfig.borderSize * tileConfig.cs;\n expandedTileBoundsMax[2] += tileConfig.borderSize * tileConfig.cs;\n\n tileConfig.set_bmin(0, expandedTileBoundsMin[0]);\n tileConfig.set_bmin(1, expandedTileBoundsMin[1]);\n tileConfig.set_bmin(2, expandedTileBoundsMin[2]);\n\n tileConfig.set_bmax(0, expandedTileBoundsMax[0]);\n tileConfig.set_bmax(1, expandedTileBoundsMax[1]);\n tileConfig.set_bmax(2, expandedTileBoundsMax[2]);\n\n // Reset build timer\n buildContext.resetTimers();\n\n // Start the build process\n buildContext.startTimer(Raw.Module.RC_TIMER_TOTAL);\n\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n `Building tile ${intermediates.tileIntermediates.length} at x: ${tileX}, y: ${tileY}`\n );\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n ` - ${config.width} x ${config.height} cells`\n );\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n ` - ${nVerts / 1000}fK verts, ${nTris / 1000}K tris`\n );\n\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n tileIntermediate.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n tileConfig.width,\n tileConfig.height,\n expandedTileBoundsMin,\n expandedTileBoundsMax,\n tileConfig.cs,\n tileConfig.ch\n )\n ) {\n return failTileMesh('Could not create heightfield');\n }\n\n // Allocate array that can hold triangle flags.\n // If you have multiple meshes you need to process, allocate\n // and array which can hold the max number of triangles you need to process.\n const triAreas = new Arrays.UnsignedCharArray();\n triAreas.resize(chunkyTriMesh.maxTrisPerChunk());\n\n const tbmin: Vector2Tuple = [\n expandedTileBoundsMin[0],\n expandedTileBoundsMin[2],\n ];\n const tbmax: Vector2Tuple = [\n expandedTileBoundsMax[0],\n expandedTileBoundsMax[2],\n ];\n\n // TODO: Make grow when returning too many items.\n const maxChunkIds = 512;\n const chunkIdsArray = new Arrays.IntArray();\n chunkIdsArray.resize(maxChunkIds);\n\n const nChunksOverlapping = chunkyTriMesh.getChunksOverlappingRect(\n tbmin,\n tbmax,\n chunkIdsArray,\n maxChunkIds\n );\n\n if (nChunksOverlapping === 0) {\n return { success: true };\n }\n\n for (let i = 0; i < nChunksOverlapping; ++i) {\n const nodeId = chunkIdsArray.get_data(i);\n const node = chunkyTriMesh.nodes(nodeId);\n const nNodeTris = node.n;\n\n const nodeTrisArray = chunkyTriMesh.getNodeTris(nodeId);\n\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nNodeTris);\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n markWalkableTriangles(\n buildContext,\n tileConfig.walkableSlopeAngle,\n vertsArray,\n nVerts,\n nodeTrisArray,\n nNodeTris,\n triAreasArray\n );\n\n const success = rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n nodeTrisArray,\n triAreasArray,\n nNodeTris,\n heightfield,\n tileConfig.walkableClimb\n );\n\n triAreasArray.free();\n\n if (!success) {\n return failTileMesh('Could not rasterize triangles');\n }\n }\n\n // Once all geometry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n tileConfig.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n tileConfig.walkableHeight,\n tileConfig.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n tileConfig.walkableHeight,\n heightfield\n );\n\n // Compact the heightfield so that it is faster to handle from now on.\n // This will result more cache coherent data as well as the neighbours\n // between walkable cells will be calculated.\n const compactHeightfield = allocCompactHeightfield();\n tileIntermediate.compactHeightfield = compactHeightfield;\n\n if (\n !buildCompactHeightfield(\n buildContext,\n tileConfig.walkableHeight,\n tileConfig.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return failTileMesh('Could not build compact heightfield');\n }\n\n if (!keepIntermediates) {\n freeHeightfield(tileIntermediate.heightfield);\n tileIntermediate.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius\n if (\n !erodeWalkableArea(\n buildContext,\n tileConfig.walkableRadius,\n compactHeightfield\n )\n ) {\n return failTileMesh('Could not erode walkable area');\n }\n\n // (Optional) Mark areas\n // markConvexPolyArea(...)\n\n // Prepare for region partitioning, by calculating Distance field along the walkable surface.\n if (!buildDistanceField(buildContext, compactHeightfield)) {\n return failTileMesh('Failed to build distance field');\n }\n\n // Partition the walkable surface into simple regions without holes.\n if (\n !buildRegions(\n buildContext,\n compactHeightfield,\n tileConfig.borderSize,\n tileConfig.minRegionArea,\n tileConfig.mergeRegionArea\n )\n ) {\n return failTileMesh('Failed to build regions');\n }\n\n //\n // Trace and simplify region contours.\n //\n const contourSet = allocContourSet();\n tileIntermediate.contourSet = contourSet;\n\n if (\n !buildContours(\n buildContext,\n compactHeightfield,\n tileConfig.maxSimplificationError,\n tileConfig.maxEdgeLen,\n contourSet,\n Raw.Module.RC_CONTOUR_TESS_WALL_EDGES\n )\n ) {\n return failTileMesh('Failed to create contours');\n }\n\n //\n // Build polygons mesh from contours.\n //\n const polyMesh = allocPolyMesh();\n if (\n !buildPolyMesh(\n buildContext,\n contourSet,\n tileConfig.maxVertsPerPoly,\n polyMesh\n )\n ) {\n return failTileMesh('Failed to triangulate contours');\n }\n\n //\n // Create detail mesh which allows to access approximate height on each polygon.\n //\n const polyMeshDetail = allocPolyMeshDetail();\n if (\n !buildPolyMeshDetail(\n buildContext,\n polyMesh,\n compactHeightfield,\n tileConfig.detailSampleDist,\n tileConfig.detailSampleMaxError,\n polyMeshDetail\n )\n ) {\n return failTileMesh('Failed to build detail mesh');\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n tileIntermediate.compactHeightfield = undefined;\n\n freeContourSet(contourSet);\n tileIntermediate.contourSet = undefined;\n }\n\n // Update poly flags from areas.\n for (let i = 0; i < polyMesh.npolys(); i++) {\n if (polyMesh.areas(i) == Raw.Recast.WALKABLE_AREA) {\n polyMesh.setAreas(i, 0);\n }\n if (polyMesh.areas(i) == 0) {\n polyMesh.setFlags(i, 1);\n }\n }\n\n const navMeshCreateParams = new NavMeshCreateParams();\n\n navMeshCreateParams.setPolyMeshCreateParams(polyMesh);\n navMeshCreateParams.setPolyMeshDetailCreateParams(polyMeshDetail);\n\n navMeshCreateParams.setWalkableHeight(tileConfig.walkableHeight);\n navMeshCreateParams.setWalkableRadius(tileConfig.walkableRadius);\n navMeshCreateParams.setWalkableClimb(tileConfig.walkableClimb);\n\n navMeshCreateParams.setCellSize(tileConfig.cs);\n navMeshCreateParams.setCellHeight(tileConfig.ch);\n\n navMeshCreateParams.setBuildBvTree(true);\n\n if (navMeshGeneratorConfig.offMeshConnections) {\n navMeshCreateParams.setOffMeshConnections(\n navMeshGeneratorConfig.offMeshConnections\n );\n }\n\n navMeshCreateParams.setTileX(tileX);\n navMeshCreateParams.setTileY(tileY);\n\n const createNavMeshDataResult = createNavMeshData(navMeshCreateParams);\n\n if (!createNavMeshDataResult.success) {\n return failTileMesh('Failed to create Detour navmesh data');\n }\n\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n `>> Polymesh: ${polyMesh.nverts()} vertices ${polyMesh.npolys()} polygons`\n );\n\n return { success: true, data: createNavMeshDataResult.navMeshData };\n };\n\n buildContext.startTimer(Raw.Module.RC_TIMER_TEMP);\n\n let lastBuiltTileBmin: Vector3Tuple = [0, 0, 0];\n let lastBuiltTileBmax: Vector3Tuple = [0, 0, 0];\n\n for (let y = 0; y < tileHeight; y++) {\n for (let x = 0; x < tileWidth; x++) {\n lastBuiltTileBmin[0] = bbMin[0] + x * tcs;\n lastBuiltTileBmin[1] = bbMin[1];\n lastBuiltTileBmin[2] = bbMin[2] + y * tcs;\n\n lastBuiltTileBmax[0] = bbMin[0] + (x + 1) * tcs;\n lastBuiltTileBmax[1] = bbMax[1];\n lastBuiltTileBmax[2] = bbMin[2] + (y + 1) * tcs;\n\n const result = buildTileMesh(x, y, lastBuiltTileBmin, lastBuiltTileBmax);\n\n if (result.success && result.data) {\n navMesh.removeTile(navMesh.getTileRefAt(x, y, 0));\n\n const addTileResult = navMesh.addTile(\n result.data,\n Raw.Module.DT_TILE_FREE_DATA,\n 0\n );\n\n if (Raw.Detour.statusFailed(addTileResult.status)) {\n buildContext.log(\n Raw.Module.RC_LOG_WARNING,\n `Failed to add tile to nav mesh` +\n '\\n\\t' +\n `tx: ${x}, ty: ${y},` +\n `status: ${dtStatusToReadableString(addTileResult.status)} (${\n addTileResult.status\n })`\n );\n\n result.data.free();\n }\n }\n }\n }\n\n buildContext.stopTimer(Raw.Module.RC_TIMER_TEMP);\n\n if (!keepIntermediates) {\n cleanup();\n }\n\n return {\n success: true,\n navMesh,\n intermediates,\n };\n};\n"],"names":["getBoundingBox","positions","indices","bbMin","x","Infinity","y","z","bbMax","i","length","ind","Math","min","max","vec3","toArray","dtIlog2","v","r","shift","Number","dtNextPow2","soloNavMeshGeneratorConfigDefaults","recastConfigDefaults","tileCacheGeneratorConfigDefaults","tileSize","expectedLayersPerTile","maxObstacles","createDefaultTileCacheMeshProcess","TileCacheMeshProcess","navMeshCreateParams","polyAreas","polyFlags","polyCount","set","tiledNavMeshGeneratorConfigDefaults","navMeshGeneratorConfig","keepIntermediates","buildContext","RecastBuildContext","intermediates","type","navMesh","NavMesh","fail","error","heightfield","freeHeightfield","undefined","compactHeightfield","freeCompactHeightfield","contourSet","freeContourSet","destroy","success","verts","nVerts","vertsArray","Arrays","FloatArray","copy","tris","nTris","trisArray","IntArray","raw","config","RecastConfig","create","minRegionArea","mergeRegionArea","detailSampleDist","cs","detailSampleMaxError","ch","gridSize","Raw","Recast","calcGridSize","width","height","allocHeightfield","createHeightfield","triAreasArray","UnsignedCharArray","resize","markWalkableTriangles","walkableSlopeAngle","rasterizeTriangles","walkableClimb","free","filterLowHangingWalkableObstacles","filterLedgeSpans","walkableHeight","filterWalkableLowHeightSpans","allocCompactHeightfield","buildCompactHeightfield","erodeWalkableArea","walkableRadius","buildDistanceField","buildRegions","borderSize","allocContourSet","buildContours","maxSimplificationError","maxEdgeLen","Module","RC_CONTOUR_TESS_WALL_EDGES","polyMesh","allocPolyMesh","buildPolyMesh","maxVertsPerPoly","polyMeshDetail","allocPolyMeshDetail","buildPolyMeshDetail","npolys","areas","WALKABLE_AREA","setAreas","setFlags","NavMeshCreateParams","setPolyMeshCreateParams","setPolyMeshDetailCreateParams","setWalkableHeight","setWalkableRadius","setWalkableClimb","setCellSize","setCellHeight","setBuildBvTree","offMeshConnections","setOffMeshConnections","createNavMeshDataResult","createNavMeshData","navMeshData","initSolo","chunkyTriMesh","tileIntermediates","tileCache","TileCache","cleanup","tileIntermediate","heightfieldLayerSet","freeHeightfieldLayerSet","recastConfig","floor","tileWidth","tileHeight","tileCacheParams","DetourTileCacheParams","orig","maxTiles","allocator","RecastLinearAllocator","compressor","RecastFastLZCompressor","tileCacheMeshProcess","init","fromArray","tileBits","maxPolysPerTile","navMeshParams","NavMeshParams","maxPolys","initTiled","RecastChunkyTriMesh","rasterizeTileLayers","tileX","tileY","tcs","tileConfig","clone","tileBoundsMin","tileBoundsMax","set_bmin","set_bmax","n","tbmin","tbmax","chunkIdsArray","nChunksOverlapping","getChunksOverlappingRect","nodeId","get_data","nNodeTris","nodes","nodeTrisArray","getNodeTris","allocHeightfieldLayerSet","buildHeightfieldLayers","tiles","nlayers","tile","heightfieldLayer","layers","header","dtTileCacheLayerHeader","magic","Detour","TILECACHE_MAGIC","version","TILECACHE_VERSION","tx","ty","tlayer","heightfieldLayerBin","bmin","heightfieldLayerBmax","bmax","minx","maxx","miny","maxy","hmin","hmax","heights","getHeightfieldLayerHeights","getHeightfieldLayerAreas","cons","getHeightfieldLayerCons","status","buildTileCacheLayer","statusFailed","push","newTiles","tileCacheData","addResult","addTile","log","RC_LOG_WARNING","dtStatus","buildNavMeshTilesAt","buildTileMesh","failTileMesh","RC_LOG_ERROR","expandedTileBoundsMin","expandedTileBoundsMax","resetTimers","startTimer","RC_TIMER_TOTAL","RC_LOG_PROGRESS","maxTrisPerChunk","setTileX","setTileY","nverts","data","RC_TIMER_TEMP","lastBuiltTileBmin","lastBuiltTileBmax","result","removeTile","getTileRefAt","addTileResult","DT_TILE_FREE_DATA","dtStatusToReadableString","stopTimer"],"mappings":"4DAEaA,EAAiB,CAC5BC,EACAC,KAEA,MAAMC,EAAQ,CAAEC,EAAGC,IAAUC,EAAGD,IAAUE,EAAGF,KACvCG,EAAQ,CAAEJ,GAAIC,IAAUC,GAAID,IAAUE,GAAIF,KAEhD,IAAK,IAAII,EAAI,EAAGA,EAAIP,EAAQQ,OAAQD,IAAK,CACvC,MAAME,EAAMT,EAAQO,GAEdL,EAAIH,EAAgB,EAANU,GACdL,EAAIL,EAAgB,EAANU,EAAU,GACxBJ,EAAIN,EAAgB,EAANU,EAAU,GAE9BR,EAAMC,EAAIQ,KAAKC,IAAIV,EAAMC,EAAGA,GAC5BD,EAAMG,EAAIM,KAAKC,IAAIV,EAAMG,EAAGA,GAC5BH,EAAMI,EAAIK,KAAKC,IAAIV,EAAMI,EAAGA,GAE5BC,EAAMJ,EAAIQ,KAAKE,IAAIN,EAAMJ,EAAGA,GAC5BI,EAAM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AAOJ,KAAM,CACjC1M,EAAQ+M,WAAW/M,EAAQgN,aAAavP,EAAGE,EAAG,IAE9C,MAAMsP,EAAgBjN,EAAQwL,QAC5BsB,EAAOJ,KACPxK,EAAAA,IAAI8B,OAAOkJ,kBACX,GAGEhL,EAAGA,IAACyH,OAAOwB,aAAa8B,EAAchC,UACxCrL,EAAa6L,IACXvJ,EAAGA,IAAC8B,OAAO0H,eAGT,yCAAOjO,UAAUE,aACNwP,2BAAyBF,EAAchC,YAChDgC,EAAchC,WAIpB6B,EAAOJ,KAAK1J,OAEf,CACF,CASH,OANApD,EAAawN,UAAUlL,EAAAA,IAAI8B,OAAO2I,eAE7BhN,GACHsG,IAGK,CACLrF,SAAS,EACTZ,UACAF,gBACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generators';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{vec3 as e,recastConfigDefaults as t,RecastBuildContext as i,NavMesh as a,Arrays as l,RecastConfig as r,Raw as o,allocHeightfield as s,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 w,buildDistanceField as S,buildRegions as y,allocContourSet as M,buildContours as C,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 L,RecastChunkyTriMesh as D,freeHeightfieldLayerSet as O,allocHeightfieldLayerSet as P,buildHeightfieldLayers as I,getHeightfieldLayerHeights as G,getHeightfieldLayerAreas as $,getHeightfieldLayerCons as N,buildTileCacheLayer as W,dtStatusToReadableString as B}from"@recast-navigation/core";const U=(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],o=t[3*r],s=t[3*r+1],n=t[3*r+2];a.x=Math.min(a.x,o),a.y=Math.min(a.y,s),a.z=Math.min(a.z,n),l.x=Math.max(l.x,o),l.y=Math.max(l.y,s),l.z=Math.max(l.z,n)}return{bbMin:e.toArray(a),bbMax:e.toArray(l)}},K=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},V=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),X={...t},Y=(e,t,T={},E=!1)=>{const H=new i,F={type:"solo",buildContext:H},L=new a,D=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)),L.destroy(),{navMesh:void 0,success:!1,intermediates:F,error:e}),O=e,P=t.length,I=new l.FloatArray;I.copy(O,O.length);const G=t,$=t.length/3,N=new l.IntArray;N.copy(G,G.length);const{bbMin:W,bbMax:B}=U(e,t),{raw:K}=r.create({...X,...T});K.minRegionArea=K.minRegionArea*K.minRegionArea,K.mergeRegionArea=K.mergeRegionArea*K.mergeRegionArea,K.detailSampleDist=K.detailSampleDist<.9?0:K.cs*K.detailSampleDist,K.detailSampleMaxError=K.ch*K.detailSampleMaxError;const V=o.Recast.calcGridSize(W,B,K.cs);K.width=V.width,K.height=V.height;const Y=s();if(F.heightfield=Y,!n(H,Y,K.width,K.height,W,B,K.cs,K.ch))return D("Could not create heightfield");const Z=new l.UnsignedCharArray;if(Z.resize($),d(H,K.walkableSlopeAngle,I,P,N,$,Z),!h(H,I,P,N,Z,$,Y,K.walkableClimb))return D("Could not rasterize triangles");Z.free(),c(H,K.walkableClimb,Y),m(H,K.walkableHeight,K.walkableClimb,Y),g(H,K.walkableHeight,Y);const j=u();if(F.compactHeightfield=j,!b(H,K.walkableHeight,K.walkableClimb,Y,j))return D("Failed to build compact data");if(E||(f(Y),F.heightfield=void 0),!w(H,K.walkableRadius,j))return D("Failed to erode walkable area");if(!S(H,j))return D("Failed to build distance field");if(!y(H,j,K.borderSize,K.minRegionArea,K.mergeRegionArea))return D("Failed to build regions");const q=M();if(F.contourSet=q,!C(H,j,K.maxSimplificationError,K.maxEdgeLen,q,o.Module.RC_CONTOUR_TESS_WALL_EDGES))return D("Failed to create contours");const J=R();if(!x(H,q,K.maxVertsPerPoly,J))return D("Failed to triangulate contours");const Q=p();if(!A(H,J,j,K.detailSampleDist,K.detailSampleMaxError,Q))return D("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)==o.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(K.walkableHeight),ee.setWalkableRadius(K.walkableRadius),ee.setWalkableClimb(K.walkableClimb),ee.setCellSize(K.cs),ee.setCellHeight(K.ch),ee.setBuildBvTree(!0),T.offMeshConnections&&ee.setOffMeshConnections(T.offMeshConnections);const te=v(ee);if(!te.success)return D("Failed to create Detour navmesh data");const{navMeshData:ie}=te;return L.initSolo(ie)?{success:!0,navMesh:L,intermediates:F}:D("Failed to create Detour navmesh")},Z={...t,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},j=()=>new T(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)})),q=(t,S,y={},M=!1)=>{const C=new i;let R={type:"tilecache",buildContext:C,chunkyTriMesh:void 0,tileIntermediates:[]};const x=new E,p=new a,A=()=>{if(!M)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)}},z=e=>(A(),x.destroy(),p.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:R,error:e}),_=t,v=S.length,T=new l.FloatArray;T.copy(_,_.length);const B=S,X=S.length/3,Y=new l.IntArray;Y.copy(B,B.length);const{bbMin:q,bbMax:J}=U(t,S),{expectedLayersPerTile:Q,maxObstacles:ee,...te}={...Z,...y},{raw:ie}=r.create(te),ae=H(q,J,ie.cs);ie.width=ae.width,ie.height=ae.height,ie.minRegionArea=ie.minRegionArea*ie.minRegionArea,ie.mergeRegionArea=ie.mergeRegionArea*ie.mergeRegionArea,ie.detailSampleDist=ie.detailSampleDist<.9?0:ie.cs*ie.detailSampleDist,ie.detailSampleMaxError=ie.ch*ie.detailSampleMaxError;const le=Math.floor(ie.tileSize),re=Math.floor((ie.width+le-1)/le),oe=Math.floor((ie.height+le-1)/le);ie.borderSize=ie.walkableRadius+3,ie.width=ie.tileSize+2*ie.borderSize,ie.height=ie.tileSize+2*ie.borderSize;const se=F.create({orig:q,cs:ie.cs,ch:ie.ch,width:ie.tileSize,height:ie.tileSize,walkableHeight:ie.walkableHeight,walkableRadius:ie.walkableRadius,walkableClimb:ie.walkableClimb,maxSimplificationError:ie.maxSimplificationError,maxTiles:re*oe*Q,maxObstacles:ee}),ne=new o.RecastLinearAllocator(32e3),de=new o.RecastFastLZCompressor,he=y.tileCacheMeshProcess??j();if(!x.init(se,ne,de,he))return z("Failed to initialize tile cache");const ce=e.fromArray(q);let me=Math.min(Math.floor(K(V(re*oe*Q))),14);me>14&&(me=14);const ge=1<<me,ue=1<<22-me,be=L.create({orig:ce,tileWidth:ie.tileSize*ie.cs,tileHeight:ie.tileSize*ie.cs,maxTiles:ge,maxPolys:ue});if(!p.initTiled(be))return z("Failed to initialize tiled navmesh");const fe=new D;if(R.chunkyTriMesh=fe,!fe.init(T,Y,X,256))return z("Failed to build chunky triangle mesh");const we=(e,t)=>{const i={tileX:e,tileY:t},a=ie.tileSize*ie.cs,{raw:S}=new r(ie).clone(),y=[q[0]+e*a,q[1],q[2]+t*a],x=[q[0]+(e+1)*a,J[1],q[2]+(t+1)*a];y[0]-=S.borderSize*S.cs,y[2]-=S.borderSize*S.cs,x[0]+=S.borderSize*S.cs,x[2]+=S.borderSize*S.cs,S.set_bmin(0,y[0]),S.set_bmin(1,y[1]),S.set_bmin(2,y[2]),S.set_bmax(0,x[0]),S.set_bmax(1,x[1]),S.set_bmax(2,x[2]);const p=s();if(i.heightfield=p,!n(C,p,S.width,S.height,y,x,S.cs,S.ch))return{n:0};const A=[y[0],y[2]],z=[x[0],x[2]],_=new l.IntArray;_.resize(512);const E=fe.getChunksOverlappingRect(A,z,_,512);if(0===E)return{n:0};for(let e=0;e<E;++e){const t=_.get_data(e),i=fe.nodes(t).n,a=fe.getNodeTris(t),r=new l.UnsignedCharArray;r.resize(i),d(C,S.walkableSlopeAngle,T,v,a,i,r);const o=h(C,T,v,a,r,i,p,S.walkableClimb);if(r.free(),!o)return{n:0}}c(C,ie.walkableClimb,p),m(C,ie.walkableHeight,ie.walkableClimb,p),g(C,ie.walkableHeight,p);const H=u();if(!b(C,ie.walkableHeight,ie.walkableClimb,p,H))return{n:0};if(M||(f(i.heightfield),i.heightfield=void 0),!w(C,ie.walkableRadius,H))return{n:0};const F=P();if(!I(C,H,ie.borderSize,ie.walkableHeight,F))return{n:0};M||(k(H),i.compactHeightfield=void 0);const L=[];for(let i=0;i<F.nlayers();i++){const a=new l.UnsignedCharArray,r=F.layers(i),s=new o.dtTileCacheLayerHeader;s.magic=o.Detour.TILECACHE_MAGIC,s.version=o.Detour.TILECACHE_VERSION,s.tx=e,s.ty=t,s.tlayer=i;const n=r.bmin(),d=r.bmax();s.set_bmin(0,n.x),s.set_bmin(1,n.y),s.set_bmin(2,n.z),s.set_bmax(0,d.x),s.set_bmax(1,d.y),s.set_bmax(2,d.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 h=G(r),c=$(r),m=N(r),g=W(de,s,h,c,m,a);if(o.Detour.statusFailed(g))return{n:0};L.push(a)}return M||(O(F),i.heightfieldLayerSet=void 0),R.tileIntermediates.push(i),{n:L.length,tiles:L}};for(let e=0;e<oe;++e)for(let t=0;t<re;++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);o.Detour.statusFailed(r.status)&&C.log(o.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<re;t++){const i=x.buildNavMeshTilesAt(t,e,p);if(o.Detour.statusFailed(i))return z(`Failed to build nav mesh tiles at ${t}, ${e}`)}return A(),{success:!0,tileCache:x,navMesh:p,intermediates:R}},J={...t},Q=(t,T,E={},F=!1)=>{const O=new i,P={type:"tiled",buildContext:O,chunkyTriMesh:void 0,tileIntermediates:[]},I=new a,G=()=>{if(!F){for(let e=0;e<P.tileIntermediates.length;e++){const t=P.tileIntermediates[e];t.compactHeightfield&&k(t.compactHeightfield),t.heightfield&&f(t.heightfield),t.contourSet&&z(t.contourSet)}P.chunkyTriMesh&&(P.chunkyTriMesh=void 0)}},$=e=>(G(),I.destroy(),{success:!1,navMesh:void 0,intermediates:P,error:e}),N=r.create({...J,...E}),{raw:W}=N,{bbMin:X,bbMax:Y}=U(t,T),Z=H(X,Y,W.cs);W.width=Z.width,W.height=Z.height,W.minRegionArea=W.minRegionArea*W.minRegionArea,W.mergeRegionArea=W.mergeRegionArea*W.mergeRegionArea,W.tileSize=Math.floor(W.tileSize),W.borderSize=W.walkableRadius+3,W.width=W.tileSize+2*W.borderSize,W.height=W.tileSize+2*W.borderSize,W.detailSampleDist=W.detailSampleDist<.9?0:W.cs*W.detailSampleDist,W.detailSampleMaxError=W.ch*W.detailSampleMaxError;const j=Math.floor(W.tileSize),q=Math.floor((Z.width+j-1)/j),Q=Math.floor((Z.height+j-1)/j),ee=W.tileSize*W.cs,te=t,ie=T.length,ae=new l.FloatArray;ae.copy(te,te.length);const le=T,re=T.length/3,oe=new l.IntArray;oe.copy(le,le.length);const se=e.fromArray(X);let ne=Math.min(Math.floor(K(V(q*Q))),14);ne>14&&(ne=14);const de=1<<ne,he=1<<22-ne,ce=L.create({orig:se,tileWidth:W.tileSize*W.cs,tileHeight:W.tileSize*W.cs,maxTiles:de,maxPolys:he});if(!I.initTiled(ce))return $("Could not init nav mesh for tiled use");const me=new D;if(P.chunkyTriMesh=me,!me.init(ae,oe,re,256))return $("Failed to build chunky triangle mesh");const ge=(e,t,i,a)=>{const r=e=>(O.log(o.Module.RC_LOG_ERROR,e),{success:!1,error:e}),T={tileX:e,tileY:t};P.tileIntermediates.push(T);const{raw:H}=N.clone(),L=[...i],D=[...a];L[0]-=H.borderSize*H.cs,L[2]-=H.borderSize*H.cs,D[0]+=H.borderSize*H.cs,D[2]+=H.borderSize*H.cs,H.set_bmin(0,L[0]),H.set_bmin(1,L[1]),H.set_bmin(2,L[2]),H.set_bmax(0,D[0]),H.set_bmax(1,D[1]),H.set_bmax(2,D[2]),O.resetTimers(),O.startTimer(o.Module.RC_TIMER_TOTAL),O.log(o.Module.RC_LOG_PROGRESS,`Building tile ${P.tileIntermediates.length} at x: ${e}, y: ${t}`),O.log(o.Module.RC_LOG_PROGRESS,` - ${W.width} x ${W.height} cells`),O.log(o.Module.RC_LOG_PROGRESS,` - ${ie/1e3}fK verts, ${re/1e3}K tris`);const I=s();if(T.heightfield=I,!n(O,I,H.width,H.height,L,D,H.cs,H.ch))return r("Could not create heightfield");(new l.UnsignedCharArray).resize(me.maxTrisPerChunk());const G=[L[0],L[2]],$=[D[0],D[2]],B=new l.IntArray;B.resize(512);const U=me.getChunksOverlappingRect(G,$,B,512);if(0===U)return{success:!0};for(let e=0;e<U;++e){const t=B.get_data(e),i=me.nodes(t).n,a=me.getNodeTris(t),o=new l.UnsignedCharArray;o.resize(i),d(O,H.walkableSlopeAngle,ae,ie,a,i,o);const s=h(O,ae,ie,a,o,i,I,H.walkableClimb);if(o.free(),!s)return r("Could not rasterize triangles")}c(O,H.walkableClimb,I),m(O,H.walkableHeight,H.walkableClimb,I),g(O,H.walkableHeight,I);const K=u();if(T.compactHeightfield=K,!b(O,H.walkableHeight,H.walkableClimb,I,K))return r("Could not build compact heightfield");if(F||(f(T.heightfield),T.heightfield=void 0),!w(O,H.walkableRadius,K))return r("Could not erode walkable area");if(!S(O,K))return r("Failed to build distance field");if(!y(O,K,H.borderSize,H.minRegionArea,H.mergeRegionArea))return r("Failed to build regions");const V=M();if(T.contourSet=V,!C(O,K,H.maxSimplificationError,H.maxEdgeLen,V,o.Module.RC_CONTOUR_TESS_WALL_EDGES))return r("Failed to create contours");const X=R();if(!x(O,V,H.maxVertsPerPoly,X))return r("Failed to triangulate contours");const Y=p();if(!A(O,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)==o.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?(O.log(o.Module.RC_LOG_PROGRESS,`>> Polymesh: ${X.nverts()} vertices ${X.npolys()} polygons`),{success:!0,data:j.navMeshData}):r("Failed to create Detour navmesh data")};O.startTimer(o.Module.RC_TIMER_TEMP);let ue=[0,0,0],be=[0,0,0];for(let e=0;e<Q;e++)for(let t=0;t<q;t++){ue[0]=X[0]+t*ee,ue[1]=X[1],ue[2]=X[2]+e*ee,be[0]=X[0]+(t+1)*ee,be[1]=Y[1],be[2]=X[2]+(e+1)*ee;const i=ge(t,e,ue,be);if(i.success&&i.data){I.removeTile(I.getTileRefAt(t,e,0));const a=I.addTile(i.data,o.Module.DT_TILE_FREE_DATA,0);o.Detour.statusFailed(a.status)&&(O.log(o.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${t}, ty: ${e},status: ${B(a.status)} (${a.status})`),i.data.free())}}return O.stopTimer(o.Module.RC_TIMER_TEMP),F||G(),{success:!0,navMesh:I,intermediates:P}};export{j as createDefaultTileCacheMeshProcess,K as dtIlog2,V as dtNextPow2,Y as generateSoloNavMesh,q as generateTileCache,Q as generateTiledNavMesh,U as getBoundingBox,X as soloNavMeshGeneratorConfigDefaults,Z as tileCacheGeneratorConfigDefaults,J as tiledNavMeshGeneratorConfigDefaults};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/generators/common.ts","../src/generators/generate-solo-nav-mesh.ts","../src/generators/generate-tile-cache.ts","../src/generators/generate-tiled-nav-mesh.ts"],"sourcesContent":["import { OffMeshConnectionParams, vec3 } from '@recast-navigation/core';\n\nexport const getBoundingBox = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>\n) => {\n const bbMin = { x: Infinity, y: Infinity, z: Infinity };\n const bbMax = { x: -Infinity, y: -Infinity, z: -Infinity };\n\n for (let i = 0; i < indices.length; i++) {\n const ind = indices[i];\n\n const x = positions[ind * 3];\n const y = positions[ind * 3 + 1];\n const z = positions[ind * 3 + 2];\n\n bbMin.x = Math.min(bbMin.x, x);\n bbMin.y = Math.min(bbMin.y, y);\n bbMin.z = Math.min(bbMin.z, z);\n\n bbMax.x = Math.max(bbMax.x, x);\n bbMax.y = Math.max(bbMax.y, y);\n bbMax.z = Math.max(bbMax.z, z);\n }\n\n return {\n bbMin: vec3.toArray(bbMin),\n bbMax: vec3.toArray(bbMax),\n };\n};\n\nexport const dtIlog2 = (v: number) => {\n let r = 0;\n let shift = 0;\n\n r = Number(v > 0xffff) << 4;\n v >>= r;\n\n shift = Number(v > 0xff) << 3;\n v >>= shift;\n r |= shift;\n\n shift = Number(v > 0xf) << 2;\n v >>= shift;\n r |= shift;\n\n shift = Number(v > 0x3) << 1;\n v >>= shift;\n r |= shift;\n r |= v >> 1;\n\n return r;\n};\n\nexport const dtNextPow2 = (v: number) => {\n v--;\n v |= v >> 1;\n v |= v >> 2;\n v |= v >> 4;\n v |= v >> 8;\n v |= v >> 16;\n v++;\n return v;\n};\n\nexport type OffMeshConnectionGeneratorParams = {\n offMeshConnections?: OffMeshConnectionParams[];\n};\n","import {\n Arrays,\n NavMesh,\n NavMeshCreateParams,\n Raw,\n RecastBuildContext,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastContourSet,\n RecastHeightfield,\n allocCompactHeightfield,\n allocContourSet,\n allocHeightfield,\n allocPolyMesh,\n allocPolyMeshDetail,\n buildCompactHeightfield,\n buildContours,\n buildDistanceField,\n buildPolyMesh,\n buildPolyMeshDetail,\n buildRegions,\n createHeightfield,\n createNavMeshData,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeContourSet,\n freeHeightfield,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n} from '@recast-navigation/core';\nimport { Pretty } from '../types';\nimport { OffMeshConnectionGeneratorParams, getBoundingBox } from './common';\n\nexport type SoloNavMeshGeneratorConfig = Pretty<\n Omit<RecastConfigType, 'tileSize'> & OffMeshConnectionGeneratorParams\n>;\n\nexport const soloNavMeshGeneratorConfigDefaults: SoloNavMeshGeneratorConfig = {\n ...recastConfigDefaults,\n};\n\nexport type SoloNavMeshGeneratorIntermediates = {\n type: 'solo';\n buildContext: RecastBuildContext;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n};\n\ntype SoloNavMeshGeneratorSuccessResult = {\n navMesh: NavMesh;\n success: true;\n intermediates: SoloNavMeshGeneratorIntermediates;\n};\n\ntype SoloNavMeshGeneratorFailResult = {\n navMesh: undefined;\n success: false;\n intermediates: SoloNavMeshGeneratorIntermediates;\n error: string;\n};\n\nexport type SoloNavMeshGeneratorResult =\n | SoloNavMeshGeneratorSuccessResult\n | SoloNavMeshGeneratorFailResult;\n\n/**\n * Builds a Solo NavMesh from the given positions and indices.\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshGeneratorConfig optional configuration for the NavMesh generator\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateSoloNavMesh = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<SoloNavMeshGeneratorConfig> = {},\n keepIntermediates = false\n): SoloNavMeshGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n const intermediates: SoloNavMeshGeneratorIntermediates = {\n type: 'solo',\n buildContext,\n };\n\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (keepIntermediates) return;\n\n if (intermediates.heightfield) {\n freeHeightfield(intermediates.heightfield);\n intermediates.heightfield = undefined;\n }\n if (intermediates.compactHeightfield) {\n freeCompactHeightfield(intermediates.compactHeightfield);\n intermediates.compactHeightfield = undefined;\n }\n if (intermediates.contourSet) {\n freeContourSet(intermediates.contourSet);\n intermediates.contourSet = undefined;\n }\n };\n\n const fail = (error: string): SoloNavMeshGeneratorFailResult => {\n cleanup();\n\n navMesh.destroy();\n\n return {\n navMesh: undefined,\n success: false,\n intermediates,\n error,\n };\n };\n\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n //\n // Step 1. Initialize build config.\n //\n const { raw: config } = RecastConfig.create({\n ...soloNavMeshGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n });\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n const gridSize = Raw.Recast.calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n //\n // Step 2. Rasterize input polygon soup.\n //\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n intermediates.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n config.width,\n config.height,\n bbMin,\n bbMax,\n config.cs,\n config.ch\n )\n ) {\n return fail('Could not create heightfield');\n }\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nTris);\n\n markWalkableTriangles(\n buildContext,\n config.walkableSlopeAngle,\n vertsArray,\n nVerts,\n trisArray,\n nTris,\n triAreasArray\n );\n\n if (\n !rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n trisArray,\n triAreasArray,\n nTris,\n heightfield,\n config.walkableClimb\n )\n ) {\n return fail('Could not rasterize triangles');\n }\n\n triAreasArray.free();\n\n //\n // Step 3. Filter walkables surfaces.\n //\n // Once all geoemtry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n config.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n config.walkableHeight,\n heightfield\n );\n\n //\n // Step 4. Partition walkable surface to simple regions.\n //\n // Compact the heightfield so that it is faster to handle from now on.\n // This will result more cache coherent data as well as the neighbours\n // between walkable cells will be calculated.\n const compactHeightfield = allocCompactHeightfield();\n intermediates.compactHeightfield = compactHeightfield;\n\n if (\n !buildCompactHeightfield(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return fail('Failed to build compact data');\n }\n\n if (!keepIntermediates) {\n freeHeightfield(heightfield);\n intermediates.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius.\n if (\n !erodeWalkableArea(buildContext, config.walkableRadius, compactHeightfield)\n ) {\n return fail('Failed to erode walkable area');\n }\n\n // (Optional) Mark areas\n // markConvexPolyArea(...)\n\n // Prepare for region partitioning, by calculating Distance field along the walkable surface.\n if (!buildDistanceField(buildContext, compactHeightfield)) {\n return fail('Failed to build distance field');\n }\n\n // Partition the walkable surface into simple regions without holes.\n if (\n !buildRegions(\n buildContext,\n compactHeightfield,\n config.borderSize,\n config.minRegionArea,\n config.mergeRegionArea\n )\n ) {\n return fail('Failed to build regions');\n }\n\n //\n // Step 5. Trace and simplify region contours.\n //\n const contourSet = allocContourSet();\n intermediates.contourSet = contourSet;\n\n if (\n !buildContours(\n buildContext,\n compactHeightfield,\n config.maxSimplificationError,\n config.maxEdgeLen,\n contourSet,\n Raw.Module.RC_CONTOUR_TESS_WALL_EDGES\n )\n ) {\n return fail('Failed to create contours');\n }\n\n //\n // Step 6. Build polygons mesh from contours.\n //\n const polyMesh = allocPolyMesh();\n if (\n !buildPolyMesh(buildContext, contourSet, config.maxVertsPerPoly, polyMesh)\n ) {\n return fail('Failed to triangulate contours');\n }\n\n //\n // Step 7. Create detail mesh which allows to access approximate height on each polygon.\n //\n const polyMeshDetail = allocPolyMeshDetail();\n if (\n !buildPolyMeshDetail(\n buildContext,\n polyMesh,\n compactHeightfield,\n config.detailSampleDist,\n config.detailSampleMaxError,\n polyMeshDetail\n )\n ) {\n return fail('Failed to build detail mesh');\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n intermediates.compactHeightfield = undefined;\n\n freeContourSet(contourSet);\n intermediates.contourSet = undefined;\n }\n\n //\n // Step 8. Create Detour data from Recast poly mesh.\n //\n for (let i = 0; i < polyMesh.npolys(); i++) {\n if (polyMesh.areas(i) == Raw.Recast.WALKABLE_AREA) {\n polyMesh.setAreas(i, 0);\n }\n if (polyMesh.areas(i) == 0) {\n polyMesh.setFlags(i, 1);\n }\n }\n\n const navMeshCreateParams = new NavMeshCreateParams();\n\n navMeshCreateParams.setPolyMeshCreateParams(polyMesh);\n navMeshCreateParams.setPolyMeshDetailCreateParams(polyMeshDetail);\n\n navMeshCreateParams.setWalkableHeight(config.walkableHeight);\n navMeshCreateParams.setWalkableRadius(config.walkableRadius);\n navMeshCreateParams.setWalkableClimb(config.walkableClimb);\n\n navMeshCreateParams.setCellSize(config.cs);\n navMeshCreateParams.setCellHeight(config.ch);\n\n navMeshCreateParams.setBuildBvTree(true);\n\n if (navMeshGeneratorConfig.offMeshConnections) {\n navMeshCreateParams.setOffMeshConnections(\n navMeshGeneratorConfig.offMeshConnections\n );\n }\n\n const createNavMeshDataResult = createNavMeshData(navMeshCreateParams);\n\n if (!createNavMeshDataResult.success) {\n return fail('Failed to create Detour navmesh data');\n }\n\n const { navMeshData } = createNavMeshDataResult;\n\n if (!navMesh.initSolo(navMeshData)) {\n return fail('Failed to create Detour navmesh');\n }\n\n return {\n success: true,\n navMesh,\n intermediates,\n };\n};\n","import {\n Arrays,\n DetourTileCacheParams,\n NavMesh,\n NavMeshParams,\n Raw,\n RecastBuildContext,\n RecastChunkyTriMesh,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastHeightfield,\n RecastHeightfieldLayerSet,\n TileCache,\n TileCacheMeshProcess,\n Vector2Tuple,\n Vector3Tuple,\n allocCompactHeightfield,\n allocHeightfield,\n allocHeightfieldLayerSet,\n buildCompactHeightfield,\n buildHeightfieldLayers,\n buildTileCacheLayer,\n calcGridSize,\n createHeightfield,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeHeightfield,\n freeHeightfieldLayerSet,\n getHeightfieldLayerAreas,\n getHeightfieldLayerCons,\n getHeightfieldLayerHeights,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n vec3,\n} from '@recast-navigation/core';\nimport type R from '@recast-navigation/wasm';\nimport { Pretty } from '../types';\nimport { dtIlog2, dtNextPow2, getBoundingBox } from './common';\n\nexport type TileCacheGeneratorConfig = Pretty<\n RecastConfigType & {\n /**\n * How many layers (or \"floors\") each navmesh tile is expected to have.\n */\n expectedLayersPerTile: number;\n\n /**\n * The max number of obstacles\n */\n maxObstacles: number;\n\n /**\n * The tile cache mesh process implementation.\n * If not provided, a default one is created via `createDefaultTileCacheMeshProcess()`\n * @default createDefaultTileCacheMeshProcess()\n */\n tileCacheMeshProcess?: TileCacheMeshProcess;\n }\n>;\n\nexport const tileCacheGeneratorConfigDefaults: TileCacheGeneratorConfig = {\n ...recastConfigDefaults,\n tileSize: 32,\n expectedLayersPerTile: 4,\n maxObstacles: 128,\n};\n\nexport type TileCacheGeneratorTileIntermediates = {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n heightfieldLayerSet?: RecastHeightfieldLayerSet;\n};\n\nexport type TileCacheGeneratorIntermediates = {\n type: 'tilecache';\n buildContext: RecastBuildContext;\n chunkyTriMesh?: RecastChunkyTriMesh;\n tileIntermediates: TileCacheGeneratorTileIntermediates[];\n};\n\ntype TileCacheGeneratorSuccessResult = {\n tileCache: TileCache;\n navMesh: NavMesh;\n success: true;\n intermediates: TileCacheGeneratorIntermediates;\n};\n\ntype TileCacheGeneratorFailResult = {\n tileCache: undefined;\n navMesh: undefined;\n success: false;\n error: string;\n intermediates: TileCacheGeneratorIntermediates;\n};\n\nexport type TileCacheGeneratorResult =\n | TileCacheGeneratorSuccessResult\n | TileCacheGeneratorFailResult;\n\nexport const createDefaultTileCacheMeshProcess = () =>\n new TileCacheMeshProcess((navMeshCreateParams, polyAreas, polyFlags) => {\n for (let i = 0; i < navMeshCreateParams.polyCount(); ++i) {\n polyAreas.set(i, 0);\n polyFlags.set(i, 1);\n }\n });\n\n/**\n * Builds a TileCache and NavMesh from the given positions and indices.\n * TileCache assumes small tiles (around 32-64 squared) and does some tricks to make the update fast.\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshConfig optional configuration for the NavMesh\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateTileCache = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<TileCacheGeneratorConfig> = {},\n keepIntermediates = false\n): TileCacheGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n let intermediates: TileCacheGeneratorIntermediates = {\n type: 'tilecache',\n buildContext,\n chunkyTriMesh: undefined,\n tileIntermediates: [],\n };\n\n const tileCache = new TileCache();\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (!keepIntermediates) {\n for (let i = 0; i < intermediates.tileIntermediates.length; i++) {\n const tileIntermediate = intermediates.tileIntermediates[i];\n\n if (tileIntermediate.heightfield) {\n freeHeightfield(tileIntermediate.heightfield);\n tileIntermediate.heightfield = undefined;\n }\n\n if (tileIntermediate.compactHeightfield) {\n freeCompactHeightfield(tileIntermediate.compactHeightfield);\n tileIntermediate.compactHeightfield = undefined;\n }\n\n if (tileIntermediate.heightfieldLayerSet) {\n freeHeightfieldLayerSet(tileIntermediate.heightfieldLayerSet);\n tileIntermediate.heightfieldLayerSet = undefined;\n }\n }\n }\n };\n\n const fail = (error: string): TileCacheGeneratorFailResult => {\n cleanup();\n\n tileCache.destroy();\n navMesh.destroy();\n\n return {\n success: false,\n navMesh: undefined,\n tileCache: undefined,\n intermediates,\n error,\n };\n };\n\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n const { expectedLayersPerTile, maxObstacles, ...recastConfig } = {\n ...tileCacheGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n };\n\n //\n // Step 1. Initialize build config.\n //\n const { raw: config } = RecastConfig.create(recastConfig);\n\n const gridSize = calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n const tileSize = Math.floor(config.tileSize);\n const tileWidth = Math.floor((config.width + tileSize - 1) / tileSize);\n const tileHeight = Math.floor((config.height + tileSize - 1) / tileSize);\n\n // Generation params\n config.borderSize = config.walkableRadius + 3; // Reserve enough padding.\n config.width = config.tileSize + config.borderSize * 2;\n config.height = config.tileSize + config.borderSize * 2;\n\n // Tile cache params\n const tileCacheParams = DetourTileCacheParams.create({\n orig: bbMin,\n cs: config.cs,\n ch: config.ch,\n width: config.tileSize,\n height: config.tileSize,\n walkableHeight: config.walkableHeight,\n walkableRadius: config.walkableRadius,\n walkableClimb: config.walkableClimb,\n maxSimplificationError: config.maxSimplificationError,\n maxTiles: tileWidth * tileHeight * expectedLayersPerTile,\n maxObstacles,\n });\n\n const allocator = new Raw.RecastLinearAllocator(32000);\n const compressor = new Raw.RecastFastLZCompressor();\n\n const tileCacheMeshProcess =\n navMeshGeneratorConfig.tileCacheMeshProcess ??\n createDefaultTileCacheMeshProcess();\n\n if (\n !tileCache.init(\n tileCacheParams,\n allocator,\n compressor,\n tileCacheMeshProcess\n )\n ) {\n return fail('Failed to initialize tile cache');\n }\n\n const orig = vec3.fromArray(bbMin);\n\n // Max tiles and max polys affect how the tile IDs are caculated.\n // There are 22 bits available for identifying a tile and a polygon.\n let tileBits = Math.min(\n Math.floor(\n dtIlog2(dtNextPow2(tileWidth * tileHeight * expectedLayersPerTile))\n ),\n 14\n );\n if (tileBits > 14) {\n tileBits = 14;\n }\n const polyBits = 22 - tileBits;\n\n const maxTiles = 1 << tileBits;\n const maxPolysPerTile = 1 << polyBits;\n\n const navMeshParams = NavMeshParams.create({\n orig,\n tileWidth: config.tileSize * config.cs,\n tileHeight: config.tileSize * config.cs,\n maxTiles,\n maxPolys: maxPolysPerTile,\n });\n\n if (!navMesh.initTiled(navMeshParams)) {\n return fail('Failed to initialize tiled navmesh');\n }\n\n const chunkyTriMesh = new RecastChunkyTriMesh();\n intermediates.chunkyTriMesh = chunkyTriMesh;\n\n if (!chunkyTriMesh.init(vertsArray, trisArray, nTris, 256)) {\n return fail('Failed to build chunky triangle mesh');\n }\n\n const rasterizeTileLayers = (tileX: number, tileY: number) => {\n // Tile intermediates\n const tileIntermediates: TileCacheGeneratorTileIntermediates = {\n tileX,\n tileY,\n };\n\n // Tile bounds\n const tcs = config.tileSize * config.cs;\n\n const { raw: tileConfig } = new RecastConfig(config).clone();\n\n const tileBoundsMin: Vector3Tuple = [\n bbMin[0] + tileX * tcs,\n bbMin[1],\n bbMin[2] + tileY * tcs,\n ];\n\n const tileBoundsMax: Vector3Tuple = [\n bbMin[0] + (tileX + 1) * tcs,\n bbMax[1],\n bbMin[2] + (tileY + 1) * tcs,\n ];\n\n tileBoundsMin[0] -= tileConfig.borderSize * tileConfig.cs;\n tileBoundsMin[2] -= tileConfig.borderSize * tileConfig.cs;\n tileBoundsMax[0] += tileConfig.borderSize * tileConfig.cs;\n tileBoundsMax[2] += tileConfig.borderSize * tileConfig.cs;\n\n tileConfig.set_bmin(0, tileBoundsMin[0]);\n tileConfig.set_bmin(1, tileBoundsMin[1]);\n tileConfig.set_bmin(2, tileBoundsMin[2]);\n\n tileConfig.set_bmax(0, tileBoundsMax[0]);\n tileConfig.set_bmax(1, tileBoundsMax[1]);\n tileConfig.set_bmax(2, tileBoundsMax[2]);\n\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n tileIntermediates.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n tileConfig.width,\n tileConfig.height,\n tileBoundsMin,\n tileBoundsMax,\n tileConfig.cs,\n tileConfig.ch\n )\n ) {\n return { n: 0 };\n }\n\n const tbmin: Vector2Tuple = [tileBoundsMin[0], tileBoundsMin[2]];\n const tbmax: Vector2Tuple = [tileBoundsMax[0], tileBoundsMax[2]];\n\n // TODO: Make grow when returning too many items.\n const maxChunkIds = 512;\n const chunkIdsArray = new Arrays.IntArray();\n chunkIdsArray.resize(maxChunkIds);\n\n const nChunksOverlapping = chunkyTriMesh.getChunksOverlappingRect(\n tbmin,\n tbmax,\n chunkIdsArray,\n maxChunkIds\n );\n\n if (nChunksOverlapping === 0) {\n return { n: 0 };\n }\n\n for (let i = 0; i < nChunksOverlapping; ++i) {\n const nodeId = chunkIdsArray.get_data(i);\n const node = chunkyTriMesh.nodes(nodeId);\n const nNodeTris = node.n;\n\n const nodeTrisArray = chunkyTriMesh.getNodeTris(nodeId);\n\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nNodeTris);\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n markWalkableTriangles(\n buildContext,\n tileConfig.walkableSlopeAngle,\n vertsArray,\n nVerts,\n nodeTrisArray,\n nNodeTris,\n triAreasArray\n );\n\n const success = rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n nodeTrisArray,\n triAreasArray,\n nNodeTris,\n heightfield,\n tileConfig.walkableClimb\n );\n\n triAreasArray.free();\n\n if (!success) {\n return { n: 0 };\n }\n }\n\n // Once all geometry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n config.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n config.walkableHeight,\n heightfield\n );\n\n const compactHeightfield = allocCompactHeightfield();\n if (\n !buildCompactHeightfield(\n buildContext,\n config.walkableHeight,\n config.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return { n: 0 };\n }\n\n if (!keepIntermediates) {\n freeHeightfield(tileIntermediates.heightfield);\n tileIntermediates.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius\n if (\n !erodeWalkableArea(\n buildContext,\n config.walkableRadius,\n compactHeightfield\n )\n ) {\n return { n: 0 };\n }\n\n const heightfieldLayerSet = allocHeightfieldLayerSet();\n if (\n !buildHeightfieldLayers(\n buildContext,\n compactHeightfield,\n config.borderSize,\n config.walkableHeight,\n heightfieldLayerSet\n )\n ) {\n return { n: 0 };\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n tileIntermediates.compactHeightfield = undefined;\n }\n\n const tiles: R.UnsignedCharArray[] = [];\n\n for (let i = 0; i < heightfieldLayerSet.nlayers(); i++) {\n const tile = new Arrays.UnsignedCharArray();\n const heightfieldLayer = heightfieldLayerSet.layers(i);\n\n // Store header\n const header = new Raw.dtTileCacheLayerHeader();\n header.magic = Raw.Detour.TILECACHE_MAGIC;\n header.version = Raw.Detour.TILECACHE_VERSION;\n\n // Tile layer location in the navmesh\n header.tx = tileX;\n header.ty = tileY;\n header.tlayer = i;\n\n const heightfieldLayerBin = heightfieldLayer.bmin();\n const heightfieldLayerBmax = heightfieldLayer.bmax();\n header.set_bmin(0, heightfieldLayerBin.x);\n header.set_bmin(1, heightfieldLayerBin.y);\n header.set_bmin(2, heightfieldLayerBin.z);\n\n header.set_bmax(0, heightfieldLayerBmax.x);\n header.set_bmax(1, heightfieldLayerBmax.y);\n header.set_bmax(2, heightfieldLayerBmax.z);\n\n // Tile info\n header.width = heightfieldLayer.width();\n header.height = heightfieldLayer.height();\n header.minx = heightfieldLayer.minx();\n header.maxx = heightfieldLayer.maxx();\n header.miny = heightfieldLayer.miny();\n header.maxy = heightfieldLayer.maxy();\n header.hmin = heightfieldLayer.hmin();\n header.hmax = heightfieldLayer.hmax();\n\n const heights = getHeightfieldLayerHeights(heightfieldLayer);\n const areas = getHeightfieldLayerAreas(heightfieldLayer);\n const cons = getHeightfieldLayerCons(heightfieldLayer);\n\n const status = buildTileCacheLayer(\n compressor,\n header,\n heights,\n areas,\n cons,\n tile\n );\n\n if (Raw.Detour.statusFailed(status)) {\n return { n: 0 };\n }\n\n tiles.push(tile);\n }\n\n if (!keepIntermediates) {\n freeHeightfieldLayerSet(heightfieldLayerSet);\n tileIntermediates.heightfieldLayerSet = undefined;\n }\n\n intermediates.tileIntermediates.push(tileIntermediates);\n\n return { n: tiles.length, tiles };\n };\n\n // Preprocess tiles\n for (let y = 0; y < tileHeight; ++y) {\n for (let x = 0; x < tileWidth; ++x) {\n const { n, tiles: newTiles } = rasterizeTileLayers(x, y);\n\n if (n > 0 && newTiles) {\n for (let i = 0; i < n; i++) {\n const tileCacheData = newTiles[i];\n\n const addResult = tileCache.addTile(tileCacheData);\n\n if (Raw.Detour.statusFailed(addResult.status)) {\n buildContext.log(\n Raw.Module.RC_LOG_WARNING,\n `Failed to add tile to tile cache - tx: ${x}, ty: ${y}`\n );\n continue;\n }\n }\n }\n }\n }\n\n // Build initial meshes\n for (let y = 0; y < tileHeight; y++) {\n for (let x = 0; x < tileWidth; x++) {\n const dtStatus = tileCache.buildNavMeshTilesAt(x, y, navMesh);\n\n if (Raw.Detour.statusFailed(dtStatus)) {\n return fail(`Failed to build nav mesh tiles at ${x}, ${y}`);\n }\n }\n }\n\n cleanup();\n\n return {\n success: true,\n tileCache,\n navMesh,\n intermediates,\n };\n};\n","import {\n Arrays,\n NavMesh,\n NavMeshCreateParams,\n NavMeshParams,\n Raw,\n RecastBuildContext,\n RecastChunkyTriMesh,\n RecastCompactHeightfield,\n RecastConfig,\n RecastConfigType,\n RecastContourSet,\n RecastHeightfield,\n Vector2Tuple,\n Vector3Tuple,\n allocCompactHeightfield,\n allocContourSet,\n allocHeightfield,\n allocPolyMesh,\n allocPolyMeshDetail,\n buildCompactHeightfield,\n buildContours,\n buildDistanceField,\n buildPolyMesh,\n buildPolyMeshDetail,\n buildRegions,\n calcGridSize,\n createHeightfield,\n createNavMeshData,\n dtStatusToReadableString,\n erodeWalkableArea,\n filterLedgeSpans,\n filterLowHangingWalkableObstacles,\n filterWalkableLowHeightSpans,\n freeCompactHeightfield,\n freeContourSet,\n freeHeightfield,\n markWalkableTriangles,\n rasterizeTriangles,\n recastConfigDefaults,\n vec3,\n} from '@recast-navigation/core';\nimport type R from '@recast-navigation/wasm';\nimport { Pretty } from '../types';\nimport {\n OffMeshConnectionGeneratorParams,\n dtIlog2,\n dtNextPow2,\n getBoundingBox,\n} from './common';\n\nexport type TiledNavMeshGeneratorConfig = Pretty<\n RecastConfigType & OffMeshConnectionGeneratorParams\n>;\n\nexport const tiledNavMeshGeneratorConfigDefaults: TiledNavMeshGeneratorConfig =\n {\n ...recastConfigDefaults,\n };\n\nexport type TiledNavMeshGeneratorIntermediates = {\n type: 'tiled';\n buildContext: RecastBuildContext;\n chunkyTriMesh?: RecastChunkyTriMesh;\n tileIntermediates: {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n }[];\n};\n\ntype TiledNavMeshGeneratorSuccessResult = {\n navMesh: NavMesh;\n success: true;\n intermediates: TiledNavMeshGeneratorIntermediates;\n};\n\ntype TiledNavMeshGeneratorFailResult = {\n navMesh: undefined;\n success: false;\n intermediates: TiledNavMeshGeneratorIntermediates;\n error: string;\n};\n\nexport type TiledNavMeshGeneratorResult =\n | TiledNavMeshGeneratorSuccessResult\n | TiledNavMeshGeneratorFailResult;\n\n/**\n * Builds a Tiled NavMesh\n * @param positions a flat array of positions\n * @param indices a flat array of indices\n * @param navMeshGeneratorConfig optional configuration for the NavMesh generator\n * @param keepIntermediates if true intermediates will be returned\n */\nexport const generateTiledNavMesh = (\n positions: ArrayLike<number>,\n indices: ArrayLike<number>,\n navMeshGeneratorConfig: Partial<TiledNavMeshGeneratorConfig> = {},\n keepIntermediates = false\n): TiledNavMeshGeneratorResult => {\n const buildContext = new RecastBuildContext();\n\n const intermediates: TiledNavMeshGeneratorIntermediates = {\n type: 'tiled',\n buildContext,\n chunkyTriMesh: undefined,\n tileIntermediates: [],\n };\n\n const navMesh = new NavMesh();\n\n const cleanup = () => {\n if (keepIntermediates) return;\n\n for (let i = 0; i < intermediates.tileIntermediates.length; i++) {\n const tileIntermediate = intermediates.tileIntermediates[i];\n\n if (tileIntermediate.compactHeightfield) {\n freeCompactHeightfield(tileIntermediate.compactHeightfield);\n }\n\n if (tileIntermediate.heightfield) {\n freeHeightfield(tileIntermediate.heightfield);\n }\n\n if (tileIntermediate.contourSet) {\n freeContourSet(tileIntermediate.contourSet);\n }\n }\n\n if (intermediates.chunkyTriMesh) {\n intermediates.chunkyTriMesh = undefined;\n }\n };\n\n const fail = (error: string): TiledNavMeshGeneratorFailResult => {\n cleanup();\n\n navMesh.destroy();\n\n return {\n success: false,\n navMesh: undefined,\n intermediates,\n error,\n };\n };\n\n //\n // Initialize build config.\n //\n const recastConfig = RecastConfig.create({\n ...tiledNavMeshGeneratorConfigDefaults,\n ...navMeshGeneratorConfig,\n });\n const { raw: config } = recastConfig;\n\n /* get input bounding box */\n const { bbMin, bbMax } = getBoundingBox(positions, indices);\n\n /* grid size */\n const gridSize = calcGridSize(bbMin, bbMax, config.cs);\n config.width = gridSize.width;\n config.height = gridSize.height;\n\n config.minRegionArea = config.minRegionArea * config.minRegionArea; // Note: area = size*size\n config.mergeRegionArea = config.mergeRegionArea * config.mergeRegionArea; // Note: area = size*size\n config.tileSize = Math.floor(config.tileSize);\n config.borderSize = config.walkableRadius + 3; // Reserve enough padding.\n config.width = config.tileSize + config.borderSize * 2;\n config.height = config.tileSize + config.borderSize * 2;\n config.detailSampleDist =\n config.detailSampleDist < 0.9 ? 0 : config.cs * config.detailSampleDist;\n config.detailSampleMaxError = config.ch * config.detailSampleMaxError;\n\n // tile size\n const tileSize = Math.floor(config.tileSize);\n const tileWidth = Math.floor((gridSize.width + tileSize - 1) / tileSize);\n const tileHeight = Math.floor((gridSize.height + tileSize - 1) / tileSize);\n const tcs = config.tileSize * config.cs;\n\n /* verts */\n const verts = positions as number[];\n const nVerts = indices.length;\n const vertsArray = new Arrays.FloatArray();\n vertsArray.copy(verts, verts.length);\n\n /* tris */\n const tris = indices as number[];\n const nTris = indices.length / 3;\n const trisArray = new Arrays.IntArray();\n trisArray.copy(tris, tris.length);\n\n /* Create dtNavMeshParams, initialise nav mesh for tiled use */\n const orig = vec3.fromArray(bbMin);\n\n // Max tiles and max polys affect how the tile IDs are caculated.\n // There are 22 bits available for identifying a tile and a polygon.\n let tileBits = Math.min(\n Math.floor(dtIlog2(dtNextPow2(tileWidth * tileHeight))),\n 14\n );\n if (tileBits > 14) tileBits = 14;\n const polyBits = 22 - tileBits;\n\n const maxTiles = 1 << tileBits;\n const maxPolysPerTile = 1 << polyBits;\n\n const navMeshParams = NavMeshParams.create({\n orig,\n tileWidth: config.tileSize * config.cs,\n tileHeight: config.tileSize * config.cs,\n maxTiles,\n maxPolys: maxPolysPerTile,\n });\n\n if (!navMesh.initTiled(navMeshParams)) {\n return fail('Could not init nav mesh for tiled use');\n }\n\n /* create chunky tri mesh */\n const chunkyTriMesh = new RecastChunkyTriMesh();\n intermediates.chunkyTriMesh = chunkyTriMesh;\n\n if (!chunkyTriMesh.init(vertsArray, trisArray, nTris, 256)) {\n return fail('Failed to build chunky triangle mesh');\n }\n\n /** @internal */\n const buildTileMesh = (\n tileX: number,\n tileY: number,\n tileBoundsMin: Vector3Tuple,\n tileBoundsMax: Vector3Tuple\n ):\n | { success: true; data?: R.UnsignedCharArray }\n | { success: false; error: string } => {\n const failTileMesh = (error: string) => {\n buildContext.log(Raw.Module.RC_LOG_ERROR, error);\n\n return { success: false as const, error };\n };\n\n const tileIntermediate: {\n tileX: number;\n tileY: number;\n heightfield?: RecastHeightfield;\n compactHeightfield?: RecastCompactHeightfield;\n contourSet?: RecastContourSet;\n } = { tileX, tileY };\n\n intermediates.tileIntermediates.push(tileIntermediate);\n\n const { raw: tileConfig } = recastConfig.clone();\n\n // Expand the heightfield bounding box by border size to find the extents of geometry we need to build this tile.\n //\n // This is done in order to make sure that the navmesh tiles connect correctly at the borders,\n // and the obstacles close to the border work correctly with the dilation process.\n // No polygons (or contours) will be created on the border area.\n //\n // IMPORTANT!\n //\n // :''''''''':\n // : +-----+ :\n // : | | :\n // : | |<--- tile to build\n // : | | :\n // : +-----+ :<-- geometry needed\n // :.........:\n //\n // You should use this bounding box to query your input geometry.\n //\n // For example if you build a navmesh for terrain, and want the navmesh tiles to match the terrain tile size\n // you will need to pass in data from neighbour terrain tiles too! In a simple case, just pass in all the 8 neighbours,\n // or use the bounding box below to only pass in a sliver of each of the 8 neighbours.\n\n const expandedTileBoundsMin = [...tileBoundsMin] as Vector3Tuple;\n const expandedTileBoundsMax = [...tileBoundsMax] as Vector3Tuple;\n\n expandedTileBoundsMin[0] -= tileConfig.borderSize * tileConfig.cs;\n expandedTileBoundsMin[2] -= tileConfig.borderSize * tileConfig.cs;\n\n expandedTileBoundsMax[0] += tileConfig.borderSize * tileConfig.cs;\n expandedTileBoundsMax[2] += tileConfig.borderSize * tileConfig.cs;\n\n tileConfig.set_bmin(0, expandedTileBoundsMin[0]);\n tileConfig.set_bmin(1, expandedTileBoundsMin[1]);\n tileConfig.set_bmin(2, expandedTileBoundsMin[2]);\n\n tileConfig.set_bmax(0, expandedTileBoundsMax[0]);\n tileConfig.set_bmax(1, expandedTileBoundsMax[1]);\n tileConfig.set_bmax(2, expandedTileBoundsMax[2]);\n\n // Reset build timer\n buildContext.resetTimers();\n\n // Start the build process\n buildContext.startTimer(Raw.Module.RC_TIMER_TOTAL);\n\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n `Building tile ${intermediates.tileIntermediates.length} at x: ${tileX}, y: ${tileY}`\n );\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n ` - ${config.width} x ${config.height} cells`\n );\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n ` - ${nVerts / 1000}fK verts, ${nTris / 1000}K tris`\n );\n\n // Allocate voxel heightfield where we rasterize our input data to.\n const heightfield = allocHeightfield();\n tileIntermediate.heightfield = heightfield;\n\n if (\n !createHeightfield(\n buildContext,\n heightfield,\n tileConfig.width,\n tileConfig.height,\n expandedTileBoundsMin,\n expandedTileBoundsMax,\n tileConfig.cs,\n tileConfig.ch\n )\n ) {\n return failTileMesh('Could not create heightfield');\n }\n\n // Allocate array that can hold triangle flags.\n // If you have multiple meshes you need to process, allocate\n // and array which can hold the max number of triangles you need to process.\n const triAreas = new Arrays.UnsignedCharArray();\n triAreas.resize(chunkyTriMesh.maxTrisPerChunk());\n\n const tbmin: Vector2Tuple = [\n expandedTileBoundsMin[0],\n expandedTileBoundsMin[2],\n ];\n const tbmax: Vector2Tuple = [\n expandedTileBoundsMax[0],\n expandedTileBoundsMax[2],\n ];\n\n // TODO: Make grow when returning too many items.\n const maxChunkIds = 512;\n const chunkIdsArray = new Arrays.IntArray();\n chunkIdsArray.resize(maxChunkIds);\n\n const nChunksOverlapping = chunkyTriMesh.getChunksOverlappingRect(\n tbmin,\n tbmax,\n chunkIdsArray,\n maxChunkIds\n );\n\n if (nChunksOverlapping === 0) {\n return { success: true };\n }\n\n for (let i = 0; i < nChunksOverlapping; ++i) {\n const nodeId = chunkIdsArray.get_data(i);\n const node = chunkyTriMesh.nodes(nodeId);\n const nNodeTris = node.n;\n\n const nodeTrisArray = chunkyTriMesh.getNodeTris(nodeId);\n\n const triAreasArray = new Arrays.UnsignedCharArray();\n triAreasArray.resize(nNodeTris);\n\n // Find triangles which are walkable based on their slope and rasterize them.\n // If your input data is multiple meshes, you can transform them here, calculate\n // the are type for each of the meshes and rasterize them.\n markWalkableTriangles(\n buildContext,\n tileConfig.walkableSlopeAngle,\n vertsArray,\n nVerts,\n nodeTrisArray,\n nNodeTris,\n triAreasArray\n );\n\n const success = rasterizeTriangles(\n buildContext,\n vertsArray,\n nVerts,\n nodeTrisArray,\n triAreasArray,\n nNodeTris,\n heightfield,\n tileConfig.walkableClimb\n );\n\n triAreasArray.free();\n\n if (!success) {\n return failTileMesh('Could not rasterize triangles');\n }\n }\n\n // Once all geometry is rasterized, we do initial pass of filtering to\n // remove unwanted overhangs caused by the conservative rasterization\n // as well as filter spans where the character cannot possibly stand.\n filterLowHangingWalkableObstacles(\n buildContext,\n tileConfig.walkableClimb,\n heightfield\n );\n filterLedgeSpans(\n buildContext,\n tileConfig.walkableHeight,\n tileConfig.walkableClimb,\n heightfield\n );\n filterWalkableLowHeightSpans(\n buildContext,\n tileConfig.walkableHeight,\n heightfield\n );\n\n // Compact the heightfield so that it is faster to handle from now on.\n // This will result more cache coherent data as well as the neighbours\n // between walkable cells will be calculated.\n const compactHeightfield = allocCompactHeightfield();\n tileIntermediate.compactHeightfield = compactHeightfield;\n\n if (\n !buildCompactHeightfield(\n buildContext,\n tileConfig.walkableHeight,\n tileConfig.walkableClimb,\n heightfield,\n compactHeightfield\n )\n ) {\n return failTileMesh('Could not build compact heightfield');\n }\n\n if (!keepIntermediates) {\n freeHeightfield(tileIntermediate.heightfield);\n tileIntermediate.heightfield = undefined;\n }\n\n // Erode the walkable area by agent radius\n if (\n !erodeWalkableArea(\n buildContext,\n tileConfig.walkableRadius,\n compactHeightfield\n )\n ) {\n return failTileMesh('Could not erode walkable area');\n }\n\n // (Optional) Mark areas\n // markConvexPolyArea(...)\n\n // Prepare for region partitioning, by calculating Distance field along the walkable surface.\n if (!buildDistanceField(buildContext, compactHeightfield)) {\n return failTileMesh('Failed to build distance field');\n }\n\n // Partition the walkable surface into simple regions without holes.\n if (\n !buildRegions(\n buildContext,\n compactHeightfield,\n tileConfig.borderSize,\n tileConfig.minRegionArea,\n tileConfig.mergeRegionArea\n )\n ) {\n return failTileMesh('Failed to build regions');\n }\n\n //\n // Trace and simplify region contours.\n //\n const contourSet = allocContourSet();\n tileIntermediate.contourSet = contourSet;\n\n if (\n !buildContours(\n buildContext,\n compactHeightfield,\n tileConfig.maxSimplificationError,\n tileConfig.maxEdgeLen,\n contourSet,\n Raw.Module.RC_CONTOUR_TESS_WALL_EDGES\n )\n ) {\n return failTileMesh('Failed to create contours');\n }\n\n //\n // Build polygons mesh from contours.\n //\n const polyMesh = allocPolyMesh();\n if (\n !buildPolyMesh(\n buildContext,\n contourSet,\n tileConfig.maxVertsPerPoly,\n polyMesh\n )\n ) {\n return failTileMesh('Failed to triangulate contours');\n }\n\n //\n // Create detail mesh which allows to access approximate height on each polygon.\n //\n const polyMeshDetail = allocPolyMeshDetail();\n if (\n !buildPolyMeshDetail(\n buildContext,\n polyMesh,\n compactHeightfield,\n tileConfig.detailSampleDist,\n tileConfig.detailSampleMaxError,\n polyMeshDetail\n )\n ) {\n return failTileMesh('Failed to build detail mesh');\n }\n\n if (!keepIntermediates) {\n freeCompactHeightfield(compactHeightfield);\n tileIntermediate.compactHeightfield = undefined;\n\n freeContourSet(contourSet);\n tileIntermediate.contourSet = undefined;\n }\n\n // Update poly flags from areas.\n for (let i = 0; i < polyMesh.npolys(); i++) {\n if (polyMesh.areas(i) == Raw.Recast.WALKABLE_AREA) {\n polyMesh.setAreas(i, 0);\n }\n if (polyMesh.areas(i) == 0) {\n polyMesh.setFlags(i, 1);\n }\n }\n\n const navMeshCreateParams = new NavMeshCreateParams();\n\n navMeshCreateParams.setPolyMeshCreateParams(polyMesh);\n navMeshCreateParams.setPolyMeshDetailCreateParams(polyMeshDetail);\n\n navMeshCreateParams.setWalkableHeight(tileConfig.walkableHeight);\n navMeshCreateParams.setWalkableRadius(tileConfig.walkableRadius);\n navMeshCreateParams.setWalkableClimb(tileConfig.walkableClimb);\n\n navMeshCreateParams.setCellSize(tileConfig.cs);\n navMeshCreateParams.setCellHeight(tileConfig.ch);\n\n navMeshCreateParams.setBuildBvTree(true);\n\n if (navMeshGeneratorConfig.offMeshConnections) {\n navMeshCreateParams.setOffMeshConnections(\n navMeshGeneratorConfig.offMeshConnections\n );\n }\n\n navMeshCreateParams.setTileX(tileX);\n navMeshCreateParams.setTileY(tileY);\n\n const createNavMeshDataResult = createNavMeshData(navMeshCreateParams);\n\n if (!createNavMeshDataResult.success) {\n return failTileMesh('Failed to create Detour navmesh data');\n }\n\n buildContext.log(\n Raw.Module.RC_LOG_PROGRESS,\n `>> Polymesh: ${polyMesh.nverts()} vertices ${polyMesh.npolys()} polygons`\n );\n\n return { success: true, data: createNavMeshDataResult.navMeshData };\n };\n\n buildContext.startTimer(Raw.Module.RC_TIMER_TEMP);\n\n let lastBuiltTileBmin: Vector3Tuple = [0, 0, 0];\n let lastBuiltTileBmax: Vector3Tuple = [0, 0, 0];\n\n for (let y = 0; y < tileHeight; y++) {\n for (let x = 0; x < tileWidth; x++) {\n lastBuiltTileBmin[0] = bbMin[0] + x * tcs;\n lastBuiltTileBmin[1] = bbMin[1];\n lastBuiltTileBmin[2] = bbMin[2] + y * tcs;\n\n lastBuiltTileBmax[0] = bbMin[0] + (x + 1) * tcs;\n lastBuiltTileBmax[1] = bbMax[1];\n lastBuiltTileBmax[2] = bbMin[2] + (y + 1) * tcs;\n\n const result = buildTileMesh(x, y, lastBuiltTileBmin, lastBuiltTileBmax);\n\n if (result.success && result.data) {\n navMesh.removeTile(navMesh.getTileRefAt(x, y, 0));\n\n const addTileResult = navMesh.addTile(\n result.data,\n Raw.Module.DT_TILE_FREE_DATA,\n 0\n );\n\n if (Raw.Detour.statusFailed(addTileResult.status)) {\n buildContext.log(\n Raw.Module.RC_LOG_WARNING,\n `Failed to add tile to nav mesh` +\n '\\n\\t' +\n `tx: ${x}, ty: ${y},` +\n `status: ${dtStatusToReadableString(addTileResult.status)} (${\n addTileResult.status\n })`\n );\n\n result.data.free();\n }\n }\n }\n }\n\n buildContext.stopTimer(Raw.Module.RC_TIMER_TEMP);\n\n if (!keepIntermediates) {\n cleanup();\n }\n\n return {\n success: true,\n navMesh,\n intermediates,\n };\n};\n"],"names":["getBoundingBox","positions","indices","bbMin","x","Infinity","y","z","bbMax","i","length","ind","Math","min","max","vec3","toArray","dtIlog2","v","r","shift","Number","dtNextPow2","soloNavMeshGeneratorConfigDefaults","recastConfigDefaults","generateSoloNavMesh","navMeshGeneratorConfig","keepIntermediates","buildContext","RecastBuildContext","intermediates","type","navMesh","NavMesh","fail","error","heightfield","freeHeightfield","undefined","compactHeightfield","freeCompactHeightfield","contourSet","freeContourSet","destroy","success","verts","nVerts","vertsArray","Arrays","FloatArray","copy","tris","nTris","trisArray","IntArray","raw","config","RecastConfig","create","minRegionArea","mergeRegionArea","detailSampleDist","cs","detailSampleMaxError","ch","gridSize","Raw","Recast","calcGridSize","width","height","allocHeightfield","createHeightfield","triAreasArray","UnsignedCharArray","resize","markWalkableTriangles","walkableSlopeAngle","rasterizeTriangles","walkableClimb","free","filterLowHangingWalkableObstacles","filterLedgeSpans","walkableHeight","filterWalkableLowHeightSpans","allocCompactHeightfield","buildCompactHeightfield","erodeWalkableArea","walkableRadius","buildDistanceField","buildRegions","borderSize","allocContourSet","buildContours","maxSimplificationError","maxEdgeLen","Module","RC_CONTOUR_TESS_WALL_EDGES","polyMesh","allocPolyMesh","buildPolyMesh","maxVertsPerPoly","polyMeshDetail","allocPolyMeshDetail","buildPolyMeshDetail","npolys","areas","WALKABLE_AREA","setAreas","setFlags","navMeshCreateParams","NavMeshCreateParams","setPolyMeshCreateParams","setPolyMeshDetailCreateParams","setWalkableHeight","setWalkableRadius","setWalkableClimb","setCellSize","setCellHeight","setBuildBvTree","offMeshConnections","setOffMeshConnections","createNavMeshDataResult","createNavMeshData","navMeshData","initSolo","tileCacheGeneratorConfigDefaults","tileSize","expectedLayersPerTile","maxObstacles","createDefaultTileCacheMeshProcess","TileCacheMeshProcess","polyAreas","polyFlags","polyCount","set","generateTileCache","chunkyTriMesh","tileIntermediates","tileCache","TileCache","cleanup","tileIntermediate","heightfieldLayerSet","freeHeightfieldLayerSet","recastConfig","floor","tileWidth","tileHeight","tileCacheParams","DetourTileCacheParams","orig","maxTiles","allocator","RecastLinearAllocator","compressor","RecastFastLZCompressor","tileCacheMeshProcess","init","fromArray","tileBits","maxPolysPerTile","navMeshParams","NavMeshParams","maxPolys","initTiled","RecastChunkyTriMesh","rasterizeTileLayers","tileX","tileY","tcs","tileConfig","clone","tileBoundsMin","tileBoundsMax","set_bmin","set_bmax","n","tbmin","tbmax","chunkIdsArray","nChunksOverlapping","getChunksOverlappingRect","nodeId","get_data","nNodeTris","nodes","nodeTrisArray","getNodeTris","allocHeightfieldLayerSet","buildHeightfieldLayers","tiles","nlayers","tile","heightfieldLayer","layers","header","dtTileCacheLayerHeader","magic","Detour","TILECACHE_MAGIC","version","TILECACHE_VERSION","tx","ty","tlayer","heightfieldLayerBin","bmin","heightfieldLayerBmax","bmax","minx","maxx","miny","maxy","hmin","hmax","heights","getHeightfieldLayerHeights","getHeightfieldLayerAreas","cons","getHeightfieldLayerCons","status","buildTileCacheLayer","statusFailed","push","newTiles","tileCacheData","addResult","addTile","log","RC_LOG_WARNING","dtStatus","buildNavMeshTilesAt","tiledNavMeshGeneratorConfigDefaults","generateTiledNavMesh","buildTileMesh","failTileMesh","RC_LOG_ERROR","expandedTileBoundsMin","expandedTileBoundsMax","resetTimers","startTimer","RC_TIMER_TOTAL","RC_LOG_PROGRESS","maxTrisPerChunk","setTileX","setTileY","nverts","data","RC_TIMER_TEMP","lastBuiltTileBmin","lastBuiltTileBmax","result","removeTile","getTileRefAt","addTileResult","DT_TILE_FREE_DATA","dtStatusToReadableString","stopTimer"],"mappings":"qjCAEaA,EAAiB,CAC5BC,EACAC,KAEA,MAAMC,EAAQ,CAAEC,EAAGC,IAAUC,EAAGD,IAAUE,EAAGF,KACvCG,EAAQ,CAAEJ,GAAIC,IAAUC,GAAID,IAAUE,GAAIF,KAEhD,IAAK,IAAII,EAAI,EAAGA,EAAIP,EAAQQ,OAAQD,IAAK,CACvC,MAAME,EAAMT,EAAQO,GAEdL,EAAIH,EAAgB,EAANU,GACdL,EAAIL,EAAgB,EAANU,EAAU,GACxBJ,EAAIN,EAAgB,EAANU,EAAU,GAE9BR,EAAMC,EAAIQ,KAAKC,IAAIV,EAAMC,EAAGA,GAC5BD,EAAMG,EAAIM,KAAKC,IAAIV,EAAMG,EAAGA,GAC5BH,EAAMI,EAAIK,KAAKC,IAAIV,EAAMI,EAAGA,GAE5BC,EAAMJ,EAAIQ,KAAKE,IAAIN,EAAMJ,EAAGA,GAC5BI,EAAMF,EAAIM,KAAKE,IAAIN,EAAMF,EAAGA,GAC5BE,EAAMD,EAAIK,KAAKE,IAAIN,EAAMD,EAAGA,EAC7B,CAED,MAAO,CACLJ,MAAOY,EAAKC,QAAQb,GACpBK,MAAOO,EAAKC,QAAQR,GACrB,EAGUS,EAAWC,IACtB,IAAIC,EAAI,EACJC,EAAQ,EAkBZ,OAhBAD,EAAIE,OAAOH,EAAI,QAAW,EAC1BA,IAAMC,EAENC,EAAQC,OAAOH,EAAI,MAAS,EAC5BA,IAAME,EACND,GAAKC,EAELA,EAAQC,OAAOH,EAAI,KAAQ,EAC3BA,IAAME,EACND,GAAKC,EAELA,EAAQC,OAAOH,EAAI,IAAQ,EAE3BC,GAAKC,EACLD,IAFAD,IAAME,IAEI,EAEHD,CAAC,EAGGG,EAA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EAAG,IAE9C,MAAMyP,EAAgB/N,EAAQoM,QAC5BwB,EAAOJ,KACPtL,EAAI8B,OAAOgK,kBACX,GAGE9L,EAAIqI,OAAOwB,aAAagC,EAAclC,UACxCjM,EAAayM,IACXnK,EAAI8B,OAAOsI,eAGT,yCAAOlO,UAAUE,aACN2P,EAAyBF,EAAclC,YAChDkC,EAAclC,WAIpB+B,EAAOJ,KAAKxK,OAEf,CACF,CASH,OANApD,EAAasO,UAAUhM,EAAI8B,OAAOyJ,eAE7B9N,GACHkH,IAGK,CACLjG,SAAS,EACTZ,UACAF,gBACD"}
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@recast-navigation/generators",
|
|
3
|
+
"description": "NavMesh generator implementations for @recast-navigation/core",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Isaac Mason",
|
|
6
|
+
"email": "isaac@isaacmason.com",
|
|
7
|
+
"url": "https://isaacmason.com/"
|
|
8
|
+
},
|
|
9
|
+
"version": "0.14.0",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://github.com/isaac-mason/recast-navigation-js",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/isaac-mason/recast-navigation-js/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "rollup --config rollup.config.js --bundleConfigAsCjs"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@recast-navigation/core": "0.14.0",
|
|
28
|
+
"@recast-navigation/wasm": "0.14.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
32
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
33
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
34
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.7.3",
|
|
37
|
+
"eslint": "^8.51.0",
|
|
38
|
+
"eslint-config-airbnb": "^18.2.1",
|
|
39
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
40
|
+
"eslint-config-prettier": "^9.0.0",
|
|
41
|
+
"eslint-import-resolver-typescript": "^3.5.5",
|
|
42
|
+
"eslint-plugin-es": "^4.1.0",
|
|
43
|
+
"eslint-plugin-import": "^2.29.0",
|
|
44
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
45
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
46
|
+
"eslint-plugin-typescript-enum": "^2.1.0",
|
|
47
|
+
"prettier": "^3.0.2",
|
|
48
|
+
"rollup": "^3.26.3",
|
|
49
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
50
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
51
|
+
"typescript": "^5.1.6"
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "yarn@3.2.1"
|
|
54
|
+
}
|