Capítulo 569 de 859

Chapter 569: LineSegments2

Core Idea

A series of lines drawn between pairs of vertices.

This adds functionality beyond LineSegments, like arbitrary line width and changing width to be in world units. Line2 extends this object, forming a polyline instead of individual segments.

This module can only be used with WebGLRenderer. When using WebGPURenderer, import the class from lines/webgpu/LineSegments2.js.

Key Concepts

  • isLineSegments2 : boolean (readonly): This flag can be used for type testing.

Code Examples

const geometry = new LineSegmentsGeometry();
geometry.setPositions( positions );
geometry.setColors( colors );
const material = new LineMaterial( { linewidth: 5, vertexColors: true } };
const lineSegments = new LineSegments2( geometry, material );
scene.add( lineSegments );
  • What it demonstrates: Typical usage of LineSegments2.

Reference Tables

Constructor

Signature
new LineSegments2( geometry : LineSegmentsGeometry, material : LineMaterial )

Properties

PropertyDescription
.isLineSegments2 : boolean (readonly)This flag can be used for type testing.

Methods

MethodDescription
.computeLineDistances() : LineSegments2Computes an array of distance values which are necessary for rendering dashed lines. For each vertex in the geometry, the method calculates the cumulative length from the current point to the very be…
.raycast( raycaster : Raycaster, intersects : Array.<Object> )Computes intersection points between a casted ray and this instance.

Key Takeaways

  1. LineSegments2 extends: EventDispatcher → Object3D → Mesh
  2. Most relevant properties: isLineSegments2.
  3. Key methods: computeLineDistances, raycast.

Connects To