motrixsim.render#
Exceptions:
Raise when the given arguments are invalid |
|
Raise when a file to be loaded is invalid |
|
Other render errors |
|
Raise when the render app is closed |
|
Base class for all render errors |
Classes:
A color in RGBA format, where each component is a float in the range [0.0, 1.0]. |
|
The Input object represents the input events of the render app. |
|
|
Layout configuration for camera viewport widgets. |
|
The RenderApp class is responsible for rendering the simulation scene. |
Gizmos module for rendering simple shapes in immediate mode. |
|
The RenderOpt object represents the options of the render app. |
|
|
The global render settings for render app. |
The RenderUI object represents the user interface of the render app. |
|
Widgets module for creating UI widgets in the render window. |
|
- exception motrixsim.render.InvalidArgumentError#
基类:
RenderErrorRaise when the given arguments are invalid
- exception motrixsim.render.InvalidFileError#
基类:
RenderErrorRaise when a file to be loaded is invalid
- exception motrixsim.render.OtherRenderError#
基类:
RenderErrorOther render errors
- exception motrixsim.render.RenderClosedError#
基类:
RenderErrorRaise when the render app is closed
- exception motrixsim.render.RenderError#
基类:
ExceptionBase class for all render errors
- class motrixsim.render.CaptureTask#
基类:
objectMethods:
Try take the image from the capture task.
Attributes:
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#
基类:
objectA color in RGBA format, where each component is a float in the range [0.0, 1.0].
Methods:
Attributes:
The alpha component of the color, representing transparency.
The blue component of the color.
The green component of the color.
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.
- 返回类型:
- 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#
基类:
objectMethods:
save_to_disk(path)Save the image to disk with the specified path.
Attributes:
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#
基类:
objectThe 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.
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)#
基类:
objectLayout configuration for camera viewport widgets.
Attributes:
- bottom#
- height#
- left#
- right#
- top#
- width#
- class motrixsim.render.RenderApp(log_level='WARN', headless=False, fps=None)#
基类:
objectThe 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:
The gizmos module of the render app.
The input module of the render app.
Check if the render app is closed.
The options of the render app.
The system camera
The UI module of the render app.
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.
- 返回类型:
- 抛出:
InvalidArgumentError -- If the array shape is invalid or not contiguous.
OtherRenderError -- If image creation fails.
- 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.
- 抛出:
RenderClosedError -- If the render app is closed.
InvalidArgumentError -- If the file is invalid.
InvalidFileError -- If there are issues with file operations.
OtherRenderError -- For other unexpected errors.
- 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].
- 抛出:
RenderClosedError -- If the render app is closed.
InvalidArgumentError -- If neither datas nor poses is provided correctly.
InvalidFileError -- If there are issues with file operations.
OtherRenderError -- Not launched with model file.
- gizmos#
The gizmos module of the render app.
Return the gizmos module for rendering simple shapes in immediate mode.
- Type:
- input#
The input module of the render app.
Return the input module for handling user input events.
- Type:
- 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:
- system_camera#
The system camera
- widgets#
The widgets module of the render app.
Return the widgets module for creating UI widgets.
- Type:
Widgets
- class motrixsim.render.RenderCamera#
基类:
objectMethods:
capture()Request a capture from this camera.
Attributes:
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.
- 返回类型:
- active#
Activates or deactivates the camera.
- class motrixsim.render.RenderGizmos#
基类:
objectGizmos 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:
Set the color of collider gizmos.
Enable or disable collider gizmos.
Enable or disable joint gizmos.
Enable or disable site gizmos.
Set the color of joint gizmos.
Set the size of joint gizmos.
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_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#
基类:
objectThe RenderOpt object represents the options of the render app.
Methods:
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)#
基类:
objectThe global render settings for render app.
Methods:
Get a render settings with high performance.
quality()Get a render settings with high quality.
Attributes:
Whether to enable OIT(Order Independent Transparency) effect.
Whether to render shadows for lights.
Whether to enable SSAO(Screen Space Ambient Occlusion) effect.
Whether to share lights between multiple simulation worlds, for performance optimization.
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.
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#
基类:
objectThe 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#
基类:
objectWidgets 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)
- 参数:
示例
```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,
- 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)
- 参数:
示例
`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) `