motrixsim.render#

Exceptions:

InvalidArgumentError

Raise when the given arguments are invalid

InvalidFileError

Raise when a file to be loaded is invalid

OtherRenderError

Other render errors

RenderClosedError

Raise when the render app is closed

RenderError

Base class for all render errors

Classes:

CaptureTask

Color

A color in RGBA format, where each component is a float in the range [0.0, 1.0].

Image

Input

The Input object represents the input events of the render app.

Layout([left, right, top, bottom, width, height])

Layout configuration for camera viewport widgets.

RenderApp([log_level, headless, fps])

The RenderApp class is responsible for rendering the simulation scene.

RenderCamera

RenderGizmos

Gizmos module for rendering simple shapes in immediate mode.

RenderOpt

The RenderOpt object represents the options of the render app.

RenderSettings(simplify_render_mesh, ...)

The global render settings for render app.

RenderUI

The RenderUI object represents the user interface of the render app.

RenderWidgets

Widgets module for creating UI widgets in the render window.

SystemCamera

exception motrixsim.render.InvalidArgumentError#

基类:RenderError

Raise when the given arguments are invalid

exception motrixsim.render.InvalidFileError#

基类:RenderError

Raise when a file to be loaded is invalid

exception motrixsim.render.OtherRenderError#

基类:RenderError

Other render errors

exception motrixsim.render.RenderClosedError#

基类:RenderError

Raise when the render app is closed

exception motrixsim.render.RenderError#

基类:Exception

Base class for all render errors

class motrixsim.render.CaptureTask#

基类:object

Methods:

take_image()

Try take the image from the capture task.

Attributes:

state

The state of the capture task.

take_image()#

Try take the image from the capture task.

返回:

The captured image. - If the capture is successful, it will return the image and close the task. - Otherwise, it will return None and the state will remain unchanged.

返回类型:

Option[Image]

抛出:

PyRuntimeError -- If the task is closed or some internal error happend.

state#

The state of the capture task.

  • pending if the capture is processing.

  • done if the capture was completed. In this status, you can retrieve the captured result.

  • closed if the result has been received or the task has been dropped by remote.

Type:

str

class motrixsim.render.Color#

基类:object

A color in RGBA format, where each component is a float in the range [0.0, 1.0].

Methods:

rgb(r, g, b)

Create a color with red, green, blue.

white()

Attributes:

a

The alpha component of the color, representing transparency.

b

The blue component of the color.

g

The green component of the color.

r

The red component of the color.

static rgb(r, g, b)#

Create a color with red, green, blue. Each value should be in the range [0.0, 1.0].

参数:
  • r (float) -- Red component.

  • g (float) -- Green component.

  • b (float) -- Blue component.

返回:

The created color.

返回类型:

Color

static white()#
a#

The alpha component of the color, representing transparency.

Type:

float

b#

The blue component of the color.

Type:

float

g#

The green component of the color.

Type:

float

r#

The red component of the color.

Type:

float

class motrixsim.render.Image#

基类:object

Methods:

save_to_disk(path)

Save the image to disk with the specified path.

Attributes:

pixels

Get the pixels of the image as a 3D numpy array.

save_to_disk(path)#

Save the image to disk with the specified path.

抛出:

PyIOError -- If saving the image fails.

pixels#

Get the pixels of the image as a 3D numpy array. The shape is (height, width, 3).

Type:

NDArray[byte]

class motrixsim.render.Input#

基类:object

The Input object represents the input events of the render app.

This class provides access to the input events of the render app. It allows you to check if a key or mouse button is pressed, and get the mouse ray.

Methods:

is_ctrl_clicked(ctrl_id)

Check whether a control with the given ID is clicked.

is_key_just_pressed(key)

Check if a key is just pressed.

is_key_pressed(key)

Check if a key is just pressed.

is_mouse_just_pressed(mouse)

Check if a mouse button is just pressed.

mouse_ray()

Returns a ray from camera to mouse click position.

is_ctrl_clicked(ctrl_id)#

Check whether a control with the given ID is clicked.

参数:

ctrl_id (int) -- The ID of the control.

返回:

True if the control is clicked, False otherwise.

