3D Game Programming

(C. Jardin) #1
varshape =newTHREE.PlaneGeometry(100, 100);
varcover =newTHREE.MeshNormalMaterial();
varground =newTHREE.Mesh(shape, cover);
scene.add(ground);
ground.rotation.set(0.5, 0, 0);

Don’t forget the rotation on the last line. Planes are so thin that you might
not see them when looking directly at them.

The numbers when building a plane are the width and depth. A plane that
is 300 wide and 100 deep might look like this:

That’s pretty much all there is to know about planes. Move our plane out of
the way:

varshape =newTHREE.PlaneGeometry(300, 100);
varcover =newTHREE.MeshNormalMaterial();
varground =newTHREE.Mesh(shape, cover);
scene.add(ground);
ground.position.set(-250, -250, -250);

Now let’s move on to the greatest shape in the world.


Rendering Donuts (Not the Kind You Eat) with Torus


In 3D-programming-speak, a donut 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 into ICE:

varshape =newTHREE.TorusGeometry(100, 25);
varcover =newTHREE.MeshNormalMaterial();
vardonut =newTHREE.Mesh(shape, cover);
scene.add(donut);

You should see a very chunky donut, as shown in Figure 1, A Chunky Donut,
on page 13.

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


Chapter 1. Project: Creating Simple Shapes • 12


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf