INavigationEngine.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import { TransformNode } from "../Meshes/transformNode";
  2. import { Vector3 } from "../Maths/math";
  3. import { AbstractMesh } from "../Meshes/abstractMesh";
  4. import { Mesh } from "../Meshes/mesh";
  5. import { Scene } from "../scene";
  6. /**
  7. * Navigation plugin interface to add navigation constrained by a navigation mesh
  8. */
  9. export interface INavigationEnginePlugin {
  10. /**
  11. * plugin name
  12. */
  13. name: string;
  14. /**
  15. * Creates a navigation mesh
  16. * @param mesh of all the geometry used to compute the navigation mesh
  17. * @param parameters bunch of parameters used to filter geometry
  18. */
  19. createMavMesh(mesh: AbstractMesh, parameters: NavMeshParameters): void;
  20. /**
  21. * Create a navigation mesh debug mesh
  22. * @param scene is where the mesh will be added
  23. * @returns debug display mesh
  24. */
  25. createDebugNavMesh(scene: Scene): Mesh;
  26. /**
  27. * Get a navigation mesh constrained position, closest to the parameter position
  28. * @param position world position
  29. * @returns the closest point to position constrained by the navigation mesh
  30. */
  31. getClosestPoint(position: Vector3): Vector3;
  32. /**
  33. * Get a navigation mesh constrained position, within a particular radius
  34. * @param position world position
  35. * @param maxRadius the maximum distance to the constrained world position
  36. * @returns the closest point to position constrained by the navigation mesh
  37. */
  38. getRandomPointAround(position: Vector3, maxRadius: number): Vector3;
  39. /**
  40. * If this plugin is supported
  41. * @returns true if plugin is supported
  42. */
  43. isSupported(): boolean;
  44. /**
  45. * Create a new Crowd so you can add agents
  46. * @param maxAgents the maximum agent count in the crowd
  47. * @param maxAgentRadius the maximum radius an agent can have
  48. * @param scene to attach the crowd to
  49. * @returns the crowd you can add agents to
  50. */
  51. createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): ICrowd;
  52. /**
  53. * Release all resources
  54. */
  55. dispose(): void;
  56. }
  57. /**
  58. * Crowd Interface. A Crowd is a collection of moving agents constrained by a navigation mesh
  59. */
  60. export interface ICrowd {
  61. /**
  62. * Add a new agent to the crowd with the specified parameter a corresponding transformNode.
  63. * You can attach anything to that node. The node position is updated in the scene update tick.
  64. * @param pos world position that will be constrained by the navigation mesh
  65. * @param parameters agent parameters
  66. * @param transform hooked to the agent that will be update by the scene
  67. * @returns agent index
  68. */
  69. addAgent(pos: Vector3, parameters: AgentParameters, transform: TransformNode): number;
  70. /**
  71. * Returns the agent position in world space
  72. * @param index agent index returned by addAgent
  73. * @returns world space position
  74. */
  75. getAgentPosition(index: number): Vector3;
  76. /**
  77. * Gets the agent velocity in world space
  78. * @param index agent index returned by addAgent
  79. * @returns world space velocity
  80. */
  81. getAgentVelocity(index: number): Vector3;
  82. /**
  83. * remove a particular agent previously created
  84. * @param index agent index returned by addAgent
  85. */
  86. removeAgent(index: number): void;
  87. /**
  88. * get the list of all agents attached to this crowd
  89. * @returns list of agent indices
  90. */
  91. getAgents() : number[];
  92. /**
  93. * Tick update done by the Scene. Agent position/velocity/acceleration is updated by this function
  94. * @param deltaTime in seconds
  95. */
  96. update(deltaTime: number): void;
  97. /**
  98. * Asks a particular agent to go to a destination. That destination is constrained by the navigation mesh
  99. * @param index agent index returned by addAgent
  100. * @param destination targeted world position
  101. */
  102. agentGoto(index: number, destination: Vector3): void;
  103. /**
  104. * Release all resources
  105. */
  106. dispose() : void;
  107. }
  108. /**
  109. * Configures an agent
  110. */
  111. export interface AgentParameters {
  112. /**
  113. * Agent radius. [Limit: >= 0]
  114. */
  115. radius: number;
  116. /**
  117. * Agent height. [Limit: > 0]
  118. */
  119. height: number;
  120. /**
  121. * Maximum allowed acceleration. [Limit: >= 0]
  122. */
  123. maxAcceleration: number;
  124. /**
  125. * Maximum allowed speed. [Limit: >= 0]
  126. */
  127. maxSpeed: number;
  128. /**
  129. * Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0]
  130. */
  131. collisionQueryRange: number;
  132. /**
  133. * The path visibility optimization range. [Limit: > 0]
  134. */
  135. pathOptimizationRange: number;
  136. /**
  137. * How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0]
  138. */
  139. separationWeight: number;
  140. }
  141. /**
  142. * Configures the navigation mesh creation
  143. */
  144. export interface NavMeshParameters {
  145. /**
  146. * The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
  147. */
  148. cs: number;
  149. /**
  150. * The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
  151. */
  152. ch: number;
  153. /**
  154. * The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
  155. */
  156. walkableSlopeAngle: number;
  157. /**
  158. * Minimum floor to 'ceiling' height that will still allow the floor area to
  159. * be considered walkable. [Limit: >= 3] [Units: vx]
  160. */
  161. walkableHeight: number;
  162. /**
  163. * Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
  164. */
  165. walkableClimb: number;
  166. /**
  167. * The distance to erode/shrink the walkable area of the heightfield away from
  168. * obstructions. [Limit: >=0] [Units: vx]
  169. */
  170. walkableRadius: number;
  171. /**
  172. * The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
  173. */
  174. maxEdgeLen: number;
  175. /**
  176. * The maximum distance a simplfied contour's border edges should deviate
  177. * the original raw contour. [Limit: >=0] [Units: vx]
  178. */
  179. maxSimplificationError: number;
  180. /**
  181. * The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
  182. */
  183. minRegionArea: number;
  184. /**
  185. * Any regions with a span count smaller than this value will, if possible,
  186. * be merged with larger regions. [Limit: >=0] [Units: vx]
  187. */
  188. mergeRegionArea: number;
  189. /**
  190. * The maximum number of vertices allowed for polygons generated during the
  191. * contour to polygon conversion process. [Limit: >= 3]
  192. */
  193. maxVertsPerPoly: number;
  194. /**
  195. * Sets the sampling distance to use when generating the detail mesh.
  196. * (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
  197. */
  198. detailSampleDist: number;
  199. /**
  200. * The maximum distance the detail mesh surface should deviate from heightfield
  201. * data. (For height detail only.) [Limit: >=0] [Units: wu]
  202. */
  203. detailSampleMaxError: number;
  204. }