physicsJoint.d.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import type { Vector3 } from "../../Maths/math.vector";
  2. import type { IPhysicsEnginePlugin } from "./IPhysicsEnginePlugin";
  3. /**
  4. * Interface for Physics-Joint data
  5. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  6. */
  7. export interface PhysicsJointData {
  8. /**
  9. * The main pivot of the joint
  10. */
  11. mainPivot?: Vector3;
  12. /**
  13. * The connected pivot of the joint
  14. */
  15. connectedPivot?: Vector3;
  16. /**
  17. * The main axis of the joint
  18. */
  19. mainAxis?: Vector3;
  20. /**
  21. * The connected axis of the joint
  22. */
  23. connectedAxis?: Vector3;
  24. /**
  25. * The collision of the joint
  26. */
  27. collision?: boolean;
  28. /**
  29. * Native Oimo/Cannon/Energy data
  30. */
  31. nativeParams?: any;
  32. }
  33. /**
  34. * This is a holder class for the physics joint created by the physics plugin
  35. * It holds a set of functions to control the underlying joint
  36. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  37. */
  38. export declare class PhysicsJoint {
  39. /**
  40. * The type of the physics joint
  41. */
  42. type: number;
  43. /**
  44. * The data for the physics joint
  45. */
  46. jointData: PhysicsJointData;
  47. private _physicsJoint;
  48. protected _physicsPlugin: IPhysicsEnginePlugin;
  49. /**
  50. * Initializes the physics joint
  51. * @param type The type of the physics joint
  52. * @param jointData The data for the physics joint
  53. */
  54. constructor(
  55. /**
  56. * The type of the physics joint
  57. */
  58. type: number,
  59. /**
  60. * The data for the physics joint
  61. */
  62. jointData: PhysicsJointData);
  63. /**
  64. * Gets the physics joint
  65. */
  66. get physicsJoint(): any;
  67. /**
  68. * Sets the physics joint
  69. */
  70. set physicsJoint(newJoint: any);
  71. /**
  72. * Sets the physics plugin
  73. */
  74. set physicsPlugin(physicsPlugin: IPhysicsEnginePlugin);
  75. /**
  76. * Execute a function that is physics-plugin specific.
  77. * @param {Function} func the function that will be executed.
  78. * It accepts two parameters: the physics world and the physics joint
  79. */
  80. executeNativeFunction(func: (world: any, physicsJoint: any) => void): void;
  81. /**
  82. * Distance-Joint type
  83. */
  84. static DistanceJoint: number;
  85. /**
  86. * Hinge-Joint type
  87. */
  88. static HingeJoint: number;
  89. /**
  90. * Ball-and-Socket joint type
  91. */
  92. static BallAndSocketJoint: number;
  93. /**
  94. * Wheel-Joint type
  95. */
  96. static WheelJoint: number;
  97. /**
  98. * Slider-Joint type
  99. */
  100. static SliderJoint: number;
  101. /**
  102. * Prismatic-Joint type
  103. */
  104. static PrismaticJoint: number;
  105. /**
  106. * Universal-Joint type
  107. * ENERGY FTW! (compare with this - @see http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions)
  108. */
  109. static UniversalJoint: number;
  110. /**
  111. * Hinge-Joint 2 type
  112. */
  113. static Hinge2Joint: number;
  114. /**
  115. * Point to Point Joint type. Similar to a Ball-Joint. Different in parameters
  116. */
  117. static PointToPointJoint: number;
  118. /**
  119. * Spring-Joint type
  120. */
  121. static SpringJoint: number;
  122. /**
  123. * Lock-Joint type
  124. */
  125. static LockJoint: number;
  126. }
  127. /**
  128. * A class representing a physics distance joint
  129. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  130. */
  131. export declare class DistanceJoint extends PhysicsJoint {
  132. /**
  133. *
  134. * @param jointData The data for the Distance-Joint
  135. */
  136. constructor(jointData: DistanceJointData);
  137. /**
  138. * Update the predefined distance.
  139. * @param maxDistance The maximum preferred distance
  140. * @param minDistance The minimum preferred distance
  141. */
  142. updateDistance(maxDistance: number, minDistance?: number): void;
  143. }
  144. /**
  145. * Represents a Motor-Enabled Joint
  146. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  147. */
  148. export declare class MotorEnabledJoint extends PhysicsJoint implements IMotorEnabledJoint {
  149. /**
  150. * Initializes the Motor-Enabled Joint
  151. * @param type The type of the joint
  152. * @param jointData The physical joint data for the joint
  153. */
  154. constructor(type: number, jointData: PhysicsJointData);
  155. /**
  156. * Set the motor values.
  157. * Attention, this function is plugin specific. Engines won't react 100% the same.
  158. * @param force the force to apply
  159. * @param maxForce max force for this motor.
  160. */
  161. setMotor(force?: number, maxForce?: number): void;
  162. /**
  163. * Set the motor's limits.
  164. * Attention, this function is plugin specific. Engines won't react 100% the same.
  165. * @param upperLimit The upper limit of the motor
  166. * @param lowerLimit The lower limit of the motor
  167. */
  168. setLimit(upperLimit: number, lowerLimit?: number): void;
  169. }
  170. /**
  171. * This class represents a single physics Hinge-Joint
  172. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  173. */
  174. export declare class HingeJoint extends MotorEnabledJoint {
  175. /**
  176. * Initializes the Hinge-Joint
  177. * @param jointData The joint data for the Hinge-Joint
  178. */
  179. constructor(jointData: PhysicsJointData);
  180. /**
  181. * Set the motor values.
  182. * Attention, this function is plugin specific. Engines won't react 100% the same.
  183. * @param {number} force the force to apply
  184. * @param {number} maxForce max force for this motor.
  185. */
  186. setMotor(force?: number, maxForce?: number): void;
  187. /**
  188. * Set the motor's limits.
  189. * Attention, this function is plugin specific. Engines won't react 100% the same.
  190. * @param upperLimit The upper limit of the motor
  191. * @param lowerLimit The lower limit of the motor
  192. */
  193. setLimit(upperLimit: number, lowerLimit?: number): void;
  194. }
  195. /**
  196. * This class represents a dual hinge physics joint (same as wheel joint)
  197. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  198. */
  199. export declare class Hinge2Joint extends MotorEnabledJoint {
  200. /**
  201. * Initializes the Hinge2-Joint
  202. * @param jointData The joint data for the Hinge2-Joint
  203. */
  204. constructor(jointData: PhysicsJointData);
  205. /**
  206. * Set the motor values.
  207. * Attention, this function is plugin specific. Engines won't react 100% the same.
  208. * @param targetSpeed the speed the motor is to reach
  209. * @param maxForce max force for this motor.
  210. * @param motorIndex motor's index, 0 or 1.
  211. */
  212. setMotor(targetSpeed?: number, maxForce?: number, motorIndex?: number): void;
  213. /**
  214. * Set the motor limits.
  215. * Attention, this function is plugin specific. Engines won't react 100% the same.
  216. * @param upperLimit the upper limit
  217. * @param lowerLimit lower limit
  218. * @param motorIndex the motor's index, 0 or 1.
  219. */
  220. setLimit(upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  221. }
  222. /**
  223. * Interface for a motor enabled joint
  224. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  225. */
  226. export interface IMotorEnabledJoint {
  227. /**
  228. * Physics joint
  229. */
  230. physicsJoint: any;
  231. /**
  232. * Sets the motor of the motor-enabled joint
  233. * @param force The force of the motor
  234. * @param maxForce The maximum force of the motor
  235. * @param motorIndex The index of the motor
  236. */
  237. setMotor(force?: number, maxForce?: number, motorIndex?: number): void;
  238. /**
  239. * Sets the limit of the motor
  240. * @param upperLimit The upper limit of the motor
  241. * @param lowerLimit The lower limit of the motor
  242. * @param motorIndex The index of the motor
  243. */
  244. setLimit(upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  245. }
  246. /**
  247. * Joint data for a Distance-Joint
  248. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  249. */
  250. export interface DistanceJointData extends PhysicsJointData {
  251. /**
  252. * Max distance the 2 joint objects can be apart
  253. */
  254. maxDistance: number;
  255. }
  256. /**
  257. * Joint data from a spring joint
  258. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  259. */
  260. export interface SpringJointData extends PhysicsJointData {
  261. /**
  262. * Length of the spring
  263. */
  264. length: number;
  265. /**
  266. * Stiffness of the spring
  267. */
  268. stiffness: number;
  269. /**
  270. * Damping of the spring
  271. */
  272. damping: number;
  273. /** this callback will be called when applying the force to the impostors. */
  274. forceApplicationCallback: () => void;
  275. }