Pushing and Pulling Shapes

In 3D programming, shapes are much easier to change than you might guess. As far back as Chapter 1, Project: Creating Simple Shapes, we’ve known how to change a shape’s size, chunkiness, and rotation. It turns out that we can do even more. Lots more.

To see this, add a call to addGround() below the START CODING line. Then define the addGround() function as shown:

 var​ ground = addGround();
 
 function​ addGround() {
 var​ faces = 99;
 var​ shape = ​new​ THREE.PlaneGeometry(10, 20, faces, faces);
 
 var​ _cover = ​new​ THREE.MeshPhongMaterial({color: ​'green'​, shininess: 0});
 var​ cover = Physijs.createMaterial(_cover, 0.8, 0.1);
 
 var​ mesh = ​new​ Physijs.HeightfieldMesh(shape, cover, 0);
  mesh.rotation.​ ...

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.