Making Boxes with the Cube Shape

Next we’ll make a cube, which is another name for a box. In 3D programming, the sides of a cube don’t have to be the same size. We can control the width, the height, and the depth.

Size: CubeGeometry(300, 100, 20)

To create a box, we’ll write more JavaScript below everything that we used to create our ball. Type the following (maybe add a blank line first):

​ ​var​ shape = ​new​ THREE.CubeGeometry(100, 100, 100);
​ ​var​ cover = ​new​ THREE.MeshNormalMaterial(flat);
​ ​var​ box = ​new​ THREE.Mesh(shape, cover);
​ scene.add(box);

If you have everything correct, you should see… a square?

Well, that’s boring. Why do we see a square instead of a box? The answer is that our ...

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.