INavigationEngine.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. import type { TransformNode } from "../Meshes/transformNode";
  2. import type { Vector3 } from "../Maths/math";
  3. import type { Mesh } from "../Meshes/mesh";
  4. import type { Scene } from "../scene";
  5. /**
  6. * Navigation plugin interface to add navigation constrained by a navigation mesh
  7. */
  8. export interface INavigationEnginePlugin {
  9. /**
  10. * plugin name
  11. */
  12. name: string;
  13. /**
  14. * Creates a navigation mesh
  15. * @param meshes array of all the geometry used to compute the navigation mesh
  16. * @param parameters bunch of parameters used to filter geometry
  17. */
  18. createNavMesh(meshes: Array<Mesh>, parameters: INavMeshParameters): void;
  19. /**
  20. * Create a navigation mesh debug mesh
  21. * @param scene is where the mesh will be added
  22. * @returns debug display mesh
  23. */
  24. createDebugNavMesh(scene: Scene): Mesh;
  25. /**
  26. * Get a navigation mesh constrained position, closest to the parameter position
  27. * @param position world position
  28. * @returns the closest point to position constrained by the navigation mesh
  29. */
  30. getClosestPoint(position: Vector3): Vector3;
  31. /**
  32. * Get a navigation mesh constrained position, closest to the parameter position
  33. * @param position world position
  34. * @param result output the closest point to position constrained by the navigation mesh
  35. */
  36. getClosestPointToRef(position: Vector3, result: Vector3): void;
  37. /**
  38. * Get a navigation mesh constrained position, within a particular radius
  39. * @param position world position
  40. * @param maxRadius the maximum distance to the constrained world position
  41. * @returns the closest point to position constrained by the navigation mesh
  42. */
  43. getRandomPointAround(position: Vector3, maxRadius: number): Vector3;
  44. /**
  45. * Get a navigation mesh constrained position, within a particular radius
  46. * @param position world position
  47. * @param maxRadius the maximum distance to the constrained world position
  48. * @param result output the closest point to position constrained by the navigation mesh
  49. */
  50. getRandomPointAroundToRef(position: Vector3, maxRadius: number, result: Vector3): void;
  51. /**
  52. * Compute the final position from a segment made of destination-position
  53. * @param position world position
  54. * @param destination world position
  55. * @returns the resulting point along the navmesh
  56. */
  57. moveAlong(position: Vector3, destination: Vector3): Vector3;
  58. /**
  59. * Compute the final position from a segment made of destination-position
  60. * @param position world position
  61. * @param destination world position
  62. * @param result output the resulting point along the navmesh
  63. */
  64. moveAlongToRef(position: Vector3, destination: Vector3, result: Vector3): void;
  65. /**
  66. * Compute a navigation path from start to end. Returns an empty array if no path can be computed.
  67. * Path is straight.
  68. * @param start world position
  69. * @param end world position
  70. * @returns array containing world position composing the path
  71. */
  72. computePath(start: Vector3, end: Vector3): Vector3[];
  73. /**
  74. * Compute a navigation path from start to end. Returns an empty array if no path can be computed.
  75. * Path follows navigation mesh geometry.
  76. * @param start world position
  77. * @param end world position
  78. * @returns array containing world position composing the path
  79. */
  80. computePathSmooth(start: Vector3, end: Vector3): Vector3[];
  81. /**
  82. * If this plugin is supported
  83. * @returns true if plugin is supported
  84. */
  85. isSupported(): boolean;
  86. /**
  87. * Create a new Crowd so you can add agents
  88. * @param maxAgents the maximum agent count in the crowd
  89. * @param maxAgentRadius the maximum radius an agent can have
  90. * @param scene to attach the crowd to
  91. * @returns the crowd you can add agents to
  92. */
  93. createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): ICrowd;
  94. /**
  95. * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
  96. * The queries will try to find a solution within those bounds
  97. * default is (1,1,1)
  98. * @param extent x,y,z value that define the extent around the queries point of reference
  99. */
  100. setDefaultQueryExtent(extent: Vector3): void;
  101. /**
  102. * Get the Bounding box extent specified by setDefaultQueryExtent
  103. * @returns the box extent values
  104. */
  105. getDefaultQueryExtent(): Vector3;
  106. /**
  107. * build the navmesh from a previously saved state using getNavmeshData
  108. * @param data the Uint8Array returned by getNavmeshData
  109. */
  110. buildFromNavmeshData(data: Uint8Array): void;
  111. /**
  112. * returns the navmesh data that can be used later. The navmesh must be built before retrieving the data
  113. * @returns data the Uint8Array that can be saved and reused
  114. */
  115. getNavmeshData(): Uint8Array;
  116. /**
  117. * Get the Bounding box extent result specified by setDefaultQueryExtent
  118. * @param result output the box extent values
  119. */
  120. getDefaultQueryExtentToRef(result: Vector3): void;
  121. /**
  122. * Set the time step of the navigation tick update.
  123. * Default is 1/60.
  124. * A value of 0 will disable fixed time update
  125. * @param newTimeStep the new timestep to apply to this world.
  126. */
  127. setTimeStep(newTimeStep: number): void;
  128. /**
  129. * Get the time step of the navigation tick update.
  130. * @returns the current time step
  131. */
  132. getTimeStep(): number;
  133. /**
  134. * If delta time in navigation tick update is greater than the time step
  135. * a number of sub iterations are done. If more iterations are need to reach deltatime
  136. * they will be discarded.
  137. * A value of 0 will set to no maximum and update will use as many substeps as needed
  138. * @param newStepCount the maximum number of iterations
  139. */
  140. setMaximumSubStepCount(newStepCount: number): void;
  141. /**
  142. * Get the maximum number of iterations per navigation tick update
  143. * @returns the maximum number of iterations
  144. */
  145. getMaximumSubStepCount(): number;
  146. /**
  147. * Creates a cylinder obstacle and add it to the navigation
  148. * @param position world position
  149. * @param radius cylinder radius
  150. * @param height cylinder height
  151. * @returns the obstacle freshly created
  152. */
  153. addCylinderObstacle(position: Vector3, radius: number, height: number): IObstacle;
  154. /**
  155. * Creates an oriented box obstacle and add it to the navigation
  156. * @param position world position
  157. * @param extent box size
  158. * @param angle angle in radians of the box orientation on Y axis
  159. * @returns the obstacle freshly created
  160. */
  161. addBoxObstacle(position: Vector3, extent: Vector3, angle: number): IObstacle;
  162. /**
  163. * Removes an obstacle created by addCylinderObstacle or addBoxObstacle
  164. * @param obstacle obstacle to remove from the navigation
  165. */
  166. removeObstacle(obstacle: IObstacle): void;
  167. /**
  168. * Release all resources
  169. */
  170. dispose(): void;
  171. }
  172. /**
  173. * Obstacle interface
  174. */
  175. export interface IObstacle {
  176. }
  177. /**
  178. * Crowd Interface. A Crowd is a collection of moving agents constrained by a navigation mesh
  179. */
  180. export interface ICrowd {
  181. /**
  182. * Add a new agent to the crowd with the specified parameter a corresponding transformNode.
  183. * You can attach anything to that node. The node position is updated in the scene update tick.
  184. * @param pos world position that will be constrained by the navigation mesh
  185. * @param parameters agent parameters
  186. * @param transform hooked to the agent that will be update by the scene
  187. * @returns agent index
  188. */
  189. addAgent(pos: Vector3, parameters: IAgentParameters, transform: TransformNode): number;
  190. /**
  191. * Returns the agent position in world space
  192. * @param index agent index returned by addAgent
  193. * @returns world space position
  194. */
  195. getAgentPosition(index: number): Vector3;
  196. /**
  197. * Gets the agent position result in world space
  198. * @param index agent index returned by addAgent
  199. * @param result output world space position
  200. */
  201. getAgentPositionToRef(index: number, result: Vector3): void;
  202. /**
  203. * Gets the agent velocity in world space
  204. * @param index agent index returned by addAgent
  205. * @returns world space velocity
  206. */
  207. getAgentVelocity(index: number): Vector3;
  208. /**
  209. * Gets the agent velocity result in world space
  210. * @param index agent index returned by addAgent
  211. * @param result output world space velocity
  212. */
  213. getAgentVelocityToRef(index: number, result: Vector3): void;
  214. /**
  215. * Gets the agent next target point on the path
  216. * @param index agent index returned by addAgent
  217. * @returns world space position
  218. */
  219. getAgentNextTargetPath(index: number): Vector3;
  220. /**
  221. * Gets the agent state
  222. * @param index agent index returned by addAgent
  223. * @returns agent state
  224. */
  225. getAgentState(index: number): number;
  226. /**
  227. * returns true if the agent in over an off mesh link connection
  228. * @param index agent index returned by addAgent
  229. * @returns true if over an off mesh link connection
  230. */
  231. overOffmeshConnection(index: number): boolean;
  232. /**
  233. * Gets the agent next target point on the path
  234. * @param index agent index returned by addAgent
  235. * @param result output world space position
  236. */
  237. getAgentNextTargetPathToRef(index: number, result: Vector3): void;
  238. /**
  239. * remove a particular agent previously created
  240. * @param index agent index returned by addAgent
  241. */
  242. removeAgent(index: number): void;
  243. /**
  244. * get the list of all agents attached to this crowd
  245. * @returns list of agent indices
  246. */
  247. getAgents(): number[];
  248. /**
  249. * Tick update done by the Scene. Agent position/velocity/acceleration is updated by this function
  250. * @param deltaTime in seconds
  251. */
  252. update(deltaTime: number): void;
  253. /**
  254. * Asks a particular agent to go to a destination. That destination is constrained by the navigation mesh
  255. * @param index agent index returned by addAgent
  256. * @param destination targeted world position
  257. */
  258. agentGoto(index: number, destination: Vector3): void;
  259. /**
  260. * Teleport the agent to a new position
  261. * @param index agent index returned by addAgent
  262. * @param destination targeted world position
  263. */
  264. agentTeleport(index: number, destination: Vector3): void;
  265. /**
  266. * Update agent parameters
  267. * @param index agent index returned by addAgent
  268. * @param parameters agent parameters
  269. */
  270. updateAgentParameters(index: number, parameters: IAgentParameters): void;
  271. /**
  272. * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
  273. * The queries will try to find a solution within those bounds
  274. * default is (1,1,1)
  275. * @param extent x,y,z value that define the extent around the queries point of reference
  276. */
  277. setDefaultQueryExtent(extent: Vector3): void;
  278. /**
  279. * Get the Bounding box extent specified by setDefaultQueryExtent
  280. * @returns the box extent values
  281. */
  282. getDefaultQueryExtent(): Vector3;
  283. /**
  284. * Get the Bounding box extent result specified by setDefaultQueryExtent
  285. * @param result output the box extent values
  286. */
  287. getDefaultQueryExtentToRef(result: Vector3): void;
  288. /**
  289. * Get the next corner points composing the path (max 4 points)
  290. * @param index agent index returned by addAgent
  291. * @returns array containing world position composing the path
  292. */
  293. getCorners(index: number): Vector3[];
  294. /**
  295. * Release all resources
  296. */
  297. dispose(): void;
  298. }
  299. /**
  300. * Configures an agent
  301. */
  302. export interface IAgentParameters {
  303. /**
  304. * Agent radius. [Limit: >= 0]
  305. */
  306. radius: number;
  307. /**
  308. * Agent height. [Limit: > 0]
  309. */
  310. height: number;
  311. /**
  312. * Maximum allowed acceleration. [Limit: >= 0]
  313. */
  314. maxAcceleration: number;
  315. /**
  316. * Maximum allowed speed. [Limit: >= 0]
  317. */
  318. maxSpeed: number;
  319. /**
  320. * Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0]
  321. */
  322. collisionQueryRange: number;
  323. /**
  324. * The path visibility optimization range. [Limit: > 0]
  325. */
  326. pathOptimizationRange: number;
  327. /**
  328. * How aggressive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0]
  329. */
  330. separationWeight: number;
  331. /**
  332. * Observers will be notified when agent gets inside the virtual circle with this Radius around destination point.
  333. * Default is agent radius
  334. */
  335. reachRadius?: number;
  336. }
  337. /**
  338. * Configures the navigation mesh creation
  339. */
  340. export interface INavMeshParameters {
  341. /**
  342. * The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
  343. */
  344. cs: number;
  345. /**
  346. * The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
  347. */
  348. ch: number;
  349. /**
  350. * The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
  351. */
  352. walkableSlopeAngle: number;
  353. /**
  354. * Minimum floor to 'ceiling' height that will still allow the floor area to
  355. * be considered walkable. [Limit: >= 3] [Units: vx]
  356. */
  357. walkableHeight: number;
  358. /**
  359. * Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
  360. */
  361. walkableClimb: number;
  362. /**
  363. * The distance to erode/shrink the walkable area of the heightfield away from
  364. * obstructions. [Limit: >=0] [Units: vx]
  365. */
  366. walkableRadius: number;
  367. /**
  368. * The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
  369. */
  370. maxEdgeLen: number;
  371. /**
  372. * The maximum distance a simplified contour's border edges should deviate
  373. * the original raw contour. [Limit: >=0] [Units: vx]
  374. */
  375. maxSimplificationError: number;
  376. /**
  377. * The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
  378. */
  379. minRegionArea: number;
  380. /**
  381. * Any regions with a span count smaller than this value will, if possible,
  382. * be merged with larger regions. [Limit: >=0] [Units: vx]
  383. */
  384. mergeRegionArea: number;
  385. /**
  386. * The maximum number of vertices allowed for polygons generated during the
  387. * contour to polygon conversion process. [Limit: >= 3]
  388. */
  389. maxVertsPerPoly: number;
  390. /**
  391. * Sets the sampling distance to use when generating the detail mesh.
  392. * (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
  393. */
  394. detailSampleDist: number;
  395. /**
  396. * The maximum distance the detail mesh surface should deviate from heightfield
  397. * data. (For height detail only.) [Limit: >=0] [Units: wu]
  398. */
  399. detailSampleMaxError: number;
  400. /**
  401. * If using obstacles, the navmesh must be subdivided internaly by tiles.
  402. * This member defines the tile cube side length in world units.
  403. * If no obstacles are needed, leave it undefined or 0.
  404. */
  405. tileSize?: number;
  406. /**
  407. * The size of the non-navigable border around the heightfield.
  408. */
  409. borderSize?: number;
  410. }