physicsShape.d.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import type { TransformNode } from "../../Meshes/transformNode";
  2. import type { AbstractMesh } from "../../Meshes/abstractMesh";
  3. import type { BoundingBox } from "../../Culling/boundingBox";
  4. import { PhysicsShapeType } from "./IPhysicsEnginePlugin";
  5. import type { PhysicsShapeParameters } from "./IPhysicsEnginePlugin";
  6. import type { PhysicsMaterial } from "./physicsMaterial";
  7. import { Vector3, Quaternion } from "../../Maths/math.vector";
  8. import type { Mesh } from "../../Meshes/mesh";
  9. import type { Scene } from "../../scene";
  10. /**
  11. * Options for creating a physics shape
  12. */
  13. export interface PhysicShapeOptions {
  14. /**
  15. * The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER
  16. */
  17. type?: PhysicsShapeType;
  18. /**
  19. * The parameters of the shape. Varies depending of the shape type.
  20. */
  21. parameters?: PhysicsShapeParameters;
  22. /**
  23. * Reference to an already existing physics shape in the plugin.
  24. */
  25. pluginData?: any;
  26. }
  27. /**
  28. * PhysicsShape class.
  29. * This class is useful for creating a physics shape that can be used in a physics engine.
  30. * A Physic Shape determine how collision are computed. It must be attached to a body.
  31. */
  32. export declare class PhysicsShape {
  33. /**
  34. * V2 Physics plugin private data for single shape
  35. */
  36. _pluginData: any;
  37. /**
  38. * The V2 plugin used to create and manage this Physics Body
  39. */
  40. private _physicsPlugin;
  41. private _type;
  42. private _material;
  43. private _isTrigger;
  44. private _isDisposed;
  45. /**
  46. * Constructs a new physics shape.
  47. * @param options The options for the physics shape. These are:
  48. * * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER
  49. * * parameters: The parameters of the shape.
  50. * * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.
  51. * You need to specify either type or pluginData.
  52. * @param scene The scene the shape belongs to.
  53. *
  54. * This code is useful for creating a new physics shape with the given type, options, and scene.
  55. * It also checks that the physics engine and plugin version are correct.
  56. * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.
  57. */
  58. constructor(options: PhysicShapeOptions, scene: Scene);
  59. /**
  60. * Returns the string "PhysicsShape".
  61. * @returns "PhysicsShape"
  62. */
  63. getClassName(): string;
  64. /**
  65. * Returns the type of the physics shape.
  66. * @returns The type of the physics shape.
  67. */
  68. get type(): PhysicsShapeType;
  69. /**
  70. * Set the membership mask of a shape. This is a bitfield of arbitrary
  71. * "categories" to which the shape is a member. This is used in combination
  72. * with the collide mask to determine if this shape should collide with
  73. * another.
  74. *
  75. * @param membershipMask Bitfield of categories of this shape.
  76. */
  77. set filterMembershipMask(membershipMask: number);
  78. /**
  79. * Get the membership mask of a shape.
  80. * @returns Bitmask of categories which this shape is a member of.
  81. */
  82. get filterMembershipMask(): number;
  83. /**
  84. * Sets the collide mask of a shape. This is a bitfield of arbitrary
  85. * "categories" to which this shape collides with. Given two shapes,
  86. * the engine will check if the collide mask and membership overlap:
  87. * shapeA.filterMembershipMask & shapeB.filterCollideMask
  88. *
  89. * If this value is zero (i.e. shapeB only collides with categories
  90. * which shapeA is _not_ a member of) then the shapes will not collide.
  91. *
  92. * Note, the engine will also perform the same test with shapeA and
  93. * shapeB swapped; the shapes will not collide if either shape has
  94. * a collideMask which prevents collision with the other shape.
  95. *
  96. * @param collideMask Bitmask of categories this shape should collide with
  97. */
  98. set filterCollideMask(collideMask: number);
  99. /**
  100. *
  101. * @returns Bitmask of categories that this shape should collide with
  102. */
  103. get filterCollideMask(): number;
  104. /**
  105. *
  106. * @param material
  107. */
  108. set material(material: PhysicsMaterial);
  109. /**
  110. * Returns the material of the physics shape.
  111. * @returns The material of the physics shape.
  112. */
  113. get material(): PhysicsMaterial;
  114. /**
  115. * Sets the density of the physics shape.
  116. * @param density The density of the physics shape.
  117. */
  118. set density(density: number);
  119. /**
  120. * Returns the density of the physics shape.
  121. * @returns The density of the physics shape.
  122. */
  123. get density(): number;
  124. /**
  125. * Utility to add a child shape to this container,
  126. * automatically computing the relative transform between
  127. * the container shape and the child instance.
  128. *
  129. * @param parentTransform The transform node associated with this shape
  130. * @param newChild The new PhysicsShape to add
  131. * @param childTransform The transform node associated with the child shape
  132. */
  133. addChildFromParent(parentTransform: TransformNode, newChild: PhysicsShape, childTransform: TransformNode): void;
  134. /**
  135. * Adds a child shape to a container with an optional transform
  136. * @param newChild The new PhysicsShape to add
  137. * @param translation Optional position of the child shape relative to this shape
  138. * @param rotation Optional rotation of the child shape relative to this shape
  139. * @param scale Optional scale of the child shape relative to this shape
  140. */
  141. addChild(newChild: PhysicsShape, translation?: Vector3, rotation?: Quaternion, scale?: Vector3): void;
  142. /**
  143. * Removes a child shape from this shape.
  144. * @param childIndex The index of the child shape to remove
  145. */
  146. removeChild(childIndex: number): void;
  147. /**
  148. * Returns the number of children of a physics shape.
  149. * @returns The number of children of a physics shape.
  150. */
  151. getNumChildren(): number;
  152. /**
  153. * Returns the bounding box of the physics shape.
  154. * @returns The bounding box of the physics shape.
  155. */
  156. getBoundingBox(): BoundingBox;
  157. set isTrigger(isTrigger: boolean);
  158. get isTrigger(): boolean;
  159. /**
  160. * Dispose the shape and release its associated resources.
  161. */
  162. dispose(): void;
  163. }
  164. /**
  165. * Helper object to create a sphere shape
  166. */
  167. export declare class PhysicsShapeSphere extends PhysicsShape {
  168. /**
  169. * Constructor for the Sphere Shape
  170. * @param center local center of the sphere
  171. * @param radius radius
  172. * @param scene scene to attach to
  173. */
  174. constructor(center: Vector3, radius: number, scene: Scene);
  175. /**
  176. * Derive an approximate sphere from the mesh.
  177. * @param mesh node from which to derive the sphere shape
  178. * @returns PhysicsShapeSphere
  179. */
  180. static FromMesh(mesh: AbstractMesh): PhysicsShapeSphere;
  181. }
  182. /**
  183. * Helper object to create a capsule shape
  184. */
  185. export declare class PhysicsShapeCapsule extends PhysicsShape {
  186. /**
  187. *
  188. * @param pointA Starting point that defines the capsule segment
  189. * @param pointB ending point of that same segment
  190. * @param radius radius
  191. * @param scene scene to attach to
  192. */
  193. constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene);
  194. /**
  195. * Derive an approximate capsule from the mesh. Note, this is
  196. * not the optimal bounding capsule.
  197. * @param mesh Node from which to derive a cylinder shape
  198. * @returns Physics Shape Capsule
  199. */
  200. static FromMesh(mesh: AbstractMesh): PhysicsShapeCapsule;
  201. }
  202. /**
  203. * Helper object to create a cylinder shape
  204. */
  205. export declare class PhysicsShapeCylinder extends PhysicsShape {
  206. /**
  207. *
  208. * @param pointA Starting point that defines the cylinder segment
  209. * @param pointB ending point of that same segment
  210. * @param radius radius
  211. * @param scene scene to attach to
  212. */
  213. constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene);
  214. /**
  215. * Derive an approximate cylinder from the mesh. Note, this is
  216. * not the optimal bounding cylinder.
  217. * @param mesh Node from which to derive a cylinder shape
  218. * @returns Physics Shape Cylinder
  219. */
  220. static FromMesh(mesh: AbstractMesh): PhysicsShapeCylinder;
  221. }
  222. /**
  223. * Helper object to create a box shape
  224. */
  225. export declare class PhysicsShapeBox extends PhysicsShape {
  226. /**
  227. *
  228. * @param center local center of the box
  229. * @param rotation local orientation
  230. * @param extents size of the box in each direction
  231. * @param scene scene to attach to
  232. */
  233. constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene);
  234. /**
  235. *
  236. * @param mesh
  237. * @returns PhysicsShapeBox
  238. */
  239. static FromMesh(mesh: AbstractMesh): PhysicsShapeBox;
  240. }
  241. /**
  242. * Helper object to create a convex hull shape
  243. */
  244. export declare class PhysicsShapeConvexHull extends PhysicsShape {
  245. /**
  246. *
  247. * @param mesh the mesh to be used as topology infos for the convex hull
  248. * @param scene scene to attach to
  249. */
  250. constructor(mesh: Mesh, scene: Scene);
  251. }
  252. /**
  253. * Helper object to create a mesh shape
  254. */
  255. export declare class PhysicsShapeMesh extends PhysicsShape {
  256. /**
  257. *
  258. * @param mesh the mesh topology that will be used to create the shape
  259. * @param scene scene to attach to
  260. */
  261. constructor(mesh: Mesh, scene: Scene);
  262. }
  263. /**
  264. * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.
  265. */
  266. export declare class PhysicsShapeContainer extends PhysicsShape {
  267. /**
  268. * Constructor of the Shape container
  269. * @param scene scene to attach to
  270. */
  271. constructor(scene: Scene);
  272. }