Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 39 ยท Geometry and Materials

Built-in Geometries

Tour every common Three.js geometry: box, sphere, plane, cylinder, torus, capsule and polyhedra, plus Lathe, Extrude, Shape and Tube. Includes live examples.

A geometry describes a shape: a list of points (vertices) and how they join into triangles. It has no color and no position of its own; the mesh supplies the material and the transform. Three.js ships with generators for the usual solids, and with tools that build geometry from 2D outlines and paths. This lesson tours them all and explains the parameter that appears everywhere: segments.

The common solids

Class Main parameters
BoxGeometry width, height, depth, widthSegments, heightSegments, depthSegments
SphereGeometry radius, widthSegments, heightSegments
PlaneGeometry width, height, widthSegments, heightSegments
CircleGeometry radius, segments
RingGeometry innerRadius, outerRadius, thetaSegments
CylinderGeometry radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded
ConeGeometry radius, height, radialSegments
CapsuleGeometry radius, length, capSegments, radialSegments
TorusGeometry radius, tube, radialSegments, tubularSegments
TorusKnotGeometry radius, tube, tubularSegments, radialSegments, p, q
TetrahedronGeometry, OctahedronGeometry, DodecahedronGeometry, IcosahedronGeometry radius, detail

Nothing to memorize: the documentation lists every parameter, and the defaults give a decent shape. The demo below shows all of them on one shelf. Toggle the wireframe in the code (wireframe: true) to see the triangles.

The geometry shelf

Segments: smoothness versus cost

A sphere is not round; it is a polyhedron made of many small flat triangles. widthSegments and heightSegments set how many. Few segments are fast but faceted, many are smooth but heavier. As a rule of thumb: 16 to 32 segments suit small or distant objects; 48 to 64 suit hero objects that fill the screen. More than that rarely improves what you see.

PlaneGeometry segments matter for another reason: if you later bend the plane (a terrain, waves, a flag), the extra vertices are where the bending happens.

Segments change the triangle count

Note two things in the code. After creating a new geometry we dispose of the old one with geometry.dispose(), because GPU memory is not freed by the garbage collector. And with flatShading on, each triangle is lit as one flat color, which is the faceted "low poly" look.

Geometry from 2D shapes and paths

Beyond solids, three families build geometry from your own data.

LatheGeometry spins a 2D profile around the y axis, like a potter's wheel. Great for vases, bottles, chess pieces and goblets.

ExtrudeGeometry pushes a 2D Shape along z to give it thickness, with optional bevels. Hearts, logos from SVG paths and floor plans all work this way. ShapeGeometry makes the flat shape without depth.

TubeGeometry sweeps a circle along a 3D curve (CatmullRomCurve3, CubicBezierCurve3, a LineCurve3 and others). Pipes, cables and roller coaster rails.

Lathe, Extrude and Tube

Helper geometries

  • EdgesGeometry(geometry, thresholdAngle) extracts only the sharp edges, useful for outlines (draw it with LineSegments).
  • WireframeGeometry(geometry) extracts every triangle edge.
  • geometry.computeBoundingBox() and computeBoundingSphere() fill geometry.boundingBox and boundingSphere, handy to center or fit a camera.
  • geometry.center() moves the geometry so its bounding box is centered on the origin.
  • geometry.translate(x, y, z), rotateX(rad) and scale(x, y, z) change the vertices themselves, as opposed to the mesh transform. Use them to move a pivot, for example to rotate a door around its hinge.

Text geometry exists too: TextGeometry in the add-ons turns a font file into 3D letters. It needs a font loaded through FontLoader, which the chapter on loading assets covers.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a geometry NOT contain?

    The material is separate. A Mesh combines a geometry with a material.
  2. 2. You want a smooth vase. Which geometry fits best?

    Lathe spins a 2D profile around an axis, which is ideal for rotationally symmetric shapes.
  3. 3. Why call geometry.dispose() when you replace a geometry?

    GPU buffers are not released by JavaScript garbage collection. dispose() frees them.
  4. 4. What does flatShading do?

    With flat shading each face uses its own normal, so edges between triangles stay visible.

Summary

  • A geometry is shape only: vertices, triangle indices, normals and UVs.
  • Three.js has generators for solids, plus Lathe, Extrude, Shape and Tube for custom shapes.
  • Segment counts trade smoothness against triangles; choose by on-screen size.
  • Dispose of geometries you replace; use center() and translate() to move pivots.

Next: Custom Shapes with BufferGeometry