O'Reilly logo

Learning Three.js: The JavaScript 3D Library for WebGL by Jos Dirksen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Summary

In this last chapter we've explored how you can extend the basic 3D functionality from Three.js by adding physics. For this we've used the Physijs library, which allows you to add gravity, collisions, constraints, and much more. The most important things to remember when working with this library are the following:

  • To use Physijs you need to change the scene you instantiate and specify the gravity you want to use. You also need to change the render loop to include a simulate step that tells Physijs to calculate the position and rotation of all the objects in the scene.
  • Only geometries wrapped in their Physijs counterpart will be subject to the physics. In most cases you can just change the THREE.Mesh definition with the Physijs variant. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required