INavigationEngine.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. 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, 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. * build the navmesh from a previously saved state using getNavmeshData
  79. * @param data the Uint8Array returned by getNavmeshData
  80. */
  81. buildFromNavmeshData(data: Uint8Array): void;
  82. /**
  83. * returns the navmesh data that can be used later. The navmesh must be built before retrieving the data
  84. * @returns data the Uint8Array that can be saved and reused
  85. */
  86. getNavmeshData(): Uint8Array;
  87. /**
  88. * Disposes the data returned by buildFromNavmeshData
  89. * @param data the Uint8Array returned by getNavmeshData
  90. */
  91. freeNavmeshData(data: Uint8Array): void;
  92. /**
  93. * Release all resources
  94. */
  95. dispose(): void;
  96. }
  97. /**
  98. * Crowd Interface. A Crowd is a collection of moving agents constrained by a navigation mesh
  99. */
  100. export interface ICrowd {
  101. /**
  102. * Add a new agent to the crowd with the specified parameter a corresponding transformNode.
  103. * You can attach anything to that node. The node position is updated in the scene update tick.
  104. * @param pos world position that will be constrained by the navigation mesh
  105. * @param parameters agent parameters
  106. * @param transform hooked to the agent that will be update by the scene
  107. * @returns agent index
  108. */
  109. addAgent(pos: Vector3, parameters: IAgentParameters, transform: TransformNode): number;
  110. /**
  111. * Returns the agent position in world space
  112. * @param index agent index returned by addAgent
  113. * @returns world space position
  114. */
  115. getAgentPosition(index: number): Vector3;
  116. /**
  117. * Gets the agent velocity in world space
  118. * @param index agent index returned by addAgent
  119. * @returns world space velocity
  120. */
  121. getAgentVelocity(index: number): Vector3;
  122. /**
  123. * remove a particular agent previously created
  124. * @param index agent index returned by addAgent
  125. */
  126. removeAgent(index: number): void;
  127. /**
  128. * get the list of all agents attached to this crowd
  129. * @returns list of agent indices
  130. */
  131. getAgents() : number[];
  132. /**
  133. * Tick update done by the Scene. Agent position/velocity/acceleration is updated by this function
  134. * @param deltaTime in seconds
  135. */
  136. update(deltaTime: number): void;
  137. /**
  138. * Asks a particular agent to go to a destination. That destination is constrained by the navigation mesh
  139. * @param index agent index returned by addAgent
  140. * @param destination targeted world position
  141. */
  142. agentGoto(index: number, destination: Vector3): void;
  143. /**
  144. * Teleport the agent to a new position
  145. * @param index agent index returned by addAgent
  146. * @param destination targeted world position
  147. */
  148. agentTeleport(index: number, destination: Vector3): void;
  149. /**
  150. * Update agent parameters
  151. * @param index agent index returned by addAgent
  152. * @param parameters agent parameters
  153. */
  154. updateAgentParameters(index: number, parameters: IAgentParameters): void;
  155. /**
  156. * Set the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
  157. * The queries will try to find a solution within those bounds
  158. * default is (1,1,1)
  159. * @param extent x,y,z value that define the extent around the queries point of reference
  160. */
  161. setDefaultQueryExtent(extent: Vector3): void;
  162. /**
  163. * Get the Bounding box extent specified by setDefaultQueryExtent
  164. * @returns the box extent values
  165. */
  166. getDefaultQueryExtent(): Vector3;
  167. /**
  168. * Release all resources
  169. */
  170. dispose() : void;
  171. }
  172. /**
  173. * Configures an agent
  174. */
  175. export interface IAgentParameters {
  176. /**
  177. * Agent radius. [Limit: >= 0]
  178. */
  179. radius: number;
  180. /**
  181. * Agent height. [Limit: > 0]
  182. */
  183. height: number;
  184. /**
  185. * Maximum allowed acceleration. [Limit: >= 0]
  186. */
  187. maxAcceleration: number;
  188. /**
  189. * Maximum allowed speed. [Limit: >= 0]
  190. */
  191. maxSpeed: number;
  192. /**
  193. * Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0]
  194. */
  195. collisionQueryRange: number;
  196. /**
  197. * The path visibility optimization range. [Limit: > 0]
  198. */
  199. pathOptimizationRange: number;
  200. /**
  201. * How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0]
  202. */
  203. separationWeight: number;
  204. }
  205. /**
  206. * Configures the navigation mesh creation
  207. */
  208. export interface INavMeshParameters {
  209. /**
  210. * The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
  211. */
  212. cs: number;
  213. /**
  214. * The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
  215. */
  216. ch: number;
  217. /**
  218. * The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
  219. */
  220. walkableSlopeAngle: number;
  221. /**
  222. * Minimum floor to 'ceiling' height that will still allow the floor area to
  223. * be considered walkable. [Limit: >= 3] [Units: vx]
  224. */
  225. walkableHeight: number;
  226. /**
  227. * Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
  228. */
  229. walkableClimb: number;
  230. /**
  231. * The distance to erode/shrink the walkable area of the heightfield away from
  232. * obstructions. [Limit: >=0] [Units: vx]
  233. */
  234. walkableRadius: number;
  235. /**
  236. * The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
  237. */
  238. maxEdgeLen: number;
  239. /**
  240. * The maximum distance a simplfied contour's border edges should deviate
  241. * the original raw contour. [Limit: >=0] [Units: vx]
  242. */
  243. maxSimplificationError: number;
  244. /**
  245. * The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
  246. */
  247. minRegionArea: number;
  248. /**
  249. * Any regions with a span count smaller than this value will, if possible,
  250. * be merged with larger regions. [Limit: >=0] [Units: vx]
  251. */
  252. mergeRegionArea: number;
  253. /**
  254. * The maximum number of vertices allowed for polygons generated during the
  255. * contour to polygon conversion process. [Limit: >= 3]
  256. */
  257. maxVertsPerPoly: number;
  258. /**
  259. * Sets the sampling distance to use when generating the detail mesh.
  260. * (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
  261. */
  262. detailSampleDist: number;
  263. /**
  264. * The maximum distance the detail mesh surface should deviate from heightfield
  265. * data. (For height detail only.) [Limit: >=0] [Units: wu]
  266. */
  267. detailSampleMaxError: number;
  268. }