Workbook 7: Transformation and Hierarchy in Three.js

This week, we’ll continue to do more THREE programming, with a focus on using THREE’s mechanisms for transformation and hierarchy to make more interesting things.

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

Learning Goals

  1. To gain some experience doing hierarchical modeling, particularly for animation
  2. To get some practice working with 3D rotations
  3. To get some experience working with the CS559 framework code
  4. To get more practice working with a modern scene graph API
  5. To see some details of how different rotation representation are used
  6. To get some exposure to modern JavaScript features like classes
  7. To get some experience working with another person’s code

Warnings to Start…

This workbook is a little “bigger” than some of the others: you need to make a number of objects. This will give you more practice at making things. Most students like making stuff - it’s one of the fun parts of doing graphics.

But there is also some substantial content: we will try to understand transformations in 3D, we will get more practice using the specific 3D API (THREE.js) and how it implements transformations and other things, and you’ll use the class software framework that will help make UIs for building things in THREE.js.

Also… in this workbook, you are required to fill out text files on some pages explaining what your assignment does. On page 6, 8 and 9 it isn’t enough to do the work: you must also edit the text file and tell us.

Over the course of this assignment, you will probably need to read some of the THREE.js Documentation (current). When you wonder what you can do with a class like BufferGeometry, or what a function like DataTextureLoader.load does, this is the place to look. Even though the documentation is for the “current” version of THREE, it still applies to the version we are using.

A Note on THREE versions

In class, we use the same version of THREE to use for the whole semester, to avoid switching versions in the middle. That way the workbooks all use the same, consistent version.

When we chose for Spring 2023, we chose version r148. This is already not the most recent release (you can see what changed on the THREE Releases Page). The differences probably do not matter for class.

You can see information about the version of THREE we provide at The CS559 THREE GitHub Repo. Of particular note: we provide typing information for THREE, and we provide a subset of the overall library (since it gets cloned into a workbook for every student).

You will also start working with the class framework code. This will require you to spend some time reading the code and its documentation (which is derived from comments in the code). It may also cause you to need to read up on some aspects of JavaScript we haven’t used much in class yet. The framework code will be discussed on page 7.

The textbook readings are meant to complement the lectures. They talk about what is going on inside of THREE (so they may not important for doing the workbook, but they are helpful in understanding how things work - which you should want to know, and may need for the exams)

  • FCG Chapter 12 - Section 12.2 (other chapter 12 sections are things we will get to later in class)
  • Hart, Chapter 7 is written in terms of explicit matrix stacks (which we did with Canvas2D), but gives examples on how to think about hierarchical modeling
  • Hart, Chapter 8 can help you if you want to see viewing another way (this was also optional in the last workbook).
  • The Real Time Rendering Book has a very thorough discussion of transformations in sections 1-3, with significant attention paid to rotations and Quaternions (Section 4.3). This material is beyond what you need for class, but may be a good thing to read if you want a better understanding of 3D transformations.

From the previous workbook, but still relevant:

The readings are here to help you understand the things we discussed in class.

Hierarchical modeling is discussed briefly in section 2 of FCG4_Ch12.pdf (0.9mb) and Hart07-jan19.pdf (14.5mb). In both cases, the focus is more on how you implement the scene graph traversal using transformation stacks than how to think in terms of hierarchical models. In the workbooks, we’ll let THREE do this work for us. However, the stack model is discussed in lecture, and you should understand it.

The lookfrom/lookat/vup transformation is called the “The Camera Transformation” in section 1.3 of FCG4_Ch07.pdf (0.5mb). Other things in the chapter discuss the Perspective Transformation in depth (no pun intended), and can help you understand these concepts better. Hart discusses lookfrom/lookat in Hart08-jan19.pdf (1.7mb), but it adds little beyond what you’ve seen already. Look at it if you want to see it explained a different way. These topics will also be discussed in the lectures.

Exercises

