import { Context, ContextManager, Observable, Event } from '@zcomponent/core'; import { HP_BodyId, HP_ShapeId, HavokPhysicsWithBindings } from '@babylonjs/havok'; import { PhysicsMassProperties } from '../IPhysics'; import { Collider } from '..'; import { Vector3 } from 'three'; import { IRigidBody, MotionType } from '../components/IRigidBody'; import { HavokInternalAPI } from './internals'; import * as THREE from 'three'; import { PhysicsConstraint } from '../behaviors/constraints/PhysicsConstraint'; interface ConstructionProps { } /** * Context for the Havok physics engine. * * This context is used to manage the physics simulation and its associated properties. * @zonctext */ export declare class HavokContext extends Context { private havok; private scene; gravity: Observable<[number, number, number], never>; rigidBodies: IRigidBody[]; private _fixedTimeStep; private _useDeltaForWorldStep; havokInternalAPI: HavokInternalAPI; constraints: PhysicsConstraint[]; onPhysicsStart: Event<[]>; onPhysicsPause: Event<[]>; onPhysicsReset: Event<[]>; onPhysicsResume: Event<[]>; private physicsOrigin; physicsHelper: PhysicsHelper; /** * Fixed time step (in seconds), if none provided (0), the engine will use the * delta time between frames. * * A good value for fixed time step is 1/60 (60 fps). */ set fixedTimeStep(value: number); get fixedTimeStep(): number; private _notifyCollisionsVec3; running: boolean; private toolbar?; private needsReset; constructor(contextManager: ContextManager, constructorProps: ConstructionProps); updateTransforms(body: IRigidBody, transform?: [[number, number, number], [number, number, number, number]]): void; setPhysicsBodyTransformation(body: IRigidBody): void; private addShapeToBody; private createShape; recreateShape(body: IRigidBody, collider: Collider): void; resetBody(body: IRigidBody): void; initConstraint(constraint: PhysicsConstraint): void; initBody(body: IRigidBody): Promise; createDebugMesh(body: IRigidBody): THREE.Mesh | null; private syncTransform; private _frame; private _syncBody; private setTargetTransform; private getStepSize; private _notifyCollisions; dispose(): never; /** * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Public API begin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ removeBody: (bodyId: HP_BodyId) => void; /** * Sets the material of a physics shape. * @param shape - The physics shape to set the material of. * @param material - The material to set. * */ setMaterial(collider: Collider): void; /** * Enable collision to be reported for a body when a callback is settup on the world * @param body the physics body * @param enabled */ setCollisionCallbackEnabled: (body: IRigidBody, enabled: boolean) => void; /** * Applies an impulse to a physics body at a given location. * @param body - The physics body to apply the impulse to. * @param impulse - The impulse vector to apply. * @param location - The location in world space to apply the impulse. * @param instanceIndex - The index of the instance to apply the impulse to. If not specified, the impulse will be applied to all instances. * * This method is useful for applying an impulse to a physics body at a given location. * This can be used to simulate physical forces such as explosions, collisions, and gravity. */ applyImpulse: (body: IRigidBody, impulse: THREE.Vector3 | [number, number, number], location: THREE.Vector3 | [number, number, number]) => void; /** * Applies a force to a physics body at a given location. * @param body - The physics body to apply the impulse to. * @param force - The force vector to apply. * @param location - The location in world space to apply the impulse. * @param instanceIndex - The index of the instance to apply the force to. If not specified, the force will be applied to all instances. * * This method is useful for applying a force to a physics body at a given location. * This can be used to simulate physical forces such as explosions, collisions, and gravity. */ applyForce: (body: IRigidBody, force: THREE.Vector3 | [number, number, number], location: THREE.Vector3 | [number, number, number]) => void; private _parsev3; /** * Sets the mass properties of a physics body. * * @param body - The physics body to set the mass properties of. * @param massProps - The mass properties to set. * @param instanceIndex - The index of the instance to set the mass properties of. If undefined, the mass properties of all the bodies will be set. * This function is useful for setting the mass properties of a physics body, * such as its mass, inertia, and center of mass. This is important for * accurately simulating the physics of the body in the physics engine. * */ setMassProperties(body: IRigidBody): void; /** * Sets the angular velocity of a physics body. * @param body - The physics body to set the angular velocity for. * @param angVel - The angular velocity vector to set. */ setAngularVelocity: (body: IRigidBody, angVel: THREE.Vector3 | [number, number, number]) => void; /** * Sets the speed limit of the world * @param speedLimit - The speed limit to set. */ setSpeedLimit(speedLimit: number): void; /** * Gets the speed limit of the world * @returns The speed limit of the world */ getSpeedLimit(): number; /** * Sets the gravity factor of a body. * @param body - The physics body to set the gravity factor for. * @param factor - The gravity factor to set. */ setGravityFactor(body: IRigidBody, factor: number): void; /** * Gets the gravity factor of a body. * @param body - The physics body to retrieve the gravity factor from. * @returns The gravity factor of the body. */ getGravityFactor: (body: IRigidBody) => number; /** * Sets the linear velocity of a physics body. * @param body - The physics body to set the linear velocity for. * @param linVel - The linear velocity vector to set. */ setLinearVelocity: (body: IRigidBody, linVel: THREE.Vector3 | [number, number, number]) => void; /** * Gets the linear damping of a physics body. * @param body - The physics body to get the linear damping from. * @returns The linear damping of the body. */ getLinearDamping: (body: IRigidBody) => number; /** * Gets the mass properties of a physics body. * @param body - The physics body to retrieve the mass properties from. * @returns The mass properties of the body. */ getMassProperties: (body: IRigidBody) => PhysicsMassProperties; /** * Gets the material associated with a physics shape. * @param shape - The shape to get the material from. * @returns The material associated with the shape. */ getMaterial: (shapeID: HP_ShapeId) => { staticFriction: number; dynamicFriction: number; restitution: number; frictionCombine: import("..").PhysicsMaterialCombineMode | undefined; restitutionCombine: import("..").PhysicsMaterialCombineMode | undefined; }; /** * Enables or disables a constraint in the physics engine. * @param constraint - The constraint to enable or disable. * @param isEnabled - Whether the constraint should be enabled or disabled. * */ setConstraintEnabled: (constraint: PhysicsConstraint, isEnabled: boolean) => void; /** * Gets the enabled state of the given constraint. * @param constraint - The constraint to get the enabled state from. * @returns The enabled state of the given constraint. * */ getConstraintEnabled: (constraint: PhysicsConstraint) => boolean; setCollisionsEnabled: (constraint: PhysicsConstraint, isEnabled: boolean) => void; /** * Sets the density of a physics shape. * @param body - The physics body to set the density of. * @param density - The density to set. * */ setDensity(body: IRigidBody, density: number): void; /** * Gets the density of a physics shape. */ getDensity: (body: IRigidBody) => number; /** * Gets the number of bodies in the world */ get numBodies(): number; /** * Sets the linear damping of the given body. * @param body - The body to set the linear damping for. * @param damping - The linear damping to set. * * This method is useful for controlling the linear damping of a body in a physics engine. * Linear damping is a force that opposes the motion of the body, and is proportional to the velocity of the body. * This method allows the user to set the linear damping of a body, which can be used to control the motion of the body. */ setLinearDamping(body: IRigidBody, damping: number): void; /** * Sets the motion type of a physics body. * Can be STATIC, DYNAMIC, or KINEMATIC. */ setMotionType(body: IRigidBody, motionType: MotionType): void; /** * Gets the motion type of a physics body. */ getMotionType: (body: IRigidBody) => MotionType; /** * Sets the angular damping of a physics body. * @param body - The physics body to set the angular damping for. * @param damping - The angular damping value to set. * * This function is useful for controlling the angular velocity of a physics body. * By setting the angular damping, the body's angular velocity will be reduced over time, allowing for more realistic physics simulations. */ setAngularDamping(body: IRigidBody, damping: number): void; /** * Gets the angular damping of a physics body. * @param body - The physics body to get the angular damping from. * @returns The angular damping of the body. * * This function is useful for retrieving the angular damping of a physics body, * which is used to control the rotational motion of the body. The angular damping is a value between 0 and 1, where 0 is no damping and 1 is full damping. */ getAngularDamping: (body: IRigidBody) => number; /** * Gets the linear velocity of a physics body and stores it in a given vector. * @param body - The physics body to get the linear velocity from. * @param linVel - The vector to store the linear velocity in. * * This method is useful for retrieving the linear velocity of a physics body, * which can be used to determine the speed and direction of the body. This * information can be useful to simulate realistic physics behavior in a game. */ getLinearVelocityToRef: (body: IRigidBody, linVel: THREE.Vector3) => void; getAngularVelocityToRef: (body: IRigidBody, angVel: THREE.Vector3) => void; /** * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! EDITOR CONTEXT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ private pauseSimulation; private playSimulation; resetSimulation: (skipEmit?: boolean) => void; registerPhysicsOrigin(origin: { element: THREE.Object3D; }): void; unregisterPhysicsOrigin(origin: { element: THREE.Object3D; }): void; private _physicsOriginMatrix; private _tempPosition; private _tempQuaternion; private _tempScale; getPhysicsOriginTransform(): THREE.Matrix4 | null; /** * Returns the scale component of the physics origin's world transform. * Used to factor out parent scale when computing collider shapes so that * shapes are defined in unscaled physics space. */ getPhysicsOriginScale(): THREE.Vector3 | null; /** * !CALLED EXTERNALLY BY LOAD CONTEXT */ ________setupWorld: (havok: HavokPhysicsWithBindings) => void; } export declare const useOnPhysicsStart: (contextManager: ContextManager) => Event<[]>; export declare const useOnPhysicsPause: (contextManager: ContextManager) => Event<[]>; export declare const useOnPhysicsReset: (contextManager: ContextManager) => Event<[]>; export declare const useOnPhysicsResume: (contextManager: ContextManager) => Event<[]>; /** * A helper for physics simulations */ export declare class PhysicsHelper { private contextManager; private _scene; private _hitData; /** * Initializes the Physics helper * @param contextManager Zum Context Manager */ constructor(contextManager: ContextManager); /** * 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): PhysicsRadialExplosionEvent | null; /** * 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): PhysicsRadialExplosionEvent | null; /** * 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): PhysicsGravitationalFieldEvent | null; /** * 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): PhysicsUpdraftEvent | null; /** * 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): PhysicsVortexEvent | null; 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 Three.js scene * @param _options The options for the vortex event */ constructor(_scene: THREE.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 * @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: IRigidBody, origin: Vector3, data: PhysicsHitData, instanceIndex?: number): boolean; /** * Triggers affected bodies callbacks * @param affectedBodiesWithData defines the list of affected bodies (including associated data) */ triggerAffectedBodiesCallback(affectedBodiesWithData: Array): void; /** * Disposes the sphere. * @param force Specifies if the sphere should be disposed by force */ /** * 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 contextManager; 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 Three.js scene * @param _origin The origin position of the gravitational field event * @param _options The options for the vortex event */ constructor(contextManager: ContextManager, _physicsHelper: PhysicsHelper, _scene: THREE.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 */ export declare class PhysicsUpdraftEvent { private contextManager; private _scene; private _origin; private _options; private _originTop; private _originDirection; private _tickCallback; private _cylinder; private _cylinderPosition; private _dataFetched; private static _HitData; /** * Initializes the physics updraft event * @param _scene Three.js scene * @param _origin The origin position of the updraft * @param _options The options for the updraft event */ constructor(contextManager: ContextManager, _scene: THREE.Scene, _origin: Vector3, _options: PhysicsUpdraftEventOptions); updateOptions(options: Partial, origin: Vector3): void; /** * 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 _tick; /*** Helpers ***/ private _prepareCylinder; private _intersectsWithCylinder; } /** * Represents a physics vortex event */ export declare class PhysicsVortexEvent { private contextManager; private _scene; private _origin; private _options; private _originTop; private _tickCallback; private _cylinder; private _cylinderPosition; private _dataFetched; private static _OriginOnPlane; private static _HitData; /** * Initializes the physics vortex event * @param _scene The Three.js scene * @param _origin The origin position of the vortex * @param _options The options for the vortex event */ constructor(contextManager: ContextManager, _scene: THREE.Scene, _origin: Vector3, _options: PhysicsVortexEventOptions); updateOptions(options: Partial, origin: Vector3): void; /** * 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 _tick; /*** Helpers ***/ private _prepareCylinder; private _intersectsWithCylinder; } /** * Options fot the radial explosion event */ 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. */ affectedBodiesCallback: (affectedBodiesWithData: Array) => void; } /** * Options fot the updraft event */ 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 */ 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 */ 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 */ export declare enum PhysicsUpdraftMode { /** Defines that the upstream forces will pull towards the top center of the cylinder */ Center = 0, /** Defines that once a body is inside the cylinder, it will shoot out perpendicular from the ground of the cylinder */ Perpendicular = 1 } /** * Interface for a physics hit data */ 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 */ export interface PhysicsRadialExplosionEventData { /** * A sphere used for the radial explosion event */ sphere: THREE.Mesh; } /** * Interface for gravitational field event data */ export interface PhysicsGravitationalFieldEventData { /** * A sphere mesh used for the gravitational field event */ sphere: THREE.Mesh; } /** * Interface for updraft event data */ export interface PhysicsUpdraftEventData { /** * A cylinder used for the updraft event */ cylinder?: THREE.Mesh; } /** * Interface for vortex event data */ export interface PhysicsVortexEventData { /** * A cylinder used for the vortex event */ cylinder: THREE.Mesh; } /** * Interface for an affected physics body */ export interface PhysicsAffectedBodyWithData { /** * The body affected by the effect */ body: IRigidBody; /** * The data about the hit/force from the explosion */ hitData: PhysicsHitData; } export {};