API

Class HavokPlugin

The Havok Physics plugin

Index
_internalSetMotionType addChild addConstraint applyAngularImpulse applyForce applyImpulse applyTorque computeMassProperties dispose disposeBody disposeConstraint disposeShape executeStep getAngularDamping getAngularVelocityToRef getAxisFriction getAxisMaxLimit getAxisMinLimit getAxisMode getAxisMotorMaxForce getAxisMotorTarget getAxisMotorType getBodiesUsingConstraint getBodyBoundingBox getBodyGeometry getBoundingBox getCollisionEndedObservable getCollisionObservable getCollisionsEnabled getDensity getEnabled getEventMask getGravity getGravityFactor getLinearDamping getLinearVelocityToRef getMassProperties getMaterial getMaxAngularVelocity getMaxLinearVelocity getMaxQueryCollectorHits getMotionType getNumChildren getPluginVersion getShape getShapeFilterCollideMask getShapeFilterMembershipMask getShapeType getTimeStep initBody initBodyInstances initConstraint initShape isSupported pointProximity raycast removeBody removeChild setActivationControl setAngularDamping setAngularVelocity setAxisFriction setAxisMaxLimit setAxisMinLimit setAxisMode setAxisMotorMaxForce setAxisMotorTarget setAxisMotorType setCollisionCallbackEnabled setCollisionEndedCallbackEnabled setCollisionsEnabled setDensity setEnabled setEventMask setGravity setGravityFactor setLinearDamping setLinearVelocity setMassProperties setMaterial setMaxQueryCollectorHits setMotionType setPhysicsBodyTransformation setShape setShapeFilterCollideMask setShapeFilterMembershipMask setTargetTransform setTimeStep setTrigger setVelocityLimits shapeCast shapeProximity sync syncTransform updateBodyInstances
_hknp: any = {}

Reference to the WASM library

name: string = "HavokPlugin"

Name of the plugin

onCollisionEndedObservable: Observable<IBasePhysicsCollisionEvent> = ...

Observable for collision ended events

onCollisionObservable: Observable<IPhysicsCollisionEvent> = ...

Observable for collision started and collision continued events

onTriggerCollisionObservable: Observable<IBasePhysicsCollisionEvent> = ...

Observable for trigger entered and trigger exited events

world: any

