Skip to content

NgtsSegments

Credits: Segments from Drei

NgtsSegments efficiently renders multiple line segments using a single draw call via Line2 from three-stdlib. This is ideal for drawing many independent line segments with consistent performance.

Usage

import { NgtsSegments, NgtsSegment } from 'angular-three-soba/performances';
<ngts-segments [options]="{ lineWidth: 2, limit: 100 }">
<ngts-segment [start]="[0, 0, 0]" [end]="[1, 1, 1]" [color]="'red'" />
<ngts-segment [start]="[1, 1, 1]" [end]="[2, 0, 0]" [color]="'blue'" />
</ngts-segments>

NgtsSegment

A single line segment within NgtsSegments. Each segment has a start point, end point, and optional color.

Drawing a Graph

@Component({
template: `
<ngts-segments [options]="{ lineWidth: 1.5 }">
@for (edge of edges(); track $index) {
<ngts-segment
[start]="edge.from"
[end]="edge.to"
[color]="edge.color"
/>
}
</ngts-segments>
`
})
export class GraphVisualization {
edges = signal<Edge[]>([]);
}

Connecting Objects

<ngts-segments [options]="{ lineWidth: 2 }">
@for (connection of connections(); track connection.id) {
<ngts-segment
[start]="connection.source.position"
[end]="connection.target.position"
[color]="connection.active ? 'lime' : 'gray'"
/>
}
</ngts-segments>

Performance Notes

  • All segments share the same material properties (lineWidth, etc.)
  • For independent lines with different widths, use NgtsLine instead
  • Set limit based on your expected maximum number of segments

Inputs

name type description required
start NgtVector3 Starting point [x, y, z] yes
end NgtVector3 Ending point [x, y, z] yes
color THREE.ColorRepresentation Segment color no

Options

Properties

name type description
limit number Maximum number of segments, default to 1000
lineWidth number Width of the line segments, default to 1.0