# Note, the API here is subject to change with future versions... import nvisii import numpy as np opt = lambda: None opt.spp = 512 opt.width = 1024 opt.height = 1024 opt.out = '22_volumes.png' nvisii.initialize(headless=False, verbose=True, window_on_top=True) nvisii.enable_denoiser() # Configuring the denoiser here to not use albedo and normal guides, which are # noisy for volumes nvisii.configure_denoiser(False, False, True) # Make a camera... camera = nvisii.entity.create(name="camera") camera.set_transform(nvisii.transform.create(name="camera_transform")) camera.set_camera( nvisii.camera.create_from_fov( name="camera_camera", field_of_view=0.785398, # note, this is in radians aspect=opt.width / float(opt.height))) nvisii.set_camera_entity(camera) camera.get_transform().look_at(at=(0, 0, .5), up=(0, 0, 1), eye=(0, 5, 2)) # Make a dome light env_tex = nvisii.texture.create_from_file( "env_tex", "./content/kiara_4_mid-morning_4k.hdr")
# # # # # # # # # # # # # # # # # # # # # # # # # if os.path.isdir(opt.outf): print(f'folder {opt.outf}/ exists') else: os.mkdir(opt.outf) print(f'created folder {opt.outf}/') # # # # # # # # # # # # # # # # # # # # # # # # # nvisii.initialize(headless = False, lazy_updates=True) if not opt.noise is True: nvisii.enable_denoiser() # Since objects are under motion, we'll disable albedo / normal guides nvisii.configure_denoiser( use_albedo_guide=False, use_normal_guide=False) # Create a camera camera = nvisii.entity.create( name = "camera", transform = nvisii.transform.create("camera"), camera = nvisii.camera.create_perspective_from_fov( name = "camera", field_of_view = 0.785398, aspect = float(opt.width)/float(opt.height) ) ) camera.get_transform().look_at( at = (0,0,0),
def __init__(self, env, img_path='images/', width=500, height=500, spp=256, use_noise=False, debug_mode=False, video_mode=False, video_path='videos/', video_name='robosuite_video_0.mp4', video_fps=60, verbose=1, vision_modalities=None): """ Initializes the nvisii wrapper. Wrapping any MuJoCo environment in this wrapper will use the NVISII wrapper for rendering. Args: env (MujocoEnv instance): The environment to wrap. img_path (string): Path to images. width (int, optional): Width of the rendered image. Defaults to 500. height (int, optional): Height of the rendered image. Defaults to 500. spp (int, optional): Sample-per-pixel for each image. Larger spp will result in higher quality images but will take more time to render each image. Higher quality images typically use an spp of around 512. use_noise (bool, optional): Use noise or denoise. Deafults to false. debug_mode (bool, optional): Use debug mode for nvisii. Deafults to false. video_mode (bool, optional): By deafult, the NVISII wrapper saves the results as images. If video_mode is set to true, a video is produced and will be stored in the directory defined by video_path. Defaults to false. video_path (string, optional): Path to store the video. Required if video_mode is set to true. Defaults to 'videos/'. video_name (string, optional): Name for the file for the video. Defaults to 'robosuite_video_0.mp4'. video_fps (int, optional): Frames per second for video. Defaults to 60. verbose (int, optional): If verbose is set to 1, the wrapper will print the image number for each image rendered. If verbose is set to 0, nothing will be printed. Defaults to 1. vision_modalities (string, optional): Options to render image with different ground truths for NVISII. Options include "normal", "texture_coordinates", "position", "depth". """ super().__init__(env, renderer_type="nvisii") self.env = env self.img_path = img_path self.width = width self.height = height self.spp = spp self.use_noise = use_noise self.video_mode = video_mode self.video_path = video_path self.video_name = video_name self.video_fps = video_fps self.verbose = verbose self.vision_modalities = vision_modalities self.img_cntr = 0 env._setup_references() # enable interactive mode when debugging if debug_mode: nvisii.initialize_interactive() else: nvisii.initialize(headless=True) self.segmentation_type = self.env.camera_segmentations # add denoiser to nvisii if not using noise if not use_noise: nvisii.configure_denoiser() nvisii.enable_denoiser() nvisii.configure_denoiser(True, True, False) if not os.path.exists(img_path): os.makedirs(img_path) if video_mode: if not os.path.exists(video_path): os.makedirs(video_path) self.video = cv2.VideoWriter(video_path + video_name, cv2.VideoWriter_fourcc(*'MP4V'), video_fps, (self.width, self.height)) print(f'video mode enabled') if vision_modalities is None and self.segmentation_type[0] == None: nvisii.sample_pixel_area(x_sample_interval=(0.0, 1.0), y_sample_interval=(0.0, 1.0)) else: nvisii.sample_pixel_area(x_sample_interval=(0.5, 0.5), y_sample_interval=(0.5, 0.5)) self._init_nvisii_components()