Skip to content
esc
Start typing to search the docs
Navigate Open

3D

Use a 3D view to explore point clouds, meshes, camera poses, and other 3D geometry. It is useful for checking scene reconstructions, robot motion, and the alignment of data from different sensors.

See the Spatial3DView reference for properties and examples.

Control the 3D camera

In a 3D view, the camera that you look through is called the eye. You can set the eye from code with the eye_controls parameter of Spatial3DView, which takes an EyeControls3D blueprint archetype (see eye_controls).

Set the eye position and look target

"""Set the eye position and look target of a 3D view from code."""

import rerun as rr
import rerun.blueprint as rrb

rr.init("rerun_example_spatial3d_eye_controls", spawn=True)

rr.log(
    "world/points",
    rr.Points3D([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], radii=0.05),
)

rr.send_blueprint(
    rrb.Spatial3DView(
        origin="/world",
        eye_controls=rrb.EyeControls3D(
            position=[4.0, -4.0, 3.0],
            look_target=[0.0, 0.0, 0.0],
            eye_up=[0.0, 0.0, 1.0],
        ),
    )
)

EyeControls3D has these fields:

FieldMeaning
kindrrb.Eye3DKind.Orbital (default) or rrb.Eye3DKind.FirstPerson.
positionThe position of the eye.
look_targetThe point that the eye looks at. For an orbital eye, this is also the point it orbits around.
eye_upThe up axis of the eye, in world space. Defaults to the up axis of the scene, or +Z if there is none.
speedTranslation speed when you move with the WASDQE keys.
tracking_entityAn entity that the eye follows. See below.
spin_speedSpin the eye around the up axis at this speed. Defaults to 0 (no spinning).

The scene up axis comes from ViewCoordinates. For example, log rr.ViewCoordinates.RIGHT_HAND_Z_UP as static data on the view's origin entity to make +Z the up axis.

The blueprint sets the eye when the Viewer receives it. After that, the user can move the eye freely. Send the blueprint again to move the eye back.

Orbital or first-person controls

  • Orbital: the eye rotates around look_target. Scroll zooms toward and away from it.
  • FirstPerson: the eye rotates around its own position, like in a first-person game. Use WASD and QE to move.
rrb.Spatial3DView(
    origin="/world",
    eye_controls=rrb.EyeControls3D(kind=rrb.Eye3DKind.FirstPerson, speed=20.0),
)

You can also switch between the two in the Viewer: select the view and change the eye kind in the selection panel.

Follow an entity

Set tracking_entity to make the eye follow an entity as it moves:

rrb.Spatial3DView(
    origin="/world",
    eye_controls=rrb.EyeControls3D(tracking_entity="/world/robot"),
)

If the tracked entity is a camera (an entity with a Pinhole), the eye takes over the pose of that camera, so you see the scene through it.

In the Viewer, you can start tracking an entity with Alt + double-click on it, or with "Set as eye tracked" in its context menu. Double-click an entity to focus on it, and double-click the background to reset the eye.

Limitations

There is currently no way to:

  • lock the eye, so that the user cannot move it,
  • limit how far the user can zoom in or out.

See missing features.

Control mesh appearance

This section explains how Mesh3D and Asset3D are shaded, and which settings you can change.

Lighting

The 3D view uses simple, fixed lighting: two directional lights and some ambient light. You cannot add lights, move them, or turn on shadows. There are no material properties, such as roughness, metallic surfaces, or specular highlights. See missing features.

Why does my mesh look flat or unlit?

Lighting needs vertex normals.

  • Mesh3D without vertex_normals is drawn unlit: every triangle gets its plain color, so the shape is hard to see. Pass vertex_normals to get shading.
  • Asset3D computes flat normals for meshes in the file that have none. To draw an asset unlit, give it all-zero vertex normals.

To compute smooth vertex normals for a Mesh3D yourself, you can use a library such as trimesh:

import trimesh

mesh = trimesh.load("model.obj", force="mesh")
rr.log(
    "mesh",
    rr.Mesh3D(
        vertex_positions=mesh.vertices,
        triangle_indices=mesh.faces,
        vertex_normals=mesh.vertex_normals,
    ),
)

Colors and textures

  • vertex_colors: one color per vertex.
  • albedo_factor: one color for the whole mesh. It is multiplied with the vertex colors and the texture.
  • albedo_texture together with vertex_texcoords: a texture image.

See the Mesh3D reference for an example of a textured mesh. For Asset3D, colors and textures come from the file, and you can tint the whole asset with albedo_factor.

Transparency

The only way to make a mesh transparent is the alpha channel of albedo_factor:

rr.log("mesh", rr.Mesh3D(vertex_positions=positions, triangle_indices=triangles, albedo_factor=[255, 255, 255, 128]))

The alpha channel of vertex_colors and of the texture is ignored.

Front and back faces