返回类型:

bool

is_key_just_pressed(key)#

Check if a key is just pressed. Check by inputting the lowercase form of the keyboard keys, such as 'a' 's' 'w' 'd' 'f5' and 'esc'. The details can be found in the "Supported Keyboard Keys Table" under the "IO Input Events" section of the 🎨 渲染器(RenderApp).

参数:

key (str) -- The key to check.

返回:

True if the key is pressed, False otherwise.

返回类型:

bool

is_key_pressed(key)#

Check if a key is just pressed. Check by inputting the lowercase form of the keyboard keys, such as 'a' 's' 'w' 'd' 'f5' and 'esc'. The details can be found in the "Supported Keyboard Keys Table" under the "IO Input Events" section of the 🎨 渲染器(RenderApp).

参数:

key (str) -- The key to check.

返回:

True if the key is pressed, False otherwise.

返回类型:

bool

is_mouse_just_pressed(mouse)#

Check if a mouse button is just pressed.

参数:

mouse (str) -- The mouse button to check.

返回:

True if the mouse button is pressed, False otherwise.

返回类型:

bool

mouse_ray()#

Returns a ray from camera to mouse click position.

返回:

The ray from camera to mouse click position. It is a 6-element array: - Origin : (array[0],array[1],array[2]) - Direction : (array[3],array[4],array[5])

返回类型:

List[float]

class motrixsim.render.Layout(left=None, right=None, top=None, bottom=None, width=None, height=None)#

基类:object

Layout configuration for camera viewport widgets.

Attributes:

bottom#
height#
left#
right#
top#
width#
class motrixsim.render.RenderApp(log_level='WARN', headless=False, fps=None)#

基类:object

The RenderApp class is responsible for rendering the simulation scene.

This class provides functionality to load models, update their transformations, and render the scene. It also handles the creation and management of the render application.

Methods:

create_image(pixels[, is_srgb, keep_in_cpu])

Create an image from a numpy array of pixel data.

get_camera(index)

Get a render camera instance.

launch(model[, batch, render_offset, ...])

Load a model into the render app.

set_all_scene_vis(visible)

set_main_camera(camera)

Set the main camera of the render app.

set_scene_vis(indices, visible)

sync(data)

Synchronize the render app backend with python data.

Attributes:

gizmos

The gizmos module of the render app.

input

The input module of the render app.

is_closed

Check if the render app is closed.

opt

The options of the render app.

system_camera

The system camera

ui

The UI module of the render app.

widgets

The widgets module of the render app.

create_image(pixels, is_srgb=True, keep_in_cpu=True)#

Create an image from a numpy array of pixel data.

参数:
  • pixels (NDArray[uint8]) -- A 3D numpy array with shape (height, width, channels) where channels is either 3 (RGB) or 4 (RGBA). The array must be contiguous and contain uint8 values in the range [0, 255].

  • is_srgb (bool) -- Whether the image is in sRGB color space. Default is True.

  • keep_in_cpu (bool) -- Whether to keep the image data in CPU memory after uploading to GPU. If False, pixel data cannot be accessed after upload. Default is True.

返回:

A handle to the created image asset that can be used for textures,

materials, etc.

返回类型:

Image

抛出:
get_camera(index)#

Get a render camera instance.

launch(model, batch=1, render_offset=None, render_settings=Ellipsis)#

Load a model into the render app.

参数:
  • model (SceneModel) -- The scene model to load into the render app.

  • batch (int, optional) -- The number of instances to create. Default is 1.

  • render_offset (Optional[List[List[float]]], optional) -- The offset of each instance in render space. Default is None.

抛出:
set_all_scene_vis(visible)#
set_main_camera(camera)#

Set the main camera of the render app.

参数:
  • camera (Optional[Camera]) -- The camera to set as the main camera. If None, the system

  • used. (camera will be)

set_scene_vis(indices, visible)#
sync(data)#

Synchronize the render app backend with python data.

参数:

data (None | SceneData | NDArray) --

