Engine API Reference - v2.22.0-beta.0
    Preparing search index...

    Class WideLineRenderer

    Renders a collection of WideLine objects using a single instanced draw call per camera/layer pass. Lines can use different widths, colors, caps, joins and dash patterns while remaining in the same batch, as these properties are stored in per-segment instance data.

    Each WideLine describes a connected polyline in world space. Its width can vary per point and is interpreted as screen pixels or world units according to WideLineRenderer#widthUnits. A line can belong to only one WideLineRenderer at a time. Use WideLineRenderer#add and WideLineRenderer#remove to transfer ownership without changing the line data.

    The following example creates a three-point line with a color gradient, variable width and rounded ends and joins:

    const renderer = new WideLineRenderer(app);
    const line = new WideLine();

    line.set(
    new Float32Array([
    -2, 0, 0,
    0, 1, 0,
    2, 0, 0
    ]),
    new Float32Array([
    1, 0, 0,
    1, 1, 0,
    0, 1, 1
    ]),
    new Float32Array([4, 12, 4])
    );
    line.cap = LINECAP_ROUND;
    line.join = LINEJOIN_ROUND;
    renderer.add(line);

    // Release GPU resources and detach all lines when no longer needed.
    app.on('destroy', () => renderer.destroy());

    Point data can be updated using WideLine#setPositions, WideLine#setColors and WideLine#setWidths. These methods preserve the point count and reuse the line's existing storage. Use WideLine#set when the point count needs to change.

    Each line segment is rendered as one GPU instance. All segments owned by this renderer are submitted together, so adding more WideLine objects does not add draw calls. A renderer with visible segments issues one draw call for each camera that renders its layer. Multiple renderers therefore provide useful update isolation, but each adds another draw call per camera/layer pass.

    Changing any owned line marks the renderer dirty. Before the next render, instance data for all of its lines is rebuilt and uploaded. For mixed workloads, place lines that rarely change in one renderer and frequently updated lines in another. There is no static or dynamic mode; the separation is achieved using two renderer instances. This prevents dynamic updates from repeatedly rebuilding the static segment data:

    const staticLines = new WideLineRenderer(app);
    const dynamicLines = new WideLineRenderer(app);

    staticLines.add(roadNetwork); // Built and uploaded once.
    dynamicLines.add(projectilePath); // Updated frequently.

    Buffer WideLineRenderer#capacity is measured in segments and grows automatically as needed. Setting it in advance can avoid GPU buffer reallocations when the expected maximum segment count is known. WideLineRenderer#clear removes the lines but retains this capacity for reuse.

    See the following examples for interactive styling and update demonstrations:

    Index
    • get capacity(): number

      Gets the allocated instance capacity, measured in generated line segments.

      Returns number

    • set capacity(value: number): void

      Allocated instance capacity, measured in generated line segments. Defaults to zero and grows automatically when required. Setting a smaller value releases unused capacity, but the result is clamped to the number of segments currently required by the owned lines.

      Parameters

      • value: number

      Returns void

    • get depthTest(): boolean

      Gets whether lines are tested against the depth buffer.

      Returns boolean

    • set depthTest(value: boolean): void

      Whether lines are tested against the depth buffer. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get depthWrite(): boolean

      Gets whether lines write to the depth buffer.

      Returns boolean

    • set depthWrite(value: boolean): void

      Whether lines write to the depth buffer. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get enabled(): boolean

      Gets whether this renderer is visible.

      Returns boolean

    • set enabled(value: boolean): void

      Whether this renderer is visible. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get layer(): Layer

      Gets the layer containing the renderer's mesh instance.

      Returns Layer

    • set layer(value: Layer): void

      The layer containing the renderer's mesh instance. Defaults to the Immediate layer.

      Parameters

      Returns void

    • get widthUnits(): number

      Gets the units used to interpret line widths.

      Returns number

    • set widthUnits(value: number): void

      Units used to interpret line widths. Can be LINEWIDTH_SCREEN for screen pixels or LINEWIDTH_WORLD for world units. World-unit lines are camera-facing ribbons, not three-dimensional tubes. Defaults to LINEWIDTH_SCREEN.

      Parameters

      • value: number

      Returns void

    • Adds a line to this renderer. A line can belong to only one renderer at a time.

      Parameters

      Returns void

    • Removes all lines. Allocated instance capacity is retained for reuse.

      Returns void

    • Releases all renderer-owned resources. Lines previously owned by this renderer remain usable and can be added to another renderer.

      Returns void

    • Removes a line from this renderer without modifying its point data or style.

      Parameters

      Returns boolean

      True if the line was owned by this renderer and was removed.