Body Class
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);
Item Index
Methods
- addEventListener
- addShape
- applyForce
- applyImpulse
- applyLocalForce
- applyLocalImpulse
- computeAABB
- dispatchEvent
- getVelocityAtWorldPoint
- hasEventListener
- pointToLocalFrame
- pointToWorldFrame
- removeEventListener
- sleep
- sleepTick
- updateBoundingRadius
- updateInertiaWorld
- updateMassProperties
- updateSolveMassProperties
- vectorToLocalFrame
- vectorToWorldFrame
- wakeUp
Properties
- aabb
- aabbNeedsUpdate
- allowSleep
- angularDamping
- angularVelocity
- AWAKE static
- collisionFilterGroup
- collisionFilterMask
- collisionResponse
- DYNAMIC static
- fixedRotation
- force
- inertia
- initAngularVelocity
- initPosition
- initQuaternion
- initVelocity
- invInertia
- invInertiaSolve
- invInertiaWorld
- invInertiaWorldSolve
- invMass
- KINEMATIC static
- linearDamping
- mass
- material
- position
- postStep deprecated
- preStep deprecated
- previousPosition
- quaternion
- shapeOffsets
- shapeOrientations
- shapes
- SLEEPING static
- sleepSpeedLimit
- sleepState
- sleepTimeLimit
- SLEEPY static
- STATIC static
- torque
- type
- velocity
- world
Methods
addEventListener
-
type
-
listener
Add an event listener
Parameters:
-
type
String -
listener
Function
Returns:
The self object, for chainability.
addShape
-
shape
-
offset
-
quaternion
Add a shape to the body with a local offset and orientation.
Parameters:
-
shape
Shape -
offset
Vec3 -
quaternion
Quaternion
Returns:
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.
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.
applyLocalForce
-
force
-
localPoint
Apply force to a local point in the body.
applyLocalImpulse
-
force
-
localPoint
Apply locally-defined impulse to a local point in the body.
computeAABB
()
Updates the .aabb
dispatchEvent
-
event
Emit an event.
Parameters:
-
event
Object-
type
String
-
Returns:
The self object, for chainability.
getVelocityAtWorldPoint
-
worldPoint
-
result
Get world velocity of a point in the body.
Returns:
The result vector.
hasEventListener
-
type
-
listener
Check if an event listener is added
Parameters:
-
type
String -
listener
Function
Returns:
pointToLocalFrame
-
worldPoint
-
result
Convert a world point to local body frame.
Returns:
pointToWorldFrame
-
localPoint
-
result
Convert a local body point to world frame.
Returns:
removeEventListener
-
type
-
listener
Remove an event listener
Parameters:
-
type
String -
listener
Function
Returns:
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
NumberThe 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
Convert a world vector to local body frame.
Returns:
vectorToWorldFrame
-
localVector
-
result
Convert a local body point to world frame.
Returns:
wakeUp
()
Wake the body up.
Properties
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
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
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
postStep
Function
deprecated
Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.
preStep
Function
deprecated
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.
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.
type
Number
One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.