The scene data to synchronize with the renderer. This argument accept following types:

  • None: No data is provided, the render will use the last known transforms.

  • SceneData: The scene data used to update the render. If you lanched the render with repeat > 1, the shape the of data must be (repeat,).

  • NDArray: A 3D numpy array with shape (num_instances, num_links, 7), where the last dimension represents the pose of each link in the format [x, y, z, qx, qy, qz, qw].

抛出:
gizmos#

The gizmos module of the render app.

Return the gizmos module for rendering simple shapes in immediate mode.

Type:

RenderGizmos

input#

The input module of the render app.

Return the input module for handling user input events.

Type:

Input

is_closed#

Check if the render app is closed.

opt#

The options of the render app.

Return the options of the render app, which can be used to configure various settings.

Type:

RenderOpt

system_camera#

The system camera

ui#

The UI module of the render app.

Type:

RenderUI

widgets#

The widgets module of the render app.

Return the widgets module for creating UI widgets.

Type:

Widgets

class motrixsim.render.RenderCamera#

基类:object

Methods:

capture()

Request a capture from this camera.

Attributes:

active

Activates or deactivates the camera.

capture()#

Request a capture from this camera. This operation is asynchronous and you need to query the result by the returned CaptureTask.

返回:

An async task that can be used to check the capture state and get the captured image.

返回类型:

CaptureTask

active#

Activates or deactivates the camera.

class motrixsim.render.RenderGizmos#

基类:object

Gizmos module for rendering simple shapes in immediate mode.

Methods:

draw_arrow(start, end[, color])

Draw a arrow.

draw_axes([pos, rot, length])

Draw the XYZ axes at the given position and rotation.

draw_capsule(half_height, radius, pos, rot)

Draw a capsule.

draw_cuboid(size, pos, rot[, color])

Draw a cuboid.

draw_cylinder(half_height, radius, pos, rot)

Draw a cylinder.

draw_grid(pos, rot[, x_count, y_count, ...])

Draw a rectangle.

draw_line(start, end[, color])

Draw a line.

draw_ray(start, vector[, color])

Draw a ray.

draw_rect(width, height, pos, rot[, color])

Draw a rectangle.

draw_sphere(radius, pos[, color])

Draw a sphere at the given position with the specified radius and color.

Attributes:

collider_color

Set the color of collider gizmos.

draw_collider

Enable or disable collider gizmos.

draw_joint

Enable or disable joint gizmos.

draw_site

Enable or disable site gizmos.

joint_color

Set the color of joint gizmos.

joint_size

Set the size of joint gizmos.

line_width

Set the line width of all gizmos.

draw_arrow(start, end, color=Ellipsis)#

Draw a arrow.

参数:
  • start (list[float] | NDArray) -- The start point of the arrow in 3D space.

  • end (list[float] | NDArray) -- The end point of the arrow.

  • color (Color) -- Color of the arrow.

draw_axes(pos=None, rot=None, length=1.0)#

Draw the XYZ axes at the given position and rotation.

参数:
  • pos (list[float] | ndarray, optional) -- the position of axes with (x,y,z) format.

  • rot (list[float] | ndarray, optional) -- the rotation of axes as a quaternion (x, y, z,

  • length (float) -- the length of each axis.

w).

draw_capsule(half_height, radius, pos, rot, color=Ellipsis)#

Draw a capsule.

参数:
  • half_height (float) -- The half height of the capsule.

  • radius (float) -- The radius of the capsule.

  • pos (list[float] | NDArray) -- Position of the capsule in 3D space.

  • rot (list[float] | NDArray) -- Rotation of the capsule as a quaternion (x, y, z, w).

  • color (Color) -- Color of the capsule.

draw_cuboid(size, pos, rot, color=Ellipsis)#

Draw a cuboid.

参数:
  • size (list[float] | NDArray) -- Size of the cuboid in 3D space.

  • pos (list[float] | NDArray) -- Position of the cuboid in 3D space.

  • rot (list[float] | NDArray) -- Rotation of the cuboid as a quaternion (x, y, z, w).

  • color (Color) -- Color of the cuboid.

draw_cylinder(half_height, radius, pos, rot, color=Ellipsis)#

Draw a cylinder.

