Skip to content

Latest commit

 

History

History
136 lines (98 loc) · 5.87 KB

File metadata and controls

136 lines (98 loc) · 5.87 KB

rt_nyx

Real-time Nyx path-traced preview for Genesis scenes.

rt_nyx attaches a Nyx camera to your scene, streams path-traced frames to an OpenCV Nyx Live window, and optionally records MP4 files with timestamped filenames under output_dir.

The simulation loop stays in your scene or environment file. This plugin only handles Nyx rendering, preview, and recording.

Requirements

  • genesis-world with Nyx (gs_nyx, gs_nyx_plugin)
  • OpenCV (opencv-python, included in genesis-world dependencies)
  • imageio

Quick start

import genesis as gs
import gs_nyx.nyx_py_sdk as nps

from tools.rt_nyx import RtNyx, RtNyxConfig

gs.init(backend=gs.cuda)

scene = gs.Scene(show_viewer=True)
# ... add entities ...

rt_nyx = RtNyx(
    scene,
    config=RtNyxConfig(
        res=(1920, 1080),
        preview_size=(960, 540),
        spp=32,
        record_fps=24,
        output_dir="out",
    ),
)

env_map = nps.EnvironmentMapAsset()
env_map.texture = "path/to/env.hdr"
env_map.layout = nps.EEnvMapLayout.LongLat

rt_nyx.add_camera(
    env_maps=(env_map,),
    lights=[
        {"type": "directional", "dir": (-0.3, 0.6, -1.0), "color": (1.0, 1.0, 1.0), "intensity": 5.0},
    ],
)

scene.build()
rt_nyx.setup()

try:
    while scene.viewer.is_alive():
        scene.step()
        if not rt_nyx.update():
            break
finally:
    rt_nyx.close()

Lifecycle

Step When Method
1 Before scene.build() RtNyx(scene, config=...)
2 Before scene.build() rt_nyx.add_camera(...)
3 After scene.build() rt_nyx.setup()
4 Each frame in your loop rt_nyx.update() (after scene.step())
5 On exit rt_nyx.close()

update() returns False when the session should end (viewer closed, preview window closed, or Q pressed).

API

RtNyx

Member Description
add_camera(**overrides) Register a Nyx camera sensor. Overrides merge with RtNyxConfig defaults.
setup() Create the preview window and resolve the output MP4 path.
update() Sync camera (if enabled), render, stream to Nyx Live, write frame to MP4.
close() Close writer and destroy OpenCV windows.
camera The underlying Nyx camera sensor.
output_path Resolved MP4 path after setup().
frame_count Number of frames written so far.

RtNyxConfig

Defined in config.py.

Field Default Description
res (1920, 1080) Nyx render resolution
preview_size None OpenCV window size (width, height)
preview_scale 0.5 Window scale relative to res (ignored when preview_size is set)
window_title "Nyx Live" OpenCV window title
pos (7, -5, 5.5) Default camera position
lookat (0, 8, 2.5) Default look-at point
fov 45.0 Field of view (degrees)
near / far 0.01 / 500.0 Clip planes
spp 32 Samples per pixel
denoise True Enable denoising
render_mode FastPathTracer Nyx render mode
env_maps () Environment map assets
lights [] Light definitions
follow_viewer True Mirror Genesis viewer camera each frame
record_to_file True Write MP4 while running
record_fps 24 MP4 frame rate
output_dir "out" Directory for auto-named recordings
output_path None Explicit MP4 path; auto YYYY-MM-DD_HH-MM-SS.mp4 when None

Pass any NyxCameraOptions field through add_camera(**overrides) to override config defaults per camera.

Controls

  • Genesis viewer: drag to adjust the camera (when follow_viewer=True, Nyx follows).
  • Nyx Live window: displays the path-traced result.
  • Q or close either window: end the session.

Notes

  • Path tracing is slow at high spp and resolution. Lower spp or res for smoother preview.
  • When record_to_file=True, frames are written at record_fps, not every simulation step.
  • Recordings are saved only if at least one frame was captured.

See also