Shapes

Shape defines the 3D graphics-related item that is directly transformable. It is the base class for all “geometric primitives”, which encodes several per-primitive graphics-related properties.

Line

Line is the simplest shape that represents a straight line. It has two points, color, and thickness.

Code Result

    sc.Line([-0.5,-0.5,0], [0.5, 0.5, 0], color=cl.green, thickness=5)

Curve

Curve is a shape drawn with multiple lines which has a bent or turns in it. There are two supported cuve types: linear and cubic. sc.Curve is default to draw cubic curve and can be switched to linear with curve_type=sc.Curve.CurveType.LINEAR. tessellation controls the smoothness of the curve. The higher the value is, the smoother the curve is, with the higher computational cost. The curve also has positions, colors, thicknesses which are all array typed properties, which means per vertex property is supported. This feature needs further development with ImGui support.

Code Result

with scene_view.scene:
    # linear curve
    with sc.Transform(transform=sc.Matrix44.get_translation_matrix(-4, 0, 0)):
        sc.Curve(
            [[0.5, -0.7, 0], [0.1, 0.6, 0], [2.0, 0.6, 0], [3.5, -0.7, 0]],
            thicknesses=[1.0],
            colors=[cl.red],
            curve_type=sc.Curve.CurveType.LINEAR,
        )
    # corresponding cubic curve
    with sc.Transform(transform=sc.Matrix44.get_translation_matrix(0, 0, 0)):
        sc.Curve(
            [[0.5, -0.7, 0], [0.1, 0.6, 0], [2.0, 0.6, 0], [3.5, -0.7, 0]],
            thicknesses=[3.0],
            colors=[cl.blue],
            tessellation=9,
        )

Rectangle

Rectangle is a shape with four sides and four corners. The corners are all right angles.

Code Result

    sc.Rectangle(color=cl.green)

It’s also possible to draw Rectangle with lines with enabling property wireframe:

Code Result

    sc.Rectangle(2, 1, thickness=5, wireframe=True)

Arc

Two radii of a circle and the arc between them. It also can be a wireframe.

Code Result

    sc.Arc(1, begin=0, end=1, thickness=5, wireframe=True)

Image

A rectangle with an image on it. It can read raster and vector graphics format and supports http:// and omniverse:// paths.

Code Result

    filename = f"{EXT_PATH}/data/main_ov_logo_square.png"
    sc.Image(filename)

Points

The list of points in 3d space. Points may have different sizes and different colors.

Code Result

    point_count = 36
    points = []
    sizes = []
    colors = []
    for i in range(point_count):
        weight = i / point_count
        angle = 2.0 * math.pi * weight
        points.append(
            [math.cos(angle), math.sin(angle), 0]
        )
        colors.append([weight, 1 - weight, 1, 1])
        sizes.append(6 * (weight + 1.0 / point_count))
    sc.Points(points, colors=colors, sizes=sizes)

PolygonMesh

Encodes a mesh. Meshes are defined as points connected to edges and faces. Each face is defined by a list of face vertices vertex_indices using indices into the point positions array. vertex_counts provides the number of points at each face. This is the minimal requirement to construct the mesh.

Code Result

    point_count = 36

    # Form the mesh data
    points = []
    vertex_indices = []
    sizes = []
    colors = []
    for i in range(point_count):
        weight = i / point_count
        angle = 2.0 * math.pi * weight
        vertex_indices.append(i)
        points.append(
            [
                math.cos(angle) * weight,
                -math.sin(angle) * weight,
                0
            ]
        )
        colors.append([weight, 1 - weight, 1, 1])
        sizes.append(6 * (weight + 1.0 / point_count))

    # Draw the mesh
    sc.PolygonMesh(
        points, colors, [point_count], vertex_indices
    )

Label

Defines a standard label for user interface items. The text size is always in the screen space and oriented to the camera. It supports omni.ui alignment.

Code Result

    sc.Label(
        "NVIDIA Omniverse",
        alignment=ui.Alignment.CENTER,
        color=cl("#76b900"),
        size=50
    )