Hello, Nyx#

The smallest end-to-end Nyx scene: a gold PBR ball on a plane, lit entirely by an HDR environment map, rendered to a single PNG.

Rendered output of

What it shows#

  • Initializing Genesis with gs.init(). The Nyx SDK is booted automatically: importing NyxCameraOptions registers its start / stop pair with Genesis, so no explicit nps.startup() / nps.shutdown() call is needed.

  • Adding scene geometry with stock Genesis morphs (Plane, Mesh) and overriding the GLB’s embedded material with gs.surfaces.Gold().

  • Configuring an HDR EnvironmentMapAsset (long-lat layout, intensity multiplier) as the sole light source.

  • Adding a Nyx camera sensor via NyxCameraOptions — resolution, pose, FOV, samples-per-pixel, and FastPathTracer.

  • Building the scene, stepping the simulation once to trigger a render, then reading the frame back from the sensor with cam.read().rgb.

Source#

 1"""
 2Minimal Nyx example: a PBR ball on a plane lit by an environment map.
 3
 4Loads PBR_Ball.glb (GLTF embedded materials are forwarded to Nyx as-is) and
 5lights it purely with an .exr environment map.
 6
 7Usage:
 8    uv run python examples/01_hello_nyx.py
 9"""
10
11import os
12from PIL import Image
13
14import genesis as gs
15import gs_nyx.nyx_py_renderer as npr
16import gs_nyx.nyx_py_sdk as nps
17from gs_nyx_plugin.nyx_camera_options import NyxCameraOptions
18
19
20HERE        = os.path.dirname(__file__)
21PBR_BALL    = os.path.join(HERE, "assets", "PBR_Ball.glb")
22ENV_MAP     = os.path.join(HERE, "assets", "kloppenheim_07_puresky_4k.hdr")
23OUTPUT_PATH = os.path.join(HERE, "out", "01_hello_nyx.png")
24
25
26def main():
27    gs.init()
28
29    scene = gs.Scene(
30        sim_options=gs.options.SimOptions(dt=0.01),
31        show_viewer=False,
32    )
33
34    scene.add_entity(
35        morph=gs.morphs.Plane(plane_size=(10.0, 10.0)),
36    )
37
38    scene.add_entity(
39        morph=gs.morphs.Mesh(file=PBR_BALL, pos=(0.0, 0.0, 0.0)),
40        surface=gs.surfaces.Gold(),
41    )
42
43    # Describe how the env map is encoded
44    env_map            = nps.EnvironmentMapAsset()
45    env_map.texture    = ENV_MAP
46    env_map.layout     = nps.EEnvMapLayout.LongLat
47    env_map.multiplier = 8
48
49    # Describe the Nyx camera sensor
50    cam = scene.add_sensor(NyxCameraOptions(
51        res         = (1920, 1080),
52        pos         = (-1.0, 1.0, 1.2),
53        lookat      = (0.0, 0.0, 0.1),
54        fov         = 20.0,
55        spp         = 64,
56        render_mode = npr.ERenderMode.FastPathTracer,
57        env_maps    = (env_map,),
58    ))
59
60    # Build the scene with a single env
61    scene.build(n_envs=1)
62
63    # This simulation step makes the camera sensor render the frame
64    scene.step()
65
66    # Read back the sensor frame and save it
67    rgb = cam.read().rgb[0].cpu().numpy()
68    os.makedirs(os.path.dirname(OUTPUT_PATH), exist_ok=True)
69    Image.fromarray(rgb).save(OUTPUT_PATH)
70    print(f"Saved {OUTPUT_PATH}")
71
72
73if __name__ == "__main__":
74    main()

Run it:

uv run python examples/01_hello_nyx.py

The output PNG is written to examples/out/01_hello_nyx.png.