Book Image

Three.js Cookbook

By : Jos Dirksen
Book Image

Three.js Cookbook

By: Jos Dirksen

Overview of this book

Table of Contents (15 chapters)
Three.js Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Rendering 3D formulas as 3D geometries


Three.js offers many different ways to create geometries. You can use the standard Three.js objects, such as THREE.BoxGeometry and THREE.SphereGeometry, create geometries completely from scratch, or just load models created by external 3D modeling programs. In this recipe, we will show you another way to create geometries. This recipe shows you how to create geometries based on math formulas.

Getting ready

For this recipe, we'll be using the THREE.ParametricGeometry object. As this is available from the standard Three.js distribution, there is no need to include additional JavaScript files.

To see the end result of this recipe, you can look at 02.10-create-parametric-geometries.html, you'll see something similar to the following screenshot:

This figure shows you a Gray's Kleinbottle, which is rendered based on a couple of simple math formulas.

How to do it...

Generating geometries using math formulas with Three.js is very easy and only takes two steps:

  1. The...