Skip to content

eulerjs API / @eulerjs/core / JavaScriptBackend

JavaScriptBackend ​

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:35

The built-in backend, in plain JavaScript: semi-implicit Euler integration with an exact gyroscopic term, and joints and contacts solved over substeps substeps per step, by extended position-based dynamics (XPBD) or by soft step (see JavaScriptBackendOptions).

Implements ​

Constructors ​

Constructor ​

ts
new JavaScriptBackend(options?): JavaScriptBackend;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:66

Parameters ​

ParameterType
options?JavaScriptBackendOptions

Returns ​

JavaScriptBackend

Properties ​

PropertyModifierTypeDefault valueDefined in
namereadonly"javascript"'javascript'packages/core/src/javascript/JavaScriptBackend.ts:36

Accessors ​

contacts ​

Get Signature ​

ts
get contacts(): readonly Contact[];

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:70

The contacts that pushed during the last step, one for each touching point.

Returns ​

readonly Contact[]

The contacts that pushed during the last step, one for each touching point.

Implementation of ​

PhysicsBackend.contacts


sensorOverlaps ​

Get Signature ​

ts
get sensorOverlaps(): readonly SensorOverlap[];

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:74

Each pair of colliders, one or both a sensor, that overlapped during the last step, among bodies at least one of which was awake.

Returns ​

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.

Implementation of ​

PhysicsBackend.sensorOverlaps

Methods ​

addBody() ​

ts
addBody(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:78

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.addBody


addJoint() ​

ts
addJoint(joint): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:117

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

Parameters ​

ParameterType
jointJoint

Returns ​

void

Implementation of ​

PhysicsBackend.addJoint


applyLoads() ​

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

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:187

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

Implementation of ​

PhysicsBackend.applyLoads


castRay() ​

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

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:203

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[]

Implementation of ​

PhysicsBackend.castRay


castShape() ​

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

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:207

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

Implementation of ​

PhysicsBackend.castShape


dispose() ​

ts
dispose(): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:251

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

Returns ​

void

Implementation of ​

PhysicsBackend.dispose


isSleeping() ​

ts
isSleeping(body): boolean;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:215

Parameters ​

ParameterType
bodyBody

Returns ​

boolean

Implementation of ​

PhysicsBackend.isSleeping


overlap() ​

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

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:211

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

Parameters ​

ParameterType
shapeCollider
positionVector3
quaternionQuaternion
filterQueryFilter

Returns ​

OverlapHit[]

Implementation of ​

PhysicsBackend.overlap


readMotion() ​

ts
readMotion(body, target): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:195

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

Parameters ​

ParameterType
bodyBody
targetBodyMotion

Returns ​

void

Implementation of ​

PhysicsBackend.readMotion


removeBody() ​

ts
removeBody(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:98

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.removeBody


removeJoint() ​

ts
removeJoint(joint): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:135

Parameters ​

ParameterType
jointJoint

Returns ​

void

Implementation of ​

PhysicsBackend.removeJoint


setCollisionsBetween() ​

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

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:152

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

Implementation of ​

PhysicsBackend.setCollisionsBetween


sleep() ​

ts
sleep(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:182

Puts the body to sleep now, stopping it.

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.sleep


step() ​

ts
step(settings): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:219

Parameters ​

ParameterType
settingsStepSettings

Returns ​

void

Implementation of ​

PhysicsBackend.step


updateBody() ​

ts
updateBody(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:109

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

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.updateBody


wakeUp() ​

ts
wakeUp(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:178

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

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.wakeUp


writePose() ​

ts
writePose(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:164

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

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.writePose


writeVelocity() ​

ts
writeVelocity(body): void;

Defined in: packages/core/src/javascript/JavaScriptBackend.ts:174

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

Parameters ​

ParameterType
bodyBody

Returns ​

void

Implementation of ​

PhysicsBackend.writeVelocity

Released under the MIT License.