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

Creating a point cloud from scratch


When you want to create a point cloud, you can pass in an existing geometry and base the point cloud on it. In this recipe, we'll show you how you can create THREE.Geometry from scratch and create a point cloud from it.

Getting ready

For this recipe, we don't require any additional JavaScript libraries and we don't need to load external models, as we create our geometry from scratch. You can look at the geometry we created by opening 06.02-create-point-system-from-scratch.html in your browser. You will see something similar to the following screenshot:

In the next section, we'll explain how to create this custom geometry and use it together with THREE.PointCloud.

How to do it...

The steps are pretty much the same as shown in the Creating a point cloud based on a geometry recipe, except that first, we need to create our own custom geometry:

  1. Creating a custom geometry is fairly easy:

      var x = 100;
      var y = 100;
      var geometry = new THREE.Geometry();
      for (var...