
Hi all! I’ve been building eulerjs, a rigid-body physics engine made for three.js, in plain TypeScript.
Try it in the browser: live examples: a wedding venue full of chairs, glasses and balloons to knock about and carry, a city with a drivable car and walking ragdolls, a formula car at Monza (with online races), a sailboat on an FFT ocean, and short demos.
Why another engine?
cannon-es is wonderfully easy to use with three.js, but anything that rests, stacks, slides or gets picked up shows its age. Friction ignores the load (each contact point gets the whole body’s weight’s worth), so things stick: when I ported the wedding demo to cannon-es to compare, chairs wouldn’t budge under 200 N where 27 N should slide them, glasses stopped dead, and stacks crept apart. The WebAssembly engines (Rapier, Jolt, Bullet) are fast and accurate, but they bring their own vectors and setup and a binary to load.
eulerjs aims for both: three.js-first and easy, and physics that holds up.
| Accuracy | eulerjs | cannon-es |
|---|---|---|
| 8-box stack kept awake, furthest the top moves in 60 s | 2.5 mm | 9.5 m (falls) |
| Box sliding down a slope, acceleration error | 0.0% | −100% (stuck) |
| Ball bounced from 3 m, height error | −1.8% | +21.6% |
| A rock hull’s moment of inertia (9.14 is right) | 9.14 | 66.7 |
Three lines to a falling crate
const world = new World();
world.addBody(crateMesh, { density: 500, collider: 'box' }); // mass, centre of mass, inertia from the mesh
renderer.setAnimationLoop(() => { world.update(timer.getDelta()); renderer.render(scene, camera); });
npm install @eulerjs/core three
- Built around three.js: give it a mesh, a group or an
InstancedMeshand it works out the body (exact mass, centre of mass and inertia from the triangles, and a fitted collider), then moves your meshes for you, interpolated between fixed steps. Hundreds of instanced props cost one draw call. - The usual toolbox: spheres, boxes, capsules, cylinders, cones, convex hulls, heightfields and triangle meshes; ray and shape casts, overlaps, contact and sensor events; hinge, slider, fixed, cone-twist, 6-DOF and distance joints with limits, motors, drives for active ragdolls and breaking; ray-cast vehicles; buoyancy, sails, keels and rudders.
- Things come to rest naturally: round shapes have rolling resistance, and what’s at rest sleeps, so a settled scene costs next to nothing.
Speed
The same scenes in all three engines (same masses, friction and sleep settings, each with its own solver defaults), in ms of computing per simulated second, lower is better:
| Scene | eulerjs | cannon-es | Rapier (plain WASM) |
|---|---|---|---|
| Pyramid of 1,015 boxes | 3979 | 12594 | 1554 |
| Pile of 400 boxes, balls, cylinders, rocks | 647 | 8269 | 145 |
| 4 m box smashed through 5,000 boxes | 8447 | 16375 | 2318 |
| 5,000 rays a step through 2,000 shapes | 1862 | 29285 | 770 |
| 64 rocks (42-corner hulls) | 69 | 6079 | 26 |
Faster than cannon-es everywhere (1.3× to 88×); still slower than Rapier’s WebAssembly (1.3× to 4.5×), which is the gap I’m closing. The full table and method are in the performance guide, and npm run bench reproduces it.
Next
Continuous collision for fast thin objects, a character controller, and physics straight from a loaded glTF scene are on the TODO.
MIT-licensed, on GitHub:
Feedback very welcome: what breaks, what’s missing, and what you’d want from a three.js-first physics engine. Thanks for reading!