diff --git a/examples/01.simple_scene.py b/examples/01.simple_scene.py index 68a867da..00a82b6c 100644 --- a/examples/01.simple_scene.py +++ b/examples/01.simple_scene.py @@ -23,7 +23,7 @@ # To make our camera entity act like a "camera", we'll add a camera component camera.set_camera( - visii.camera.create_perspective_from_fov( + visii.camera.create_from_fov( name = "camera_camera", field_of_view = 0.785398, # note, this is in radians aspect = float(WIDTH)/float(HEIGHT) diff --git a/examples/09.meta_data_exporting.py b/examples/09.meta_data_exporting.py index 71420592..45599c84 100644 --- a/examples/09.meta_data_exporting.py +++ b/examples/09.meta_data_exporting.py @@ -41,7 +41,7 @@ print(f'created folder {opt.outf}/') # # # # # # # # # # # # # # # # # # # # # # # # # -visii.initialize(headless=False, verbose=True) +visii.initialize(headless=False, verbose=True, lazy_updates = True) if not opt.noise is True: visii.enable_denoiser() diff --git a/examples/10.light_texture.py b/examples/10.light_texture.py index 9aa20b69..bfc2809b 100644 --- a/examples/10.light_texture.py +++ b/examples/10.light_texture.py @@ -27,7 +27,7 @@ opt = parser.parse_args() # # # # # # # # # # # # # # # # # # # # # # # # # -visii.initialize(headless = True) +visii.initialize(headless = True, verbose = True) if not opt.noise is True: visii.enable_denoiser() diff --git a/examples/15.camera_motion_car_blur.py b/examples/15.camera_motion_car_blur.py index 5064d45a..15c30ca7 100644 --- a/examples/15.camera_motion_car_blur.py +++ b/examples/15.camera_motion_car_blur.py @@ -25,11 +25,14 @@ parser.add_argument('--out', default='tmp.png', help = "output filename") +parser.add_argument('--control', + default=False, + help = "output filename") opt = parser.parse_args() # # # # # # # # # # # # # # # # # # # # # # # # # -visii.initialize_interactive() +visii.initialize() visii.set_dome_light_intensity(.8) visii.resize_window(int(opt.width), int(opt.height)) # # # # # # # # # # # # # # # # # # # # # # # # # @@ -185,118 +188,128 @@ # visii.render_to_png(1024, 1024, 1000, "motion_blur_3") +if opt.control: + + + # # # # # # # # # # # # # # # # # # # # # # # # # + import pygame + pygame.init() + screen = pygame.display.set_mode((400, 400)) + + while game_running: + + # visii camera matrix + cam_matrix = camera.get_transform().get_local_to_world_matrix() + to_add = visii.vec4(0,0,0,0) + + keys = pygame.key.get_pressed() + mouse = pygame.mouse.get_pressed() + mouseRel = pygame.mouse.get_rel() + + # print(mouseRel) + + # camera control + # Forward and backward + if keys[pygame.K_w]: + to_add[2] = 1 * speed_camera * -1 + if keys[pygame.K_s]: + to_add[2] = 1 * speed_camera + + # left and right + if keys[pygame.K_a]: + to_add[0] = 1 * speed_camera * -1 + if keys[pygame.K_d]: + to_add[0] = 1 * speed_camera + + # up and down + if keys[pygame.K_q]: + to_add[1] = 1 * speed_camera * -1 + if keys[pygame.K_e]: + to_add[1] = 1 * speed_camera + + # camera rotation + if mouse[0]: + pygame.event.set_grab(True) + pygame.mouse.set_visible(False) + camera_movement = mouseRel + rotate_camera = True + else: + if rotate_camera: + pygame.mouse.set_pos([200,200]) + pygame.event.set_grab(False) + pygame.mouse.set_visible(True) + rotate_camera = False + + for event in pygame.event.get(): + # print(event) + + # Game is running check for quit + if event.type == pygame.QUIT: + game_running = False + + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + game_running = False + + # change speed movement + if event.key == pygame.K_UP: + speed_camera *= 0.5 + print('decrease speed camera') + if event.key == pygame.K_DOWN: + speed_camera /= 0.5 + print('increase speed camera') + + # set mouse in the middle when moving -# # # # # # # # # # # # # # # # # # # # # # # # # -import pygame -pygame.init() -screen = pygame.display.set_mode((400, 400)) - -while game_running: - - # visii camera matrix - cam_matrix = camera.get_transform().get_local_to_world_matrix() - to_add = visii.vec4(0,0,0,0) - - keys = pygame.key.get_pressed() - mouse = pygame.mouse.get_pressed() - mouseRel = pygame.mouse.get_rel() - - # print(mouseRel) - - # camera control - # Forward and backward - if keys[pygame.K_w]: - to_add[2] = 1 * speed_camera * -1 - if keys[pygame.K_s]: - to_add[2] = 1 * speed_camera - - # left and right - if keys[pygame.K_a]: - to_add[0] = 1 * speed_camera * -1 - if keys[pygame.K_d]: - to_add[0] = 1 * speed_camera - - # up and down - if keys[pygame.K_q]: - to_add[1] = 1 * speed_camera * -1 - if keys[pygame.K_e]: - to_add[1] = 1 * speed_camera - - # camera rotation - if mouse[0]: - pygame.event.set_grab(True) - pygame.mouse.set_visible(False) - camera_movement = mouseRel - rotate_camera = True - else: if rotate_camera: - pygame.mouse.set_pos([200,200]) - pygame.event.set_grab(False) - pygame.mouse.set_visible(True) - rotate_camera = False - - for event in pygame.event.get(): - # print(event) - - # Game is running check for quit - if event.type == pygame.QUIT: - game_running = False - - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_ESCAPE: - game_running = False + x_rot -= (camera_movement[0]) * 0.001 + y_rot -= (camera_movement[1]) * 0.001 + + init_rot = visii.angleAxis( + visii.pi() * .5, + visii.vec3(1,0,0) + ) - # change speed movement - if event.key == pygame.K_UP: - speed_camera *= 0.5 - print('decrease speed camera') - if event.key == pygame.K_DOWN: - speed_camera /= 0.5 - print('increase speed camera') - - # set mouse in the middle when moving - - if rotate_camera: - x_rot -= (camera_movement[0]) * 0.001 - y_rot -= (camera_movement[1]) * 0.001 - - init_rot = visii.angleAxis( - visii.pi() * .5, - visii.vec3(1,0,0) - ) - - rot_x_to_apply = visii.angleAxis( - x_rot + visii.pi() * 1.25, - # camera.get_transform().get_up() - visii.vec3(0,1,0) - ) - - rot_y_to_apply = visii.angleAxis( - y_rot, - visii.vec3(1,0,0) - ) - - camera.get_transform().set_rotation(init_rot * rot_x_to_apply * rot_y_to_apply) - camera.get_transform().clear_motion() - camera.get_camera().set_aperture_diameter(5000) - camera.get_camera().set_focal_distance(500) - - # control the camera - if abs(to_add[0]) > 0.0 or \ - abs(to_add[1]) > 0.0 or \ - abs(to_add[2]) > 0.0: - - to_add_world = cam_matrix * to_add - - camera.get_transform().add_position( - visii.vec3( - to_add_world[0], - to_add_world[1], - to_add_world[2] + rot_x_to_apply = visii.angleAxis( + x_rot + visii.pi() * 1.25, + # camera.get_transform().get_up() + visii.vec3(0,1,0) + ) + + rot_y_to_apply = visii.angleAxis( + y_rot, + visii.vec3(1,0,0) + ) + + camera.get_transform().set_rotation(init_rot * rot_x_to_apply * rot_y_to_apply) + camera.get_transform().clear_motion() + camera.get_camera().set_aperture_diameter(5000) + camera.get_camera().set_focal_distance(500) + + # control the camera + if abs(to_add[0]) > 0.0 or \ + abs(to_add[1]) > 0.0 or \ + abs(to_add[2]) > 0.0: + + to_add_world = cam_matrix * to_add + + camera.get_transform().add_position( + visii.vec3( + to_add_world[0], + to_add_world[1], + to_add_world[2] + ) ) - ) - camera.get_camera().set_aperture_diameter(5000) - camera.get_camera().set_focal_distance(500) + camera.get_camera().set_aperture_diameter(5000) + camera.get_camera().set_focal_distance(500) + + +visii.render_to_png( + width=int(opt.width), + height=int(opt.height), + samples_per_pixel=int(opt.spp), + image_path=f"{opt.out}" +) # let's clean up the GPU visii.deinitialize() \ No newline at end of file diff --git a/examples/16.create_mesh_from_data.py b/examples/16.create_mesh_from_data.py index 412a13d8..a9849740 100644 --- a/examples/16.create_mesh_from_data.py +++ b/examples/16.create_mesh_from_data.py @@ -40,9 +40,8 @@ camera = visii.entity.create( name = "camera", transform = visii.transform.create("camera"), - camera = visii.camera.create_perspective_from_fov( - name = "camera", - field_of_view = 0.785398, + camera = visii.camera.create( + name = "camera", aspect = float(opt.width)/float(opt.height) ) )