Workbook 7: 3D and Three

CS559 Spring 2021 Sample Solution - Workbook 7

Written by CS559 course staff

You can try out the example solutions here. The interesting code is on page 8 and page 9.

This workbook is due on Monday, March 15, 2021.

In this workbook, we’ll move on to doing some 3D programming. To do this, we’ll use a Javascript library called THREE.js (we’ll just say THREE from now on).

There are two major goals in this workbook:

Learning Goals

  1. Get you set up with the mechanics of using THREE.js
  2. Get you to make some basics 3D pictures and animations using THREE.js and the basic pieces

The idea is that once you’ve gotten started, it will be easier to explain both what is happening “underneath the hood” as well as fancier things. However, one down side of this strategy is that you may not always understand why you are doing things (since we aren’t explaining how things work), and you may wonder why we are limiting ourselves to simple things (because we are saving more complicated stuff for later).

There are two parts to the reading: you need to learn about the THREE.js library in order to use it, and you need to learn about the basic concepts of transformations in 3D (since you need to know them). You don’t need to understand the graphics stuff in order to do the workbook, but you will want to know it for the quiz and exam, and if you really want to know graphics.

Learning THREE: The official documentation can be found here. This is mainly a reference. Once you get started you can look up the details of the things you need.

Be warned: a lot of the fancier stuff may not make sense until we’ve talked about what is happening “under the hood”. The documentation dives into details quite quickly. The workbook is designed to guide you through the basics. We suggest you use the official documentation as a reference to get the details as you need them.

The workbook and lectures should give you enough of an idea of how THREE works to complete the workbook, but you might find it helpful to see other materials or examples. The workbook’s version of the library does not include THREE.js in its entirety, mostly excluding many of the examples. We only included enough to get you through the workbooks. You can download the entire library if you wish, but please don’t add it to your git repo if you do.

While there are a lot of THREE resources around the web, and the API documentation is pretty complete, things tend not to be that well-organized or beginner-friendly. If you find good additional resources, please post them on Piazza. Here are some things I found useful:

  • THREE.js Getting Started - Shows you the minimal steps for creating a scene with THREE. It’s a bit redundant with this workbook, but seeing things in someone else’s words may be useful.

  • THREE.js Tutorial - This is very similar to the way we’ll introduce things in this workbook. Read this to see what we’re talking about said in different words.

  • Aviator Game - this is a complicated example that builds things up from scratch. It’s a bit of a fancy application to start with, but you can see how the author builds something pretty cool using the pieces we’ll learn about.

The textbooks: Between now and the exam, you need to understand transformations in 3D and viewing and projection (which will turn out to be a special case of transformations). THREE takes care of a lot of this for us, so you may not see it when you program. THREE does a good job of hiding the matrices if you don’t want to see them (unlike 2D Canvas, it will let you see them).

When we learned about transformations, we skipped 3D transformations. Now is a good time to come back to them. You are required to read:

  • The Big Fun Book of Computer Graphics, Chapter 6. This Chapter mixes in many different, but important things, including a review of the vector algebra basics. Most of the chapter is essential and required. This will tell you what you can skip.

    • 6.1 - Scale and Translation - important, but a simple extension of 2D
    • 6.2 - Handedness of Coordinate Systems - important
    • 6.3 - Vector Arithmetic - a good review including dot products and cross products. The section on Gramm-Schmidt Orthonormalization is optional (but it is a useful advanced topic).
    • 6.4 - Rotation about a Coordinate Axis - important
    • 6.5 - Properties of Rotation Matrices - the first part is important. The part on Cayley’s Formula is optional.
    • 6.6 - Rotation about an Arbitrary Axis - this is very valuable, and good for getting the intuitions about rotations, but is optional since we won’t discuss it in detail in class.

The following are also required. You may not need it immediately for the workbook, but it will come back for the exams:

  • Fundamentals of CG - Chapter 6 Section 6.2 - “3D Linear Transformations”, which mainly just gives the matrices for 2D and 3D transformations. You might want to go over other parts of the Chapter (they were required in the past).
  • Fundamentals of CG - Chapter 7: Viewing - this will explain how cameras work. This chapter is short.
  • Fundamentals of CG - Chapter 12 Section 12.2: Scene Graphs - this reiterates what we’ve seen about using transformations to create hierarchical models. You only need Section 12.2 - we’ll come back to other parts of this chapter later in the semester.

These readings are optional:

  • FCG4_Ch08.pdf (0.6mb): The Graphics Pipeline - this will explain how drawing actually happens, with all the steps that the APIs are taking care of for us.
  • Hart07-jan19.pdf (14.5mb): More examples of using transformations, since getting practice is useful.
  • Hart08-jan19.pdf (1.7mb): Hart’s explanation of viewing. This provides another version of what is in FCG Ch. 7 - useful if you want to see it multiple ways.

Exercises

Most pages have code examples - make sure you understand how they work.

Pages 2, 4, 5 and 6 have simple examples on them. Make sure they work, and that you understand them.

Pages 8 and 9 ask you to make pictures. For now, please focus on understanding the basic features: you will have plenty of time later to use fancier features.

Rubric for Grading

Workbook Rubric (96 points total)
Points (86):
5 pt
correct handin with quiz
Box 07-02-02
2 pt
move the yellow cube
Box 07-04-03
10 pt
stacking the boxes as described
Box 07-05-03
5 pt
add lights to scene so that sides of the cubes appear in different colors
Box 07-06-01
10 pt
give each sphere a different, non-white material (1pt each, 1 pt for all different)
Box 07-08-01
8 pt
Visible Objects (requires lights, camera, at least some shapes)
Box 07-08-01
3 pt
Different materials used (everything isn't the same color
Box 07-08-01
3 pt
There is a ground, Snowman on ground
Box 07-08-01
8 pt
Snowman Body as 3 stacked spheres
Box 07-08-01
8 pt
Snowman Face (eyes, nose, mouth
Box 07-09-01
4 pt
Museum cameras work (1 pt per camera)
Box 07-09-01
6 pt
Museum objects correctly placed (2 pt per new object)
Box 07-09-01
6 pt
Museum objects move correctly (2 pt per new object), not all the same
Box 07-09-01
4 pt
Museum objects each have spotlights (1 pt per object)
Box 07-09-01
4 pt
Each new object has its own material
Bonus points (14 possible, of which you can earn a maximum of 10):
Box 07-08-01
2 pt
Animated snowman
Box 07-08-01
4 pt
Second, creative snowman
Box 07-08-01
2 pt
Artistic merit: Cool Snowman
Box 07-09-01
3 pt
Artistic merit: Cool museum objects (1 pt each)
Box 07-09-01
3 pt
Artistic merit: Cool museum object motions (1 pt each)

Ground Rules for Workbook 7

For the programming assignment, we are going to ask you to make some pictures by writing programs that use THREE. We want you to focus on using the parts that we’ve discussed, not trying to show off that you can figure out the fancier features on your own.

You must:

  • Use one material per primitive object.
  • Use solid colors (no textures).
  • Use only built-in shapes (do not make your own meshes).
  • Do not use reflections.
  • You do not need to add shadows (but you can keep the ones we have in the starter code)
  • Do not add other object models (although, you can use the sample ones we provided).
  • Do not make your own new kinds of materials (by writing shaders).

You’ll get to do all of these things later in the class. For now, you can be creative and make sure you understand how to put together the basic pieces.

Get Started

Don’t forget to commit and push as you work! And don’t forget to do the handin quiz when you are done!

Get started on Page  1  (The THREE.js library)!