Extending Three.js with a custom geometry object

In the recipes you've seen so far, we create Three.js objects from scratch. We either build a new geometry from scratch with vertices and faces, or we reuse an existing one and configure it for our purpose. While this is good enough for most scenarios, it isn't the best solution when you need to maintain a large code base with lots of different geometries. In Three.js, you create geometries by just instantiating a THREE.GeometryName object. In this recipe, we'll show you how you can create a custom geometry object and instantiate it just like the other Three.js objects.

Getting ready

The example that you can use to experiment with this recipe can be found in the provided sources. Open up 02.11-extend-threejs-with-custom-geometry.html ...

Get Three.js Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.