参数:
  • half_height (float) -- The half height of the cylinder.

  • radius (float) -- The radius of the cylinder.

  • pos (list[float] | NDArray) -- Position of the cylinder in 3D space.

  • rot (list[float] | NDArray) -- Rotation of the cylinder as a quaternion (x, y, z, w).

  • color (Color) -- Color of the cylinder.

draw_grid(pos, rot, x_count=2, y_count=2, z_count=2, spacing=None, color=Ellipsis)#

Draw a rectangle.

参数:
  • pos (list[float] | NDArray) -- Position of the rectangle in 3D space.

  • rot (list[float] | NDArray) -- Rotation of the rectangle as a quaternion (x, y, z, w).

  • x_count (unsigned int) -- The number of grid cells along the x-axis.

  • y_count (unsigned int) -- The number of grid cells along the y-axis.

  • z_count (unsigned int) -- The number of grid cells along the z-axis.

  • spacing (list[float] | NDArray) -- The spacing(x,y,z) between the grid cells.

  • color (Color) -- Color of the rectangle.

draw_line(start, end, color=Ellipsis)#

Draw a line.

参数:
  • start (list[float] | NDArray) -- The start point of the line in 3D space.

  • end (list[float] | NDArray) -- The end point of the line.

  • color (Color) -- Color of the line.

draw_ray(start, vector, color=Ellipsis)#

Draw a ray.

参数:
  • start (list[float] | NDArray) -- The start point of the ray in 3D space.

  • vector (list[float] | NDArray) -- The direction of the ray.

  • color (Color) -- Color of the ray.

draw_rect(width, height, pos, rot, color=Ellipsis)#

Draw a rectangle.

参数:
  • width (float) -- The width of the rectangle.

  • height (float) -- The height of the rectangle.

  • pos (list[float] | NDArray) -- Position of the rectangle in 3D space.

  • rot (list[float] | NDArray) -- Rotation of the rectangle as a quaternion (x, y, z, w).

  • color (Color) -- Color of the rectangle.

draw_sphere(radius, pos, color=Ellipsis)#

Draw a sphere at the given position with the specified radius and color.

参数:
  • radius (float) -- The radius of the sphere.

  • pos (list[float] | NDArray) -- The position of the sphere in 3D space.

  • color (Color) -- The color of the sphere.

collider_color#

Set the color of collider gizmos.

参数:

color (Color) -- Color of the collider gizmos.

draw_collider#

Enable or disable collider gizmos.

参数:

flag (bool) -- Enable/Disable the collider gizmos.

draw_joint#

Enable or disable joint gizmos.

参数:

flag (bool) -- Enable/Disable the joint gizmos.

draw_site#

Enable or disable site gizmos.

参数:

flag (bool) -- Enable/Disable the site gizmos.

joint_color#

Set the color of joint gizmos.

参数:

color (Color) -- Color of the joint gizmos.

joint_size#

Set the size of joint gizmos.

参数:

size (float) -- The size of joint gizmos.

line_width#

Set the line width of all gizmos.

参数:

width (float) -- The line width of all gizmos.

class motrixsim.render.RenderOpt#

基类:object

The RenderOpt object represents the options of the render app.

Methods:

is_left_panel_vis()

Check if the left panel is visible.

set_left_panel_vis(enabled)

Set the visibility of the left panel.

is_left_panel_vis()#

Check if the left panel is visible.

返回:

True if the left panel is visible, False otherwise.

返回类型:

bool

set_left_panel_vis(enabled)#

Set the visibility of the left panel.

参数:

enabled (bool) -- True to show the left panel, False to hide it.

class motrixsim.render.RenderSettings(simplify_render_mesh, enable_shadow, enable_ssao, enable_oit, share_lights_between_envs)#

基类:object

The global render settings for render app.

Methods:

performance()

Get a render settings with high performance.

quality()

Get a render settings with high quality.

Attributes:

enable_oit

Whether to enable OIT(Order Independent Transparency) effect.

enable_shadow

Whether to render shadows for lights.

enable_ssao

Whether to enable SSAO(Screen Space Ambient Occlusion) effect.

share_lights_between_envs

Whether to share lights between multiple simulation worlds, for performance optimization.

simplify_render_mesh

Wether to simplify render mesh when loading the model.