By default, both sides of each triangle are drawn. Set face_rendering to "Front" or "Back" to draw only one side. Front faces have their vertices in counter-clockwise order.

rr.Mesh3D(vertex_positions=positions, triangle_indices=triangles, face_rendering="Front")

Depth images, heightmaps, and voxels

Depth image to 3D point cloud

Log a DepthImage under an entity with a Pinhole camera. The 3D view then projects every pixel into 3D, so you get a point cloud without computing it yourself. Set meter to the number of depth units per meter (for example 1000 for depth in millimeters).

"""Create and log a depth image and pinhole camera."""

import numpy as np

import rerun as rr

depth_image = 65535 * np.ones((200, 300), dtype=np.uint16)
depth_image[50:150, 50:150] = 20000
depth_image[130:180, 100:280] = 45000

rr.init("rerun_example_depth_image_3d", spawn=True)

# If we log a pinhole camera model, the depth gets automatically
# back-projected to 3D
rr.log(
    "world/camera",
    rr.Pinhole(
        width=depth_image.shape[1],
        height=depth_image.shape[0],
        focal_length=200,
    ),
)

# Log the tensor.
rr.log(
    "world/camera/depth",
    rr.DepthImage(depth_image, meter=10_000.0, colormap="viridis"),
)

To place the camera in the world, log a Transform3D to the camera entity. The same depth image is also shown as an image in a 2D view. point_fill_ratio sets the size of the points, and colormap and depth_range set their colors.

Heightmaps and elevation grids

There is no built-in heightmap or surface archetype. Build a Mesh3D from the grid: one vertex per cell, and two triangles per grid square.

"""Draw a heightmap as a triangle mesh with one vertex per grid cell."""

import numpy as np

import rerun as rr

rr.init("rerun_example_spatial3d_heightmap", spawn=True)

rows, cols = 100, 120
cell_size = 0.1
y, x = np.mgrid[0:rows, 0:cols] * cell_size
height = 0.5 * np.sin(x) * np.cos(y)

positions = np.column_stack([x.ravel(), y.ravel(), height.ravel()])

index = np.arange(rows * cols).reshape(rows, cols)
top_left = index[:-1, :-1].ravel()
top_right = index[:-1, 1:].ravel()
bottom_left = index[1:, :-1].ravel()
bottom_right = index[1:, 1:].ravel()
triangles = np.concatenate([
    np.column_stack([top_left, bottom_left, top_right]),
    np.column_stack([top_right, bottom_left, bottom_right]),
])

rr.log(
    "terrain",
    rr.Mesh3D(vertex_positions=positions, triangle_indices=triangles),
)

The mesh has no normals, so it is drawn without shading. Pass vertex_normals to get lighting, and vertex_colors to color it by height. See Control mesh appearance.

For a quick look, you can instead log the grid as a Points3D with the same positions, or as a 2D Image or DepthImage with a colormap.

Voxels

For sparse voxel grids, such as occupancy maps, use VoxelGridMap. It takes integer voxel indices, a voxel size, and optional values with a colormap. VoxelGridMap is unstable: its data format may change in future releases.

"""Log a simple sparse voxel grid map."""

import numpy as np

import rerun as rr

voxel_indices = np.array(
    [
        [-1, 0, 0],
        [1, 0, 0],
        [1, 1, 0],
        [3, 0, 0],
        [3, 0, 1],
        [4, 0, 1],
    ],
    dtype=np.int32,
)
values = np.array([0.0, 0.2, 0.4, 0.6, 0.8, 1.0], dtype=np.float32)

rr.init("rerun_example_voxel_grid_map_simple", spawn=True)

rr.log(
    "world/voxels",
    rr.VoxelGridMap(
        voxel_indices,
        voxel_size=[0.25, 0.25, 0.25],
        values=values,
        value_range=[0.0, 1.0],
        colormap=rr.components.Colormap.Turbo,
        translation=[-0.5, -0.5, 0.0],
    ),
)

You can also draw voxels as Boxes3D with fill_mode="solid", one box per voxel. This works for a moderate number of voxels.

Dense volumes

For dense 3D scalar fields, such as CT or MRI scans, signed distance fields, or occupancy probabilities, use Volume3D. It is rendered with ray marching. Volume3D is unstable: its data format may change in future releases.

"""Log a small volume: a soft sphere sampled on a 32³ grid."""

import numpy as np

import rerun as rr

SIZE = 32
RADIUS = np.float32(14.0)

rr.init("rerun_example_volume3d_simple", spawn=True)

# Squared distance from the center of the grid, per voxel, in voxel units.
axis = np.arange(SIZE, dtype=np.float32) - np.float32(0.5 * (SIZE - 1))
z, y, x = np.meshgrid(axis, axis, axis, indexing="ij")
distance_sq = x * x + y * y + z * z

# A soft sphere: 1 at the center, falling off to 0 at `RADIUS`.
values = np.maximum(
    np.float32(0.0), np.float32(1.0) - distance_sq / (RADIUS * RADIUS)
)

