Rendering Donuts (Not the Kind You Eat) with Torus

In 3D-programming-speak, a donut shape is called a torus. The simplest torus that we can create needs us to assign two values: one for the distance from the center to the outside edge, and the other for the thickness of the tube.

TorusGeometry(100, 25)

Type the following below your plane code:

​ ​var​ shape = ​new​ THREE.TorusGeometry(100, 25);
​ ​var​ cover = ​new​ THREE.MeshNormalMaterial(flat);
​ ​var​ donut = ​new​ THREE.Mesh(shape, cover);
​ scene.add(donut);

You should see a very chunky donut:

images/getting_started/chunky_donut.png

By now you probably know how to make the donut less chunky.

TorusGeometry(100, ...

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.