Created Havok world which physics bodies are added to (default world for non-floating-origin)

  • Adds a constraint to the physics engine.

    Parameters

    • body: PhysicsBody

      The main body to which the constraint is applied.

    • childBody: PhysicsBody

      The body to which the constraint is applied.

    • constraint: PhysicsConstraint

      The constraint to be applied.

    • OptionalinstanceIndex: number

      If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.

    • OptionalchildInstanceIndex: number

      If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.

    Returns void

  • Applies an angular impulse(torque) to a physics body

    Parameters

    • body: PhysicsBody

      The physics body to apply the impulse to.

    • angularImpulse: Vector3

      The torque value

    • OptionalinstanceIndex: number

      The index of the instance to apply the impulse to. If not specified, the impulse will be applied to all instances.

    Returns void

  • Applies a force to a physics body at a given location.

    Parameters

    • body: PhysicsBody

      The physics body to apply the impulse to.

    • force: Vector3

      The force vector to apply.

    • location: Vector3

      The location in world space to apply the impulse.

    • OptionalinstanceIndex: number

      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.

    Returns void

  • Applies an impulse to a physics body at a given location.

    Parameters

    • body: PhysicsBody

      The physics body to apply the impulse to.

    • impulse: Vector3

      The impulse vector to apply.

    • location: Vector3

      The location in world space to apply the impulse.

    • OptionalinstanceIndex: number

      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.

    Returns void

  • Applies a torque to a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to apply the torque to.

    • torque: Vector3

      The torque vector.

    • OptionalinstanceIndex: number

      The index of the instance to apply the torque to. If not specified, the torque will be applied to all instances.

      This method is useful for applying a torque to a physics body. This can be used to simulate rotational forces such as motors, angular momentum, and rotational dynamics.

    Returns void

  • Disposes a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to dispose.

      This method is useful for releasing the resources associated with a physics body when it is no longer needed. This is important for avoiding memory leaks in the physics engine.

    Returns void

  • Disposes a physics constraint.

    Parameters

    • constraint: PhysicsConstraint

      The physics constraint to dispose.

      This method is useful for releasing the resources associated with a physics constraint, such as the Havok constraint, when it is no longer needed. This is important for avoiding memory leaks.

    Returns void

  • Releases a physics shape from the physics engine.

    Parameters

    • shape: PhysicsShape

      The physics shape to be released.

      This method is useful for releasing a physics shape from the physics engine, freeing up resources and preventing memory leaks.

    Returns void

  • Executes a single step of the physics engine.

    Parameters

    • delta: number

      The time delta in seconds since the last step.

    • physicsBodies: PhysicsBody[]

      An array of physics bodies to be simulated.

      This method is useful for simulating the physics engine. It sets the physics body transformation, steps the world, syncs the physics body, and notifies collisions. This allows for the physics engine to accurately simulate the physics bodies in the world.

    Returns void

  • Gets the angular damping of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to get the angular damping from.

    • OptionalinstanceIndex: number

      The index of the instance to get the angular damping from. If not specified, the angular damping of the first instance will be returned.

    Returns number

    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.

  • Gets the angular velocity of a body.

    Parameters

    • body: PhysicsBody

      The body to get the angular velocity from.

    • angVel: Vector3

      The vector3 to store the angular velocity.

    • OptionalinstanceIndex: number

      The index of the instance to get the angular velocity from. If not specified, the angular velocity of the first instance will be returned.

      This method is useful for getting the angular velocity of a body in a physics engine. It takes the body and a vector3 as parameters and stores the angular velocity of the body in the vector3. This is useful for getting the angular velocity of a body in order to calculate the motion of the body in the physics engine.

    Returns void

  • Gets the geometry of a physics body.

    Parameters

    Returns {
        indices: number[] | Uint32Array<ArrayBufferLike>;
        positions: number[] | Float32Array<ArrayBufferLike>;
    }

    An object containing the positions and indices of the body's geometry.

  • Calculates the bounding box of a given physics shape.

    Parameters

    • _shape: PhysicsShape

      The physics shape to calculate the bounding box for.

    Returns BoundingBox

    The calculated bounding box.

    This method is useful for physics engines as it allows to calculate the boundaries of a given shape. Knowing the boundaries of a shape is important for collision detection and other physics calculations.

  • Retrieves the event mask of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to retrieve the event mask from.

    • OptionalinstanceIndex: number

      The index of the instance to retrieve the event mask from.

    Returns number

    The event mask of the physics body.

  • Get the gravity factor of a body

    Parameters

    • body: PhysicsBody

      the physics body to get the gravity factor from

    • OptionalinstanceIndex: number

      the index of the instance in an instanced body. If not specified, the gravity factor of the first instance will be returned.

    Returns number

    the gravity factor

  • Gets the linear damping of the given body.

    Parameters

    • body: PhysicsBody

      The body to get the linear damping from.

    • OptionalinstanceIndex: number

      The index of the instance to get the linear damping from. If not specified, the linear damping of the first instance will be returned.

    Returns number

    The linear damping of the given body.

    This method is useful for getting 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. It is used to simulate the effects of air resistance and other forms of friction.

  • Gets the linear velocity of a physics body and stores it in a given vector.

    Parameters

    • body: PhysicsBody

      The physics body to get the linear velocity from.

    • linVel: Vector3

      The vector to store the linear velocity in.

    • OptionalinstanceIndex: number

      The index of the instance to get the linear velocity from. If not specified, the linear velocity of the first instance will be returned.

      This function 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 used to simulate realistic physics behavior in a game.

    Returns void

  • Returns the version of the physics engine plugin.

    Returns number

    The version of the physics engine plugin.

    This method is useful for determining the version of the physics engine plugin that is currently running.

  • Initializes a physics body with the given position and orientation.

    Parameters

    • body: PhysicsBody

      The physics body to initialize.

    • motionType: PhysicsMotionType

      The motion type of the body.

    • position: Vector3

      The position of the body.

    • orientation: Quaternion

      The orientation of the body. This code is useful for initializing a physics body with the given position and orientation. It creates a plugin data for the body and adds it to the world. It then converts the position and orientation to a transform and sets the body's transform to the given values.

    Returns void

  • Initializes the body instances for a given physics body and mesh.

    Parameters

    • body: PhysicsBody

      The physics body to initialize.

    • motionType: PhysicsMotionType

      How the body will be handled by the engine

    • mesh: Mesh

      The mesh to initialize.

      This code is useful for creating a physics body from a mesh. It creates a body instance for each instance of the mesh and adds it to the world. It also sets the position of the body instance to the position of the mesh instance. This allows for the physics engine to accurately simulate the mesh in the world.

    Returns void

  • Initializes a physics constraint with the given parameters.

    Parameters

    • constraint: PhysicsConstraint

      The physics constraint to be initialized.

    • body: PhysicsBody

      The main body

    • childBody: PhysicsBody

      The child body.

    • OptionalinstanceIndex: number

      If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.

    • OptionalchildInstanceIndex: number

      If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.

      This function is useful for setting up a physics constraint in a physics engine.

    Returns void

  • Initializes a physics shape with the given type and parameters.

    Parameters

    • shape: PhysicsShape

      The physics shape to initialize.

    • type: PhysicsShapeType

      The type of shape to initialize.

    • options: PhysicsShapeParameters

      The parameters for the shape.

      This code is useful for initializing a physics shape with the given type and parameters. It allows for the creation of a sphere, box, capsule, container, cylinder, mesh, and heightfield. Depending on the type of shape, different parameters are required. For example, a sphere requires a radius, while a box requires extents and a rotation.

    Returns void

  • Performs a raycast from a given start point to a given end point and stores the result in a given PhysicsRaycastResult object.

    Parameters

    • from: Vector3

      The start point of the raycast.

    • to: Vector3

      The end point of the raycast.

    • result: PhysicsRaycastResult | PhysicsRaycastResult[]

      The PhysicsRaycastResult object (or array of PhysicsRaycastResults) to store the result of the raycast.

    • Optionalquery: IRaycastQuery

      The raycast query options. See [[IRaycastQuery]] for more information.

      Performs a raycast. It takes in two points, from and to, and a PhysicsRaycastResult object to store the result of the raycast. It then performs the raycast and stores the hit data in the PhysicsRaycastResult object. If result is an empty array, it will be populated with every detected raycast hit. If result is a populated array, it will only fill the PhysicsRaycastResults present in the array.

    Returns void

  • Sets the angular damping of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the angular damping for.

    • damping: number

      The angular damping value to set.

    • OptionalinstanceIndex: number

      The index of the instance to set the angular damping for. If not specified, the angular damping of the first instance will be 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.

    Returns void

  • Sets the angular velocity of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the angular velocity of.

    • angVel: Vector3

      The angular velocity to set.

    • OptionalinstanceIndex: number

      The index of the instance to set the angular velocity of. If not specified, the angular velocity of the first instance will be set.

      This function is useful for setting the angular velocity of a physics body in a physics engine. This allows for more realistic simulations of physical objects, as they can be given a rotational velocity.

    Returns void

  • Enable collision to be reported for a body when a callback is setup on the world

    Parameters

    • body: PhysicsBody

      the physics body

    • enabled: boolean

      whether to enable or disable collision events

    Returns void

  • Enable collision ended to be reported for a body when a callback is setup on the world

    Parameters

    • body: PhysicsBody

      the physics body

    • enabled: boolean

      whether to enable or disable collision ended events

    Returns void

  • Sets the event mask of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the event mask for.

    • eventMask: number

      The event mask to set.

    • OptionalinstanceIndex: number

      The index of the instance to set the event mask for

      This function is useful for setting the event mask of a physics body, which is used to determine which events the body will respond to. This is important for ensuring that the physics engine is able to accurately simulate the behavior of the body in the game world.

    Returns void

  • Sets the gravity of the physics world.

    Parameters

    • gravity: Vector3

      The gravity vector to set.

    • OptionalworldPosition: Vector3

      Optional world position to specify which region's gravity to set. If provided, only the region containing this position will be updated. If not provided, all regions will be updated (default behavior). This is useful for planetary scenarios where gravity direction varies by location.

    Returns void

  • Sets the gravity factor of a body

    Parameters

    • body: PhysicsBody

      the physics body to set the gravity factor for

    • factor: number

      the gravity factor

    • OptionalinstanceIndex: number

      the index of the instance in an instanced body

    Returns void

  • Sets the linear damping of the given body.

    Parameters

    • body: PhysicsBody

      The body to set the linear damping for.

    • damping: number

      The linear damping to set.

    • OptionalinstanceIndex: number

      The index of the instance to set the linear damping for. If not specified, the linear damping of the first instance will be 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.

    Returns void

  • Sets the linear velocity of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the linear velocity of.

    • linVel: Vector3

      The linear velocity to set.

    • OptionalinstanceIndex: number

      The index of the instance to set the linear velocity of. If not specified, the linear velocity of the first instance will be set.

      This function is useful for setting the linear velocity of a physics body, which is necessary for simulating motion in a physics engine. The linear velocity is the speed and direction of the body's movement.

    Returns void

  • Sets the mass properties of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the mass properties of.

    • massProps: PhysicsMassProperties

      The mass properties to set.

    • OptionalinstanceIndex: number

      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.

    Returns void

  • Sets the transformation of the given physics body to the given transform node.

    Parameters

    • body: PhysicsBody

      The physics body to set the transformation for.

    • node: TransformNode

      The transform node to set the transformation from. Sets the transformation of the given physics body to the given transform node.

      This function is useful for setting the transformation of a physics body to a transform node, which is necessary for the physics engine to accurately simulate the motion of the body. It also takes into account instances of the transform node, which is necessary for accurate simulation of multiple bodies with the same transformation.

    Returns void

  • Sets the shape of a physics body.

    Parameters

    • body: PhysicsBody

      The physics body to set the shape for.

    • shape: Nullable<PhysicsShape>

      The physics shape to set.

      This function is used to set the shape of a physics body. It is useful for creating a physics body with a specific shape, such as a box or a sphere, which can then be used to simulate physical interactions in a physics engine. This function is especially useful for meshes with multiple instances, as it will set the shape for each instance of the mesh.

    Returns void

  • Sets the shape filter membership mask of a body

    Parameters

    • shape: PhysicsShape

      The physics body to set the shape filter membership mask for.

    • membershipMask: number

      The shape filter membership mask to set.

    Returns void

  • Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target

    Parameters

    • body: PhysicsBody

      The physics body to set the target transformation for.

    • position: Vector3

      The target position

    • rotation: Quaternion

      The target rotation

    • OptionalinstanceIndex: number

      The index of the instance in an instanced body

    Returns void

  • Sets the fixed time step for the physics engine.

    Parameters

    • timeStep: number

      The fixed time step to use for the physics engine.

    Returns void

  • Set the maximum allowed linear and angular velocities

    Parameters

    • maxLinearVelocity: number

      maximum allowed linear velocity

    • maxAngularVelocity: number

      maximum allowed angular velocity

    Returns void

  • Given a shape in a specific orientation, cast it from the start to end position specified by the query, and return the first hit.

    Parameters

    • query: IPhysicsShapeCastQuery

      the query to perform.

    • inputShapeResult: ShapeCastResult

      contact point on input shape, in input shape space

    • hitShapeResult: ShapeCastResult

      contact point on hit shape, in world space

    Returns void

    IPhysicsShapeCastQuery

  • Synchronizes the transform of a physics body with its transform node.

    Parameters

    • body: PhysicsBody

      The physics body to synchronize.

      This function is useful for keeping the physics body's transform in sync with its transform node. This is important for ensuring that the physics body is accurately represented in the physics engine.

    Returns void

  • Synchronizes the transform of a physics body with the transform of its corresponding transform node.

    Parameters

    • body: PhysicsBody

      The physics body to synchronize.

    • transformNode: TransformNode

      The destination Transform Node.

      This code is useful for synchronizing the position and orientation of a physics body with the position and orientation of its corresponding transform node. This is important for ensuring that the physics body and the transform node are in the same position and orientation in the scene. This is necessary for the physics engine to accurately simulate the physical behavior of the body.

    Returns void