Creating a basic Three.js scene with Rapier
Figure 12.1 – Simple Rapier physics
When you open this example, you’ll see the cube slowly drop down, hit the corner of the gray horizontal plane, and bounce off it. We could have accomplished this without using a physics engine by updating the position and rotation of the cube and programming how it should react. This is, however, rather difficult to do since we need to know exactly when it hits, where it hits, and how the cube should spin away after the hit. With Rapier, we just have to configure the physical world, and Rapier will calculate exactly what happens to the objects in the scene.
Before we can configure our models to use the Rapier engine, we need to install Rapier in our project (we’ve already done this, so you don...