Skip to content

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 ​

ts
new Body(options?): Body;

Defined in: packages/core/src/Body.ts:172

Parameters ​

ParameterType
options?BodyOptions

Returns ​

Body

Overrides ​

ts
RigidBodyState.constructor

Properties ​

PropertyModifierTypeDescriptionInherited fromDefined in
angularDampingpublicnumber--packages/core/src/Body.ts:139
angularVelocityreadonlyVector3Angular velocity in world space, in rad/s.RigidBodyState.angularVelocitypackages/core/src/RigidBodyState.ts:35
canSleeppublicbooleanWhether the body may fall asleep once it has been still for a while.-packages/core/src/Body.ts:142
collidersreadonlyreadonly Collider[]The shapes the body collides with. Change them with addCollider and removeCollider.-packages/core/src/Body.ts:149
gravityScalepublicnumber--packages/core/src/Body.ts:140
instancereadonlyBodyInstance | undefinedThe instance of an InstancedMesh that follows the body, if it is drawn as one.-packages/core/src/Body.ts:145
linearDampingpublicnumber--packages/core/src/Body.ts:138
objectreadonlyObject3D<Object3DEventMap> | undefined--packages/core/src/Body.ts:143
positionreadonlyVector3Origin of the body frame in world space.RigidBodyState.positionpackages/core/src/RigidBodyState.ts:32
previousPositionreadonlyVector3Pose at the start of the last step, used to interpolate rendering between steps.-packages/core/src/Body.ts:157
previousQuaternionreadonlyQuaternion--packages/core/src/Body.ts:158
quaternionreadonlyQuaternion-RigidBodyState.quaternionpackages/core/src/RigidBodyState.ts:33
typereadonlyBodyType-RigidBodyState.typepackages/core/src/RigidBodyState.ts:55
velocityreadonlyVector3Velocity of the centre of mass, in m/s.RigidBodyState.velocitypackages/core/src/RigidBodyState.ts:34
voxelsreadonlyVoxels | undefinedThe body's volume as cells, if it was made with them; buoyancy uses it.-packages/core/src/Body.ts:147
worldCenterOfMassreadonlyVector3Centre of mass in world space, kept in sync with the pose by the world.RigidBodyState.worldCenterOfMasspackages/core/src/RigidBodyState.ts:37
worldInverseInertiareadonlyMatrix3Inverse 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.worldInverseInertiapackages/core/src/RigidBodyState.ts:43

Accessors ​

behaviors ​

Get Signature ​

ts
get behaviors(): readonly Behavior[];

Defined in: packages/core/src/Body.ts:273

Returns ​

readonly Behavior[]


inverseMass ​

Get Signature ​

ts
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 ​

ts
RigidBodyState.inverseMass

isDynamic ​

Get Signature ​

ts
get isDynamic(): boolean;

Defined in: packages/core/src/RigidBodyState.ts:57

Returns ​

boolean

Inherited from ​

ts
RigidBodyState.isDynamic

isSleeping ​

Get Signature ​

ts
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 ​

ts
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 ​

ts
RigidBodyState.mass

massProperties ​

Get Signature ​

ts
get massProperties(): MassProperties | undefined;

Defined in: packages/core/src/RigidBodyState.ts:61

Returns ​

MassProperties | undefined

Inherited from ​

ts
RigidBodyState.massProperties

world ​

Get Signature ​

ts
get world(): World | undefined;

Defined in: packages/core/src/Body.ts:269

Returns ​

World | undefined

Methods ​

addBehavior() ​

ts
addBehavior<SomeBehavior>(behavior): SomeBehavior;

Defined in: packages/core/src/Body.ts:303

Type Parameters ​

Type Parameter
SomeBehavior extends Behavior

Parameters ​

ParameterType
behaviorSomeBehavior

Returns ​

SomeBehavior


addCollider() ​

ts
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 ​

ParameterType
colliderSomeCollider

Returns ​

SomeCollider


applyForce() ​

ts
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 ​

ParameterType
forceVector3
worldPoint?Vector3

Returns ​

void


applyForceAtLocalPoint() ​

ts
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 ​

ParameterType
forceVector3
localPointVector3

Returns ​

void


applyImpulse() ​

ts
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 ​

ParameterType
impulseVector3
worldPoint?Vector3

Returns ​

void


applyTorque() ​

ts
applyTorque(torque): void;

Defined in: packages/core/src/Body.ts:332

Parameters ​

ParameterType
torqueVector3

Returns ​

void


assignMassProperties() ​

ts
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 ​

ParameterType
massPropertiesMassProperties

Returns ​

void

Inherited from ​

ts
RigidBodyState.assignMassProperties

directionToWorld() ​

ts
directionToWorld(vector): Vector3;

Defined in: packages/core/src/RigidBodyState.ts:102

Rotates a direction from the body frame to world space in place.

Parameters ​

ParameterType
vectorVector3

Returns ​

Vector3

Inherited from ​

ts
RigidBodyState.directionToWorld

fromInstances() ​

ts
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 ​

ParameterType
meshInstancedMesh
options?InstancedBodyOptions

Returns ​

Body[]


fromObject() ​

ts
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 ​

ParameterType
objectObject3D
options?ObjectBodyOptions

Returns ​

Body


localToWorld() ​

ts
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 ​

ParameterType
vectorVector3

Returns ​

Vector3

Inherited from ​

ts
RigidBodyState.localToWorld

pointToWorld() ​

ts
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 ​

ParameterType
localPointVector3
target?Vector3

Returns ​

Vector3

Inherited from ​

ts
RigidBodyState.pointToWorld

pointVelocity() ​

ts
pointVelocity(worldPoint, target?): Vector3;

Defined in: packages/core/src/RigidBodyState.ts:81

Velocity of the material point of the body currently at worldPoint.

Parameters ​

ParameterType
worldPointVector3
target?Vector3

Returns ​

Vector3

Inherited from ​

ts
RigidBodyState.pointVelocity

removeBehavior() ​

ts
removeBehavior(behavior): void;

Defined in: packages/core/src/Body.ts:309

Parameters ​

ParameterType
behaviorBehavior

Returns ​

void


removeCollider() ​

ts
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 ​

ParameterType
colliderCollider

Returns ​

void


setMass() ​

ts
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 ​

ParameterType
massnumber

Returns ​

void


setMassProperties() ​

ts
setMassProperties(massProperties): void;

Defined in: packages/core/src/Body.ts:278

Replaces the mass properties, and wakes the body.

Parameters ​

ParameterType
massPropertiesMassProperties

Returns ​

void


setPose() ​

ts
setPose(position, quaternion): void;

Defined in: packages/core/src/Body.ts:293

Moves the body instantly, without interpolating from the old pose.

Parameters ​

ParameterType
positionVector3
quaternionQuaternion

Returns ​

void


sleep() ​

ts
sleep(): void;

Defined in: packages/core/src/Body.ts:261

Puts the body to sleep now, stopping it.

Returns ​

void


syncObject() ​

ts
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 ​

ParameterTypeDefault value
alpha?number1

Returns ​

void


wakeUp() ​

ts
wakeUp(): void;

Defined in: packages/core/src/Body.ts:255

Wakes the body and restarts its sleep timer.

Returns ​

void


worldToLocal() ​

ts
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 ​

ParameterType
vectorVector3

Returns ​

Vector3

Inherited from ​

ts
RigidBodyState.worldToLocal

Released under the MIT License.