Skip to content

eulerjs API / @eulerjs/scene / ScenePhysics

ScenePhysics ​

Defined in: packages/scene/src/ScenePhysics.ts:54

Makes the bodies for a three.js scene from what its objects say about themselves, in userData.physics (see PhysicsData). Use it with world.use(new ScenePhysics()).

Each object with userData.physics becomes one body, whatever else it holds: a mesh, or a group of them (a glTF node of several primitives, say), together with the meshes under it that don't have physics of their own. It starts where it is drawn, nested in moved groups or not, and moves its object as it goes. An InstancedMesh becomes a body for each instance.

What it collides as: three.js's box, sphere, cylinder, cone and capsule geometries as those shapes, while they are still the shape three.js made them; anything else as its convex hull if it moves, or as its very triangles if it doesn't. A moving body's mass properties come from its meshes when they are closed, else from its collider.

Implements ​

Constructors ​

Constructor ​

ts
new ScenePhysics(): ScenePhysics;

Returns ​

ScenePhysics

Properties ​

PropertyModifierTypeDefault valueDefined in
namereadonly"scene"'scene'packages/scene/src/ScenePhysics.ts:55

Methods ​

addObject() ​

ts
addObject(object, physics?): 
  | Body
  | Body[];

Defined in: packages/scene/src/ScenePhysics.ts:86

Makes the body for one object, as physics says (its userData.physics unless given), and notes it there as body: for an InstancedMesh, the list of its instances' bodies.

Parameters ​

ParameterType
objectObject3D
physics?PhysicsData

Returns ​

| Body | Body[]


addScene() ​

ts
addScene(root): Body[];

Defined in: packages/scene/src/ScenePhysics.ts:70

Makes a body for every object in root (and root itself) whose userData.physics is set, in the tree's order, skipping any that already has one. Returns the bodies made.

Parameters ​

ParameterType
rootObject3D

Returns ​

Body[]


dispose() ​

ts
dispose(): void;

Defined in: packages/scene/src/ScenePhysics.ts:62

Called by world.removePlugin(plugin) and world.dispose().

Returns ​

void

Implementation of ​

Plugin.dispose


install() ​

ts
install(world): void;

Defined in: packages/scene/src/ScenePhysics.ts:58

Called once by world.use(plugin).

Parameters ​

ParameterType
worldWorld

Returns ​

void

Implementation of ​

Plugin.install


removeObject() ​

ts
removeObject(object): void;

Defined in: packages/scene/src/ScenePhysics.ts:114

Takes an object's body, or its instances' bodies, out of the world, and forgets them in its userData.physics.

Parameters ​

ParameterType
objectObject3D

Returns ​

void

Released under the MIT License.