@onerjs/addons 8.27.0 → 8.27.2

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.
Files changed (82) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/index.js.map +1 -1
  4. package/navigation/common/config.d.ts +35 -0
  5. package/navigation/common/config.js +61 -0
  6. package/navigation/common/config.js.map +1 -0
  7. package/navigation/common/convert.d.ts +8 -0
  8. package/navigation/common/convert.js +22 -0
  9. package/navigation/common/convert.js.map +1 -0
  10. package/navigation/common/getters.d.ts +15 -0
  11. package/navigation/common/getters.js +76 -0
  12. package/navigation/common/getters.js.map +1 -0
  13. package/navigation/common/index.d.ts +6 -0
  14. package/navigation/common/index.js +7 -0
  15. package/navigation/common/index.js.map +1 -0
  16. package/navigation/common/smooth-path.d.ts +32 -0
  17. package/navigation/common/smooth-path.js +340 -0
  18. package/navigation/common/smooth-path.js.map +1 -0
  19. package/navigation/common/tile-cache.d.ts +15 -0
  20. package/navigation/common/tile-cache.js +32 -0
  21. package/navigation/common/tile-cache.js.map +1 -0
  22. package/navigation/common/utils.d.ts +17 -0
  23. package/navigation/common/utils.js +66 -0
  24. package/navigation/common/utils.js.map +1 -0
  25. package/navigation/debug/NavigationDebugger.d.ts +248 -0
  26. package/navigation/debug/NavigationDebugger.js +587 -0
  27. package/navigation/debug/NavigationDebugger.js.map +1 -0
  28. package/navigation/debug/index.d.ts +2 -0
  29. package/navigation/debug/index.js +3 -0
  30. package/navigation/debug/index.js.map +1 -0
  31. package/navigation/debug/simple-debug.d.ts +13 -0
  32. package/navigation/debug/simple-debug.js +23 -0
  33. package/navigation/debug/simple-debug.js.map +1 -0
  34. package/navigation/factory/common.d.ts +20 -0
  35. package/navigation/factory/common.js +80 -0
  36. package/navigation/factory/common.js.map +1 -0
  37. package/navigation/factory/factory.single-thread.d.ts +7 -0
  38. package/navigation/factory/factory.single-thread.js +15 -0
  39. package/navigation/factory/factory.single-thread.js.map +1 -0
  40. package/navigation/factory/factory.wasm.d.ts +7 -0
  41. package/navigation/factory/factory.wasm.js +15 -0
  42. package/navigation/factory/factory.wasm.js.map +1 -0
  43. package/navigation/factory/factory.worker.d.ts +9 -0
  44. package/navigation/factory/factory.worker.js +40 -0
  45. package/navigation/factory/factory.worker.js.map +1 -0
  46. package/navigation/factory/index.d.ts +2 -0
  47. package/navigation/factory/index.js +4 -0
  48. package/navigation/factory/index.js.map +1 -0
  49. package/navigation/generator/generator.common.d.ts +25 -0
  50. package/navigation/generator/generator.common.js +40 -0
  51. package/navigation/generator/generator.common.js.map +1 -0
  52. package/navigation/generator/generator.single-thread.d.ts +20 -0
  53. package/navigation/generator/generator.single-thread.js +57 -0
  54. package/navigation/generator/generator.single-thread.js.map +1 -0
  55. package/navigation/generator/generator.worker.d.ts +29 -0
  56. package/navigation/generator/generator.worker.js +47 -0
  57. package/navigation/generator/generator.worker.js.map +1 -0
  58. package/navigation/generator/index.d.ts +3 -0
  59. package/navigation/generator/index.js +5 -0
  60. package/navigation/generator/index.js.map +1 -0
  61. package/navigation/generator/injection.d.ts +6 -0
  62. package/navigation/generator/injection.js +16 -0
  63. package/navigation/generator/injection.js.map +1 -0
  64. package/navigation/index.d.ts +5 -0
  65. package/navigation/index.js +7 -0
  66. package/navigation/index.js.map +1 -0
  67. package/navigation/plugin/RecastJSCrowd.d.ts +198 -0
  68. package/navigation/plugin/RecastJSCrowd.js +359 -0
  69. package/navigation/plugin/RecastJSCrowd.js.map +1 -0
  70. package/navigation/plugin/RecastNavigationJSPlugin.d.ts +396 -0
  71. package/navigation/plugin/RecastNavigationJSPlugin.js +445 -0
  72. package/navigation/plugin/RecastNavigationJSPlugin.js.map +1 -0
  73. package/navigation/plugin/index.d.ts +1 -0
  74. package/navigation/plugin/index.js +2 -0
  75. package/navigation/plugin/index.js.map +1 -0
  76. package/navigation/types.d.ts +199 -0
  77. package/navigation/types.js +11 -0
  78. package/navigation/types.js.map +1 -0
  79. package/navigation/worker/navmesh-worker.d.ts +4 -0
  80. package/navigation/worker/navmesh-worker.js +63 -0
  81. package/navigation/worker/navmesh-worker.js.map +1 -0
  82. package/package.json +2 -2
