123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- import type { Nullable } from "../types";
- import { Vector3 } from "../Maths/math.vector";
- import type { Mesh } from "../Meshes/mesh";
- import type { Scene } from "../scene";
- import type { PhysicsImpostor } from "./v1/physicsImpostor";
- import type { PhysicsBody } from "./v2/physicsBody";
- /**
- * A helper for physics simulations
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare class PhysicsHelper {
- private _scene;
- private _physicsEngine;
- private _hitData;
- /**
- * Initializes the Physics helper
- * @param scene Babylon.js scene
- */
- constructor(scene: Scene);
- /**
- * Applies a radial explosion impulse
- * @param origin the origin of the explosion
- * @param radiusOrEventOptions the radius or the options of radial explosion
- * @param strength the explosion strength
- * @param falloff possible options: Constant & Linear. Defaults to Constant
- * @returns A physics radial explosion event, or null
- */
- applyRadialExplosionImpulse(origin: Vector3, radiusOrEventOptions: number | PhysicsRadialExplosionEventOptions, strength?: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsRadialExplosionEvent>;
- /**
- * Applies a radial explosion force
- * @param origin the origin of the explosion
- * @param radiusOrEventOptions the radius or the options of radial explosion
- * @param strength the explosion strength
- * @param falloff possible options: Constant & Linear. Defaults to Constant
- * @returns A physics radial explosion event, or null
- */
- applyRadialExplosionForce(origin: Vector3, radiusOrEventOptions: number | PhysicsRadialExplosionEventOptions, strength?: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsRadialExplosionEvent>;
- private _applicationForBodies;
- /**
- * Creates a gravitational field
- * @param origin the origin of the gravitational field
- * @param radiusOrEventOptions the radius or the options of radial gravitational field
- * @param strength the gravitational field strength
- * @param falloff possible options: Constant & Linear. Defaults to Constant
- * @returns A physics gravitational field event, or null
- */
- gravitationalField(origin: Vector3, radiusOrEventOptions: number | PhysicsRadialExplosionEventOptions, strength?: number, falloff?: PhysicsRadialImpulseFalloff): Nullable<PhysicsGravitationalFieldEvent>;
- /**
- * Creates a physics updraft event
- * @param origin the origin of the updraft
- * @param radiusOrEventOptions the radius or the options of the updraft
- * @param strength the strength of the updraft
- * @param height the height of the updraft
- * @param updraftMode possible options: Center & Perpendicular. Defaults to Center
- * @returns A physics updraft event, or null
- */
- updraft(origin: Vector3, radiusOrEventOptions: number | PhysicsUpdraftEventOptions, strength?: number, height?: number, updraftMode?: PhysicsUpdraftMode): Nullable<PhysicsUpdraftEvent>;
- /**
- * Creates a physics vortex event
- * @param origin the of the vortex
- * @param radiusOrEventOptions the radius or the options of the vortex
- * @param strength the strength of the vortex
- * @param height the height of the vortex
- * @returns a Physics vortex event, or null
- * A physics vortex event or null
- */
- vortex(origin: Vector3, radiusOrEventOptions: number | PhysicsVortexEventOptions, strength?: number, height?: number): Nullable<PhysicsVortexEvent>;
- private _copyPhysicsHitData;
- }
- /**
- * Represents a physics radial explosion event
- */
- declare class PhysicsRadialExplosionEvent {
- private _scene;
- private _options;
- private _sphere;
- private _dataFetched;
- /**
- * Initializes a radial explosion event
- * @param _scene BabylonJS scene
- * @param _options The options for the vortex event
- */
- constructor(_scene: Scene, _options: PhysicsRadialExplosionEventOptions);
- /**
- * Returns the data related to the radial explosion event (sphere).
- * @returns The radial explosion event data
- */
- getData(): PhysicsRadialExplosionEventData;
- private _getHitData;
- /**
- * Returns the force and contact point of the body or false, if the body is not affected by the force/impulse.
- * @param body A physics body where the transform node is an AbstractMesh
- * @param origin the origin of the explosion
- * @param data the data of the hit
- * @param instanceIndex the instance index of the body
- * @returns if there was a hit
- */
- getBodyHitData(body: PhysicsBody, origin: Vector3, data: PhysicsHitData, instanceIndex?: number): boolean;
- /**
- * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
- * @param impostor A physics imposter
- * @param origin the origin of the explosion
- * @param data the data of the hit
- * @returns A physics force and contact point, or null
- */
- getImpostorHitData(impostor: PhysicsImpostor, origin: Vector3, data: PhysicsHitData): boolean;
- /**
- * Triggers affected impostors callbacks
- * @param affectedImpostorsWithData defines the list of affected impostors (including associated data)
- */
- triggerAffectedImpostorsCallback(affectedImpostorsWithData: Array<PhysicsAffectedImpostorWithData>): void;
- /**
- * Triggers affected bodies callbacks
- * @param affectedBodiesWithData defines the list of affected bodies (including associated data)
- */
- triggerAffectedBodiesCallback(affectedBodiesWithData: Array<PhysicsAffectedBodyWithData>): void;
- /**
- * Disposes the sphere.
- * @param force Specifies if the sphere should be disposed by force
- */
- dispose(force?: boolean): void;
- /*** Helpers ***/
- private _prepareSphere;
- private _intersectsWithSphere;
- }
- /**
- * Represents a gravitational field event
- */
- declare class PhysicsGravitationalFieldEvent {
- private _physicsHelper;
- private _scene;
- private _origin;
- private _options;
- private _tickCallback;
- private _sphere;
- private _dataFetched;
- /**
- * Initializes the physics gravitational field event
- * @param _physicsHelper A physics helper
- * @param _scene BabylonJS scene
- * @param _origin The origin position of the gravitational field event
- * @param _options The options for the vortex event
- */
- constructor(_physicsHelper: PhysicsHelper, _scene: Scene, _origin: Vector3, _options: PhysicsRadialExplosionEventOptions);
- /**
- * Returns the data related to the gravitational field event (sphere).
- * @returns A gravitational field event
- */
- getData(): PhysicsGravitationalFieldEventData;
- /**
- * Enables the gravitational field.
- */
- enable(): void;
- /**
- * Disables the gravitational field.
- */
- disable(): void;
- /**
- * Disposes the sphere.
- * @param force The force to dispose from the gravitational field event
- */
- dispose(force?: boolean): void;
- private _tick;
- }
- /**
- * Represents a physics updraft event
- */
- declare class PhysicsUpdraftEvent {
- private _scene;
- private _origin;
- private _options;
- private _physicsEngine;
- private _originTop;
- private _originDirection;
- private _tickCallback;
- private _cylinder;
- private _cylinderPosition;
- private _dataFetched;
- private static _HitData;
- /**
- * Initializes the physics updraft event
- * @param _scene BabylonJS scene
- * @param _origin The origin position of the updraft
- * @param _options The options for the updraft event
- */
- constructor(_scene: Scene, _origin: Vector3, _options: PhysicsUpdraftEventOptions);
- /**
- * Returns the data related to the updraft event (cylinder).
- * @returns A physics updraft event
- */
- getData(): PhysicsUpdraftEventData;
- /**
- * Enables the updraft.
- */
- enable(): void;
- /**
- * Disables the updraft.
- */
- disable(): void;
- /**
- * Disposes the cylinder.
- * @param force Specifies if the updraft should be disposed by force
- */
- dispose(force?: boolean): void;
- private _getHitData;
- private _getBodyHitData;
- private _getImpostorHitData;
- private _tick;
- /*** Helpers ***/
- private _prepareCylinder;
- private _intersectsWithCylinder;
- }
- /**
- * Represents a physics vortex event
- */
- declare class PhysicsVortexEvent {
- private _scene;
- private _origin;
- private _options;
- private _physicsEngine;
- private _originTop;
- private _tickCallback;
- private _cylinder;
- private _cylinderPosition;
- private _dataFetched;
- private static _OriginOnPlane;
- private static _HitData;
- /**
- * Initializes the physics vortex event
- * @param _scene The BabylonJS scene
- * @param _origin The origin position of the vortex
- * @param _options The options for the vortex event
- */
- constructor(_scene: Scene, _origin: Vector3, _options: PhysicsVortexEventOptions);
- /**
- * Returns the data related to the vortex event (cylinder).
- * @returns The physics vortex event data
- */
- getData(): PhysicsVortexEventData;
- /**
- * Enables the vortex.
- */
- enable(): void;
- /**
- * Disables the cortex.
- */
- disable(): void;
- /**
- * Disposes the sphere.
- * @param force
- */
- dispose(force?: boolean): void;
- private _getHitData;
- private _getBodyHitData;
- private _getImpostorHitData;
- private _tick;
- /*** Helpers ***/
- private _prepareCylinder;
- private _intersectsWithCylinder;
- }
- /**
- * Options fot the radial explosion event
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare class PhysicsRadialExplosionEventOptions {
- /**
- * The radius of the sphere for the radial explosion.
- */
- radius: number;
- /**
- * The strength of the explosion.
- */
- strength: number;
- /**
- * The strength of the force in correspondence to the distance of the affected object
- */
- falloff: PhysicsRadialImpulseFalloff;
- /**
- * Sphere options for the radial explosion.
- */
- sphere: {
- segments: number;
- diameter: number;
- };
- /**
- * Sphere options for the radial explosion.
- */
- affectedImpostorsCallback: (affectedImpostorsWithData: Array<PhysicsAffectedImpostorWithData>) => void;
- /**
- * Sphere options for the radial explosion.
- */
- affectedBodiesCallback: (affectedBodiesWithData: Array<PhysicsAffectedBodyWithData>) => void;
- }
- /**
- * Options fot the updraft event
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare class PhysicsUpdraftEventOptions {
- /**
- * The radius of the cylinder for the vortex
- */
- radius: number;
- /**
- * The strength of the updraft.
- */
- strength: number;
- /**
- * The height of the cylinder for the updraft.
- */
- height: number;
- /**
- * The mode for the updraft.
- */
- updraftMode: PhysicsUpdraftMode;
- }
- /**
- * Options fot the vortex event
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare class PhysicsVortexEventOptions {
- /**
- * The radius of the cylinder for the vortex
- */
- radius: number;
- /**
- * The strength of the vortex.
- */
- strength: number;
- /**
- * The height of the cylinder for the vortex.
- */
- height: number;
- /**
- * At which distance, relative to the radius the centripetal forces should kick in? Range: 0-1
- */
- centripetalForceThreshold: number;
- /**
- * This multiplier determines with how much force the objects will be pushed sideways/around the vortex, when below the threshold.
- */
- centripetalForceMultiplier: number;
- /**
- * This multiplier determines with how much force the objects will be pushed sideways/around the vortex, when above the threshold.
- */
- centrifugalForceMultiplier: number;
- /**
- * This multiplier determines with how much force the objects will be pushed upwards, when in the vortex.
- */
- updraftForceMultiplier: number;
- }
- /**
- * The strength of the force in correspondence to the distance of the affected object
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare enum PhysicsRadialImpulseFalloff {
- /** Defines that impulse is constant in strength across it's whole radius */
- Constant = 0,
- /** Defines that impulse gets weaker if it's further from the origin */
- Linear = 1
- }
- /**
- * The strength of the force in correspondence to the distance of the affected object
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export declare enum PhysicsUpdraftMode {
- /** Defines that the upstream forces will pull towards the top center of the cylinder */
- Center = 0,
- /** Defines that once a impostor is inside the cylinder, it will shoot out perpendicular from the ground of the cylinder */
- Perpendicular = 1
- }
- /**
- * Interface for a physics hit data
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsHitData {
- /**
- * The force applied at the contact point
- */
- force: Vector3;
- /**
- * The contact point
- */
- contactPoint: Vector3;
- /**
- * The distance from the origin to the contact point
- */
- distanceFromOrigin: number;
- /**
- * For an instanced physics body (mesh with thin instances), the index of the thin instance the hit applies to
- */
- instanceIndex?: number;
- }
- /**
- * Interface for radial explosion event data
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsRadialExplosionEventData {
- /**
- * A sphere used for the radial explosion event
- */
- sphere: Mesh;
- }
- /**
- * Interface for gravitational field event data
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsGravitationalFieldEventData {
- /**
- * A sphere mesh used for the gravitational field event
- */
- sphere: Mesh;
- }
- /**
- * Interface for updraft event data
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsUpdraftEventData {
- /**
- * A cylinder used for the updraft event
- */
- cylinder?: Mesh;
- }
- /**
- * Interface for vortex event data
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsVortexEventData {
- /**
- * A cylinder used for the vortex event
- */
- cylinder: Mesh;
- }
- /**
- * Interface for an affected physics impostor
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
- */
- export interface PhysicsAffectedImpostorWithData {
- /**
- * The impostor affected by the effect
- */
- impostor: PhysicsImpostor;
- /**
- * The data about the hit/force from the explosion
- */
- hitData: PhysicsHitData;
- }
- /**
- * Interface for an affected physics body
- * @see
- */
- export interface PhysicsAffectedBodyWithData {
- /**
- * The impostor affected by the effect
- */
- body: PhysicsBody;
- /**
- * The data about the hit/force from the explosion
- */
- hitData: PhysicsHitData;
- }
- export {};
|