Skip to content

Segments

Segments

Segments(
    positions: Transform | Buffer,
    line_caps: Transform | Buffer | LineCap,
    line_colors: Transform | Buffer | Color,
    line_widths: Transform | Buffer | float,
)

Segments are line segments between two vertices. They can be colored and styled (dash pattern). They possess a thickness but always face the viewer such that their apparent thickness is constant. Their end points (caps) can be styled following the SVG specification (butt, round or cap).

IN/OUT variables
// Rendering stage 1
in uniform vec4 viewport;                     // in("viewport")
in attribute [ vec2 | vec3 ] positions;       // in("positions")
in [ attribute | uniform ] int line_caps;     // in("fill_colors")
in [ attribute | uniform ] vec4 line_colors;  // in("line_colors")
in [ attribute | uniform ] float line_widths; // in("line_widths")

// Rendering stage 2
out attribute vec3 screen;                    // out("screen[positions]")
out attribute vec3 segments;                  // out("screen[segments]")

// Rendering stage 3
out attribute int line_caps;                  // out("line_caps")
out attribute vec4 line_colors;               // out("line_colors")
out attribute float line_widths;              // out("line_widths")
Example
1
2
3
4
5
positions = core.Buffer(2*3, np.dtype(np.float32))
markers = visual.Segments(positions,
                          line_caps=core.LineCap.round,
                          line_colors=(0,0,0,0),
                          line_widths=0.0)
1. COMMAND
     - METHOD: "core.Buffer" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2025-03-18T15:02:34.095178 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - COUNT: 6 (int)
     - DTYPE: float32 (dtype)
     - DATA: None (memoryview | bytes)

2. COMMAND
     - METHOD: "visual.Segments" (str)
     - COMMAND_ID: 2 (int)
     - TIMESTAMP: 2025-03-18T15:02:34.095279 (datetime)
   PARAMETERS
     - OBJECT_ID: 2 (int)
     - POSITIONS_ID: 1 (Transform | Buffer)
     - LINE_CAPS: 2 (Transform | Buffer | LineCap)
     - LINE_COLORS: Color(r=0, g=0, b=0, a=0) (converted) (Transform | Buffer | Color)
     - LINE_WIDTHS: 0.0 (Transform | Buffer | float)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Buffer",
      "id": 1,
      "timestamp": 1742306554.095178,
      "parameters": {
        "id": 1,
        "count": 6,
        "dtype": "float32",
        "data": null
      }
    },
    {
      "method": "visual.Segments",
      "id": 2,
      "timestamp": 1742306554.095279,
      "parameters": {
        "id": 2,
        "positions(id)": 1,
        "line_caps": 2,
        "line_colors": [
          0,
          0,
          0,
          0
        ],
        "line_widths": 0.0
      }
    }
  ]
}

Create a visual of n segments at given positions with given line_colors, line_widths and line_caps.

Parameters:

Name Type Description Default
positions Transform | Buffer

Segments positions (2,vec3)

required
line_caps Transform | Buffer | LineCap

Segments end caps (int)

required
line_colors Transform | Buffer | Color

Segments line colors (vec4)

required
line_widths Transform | Buffer | Measure

Segments line width (float)

required

render

render(
    viewport: Viewport,
    model: Matrix = None,
    view: Matrix = None,
    proj: Matrix = None,
)

Render the visual on viewport using the given model, view, proj matrices

Parameters:

Name Type Description Default
viewport Viewport

Viewport where to render the visual

required
model Matrix

Model matrix to use for rendering

None
view Matrix

View matrix to use for rendering

None
proj Matrix

Projection matrix to use for rendering

None