Drawing objects#

This section explains how to render and interact with objects in HelloTriangle.

Which objects can be rendered?#

You can render both Mesh and Coords objects. For meshes, all supported element types can be rendered (see Element types).

Objects are drawn using the draw() function:

draw(mymesh, name="mymesh", color="red")
draw(mycoords, name="mycoords", color="black")

Note

If you do not specify a name, a random one will be assigned automatically. The name will appear in the Visualization Settings panel of the GUI.

Your script may contain multiple draw() statements — all corresponding objects will appear in the 3D viewer.

Choosing colors#

You can specify object colors in several ways:

  • Hexadecimal (string): "#990000"

  • Named colors (string): "skyblue" (any of the 140 X11 color names)

  • RGB values (string): "rgb(255, 0, 0)" or "rgb(100%, 0%, 0%)"

  • HSL values (string): "hsl(0, 100%, 50%)"

Advanced styling with the style parameter#

For more control over mesh appearance, use the style parameter with a dictionary. This allows you to set root-level properties that apply to all representations (faces, edges, points), as well as representation-specific overrides.

Basic style dict example:

# Root-level properties apply to all representations
draw(mymesh, name="mesh", style={
    "color": "#ff0000",
    "opacity": 0.8
})

Representation-specific styling:

For 2D (surface) and 3D (volumetric) meshes, you can separately control faces, edges (lines), and vertices (points):

# Different colors for faces, edges, and points
draw(mymesh, name="mesh", style={
    "faces": {
        "color": "#00ff00",
        "opacity": 0.9,
        "metalness": 0.5,
        "roughness": 0.5
    },
    "lines": {
        "color": "#000000",
        "width": 2.0,
        "opacity": 1.0
    },
    "points": {
        "color": "#ff0000",
        "size": 3.0,
        "opacity": 1.0
    }
})

Available style properties:

  • Root level (applies to all representations):

    • color: Color string (any format above)

    • opacity: Float from 0.0 (transparent) to 1.0 (opaque)

  • Faces (faces dict):

    • color: Face color

    • opacity: Face transparency

    • metalness: Float from 0.0 (non-metallic) to 1.0 (metallic)

    • roughness: Float from 0.0 (smooth) to 1.0 (rough)

    • visible: Boolean to show/hide faces

    • transparencyMode: String, one of "default", "simple", or "dithered"

  • Lines/Edges (lines dict):

    • color: Line color

    • opacity: Line transparency

    • width: Line width (float)

    • visible: Boolean to show/hide edges

    • transparencyMode: String, "default" or "simple"

  • Points/Vertices (points dict):

    • color: Point color

    • opacity: Point transparency

    • size: Point size (float)

    • visible: Boolean to show/hide points

    • transparencyMode: String, "default" or "simple"

Note

Transparency modes:

  • "default": Standard transparency with depth writing (best for faces)

  • "simple": Disables depth writing when transparent (best for edges/points)

  • "dithered": Alpha hashing for order-independent transparency (faces only)

Combining root and representation styles:

Root-level properties serve as defaults. Representation-specific values override them:

# Root color applies to all, but faces get a different opacity
draw(mymesh, name="mesh", style={
    "color": "#2BB786",  # Applied to faces, lines, and points
    "faces": {
        "opacity": 0.7   # Only faces are semi-transparent
    }
})

GUI options#

After running a script with one or more draw() calls, all rendered objects will appear in the Visualization Settings panel on the right-hand side of the screen. From this panel you can:

  • Interactively change object colors

  • Adjust transparency

  • For 2D (surface) and 3D (volumetric) meshes, separately control the appearance of faces, edges, and vertices

  • Copy the current style as Python code to paste into your script

Note

When you re-run a script, any manual changes made in the visualization settings panel will be reset. To preserve your styling, copy the style from the visualization panel and add it to your script using the style parameter.

Scene-level settings#

Use the set_scene() function to configure scene-level properties such as background color and camera type. These settings apply to the entire 3D viewer, not individual objects.

# Set background color and camera type
set_scene(
    background="#f0f0f0",
    camera={"type": "orthographic"}
)

# Draw your meshes
draw(mymesh, name="mesh", color="red")

Available scene parameters:

  • background: Background color (any color format: hex, named color, rgb, hsl)

  • camera: Dictionary with a "type" key:

    • {"type": "perspective"} - Perspective camera (default)

    • {"type": "orthographic"} - Orthographic camera (no perspective distortion)

Note

You can call set_scene() at any point in your script, but it’s typically placed at the beginning. The settings will be preserved in the visualization panel, where you can also adjust them interactively.