index.d.ts 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. declare module 'babylonjs/physics' {
  2. interface PhysicsJointData {
  3. mainPivot?: Vector3;
  4. connectedPivot?: Vector3;
  5. mainAxis?: Vector3;
  6. connectedAxis?: Vector3;
  7. collision?: boolean;
  8. nativeParams?: any;
  9. }
  10. /**
  11. * This is a holder class for the physics joint created by the physics plugin.
  12. * It holds a set of functions to control the underlying joint.
  13. */
  14. class PhysicsJoint {
  15. type: number;
  16. jointData: PhysicsJointData;
  17. private _physicsJoint;
  18. protected _physicsPlugin: IPhysicsEnginePlugin;
  19. constructor(type: number, jointData: PhysicsJointData);
  20. physicsJoint: any;
  21. physicsPlugin: IPhysicsEnginePlugin;
  22. /**
  23. * Execute a function that is physics-plugin specific.
  24. * @param {Function} func the function that will be executed.
  25. * It accepts two parameters: the physics world and the physics joint.
  26. */
  27. executeNativeFunction(func: (world: any, physicsJoint: any) => void): void;
  28. static DistanceJoint: number;
  29. static HingeJoint: number;
  30. static BallAndSocketJoint: number;
  31. static WheelJoint: number;
  32. static SliderJoint: number;
  33. static PrismaticJoint: number;
  34. static UniversalJoint: number;
  35. static Hinge2Joint: number;
  36. static PointToPointJoint: number;
  37. static SpringJoint: number;
  38. static LockJoint: number;
  39. }
  40. /**
  41. * A class representing a physics distance joint.
  42. */
  43. class DistanceJoint extends PhysicsJoint {
  44. constructor(jointData: DistanceJointData);
  45. /**
  46. * Update the predefined distance.
  47. */
  48. updateDistance(maxDistance: number, minDistance?: number): void;
  49. }
  50. class MotorEnabledJoint extends PhysicsJoint implements IMotorEnabledJoint {
  51. constructor(type: number, jointData: PhysicsJointData);
  52. /**
  53. * Set the motor values.
  54. * Attention, this function is plugin specific. Engines won't react 100% the same.
  55. * @param {number} force the force to apply
  56. * @param {number} maxForce max force for this motor.
  57. */
  58. setMotor(force?: number, maxForce?: number): void;
  59. /**
  60. * Set the motor's limits.
  61. * Attention, this function is plugin specific. Engines won't react 100% the same.
  62. */
  63. setLimit(upperLimit: number, lowerLimit?: number): void;
  64. }
  65. /**
  66. * This class represents a single hinge physics joint
  67. */
  68. class HingeJoint extends MotorEnabledJoint {
  69. constructor(jointData: PhysicsJointData);
  70. /**
  71. * Set the motor values.
  72. * Attention, this function is plugin specific. Engines won't react 100% the same.
  73. * @param {number} force the force to apply
  74. * @param {number} maxForce max force for this motor.
  75. */
  76. setMotor(force?: number, maxForce?: number): void;
  77. /**
  78. * Set the motor's limits.
  79. * Attention, this function is plugin specific. Engines won't react 100% the same.
  80. */
  81. setLimit(upperLimit: number, lowerLimit?: number): void;
  82. }
  83. /**
  84. * This class represents a dual hinge physics joint (same as wheel joint)
  85. */
  86. class Hinge2Joint extends MotorEnabledJoint {
  87. constructor(jointData: PhysicsJointData);
  88. /**
  89. * Set the motor values.
  90. * Attention, this function is plugin specific. Engines won't react 100% the same.
  91. * @param {number} force the force to apply
  92. * @param {number} maxForce max force for this motor.
  93. * @param {motorIndex} the motor's index, 0 or 1.
  94. */
  95. setMotor(force?: number, maxForce?: number, motorIndex?: number): void;
  96. /**
  97. * Set the motor limits.
  98. * Attention, this function is plugin specific. Engines won't react 100% the same.
  99. * @param {number} upperLimit the upper limit
  100. * @param {number} lowerLimit lower limit
  101. * @param {motorIndex} the motor's index, 0 or 1.
  102. */
  103. setLimit(upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  104. }
  105. interface IMotorEnabledJoint {
  106. physicsJoint: any;
  107. setMotor(force?: number, maxForce?: number, motorIndex?: number): void;
  108. setLimit(upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  109. }
  110. interface DistanceJointData extends PhysicsJointData {
  111. maxDistance: number;
  112. }
  113. interface SpringJointData extends PhysicsJointData {
  114. length: number;
  115. stiffness: number;
  116. damping: number;
  117. }
  118. }
  119. declare module 'babylonjs/physics' {
  120. interface PhysicsImpostorParameters {
  121. mass: number;
  122. friction?: number;
  123. restitution?: number;
  124. nativeOptions?: any;
  125. ignoreParent?: boolean;
  126. disableBidirectionalTransformation?: boolean;
  127. }
  128. interface IPhysicsEnabledObject {
  129. position: Vector3;
  130. rotationQuaternion: Nullable<Quaternion>;
  131. scaling: Vector3;
  132. rotation?: Vector3;
  133. parent?: any;
  134. getBoundingInfo(): BoundingInfo;
  135. computeWorldMatrix(force: boolean): Matrix;
  136. getWorldMatrix?(): Matrix;
  137. getChildMeshes?(directDescendantsOnly?: boolean): Array<AbstractMesh>;
  138. getVerticesData(kind: string): Nullable<Array<number> | Float32Array>;
  139. getIndices?(): Nullable<IndicesArray>;
  140. getScene?(): Scene;
  141. getAbsolutePosition(): Vector3;
  142. getAbsolutePivotPoint(): Vector3;
  143. rotate(axis: Vector3, amount: number, space?: Space): TransformNode;
  144. translate(axis: Vector3, distance: number, space?: Space): TransformNode;
  145. setAbsolutePosition(absolutePosition: Vector3): TransformNode;
  146. getClassName(): string;
  147. }
  148. class PhysicsImpostor {
  149. object: IPhysicsEnabledObject;
  150. type: number;
  151. private _options;
  152. private _scene;
  153. static DEFAULT_OBJECT_SIZE: Vector3;
  154. static IDENTITY_QUATERNION: Quaternion;
  155. private _physicsEngine;
  156. private _physicsBody;
  157. private _bodyUpdateRequired;
  158. private _onBeforePhysicsStepCallbacks;
  159. private _onAfterPhysicsStepCallbacks;
  160. private _onPhysicsCollideCallbacks;
  161. private _deltaPosition;
  162. private _deltaRotation;
  163. private _deltaRotationConjugated;
  164. private _parent;
  165. private _isDisposed;
  166. private static _tmpVecs;
  167. private static _tmpQuat;
  168. readonly isDisposed: boolean;
  169. mass: number;
  170. friction: number;
  171. restitution: number;
  172. uniqueId: number;
  173. private _joints;
  174. constructor(object: IPhysicsEnabledObject, type: number, _options?: PhysicsImpostorParameters, _scene?: Scene | undefined);
  175. /**
  176. * This function will completly initialize this impostor.
  177. * It will create a new body - but only if this mesh has no parent.
  178. * If it has, this impostor will not be used other than to define the impostor
  179. * of the child mesh.
  180. */
  181. _init(): void;
  182. private _getPhysicsParent();
  183. /**
  184. * Should a new body be generated.
  185. */
  186. isBodyInitRequired(): boolean;
  187. setScalingUpdated(updated: boolean): void;
  188. /**
  189. * Force a regeneration of this or the parent's impostor's body.
  190. * Use under cautious - This will remove all joints already implemented.
  191. */
  192. forceUpdate(): void;
  193. /**
  194. * Gets the body that holds this impostor. Either its own, or its parent.
  195. */
  196. /**
  197. * Set the physics body. Used mainly by the physics engine/plugin
  198. */
  199. physicsBody: any;
  200. parent: Nullable<PhysicsImpostor>;
  201. resetUpdateFlags(): void;
  202. getObjectExtendSize(): Vector3;
  203. getObjectCenter(): Vector3;
  204. /**
  205. * Get a specific parametes from the options parameter.
  206. */
  207. getParam(paramName: string): any;
  208. /**
  209. * Sets a specific parameter in the options given to the physics plugin
  210. */
  211. setParam(paramName: string, value: number): void;
  212. /**
  213. * Specifically change the body's mass option. Won't recreate the physics body object
  214. */
  215. setMass(mass: number): void;
  216. getLinearVelocity(): Nullable<Vector3>;
  217. setLinearVelocity(velocity: Nullable<Vector3>): void;
  218. getAngularVelocity(): Nullable<Vector3>;
  219. setAngularVelocity(velocity: Nullable<Vector3>): void;
  220. /**
  221. * Execute a function with the physics plugin native code.
  222. * Provide a function the will have two variables - the world object and the physics body object.
  223. */
  224. executeNativeFunction(func: (world: any, physicsBody: any) => void): void;
  225. /**
  226. * Register a function that will be executed before the physics world is stepping forward.
  227. */
  228. registerBeforePhysicsStep(func: (impostor: PhysicsImpostor) => void): void;
  229. unregisterBeforePhysicsStep(func: (impostor: PhysicsImpostor) => void): void;
  230. /**
  231. * Register a function that will be executed after the physics step
  232. */
  233. registerAfterPhysicsStep(func: (impostor: PhysicsImpostor) => void): void;
  234. unregisterAfterPhysicsStep(func: (impostor: PhysicsImpostor) => void): void;
  235. /**
  236. * register a function that will be executed when this impostor collides against a different body.
  237. */
  238. registerOnPhysicsCollide(collideAgainst: PhysicsImpostor | Array<PhysicsImpostor>, func: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor) => void): void;
  239. unregisterOnPhysicsCollide(collideAgainst: PhysicsImpostor | Array<PhysicsImpostor>, func: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor | Array<PhysicsImpostor>) => void): void;
  240. private _tmpQuat;
  241. private _tmpQuat2;
  242. getParentsRotation(): Quaternion;
  243. /**
  244. * this function is executed by the physics engine.
  245. */
  246. beforeStep: () => void;
  247. /**
  248. * this function is executed by the physics engine.
  249. */
  250. afterStep: () => void;
  251. /**
  252. * Legacy collision detection event support
  253. */
  254. onCollideEvent: Nullable<(collider: PhysicsImpostor, collidedWith: PhysicsImpostor) => void>;
  255. onCollide: (e: {
  256. body: any;
  257. }) => void;
  258. /**
  259. * Apply a force
  260. */
  261. applyForce(force: Vector3, contactPoint: Vector3): PhysicsImpostor;
  262. /**
  263. * Apply an impulse
  264. */
  265. applyImpulse(force: Vector3, contactPoint: Vector3): PhysicsImpostor;
  266. /**
  267. * A help function to create a joint.
  268. */
  269. createJoint(otherImpostor: PhysicsImpostor, jointType: number, jointData: PhysicsJointData): PhysicsImpostor;
  270. /**
  271. * Add a joint to this impostor with a different impostor.
  272. */
  273. addJoint(otherImpostor: PhysicsImpostor, joint: PhysicsJoint): PhysicsImpostor;
  274. /**
  275. * Will keep this body still, in a sleep mode.
  276. */
  277. sleep(): PhysicsImpostor;
  278. /**
  279. * Wake the body up.
  280. */
  281. wakeUp(): PhysicsImpostor;
  282. clone(newObject: IPhysicsEnabledObject): Nullable<PhysicsImpostor>;
  283. dispose(): void;
  284. setDeltaPosition(position: Vector3): void;
  285. setDeltaRotation(rotation: Quaternion): void;
  286. getBoxSizeToRef(result: Vector3): PhysicsImpostor;
  287. getRadius(): number;
  288. /**
  289. * Sync a bone with this impostor
  290. * @param bone The bone to sync to the impostor.
  291. * @param boneMesh The mesh that the bone is influencing.
  292. * @param jointPivot The pivot of the joint / bone in local space.
  293. * @param distToJoint Optional distance from the impostor to the joint.
  294. * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
  295. */
  296. syncBoneWithImpostor(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion): void;
  297. /**
  298. * Sync impostor to a bone
  299. * @param bone The bone that the impostor will be synced to.
  300. * @param boneMesh The mesh that the bone is influencing.
  301. * @param jointPivot The pivot of the joint / bone in local space.
  302. * @param distToJoint Optional distance from the impostor to the joint.
  303. * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
  304. * @param boneAxis Optional vector3 axis the bone is aligned with
  305. */
  306. syncImpostorWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3): void;
  307. static NoImpostor: number;
  308. static SphereImpostor: number;
  309. static BoxImpostor: number;
  310. static PlaneImpostor: number;
  311. static MeshImpostor: number;
  312. static CylinderImpostor: number;
  313. static ParticleImpostor: number;
  314. static HeightmapImpostor: number;
  315. }
  316. }
  317. declare module 'babylonjs/physics' {
  318. interface PhysicsImpostorJoint {
  319. mainImpostor: PhysicsImpostor;
  320. connectedImpostor: PhysicsImpostor;
  321. joint: PhysicsJoint;
  322. }
  323. class PhysicsEngine {
  324. private _physicsPlugin;
  325. gravity: Vector3;
  326. constructor(gravity: Nullable<Vector3>, _physicsPlugin?: IPhysicsEnginePlugin);
  327. setGravity(gravity: Vector3): void;
  328. /**
  329. * Set the time step of the physics engine.
  330. * default is 1/60.
  331. * To slow it down, enter 1/600 for example.
  332. * To speed it up, 1/30
  333. * @param {number} newTimeStep the new timestep to apply to this world.
  334. */
  335. setTimeStep(newTimeStep?: number): void;
  336. /**
  337. * Get the time step of the physics engine.
  338. */
  339. getTimeStep(): number;
  340. dispose(): void;
  341. getPhysicsPluginName(): string;
  342. static Epsilon: number;
  343. private _impostors;
  344. private _joints;
  345. /**
  346. * Adding a new impostor for the impostor tracking.
  347. * This will be done by the impostor itself.
  348. * @param {PhysicsImpostor} impostor the impostor to add
  349. */
  350. addImpostor(impostor: PhysicsImpostor): void;
  351. /**
  352. * Remove an impostor from the engine.
  353. * This impostor and its mesh will not longer be updated by the physics engine.
  354. * @param {PhysicsImpostor} impostor the impostor to remove
  355. */
  356. removeImpostor(impostor: PhysicsImpostor): void;
  357. /**
  358. * Add a joint to the physics engine
  359. * @param {PhysicsImpostor} mainImpostor the main impostor to which the joint is added.
  360. * @param {PhysicsImpostor} connectedImpostor the impostor that is connected to the main impostor using this joint
  361. * @param {PhysicsJoint} the joint that will connect both impostors.
  362. */
  363. addJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
  364. removeJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
  365. /**
  366. * Called by the scene. no need to call it.
  367. */
  368. _step(delta: number): void;
  369. getPhysicsPlugin(): IPhysicsEnginePlugin;
  370. getImpostors(): Array<PhysicsImpostor>;
  371. getImpostorForPhysicsObject(object: IPhysicsEnabledObject): Nullable<PhysicsImpostor>;
  372. getImpostorWithPhysicsBody(body: any): Nullable<PhysicsImpostor>;
  373. }
  374. interface IPhysicsEnginePlugin {
  375. world: any;
  376. name: string;
  377. setGravity(gravity: Vector3): void;
  378. setTimeStep(timeStep: number): void;
  379. getTimeStep(): number;
  380. executeStep(delta: number, impostors: Array<PhysicsImpostor>): void;
  381. applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  382. applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  383. generatePhysicsBody(impostor: PhysicsImpostor): void;
  384. removePhysicsBody(impostor: PhysicsImpostor): void;
  385. generateJoint(joint: PhysicsImpostorJoint): void;
  386. removeJoint(joint: PhysicsImpostorJoint): void;
  387. isSupported(): boolean;
  388. setTransformationFromPhysicsBody(impostor: PhysicsImpostor): void;
  389. setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion): void;
  390. setLinearVelocity(impostor: PhysicsImpostor, velocity: Nullable<Vector3>): void;
  391. setAngularVelocity(impostor: PhysicsImpostor, velocity: Nullable<Vector3>): void;
  392. getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  393. getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  394. setBodyMass(impostor: PhysicsImpostor, mass: number): void;
  395. getBodyMass(impostor: PhysicsImpostor): number;
  396. getBodyFriction(impostor: PhysicsImpostor): number;
  397. setBodyFriction(impostor: PhysicsImpostor, friction: number): void;
  398. getBodyRestitution(impostor: PhysicsImpostor): number;
  399. setBodyRestitution(impostor: PhysicsImpostor, restitution: number): void;
  400. sleepBody(impostor: PhysicsImpostor): void;
  401. wakeUpBody(impostor: PhysicsImpostor): void;
  402. updateDistanceJoint(joint: PhysicsJoint, maxDistance: number, minDistance?: number): void;
  403. setMotor(joint: IMotorEnabledJoint, speed: number, maxForce?: number, motorIndex?: number): void;
  404. setLimit(joint: IMotorEnabledJoint, upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  405. getRadius(impostor: PhysicsImpostor): number;
  406. getBoxSizeToRef(impostor: PhysicsImpostor, result: Vector3): void;
  407. syncMeshWithImpostor(mesh: AbstractMesh, impostor: PhysicsImpostor): void;
  408. dispose(): void;
  409. }
  410. }
  411. declare module 'babylonjs/physics' {
  412. class PhysicsHelper {
  413. private _scene;
  414. private _physicsEngine;
  415. constructor(scene: Scene);
  416. /**
  417. * @param {Vector3} origin the origin of the explosion
  418. * @param {number} radius the explosion radius
  419. * @param {number} strength the explosion strength
  420. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  421. */
  422. applyRadialExplosionImpulse(origin: Vector3, radius: number, strength: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsRadialExplosionEvent>;
  423. /**
  424. * @param {Vector3} origin the origin of the explosion
  425. * @param {number} radius the explosion radius
  426. * @param {number} strength the explosion strength
  427. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  428. */
  429. applyRadialExplosionForce(origin: Vector3, radius: number, strength: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsRadialExplosionEvent>;
  430. /**
  431. * @param {Vector3} origin the origin of the explosion
  432. * @param {number} radius the explosion radius
  433. * @param {number} strength the explosion strength
  434. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  435. */
  436. gravitationalField(origin: Vector3, radius: number, strength: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsGravitationalFieldEvent>;
  437. /**
  438. * @param {Vector3} origin the origin of the updraft
  439. * @param {number} radius the radius of the updraft
  440. * @param {number} strength the strength of the updraft
  441. * @param {number} height the height of the updraft
  442. * @param {PhysicsUpdraftMode} updraftMode possible options: Center & Perpendicular. Defaults to Center
  443. */
  444. updraft(origin: Vector3, radius: number, strength: number, height: number, updraftMode?: PhysicsUpdraftMode): Nullable<PhysicsUpdraftEvent>;
  445. /**
  446. * @param {Vector3} origin the of the vortex
  447. * @param {number} radius the radius of the vortex
  448. * @param {number} strength the strength of the vortex
  449. * @param {number} height the height of the vortex
  450. */
  451. vortex(origin: Vector3, radius: number, strength: number, height: number): Nullable<PhysicsVortexEvent>;
  452. }
  453. /***** Radial explosion *****/
  454. class PhysicsRadialExplosionEvent {
  455. private _scene;
  456. private _sphere;
  457. private _sphereOptions;
  458. private _rays;
  459. private _dataFetched;
  460. constructor(scene: Scene);
  461. /**
  462. * Returns the data related to the radial explosion event (sphere & rays).
  463. * @returns {PhysicsRadialExplosionEventData}
  464. */
  465. getData(): PhysicsRadialExplosionEventData;
  466. /**
  467. * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
  468. * @param impostor
  469. * @param {Vector3} origin the origin of the explosion
  470. * @param {number} radius the explosion radius
  471. * @param {number} strength the explosion strength
  472. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear
  473. * @returns {Nullable<PhysicsForceAndContactPoint>}
  474. */
  475. getImpostorForceAndContactPoint(impostor: PhysicsImpostor, origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff): Nullable<PhysicsForceAndContactPoint>;
  476. /**
  477. * Disposes the sphere.
  478. * @param {bolean} force
  479. */
  480. dispose(force?: boolean): void;
  481. /*** Helpers ***/
  482. private _prepareSphere();
  483. private _intersectsWithSphere(impostor, origin, radius);
  484. }
  485. /***** Gravitational Field *****/
  486. class PhysicsGravitationalFieldEvent {
  487. private _physicsHelper;
  488. private _scene;
  489. private _origin;
  490. private _radius;
  491. private _strength;
  492. private _falloff;
  493. private _tickCallback;
  494. private _sphere;
  495. private _dataFetched;
  496. constructor(physicsHelper: PhysicsHelper, scene: Scene, origin: Vector3, radius: number, strength: number, falloff?: PhysicsRadialImpulseFalloff);
  497. /**
  498. * Returns the data related to the gravitational field event (sphere).
  499. * @returns {PhysicsGravitationalFieldEventData}
  500. */
  501. getData(): PhysicsGravitationalFieldEventData;
  502. /**
  503. * Enables the gravitational field.
  504. */
  505. enable(): void;
  506. /**
  507. * Disables the gravitational field.
  508. */
  509. disable(): void;
  510. /**
  511. * Disposes the sphere.
  512. * @param {bolean} force
  513. */
  514. dispose(force?: boolean): void;
  515. private _tick();
  516. }
  517. /***** Updraft *****/
  518. class PhysicsUpdraftEvent {
  519. private _scene;
  520. private _origin;
  521. private _radius;
  522. private _strength;
  523. private _height;
  524. private _updraftMode;
  525. private _physicsEngine;
  526. private _originTop;
  527. private _originDirection;
  528. private _tickCallback;
  529. private _cylinder;
  530. private _cylinderPosition;
  531. private _dataFetched;
  532. constructor(_scene: Scene, _origin: Vector3, _radius: number, _strength: number, _height: number, _updraftMode: PhysicsUpdraftMode);
  533. /**
  534. * Returns the data related to the updraft event (cylinder).
  535. * @returns {PhysicsUpdraftEventData}
  536. */
  537. getData(): PhysicsUpdraftEventData;
  538. /**
  539. * Enables the updraft.
  540. */
  541. enable(): void;
  542. /**
  543. * Disables the cortex.
  544. */
  545. disable(): void;
  546. /**
  547. * Disposes the sphere.
  548. * @param {bolean} force
  549. */
  550. dispose(force?: boolean): void;
  551. private getImpostorForceAndContactPoint(impostor);
  552. private _tick();
  553. /*** Helpers ***/
  554. private _prepareCylinder();
  555. private _intersectsWithCylinder(impostor);
  556. }
  557. /***** Vortex *****/
  558. class PhysicsVortexEvent {
  559. private _scene;
  560. private _origin;
  561. private _radius;
  562. private _strength;
  563. private _height;
  564. private _physicsEngine;
  565. private _originTop;
  566. private _centripetalForceThreshold;
  567. private _updraftMultiplier;
  568. private _tickCallback;
  569. private _cylinder;
  570. private _cylinderPosition;
  571. private _dataFetched;
  572. constructor(_scene: Scene, _origin: Vector3, _radius: number, _strength: number, _height: number);
  573. /**
  574. * Returns the data related to the vortex event (cylinder).
  575. * @returns {PhysicsVortexEventData}
  576. */
  577. getData(): PhysicsVortexEventData;
  578. /**
  579. * Enables the vortex.
  580. */
  581. enable(): void;
  582. /**
  583. * Disables the cortex.
  584. */
  585. disable(): void;
  586. /**
  587. * Disposes the sphere.
  588. * @param {bolean} force
  589. */
  590. dispose(force?: boolean): void;
  591. private getImpostorForceAndContactPoint(impostor);
  592. private _tick();
  593. /*** Helpers ***/
  594. private _prepareCylinder();
  595. private _intersectsWithCylinder(impostor);
  596. }
  597. /***** Enums *****/
  598. /**
  599. * The strenght of the force in correspondence to the distance of the affected object
  600. */
  601. enum PhysicsRadialImpulseFalloff {
  602. Constant = 0,
  603. Linear = 1,
  604. }
  605. /**
  606. * The strenght of the force in correspondence to the distance of the affected object
  607. */
  608. enum PhysicsUpdraftMode {
  609. Center = 0,
  610. Perpendicular = 1,
  611. }
  612. /***** Data interfaces *****/
  613. interface PhysicsForceAndContactPoint {
  614. force: Vector3;
  615. contactPoint: Vector3;
  616. }
  617. interface PhysicsRadialExplosionEventData {
  618. sphere: Mesh;
  619. rays: Array<Ray>;
  620. }
  621. interface PhysicsGravitationalFieldEventData {
  622. sphere: Mesh;
  623. }
  624. interface PhysicsUpdraftEventData {
  625. cylinder: Mesh;
  626. }
  627. interface PhysicsVortexEventData {
  628. cylinder: Mesh;
  629. }
  630. }
  631. declare module 'babylonjs/physics' {
  632. class CannonJSPlugin implements IPhysicsEnginePlugin {
  633. private _useDeltaForWorldStep;
  634. world: any;
  635. name: string;
  636. private _physicsMaterials;
  637. private _fixedTimeStep;
  638. BJSCANNON: any;
  639. constructor(_useDeltaForWorldStep?: boolean, iterations?: number);
  640. setGravity(gravity: Vector3): void;
  641. setTimeStep(timeStep: number): void;
  642. getTimeStep(): number;
  643. executeStep(delta: number, impostors: Array<PhysicsImpostor>): void;
  644. applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  645. applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  646. generatePhysicsBody(impostor: PhysicsImpostor): void;
  647. private _processChildMeshes(mainImpostor);
  648. removePhysicsBody(impostor: PhysicsImpostor): void;
  649. generateJoint(impostorJoint: PhysicsImpostorJoint): void;
  650. removeJoint(impostorJoint: PhysicsImpostorJoint): void;
  651. private _addMaterial(name, friction, restitution);
  652. private _checkWithEpsilon(value);
  653. private _createShape(impostor);
  654. private _createHeightmap(object, pointDepth?);
  655. private _minus90X;
  656. private _plus90X;
  657. private _tmpPosition;
  658. private _tmpDeltaPosition;
  659. private _tmpUnityRotation;
  660. private _updatePhysicsBodyTransformation(impostor);
  661. setTransformationFromPhysicsBody(impostor: PhysicsImpostor): void;
  662. setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion): void;
  663. isSupported(): boolean;
  664. setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
  665. setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
  666. getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  667. getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  668. setBodyMass(impostor: PhysicsImpostor, mass: number): void;
  669. getBodyMass(impostor: PhysicsImpostor): number;
  670. getBodyFriction(impostor: PhysicsImpostor): number;
  671. setBodyFriction(impostor: PhysicsImpostor, friction: number): void;
  672. getBodyRestitution(impostor: PhysicsImpostor): number;
  673. setBodyRestitution(impostor: PhysicsImpostor, restitution: number): void;
  674. sleepBody(impostor: PhysicsImpostor): void;
  675. wakeUpBody(impostor: PhysicsImpostor): void;
  676. updateDistanceJoint(joint: PhysicsJoint, maxDistance: number, minDistance?: number): void;
  677. setMotor(joint: IMotorEnabledJoint, speed?: number, maxForce?: number, motorIndex?: number): void;
  678. setLimit(joint: IMotorEnabledJoint, upperLimit: number, lowerLimit?: number): void;
  679. syncMeshWithImpostor(mesh: AbstractMesh, impostor: PhysicsImpostor): void;
  680. getRadius(impostor: PhysicsImpostor): number;
  681. getBoxSizeToRef(impostor: PhysicsImpostor, result: Vector3): void;
  682. dispose(): void;
  683. private _extendNamespace();
  684. }
  685. }
  686. declare module 'babylonjs/physics' {
  687. class OimoJSPlugin implements IPhysicsEnginePlugin {
  688. world: any;
  689. name: string;
  690. BJSOIMO: any;
  691. constructor(iterations?: number);
  692. setGravity(gravity: Vector3): void;
  693. setTimeStep(timeStep: number): void;
  694. getTimeStep(): number;
  695. private _tmpImpostorsArray;
  696. executeStep(delta: number, impostors: Array<PhysicsImpostor>): void;
  697. applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  698. applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3): void;
  699. generatePhysicsBody(impostor: PhysicsImpostor): void;
  700. private _tmpPositionVector;
  701. removePhysicsBody(impostor: PhysicsImpostor): void;
  702. generateJoint(impostorJoint: PhysicsImpostorJoint): void;
  703. removeJoint(impostorJoint: PhysicsImpostorJoint): void;
  704. isSupported(): boolean;
  705. setTransformationFromPhysicsBody(impostor: PhysicsImpostor): void;
  706. setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion): void;
  707. private _getLastShape(body);
  708. setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
  709. setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3): void;
  710. getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  711. getAngularVelocity(impostor: PhysicsImpostor): Nullable<Vector3>;
  712. setBodyMass(impostor: PhysicsImpostor, mass: number): void;
  713. getBodyMass(impostor: PhysicsImpostor): number;
  714. getBodyFriction(impostor: PhysicsImpostor): number;
  715. setBodyFriction(impostor: PhysicsImpostor, friction: number): void;
  716. getBodyRestitution(impostor: PhysicsImpostor): number;
  717. setBodyRestitution(impostor: PhysicsImpostor, restitution: number): void;
  718. sleepBody(impostor: PhysicsImpostor): void;
  719. wakeUpBody(impostor: PhysicsImpostor): void;
  720. updateDistanceJoint(joint: PhysicsJoint, maxDistance: number, minDistance?: number): void;
  721. setMotor(joint: IMotorEnabledJoint, speed: number, maxForce?: number, motorIndex?: number): void;
  722. setLimit(joint: IMotorEnabledJoint, upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
  723. syncMeshWithImpostor(mesh: AbstractMesh, impostor: PhysicsImpostor): void;
  724. getRadius(impostor: PhysicsImpostor): number;
  725. getBoxSizeToRef(impostor: PhysicsImpostor, result: Vector3): void;
  726. dispose(): void;
  727. }
  728. }
  729. import {EffectFallbacks,EffectCreationOptions,Effect,Nullable,float,double,int,FloatArray,IndicesArray,KeyboardEventTypes,KeyboardInfo,KeyboardInfoPre,PointerEventTypes,PointerInfoBase,PointerInfoPre,PointerInfo,ToGammaSpace,ToLinearSpace,Epsilon,Color3,Color4,Vector2,Vector3,Vector4,ISize,Size,Quaternion,Matrix,Plane,Viewport,Frustum,Space,Axis,BezierCurve,Orientation,Angle,Arc2,Path2,Path3D,Curve3,PositionNormalVertex,PositionNormalTextureVertex,Tmp,Scalar,expandToProperty,serialize,serializeAsTexture,serializeAsColor3,serializeAsFresnelParameters,serializeAsVector2,serializeAsVector3,serializeAsMeshReference,serializeAsColorCurves,serializeAsColor4,serializeAsImageProcessingConfiguration,serializeAsQuaternion,SerializationHelper,EventState,Observer,MultiObserver,Observable,SmartArray,SmartArrayNoDuplicate,IAnimatable,LoadFileError,RetryStrategy,IFileRequest,Tools,PerfCounter,className,AsyncLoop,_AlphaState,_DepthCullingState,_StencilState,InstancingAttributeInfo,RenderTargetCreationOptions,EngineCapabilities,EngineOptions,IDisplayChangedEventArgs,Engine,Node,BoundingSphere,BoundingBox,ICullable,BoundingInfo,TransformNode,AbstractMesh,Light,Camera,RenderingManager,RenderingGroup,IDisposable,IActiveMeshCandidateProvider,RenderingGroupInfo,Scene,Buffer,VertexBuffer,InternalTexture,BaseTexture,Texture,_InstancesBatch,Mesh,BaseSubMesh,SubMesh,MaterialDefines,Material,UniformBuffer,IGetSetVerticesData,VertexData,Geometry,_PrimitiveGeometry,RibbonGeometry,BoxGeometry,SphereGeometry,DiscGeometry,CylinderGeometry,TorusGeometry,GroundGeometry,TiledGroundGeometry,PlaneGeometry,TorusKnotGeometry,PostProcessManager,PerformanceMonitor,RollingAverage,IImageProcessingConfigurationDefines,ImageProcessingConfiguration,ColorGradingTexture,ColorCurves,Behavior,MaterialHelper,PushMaterial,StandardMaterialDefines,StandardMaterial} from 'babylonjs/core';
  730. import {EngineInstrumentation,SceneInstrumentation,_TimeToken} from 'babylonjs/instrumentation';
  731. import {Particle,IParticleSystem,ParticleSystem,BoxParticleEmitter,ConeParticleEmitter,SphereParticleEmitter,SphereDirectedParticleEmitter,IParticleEmitterType} from 'babylonjs/particles';
  732. import {GPUParticleSystem} from 'babylonjs/gpuParticles';
  733. import {FramingBehavior,BouncingBehavior,AutoRotationBehavior} from 'babylonjs/cameraBehaviors';
  734. import {NullEngineOptions,NullEngine} from 'babylonjs/nullEngine';
  735. import {TextureTools} from 'babylonjs/textureTools';
  736. import {SolidParticle,ModelShape,DepthSortedParticle,SolidParticleSystem} from 'babylonjs/solidParticles';
  737. import {Collider,CollisionWorker,ICollisionCoordinator,SerializedMesh,SerializedSubMesh,SerializedGeometry,BabylonMessage,SerializedColliderToWorker,WorkerTaskType,WorkerReply,CollisionReplyPayload,InitPayload,CollidePayload,UpdatePayload,WorkerReplyType,CollisionCoordinatorWorker,CollisionCoordinatorLegacy} from 'babylonjs/collisions';
  738. import {IntersectionInfo,PickingInfo,Ray} from 'babylonjs/picking';
  739. import {SpriteManager,Sprite} from 'babylonjs/sprites';
  740. import {AnimationRange,AnimationEvent,PathCursor,Animation,TargetedAnimation,AnimationGroup,RuntimeAnimation,Animatable,IEasingFunction,EasingFunction,CircleEase,BackEase,BounceEase,CubicEase,ElasticEase,ExponentialEase,PowerEase,QuadraticEase,QuarticEase,QuinticEase,SineEase,BezierCurveEase} from 'babylonjs/animations';
  741. import {Condition,ValueCondition,PredicateCondition,StateCondition,Action,ActionEvent,ActionManager,InterpolateValueAction,SwitchBooleanAction,SetStateAction,SetValueAction,IncrementValueAction,PlayAnimationAction,StopAnimationAction,DoNothingAction,CombineAction,ExecuteCodeAction,SetParentAction,PlaySoundAction,StopSoundAction} from 'babylonjs/actions';
  742. import {GroundMesh,InstancedMesh,LinesMesh} from 'babylonjs/additionalMeshes';
  743. import {ShaderMaterial} from 'babylonjs/shaderMaterial';
  744. import {MeshBuilder} from 'babylonjs/meshBuilder';
  745. import {PBRBaseMaterial,PBRBaseSimpleMaterial,PBRMaterial,PBRMetallicRoughnessMaterial,PBRSpecularGlossinessMaterial} from 'babylonjs/pbrMaterial';
  746. import {CameraInputTypes,ICameraInput,CameraInputsMap,CameraInputsManager,TargetCamera} from 'babylonjs/targetCamera';
  747. import {ArcRotateCameraKeyboardMoveInput,ArcRotateCameraMouseWheelInput,ArcRotateCameraPointersInput,ArcRotateCameraInputsManager,ArcRotateCamera} from 'babylonjs/arcRotateCamera';
  748. import {FreeCameraMouseInput,FreeCameraKeyboardMoveInput,FreeCameraInputsManager,FreeCamera} from 'babylonjs/freeCamera';
  749. import {HemisphericLight} from 'babylonjs/hemisphericLight';
  750. import {IShadowLight,ShadowLight,PointLight} from 'babylonjs/pointLight';
  751. import {DirectionalLight} from 'babylonjs/directionalLight';
  752. import {SpotLight} from 'babylonjs/spotLight';
  753. import {CubeTexture,RenderTargetTexture,IMultiRenderTargetOptions,MultiRenderTarget,MirrorTexture,RefractionTexture,DynamicTexture,VideoTexture,RawTexture} from 'babylonjs/additionalTextures';
  754. import {AudioEngine,Sound,SoundTrack,Analyser} from 'babylonjs/audio';
  755. import {ILoadingScreen,DefaultLoadingScreen,SceneLoaderProgressEvent,ISceneLoaderPluginExtensions,ISceneLoaderPluginFactory,ISceneLoaderPlugin,ISceneLoaderPluginAsync,SceneLoader,FilesInput} from 'babylonjs/loader';
  756. import {IShadowGenerator,ShadowGenerator} from 'babylonjs/shadows';
  757. import {StringDictionary} from 'babylonjs/stringDictionary';
  758. import {Tags,AndOrNotEvaluator} from 'babylonjs/userData';
  759. import {FresnelParameters} from 'babylonjs/fresnel';
  760. import {MultiMaterial} from 'babylonjs/multiMaterial';
  761. import {Database} from 'babylonjs/offline';
  762. import {FreeCameraTouchInput,TouchCamera} from 'babylonjs/touchCamera';
  763. import {ProceduralTexture,CustomProceduralTexture} from 'babylonjs/procedural';
  764. import {FreeCameraGamepadInput,ArcRotateCameraGamepadInput,GamepadManager,StickValues,GamepadButtonChanges,Gamepad,GenericPad,Xbox360Button,Xbox360Dpad,Xbox360Pad,PoseEnabledControllerType,MutableGamepadButton,ExtendedGamepadButton,PoseEnabledControllerHelper,PoseEnabledController,WebVRController,OculusTouchController,ViveController,GenericController,WindowsMotionController} from 'babylonjs/gamepad';
  765. import {FollowCamera,ArcFollowCamera,UniversalCamera,GamepadCamera} from 'babylonjs/additionalCameras';
  766. import {DepthRenderer} from 'babylonjs/depthRenderer';
  767. import {GeometryBufferRenderer} from 'babylonjs/geometryBufferRenderer';
  768. import {PostProcessOptions,PostProcess,PassPostProcess} from 'babylonjs/postProcesses';
  769. import {BlurPostProcess} from 'babylonjs/additionalPostProcess_blur';
  770. import {FxaaPostProcess} from 'babylonjs/additionalPostProcess_fxaa';
  771. import {HighlightsPostProcess} from 'babylonjs/additionalPostProcess_highlights';
  772. import {RefractionPostProcess,BlackAndWhitePostProcess,ConvolutionPostProcess,FilterPostProcess,VolumetricLightScatteringPostProcess,ColorCorrectionPostProcess,TonemappingOperator,TonemapPostProcess,DisplayPassPostProcess,ImageProcessingPostProcess} from 'babylonjs/additionalPostProcesses';
  773. import {PostProcessRenderPipelineManager,PostProcessRenderPass,PostProcessRenderEffect,PostProcessRenderPipeline} from 'babylonjs/renderingPipeline';
  774. import {SSAORenderingPipeline,SSAO2RenderingPipeline,LensRenderingPipeline,StandardRenderingPipeline} from 'babylonjs/additionalRenderingPipeline';
  775. import {DefaultRenderingPipeline} from 'babylonjs/defaultRenderingPipeline';
  776. import {Bone,BoneIKController,BoneLookController,Skeleton} from 'babylonjs/bones';
  777. import {SphericalPolynomial,SphericalHarmonics,CubeMapToSphericalPolynomialTools,CubeMapInfo,PanoramaToCubeMapTools,HDRInfo,HDRTools,HDRCubeTexture} from 'babylonjs/hdr';
  778. import {CSG} from 'babylonjs/csg';
  779. import {Polygon,PolygonMeshBuilder} from 'babylonjs/polygonMesh';
  780. import {LensFlare,LensFlareSystem} from 'babylonjs/lensFlares';
  781. import {TGATools,DDSInfo,DDSTools,KhronosTextureContainer} from 'babylonjs/textureFormats';
  782. import {Debug,RayHelper,DebugLayer,BoundingBoxRenderer} from 'babylonjs/debug';
  783. import {MorphTarget,MorphTargetManager} from 'babylonjs/morphTargets';
  784. import {IOctreeContainer,Octree,OctreeBlock} from 'babylonjs/octrees';
  785. import {SIMDHelper} from 'babylonjs/simd';
  786. import {VRDistortionCorrectionPostProcess,AnaglyphPostProcess,StereoscopicInterlacePostProcess,FreeCameraDeviceOrientationInput,ArcRotateCameraVRDeviceOrientationInput,VRCameraMetrics,DevicePose,PoseControlled,WebVROptions,WebVRFreeCamera,DeviceOrientationCamera,VRDeviceOrientationFreeCamera,VRDeviceOrientationGamepadCamera,VRDeviceOrientationArcRotateCamera,AnaglyphFreeCamera,AnaglyphArcRotateCamera,AnaglyphGamepadCamera,AnaglyphUniversalCamera,StereoscopicFreeCamera,StereoscopicArcRotateCamera,StereoscopicGamepadCamera,StereoscopicUniversalCamera,VRTeleportationOptions,VRExperienceHelperOptions,VRExperienceHelper} from 'babylonjs/vr';
  787. import {JoystickAxis,VirtualJoystick,VirtualJoysticksCamera,FreeCameraVirtualJoystickInput} from 'babylonjs/virtualJoystick';
  788. import {ISimplifier,ISimplificationSettings,SimplificationSettings,ISimplificationTask,SimplificationQueue,SimplificationType,DecimationTriangle,DecimationVertex,QuadraticMatrix,Reference,QuadraticErrorSimplification,MeshLODLevel,SceneOptimization,TextureOptimization,HardwareScalingOptimization,ShadowsOptimization,PostProcessesOptimization,LensFlaresOptimization,ParticlesOptimization,RenderTargetsOptimization,MergeMeshesOptimization,SceneOptimizerOptions,SceneOptimizer} from 'babylonjs/optimizations';
  789. import {OutlineRenderer,EdgesRenderer,IHighlightLayerOptions,HighlightLayer} from 'babylonjs/highlights';
  790. import {SceneSerializer} from 'babylonjs/serialization';
  791. import {AssetTaskState,AbstractAssetTask,IAssetsProgressEvent,AssetsProgressEvent,MeshAssetTask,TextFileAssetTask,BinaryFileAssetTask,ImageAssetTask,ITextureAssetTask,TextureAssetTask,CubeTextureAssetTask,HDRCubeTextureAssetTask,AssetsManager} from 'babylonjs/assetsManager';
  792. import {ReflectionProbe} from 'babylonjs/probes';
  793. import {BackgroundMaterial} from 'babylonjs/backgroundMaterial';
  794. import {Layer} from 'babylonjs/layer';
  795. import {IEnvironmentHelperOptions,EnvironmentHelper} from 'babylonjs/environmentHelper';