Skip to content

Commit

Permalink
some final tweaks to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
natevm committed Oct 22, 2020
1 parent 6dac291 commit a867757
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 115 deletions.
2 changes: 1 addition & 1 deletion examples/01.simple_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/09.meta_data_exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/10.light_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
231 changes: 122 additions & 109 deletions examples/15.camera_motion_car_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
# # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -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()
5 changes: 2 additions & 3 deletions examples/16.create_mesh_from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Expand Down

0 comments on commit a867757

Please sign in to comment.