Lab: Color By Normal

How to 3D

Chapter 3: Triangle Meshes

Lab: Color By Normal

Your next milestone involves loading in 3D models and shading them according to a light source. This lab will prepare the groundwork for that milestone by acquainting you with glTF files and vertex normals. Complete these steps:

Work first through Tuesday's exercise to get a renderer that reads in a simple glTF file and models it as points.
Extract the triangle indices from the glTF object and store them alongside the positions in your Trimesh class. They can be extracted much like the positions were extracted, but they should be dropped into a Uint16Array rather than a Float32Array because they are short integers. Then they should be unpacked into a flat array of numbers, not an array of Vector3.
Include the indices in the VertexAttributes and draw the model as indexed triangles.
Extract the normals from the glTF object and store them alongside the positions in your Trimesh class. Normals are vectors that are perpendicular to the model surface. We will learn more about them in a forthcoming chapter on lighting.
Color the model by interpreting the normals as RGB colors. Some portions of the model will render black. What does that mean? How can you tweak the shader so you see a colorful gradient everywhere?

Submission

To receive credit for your lab work, follow these steps:

Share a screenshot of your renderer in a post on the #lab-gallery channel in Discord. Tag your group members.

Only labs submitted on time will be granted credit. Late labs or forgot-to-submits are not accepted because Wednesday at noon is when your instructor has time to grade.

← glTF Exploration