To get started, use the generateSoloNavMesh function from navcat/blocks to create a navigation mesh from geometry, and then use findPath from navcat to perform pathfinding.
Workflow:
- Prepare
positions (Float32Array) and indices (Uint32Array) from your level geometry. - Define
SoloNavMeshInput containing your geometry. - Configure
SoloNavMeshOptions (see parameter table below). - Call
generateSoloNavMesh(input, options) to get the navMesh. - Use
findPath(navMesh, start, end, halfExtents, filter) to find a path.
import { DEFAULT_QUERY_FILTER, findPath, type Vec3 } from 'navcat';
import { generateSoloNavMesh, type SoloNavMeshInput, type SoloNavMeshOptions } from 'navcat/blocks';
/* generation input */
const positions = new Float32Array([/* ... */]);
const indices = new Uint32Array([/* ... */]);
const input: SoloNavMeshInput = {
positions,
indices,
};
/* generation options */
const options: SoloNavMeshOptions = {
cellSize: 0.15,
cellHeight: 0.25,
walkableRadiusWorld: 0.3,
walkableRadiusVoxels: Math.ceil(0.3 / 0.15),
walkableClimbWorld: 0.5,
walkableClimbVoxels: Math.ceil(0.5 / 0.25),
walkableHeightWorld: 2.0,
walkableHeightVoxels: Math.ceil(2.0 / 0.25),
walkableSlopeAngleDegrees: 45,
borderSize: 0,
minRegionArea: 8,
mergeRegionArea: 20,
maxSimplificationError: 1.3,
maxEdgeLength: 12,
maxVerticesPerPoly: 5,
detailSampleDistance: 0.15 * 6,
detailSampleMaxError: 0.25 * 1,
};
/* generate the navmesh */
const result = generateSoloNavMesh(input, options);
const navMesh = result.navMesh;
/* find a path */
const start: Vec3 = [-4, 0, -4];
const end: Vec3 = [4, 0, 4];
const halfExtents: Vec3 = [0.5, 0.5, 0.5];
const path = findPath(navMesh, start, end, halfExtents, DEFAULT_QUERY_FILTER);
console.log('path:', path.path.map((p) => p.position));