Recursive AI

Get replay entity screen coordinates

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.

Use run.oppr from the zip. Headless mode needs a graphics renderer.

Terminal
dotnet tool install -g RecursiveAI.OneScope.Tool

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

Terminal
onescope open run.oppr --headless \
  --size 640x480 --run 'seek {"step":20}' \
  --run capture_frame \
  --run 'project {"view":0,
    "entity":"72057598332895233"}'

The example is the full program below: unzip it and dotnet run.

The zip contains run.oppr and a C# program that runs the same operations, so you can use either the command above or dotnet run.

The ID in the command is the ball’s; list entities to find IDs in your own recording.

The last result gives the ball’s label position: "x":233,"y":173.72,"onScreen":true. Use x and y only for placement inside the requested view when onScreen is true.

The full program

The download opens the OnePhysics recording and projects the ball’s ID, 72057598332895233, at step 20. It moves the camera to put the ball outside view 0 and projects the same ID again. Each capture lays out the shell with the camera and window size used for that query.

C#
using System.Diagnostics;
using System.Text.Json;
 
string toolDir = Path.GetFullPath("obj/onescope-tool");
string tool = Path.Combine(toolDir,
    OperatingSystem.IsWindows() ? "onescope.exe" : "onescope");
if (!File.Exists(tool))
    Run("dotnet", "tool", "install", "RecursiveAI.OneScope.Tool",
        "--version", "1.0.0", "--tool-path", toolDir);
 
var results = Open(
    """seek {"step":20}""",
    "capture_frame",
    """project {"view":0,"entity":"72057598332895233"}""",
    """view {"index":0,"target":[30,0,0]}""",
    "capture_frame",
    """project {"view":0,"entity":"72057598332895233"}""");
 
foreach (var point in new[] { results[3], results[^1] })
{
    if (point.GetProperty("onScreen").GetBoolean())
        Console.WriteLine($"Place label at ({point.GetProperty("x")}, {point.GetProperty("y")})");
    else
        Console.WriteLine("Skip label: outside view");
}
 
JsonElement[] Open(params string[] operations)
{
    var arguments = new List<string>
    {
        "open", "run.oppr", "--headless", "--size", "640x480"
    };
    foreach (string operation in operations)
        arguments.AddRange(["--run", operation]);
    return Run(tool, arguments.ToArray())
        .Split('\n', StringSplitOptions.RemoveEmptyEntries)
        .Select(line => JsonDocument.Parse(line).RootElement.Clone())
        .ToArray();
}
 
static string Run(string command, params string[] arguments)
{
    var start = new ProcessStartInfo(command)
    {
        RedirectStandardOutput = true,
        RedirectStandardError = true
    };
    foreach (string argument in arguments)
        start.ArgumentList.Add(argument);
    using var process = Process.Start(start)!;
    var output = process.StandardOutput.ReadToEndAsync();
    var errors = process.StandardError.ReadToEndAsync();
    process.WaitForExit();
    if (process.ExitCode != 0)
        throw new InvalidOperationException(output.Result + errors.Result);
    return output.Result;
}
Text
Place label at (233, 173.72)
Skip label: outside view

If nothing is drawn for that ID at the current step with the view’s enabled overlays, project returns not_found, not onScreen:false.

Variations

Project through the first view showing a source. Instead of passing a view, replace the final --run argument with this one. Here source 0’s first view is view 0, so the coordinates are unchanged.

Terminal
  --run 'project {"source":0,
    "entity":"72057598332895233"}'

The short answer

Pass project an entity ID and a view number after laying out the shell. It returns world, the anchor in simulation coordinates, plus x and y, the anchor in window pixels. Place a screen-space annotation when onScreen is true. This is the opposite direction from pick: projection starts with a known object, not a pixel.

How do I convert a world position to a screen position?

In this command you supply an ID, not a free-standing world coordinate. OneScope takes an anchor from the first matching non-label drawing for that entity in the view. For the sample ball that’s its center, but for a triangle it’s the triangle’s centroid. To find the ID in your file, list the replay entities. Pass the digits as a string if your JSON client can’t hold an unsigned 64-bit ID exactly.

The camera determines where that anchor lands. Project again after moving the camera, resizing the window, or seeking to another step. In an offscreen run, capture_frame lays out the whole shell. The result is in that shell’s pixel coordinates, not the coordinates of a cropped image or a separate export of just one view. If you draw a label on a crop, subtract the crop’s origin before placing it.

How can I tell whether the projected point is on screen?

onScreen tests whether the anchor falls within the chosen view’s rectangle. A successful response can still have onScreen:false: the program moves the camera, and the anchor lands outside view 0 although the entity still contributes a drawing. Don’t use this flag as an occlusion test or as a test of whether any part of a large object is visible. It checks the anchor, not the whole shape or what’s in front of it.

Treat an operation error separately from an offscreen point. A wrong source, an ID that isn’t drawn yet at the chosen step, or an overlay that hides its drawing can prevent a projection entirely. If a view hasn’t been laid out, capture a full-shell frame or let the desktop window render before asking for the coordinates.

All onescope recipes