API Docs for: 0.6.1
Show:

Body Class

Extends EventTarget

Base class for all body types.

Constructor

Body

(
  • [options]
)

Parameters:

  • [options] Object optional
    • [position] Vec3 optional
    • [velocity] Vec3 optional
    • [angularVelocity] Vec3 optional
    • [quaternion] Quaternion optional
    • [mass] Number optional
    • [material] Material optional
    • [type] Number optional
    • [linearDamping=0.01] Number optional
    • [angularDamping=0.01] Number optional
    • [allowSleep=true] Boolean optional
    • [sleepSpeedLimit=0.1] Number optional
    • [sleepTimeLimit=1] Number optional
    • [collisionFilterGroup=1] Number optional
    • [collisionFilterMask=1] Number optional
    • [fixedRotation=false] Boolean optional
    • [shape] Body optional

Example:

var body = new Body({
            mass: 1
        });
        var shape = new Sphere(1);
        body.addShape(shape);
        world.add(body);
        

Methods

addEventListener

(
  • type
  • listener
)
EventTarget

Add an event listener

Parameters:

  • type String
  • listener Function

Returns:

EventTarget:

The self object, for chainability.

addShape

(
  • shape
  • offset
  • quaternion
)
Body

Add a shape to the body with a local offset and orientation.

Parameters:

Returns:

Body:

The body object, for chainability.

applyForce

(
  • force
  • worldPoint
)

Apply force to a world point. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque.

Parameters:

  • force Vec3

    The amount of force to add.

  • worldPoint Vec3

    A world point to apply the force on.

applyImpulse

(
  • impulse
  • worldPoint
)

Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.

Parameters:

  • impulse Vec3

    The amount of impulse to add.

  • worldPoint Vec3

    A world point to apply the force on.

applyLocalForce

(
  • force
  • localPoint
)

Apply force to a local point in the body.

Parameters:

  • force Vec3

    The force vector to apply, defined locally in the body frame.

  • localPoint Vec3

    A local point in the body to apply the force on.

applyLocalImpulse

(
  • force
  • localPoint
)

Apply locally-defined impulse to a local point in the body.

Parameters:

  • force Vec3

    The force vector to apply, defined locally in the body frame.

  • localPoint Vec3

    A local point in the body to apply the force on.

computeAABB

()

Updates the .aabb

dispatchEvent

(
  • event
)
EventTarget

Emit an event.

Parameters:

  • event Object
    • type String

Returns:

EventTarget:

The self object, for chainability.

getVelocityAtWorldPoint

(
  • worldPoint
  • result
)
Vec3

Get world velocity of a point in the body.

Parameters:

Returns:

Vec3:

The result vector.

hasEventListener

(
  • type
  • listener
)
Boolean

Check if an event listener is added

Parameters:

  • type String
  • listener Function

Returns:

Boolean:

pointToLocalFrame

(
  • worldPoint
  • result
)
Vec3

Convert a world point to local body frame.

Parameters:

Returns:

Vec3:

pointToWorldFrame

(
  • localPoint
  • result
)
Vec3

Convert a local body point to world frame.

Parameters:

Returns:

Vec3:

removeEventListener

(
  • type
  • listener
)
EventTarget

Remove an event listener

Parameters:

  • type String
  • listener Function

Returns:

EventTarget:

The self object, for chainability.

sleep

()

Force body sleep

sleepTick

(
  • time
)

Called every timestep to update internal sleep timer and change sleep state if needed.

Parameters:

  • time Number

    The world time in seconds

updateBoundingRadius

()

Update the bounding radius of the body. Should be done if any of the shapes are changed.

updateInertiaWorld

()

Update .inertiaWorld and .invInertiaWorld

updateMassProperties

()

Should be called whenever you change the body shape or mass.

updateSolveMassProperties

()

If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate "solve mass".

vectorToLocalFrame

(
  • worldPoint
  • result
)
Vec3

Convert a world vector to local body frame.

Parameters:

Returns:

Vec3:

vectorToWorldFrame

(
  • localVector
  • result
)
Vec3

Convert a local body point to world frame.

Parameters:

Returns:

Vec3:

wakeUp

()

Wake the body up.

Properties

aabb

AABB

aabbNeedsUpdate

Boolean

Indicates if the AABB needs to be updated before use.

allowSleep

Boolean

If true, the body will automatically fall to sleep.

Default: true

angularDamping

Number

angularVelocity

Vec3

AWAKE

Number static

collisionFilterGroup

Number

collisionFilterMask

Number

collisionResponse

Number

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

DYNAMIC

Number static

A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.

fixedRotation

Boolean

Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.

Default: false

force

Vec3

Linear force on the body

inertia

Vec3

initAngularVelocity

Vec3

initPosition

Vec3

Initial position of the body

initQuaternion

Quaternion

initVelocity

Vec3

invInertia

Vec3

invInertiaSolve

Vec3

invInertiaWorld

Mat3

invInertiaWorldSolve

Mat3

invMass

Number

KINEMATIC

Number static

A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.

linearDamping

Number

mass

Number

Default: 0

material

Material

position

Vec3

postStep

Function deprecated

Defined in src/objects/Body.js:64

Deprecated: Use World events instead

Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.

preStep

Function deprecated

Defined in src/objects/Body.js:56

Deprecated: Use World events instead

Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, "this" will refer to this Body object.

previousPosition

Vec3

quaternion

Quaternion

Orientation of the body

shapeOffsets

Array

shapeOrientations

Array

shapes

Array

SLEEPING

Number static

sleepSpeedLimit

Number

If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.

Default: 0.1

sleepState

Number

Current sleep state.

sleepTimeLimit

Number

If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.

Default: 1

SLEEPY

Number static

STATIC

Number static

A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.

torque

Vec3

Rotational force on the body, around center of mass

type

Number

One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.

velocity

Vec3

world

World

Reference to the world the body is living in