INavigationEngine.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import { TransformNode } from "../Meshes/transformNode";
  2. import { Vector3 } from "../Maths/math";
  3. import { Mesh } from "../Meshes/mesh";
  4. import { 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 navigatio mesh
  16. * @param parameters bunch of parameters used to filter geometry
  17. */
  18. createMavMesh(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, within a particular radius
  33. * @param position world position
  34. * @param maxRadius the maximum distance to the constrained world position
  35. * @returns the closest point to position constrained by the navigation mesh
  36. */
  37. getRandomPointAround(position: Vector3, maxRadius: number): Vector3;
  38. /**
  39. * Compute the final position from a segment made of destination-position
  40. * @param position world position
  41. * @param destination world position
  42. * @returns the resulting point along the navmesh
  43. */
  44. moveAlong(position: Vector3, destination: Vector3): Vector3;
  45. /**
  46. * Compute a navigation path from start to end. Returns an empty array if no path can be computed
  47. * @param start world position
  48. * @param end world position
  49. * @returns array containing world position composing the path
  50. */
  51. computePath(start: Vector3, end: Vector3): Vector3[];
  52. /**
  53. * If this plugin is supported
  54. * @returns true if plugin is supported
  55. */
  56. isSupported(): boolean;
  57. /**
  58. * Create a new Crowd so you can add agents
  59. * @param maxAgents the maximum agent count in the crowd
  60. * @param maxAgentRadius the maximum radius an agent can have
  61. * @param scene to attach the crowd to
  62. * @returns the crowd you can add agents to
  63. */
  64. createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): ICrowd;
  65. /**
  66. * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
  67. * The queries will try to find a solution within those bounds
  68. * default is (1,1,1)
  69. * @param extent x,y,z value that define the extent around the queries point of reference
  70. */
  71. setDefaultQueryExtent(extent: Vector3): void;
  72. /**
  73. * Get the Bounding box extent specified by setDefaultQueryExtent
  74. * @returns the box extent values
  75. */
  76. getDefaultQueryExtent(): Vector3;
  77. /**
  78. * Release all resources
  79. */
  80. dispose(): void;
  81. }
  82. /**
  83. * Crowd Interface. A Crowd is a collection of moving agents constrained by a navigation mesh
  84. */
  85. export interface ICrowd {
  86. /**
  87. * Add a new agent to the crowd with the specified parameter a corresponding transformNode.
  88. * You can attach anything to that node. The node position is updated in the scene update tick.
  89. * @param pos world position that will be constrained by the navigation mesh
  90. * @param parameters agent parameters
  91. * @param transform hooked to the agent that will be update by the scene
  92. * @returns agent index
  93. */
  94. addAgent(pos: Vector3, parameters: IAgentParameters, transform: TransformNode): number;
  95. /**
  96. * Returns the agent position in world space
  97. * @param index agent index returned by addAgent
  98. * @returns world space position
  99. */
  100. getAgentPosition(index: number): Vector3;
  101. /**
  102. * Gets the agent velocity in world space
  103. * @param index agent index returned by addAgent
  104. * @returns world space velocity
  105. */
  106. getAgentVelocity(index: number): Vector3;
  107. /**
  108. * remove a particular agent previously created
  109. * @param index agent index returned by addAgent
  110. */
  111. removeAgent(index: number): void;
  112. /**
  113. * get the list of all agents attached to this crowd
  114. * @returns list of agent indices
  115. */
  116. getAgents() : number[];
  117. /**
  118. * Tick update done by the Scene. Agent position/velocity/acceleration is updated by this function
  119. * @param deltaTime in seconds
  120. */
  121. update(deltaTime: number): void;
  122. /**
  123. * Asks a particular agent to go to a destination. That destination is constrained by the navigation mesh
  124. * @param index agent index returned by addAgent
  125. * @param destination targeted world position
  126. */
  127. agentGoto(index: number, destination: Vector3): void;
  128. /**
  129. * Teleport the agent to a new position
  130. * @param index agent index returned by addAgent
  131. * @param destination targeted world position
  132. */
  133. agentTeleport(index: number, destination: Vector3): void;
  134. /**
  135. * Update agent parameters
  136. * @param index agent index returned by addAgent
  137. * @param parameters agent parameters
  138. */
  139. updateAgentParameters(index: number, parameters: IAgentParameters): void;
  140. /**
  141. * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
  142. * The queries will try to find a solution within those bounds
  143. * default is (1,1,1)
  144. * @param extent x,y,z value that define the extent around the queries point of reference
  145. */
  146. setDefaultQueryExtent(extent: Vector3): void;
  147. /**
  148. * Get the Bounding box extent specified by setDefaultQueryExtent
  149. * @returns the box extent values
  150. */
  151. getDefaultQueryExtent(): Vector3;
  152. /**
  153. * Release all resources
  154. */
  155. dispose() : void;
  156. }
  157. /**
  158. * Configures an agent
  159. */
  160. export interface IAgentParameters {
  161. /**
  162. * Agent radius. [Limit: >= 0]
  163. */
  164. radius: number;
  165. /**
  166. * Agent height. [Limit: > 0]
  167. */
  168. height: number;
  169. /**
  170. * Maximum allowed acceleration. [Limit: >= 0]
  171. */
  172. maxAcceleration: number;
  173. /**
  174. * Maximum allowed speed. [Limit: >= 0]
  175. */
  176. maxSpeed: number;
  177. /**
  178. * Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0]
  179. */
  180. collisionQueryRange: number;
  181. /**
  182. * The path visibility optimization range. [Limit: > 0]
  183. */
  184. pathOptimizationRange: number;
  185. /**
  186. * How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0]
  187. */
  188. separationWeight: number;
  189. }
  190. /**
  191. * Configures the navigation mesh creation
  192. */
  193. export interface INavMeshParameters {
  194. /**
  195. * The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
  196. */
  197. cs: number;
  198. /**
  199. * The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
  200. */
  201. ch: number;
  202. /**
  203. * The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
  204. */
  205. walkableSlopeAngle: number;
  206. /**
  207. * Minimum floor to 'ceiling' height that will still allow the floor area to
  208. * be considered walkable. [Limit: >= 3] [Units: vx]
  209. */
  210. walkableHeight: number;
  211. /**
  212. * Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
  213. */
  214. walkableClimb: number;
  215. /**
  216. * The distance to erode/shrink the walkable area of the heightfield away from
  217. * obstructions. [Limit: >=0] [Units: vx]
  218. */
  219. walkableRadius: number;
  220. /**
  221. * The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
  222. */
  223. maxEdgeLen: number;
  224. /**
  225. * The maximum distance a simplfied contour's border edges should deviate
  226. * the original raw contour. [Limit: >=0] [Units: vx]
  227. */
  228. maxSimplificationError: number;
  229. /**
  230. * The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
  231. */
  232. minRegionArea: number;
  233. /**
  234. * Any regions with a span count smaller than this value will, if possible,
  235. * be merged with larger regions. [Limit: >=0] [Units: vx]
  236. */
  237. mergeRegionArea: number;
  238. /**
  239. * The maximum number of vertices allowed for polygons generated during the
  240. * contour to polygon conversion process. [Limit: >= 3]
  241. */
  242. maxVertsPerPoly: number;
  243. /**
  244. * Sets the sampling distance to use when generating the detail mesh.
  245. * (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
  246. */
  247. detailSampleDist: number;
  248. /**
  249. * The maximum distance the detail mesh surface should deviate from heightfield
  250. * data. (For height detail only.) [Limit: >=0] [Units: wu]
  251. */
  252. detailSampleMaxError: number;
  253. }