static performance()#

Get a render settings with high performance.

static quality()#

Get a render settings with high quality.

enable_oit#

Whether to enable OIT(Order Independent Transparency) effect.

enable_shadow#

Whether to render shadows for lights.

enable_ssao#

Whether to enable SSAO(Screen Space Ambient Occlusion) effect.

share_lights_between_envs#

Whether to share lights between multiple simulation worlds, for performance optimization. If false, each simulation world will have its own set of lights, which may cost more rendering resources, or out of memory crash depends on the number of simulation worlds and scene complexity.

simplify_render_mesh#

Wether to simplify render mesh when loading the model.

class motrixsim.render.RenderUI#

基类:object

The RenderUI object represents the user interface of the render app.

This class provides access to the user interface of the render app. It allows you to add buttons, toggles, and other UI elements to the render app.

Methods:

add_button(label, on_click)

Add a button to the user interface.

add_toggle(label, default, on_changed)

Add a toggle to the user interface.

add_button(label, on_click)#

Add a button to the user interface.

参数:
  • label (str) -- The label of the button.

  • on_click (PyAny) -- The callback function to be called when the button is clicked.

返回:

The ID of the button.

返回类型:

int

add_toggle(label, default, on_changed)#

Add a toggle to the user interface.

参数:
  • label (str) -- The label of the toggle.

  • default (bool) -- The default state of the toggle.

  • on_changed (PyAny) -- The callback function to be called when the toggle is changed.

class motrixsim.render.RenderWidgets#

基类:object

Widgets module for creating UI widgets in the render window.

Methods:

create_camera_viewport(camera[, layout, ...])

Create a camera viewport widget in the render window.

create_image_widget(image[, layout])

Create an image widget in the render window.

create_camera_viewport(camera, layout=None, sim_world_index=0)#

Create a camera viewport widget in the render window.

备注

This creates a camera viewport overlay that displays the output of a sensor camera. The layout parameters accept multiple formats: - String: "50px" for pixels, "50%" for percentage, "auto" for automatic - Number: Interpreted as pixels (e.g., 50 = 50px)

参数:
  • camera (Camera) -- The camera object to display in the viewport.

  • layout (Optional[Layout]) -- The layout configuration for the viewport. If None, uses default layout (50px from top-left with 200x200 size).

  • sim_world_index (int) -- The index of the simulation world. Default is 0.

示例

```python renderer = motrixsim.render.RenderApp() renderer.launch(model) cameras = model.cameras # Create viewport with default layout vp = renderer.widgets.create_camera_viewport(cameras[0]) # Create viewport with custom layout layout = motrixsim.render.Layout(left=50, top=50, width=400, height=300) vp = renderer.widgets.create_camera_viewport(cameras[0], layout=layout) # Create viewport with percentage-based layout layout = motrixsim.render.Layout(

left="10%", top="10%", width="50%", height="50%"

) vp = renderer.widgets.create_camera_viewport(cameras[1], sim_world_index=1,

layout=layout) # Access camera properties

print(f"Camera name: {vp.camera.name}") ```

create_image_widget(image, layout=None)#

Create an image widget in the render window.

备注

This creates an image widget overlay that displays the specified image. The layout parameters accept multiple formats: - String: "50px" for pixels, "50%" for percentage, "auto" for automatic - Number: Interpreted as pixels (e.g., 50 = 50px)

参数:
  • image (Image) -- The image object to display in the widget.

  • layout (Optional[Layout]) -- The layout configuration for the widget. If None, uses default layout (0px from top-left with automatic size).

示例

`python renderer = motrixsim.render.RenderApp() renderer.launch(model) # Load an image img = motrixsim.render.Image.from_file("path/to/image.png") # Create widget with default layout widget = renderer.widgets.create_image_widget(img) # Create widget with custom layout layout = motrixsim.render.Layout(left=100, top=100, width=200, height=200) widget = renderer.widgets.create_image_widget(img, layout=layout) # Update the widget widget.update(layout=new_layout) `

class motrixsim.render.SystemCamera#

基类:object

Attributes:

active

Activates or deactivates the system camera.

active#

Activates or deactivates the system camera.