Skip to content

eulerjs API / @eulerjs/core / PhysicsBackend

PhysicsBackend ​

Defined in: packages/core/src/backend.ts:59

What actually simulates a world. The world, its bodies and joints are the same whatever the backend; the backend keeps its own copy of each body and the world keeps the two in step:

  1. before a step, it writes the poses and velocities you changed, wake and sleep requests, and the forces gathered during the step;
  2. step simulates;
  3. it reads every body's motion and sleep state back.

Backends read a body's settings (type, damping, gravity scale, canSleep, collider materials) and a joint's settings from the objects themselves, so changes to those take effect on the next step. Bodies a joint ties together don't collide with each other while it is in the world if its collideConnected is false. updateBody is called when its mass properties or colliders change.

Properties ​

PropertyModifierTypeDescriptionDefined in
contactsreadonlyreadonly Contact[]The contacts that pushed during the last step, one for each touching point.packages/core/src/backend.ts:89
namereadonlystring-packages/core/src/backend.ts:60
sensorOverlapsreadonlyreadonly SensorOverlap[]Each pair of colliders, one or both a sensor, that overlapped during the last step, among bodies at least one of which was awake.packages/core/src/backend.ts:91

Methods ​

addBody() ​

ts
addBody(body): void;

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

Parameters ​

ParameterType
bodyBody

Returns ​

void


addJoint() ​

ts
addJoint(joint): void;

Defined in: packages/core/src/backend.ts:66

Throws an EulerError for a kind of joint the backend can't simulate.

Parameters ​

ParameterType
jointJoint

Returns ​

void


applyLoads() ​

ts
applyLoads(
   body, 
   force, 
   torque
): void;

Defined in: packages/core/src/backend.ts:83

Adds a force through the centre of mass and a torque about it, both in world space, to the next step only.

Parameters ​

ParameterType
bodyBody
forceVector3
torqueVector3

Returns ​

void


castRay() ​

ts
castRay(
   origin, 
   direction, 
   maxDistance, 
   filter, 
   all
): QueryHit[];

Defined in: packages/core/src/backend.ts:97

Every collider a ray from origin along the unit direction meets within maxDistance, with where it first meets it, nearest first; only the nearest unless all. Uses the bodies as the backend last had them: the world writes poses you changed before asking.

Parameters ​

ParameterType
originVector3
directionVector3
maxDistancenumber
filterQueryFilter
allboolean

Returns ​

QueryHit[]


castShape() ​

ts
castShape(
   shape, 
   position, 
   quaternion, 
   direction, 
   maxDistance, 
   filter
): QueryHit | undefined;

Defined in: packages/core/src/backend.ts:99

Where shape, at position turned by quaternion and swept along the unit direction, first touches a collider within maxDistance.

Parameters ​

ParameterType
shapeCollider
positionVector3
quaternionQuaternion
directionVector3
maxDistancenumber
filterQueryFilter

Returns ​

QueryHit | undefined


dispose()? ​

ts
optional dispose(): void;

Defined in: packages/core/src/backend.ts:103

Frees whatever the backend holds; called by world.dispose().

Returns ​

void


isSleeping() ​

ts
isSleeping(body): boolean;

Defined in: packages/core/src/backend.ts:87

Parameters ​

ParameterType
bodyBody

Returns ​

boolean


overlap() ​

ts
overlap(
   shape, 
   position, 
   quaternion, 
   filter
): OverlapHit[];

Defined in: packages/core/src/backend.ts:101

Every collider that shape, at position turned by quaternion, overlaps or touches.

Parameters ​

ParameterType
shapeCollider
positionVector3
quaternionQuaternion
filterQueryFilter

Returns ​

OverlapHit[]


readMotion() ​

ts
readMotion(body, target): void;

Defined in: packages/core/src/backend.ts:86

Writes the backend's pose and velocities for the body into target.

Parameters ​

ParameterType
bodyBody
targetBodyMotion

Returns ​

void


removeBody() ​

ts
removeBody(body): void;

Defined in: packages/core/src/backend.ts:62

Parameters ​

ParameterType
bodyBody

Returns ​

void


removeJoint() ​

ts
removeJoint(joint): void;

Defined in: packages/core/src/backend.ts:67

Parameters ​

ParameterType
jointJoint

Returns ​

void


setCollisionsBetween() ​

ts
setCollisionsBetween(
   bodyA, 
   bodyB, 
   enabled
): void;

Defined in: packages/core/src/backend.ts:73

Stops two bodies colliding with each other, or lets them again. The world calls it at most once each way per pair, and with enabled true for every pair it disabled before either body is removed. Joints with collideConnected false keep their bodies apart on their own.

Parameters ​

ParameterType
bodyABody
bodyBBody
enabledboolean

Returns ​

void


sleep() ​

ts
sleep(body): void;

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

Puts the body to sleep now, stopping it.

Parameters ​

ParameterType
bodyBody

Returns ​

void


step() ​

ts
step(settings): void;

Defined in: packages/core/src/backend.ts:84

Parameters ​

ParameterType
settingsStepSettings

Returns ​

void


updateBody() ​

ts
updateBody(body): void;

Defined in: packages/core/src/backend.ts:64

The body's mass properties or list of colliders changed.

Parameters ​

ParameterType
bodyBody

Returns ​

void


wakeUp() ​

ts
wakeUp(body): void;

Defined in: packages/core/src/backend.ts:79

Wakes the body and restarts its sleep timer, even if it is already awake.

Parameters ​

ParameterType
bodyBody

Returns ​

void


writePose() ​

ts
writePose(body): void;

Defined in: packages/core/src/backend.ts:75

Moves the backend's copy of the body to the body's position and quaternion.

Parameters ​

ParameterType
bodyBody

Returns ​

void


writeVelocity() ​

ts
writeVelocity(body): void;

Defined in: packages/core/src/backend.ts:77

Sets the backend's copy of the body's velocity and angular velocity to the body's.

Parameters ​

ParameterType
bodyBody

Returns ​

void

Released under the MIT License.