Skip to content

eulerjsRigid-body physics for three.js

Bodies built from your meshes, joints with drives and limits, an accurate solver that sleeps what's at rest, and plugins for the sea, sails, cars and triangle meshes.

A spectral sea to the horizon, with crates afloat on it

Why eulerjs ​

Faster than cannon-es where real scenes spend their time, and right where cannon-es is wrong.

41×
faster than cannon-es on a settled pile of boxes: what's at rest sleeps, and stays asleep
88×
faster with convex hulls: 64 tumbling rocks of 42 corners each
2.5 mm
how far an eight-box stack's top moves in a minute awake; cannon-es's falls over
0.0%
error in a box's acceleration sliding down a slope; in cannon-es it doesn't slide at all

It gets the physics right. Stacks stand, boxes slide down slopes at the textbook acceleration, balls bounce to the height their restitution says, and a rock's inertia is integrated from its hull, not guessed from its bounding box. It's fast where it counts: real scenes are mostly at rest, and a city full of props costs a thirtieth of cannon-es's; with a crowd of ragdolls all awake and walking it is still the faster of the two. And it's three.js through and through: give it a mesh and it works out the body.

Against cannon-es ​

The same scenes in both engines, at 60 steps a second, with the same masses, friction and sleep thresholds; each keeps its own solver defaults. Milliseconds of computing per simulated second on a Ryzen 5 4600H, lower is better.

Sceneeulerjscannon-es
125 boxes settled5 ms204 mseulerjs 41× faster
64 rocks (42-corner hulls)59 ms6093 mseulerjs 103× faster
Mixed pile: 400 boxes, balls, cylinders and rocks447 ms8125 mseulerjs 18.2× faster
Pyramid of 1,015 boxes3156 ms10864 mseulerjs 3.4× faster
125 boxes falling into a pile94 ms216 mseulerjs 2.3× faster
400 spheres, never sleeping76 ms101 mseulerjs 1.3× faster
The city at rest4 ms120 mseulerjs 30× faster
The city, 25 ragdolls walking282 ms629 mseulerjs 2.2× faster
The city, 100 ragdolls walking1261 ms2670 mseulerjs 2.1× faster
Accuracyeulerjscannon-es
8-box stack kept awake, top's furthest move in 60 s2.5 mm9.5 m (falls)
Box sliding down a slope, acceleration error0.0%−100% (stuck)
Ball bounced from 3 m, height error−1.8%+21.6%
A rock's moment of inertia (9.14 is right)9.1466.7
A box resting on the ground, how far it sinks0.07 mm0.00 mm

Every number comes from npm run bench in the repository; the performance guide has all of them, and what cannon-es does better.

A world in a few lines ​

ts
import { BoxGeometry, Mesh, MeshStandardMaterial } from 'three';
import { World } from '@eulerjs/core';

const world = new World();

// the ground, and a crate dropped on it: mass from the meshes, and boxes fitted round them to collide as
const ground = new Mesh(new BoxGeometry(20, 1, 20), new MeshStandardMaterial());
ground.position.y = -0.5;
world.addBody(ground, { type: 'static', collider: 'box' });

const crate = new Mesh(new BoxGeometry(1, 1, 1), new MeshStandardMaterial({ color: 0xd08770 }));
crate.position.y = 4;
world.addBody(crate, { density: 500, collider: 'box' });

renderer.setAnimationLoop(() => {
  // fixed steps for the time gone, then the meshes moved to their bodies
  world.update(timer.getDelta());
  renderer.render(scene, camera);
});

Get started →

Released under the MIT License.