Workbook 6: 3D and Three

CS559 Spring 2023 Sample Solution

This is a sample solution for the Workbook. You are welcome to refer to it to learn one way to do the assignment but only after you have turned in your own assignment

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: we both want you to get the idea of the specific THREE library, but also to see the general graphics concepts.

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
  3. Provide experience with the basic concepts of 3D Graphics
  4. Be able to work with standard camera models, lighting models, and primitives used in computer graphics

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 (if you find others, post them on Piazza!):

  • 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 following are 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 Chapter 8: The Graphics Pipeline - this will explain how drawing actually happens, with all the steps that the APIs are taking care of for us.

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.

Page  8  (Snowman) and Page  9  (Space-Age Sculpture Museum) 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 (97 points total)
Points (86):
20 pt
correct WB6 Canvas Assignment submission
20 pt
correct WB6G Canvas Assignment submission on time
Box 06-02-02
1 pt
move the yellow cube
Box 06-04-03
5 pt
stacking the boxes as described
Box 06-05-03
4 pt
add lights to scene so that sides of the cubes appear in different colors
Box 06-06-01
5 pt
give each sphere a different, non-white material (1/2 pt each, 1/2 pt for all different)
Box 06-08-01
3 pt
Visible Objects (requires lights, camera, at least some shapes)
Box 06-08-01
2 pt
Different materials used (everything isn't the same color
Box 06-08-01
3 pt
There is a ground, Snowman on ground
Box 06-08-01
4 pt
Snowman Body as 3 stacked spheres
Box 06-08-01
4 pt
Snowman Face (eyes, nose, mouth
Box 06-09-01
2 pt
Museum cameras work (1/2 pt per camera)
Box 06-09-01
3 pt
Museum objects (1 pt for each object that is more than a simple primitive)
Box 06-09-01
3 pt
Museum objects correctly placed (1 pt per new object)
Box 06-09-01
3 pt
Museum objects move correctly (1 pt per new object), not all the same
Box 06-09-01
2 pt
Museum objects each have spotlights (1/2 pt per object)
Box 06-09-01
2 pt
Each new object has its own material
Advanced points (11):
Box 06-08-01
2 pt
Animated snowman
Box 06-08-01
3 pt
Second, creative snowman
Box 06-09-01
2 pt
At least one object has articulated motion
Box 06-09-01
2 pt
Complex museum objects
Box 06-09-01
2 pt
Complex museum object motions

Ground Rules for Workbook 6

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 submit 06-workbook.txt the WB6 Canvas Assignment when you are done!

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