@@ -0,0 +1,445 @@
1
+ import { Logger } from "@onerjs/core/Misc/logger.js";
2
+ import { TmpVectors, Vector3 } from "@onerjs/core/Maths/math.js";
3
+ import { RecastJSCrowd } from "./RecastJSCrowd.js";
4
+ import { ConvertNavPathPoints } from "../common/convert.js";
5
+ import { ComputeSmoothPath } from "../common/smooth-path.js";
6
+ import { CreateDebugNavMesh } from "../debug/simple-debug.js";
7
+ import { GetRecast } from "../factory/common.js";
8
+ import { InjectGenerators } from "../generator/injection.js";
9
+ import { DefaultMaxObstacles } from "../common/config.js";
10
+ import { WaitForFullTileCacheUpdate } from "../common/tile-cache.js";
11
+ /**
12
+ * Navigation plugin for Babylon.js. It is a simple wrapper around the recast-navigation-js library. Not all features are implemented.
13
+ * @remarks This plugin provides navigation mesh generation and pathfinding capabilities using the recast-navigation-js library
14
+ * @remarks It supports both single-threaded and multi-threaded generation of navigation meshes.
15
+ * @remarks The plugin can be used to create navigation meshes from meshes in a scene, compute paths, and manage crowd agents, etc.
16
+ * @remarks It also provides methods for creating obstacles and querying the navigation mesh.
17
+ * @see https://github.com/isaac-mason/recast-navigation-js
18
+ */
19
+ export class RecastNavigationJSPluginV2 {
20
+ /**
21
+ * The navmesh query created from the navmesh
22
+ * @remarks This is used to query the navmesh for pathfinding and other navigation tasks
23
+ */
24
+ get navMeshQuery() {
25
+ return this._navMeshQuery;
26
+ }
27
+ /**
28
+ * Creates a RecastNavigationJSPluginV2 instance
29
+ * @param recastInjection The recast-navigation-js injection containing core and generators
30
+ */
31
+ constructor(recastInjection) {
32
+ /**
33
+ * plugin name
34
+ */
35
+ this.name = "RecastNavigationJSPlugin";
36
+ // Crowd specific properties
37
+ this._maximumSubStepCount = 10;
38
+ this._timeStep = 1 / 60;
39
+ this._timeFactor = 1;
40
+ if (!recastInjection) {
41
+ recastInjection = GetRecast();
42
+ InjectGenerators(this);
43
+ }
44
+ this.bjsRECAST = recastInjection;
45
+ if (!this.isSupported()) {
46
+ Logger.Error("RecastJS is not available. Please make sure you included the js file.");
47
+ return;
48
+ }
49
+ this.setTimeStep();
50
+ }
51
+ /**
52
+ * Set the time step of the navigation tick update.
53
+ * Default is 1/60.
54
+ * A value of 0 will disable fixed time update
55
+ * @param newTimeStep the new timestep to apply to this world.
56
+ */
57
+ setTimeStep(newTimeStep = 1 / 60) {
58
+ this._timeStep = newTimeStep;
59
+ }
60
+ /**
61
+ * Get the time step of the navigation tick update.
62
+ * @returns the current time step
63
+ */
64
+ getTimeStep() {
65
+ return this._timeStep;
66
+ }
67
+ /**
68
+ * If delta time in navigation tick update is greater than the time step
69
+ * a number of sub iterations are done. If more iterations are need to reach deltatime
70
+ * they will be discarded.
71
+ * A value of 0 will set to no maximum and update will use as many substeps as needed
72
+ * @param newStepCount the maximum number of iterations
73
+ */
74
+ setMaximumSubStepCount(newStepCount = 10) {
75
+ this._maximumSubStepCount = newStepCount;
76
+ }
77
+ /**
78
+ * Get the maximum number of iterations per navigation tick update
79
+ * @returns the maximum number of iterations
80
+ */
81
+ getMaximumSubStepCount() {
82
+ return this._maximumSubStepCount;
83
+ }
84
+ /**
85
+ * Time factor applied when updating crowd agents (default 1). A value of 0 will pause crowd updates.
86
+ * @param value the time factor applied at update
87
+ */
88
+ set timeFactor(value) {
89
+ this._timeFactor = Math.max(value, 0);
90
+ }
91
+ /**
92
+ * Get the time factor used for crowd agent update
93
+ * @returns the time factor
94
+ */
95
+ get timeFactor() {
96
+ return this._timeFactor;
97
+ }
98
+ /**
99
+ * Creates a navigation mesh - will be injected by the factory
100
+ * @param meshes array of all the geometry used to compute the navigation mesh
101
+ * @param parameters bunch of parameters used to filter geometry
102
+ * @returns the created navmesh and navmesh query
103
+ * @throws Error if the function is not injected yet or if the navmesh is not created
104
+ */
105
+ createNavMesh(meshes, parameters) {
106
+ if (!this.createNavMeshImpl) {
107
+ throw new Error("Function not injected yet. Use the factory to create the plugin.");
108
+ }
109
+ this._preprocessParameters(parameters);
110
+ const result = this.createNavMeshImpl(meshes, parameters);
111
+ return this._processNavMeshResult(result);
112
+ }
113
+ /**
114
+ * Creates a navigation mesh asynchronously - will be injected by the factory
115
+ * @param meshes array of all the geometry used to compute the navigation mesh
116
+ * @param parameters bunch of parameters used to filter geometry
117
+ * @returns the created navmesh and navmesh query
118
+ * @throws Error if the function is not injected yet or if the navmesh is not created
119
+ */
120
+ async createNavMeshAsync(meshes, parameters) {
121
+ if (!this.createNavMeshAsyncImpl) {
122
+ throw new Error("Function not injected yet. Use the factory to create the plugin.");
123
+ }
124
+ this._preprocessParameters(parameters);
125
+ const result = await this.createNavMeshAsyncImpl(meshes, parameters);
126
+ return this._processNavMeshResult(result);
127
+ }
128
+ /**
129
+ * Create a navigation mesh debug mesh
130
+ * @param scene is where the mesh will be added
131
+ * @returns debug display mesh
132
+ */
133
+ createDebugNavMesh(scene) {
134
+ if (!this.navMesh) {
135
+ throw new Error("There is no navMesh generated.");
136
+ }
137
+ if (this.navMesh && this.tileCache) {
138
+ WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);
139
+ }
140
+ return CreateDebugNavMesh(this.navMesh, scene);
141
+ }
142
+ /**
143
+ * Get a navigation mesh constrained position, closest to the parameter position
144
+ * @param position world position
145
+ * @returns the closest point to position constrained by the navigation mesh
146
+ */
147
+ getClosestPoint(position, options) {
148
+ const ret = this._navMeshQuery.findClosestPoint(position, options);
149
+ const pr = new Vector3(ret.point.x, ret.point.y, ret.point.z);
150
+ return pr;
151
+ }
152
+ /**
153
+ * Get a navigation mesh constrained position, closest to the parameter position
154
+ * @param position world position
155
+ * @param result output the closest point to position constrained by the navigation mesh
156
+ */
157
+ getClosestPointToRef(position, result, options) {
158
+ const ret = this._navMeshQuery.findClosestPoint(position, options);
159
+ result.set(ret.point.x, ret.point.y, ret.point.z);
160
+ }
161
+ /**
162
+ * Get a navigation mesh constrained position, within a particular radius
163
+ * @param position world position
164
+ * @param maxRadius the maximum distance to the constrained world position
165
+ * @returns the closest point to position constrained by the navigation mesh
166
+ */
167
+ getRandomPointAround(position, maxRadius, options) {
168
+ const ret = this._navMeshQuery.findRandomPointAroundCircle(position, maxRadius, options);
169
+ const pr = new Vector3(ret.randomPoint.x, ret.randomPoint.y, ret.randomPoint.z);
170
+ return pr;
171
+ }
172
+ /**
173
+ * Get a navigation mesh constrained position, within a particular radius
174
+ * @param position world position
175
+ * @param maxRadius the maximum distance to the constrained world position
176
+ * @param result output the closest point to position constrained by the navigation mesh
177
+ */
178
+ getRandomPointAroundToRef(position, maxRadius, result, options) {
179
+ const ret = this._navMeshQuery.findRandomPointAroundCircle(position, maxRadius, options);
180
+ result.set(ret.randomPoint.x, ret.randomPoint.y, ret.randomPoint.z);
181
+ }
182
+ /**
183
+ * Compute the final position from a segment made of destination-position
184
+ * @param position position to start from
185
+ * @param destination position to go to
186
+ * @param startRef the reference id of the start polygon
187
+ * @param options options for the function
188
+ * @returns the resulting point along the navmesh
189
+ */
190
+ moveAlong(position, destination, startRef = 0, options) {
191
+ const ret = this._navMeshQuery.moveAlongSurface(startRef, position, destination, options);
192
+ const pr = new Vector3(ret.resultPosition.x, ret.resultPosition.y, ret.resultPosition.z);
193
+ return pr;
194
+ }
195
+ /**
196
+ * Compute the final position from a segment made of destination-position
197
+ * @param position world position
198
+ * @param destination world position
199
+ * @param result output the resulting point along the navmesh
200
+ * @param startRef the reference id of the start polygon.
201
+ * @param options options for the function
202
+ */
203
+ moveAlongToRef(position, destination, result, startRef = 0, options) {
204
+ const ret = this._navMeshQuery.moveAlongSurface(startRef, position, destination, options);
205
+ result.set(ret.resultPosition.x, ret.resultPosition.y, ret.resultPosition.z);
206
+ }
207
+ /**
208
+ * Compute a navigation path from start to end. Returns an empty array if no path can be computed
209
+ * Path is straight.
210
+ * @param start world position
211
+ * @param end world position
212
+ * @param options options for the function
213
+ * @returns array containing world position composing the path
214
+ */
215
+ computePath(start, end, options) {
216
+ return ConvertNavPathPoints(this._navMeshQuery.computePath(start, end, options));
217
+ }
218
+ /**
219
+ * Creates a navigation mesh - will be injected by the factory
220
+ * @param start the start position of the navmesh
221
+ * @param end the end position of the navmesh
222
+ * @param options options to configure the path computation
223
+ * @returns array containing world position composing the path
224
+ */
225
+ computePathSmooth(start, end, options) {
226
+ if (!this.navMesh) {
227
+ Logger.Error("No navmesh available. Cannot compute smooth path.");
228
+ return [];
229
+ }
230
+ return ComputeSmoothPath(this.navMesh, this._navMeshQuery, start, end, options);
231
+ }
232
+ /**
233
+ * Create a new Crowd so you can add agents
234
+ * @param maxAgents the maximum agent count in the crowd
235
+ * @param maxAgentRadius the maximum radius an agent can have
236
+ * @param scene to attach the crowd to
237
+ * @returns the crowd you can add agents to
238
+ */
239
+ createCrowd(maxAgents, maxAgentRadius, scene) {
240
+ const crowd = new RecastJSCrowd(this, maxAgents, maxAgentRadius, scene);
241
+ this._crowd = crowd;
242
+ return crowd;
243
+ }
244
+ /**
245
+ * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
246
+ * The queries will try to find a solution within those bounds
247
+ * default is (1,1,1)
248
+ * @param extent x,y,z value that define the extent around the queries point of reference
249
+ */
250
+ setDefaultQueryExtent(extent) {
251
+ this._navMeshQuery.defaultQueryHalfExtents = extent;
252
+ }
253
+ /**
254
+ * Get the Bounding box extent specified by setDefaultQueryExtent
255
+ * @returns the box extent values
256
+ */
257
+ getDefaultQueryExtent() {
258
+ return new Vector3(this._navMeshQuery.defaultQueryHalfExtents.x, this._navMeshQuery.defaultQueryHalfExtents.y, this._navMeshQuery.defaultQueryHalfExtents.z);
259
+ }
260
+ /**
261
+ * Get the Bounding box extent result specified by setDefaultQueryExtent
262
+ * @param result output the box extent values
263
+ */
264
+ getDefaultQueryExtentToRef(result) {
265
+ result.set(this._navMeshQuery.defaultQueryHalfExtents.x, this._navMeshQuery.defaultQueryHalfExtents.y, this._navMeshQuery.defaultQueryHalfExtents.z);
266
+ }
267
+ /**
268
+ * build the navmesh from a previously saved state using getNavmeshData
269
+ * @param data the Uint8Array returned by getNavmeshData
270
+ */
271
+ buildFromNavmeshData(data) {
272
+ const result = this.bjsRECAST.importNavMesh(data);
273
+ this.navMesh = result.navMesh;
274
+ this._navMeshQuery = new this.bjsRECAST.NavMeshQuery(this.navMesh);
275
+ }
276
+ /**
277
+ * returns the navmesh data that can be used later. The navmesh must be built before retrieving the data
278
+ * @returns data the Uint8Array that can be saved and reused
279
+ */
280
+ getNavmeshData() {
281
+ if (!this.navMesh) {
282
+ throw new Error("There is no NavMesh generated.");
283
+ }
284
+ return this.bjsRECAST.exportNavMesh(this.navMesh);
285
+ }
286
+ /**
287
+ * Disposes
288
+ */
289
+ dispose() {
290
+ this._crowd?.dispose();
291
+ this.navMesh?.destroy();
292
+ this._navMeshQuery?.destroy();
293
+ this.tileCache?.destroy();
294
+ }
295
+ /**
296
+ * Creates a cylinder obstacle and add it to the navigation
297
+ * @param position world position
298
+ * @param radius cylinder radius
299
+ * @param height cylinder height
300
+ * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning
301
+ * @returns the obstacle freshly created
302
+ */
303
+ addCylinderObstacle(position, radius, height, doNotWaitForCacheUpdate = false) {
304
+ const obstacleResult = this.tileCache?.addCylinderObstacle(position, radius, height);
305
+ if (!obstacleResult?.success) {
306
+ return null;
307
+ }
308
+ if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {
309
+ WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);
310
+ }
311
+ return obstacleResult.obstacle ?? null;
312
+ }
313
+ /**
314
+ * Creates an oriented box obstacle and add it to the navigation
315
+ * @param position world position
316
+ * @param extent box size
317
+ * @param angle angle in radians of the box orientation on Y axis
318
+ * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning
319
+ * @returns the obstacle freshly created
320
+ */
321
+ addBoxObstacle(position, extent, angle, doNotWaitForCacheUpdate = false) {
322
+ const obstacleResult = this.tileCache?.addBoxObstacle(position, extent, angle);
323
+ if (!obstacleResult?.success) {
324
+ return null;
325
+ }
326
+ if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {
327
+ WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);
328
+ }
329
+ return obstacleResult.obstacle ?? null;
330
+ }
331
+ /**
332
+ * Removes an obstacle created by addCylinderObstacle or addBoxObstacle
333
+ * @param obstacle obstacle to remove from the navigation
334
+ * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning
335
+ *
336
+ */
337
+ removeObstacle(obstacle, doNotWaitForCacheUpdate = false) {
338
+ this.tileCache?.removeObstacle(obstacle);
339
+ if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {
340
+ WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);
341
+ }
342
+ }
343
+ /**
344
+ * If this plugin is supported
345
+ * @returns true if plugin is supported
346
+ */
347
+ isSupported() {
348
+ return !!this.bjsRECAST;
349
+ }
350
+ /**
351
+ * Returns the seed used for randomized functions like `getRandomPointAround`
352
+ * @returns seed number
353
+ */
354
+ getRandomSeed() {
355
+ return this.bjsRECAST.getRandomSeed();
356
+ }
357
+ /**
358
+ * Set the seed used for randomized functions like `getRandomPointAround`
359
+ * @param seed number used as seed for random functions
360
+ */
361
+ setRandomSeed(seed) {
362
+ this.bjsRECAST.setRandomSeed(seed);
363
+ }
364
+ // New funccntions beyond the INavigationEnginePlugin interface
365
+ /**
366
+ * Perform a raycast on the navmesh
367
+ * @param start start position
368
+ * @param end end position
369
+ * @returns if a direct path exists between start and end, and the hit point if any
370
+ */
371
+ raycast(start, end) {
372
+ const nearestStartPoly = this._navMeshQuery.findNearestPoly(start);
373
+ const raycastResult = this._navMeshQuery.raycast(nearestStartPoly.nearestRef, start, end);
374
+ const hit = 0 < raycastResult.t && raycastResult.t < 1.0;
375
+ if (!hit) {
376
+ return {
377
+ hit: false,
378
+ };
379
+ }
380
+ else {
381
+ TmpVectors.Vector3[0].set(start.x, start.y, start.z);
382
+ TmpVectors.Vector3[1].set(end.x, end.y, end.z);
383
+ const distanceToHitBorder = Vector3.Distance(TmpVectors.Vector3[0], TmpVectors.Vector3[1]) * (raycastResult?.t ?? 0);
384
+ const direction = TmpVectors.Vector3[1].subtract(TmpVectors.Vector3[0]).normalize();
385
+ const hitPoint = TmpVectors.Vector3[0].add(direction.multiplyByFloats(distanceToHitBorder, distanceToHitBorder, distanceToHitBorder));
386
+ return {
387
+ hit: true,
388
+ hitPoint,
389
+ };
390
+ }
391
+ }
392
+ /**
393
+ * Compute the final position from a segment made of destination-position, and return the height of the polygon
394
+ * This is a more sophisiticated version of moveAlong that will use the height of the polygon at the end position
395
+ * @param position world position to start from
396
+ * @param velocity wvelocity of the movement
397
+ * @param options options for the function
398
+ * @returns the resulting point along the navmesh, the polygon reference id and the height of the polygon
399
+ */
400
+ moveAlongWithVelocity(position, velocity, options) {
401
+ const { point, polyRef } = this._navMeshQuery.findClosestPoint({
402
+ x: position.x,
403
+ y: position.y,
404
+ z: position.z,
405
+ }, options);
406
+ const { resultPosition } = this._navMeshQuery.moveAlongSurface(polyRef, point, {
407
+ x: point.x + velocity.x,
408
+ y: point.y + velocity.y,
409
+ z: point.z + velocity.z,
410
+ }, options);
411
+ const polyHeightResult = this._navMeshQuery.getPolyHeight(polyRef, resultPosition);
412
+ return {
413
+ position: { x: resultPosition.x, y: polyHeightResult.success ? polyHeightResult.height : resultPosition.y, z: resultPosition.z },
414
+ polyRef: polyRef,
415
+ height: polyHeightResult.height,
416
+ };
417
+ }
418
+ /**
419
+ * Handles common post-processing and validation of navmesh creation results
420
+ * @param result The partial result from navmesh creation
421
+ * @returns The validated and complete CreateNavMeshresult
422
+ */
423
+ _processNavMeshResult(result) {
424
+ if (!result?.navMesh || !result?.navMeshQuery) {
425
+ throw new Error("Unable to create navmesh. No navMesh or navMeshQuery returned.");
426
+ }
427
+ this.navMesh = result.navMesh;
428
+ this._navMeshQuery = result.navMeshQuery;
429
+ this.intermediates = result.intermediates;
430
+ this.tileCache = result.tileCache;
431
+ return {
432
+ navMesh: result.navMesh,
433
+ navMeshQuery: result.navMeshQuery,
434
+ intermediates: result.intermediates,
435
+ tileCache: result.tileCache, // tileCache is optional
436
+ };
437
+ }
438
+ _preprocessParameters(parameters) {
439
+ if ((parameters.tileSize ?? 0 > 0) && !!parameters.maxObstacles) {
440
+ parameters.maxObstacles = DefaultMaxObstacles;
441
+ }
442
+ parameters.walkableSlopeAngle = Math.max(0.1, parameters.walkableSlopeAngle ?? 60);
443
+ }
444
+ }
445
+ //# sourceMappingURL=RecastNavigationJSPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecastNavigationJSPlugin.js","sourceRoot":"","sources":["../../../../../dev/addons/src/navigation/plugin/RecastNavigationJSPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,oCAAyB;AAG1C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,mCAAwB;AAKtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,OAAO,0BAA0B;IAiCnC;;;OAGG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IA0BD;;;OAGG;IACH,YAAmB,eAAiC;QA9CpD;;WAEG;QACI,SAAI,GAAW,0BAA0B,CA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AAU,CAAC,YAAY,EAAE,CAAC;YAC9D,UAAU,CAAC,YAAY,GAAG,mBAAmB,CAAC;QAClD,CAAC;QAED,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;IACvF,CAAC;CACJ","sourcesContent":["import type { NavMesh, QueryFilter, TileCache, NavMeshQuery } from \"@recast-navigation/core\";\n\nimport type { ICrowd, INavigationEnginePlugin, IObstacle } from \"core/Navigation/INavigationEngine\";\nimport { Logger } from \"core/Misc/logger\";\nimport type { Mesh } from \"core/Meshes/mesh\";\nimport type { Scene } from \"core/scene\";\nimport { TmpVectors, Vector3 } from \"core/Maths/math\";\nimport type { IVector3Like } from \"core/Maths/math.like\";\nimport type { Nullable } from \"core/types\";\n\nimport type { CreateNavMeshResult, GeneratorIntermediates, INavMeshParametersV2, RecastInjection } from \"../types\";\nimport { RecastJSCrowd } from \"./RecastJSCrowd\";\nimport { ConvertNavPathPoints } from \"../common/convert\";\nimport { ComputeSmoothPath } from \"../common/smooth-path\";\nimport { CreateDebugNavMesh } from \"../debug/simple-debug\";\nimport { GetRecast } from \"../factory/common\";\nimport { InjectGenerators } from \"../generator/injection\";\nimport { DefaultMaxObstacles } from \"../common/config\";\nimport { WaitForFullTileCacheUpdate } from \"../common/tile-cache\";\n\n/**\n * Navigation plugin for Babylon.js. It is a simple wrapper around the recast-navigation-js library. Not all features are implemented.\n * @remarks This plugin provides navigation mesh generation and pathfinding capabilities using the recast-navigation-js library\n * @remarks It supports both single-threaded and multi-threaded generation of navigation meshes.\n * @remarks The plugin can be used to create navigation meshes from meshes in a scene, compute paths, and manage crowd agents, etc.\n * @remarks It also provides methods for creating obstacles and querying the navigation mesh.\n * @see https://github.com/isaac-mason/recast-navigation-js\n */\nexport class RecastNavigationJSPluginV2 implements INavigationEnginePlugin {\n /**\n * Creates a navigation mesh - will be injected by the factory\n * @param meshes array of all the geometry used to compute the navigation mesh\n * @param parameters bunch of parameters used to filter geometry\n * @returns the created navmesh and navmesh query\n */\n createNavMeshImpl: (meshes: Array<Mesh>, parameters: INavMeshParametersV2) => CreateNavMeshResult;\n\n /**\n * Creates a navigation mesh - will be injected by the factory\n * @param meshes array of all the geometry used to compute the navigation mesh\n * @param parameters bunch of parameters used to filter geometry\n * @returns the created navmesh and navmesh query\n */\n createNavMeshAsyncImpl: (meshes: Array<Mesh>, parameters: INavMeshParametersV2) => Promise<CreateNavMeshResult>;\n\n /**\n * recast-navigation-js injection\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public bjsRECAST: RecastInjection;\n\n /**\n * plugin name\n */\n public name: string = \"RecastNavigationJSPlugin\";\n\n /**\n * the navmesh created\n */\n public navMesh?: NavMesh;\n\n /**\n * The navmesh query created from the navmesh\n * @remarks This is used to query the navmesh for pathfinding and other navigation tasks\n */\n public get navMeshQuery(): NavMeshQuery {\n return this._navMeshQuery;\n }\n\n private _navMeshQuery!: NavMeshQuery;\n\n /**\n * Intermediates generated during the navmesh creation\n * @remarks This is used for debugging and visualization purposes.\n * @remarks You have access to vertices, indices and vertex colors to visusalize the navmesh creation process.\n * @remarks This is only available if the `keepIntermediates` parameter is set\n * @remarks to true during navmesh generation.\n */\n public intermediates?: GeneratorIntermediates;\n\n /**\n * Tile cache used for tiled navigation meshes\n * @remarks This is used to store and manage tiles of the navigation mesh for efficient path and when obstacles are used.\n */\n public tileCache?: TileCache;\n\n // Crowd specific properties\n private _maximumSubStepCount: number = 10;\n private _timeStep: number = 1 / 60;\n private _timeFactor: number = 1;\n\n private _crowd?: ICrowd;\n\n /**\n * Creates a RecastNavigationJSPluginV2 instance\n * @param recastInjection The recast-navigation-js injection containing core and generators\n */\n public constructor(recastInjection?: RecastInjection) {\n if (!recastInjection) {\n recastInjection = GetRecast();\n InjectGenerators(this);\n }\n\n this.bjsRECAST = recastInjection;\n\n if (!this.isSupported()) {\n Logger.Error(\"RecastJS is not available. Please make sure you included the js file.\");\n return;\n }\n this.setTimeStep();\n }\n\n /**\n * Set the time step of the navigation tick update.\n * Default is 1/60.\n * A value of 0 will disable fixed time update\n * @param newTimeStep the new timestep to apply to this world.\n */\n public setTimeStep(newTimeStep: number = 1 / 60): void {\n this._timeStep = newTimeStep;\n }\n\n /**\n * Get the time step of the navigation tick update.\n * @returns the current time step\n */\n public getTimeStep(): number {\n return this._timeStep;\n }\n\n /**\n * If delta time in navigation tick update is greater than the time step\n * a number of sub iterations are done. If more iterations are need to reach deltatime\n * they will be discarded.\n * A value of 0 will set to no maximum and update will use as many substeps as needed\n * @param newStepCount the maximum number of iterations\n */\n public setMaximumSubStepCount(newStepCount: number = 10): void {\n this._maximumSubStepCount = newStepCount;\n }\n\n /**\n * Get the maximum number of iterations per navigation tick update\n * @returns the maximum number of iterations\n */\n public getMaximumSubStepCount(): number {\n return this._maximumSubStepCount;\n }\n\n /**\n * Time factor applied when updating crowd agents (default 1). A value of 0 will pause crowd updates.\n * @param value the time factor applied at update\n */\n public set timeFactor(value: number) {\n this._timeFactor = Math.max(value, 0);\n }\n\n /**\n * Get the time factor used for crowd agent update\n * @returns the time factor\n */\n public get timeFactor(): number {\n return this._timeFactor;\n }\n\n /**\n * Creates a navigation mesh - will be injected by the factory\n * @param meshes array of all the geometry used to compute the navigation mesh\n * @param parameters bunch of parameters used to filter geometry\n * @returns the created navmesh and navmesh query\n * @throws Error if the function is not injected yet or if the navmesh is not created\n */\n public createNavMesh(meshes: Array<Mesh>, parameters: INavMeshParametersV2): CreateNavMeshResult {\n if (!this.createNavMeshImpl) {\n throw new Error(\"Function not injected yet. Use the factory to create the plugin.\");\n }\n\n this._preprocessParameters(parameters);\n\n const result = this.createNavMeshImpl(meshes, parameters);\n return this._processNavMeshResult(result);\n }\n\n /**\n * Creates a navigation mesh asynchronously - will be injected by the factory\n * @param meshes array of all the geometry used to compute the navigation mesh\n * @param parameters bunch of parameters used to filter geometry\n * @returns the created navmesh and navmesh query\n * @throws Error if the function is not injected yet or if the navmesh is not created\n */\n public async createNavMeshAsync(meshes: Array<Mesh>, parameters: INavMeshParametersV2): Promise<CreateNavMeshResult> {\n if (!this.createNavMeshAsyncImpl) {\n throw new Error(\"Function not injected yet. Use the factory to create the plugin.\");\n }\n\n this._preprocessParameters(parameters);\n\n const result = await this.createNavMeshAsyncImpl(meshes, parameters);\n return this._processNavMeshResult(result);\n }\n\n /**\n * Create a navigation mesh debug mesh\n * @param scene is where the mesh will be added\n * @returns debug display mesh\n */\n public createDebugNavMesh(scene: Scene): Mesh {\n if (!this.navMesh) {\n throw new Error(\"There is no navMesh generated.\");\n }\n\n if (this.navMesh && this.tileCache) {\n WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);\n }\n\n return CreateDebugNavMesh(this.navMesh, scene);\n }\n\n /**\n * Get a navigation mesh constrained position, closest to the parameter position\n * @param position world position\n * @returns the closest point to position constrained by the navigation mesh\n */\n public getClosestPoint(\n position: IVector3Like,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n }\n ): Vector3 {\n const ret = this._navMeshQuery.findClosestPoint(position, options);\n const pr = new Vector3(ret.point.x, ret.point.y, ret.point.z);\n return pr;\n }\n\n /**\n * Get a navigation mesh constrained position, closest to the parameter position\n * @param position world position\n * @param result output the closest point to position constrained by the navigation mesh\n */\n public getClosestPointToRef(\n position: IVector3Like,\n result: Vector3,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n }\n ): void {\n const ret = this._navMeshQuery.findClosestPoint(position, options);\n result.set(ret.point.x, ret.point.y, ret.point.z);\n }\n\n /**\n * Get a navigation mesh constrained position, within a particular radius\n * @param position world position\n * @param maxRadius the maximum distance to the constrained world position\n * @returns the closest point to position constrained by the navigation mesh\n */\n public getRandomPointAround(\n position: IVector3Like,\n maxRadius: number,\n options?: {\n startRef?: number;\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n }\n ): Vector3 {\n const ret = this._navMeshQuery.findRandomPointAroundCircle(position, maxRadius, options);\n const pr = new Vector3(ret.randomPoint.x, ret.randomPoint.y, ret.randomPoint.z);\n return pr;\n }\n\n /**\n * Get a navigation mesh constrained position, within a particular radius\n * @param position world position\n * @param maxRadius the maximum distance to the constrained world position\n * @param result output the closest point to position constrained by the navigation mesh\n */\n public getRandomPointAroundToRef(\n position: IVector3Like,\n maxRadius: number,\n result: Vector3,\n options?: {\n startRef?: number;\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n }\n ): void {\n const ret = this._navMeshQuery.findRandomPointAroundCircle(position, maxRadius, options);\n result.set(ret.randomPoint.x, ret.randomPoint.y, ret.randomPoint.z);\n }\n\n /**\n * Compute the final position from a segment made of destination-position\n * @param position position to start from\n * @param destination position to go to\n * @param startRef the reference id of the start polygon\n * @param options options for the function\n * @returns the resulting point along the navmesh\n */\n public moveAlong(\n position: IVector3Like,\n destination: IVector3Like,\n startRef = 0,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * The maximum number of polygons the output visited array can hold.\n */\n maxVisitedSize?: number;\n }\n ): Vector3 {\n const ret = this._navMeshQuery.moveAlongSurface(startRef, position, destination, options);\n const pr = new Vector3(ret.resultPosition.x, ret.resultPosition.y, ret.resultPosition.z);\n return pr;\n }\n\n /**\n * Compute the final position from a segment made of destination-position\n * @param position world position\n * @param destination world position\n * @param result output the resulting point along the navmesh\n * @param startRef the reference id of the start polygon.\n * @param options options for the function\n */\n public moveAlongToRef(\n position: IVector3Like,\n destination: IVector3Like,\n result: Vector3,\n startRef = 0,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n maxVisitedSize?: number;\n }\n ): void {\n const ret = this._navMeshQuery.moveAlongSurface(startRef, position, destination, options);\n result.set(ret.resultPosition.x, ret.resultPosition.y, ret.resultPosition.z);\n }\n\n /**\n * Compute a navigation path from start to end. Returns an empty array if no path can be computed\n * Path is straight.\n * @param start world position\n * @param end world position\n * @param options options for the function\n * @returns array containing world position composing the path\n */\n public computePath(\n start: IVector3Like,\n end: IVector3Like,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n maxPathPolys?: number;\n maxStraightPathPoints?: number;\n }\n ): Vector3[] {\n return ConvertNavPathPoints(this._navMeshQuery.computePath(start, end, options));\n }\n\n /**\n * Creates a navigation mesh - will be injected by the factory\n * @param start the start position of the navmesh\n * @param end the end position of the navmesh\n * @param options options to configure the path computation\n * @returns array containing world position composing the path\n */\n public computePathSmooth(\n start: Vector3,\n end: Vector3,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n maxPathPolys?: number;\n maxSmoothPathPoints?: number;\n stepSize?: number;\n slop?: number;\n }\n ): Vector3[] {\n if (!this.navMesh) {\n Logger.Error(\"No navmesh available. Cannot compute smooth path.\");\n return [];\n }\n return ComputeSmoothPath(this.navMesh, this._navMeshQuery, start, end, options);\n }\n\n /**\n * Create a new Crowd so you can add agents\n * @param maxAgents the maximum agent count in the crowd\n * @param maxAgentRadius the maximum radius an agent can have\n * @param scene to attach the crowd to\n * @returns the crowd you can add agents to\n */\n public createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): ICrowd {\n const crowd = new RecastJSCrowd(this, maxAgents, maxAgentRadius, scene);\n this._crowd = crowd;\n return crowd;\n }\n\n /**\n * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)\n * The queries will try to find a solution within those bounds\n * default is (1,1,1)\n * @param extent x,y,z value that define the extent around the queries point of reference\n */\n public setDefaultQueryExtent(extent: IVector3Like): void {\n this._navMeshQuery.defaultQueryHalfExtents = extent;\n }\n\n /**\n * Get the Bounding box extent specified by setDefaultQueryExtent\n * @returns the box extent values\n */\n public getDefaultQueryExtent(): Vector3 {\n return new Vector3(this._navMeshQuery.defaultQueryHalfExtents.x, this._navMeshQuery.defaultQueryHalfExtents.y, this._navMeshQuery.defaultQueryHalfExtents.z);\n }\n\n /**\n * Get the Bounding box extent result specified by setDefaultQueryExtent\n * @param result output the box extent values\n */\n public getDefaultQueryExtentToRef(result: Vector3): void {\n result.set(this._navMeshQuery.defaultQueryHalfExtents.x, this._navMeshQuery.defaultQueryHalfExtents.y, this._navMeshQuery.defaultQueryHalfExtents.z);\n }\n\n /**\n * build the navmesh from a previously saved state using getNavmeshData\n * @param data the Uint8Array returned by getNavmeshData\n */\n public buildFromNavmeshData(data: Uint8Array): void {\n const result = this.bjsRECAST.importNavMesh(data);\n this.navMesh = result.navMesh;\n this._navMeshQuery = new this.bjsRECAST.NavMeshQuery(this.navMesh);\n }\n\n /**\n * returns the navmesh data that can be used later. The navmesh must be built before retrieving the data\n * @returns data the Uint8Array that can be saved and reused\n */\n public getNavmeshData(): Uint8Array {\n if (!this.navMesh) {\n throw new Error(\"There is no NavMesh generated.\");\n }\n return this.bjsRECAST.exportNavMesh(this.navMesh);\n }\n\n /**\n * Disposes\n */\n public dispose() {\n this._crowd?.dispose();\n this.navMesh?.destroy();\n this._navMeshQuery?.destroy();\n this.tileCache?.destroy();\n }\n\n /**\n * Creates a cylinder obstacle and add it to the navigation\n * @param position world position\n * @param radius cylinder radius\n * @param height cylinder height\n * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning\n * @returns the obstacle freshly created\n */\n public addCylinderObstacle(position: IVector3Like, radius: number, height: number, doNotWaitForCacheUpdate = false): Nullable<IObstacle> {\n const obstacleResult = this.tileCache?.addCylinderObstacle(position, radius, height);\n if (!obstacleResult?.success) {\n return null;\n }\n\n if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {\n WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);\n }\n\n return (obstacleResult.obstacle as IObstacle) ?? null;\n }\n\n /**\n * Creates an oriented box obstacle and add it to the navigation\n * @param position world position\n * @param extent box size\n * @param angle angle in radians of the box orientation on Y axis\n * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning\n * @returns the obstacle freshly created\n */\n public addBoxObstacle(position: IVector3Like, extent: IVector3Like, angle: number, doNotWaitForCacheUpdate = false): Nullable<IObstacle> {\n const obstacleResult = this.tileCache?.addBoxObstacle(position, extent, angle);\n if (!obstacleResult?.success) {\n return null;\n }\n\n if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {\n WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);\n }\n\n return (obstacleResult.obstacle as IObstacle) ?? null;\n }\n\n /**\n * Removes an obstacle created by addCylinderObstacle or addBoxObstacle\n * @param obstacle obstacle to remove from the navigation\n * @param doNotWaitForCacheUpdate if true the function will not wait for the tile cache to be fully updated before returning\n *\n */\n public removeObstacle(obstacle: IObstacle, doNotWaitForCacheUpdate = false): void {\n this.tileCache?.removeObstacle(obstacle);\n\n if (!doNotWaitForCacheUpdate && this.navMesh && this.tileCache) {\n WaitForFullTileCacheUpdate(this.navMesh, this.tileCache);\n }\n }\n\n /**\n * If this plugin is supported\n * @returns true if plugin is supported\n */\n public isSupported(): boolean {\n return !!this.bjsRECAST;\n }\n\n /**\n * Returns the seed used for randomized functions like `getRandomPointAround`\n * @returns seed number\n */\n public getRandomSeed(): number {\n return this.bjsRECAST.getRandomSeed();\n }\n\n /**\n * Set the seed used for randomized functions like `getRandomPointAround`\n * @param seed number used as seed for random functions\n */\n public setRandomSeed(seed: number): void {\n this.bjsRECAST.setRandomSeed(seed);\n }\n\n // New funccntions beyond the INavigationEnginePlugin interface\n\n /**\n * Perform a raycast on the navmesh\n * @param start start position\n * @param end end position\n * @returns if a direct path exists between start and end, and the hit point if any\n */\n public raycast(start: IVector3Like, end: IVector3Like) {\n const nearestStartPoly = this._navMeshQuery.findNearestPoly(start);\n const raycastResult = this._navMeshQuery.raycast(nearestStartPoly.nearestRef, start, end);\n\n const hit = 0 < raycastResult.t && raycastResult.t < 1.0;\n if (!hit) {\n return {\n hit: false,\n };\n } else {\n TmpVectors.Vector3[0].set(start.x, start.y, start.z);\n TmpVectors.Vector3[1].set(end.x, end.y, end.z);\n\n const distanceToHitBorder = Vector3.Distance(TmpVectors.Vector3[0], TmpVectors.Vector3[1]) * (raycastResult?.t ?? 0);\n const direction = TmpVectors.Vector3[1].subtract(TmpVectors.Vector3[0]).normalize();\n const hitPoint = TmpVectors.Vector3[0].add(direction.multiplyByFloats(distanceToHitBorder, distanceToHitBorder, distanceToHitBorder));\n\n return {\n hit: true,\n hitPoint,\n };\n }\n }\n\n /**\n * Compute the final position from a segment made of destination-position, and return the height of the polygon\n * This is a more sophisiticated version of moveAlong that will use the height of the polygon at the end position\n * @param position world position to start from\n * @param velocity wvelocity of the movement\n * @param options options for the function\n * @returns the resulting point along the navmesh, the polygon reference id and the height of the polygon\n */\n public moveAlongWithVelocity(\n position: IVector3Like,\n velocity: IVector3Like,\n options?: {\n /**\n * The polygon filter to apply to the query.\n */\n filter?: QueryFilter;\n /**\n * Half extents for the search box\n */\n halfExtents?: IVector3Like;\n /**\n * The maximum number of polygons the output visited array can hold.\n */\n maxVisitedSize?: number;\n }\n ) {\n const { point, polyRef } = this._navMeshQuery.findClosestPoint(\n {\n x: position.x,\n y: position.y,\n z: position.z,\n },\n options\n );\n\n const { resultPosition } = this._navMeshQuery.moveAlongSurface(\n polyRef,\n point,\n {\n x: point.x + velocity.x,\n y: point.y + velocity.y,\n z: point.z + velocity.z,\n },\n options\n );\n const polyHeightResult = this._navMeshQuery.getPolyHeight(polyRef, resultPosition);\n\n return {\n position: { x: resultPosition.x, y: polyHeightResult.success ? polyHeightResult.height : resultPosition.y, z: resultPosition.z },\n polyRef: polyRef,\n height: polyHeightResult.height,\n };\n }\n\n /**\n * Handles common post-processing and validation of navmesh creation results\n * @param result The partial result from navmesh creation\n * @returns The validated and complete CreateNavMeshresult\n */\n private _processNavMeshResult(result: Nullable<Partial<CreateNavMeshResult>>): CreateNavMeshResult {\n if (!result?.navMesh || !result?.navMeshQuery) {\n throw new Error(\"Unable to create navmesh. No navMesh or navMeshQuery returned.\");\n }\n\n this.navMesh = result.navMesh;\n this._navMeshQuery = result.navMeshQuery;\n this.intermediates = result.intermediates;\n this.tileCache = result.tileCache;\n\n return {\n navMesh: result.navMesh,\n navMeshQuery: result.navMeshQuery,\n intermediates: result.intermediates,\n tileCache: result.tileCache, // tileCache is optional\n };\n }\n\n private _preprocessParameters(parameters: INavMeshParametersV2) {\n if ((parameters.tileSize ?? 0 > 0) && !!parameters.maxObstacles) {\n parameters.maxObstacles = DefaultMaxObstacles;\n }\n\n parameters.walkableSlopeAngle = Math.max(0.1, parameters.walkableSlopeAngle ?? 60);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export * from "./RecastNavigationJSPlugin.js";
@@ -0,0 +1,2 @@
1
+ export * from "./RecastNavigationJSPlugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/addons/src/navigation/plugin/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./RecastNavigationJSPlugin\";\n"]}