Postscript
In this module, you added objects to your scene and then animated them together as a group. You also got a glimpse of vectors, meshes, and materials.
The next module will cover adding behavior to the grid cells you created in this module. The more abstract notion of state will also be introduced.
Optional exercises
If you would like to experiment with the demo before moving on to the next module, here are some things to try. Once you're done experimenting, be sure to restore your code to its previous state before moving on to the next module. If you are unsure what you have changed, you can get your code back to the tutorial state by copying it from this module's checkpoint.
Try different values for
GRID_SIZE
. Remember that this value must be an integer. Be aware that as you increase this value, there will be a point where the animation noticeably slows down and may even cause your browser to crash.The
buildCellVisual
function only creates cubes. Change the function so that it creates a shape other than a cube. For example, try creating tetrahedrons instead (usingTHREE.TetrahedronGeometry
).The
update
function used in this module rotates the grid on the y-axis. Add a line to the function so that the grid also rotates on the x-axis. How does this affect the overall scene? What happens if you go a step further and also rotate it on the z-axis?What if the shape of each cell was determined randomly? Modify the
buildCellVisual
function so that it creates a random shape each time it is called. Limit the possible random shapes toTHREE.BoxGeometry
,THREE.ConeGeometry
andTHREE.SphereGeometry
.Consider the logic that determines where to place the camera:
camera.position.set(0, 0, GRID_SIZE * (MAX_CELL_SIZE + CELL_SPACING));
How might you modify the
setUpLights
function so that the position of the lights is determined by the size of your rotating grid? What happens if you accidentally place one of your lights inside the grid? This is an advanced exercise.
Additional resources
- Vectors
- What is a vector? - a 5-minute animated video from TED-Ed about vectors
- Scalars and Vectors - an overview from NASA of vectors and scalars and how they are used
- An introduction to vectors - a lengthier written article from Math Insight about vectors and basic vector math
- JavaScript topics
- Array.prototype.flat() - documentation about the
.flat()
method on arrays.
- Array.prototype.flat() - documentation about the
- three.js classes introduced in this section