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:
- before a step, it writes the poses and velocities you changed, wake and sleep requests, and the forces gathered during the step;
stepsimulates;- 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
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
contacts | readonly | readonly Contact[] | The contacts that pushed during the last step, one for each touching point. | packages/core/src/backend.ts:89 |
name | readonly | string | - | packages/core/src/backend.ts:60 |
sensorOverlaps | readonly | readonly 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()
addBody(body): void;Defined in: packages/core/src/backend.ts:61
Parameters
| Parameter | Type |
|---|---|
body | Body |
Returns
void
addJoint()
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
| Parameter | Type |
|---|---|
joint | Joint |
Returns
void
applyLoads()
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
| Parameter | Type |
|---|---|
body | Body |
force | Vector3 |
torque | Vector3 |
Returns
void
castRay()
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
| Parameter | Type |
|---|---|
origin | Vector3 |
direction | Vector3 |
maxDistance | number |
filter | QueryFilter |
all | boolean |
Returns
QueryHit[]
castShape()
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
| Parameter | Type |
|---|---|
shape | Collider |
position | Vector3 |
quaternion | Quaternion |
direction | Vector3 |
maxDistance | number |
filter | QueryFilter |
Returns
QueryHit | undefined
dispose()?
optional dispose(): void;Defined in: packages/core/src/backend.ts:103
Frees whatever the backend holds; called by world.dispose().
Returns
void
isSleeping()
isSleeping(body): boolean;Defined in: packages/core/src/backend.ts:87
Parameters
| Parameter | Type |
|---|---|
body | Body |
Returns
boolean
overlap()
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
| Parameter | Type |
|---|---|
shape | Collider |
position | Vector3 |
quaternion | Quaternion |
filter | QueryFilter |
Returns
readMotion()
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
| Parameter | Type |
|---|---|
body | Body |
target | BodyMotion |
Returns
void
removeBody()
removeBody(body): void;Defined in: packages/core/src/backend.ts:62
Parameters
| Parameter | Type |
|---|---|
body | Body |
Returns
void
removeJoint()
removeJoint(joint): void;Defined in: packages/core/src/backend.ts:67
Parameters
| Parameter | Type |
|---|---|
joint | Joint |
Returns
void
setCollisionsBetween()
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
| Parameter | Type |
|---|---|
bodyA | Body |
bodyB | Body |
enabled | boolean |
Returns
void
sleep()
sleep(body): void;Defined in: packages/core/src/backend.ts:81
Puts the body to sleep now, stopping it.
Parameters
| Parameter | Type |
|---|---|
body | Body |
Returns
void
step()
step(settings): void;Defined in: packages/core/src/backend.ts:84
Parameters
| Parameter | Type |
|---|---|
settings | StepSettings |
Returns
void
updateBody()
updateBody(body): void;Defined in: packages/core/src/backend.ts:64
The body's mass properties or list of colliders changed.
Parameters
| Parameter | Type |
|---|---|
body | Body |
Returns
void
wakeUp()
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
| Parameter | Type |
|---|---|
body | Body |
Returns
void
writePose()
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
| Parameter | Type |
|---|---|
body | Body |
Returns
void
writeVelocity()
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
| Parameter | Type |
|---|---|
body | Body |
Returns
void
