Then we add the following points after the ground’s shadow properties:
ground.river_points = river_points;
The entire makeGround() function should now look like this:
functionmakeGround(size) {
varfaces = 100;
varshape =newTHREE.PlaneGeometry(size, size, faces, faces);
varriver_points = digRiver(shape, faces + 1);
varcover = Physijs.createMaterial(
newTHREE.MeshPhongMaterial({
emissive:newTHREE.Color(0x339933),// a little green
specular:newTHREE.Color(0x333333) // dark gray / not shiny
}),
1, // high friction (hard to move across)
0.1// not very bouncy
);
varground =newPhysijs.HeightfieldMesh(
shape, cover, 0
);
ground.rotation.set(-Math.PI/2, 0.2, -Math.PI/2);
ground.receiveShadow = true;
ground.castShadow = true;
ground.river_points = river_points;
returnground;
}
Can you see what the problem is? That’s right—this will break our code
because we haven’t defined the digRiver() function. We’ll do that next.
Pulling Corners
We dig our river by typing in the following code after the makeGround() function:
functiondigRiver(shape, size) {
varcenter_points = [];
for(varrow=0; row<size; row++) {
varcenter = Math.sin(4*Math.PI*row/size);
center = center * 0.1 * size;
center = Math.floor(center + size/2);
center = row*size + center;
for(vardistance=0; distance<12; distance++) {
shape.vertices[center + distance].z = -5 * (12 - distance);
shape.vertices[center - distance].z = -5 * (12 - distance);
}
center_points.push(shape.vertices[center]);
Chapter 20. Project: River Rafting • 192
Prepared exclusively for Michael Powell report erratum • discuss