@recast-navigation/generators 0.0.0-canary-20261030-064e4acc

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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright © 2025 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 { type 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,82 @@
1
+ import { NavMesh, RecastBuildContext, type RecastCompactHeightfield, type RecastConfig, type RecastContourSet, type RecastHeightfield, type RecastPolyMesh, type RecastPolyMeshDetail, type UnsignedCharArray, type Vector3Tuple } from '@recast-navigation/core';
2
+ import type { Pretty } from '../types';
3
+ import { type OffMeshConnectionGeneratorParams } from './common';
4
+ export type SoloNavMeshGeneratorConfig = Pretty<Omit<RecastConfig, 'tileSize'> & OffMeshConnectionGeneratorParams & {
5
+ /**
6
+ * @default true
7
+ */
8
+ buildBvTree?: boolean;
9
+ /**
10
+ * The minimum and maximum bounds of the heightfield's AABB in world units.
11
+ * If not provided, the bounding box will be calculated from the input positions and indices
12
+ */
13
+ bounds?: [bbMin: Vector3Tuple, bbMax: Vector3Tuple];
14
+ }>;
15
+ export declare const soloNavMeshGeneratorConfigDefaults: {
16
+ buildBvTree: true;
17
+ borderSize: number;
18
+ tileSize: number;
19
+ cs: number;
20
+ ch: number;
21
+ walkableSlopeAngle: number;
22
+ walkableHeight: number;
23
+ walkableClimb: number;
24
+ walkableRadius: number;
25
+ maxEdgeLen: number;
26
+ maxSimplificationError: number;
27
+ minRegionArea: number;
28
+ mergeRegionArea: number;
29
+ maxVertsPerPoly: number;
30
+ detailSampleDist: number;
31
+ detailSampleMaxError: number;
32
+ };
33
+ export type SoloNavMeshGeneratorIntermediates = {
34
+ type: 'solo';
35
+ buildContext: RecastBuildContext;
36
+ heightfield?: RecastHeightfield;
37
+ compactHeightfield?: RecastCompactHeightfield;
38
+ contourSet?: RecastContourSet;
39
+ polyMesh?: RecastPolyMesh;
40
+ polyMeshDetail?: RecastPolyMeshDetail;
41
+ };
42
+ type GenerateSoloNavMeshDataSuccessResult = {
43
+ navMeshData: UnsignedCharArray;
44
+ success: true;
45
+ intermediates: SoloNavMeshGeneratorIntermediates;
46
+ };
47
+ type GenerateSoloNavMeshDataFailResult = {
48
+ navMeshData: undefined;
49
+ success: false;
50
+ intermediates: SoloNavMeshGeneratorIntermediates;
51
+ error: string;
52
+ };
53
+ export type GenerateSoloNavMeshDataResult = GenerateSoloNavMeshDataSuccessResult | GenerateSoloNavMeshDataFailResult;
54
+ /**
55
+ * Builds Solo NavMesh data from the given positions and indices.
56
+ * @param positions a flat array of positions
57
+ * @param indices a flat array of indices
58
+ * @param navMeshGeneratorConfig optional configuration for the NavMesh generator
59
+ * @param keepIntermediates if true intermediates will be returned
60
+ */
61
+ export declare const generateSoloNavMeshData: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<SoloNavMeshGeneratorConfig>, keepIntermediates?: boolean) => GenerateSoloNavMeshDataResult;
62
+ type GenerateSoloNavMeshSuccessResult = {
63
+ navMesh: NavMesh;
64
+ success: true;
65
+ intermediates: SoloNavMeshGeneratorIntermediates;
66
+ };
67
+ type GenerateSoloNavMeshFailResult = {
68
+ navMesh: undefined;
69
+ success: false;
70
+ intermediates: SoloNavMeshGeneratorIntermediates;
71
+ error: string;
72
+ };
73
+ export type GenerateSoloNavMeshResult = GenerateSoloNavMeshSuccessResult | GenerateSoloNavMeshFailResult;
74
+ /**
75
+ * Builds a Solo NavMesh from the given positions and indices.
76
+ * @param positions a flat array of positions
77
+ * @param indices a flat array of indices
78
+ * @param navMeshGeneratorConfig optional configuration for the NavMesh generator
79
+ * @param keepIntermediates if true intermediates will be returned
80
+ */
81
+ export declare const generateSoloNavMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<SoloNavMeshGeneratorConfig>, keepIntermediates?: boolean) => GenerateSoloNavMeshResult;
82
+ export {};
@@ -0,0 +1,63 @@
1
+ import { NavMesh, RecastBuildContext, RecastChunkyTriMesh, type RecastCompactHeightfield, type RecastConfig, type RecastHeightfield, type RecastHeightfieldLayerSet, TileCache, TileCacheMeshProcess, type Vector3Tuple } from '@recast-navigation/core';
2
+ import type { Pretty } from '../types';
3
+ type TileCacheRecastConfig = Omit<RecastConfig, 'minRegionArea' | 'maxEdgeLen'>;
4
+ export type TileCacheGeneratorConfig = Pretty<TileCacheRecastConfig & {
5
+ /**
6
+ * The minimum and maximum bounds of the heightfield's AABB in world units.
7
+ * If not provided, the bounding box will be calculated from the input positions and indices
8
+ */
9
+ bounds?: [bbMin: Vector3Tuple, bbMax: Vector3Tuple];
10
+ /**
11
+ * How many layers (or "floors") each navmesh tile is expected to have.
12
+ */
13
+ expectedLayersPerTile: number;
14
+ /**
15
+ * The max number of obstacles
16
+ */
17
+ maxObstacles: number;
18
+ /**
19
+ * The tile cache mesh process implementation.
20
+ * If not provided, a default one is created via `createDefaultTileCacheMeshProcess()`
21
+ * @default createDefaultTileCacheMeshProcess()
22
+ */
23
+ tileCacheMeshProcess?: TileCacheMeshProcess;
24
+ }>;
25
+ export declare const tileCacheGeneratorConfigDefaults: TileCacheGeneratorConfig;
26
+ export type TileCacheGeneratorTileIntermediates = {
27
+ tileX: number;
28
+ tileY: number;
29
+ heightfield?: RecastHeightfield;
30
+ compactHeightfield?: RecastCompactHeightfield;
31
+ heightfieldLayerSet?: RecastHeightfieldLayerSet;
32
+ };
33
+ export type TileCacheGeneratorIntermediates = {
34
+ type: 'tilecache';
35
+ buildContext: RecastBuildContext;
36
+ chunkyTriMesh?: RecastChunkyTriMesh;
37
+ tileIntermediates: TileCacheGeneratorTileIntermediates[];
38
+ };
39
+ type TileCacheGeneratorSuccessResult = {
40
+ tileCache: TileCache;
41
+ navMesh: NavMesh;
42
+ success: true;
43
+ intermediates: TileCacheGeneratorIntermediates;
44
+ };
45
+ type TileCacheGeneratorFailResult = {
46
+ tileCache: undefined;
47
+ navMesh: undefined;
48
+ success: false;
49
+ error: string;
50
+ intermediates: TileCacheGeneratorIntermediates;
51
+ };
52
+ export type TileCacheGeneratorResult = TileCacheGeneratorSuccessResult | TileCacheGeneratorFailResult;
53
+ export declare const createDefaultTileCacheMeshProcess: () => TileCacheMeshProcess;
54
+ /**
55
+ * Builds a TileCache and NavMesh from the given positions and indices.
56
+ * TileCache assumes small tiles (around 32-64 squared) and does some tricks to make the update fast.
57
+ * @param positions a flat array of positions
58
+ * @param indices a flat array of indices
59
+ * @param navMeshConfig optional configuration for the NavMesh
60
+ * @param keepIntermediates if true intermediates will be returned
61
+ */
62
+ export declare const generateTileCache: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TileCacheGeneratorConfig>, keepIntermediates?: boolean) => TileCacheGeneratorResult;
63
+ export {};
@@ -0,0 +1,111 @@
1
+ import { type FloatArray, type IntArray, NavMesh, type OffMeshConnectionParams, type RawModule, RecastBuildContext, RecastChunkyTriMesh, type RecastCompactHeightfield, type RecastConfig, type RecastContourSet, type RecastHeightfield, type RecastPolyMesh, type RecastPolyMeshDetail, type UnsignedCharArray, type Vector3Tuple } from '@recast-navigation/core';
2
+ import type { Pretty } from '../types';
3
+ import { type OffMeshConnectionGeneratorParams } from './common';
4
+ export declare const buildTiledNavMeshRcConfig: ({ recastConfig, navMeshBounds: [navMeshBoundsMin, navMeshBoundsMax], }: {
5
+ recastConfig: RecastConfig;
6
+ navMeshBounds: [min: Vector3Tuple, max: Vector3Tuple];
7
+ }) => {
8
+ config: RawModule.rcConfig;
9
+ gridSize: RawModule.RecastCalcGridSizeResult;
10
+ tileSize: number;
11
+ tileWidth: number;
12
+ tileHeight: number;
13
+ tcs: number;
14
+ orig: {
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ };
19
+ maxTiles: number;
20
+ maxPolysPerTile: number;
21
+ };
22
+ export type TiledNavMeshGeneratorConfig = Pretty<RecastConfig & OffMeshConnectionGeneratorParams & {
23
+ /**
24
+ * The minimum and maximum bounds of the heightfield's AABB in world units.
25
+ * If not provided, the bounding box will be calculated from the input positions and indices
26
+ */
27
+ bounds?: [bbMin: Vector3Tuple, bbMax: Vector3Tuple];
28
+ /**
29
+ * @default 128
30
+ */
31
+ chunkyTriMeshTrisPerChunk?: number;
32
+ /**
33
+ * @default true
34
+ */
35
+ buildBvTree?: boolean;
36
+ }>;
37
+ export declare const tiledNavMeshGeneratorConfigDefaults: {
38
+ chunkyTriMeshTrisPerChunk: number;
39
+ buildBvTree: true;
40
+ borderSize: number;
41
+ tileSize: number;
42
+ cs: number;
43
+ ch: number;
44
+ walkableSlopeAngle: number;
45
+ walkableHeight: number;
46
+ walkableClimb: number;
47
+ walkableRadius: number;
48
+ maxEdgeLen: number;
49
+ maxSimplificationError: number;
50
+ minRegionArea: number;
51
+ mergeRegionArea: number;
52
+ maxVertsPerPoly: number;
53
+ detailSampleDist: number;
54
+ detailSampleMaxError: number;
55
+ };
56
+ type TileIntermediates = {
57
+ x: number;
58
+ y: number;
59
+ heightfield?: RecastHeightfield;
60
+ compactHeightfield?: RecastCompactHeightfield;
61
+ contourSet?: RecastContourSet;
62
+ polyMesh?: RecastPolyMesh;
63
+ polyMeshDetail?: RecastPolyMeshDetail;
64
+ };
65
+ type GenerateTileNavMeshDataSuccessResult = {
66
+ success: true;
67
+ data?: UnsignedCharArray;
68
+ intermediates: TileIntermediates;
69
+ };
70
+ type GenerateTileNavMeshDataFailResult = {
71
+ success: false;
72
+ error: string;
73
+ intermediates: TileIntermediates;
74
+ };
75
+ export type GenerateTileNavMeshDataResult = GenerateTileNavMeshDataSuccessResult | GenerateTileNavMeshDataFailResult;
76
+ export declare const generateTileNavMeshData: (positions: FloatArray, indices: IntArray, rcConfig: RawModule.rcConfig, chunkyTriMesh: RecastChunkyTriMesh, tile: {
77
+ x: number;
78
+ y: number;
79
+ bmin: Vector3Tuple;
80
+ bmax: Vector3Tuple;
81
+ }, options?: {
82
+ offMeshConnections?: OffMeshConnectionParams[];
83
+ buildBvTree?: boolean;
84
+ }, keepIntermediates?: boolean, buildContextParam?: RecastBuildContext) => GenerateTileNavMeshDataResult;
85
+ export type TiledNavMeshGeneratorIntermediates = {
86
+ type: 'tiled';
87
+ buildContext: RecastBuildContext;
88
+ chunkyTriMesh?: RecastChunkyTriMesh;
89
+ tileIntermediates: TileIntermediates[];
90
+ };
91
+ type GenerateTiledNavMeshSuccessResult = {
92
+ navMesh: NavMesh;
93
+ success: true;
94
+ intermediates: TiledNavMeshGeneratorIntermediates;
95
+ };
96
+ type GenerateTiledNavMeshFailResult = {
97
+ navMesh: undefined;
98
+ success: false;
99
+ intermediates: TiledNavMeshGeneratorIntermediates;
100
+ error: string;
101
+ };
102
+ export type GenerateTiledNavMeshResult = GenerateTiledNavMeshSuccessResult | GenerateTiledNavMeshFailResult;
103
+ /**
104
+ * Builds a Tiled NavMesh
105
+ * @param positions a flat array of positions
106
+ * @param indices a flat array of indices
107
+ * @param navMeshGeneratorConfig optional configuration for the NavMesh generator
108
+ * @param keepIntermediates if true intermediates will be returned
109
+ */
110
+ export declare const generateTiledNavMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TiledNavMeshGeneratorConfig>, keepIntermediates?: boolean) => GenerateTiledNavMeshResult;
111
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './common';
2
+ export * from './generate-solo-nav-mesh';
3
+ export * from './generate-tile-cache';
4
+ export * from './generate-tiled-nav-mesh';
5
+ export * from './merge-positions-and-indices';
@@ -0,0 +1,4 @@
1
+ export declare const mergePositionsAndIndices: (meshes: Array<{
2
+ positions: ArrayLike<number>;
3
+ indices: ArrayLike<number>;
4
+ }>) => [Float32Array, Uint32Array];
@@ -0,0 +1 @@
1
+ export * from './generators';