def test_render_rendering_cleaning(): download_assets() test_dir = os.path.join(gibson2.assets_path, 'test') for i in range(5): renderer = MeshRenderer(width=800, height=600) renderer.load_object( os.path.join(test_dir, 'mesh/bed1a77d92d64f5cbbaaae4feed64ec1_new.obj')) renderer.add_instance(0) renderer.set_camera([0, 0, 1.2], [0, 1, 1.2], [0, 1, 0]) renderer.set_fov(90) rgb = renderer.render(('rgb'))[0] assert (np.sum(rgb, axis=(0, 1, 2)) > 0) GPUtil.showUtilization() renderer.release() GPUtil.showUtilization()
def main(): if len(sys.argv) > 1: model_path = sys.argv[1] else: model_path = os.path.join(get_scene_path('Rs'), 'mesh_z_up.obj') renderer = MeshRenderer(width=512, height=512) renderer.load_object(model_path) renderer.add_instance(0) camera_pose = np.array([0, 0, 1.2]) view_direction = np.array([1, 0, 0]) renderer.set_camera(camera_pose, camera_pose + view_direction, [0, 0, 1]) renderer.set_fov(90) frames = renderer.render( modes=('rgb', 'normal', '3d')) frames = cv2.cvtColor(np.concatenate(frames, axis=1), cv2.COLOR_RGB2BGR) cv2.imshow('image', frames) cv2.waitKey(0)
def test_render_rendering(record_property): download_assets() test_dir = os.path.join(gibson2.assets_path, 'test') renderer = MeshRenderer(width=800, height=600) start = time.time() renderer.load_object( os.path.join(test_dir, 'mesh/bed1a77d92d64f5cbbaaae4feed64ec1_new.obj')) elapsed = time.time() - start renderer.add_instance(0) renderer.set_camera([0, 0, 1.2], [0, 1, 1.2], [0, 1, 0]) renderer.set_fov(90) rgb = renderer.render(('rgb'))[0] record_property("object_loading_time", elapsed) assert (np.sum(rgb, axis=(0, 1, 2)) > 0) renderer.release()
def main(): global _mouse_ix, _mouse_iy, down, view_direction if len(sys.argv) > 1: model_path = sys.argv[1] else: model_path = os.path.join(get_scene_path('Rs'), 'mesh_z_up.obj') renderer = MeshRenderer(width=512, height=512) renderer.load_object(model_path) renderer.add_instance(0) print(renderer.visual_objects, renderer.instances) print(renderer.materials_mapping, renderer.mesh_materials) px = 0 py = 0.2 camera_pose = np.array([px, py, 0.5]) view_direction = np.array([0, -1, -1]) renderer.set_camera(camera_pose, camera_pose + view_direction, [0, 0, 1]) renderer.set_fov(90) _mouse_ix, _mouse_iy = -1, -1 down = False def change_dir(event, x, y, flags, param): global _mouse_ix, _mouse_iy, down, view_direction if event == cv2.EVENT_LBUTTONDOWN: _mouse_ix, _mouse_iy = x, y down = True if event == cv2.EVENT_MOUSEMOVE: if down: dx = (x - _mouse_ix) / 100.0 dy = (y - _mouse_iy) / 100.0 _mouse_ix = x _mouse_iy = y r1 = np.array([[np.cos(dy), 0, np.sin(dy)], [0, 1, 0], [-np.sin(dy), 0, np.cos(dy)]]) r2 = np.array([[np.cos(-dx), -np.sin(-dx), 0], [np.sin(-dx), np.cos(-dx), 0], [0, 0, 1]]) view_direction = r1.dot(r2).dot(view_direction) elif event == cv2.EVENT_LBUTTONUP: down = False cv2.namedWindow('test') cv2.setMouseCallback('test', change_dir) while True: with Profiler('Render'): frame = renderer.render(modes=('rgb')) cv2.imshow( 'test', cv2.cvtColor(np.concatenate(frame, axis=1), cv2.COLOR_RGB2BGR)) q = cv2.waitKey(1) if q == ord('w'): px += 0.01 elif q == ord('s'): px -= 0.01 elif q == ord('a'): py += 0.01 elif q == ord('d'): py -= 0.01 elif q == ord('q'): break camera_pose = np.array([px, py, 0.5]) renderer.set_camera(camera_pose, camera_pose + view_direction, [0, 0, 1]) renderer.release()