Rough Terrain

Ground is rarely perfectly flat. In graphics, we call rough terrain noisy, which is why we added that noise code collection in the setup.

Still inside the addGround() function, delete the lines that pulled up the vertices. Then, replace them with a loop that works through each vertex in the plane.

​ ​var​ faces = 99;
​ ​var​ shape = ​new​ THREE.PlaneGeometry(10, 20, faces, faces);
​ 
»​var​ numVertices = shape.vertices.length;
»​var​ noiseMaker = ​new​ SimplexNoise();
»​for​ (​var​ i=0; i<numVertices; i++) {
» ​var​ vertex = shape.vertices[i];
» ​var​ noise = 0.25 * noiseMaker.noise(vertex.x, vertex.y);
» vertex.z = noise;
»}

We don’t pull each vertex in the Z direction by the same ...

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.