主要内容

addPrimitive

R2026b

Create primitive collection in RoadRunner Viewer scene graph

Since R2026b

    Description

    pc = addPrimitive(rrViewer) creates a primitive collection in the scene graph of the specified RoadRunner Viewer object rrViewer and returns a PrimitiveCollection object, pc. The PrimitiveCollection object enables you to draw 3D primitives, such as points, lines, and triangles, in the RoadRunner Viewer scene graph. To organize your 3D primitives, you can create multiple PrimitiveCollection objects. You can use 3D primitives to highlight actor trajectories and road lanes, indicate sensor locations, or outline the locations of expected events during simulation.

    example

    Examples

    collapse all

    Use a PrimitiveCollection object to draw points, lines, and two triangles in the RoadRunner Viewer scene graph. This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Open RoadRunner Viewer and create a roadrunnerViewer object rrViewer.

    rrViewer = roadrunnerViewer;

    To create a PrimitiveCollection object, pc, use the addPrimitive function and specify the roadrunnerViewer object rrViewer.

    pc = addPrimitive(rrViewer);

    Draw a row of red points along the x-axis of the RoadRunner Viewer scene graph. Use the drawPoints function and specify the primitive collection pc, the point locations pts, the point color, and the point size.

    pts = [0 0 0; 1 0 0; 2 0 0; 3 0 0; 4 0 0];
    drawPoints(pc,pts,[1 0 0],10);

    Draw a green polyline in the RoadRunner Viewer scene graph. Use the drawLines function and specify the primitive collection pc, the polyline point locations linePts, the line color, and the line width.

    linePts = [0 0 1; 1 1 1; 2 0 1; 3 1 1; 4 0 1];
    drawLines(pc,linePts,[0 0.8 0],3);

    Draw two blue triangles that form a square in the RoadRunner Viewer scene graph. Use the drawTriangles function and specify the primitive collection pc, the triangle vertex locations triVerts, and the triangle color.

    triVerts = [-2 0 0; -1 0 0; -2 0 1; -1 0 0; -1 0 1; -2 0 1];
    drawTriangles(pc,triVerts,[0 0.4 1]);

    To update the scene graph and view the newly added primitives, use the drawnow function.

    drawnow(rrViewer)

    Input Arguments

    collapse all

    RoadRunner Viewer in which to create a primitive collection, specified as a roadrunnerViewer object.

    Output Arguments

    collapse all

    Primitive collection, returned as a PrimitiveCollection object. Use the PrimitiveCollection object to draw 3D primitives, such as points, lines, and triangles, in the RoadRunner Viewer scene graph.

    Version History

    Introduced in R2026b