The main exercises for this workbook are:

  • Rotation Toys - We are giving you demos to play with. You should use them to help build your intuitions as to how 3D rotations work (or do not work) as the case may be.
  • The Quadcopter / Aircraft - you get to make a quadcopter again, this time in 3D. It’s a hierarchical model. And you’ll need to show that you can use a “lookat” transformation.
  • Graphics Park - before we get to Graphics Town, we’ll start smaller. This is a chance to animate some hierarchical objects in 3D and figure out the framework code.
  • Construction Equipment - another chance to use the framework code and make a different kind of hierarchical object.

Over the next few weeks, we’ll be using the framework code to make increasingly interesting objects. The idea is that by the end of the semester, all of the objects you make can fit together into Graphics Town.

Rubric for Grading

There are lots of opportunities for advanced points on this assignment, but we limit the total number you can earn for this workbook.

The objects that you make using the framework will be usable in the future: we will use the framework for all of the future assignments, including the final “Graphics Town” assignment. If you make nice objects now, you can use them again.

Hopefully, you are making really cool stuff because you like making cool stuff and are learning from doing it, not just because we are giving you a few points.

Workbook Rubric (97 points total)
Points (87):
30 pt
Correct hand-in
Page 2
1 pt
experimenting with the demos on page 2. (We’ll just trust that you’ve done it if you turn any other part in.)
Page 3
1 pt
experimenting with the demos on page 3. (We’ll just trust that you’ve done it if you turn any other part in.)
Box 07-06-01
2 pt
Some aircraft that isn’t a donut
Box 07-06-01
3 pt
A propeller that spins (not the body)
Box 07-06-01
3 pt
More than one propeller spinning (per aircraft)
Box 07-06-01
2 pt
(at least) One aircraft that flies in a circle (or curved path)
Box 07-06-01
3 pt
aircraft points forward as it moves
Box 07-06-01
3 pt
multiple aircraft both moving, both with propellers
Box 07-06-01
2 pt
Radar dish (or some pointable object)
Box 07-06-01
3 pt
Radar correctly points at aircraft (tracks as aircraft moves) - should use lookat
Box 07-08-01
1 pt
take out bouncing cube
Box 07-08-01
1 pt
place at least 1 more swing
Box 07-08-01
1 pt
place carousel
Box 07-08-01
3 pt
carousel has poles and ''horses''
Box 07-08-01
4 pt
carousel has correct motion (spins, horses go up and down)
Box 07-08-01
4 pt
another moving object
Box 07-09-01
4 pt
equipment 1 is identifiable (can tell what it is)
Box 07-09-01
4 pt
equipment 2 is identifiable
Box 07-09-01
4 pt
equipment 1 has correct articulation
Box 07-09-01
4 pt
equipment 2 has correct articulation
Box 07-09-01
3 pt
UI works for 1&2
Box 07-09-01
1 pt
good use of colors/materials for all equipment (not just one color)
Advanced points (19 possible, of which you can earn a maximum of 10):
Box 07-06-01
1 pt
cool aircraft
Box 07-06-01
1 pt
more complex motion
Box 07-06-01
2 pt
multiple types of aircraft - each with an articulation/propeller
Box 07-06-01
1 pt
other cool features (students came up with some great things in 2D!)
Box 07-08-01
1 pt
fancier looking carousel
Box 07-08-01
3 pt
more theme park rides (1st of up to 3 with hierarchical motion - 2 pts)
Box 07-08-01
2 pt
more theme park rides (2nd of up to 2 with hierarchical motion - 2 pts)
Box 07-09-01
3 pt
third machine identifyable with working articulation
Box 07-09-01
2 pt
nice shapes
Box 07-09-01
2 pt
more than the minimum degrees of freedom on the objects
Box 07-09-01
1 pt
at least one object has 4+ d.o.f. (beyond position/orientation)

Get started on Page  1  (Rotations in 3D)!