You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h3>2. Using 3rd-Party Physics JS/TS Libraries</h3>
94
+
95
+
<p>
96
+
Many physics engines are written directly in JavaScript or TypeScript and are designed to work
97
+
easily with the web ecosystem. Libraries like <b>cannon-es</b> are popular choices because they are
98
+
lightweight and easy to integrate specifically with three.js.
99
+
</p>
100
+
101
+
<p>
102
+
When using these libraries, you instantiate the physics world and bodies yourself, then manually
103
+
copy the position and quaternion from the physics body to the three.js mesh in your animation loop.
104
+
</p>
105
+
106
+
107
+
<h4>
108
+
Projects
109
+
</h4>
110
+
<ul>
111
+
<li><b><ahref="https://github.com/pmndrs/cannon-es" target="_blank">cannon-es</a></b>: A lightweight 3D physics engine purely written in JS/TS. Under an MIT license. Apparently no longer maintained (latest commit more than a couple years ago).</li>
112
+
<li><b><ahref="https://github.com/schteppe/cannon.js" target="_blank">cannon.js</a></b>: A lightweight 3D physics engine purely written in JavaScript. Under an MIT license. No longer maintained (latest commit more than a couple years ago). Consider using its more recent fork cannon-es.</li>
113
+
<li><b><ahref="https://github.com/lo-th/phy" target="_blank">phy</a></b>: Physics engine for three.js purely written in JavaScript. Under an MIT license. Latest commit. Currently maintained.</li>
114
+
<li><b><ahref="https://github.com/lo-th/Oimo.js" target="_blank">Oimo.js</a></b>: A no-longer maintained lightweight 3D physics engine written purely in JavaScript. Under an MIT license. Consider using phy instead (as per the author's advise).</li>
115
+
</ul>
116
+
<p>
117
+
It should also be noted that there are a couple of 3D physics engines that are seemingly written in JS/TS but are in reality calling other standalone 3D physics engines. For example:
118
+
</p>
119
+
<ul>
120
+
<li><b><ahref="https://github.com/chandlerprall/Physijs" target="_blank">Physijs</a></b>: Calls ammo.js under the hood to do physics work in a separate thread (using web workers). Under MIT license. Apparently no longer maintained (latest commit more than a couple of years ago).</li>
121
+
<li><b><ahref="https://github.com/enable3d/enable3d" target="_blank">enable3d</a></b>: 3D physics framework for three.js built on top of ammo.js. Under LGPL-3.0 license. Apparently maintained.</li>
122
+
</ul>
123
+
124
+
<h3>3. Importing WASM-based Engines</h3>
125
+
126
+
<p>
127
+
For maximum performance, stability, and precision, especially with complex simulations, you can use physics engines written in
128
+
C++ or Rust (or any other language that supports WASM) that have been compiled to WebAssembly (WASM). Engines like <b>Ammo.js</b> (a port of
129
+
Bullet Physics) and <b>Rapier</b> fall into this category.
130
+
</p>
131
+
132
+
<p>
133
+
While this approach offers the most features and best performance, it often requires more setup code
134
+
to handle the WASM memory management and interaction with the physics API directly.
135
+
</p>
136
+
137
+
<h4>
138
+
Examples
139
+
</h4>
140
+
<ul>
141
+
<li><ahref="https://threejs.org/examples/physics_ammo_break.html" target="_blank">physics / ammo / break</a></li>
142
+
<li><ahref="https://threejs.org/examples/physics_ammo_cloth.html" target="_blank">physics / ammo / cloth</a></li>
143
+
<li><ahref="https://threejs.org/examples/physics_ammo_rope.html" target="_blank">physics / ammo / rope</a></li>
144
+
<li><ahref="https://threejs.org/examples/physics_ammo_terrain.html" target="_blank">physics / ammo / terrain</a></li>
145
+
<li><ahref="https://threejs.org/examples/physics_ammo_volume.html" target="_blank">physics / ammo / volume</a></li>
146
+
</ul>
147
+
148
+
<h4>
149
+
Projects
150
+
</h4>
151
+
<ul>
152
+
<li><b><ahref="https://github.com/jrouwe/JoltPhysics" target="_blank">JoltPhysics</a></b>: A multi core friendly rigid body physics and collision detection library. Written in C++. Under MIT license. Actively maintained. Proven with its usage in world-renowned titles and game engines including: Horizon Forbidden West, Death Stranding 2, and official supported by the Godot game engine.</li>
153
+
<li><b><ahref="https://github.com/NVIDIA-Omniverse/PhysX" target="_blank">PhysX</a></b>: Industry-standard realtime 3D physics engine provided by NVIDIA. Under BSD-3-Clause license. Actively maintained and very stable.</li>
154
+
<li><b><ahref="https://github.com/dimforge/rapier" target="_blank">Rapier</a></b>: 2D and 3D physics engines focused on performance. Written in Rust. Under an MIT license. Actively maintained.</li>
Real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc. Written in C++. Under a ZLIB license. Potentially no longer maintained.</li>
157
+
</ul>
158
+
<p>
159
+
Some of these multi-platform 3D physics engines have a ready-to-use WASM port, including:
160
+
</p>
161
+
<ul>
162
+
<li><b><ahref="https://github.com/jrouwe/JoltPhysics.js" target="_blank">JoltPhysics.js</a></b>: Port of JoltPhysics to JavaScript using Emscripten. Under MIT license. Currently maintained.</li>
163
+
<li><b><ahref="https://github.com/fabmax/physx-js-webidl" target="_blank">physx-js-webidl</a></b>: Javascript WASM bindings for Nvidia PhysX. Under MIT license. Currently maintained.</li>
164
+
<li><b><ahref="https://github.com/dimforge/rapier.js" target="_blank">Rapier.js</a></b>: Official JavaScript bindings for the Rapier physics engine. Under Apache-2.0 license. Actively maintained.</li>
165
+
<li><b><ahref="https://github.com/kripken/ammo.js" target="_blank">Ammo.js</a></b>: Direct port of the Bullet physics engine to JavaScript using Emscripten. No longer maintained (latest commit a couple of years ago). Under an MIT-like custom permissive license.</li>
0 commit comments