Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 6 additions & 53 deletions examples/rendering/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,69 +143,22 @@ def main():
)
########################## cameras ##########################
cam_0 = scene.add_camera(
pos=(8.5, 0.0, 4.5),
lookat=(3.0, 0.0, 0.5),
fov=50,
res=(1600, 900),
pos=(8.5, 0.0, 1.5),
lookat=(3.0, 0.0, 0.7),
fov=60,
GUI=True,
spp=512,
)
scene.build()

########################## forward + backward twice ##########################
scene.reset()
horizon = 10
horizon = 2000

for i in range(horizon):
scene.step()
rgb, depth, _, _ = scene.batch_render()
output_rgb_and_depth('img_output/test', rgb, depth, i)


import os
import cv2
import numpy as np

# TODO: Dump image faster, e.g., asynchronously or generate a video instead of saving images.
def output_rgb(output_dir, rgb, i_env, i_cam, i_step):
rgb = rgb.cpu().numpy()[i_env, i_cam]
cv2.imwrite(f'{output_dir}/rgb_env{i_env}_cam{i_cam}_{i_step:03d}.png', rgb)

def output_depth(output_dir, depth, i_env, i_cam, i_step):
depth = depth.cpu().numpy()[i_env, i_cam]
depth = np.asarray(depth)
depth = np.clip(depth, 0, 100)
depth_normalized = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX)
depth_uint8 = depth_normalized.astype(np.uint8)
cv2.imwrite(f'{output_dir}/depth_env{i_env}_cam{i_cam}_{i_step:03d}.png', depth_uint8)

def output_rgb_and_depth(output_dir, rgb, depth, i_step):
# loop over the first and second dimension of rgb and depth
for i_env in range(rgb.shape[0]):
for i_cam in range(rgb.shape[1]):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
output_rgb(output_dir, rgb, i_env, i_cam, i_step)
output_depth(output_dir, depth, i_env, i_cam, i_step)

def output_rgb_single_cam(output_dir, rgb, i_env, i_step, cam_idx):
rgb = rgb.cpu().numpy()[i_env]
cv2.imwrite(f'{output_dir}/rgb_env{i_env}_cam{cam_idx}_{i_step:03d}.png', rgb)

def output_depth_single_cam(output_dir, depth, i_env, i_step, cam_idx):
depth = depth.cpu().numpy()[i_env]
depth = np.asarray(depth)
depth = np.clip(depth, 0, 100)
depth_normalized = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX)
depth_uint8 = depth_normalized.astype(np.uint8)
cv2.imwrite(f'{output_dir}/depth_env{i_env}_cam{cam_idx}_{i_step:03d}.png', depth_uint8)

def output_rgb_and_depth_single_cam(output_dir, rgb, depth, i_step, cam_idx):
# loop over the first and second dimension of rgb and depth
for i_env in range(rgb.shape[0]):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
output_rgb_single_cam(output_dir, rgb, i_env, i_step, cam_idx)
output_depth_single_cam(output_dir, depth, i_env, i_step, cam_idx)
cam_0.render()


if __name__ == "__main__":
Expand Down
14 changes: 4 additions & 10 deletions examples/rigid/single_franka.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import argparse

import genesis as gs
import numpy as np
from genesis.utils.image_exporter import FrameImageExporter


def main():

Expand Down Expand Up @@ -45,16 +44,11 @@ def main():
GUI=True,
)
########################## build ##########################

# Create an image exporter
output_dir = 'img_output/test'
exporter = FrameImageExporter(output_dir)

scene.build()
for i in range(10):
for i in range(1000):
scene.step()
rgb, depth, seg, normal = cam_0.render(rgb=True, depth=True)
exporter.export_frame_single_cam(i, cam_0.idx, rgb=rgb, depth=depth)
# cam_0.render()


if __name__ == "__main__":
main()
15 changes: 8 additions & 7 deletions examples/rigid/single_franka_batch_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def main():
########################## build ##########################
n_envs = 3
n_steps = 2
do_batch_export = True
is_render_all_cams = True
scene.build(n_envs=n_envs)

# Warmup
scene.step()
rgb, depth, _, _ = scene.batch_render()
rgb, depth, _, _ = scene.render_all_cams()

# Create an image exporter
output_dir = 'img_output/test'
Expand All @@ -93,18 +93,19 @@ def main():

for i in range(n_steps):
scene.step()
if do_batch_export:
rgb, depth, _, _ = scene.batch_render()
exporter.export_frame_batch_cam(i, rgb=rgb, depth=depth)
if is_render_all_cams:
rgb, depth, _, _ = scene.render_all_cams()
exporter.export_frame_all_cams(i, rgb=rgb, depth=depth)
else:
rgb, depth, _, _ = cam_0.render()
exporter.export_frame_single_cam(i, cam_0.idx, rgb=rgb, depth=depth)

end_time = time()
actual_n_envs = n_envs if n_envs > 0 else 1
print(f'n_envs: {n_envs}')
print(f'Time taken: {end_time - start_time} seconds')
print(f'Time taken per env: {(end_time - start_time) / n_envs} seconds')
print(f'FPS: {n_envs * n_steps / (end_time - start_time)}')
print(f'Time taken per env: {(end_time - start_time) / actual_n_envs} seconds')
print(f'FPS: {actual_n_envs * n_steps / (end_time - start_time)}')
print(f'FPS per env: {n_steps / (end_time - start_time)}')


Expand Down
31 changes: 0 additions & 31 deletions genesis/assets/xml/box_mesh.xml

This file was deleted.

27 changes: 0 additions & 27 deletions genesis/assets/xml/unitree_g1/LICENSE

This file was deleted.

29 changes: 0 additions & 29 deletions genesis/assets/xml/unitree_g1/README.md

This file was deleted.

Binary file removed genesis/assets/xml/unitree_g1/assets/head_link.STL
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed genesis/assets/xml/unitree_g1/assets/logo_link.STL
Binary file not shown.
Binary file removed genesis/assets/xml/unitree_g1/assets/pelvis.STL
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed genesis/assets/xml/unitree_g1/assets/torso_link.STL
Diff not rendered.
Binary file removed genesis/assets/xml/unitree_g1/g1.png
Diff not rendered.
Loading
Loading