eulerjs API / @eulerjs/core / Body
Body
Defined in: packages/core/src/Body.ts:137
A rigid body. The body frame is the frame its mass properties are expressed in, normally the local frame of the mesh it was built from. Dynamics happen about the centre of mass; position is the frame's origin, so a bound object's origin lands exactly on it.
Its pose and velocities are yours to read and change, like an Object3D's. Changes take effect when the world next steps; the world writes the backend's results back after every step.
Extends
RigidBodyState
Constructors
Constructor
new Body(options?): Body;Defined in: packages/core/src/Body.ts:172
Parameters
| Parameter | Type |
|---|---|
options? | BodyOptions |
Returns
Body
Overrides
RigidBodyState.constructorProperties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
angularDamping | public | number | - | - | packages/core/src/Body.ts:139 |
angularVelocity | readonly | Vector3 | Angular velocity in world space, in rad/s. | RigidBodyState.angularVelocity | packages/core/src/RigidBodyState.ts:35 |
canSleep | public | boolean | Whether the body may fall asleep once it has been still for a while. | - | packages/core/src/Body.ts:142 |
colliders | readonly | readonly Collider[] | The shapes the body collides with. Change them with addCollider and removeCollider. | - | packages/core/src/Body.ts:149 |
gravityScale | public | number | - | - | packages/core/src/Body.ts:140 |
instance | readonly | BodyInstance | undefined | The instance of an InstancedMesh that follows the body, if it is drawn as one. | - | packages/core/src/Body.ts:145 |
linearDamping | public | number | - | - | packages/core/src/Body.ts:138 |
object | readonly | Object3D<Object3DEventMap> | undefined | - | - | packages/core/src/Body.ts:143 |
position | readonly | Vector3 | Origin of the body frame in world space. | RigidBodyState.position | packages/core/src/RigidBodyState.ts:32 |
previousPosition | readonly | Vector3 | Pose at the start of the last step, used to interpolate rendering between steps. | - | packages/core/src/Body.ts:157 |
previousQuaternion | readonly | Quaternion | - | - | packages/core/src/Body.ts:158 |
quaternion | readonly | Quaternion | - | RigidBodyState.quaternion | packages/core/src/RigidBodyState.ts:33 |
type | readonly | BodyType | - | RigidBodyState.type | packages/core/src/RigidBodyState.ts:55 |
velocity | readonly | Vector3 | Velocity of the centre of mass, in m/s. | RigidBodyState.velocity | packages/core/src/RigidBodyState.ts:34 |
voxels | readonly | Voxels | undefined | The body's volume as cells, if it was made with them; buoyancy uses it. | - | packages/core/src/Body.ts:147 |
worldCenterOfMass | readonly | Vector3 | Centre of mass in world space, kept in sync with the pose by the world. | RigidBodyState.worldCenterOfMass | packages/core/src/RigidBodyState.ts:37 |
worldInverseInertia | readonly | Matrix3 | Inverse inertia tensor in world space, kept in sync with the pose by the world: how fast an angular impulse turns the body, for working out how hard it is to push at a point. Read it; don't change it. | RigidBodyState.worldInverseInertia | packages/core/src/RigidBodyState.ts:43 |
Accessors
behaviors
Get Signature
get behaviors(): readonly Behavior[];Defined in: packages/core/src/Body.ts:273
Returns
readonly Behavior[]
inverseMass
Get Signature
get inverseMass(): number;Defined in: packages/core/src/RigidBodyState.ts:71
1 / mass, or 0 for bodies that forces can't move.
Returns
number
Inherited from
RigidBodyState.inverseMassisDynamic
Get Signature
get isDynamic(): boolean;Defined in: packages/core/src/RigidBodyState.ts:57
Returns
boolean
Inherited from
RigidBodyState.isDynamicisSleeping
Get Signature
get isSleeping(): boolean;Defined in: packages/core/src/Body.ts:250
A sleeping body is not simulated until something disturbs it: an awake body running into it, a force, torque or impulse, a new pose or velocity, or wakeUp().
Returns
boolean
mass
Get Signature
get mass(): number;Defined in: packages/core/src/RigidBodyState.ts:66
Total mass in kg, or Infinity for bodies that forces can't move.
Returns
number
Inherited from
RigidBodyState.massmassProperties
Get Signature
get massProperties(): MassProperties | undefined;Defined in: packages/core/src/RigidBodyState.ts:61
Returns
MassProperties | undefined
Inherited from
RigidBodyState.massPropertiesworld
Get Signature
get world(): World | undefined;Defined in: packages/core/src/Body.ts:269
Returns
World | undefined
Methods
addBehavior()
addBehavior<SomeBehavior>(behavior): SomeBehavior;Defined in: packages/core/src/Body.ts:303
Type Parameters
| Type Parameter |
|---|
SomeBehavior extends Behavior |
Parameters
| Parameter | Type |
|---|---|
behavior | SomeBehavior |
Returns
SomeBehavior
addCollider()
addCollider<SomeCollider>(collider): SomeCollider;Defined in: packages/core/src/Body.ts:231
Adds a shape to collide with, and wakes the body, since what holds it up may have changed.
Type Parameters
| Type Parameter |
|---|
SomeCollider extends Collider |
Parameters
| Parameter | Type |
|---|---|
collider | SomeCollider |
Returns
SomeCollider
applyForce()
applyForce(force, worldPoint?): void;Defined in: packages/core/src/Body.ts:317
Pushes the body for this step. Applied at worldPoint, the force also creates a torque.
Parameters
| Parameter | Type |
|---|---|
force | Vector3 |
worldPoint? | Vector3 |
Returns
void
applyForceAtLocalPoint()
applyForceAtLocalPoint(force, localPoint): void;Defined in: packages/core/src/Body.ts:328
Like applyForce, with the point given in the body's own frame.
Parameters
| Parameter | Type |
|---|---|
force | Vector3 |
localPoint | Vector3 |
Returns
void
applyImpulse()
applyImpulse(impulse, worldPoint?): void;Defined in: packages/core/src/Body.ts:339
Changes the velocity at once, as if impulse (N·s) were delivered at worldPoint.
Parameters
| Parameter | Type |
|---|---|
impulse | Vector3 |
worldPoint? | Vector3 |
Returns
void
applyTorque()
applyTorque(torque): void;Defined in: packages/core/src/Body.ts:332
Parameters
| Parameter | Type |
|---|---|
torque | Vector3 |
Returns
void
assignMassProperties()
protected assignMassProperties(massProperties): void;Defined in: packages/core/src/RigidBodyState.ts:123
Sets the mass properties after checking a dynamic body can be moved by them. Doesn't refresh the derived state.
Parameters
| Parameter | Type |
|---|---|
massProperties | MassProperties |
Returns
void
Inherited from
RigidBodyState.assignMassPropertiesdirectionToWorld()
directionToWorld(vector): Vector3;Defined in: packages/core/src/RigidBodyState.ts:102
Rotates a direction from the body frame to world space in place.
Parameters
| Parameter | Type |
|---|---|
vector | Vector3 |
Returns
Vector3
Inherited from
RigidBodyState.directionToWorldfromInstances()
static fromInstances(mesh, options?): Body[];Defined in: packages/core/src/Body.ts:401
Bodies for every instance of mesh, posed as the instances are, colliding as collider says and weighed from the mesh's geometry (or their colliders). world.addInstances does this for you.
Parameters
| Parameter | Type |
|---|---|
mesh | InstancedMesh |
options? | InstancedBodyOptions |
Returns
Body[]
fromObject()
static fromObject(object, options?): Body;Defined in: packages/core/src/Body.ts:209
A body for a three.js object, with mass properties computed from its meshes and its starting pose read from it. world.addBody(object, options) does this for you.
Parameters
| Parameter | Type |
|---|---|
object | Object3D |
options? | ObjectBodyOptions |
Returns
Body
localToWorld()
localToWorld(vector): Vector3;Defined in: packages/core/src/RigidBodyState.ts:92
Transforms vector from the body frame to world space in place, like Object3D.localToWorld.
Parameters
| Parameter | Type |
|---|---|
vector | Vector3 |
Returns
Vector3
Inherited from
RigidBodyState.localToWorldpointToWorld()
pointToWorld(localPoint, target?): Vector3;Defined in: packages/core/src/RigidBodyState.ts:87
Where a point given in the body frame is in world space, written into target.
Parameters
| Parameter | Type |
|---|---|
localPoint | Vector3 |
target? | Vector3 |
Returns
Vector3
Inherited from
RigidBodyState.pointToWorldpointVelocity()
pointVelocity(worldPoint, target?): Vector3;Defined in: packages/core/src/RigidBodyState.ts:81
Velocity of the material point of the body currently at worldPoint.
Parameters
| Parameter | Type |
|---|---|
worldPoint | Vector3 |
target? | Vector3 |
Returns
Vector3
Inherited from
RigidBodyState.pointVelocityremoveBehavior()
removeBehavior(behavior): void;Defined in: packages/core/src/Body.ts:309
Parameters
| Parameter | Type |
|---|---|
behavior | Behavior |
Returns
void
removeCollider()
removeCollider(collider): void;Defined in: packages/core/src/Body.ts:239
Removes a shape, and wakes the body, since what holds it up may have changed.
Parameters
| Parameter | Type |
|---|---|
collider | Collider |
Returns
void
setMass()
setMass(mass): void;Defined in: packages/core/src/Body.ts:285
Changes the mass while keeping the shape, so the inertia scales with it.
Parameters
| Parameter | Type |
|---|---|
mass | number |
Returns
void
setMassProperties()
setMassProperties(massProperties): void;Defined in: packages/core/src/Body.ts:278
Replaces the mass properties, and wakes the body.
Parameters
| Parameter | Type |
|---|---|
massProperties | MassProperties |
Returns
void
setPose()
setPose(position, quaternion): void;Defined in: packages/core/src/Body.ts:293
Moves the body instantly, without interpolating from the old pose.
Parameters
| Parameter | Type |
|---|---|
position | Vector3 |
quaternion | Quaternion |
Returns
void
sleep()
sleep(): void;Defined in: packages/core/src/Body.ts:261
Puts the body to sleep now, stopping it.
Returns
void
syncObject()
syncObject(alpha?): void;Defined in: packages/core/src/Body.ts:358
Writes the pose, interpolated alpha of the way from the previous step, into the bound object or instance.
Parameters
| Parameter | Type | Default value |
|---|---|---|
alpha? | number | 1 |
Returns
void
wakeUp()
wakeUp(): void;Defined in: packages/core/src/Body.ts:255
Wakes the body and restarts its sleep timer.
Returns
void
worldToLocal()
worldToLocal(vector): Vector3;Defined in: packages/core/src/RigidBodyState.ts:97
Transforms vector from world space to the body frame in place, like Object3D.worldToLocal.
Parameters
| Parameter | Type |
|---|---|
vector | Vector3 |
Returns
Vector3
Inherited from
RigidBodyState.worldToLocal