# Dimensions are ordered `[z, y, x]`. Only `f16` values are supported for now.
rr.log(
    "volume",
    rr.Volume3D(values.astype(np.float16), voxel_size=[0.1, 0.1, 0.1]),
)

For 2D occupancy grids, for example from a robot's map, see GridMap.

Covariance ellipsoids in 3D

Use Ellipsoids3D. To draw a 3×3 covariance matrix, take its eigendecomposition:

  • the half sizes of the ellipsoid are k * sqrt(eigenvalues), where k is the number of standard deviations,
  • the rotation is the matrix of eigenvectors (one eigenvector per column).

Put the rotation and the mean in a Transform3D on the same entity:

"""Draw a 3D covariance matrix as an ellipsoid."""

import numpy as np

import rerun as rr

rr.init("rerun_example_spatial3d_covariance", spawn=True)

mean = np.array([1.0, 2.0, 0.5])
covariance = np.array([
    [0.40, 0.10, 0.00],
    [0.10, 0.20, 0.05],
    [0.00, 0.05, 0.10],
])

eigenvalues, eigenvectors = np.linalg.eigh(covariance)
k = 2.0  # Two standard deviations

rr.log(
    "estimate/covariance",
    rr.Transform3D(translation=mean, mat3x3=eigenvectors),
)
rr.log(
    "estimate/covariance",
    rr.Ellipsoids3D(half_sizes=[k * np.sqrt(eigenvalues)]),
)

To draw many ellipsoids in one entity, pass centers and one rotation per ellipsoid with quaternions instead. You can convert a rotation matrix to a quaternion with, for example, scipy.spatial.transform.Rotation.from_matrix(eigenvectors).as_quat() (which returns xyzw). If np.linalg.det(eigenvectors) is negative, flip the sign of one column first, so that the matrix is a rotation.

For other uncertainty visualizations, see 2D covariance ellipses and time series error bands.

Gaussian splats

GaussianSplats3D draws 3D Gaussians with a center, per-axis scales (standard deviations), a rotation, and a color with opacity. It is meant for 3D Gaussian Splatting (3DGS) reconstructions, but you can also use it to show many probability distributions at once. GaussianSplats3D is unstable: its data format may change in future releases.

3DGS .ply files are loaded as GaussianSplats3D when you open them in the Viewer, or log them with rr.log_file_from_path.

Text labels

For labels on points, boxes, arrows, and lines, see Text labels. The same label rules, visibility controls, and limitations apply in 2D and 3D views.

Keypoints and connections

Use an annotation context to connect and label joints in a 3D skeleton. See Keypoints and connections for the shared 2D and 3D setup.

Color a point cloud by height or intensity

Points3D has no colormap and no scalar-to-color input. To color points by a value (height, intensity, temperature, …), compute one RGB(A) color per point yourself and pass it as colors. For example, with a matplotlib colormap:

import matplotlib
import numpy as np
import rerun as rr

heights = positions[:, 2]
normalized = (heights - heights.min()) / max(np.ptp(heights), 1e-9)
colors = matplotlib.colormaps["viridis"](normalized)  # RGBA floats in 0-1

rr.log("points", rr.Points3D(positions, colors=colors))

To switch between several colorings without logging the points again, log each color set as its own component and use component mappings.

Show recent history in a 3D view

Pass a VisibleTimeRange to the time_ranges parameter of the view:

"""Log line strips over time and view a sliding window (e.g. trajectories)."""

import math

import rerun as rr
import rerun.blueprint as rrb


def point(t: float, phase: float) -> list[float]:
    # Sample a point on a helix.
    angle = 0.5 * t + phase
    return [math.cos(angle), math.sin(angle), 0.1 * t]


rr.init("rerun_example_line_strips3d_time_window", spawn=True)

# Configure the visible time range in the blueprint.
# You can also override this per entity.
rr.send_blueprint(
    rrb.Spatial3DView(
        origin="/",
        time_ranges=rrb.VisibleTimeRange(
            "time",
            start=rrb.TimeRangeBoundary.cursor_relative(seconds=-5.0),
            end=rrb.TimeRangeBoundary.cursor_relative(),
        ),
    )
)

# Log the line strip increments with timestamps.
for i in range(600):
    t0 = i / 30.0
    t1 = (i + 1) / 30.0

    rr.set_time("time", duration=t1)
    rr.log(
        "trails",
        rr.LineStrips3D(
            [
                [point(t0, 0.0), point(t1, 0.0)],
                [point(t0, math.pi), point(t1, math.pi)],
            ],
            colors=[[255, 120, 0], [0, 180, 255]],
            radii=0.02,
        ),
    )

Everything logged in the 5 seconds before the time cursor is now drawn at once. This is how you draw trails: log one short line segment or one point per time step, and let the time range accumulate them.