Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 39 ยท Geometry and Materials

Lines, Points and Sprites

Draw lines, dashed curves, outlines, point clouds and camera-facing sprites in Three.js, and build a star field and a canvas-text label with live examples.

Not everything is a solid mesh. Charts and wireframes are lines. Star fields, dust and snow are clouds of points. Name tags and icons are flat pictures that always face the viewer. Three.js has dedicated object types for these: Line, Points and Sprite. They use the same geometry-plus-material idea but render differently and are much cheaper than meshes.

Lines

A line is a geometry whose vertices are connected in order. Use a Line material, not a mesh material.

Class Connects
Line Vertex 0 to 1 to 2 ... in one strip
LineLoop Same, and closes back to the first vertex
LineSegments Pairs: 0-1, 2-3, 4-5 ... (separate segments)
JavaScript
const points = [
  new THREE.Vector3(-1, 0, 0),
  new THREE.Vector3(0, 1, 0),
  new THREE.Vector3(1, 0, 0),
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, new THREE.LineBasicMaterial({ color: "#ffd166" }));
scene.add(line);

setFromPoints is a shortcut that fills the position attribute from an array of vectors. Curves give you points through curve.getPoints(count), which draws smooth paths easily.

WebGL draws lines exactly one pixel wide on almost all hardware, so linewidth in LineBasicMaterial has no effect. For thick lines use the add-on classes Line2, LineGeometry and LineMaterial from three/addons/lines/, which build the line out of screen-facing quads.

Dashed lines

LineDashedMaterial has dashSize and gapSize. The geometry needs per-vertex distances: call line.computeLineDistances() after building it.

Outlines with EdgesGeometry

EdgesGeometry extracts the edges of a mesh where faces meet at more than thresholdAngle degrees. Drawn as LineSegments, it makes an outline, great for blueprints and selection highlights.

Curves, dashes and outlines

Points

Points renders each vertex as a single square dot, or as a textured square. A geometry with 100,000 random positions is a cheap particle system: it is one draw call.

Key PointsMaterial options:

  • size: dot size. With sizeAttenuation: true (default) it is in world units and dots shrink with distance; with false it is in pixels.
  • color or vertexColors: true for per-point colors.
  • map and alphaMap: a texture on each dot, for round or soft particles.
  • transparent, depthWrite: false, blending: AdditiveBlending for glowing particles.

Because the points are squares by default, a soft round look needs a small texture. We generate one with a canvas, no image file required.

A rotating star field

Four thousand stars cost one draw call. The loop above only rotates the whole Points object; to animate individual points you either rewrite the position attribute (expensive for big counts) or use a vertex shader.

Sprites

A Sprite is a flat quad that always faces the camera, like a billboard. It uses a SpriteMaterial, which accepts a map and color. Sprites are ideal for labels, icons, lens flares and tree billboards in the distance. sizeAttenuation works as it does for points, and you scale a sprite with sprite.scale.set(width, height, 1).

For labels, draw text into a 2D canvas, wrap it in a CanvasTexture and give it to a sprite. That avoids loading fonts for 3D text.

Sprite labels from canvas text

Orbit the camera: the cubes turn but the labels keep facing you. Setting depthTest: false and a high renderOrder keeps them visible even behind other objects, which is usually what you want for annotations.

Choosing between them

  • A dot cloud of any size, same look: Points.
  • A few billboards with different textures: Sprite.
  • Thousands of individual textured objects, each with its own transform: InstancedMesh, covered in the performance chapter.
  • Thick lines or paths that need real width: Line2 add-on, or a TubeGeometry for 3D tubes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which class draws separate segments from pairs of vertices (0-1, 2-3, ...)?

    Line draws one strip, LineLoop closes it, LineSegments treats every two vertices as one separate segment.
  2. 2. Why does setting linewidth on LineBasicMaterial usually do nothing?

    Use the Line2 add-ons for wide lines.
  3. 3. What must you call for LineDashedMaterial to show dashes?

    The dash pattern uses a per-vertex distance attribute that computeLineDistances creates.
  4. 4. What is special about a Sprite?

    Sprites are billboards: a quad that rotates to face the camera automatically.

Summary

  • Line, LineLoop and LineSegments draw one-pixel lines; use EdgesGeometry for outlines and Line2 for thick lines.
  • Points renders thousands of dots in one draw call; use map, vertexColors and additive blending for glow.
  • Sprite is a camera-facing quad that is perfect for labels and icons, easy to make with canvas text.
  • Pick the lightest object type that does the job.

Next: Light Types