Changing Color

Add the following below START CODING ON THE NEXT LINE:

 
var​ shape = ​new​ THREE.SphereGeometry(100);
 
var​ cover = ​new​ THREE.MeshBasicMaterial();
 
cover.color.setRGB(1, 0, 0);
 
var​ ball = ​new​ THREE.Mesh(shape, cover);
 
scene.add(ball);

MeshBasicMaterial

Notice that, instead of the MeshNormalMaterial that we have used to wrap things so far, we’re now using a MeshBasicMaterial. Since it’s a basic cover, there’s not much we can do with it. But we can change the color, which is new.

You should see a red ball on the screen:

images/lights_and_materials/red_ball.png

Colors in computer programs are written as RGB numbers, which describe how much red (R) green (G), and ...

Get 3D Game Programming for Kids 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.