Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.2 — Everything Is Triangles
3D Web · Example 1 of 2

Count the triangles in seven shapes

Each count comes from the geometry's index and again from the renderer. The wireframe sphere (8 × 6) shows its 80 triangles.

Every 3D shape is a mesh of triangles joined at corner points called vertices. Triangles are used because three points are always flat, and the number of triangles is the first thing that decides how much a scene costs.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

A cylinder has 12 sides. Compute its triangles (sides plus two caps) and check with geometry.index.count / 3.

02

A designer's model has 2 million triangles and runs at 15 frames per second on a phone. Name two things you would try before asking for a new model.

Explain it without notes

01

Why does the GPU use triangles and not squares or other polygons?

02

A sphere has 32 segments around and 16 from top to bottom. How many triangles is that and how do you get the number?

Count the triangles in seven shapes
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

Plane 1 x 1                   4 vertices      2 triangles | renderer.info: 2
Box 1 x 1 x 1                24 vertices     12 triangles | renderer.info: 12
Cylinder, 8 sides            52 vertices     32 triangles | renderer.info: 32
Cylinder, 64 sides          388 vertices    256 triangles | renderer.info: 256
Sphere 8 x 6                 63 vertices     80 triangles | renderer.info: 80
Sphere 32 x 16 (default)    561 vertices    960 triangles | renderer.info: 960
Sphere 64 x 32             2145 vertices   3968 triangles | renderer.info: 3968