Reader small image

You're reading from  Learning Three.js - the JavaScript 3D Library for WebGL

Product typeBook
Published inMar 2015
Reading LevelIntermediate
Publisher
ISBN-139781784392215
Edition1st Edition
Languages
Right arrow
Author (1)
Jos Dirksen
Jos Dirksen
author image
Jos Dirksen

Jos Dirksen has worked as a software developer and architect for almost two decades. He has a lot of experience in many technologies, ranging from backend technologies, such as Java and Scala, to frontend development using HTML5, CSS, JavaScript, and Typescript. Besides working with these technologies, Jos regularly speaks at conferences and likes to write about new and interesting technologies on his blog. He also likes to experiment with new technologies and see how they can best be used to create beautiful data visualizations. Previously, Jos has worked in many different roles in the private and public sectors, ranging from private companies such as ING, ASML, Malmberg, and Philips to organizations in the public sector, such as the Department of Defense and the Port of Rotterdam.
Read more about Jos Dirksen

Right arrow

Chapter 5. Learning to Work with Geometries

In the previous chapters, you learned a lot about how to work with Three.js. You know how to create a basic scene, add lighting, and configure the material for your meshes. In Chapter 2, Basic Components That Make Up a Three.js Scene, we touched upon, but didn't really go into the details of, the available geometries that Three.js provides and that you can use to create your 3D objects. In this and the next chapter, we'll walk you through all the geometries (except THREE.Line, which we discussed in the previous chapter) Three.js provides out of the box. In this chapter, we'll look at the following geometries:

  • THREE.CircleGeometry

  • THREE.RingGeometry

  • THREE.PlaneGeometry

  • THREE.ShapeGeometry

  • THREE.BoxGeometry

  • THREE.SphereGeometry

  • THREE.CylinderGeometry

  • THREE.TorusGeometry

  • THREE.TorusKnotGeometry

  • THREE.PolyhedronGeometry

  • THREE.IcosahedronGeometry

  • THREE.OctahedronGeometry

  • THREE.TetraHedronGeometry

  • THREE.DodecahedronGeometry

And in the next...

The basic geometries provided by Three.js


In Three.js, we have a couple of geometries that result in a two-dimensional mesh and a larger number of geometries that create a three-dimensional mesh. In this section, we'll first look at the 2D geometries: THREE.CircleGeometry, THREE.RingGeometry, THREE.PlaneGeometry, and THREE.ShapeGeometry. After that, we'll explore all the basic 3D geometries that are available.

Two-dimensional geometries

Two-dimensional objects look like flat objects and, as the name implies, only have two dimensions. The first two-dimensional geometry on the list is THREE.PlaneGeometry.

THREE.PlaneGeometry

A PlaneGeometry object can be used to create a very simple two-dimensional rectangle. For an example of this geometry, look at the 01-basic-2d-geometries-plane.html example in the sources for this chapter. A rectangle created using PlaneGeometry is shown in the following screenshot:

Creating this geometry is very simple, as follows:

new THREE.PlaneGeometry(width, height,widthSegments...

Summary


In this chapter, we discussed all of the standard geometries Three.js has to offer. As you saw, there are a whole lot of geometries you can use right out of the box. To best learn how to use the geometries, experiment with the geometries. Use the examples in this chapter to get to know the properties you can use to customize the standard set of geometries available from Three.js. It is also a good thing that when you start with geometries, you choose a basic material; don't go directly for the complex materials, but start simple with THREE.MeshBasicMaterial with the wireframe set to true, or THREE.MeshNormalMaterial. That way, you'll get a much better picture of the true shape of a geometry. For two-dimensional shapes, it's important to remember that they are placed on the x-y plane. If you want to have a two-dimensional shape horizontally, you'll have to rotate the mesh around the x axis for -0.5 * PI. And finally, take care that if you're rotating a two-dimensional shape, or a...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Three.js - the JavaScript 3D Library for WebGL
Published in: Mar 2015Publisher: ISBN-13: 9781784392215
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jos Dirksen

Jos Dirksen has worked as a software developer and architect for almost two decades. He has a lot of experience in many technologies, ranging from backend technologies, such as Java and Scala, to frontend development using HTML5, CSS, JavaScript, and Typescript. Besides working with these technologies, Jos regularly speaks at conferences and likes to write about new and interesting technologies on his blog. He also likes to experiment with new technologies and see how they can best be used to create beautiful data visualizations. Previously, Jos has worked in many different roles in the private and public sectors, ranging from private companies such as ING, ASML, Malmberg, and Philips to organizations in the public sector, such as the Department of Defense and the Port of Rotterdam.
Read more about Jos Dirksen