Recursive AI

Draw replay wireframe overlays in C#

OneScope is a free, open-source viewer for simulation recordings, with a desktop window or command-line control, from Recursive AI. MIT or Apache-2.0.

Show a box’s bounds without filling it.

Terminal
dotnet add package RecursiveAI.OneScope.Sdk

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneScope.Sdk;
using Rot = System.Numerics.Quaternion;
var frame = new DrawList();
var style = new DrawStyle(Color32.White,
    Flags: DrawFlags.Wireframe);
frame.Box(new(0), new(1), Rot.Identity, style);
Console.WriteLine(frame.Items[0].Flags);

Unzip the example, then dotnet run.

Text
Wireframe

The console example submits a draw item and prints its flag; it doesn’t open a replay window. In a OneScope module, add the box to the DrawList passed to IScopeWorld.Draw.

To see the outline in the replay viewer, write and load a OneScope replay module.

The full program

The example submits a solid box and a slightly larger wireframe box at the same position. It takes no input files. The sizes passed to Box are half extents, so Vector3.One gives a box two units wide along each axis.

C#
using System.Numerics;
using OneScope.Sdk;
 
const int boundsOverlay = 1;
var overlay = new OverlayInfo(boundsOverlay, "Bounds", DefaultOn: true);
var frame = new DrawList();
 
// In a replay module, use the current frame's position and rotation.
var center = new Vector3(3, 0, 2);
var rotation = Quaternion.Identity;
var body = new DrawStyle(Color32.White);
var bounds = new DrawStyle(new Color32(255, 190, 0, 255), Overlay: overlay.Id,
    Flags: DrawFlags.Wireframe);
 
frame.Box(center, new Vector3(0.75f), rotation, body);
frame.Box(center, Vector3.One, rotation, bounds);
 
Console.WriteLine($"{overlay.Name} overlay: default on = {overlay.DefaultOn}");
foreach (var item in frame.Items)
    Console.WriteLine($"{item.Kind}: overlay {item.Overlay}, {item.Flags}");
Text
Bounds overlay: default on = True
Box: overlay 0, None
Box: overlay 1, Wireframe

In your module, include the OverlayInfo in SourceInfo.Overlays to give the bounds their own toggle. If the overlay is off in the view, the shell hides items with that overlay ID even though they’re in the draw list.

Variations

To keep the bounds visible even when a solid object is in front of them in 3D, replace the bounds declaration in the full program with this one:

C#
var bounds = new DrawStyle(new Color32(255, 190, 0, 255),
    Overlay: overlay.Id,
    Flags: DrawFlags.Wireframe | DrawFlags.OnTop);

The second box now prints:

Text
Box: overlay 1, Wireframe, OnTop

The short answer

Set DrawStyle.Flags to DrawFlags.Wireframe on the geometry you want to show as edges. Give those items their own overlay ID so you can turn them off without hiding the solid scene. Add DrawFlags.OnTop if the edges should remain visible through other objects in the 3D view.

How do you draw a wireframe over a solid model?

Submit two draw items: one for the solid model and one for the geometry you want to outline. They don’t have to be the same shape. A wireframe box works well when you want to see the volume around a body without seeing every triangle of its mesh. To inspect how a mesh is triangulated instead, submit the mesh with DrawFlags.Wireframe. The 3D renderer’s mesh path draws all three edges of each triangle, so a face split into two triangles also shows the diagonal.

Build the overlay from the position and rotation of the frame you’re viewing, not from the newest state of the simulation. The viewer clears and refills the draw list each frame, so when you seek backward the outline follows the pose at that step. To keep the body pickable, set its EntityId on the solid item. The picker skips wireframe boxes rather than testing their edges.

How do you draw debug lines on top of 3D geometry?

With Wireframe alone, another object can hide the edges behind it. That’s useful when you’re checking where the box sits relative to a wall. Combine Wireframe and OnTop when you need to trace the full outline even behind the wall. In the 3D renderer, OnTop makes those debug lines ignore depth. Changing Layer is not the same thing: layer sets draw order, not depth. Keep OnTop for the diagnostic shapes that need it; otherwise the edges can make a hidden body look like it’s in front of the wall.

All onescope recipes