def interact():
        global speed_camera
        global cursor
        global rot

        # visii camera matrix 
        cam_matrix = camera.get_transform().get_local_to_world_matrix()
        dt = visii.vec4(0,0,0,0)

        # translation
        if visii.is_button_held("W"): dt[2] = -speed_camera
        if visii.is_button_held("S"): dt[2] =  speed_camera
        if visii.is_button_held("A"): dt[0] = -speed_camera
        if visii.is_button_held("D"): dt[0] =  speed_camera
        if visii.is_button_held("Q"): dt[1] = -speed_camera
        if visii.is_button_held("E"): dt[1] =  speed_camera 

        # control the camera
        if visii.length(dt) > 0.0:
            w_dt = cam_matrix * dt
            camera.get_transform().add_position(visii.vec3(w_dt))

        # camera rotation
        cursor[2] = cursor[0]
        cursor[3] = cursor[1]
        cursor[0] = visii.get_cursor_pos().x
        cursor[1] = visii.get_cursor_pos().y
        if visii.is_button_held("MOUSE_LEFT"):
            visii.set_cursor_mode("DISABLED")
            rotate_camera = True
        else:
            visii.set_cursor_mode("NORMAL")
            rotate_camera = False

        if rotate_camera:
            rot.x -= (cursor[0] - cursor[2]) * 0.001
            rot.y -= (cursor[1] - cursor[3]) * 0.001
            init_rot = visii.angleAxis(visii.pi() * .5, (1,0,0))
            yaw = visii.angleAxis(rot.x, (0,1,0))
            pitch = visii.angleAxis(rot.y, (1,0,0)) 
            camera.get_transform().set_rotation(init_rot * yaw * pitch)

        # change speed movement
        if visii.is_button_pressed("UP"):
            speed_camera *= 0.5 
            print('decrease speed camera', speed_camera)
        if visii.is_button_pressed("DOWN"):
            speed_camera /= 0.5
            print('increase speed camera', speed_camera)
Ejemplo n.º 2
0
        name = str(x) + "_" + str(y)
        m = box_mesh
        if y % 4 < 2:
            m = sphere_mesh

        visii.entity.create(
            name=name,
            mesh=m,
            transform=visii.transform.create(
                name=name,
                # position = (x * 1.3 + .33 * pow(-1, y), 0, y * .35),
                position=(x * .25, 0, y * .25 * .7 + .02 * pow(-1, y)),
                # scale = (.15, .15, .15),
                scale=((y % 2) * .01 + .09, (y % 2) * .01 + .09,
                       (y % 2) * .01 + .09),
                rotation=visii.angleAxis(-.78, (1, 0, 0))),
            material=visii.material.create(name=name))
        mat = visii.material.get(name)

        # The diffuse, metal, or glass surface color
        # mat.set_base_color(...)
        mat.set_base_color(hsv_to_rgb(y / 60.0, y % 2, 1.0))

        # Specifies the microfacet roughness of the surface for diffuse
        # or specular reflection
        if y == 0 or y == 1:
            mat.set_roughness(x / 20.0)

        # Blends between a non-metallic and a metallic material model.
        if y == 2 or y == 3:
            mat.set_roughness(0.0)
Ejemplo n.º 3
0
camera.get_transform().look_at(
    at=(-5, 0, 12),  # look at (world coordinate)
    up=(0, 0, 1),  # up vector
    eye=(5, -15, 18))
visii.set_camera_entity(camera)

visii.disable_dome_light_sampling()

# # # # # # # # # # # # # # # # # # # # # # # # #

sdb = visii.import_scene(
    file_path='content/salle_de_bain_separated/salle_de_bain_separated.obj',
    position=(1, 0, 0),
    scale=(1.0, 1.0, 1.0),
    rotation=visii.angleAxis(3.14 * .5, (1, 0, 0)),
    args=["verbose"]  # list assets as they are loaded
)

# Using the above function,
# visii loads each obj model as its own entity.
# You can find them by name (with an optional prefix added
# to front of each generated component name)

# visii generates the same naming pattern for the different
# materials defined in the mtl file

# since obj/mtl do not have definition for metallic properties
# lets add them manually to the material
mirror = visii.material.get('Mirror')
Ejemplo n.º 4
0
            showbelief=opt.showbelief,
            P_matrix=P_matrix,
            gt_keypoints=gt_keypoints)

        # transfer from dope to visii frame
        for name in Metric:
            temp = Metric[name]['orientation']
            if not temp is None:
                '''
                q_dope = Quaternion(w=temp[3],x=temp[0],y=temp[1],z=temp[2])
                q_dope_trans = q_dope * quat_trans_dope_to_visii
                Metric[name]['orientation'] = q_dope_trans
                '''
                rot = visii.quat(temp[3], temp[0], temp[1], temp[2])
                if opt.transform_visii:
                    rot = rot * visii.angleAxis(-1.57, visii.vec3(
                        0, 0, 1)) * visii.angleAxis(-1.57, visii.vec3(0, 1, 0))
                    rot.w, rot.x, rot.y, rot.z = rot.w, rot.x, -rot.y, -rot.z
                if opt.transform_hope:
                    rot = rot * visii.angleAxis(1.57, visii.vec3(
                        1, 0, 0)) * visii.angleAxis(1.57, visii.vec3(0, 0, 1))
                Metric[name]['orientation'] = Quaternion(w=rot.w,
                                                         x=rot.x,
                                                         y=rot.y,
                                                         z=rot.z)

        # add ground truth
        if not opt.real_world:
            objects_gt = visii_camera['objects']
            for object_gt in objects_gt:
                if object_gt['class'] in Metric:
                    location_gt = np.array(object_gt['location'])
Ejemplo n.º 5
0
    name="light_2",
    mesh=visii.mesh.create_teapotahedron('light_2'),
    transform=visii.transform.create("light_2"),
)
# a light is an entity with a light added to it.
obj_entity.set_light(visii.light.create('light_2'))
obj_entity.get_light().set_intensity(100000)

# you can also set the light color manually
obj_entity.get_light().set_color_texture(tex)

#lets set the size and placement of the light
obj_entity.get_transform().set_scale(visii.vec3(0.1))
obj_entity.get_transform().set_position(visii.vec3(-0.5, 0.4, 0))
obj_entity.get_transform().set_rotation(
    visii.angleAxis(90, visii.vec3(0, 0, 1)))

# # # # # # # # # # # # # # # # # # # # # # # # #

# Lets set some objects in the scene
entity = visii.entity.create(
    name="floor",
    mesh=visii.mesh.create_plane("mesh_floor"),
    transform=visii.transform.create("transform_floor"),
    material=visii.material.create("material_floor"))
entity.get_transform().set_scale(visii.vec3(100))
mat = visii.material.get("material_floor")
mat.set_base_color(visii.vec3(0.19, 0.16, 0.19))
mat.set_roughness(1)

sphere = visii.entity.create(name="sphere",
Ejemplo n.º 6
0
opt.out = '15_camera_motion_car_blur.png'
opt.control = True

# # # # # # # # # # # # # # # # # # # # # # # # #
visii.initialize()
visii.set_dome_light_intensity(.8)
visii.resize_window(int(opt.width), int(opt.height))
# # # # # # # # # # # # # # # # # # # # # # # # #

# load the textures
dome = visii.texture.create_from_file("dome", "content/teatro_massimo_2k.hdr")

# we can add HDR images to act as dome
visii.set_dome_light_texture(dome)
visii.set_dome_light_rotation(
    visii.angleAxis(visii.pi() * .5, visii.vec3(0, 0, 1)))

car_speed = 0
car_speed_x = car_speed
car_speed_y = -2 * car_speed

camera_height = 80
# # # # # # # # # # # # # # # # # # # # # # # # #

if not opt.noise is True:
    visii.enable_denoiser()

camera = visii.entity.create(name="camera",
                             transform=visii.transform.create("camera"),
                             camera=visii.camera.create(
                                 name="camera",
# Create a scene to use for exporting segmentations
floor = visii.entity.create(name="floor",
                            mesh=visii.mesh.create_plane("floor"),
                            transform=visii.transform.create("floor"),
                            material=visii.material.create("floor"))

floor.get_transform().set_scale((2, 2, 2))
floor.get_material().set_roughness(1.0)
areaLight1 = visii.entity.create(
    name="areaLight1",
    light=visii.light.create("areaLight1"),
    transform=visii.transform.create("areaLight1"),
    mesh=visii.mesh.create_plane("areaLight1"),
)
areaLight1.get_transform().set_rotation(visii.angleAxis(3.14, (1, 0, 0)))
areaLight1.get_light().set_intensity(1)
areaLight1.get_light().set_exposure(-3)
areaLight1.get_light().set_temperature(8000)
areaLight1.get_transform().set_position((0, 0, .6))
areaLight1.get_transform().set_scale((.2, .2, .2))

mesh1 = visii.entity.create(name="mesh1",
                            mesh=visii.mesh.create_teapotahedron("mesh1",
                                                                 segments=64),
                            transform=visii.transform.create("mesh1"),
                            material=visii.material.create("mesh1"))

brick_base_color = visii.texture.create_from_file(
    "bricks_base_color", "./content/Bricks051_2K_Color.jpg")
brick_normal = visii.texture.create_from_file(
# Create a scene to use for exporting segmentations
floor = visii.entity.create(name="floor",
                            mesh=visii.mesh.create_plane("floor"),
                            transform=visii.transform.create("floor"),
                            material=visii.material.create("floor"))

floor.get_transform().set_scale((2, 2, 2))
floor.get_material().set_roughness(1.0)
areaLight1 = visii.entity.create(
    name="areaLight1",
    light=visii.light.create("areaLight1"),
    transform=visii.transform.create("areaLight1"),
    mesh=visii.mesh.create_plane("areaLight1"),
)
areaLight1.get_transform().set_rotation(visii.angleAxis(3.14, (1, 0, 0)))
areaLight1.get_light().set_intensity(1)
areaLight1.get_light().set_exposure(-3)
areaLight1.get_light().set_temperature(8000)
areaLight1.get_transform().set_position((0, 0, .6))
areaLight1.get_transform().set_scale((.2, .2, .2))

mesh1 = visii.entity.create(name="mesh1",
                            mesh=visii.mesh.create_teapotahedron("mesh1",
                                                                 segments=64),
                            transform=visii.transform.create("mesh1"),
                            material=visii.material.create("mesh1"))

brick_base_color = visii.texture.create_from_file(
    "bricks_base_color", "./content/Bricks051_2K_Color.jpg")
brick_normal = visii.texture.create_from_file(
Ejemplo n.º 9
0
obj_entity = visii.entity.create(
    name="light_2",
    mesh=visii.mesh.create_teapotahedron('light_2'),
    transform=visii.transform.create("light_2"),
)
# a light is an entity with a light added to it.
obj_entity.set_light(visii.light.create('light_2'))
obj_entity.get_light().set_intensity(1)

# you can also set the light color manually
obj_entity.get_light().set_color((1, 0, 0))

#lets set the size and placement of the light
obj_entity.get_transform().set_scale((0.1, 0.1, 0.1))
obj_entity.get_transform().set_position((0, -0.6, 0.4))
obj_entity.get_transform().set_rotation(visii.angleAxis(90, (0, 0, 1)))

# third light
obj_entity = visii.entity.create(
    name="light_3",
    mesh=visii.mesh.create_plane('light_3', flip_z=True),
    transform=visii.transform.create("light_3"),
)
obj_entity.set_light(visii.light.create('light_3'))
# Intensity effects the appearance of the light in
# addition to what intensity that light emits.
obj_entity.get_light().set_intensity(1)

# Exposure does not effect direct appearance of the light,
# but does effect the relative power of the light in illuminating
# other objects.
Ejemplo n.º 10
0
camera.get_transform().look_at(
    visii.vec3(0, 0, 1.2),  # look at (world coordinate)
    visii.vec3(0, 0, 1),  # up vector
    visii.vec3(1, -1.5, 1.8))
visii.set_camera_entity(camera)

# # # # # # # # # # # # # # # # # # # # # # # # #

# This function loads the
sdb = visii.import_obj(
    "sdb",  # prefix name
    'content/salle_de_bain_separated/salle_de_bain_separated.obj',  #obj path
    'content/salle_de_bain_separated/',  # mtl folder 
    visii.vec3(1, 0, 0),  # translation 
    visii.vec3(0.1),  # scale here
    visii.angleAxis(3.14 * .5, visii.vec3(1, 0, 0))  #rotation here
)

# visii loads each obj model as its own entity
# you can find them by name where a prefix is added
# to the obj name defined is added.

# visii does the same thing for the different material defined
# in the mtl file

# since obj/mtl do not have definition for metallic propreties
# lets add them manually to the material
mirror = visii.material.get('sdbMirror')

mirror.set_roughness(0)
mirror.set_metallic(1)
Ejemplo n.º 11
0
rough_tex = visii.texture.create_from_file(
    "rough", 'content/Bricks051_2K_Roughness.jpg', linear=True)

mat.set_base_color_texture(color_tex)
mat.set_normal_map_texture(normal_tex)
mat.set_roughness_texture(rough_tex)

# # # # # # # # # # # # # # # # # # # # # # # # #

for i in range(20):
    obj_entity.get_transform().look_at(
        at=(0, 0, 0),
        up=(0, 0, 1),
        eye=(math.sin(math.pi * 2.0 * (i / 20.0)),
             math.cos(math.pi * 2.0 * (i / 20.0)), 1))
    entity.get_transform().set_rotation(
        visii.angleAxis(math.pi * 2.0 * (i / 20.0), (0, 0, 1)))
    # time.sleep(.1)
    visii.render_to_file(width=int(opt.width),
                         height=int(opt.height),
                         samples_per_pixel=int(opt.spp),
                         file_path=f"{opt.outf}/{str(i).zfill(5)}.png")

# let's clean up the GPU
visii.deinitialize()

subprocess.call([
    'ffmpeg', '-y', '-framerate', '30', '-i', r"%05d.png", '-vcodec',
    'libx264', '-pix_fmt', 'yuv420p', '../output.mp4'
],
                cwd=os.path.realpath(opt.outf))
Ejemplo n.º 12
0
)
# a light is an entity with a light added to it. 
obj_entity.set_light(
    visii.light.create('light_2')
)
obj_entity.get_light().set_intensity(3)
obj_entity.get_light().set_exposure(-5)

# you can also set the light color manually
obj_entity.get_light().set_color_texture(tex)

#lets set the size and placement of the light
obj_entity.get_transform().set_scale((0.1, 0.1, 0.1))
obj_entity.get_transform().set_position((-0.5,0.4,0))
obj_entity.get_transform().set_rotation(
    visii.angleAxis(90, (0,0,1))
)

# # # # # # # # # # # # # # # # # # # # # # # # #

# Lets set some objects in the scene
room = visii.entity.create(
    name="room",
    mesh = visii.mesh.create_box('room'),
    transform = visii.transform.create("room"),
    material = visii.material.create("room"),
)
room.get_transform().set_scale((2.0,2.0,2.0))
room.get_transform().set_position((0,0,2.0))
mat = visii.material.get("room")
mat.set_base_color(visii.vec3(0.19,0.16,0.19)) 
opt.noise = False
opt.out = '15_camera_motion_car_blur.png'
opt.control = True

# # # # # # # # # # # # # # # # # # # # # # # # #
visii.initialize()
visii.set_dome_light_intensity(.8)
visii.resize_window(int(opt.width), int(opt.height))
# # # # # # # # # # # # # # # # # # # # # # # # #

# load the textures
dome = visii.texture.create_from_file("dome", "content/teatro_massimo_2k.hdr")

# we can add HDR images to act as dome
visii.set_dome_light_texture(dome)
visii.set_dome_light_rotation(visii.angleAxis(visii.pi() * .5, visii.vec3(0, 0, 1)))

car_speed = 0
car_speed_x = car_speed
car_speed_y = -2 * car_speed

camera_height = 80
# # # # # # # # # # # # # # # # # # # # # # # # #

if not opt.noise is True: 
    visii.enable_denoiser()

camera = visii.entity.create(
    name = "camera",
    transform = visii.transform.create("camera"),
    camera = visii.camera.create(
Ejemplo n.º 14
0
#%%
mesh1 = v.entity.create(name="mesh1",
                        mesh=v.mesh.create_from_obj("mesh2",
                                                    "../data/dragon.obj"),
                        transform=v.transform.create("mesh1"),
                        material=v.material.create("mesh1"))

#%%
mesh2 = v.entity.create(name="mesh2",
                        mesh=v.mesh.create_sphere("sphere2"),
                        transform=v.transform.create("mesh2"),
                        material=v.material.create("mesh2"))

# %%
mesh1.get_transform().set_scale(v.vec3(4))
mesh1.get_transform().set_rotation(v.angleAxis(1.57, v.vec3(1, 0, 0)))
mesh1.get_transform().set_position(v.vec3(0, 0, 1.0))

#%%
areaLight1 = v.entity.create(
    name="areaLight1",
    light=v.light.create("areaLight1"),
    transform=v.transform.create("areaLight1"),
    mesh=v.mesh.create_sphere("areaLight1"),
)
# %%
areaLight1.get_transform().set_scale(v.vec3(.25))
#%%
floor.get_transform().set_scale(v.vec3(1000))
mesh1.get_transform().set_scale(v.vec3(.5))
areaLight1.get_transform().set_position(v.vec3(0, 0, 4))
Ejemplo n.º 15
0
def f(frame_ids):
    # headless - no window
    # verbose - output number of frames rendered, etc..
    visii.initialize(headless=True, verbose=False)

    # Use a neural network to denoise ray traced
    visii.enable_denoiser()

    # set up dome background
    negatives = list(glob.glob("negatives/*.jpg"))
    visii.set_dome_light_intensity(1)

    # create an entity that will serve as our camera.
    camera = visii.entity.create(name="camera")

    # To place the camera into our scene, we'll add a "transform" component.
    # (All visii objects have a "name" that can be used for easy lookup later.)
    camera.set_transform(visii.transform.create(name="camera_transform"))

    # To make our camera entity act like a "camera", we'll add a camera component
    camera.set_camera(
        visii.camera.create_from_fov(
            name="camera_camera",
            field_of_view=1.4,  # note, this is in radians
            aspect=opt.width / float(opt.height)))

    # Finally, we'll select this entity to be the current camera entity.
    # (visii can only use one camera at the time)
    visii.set_camera_entity(camera)

    # lets store the camera look at information so we can export it
    camera_struct_look_at = {
        'at': [0, 0, 0],
        'up': [0, 0, 1],
        'eye': [-1, 0, 0]
    }

    # Lets set the camera to look at an object.
    # We'll do this by editing the transform component.
    camera.get_transform().look_at(at=camera_struct_look_at['at'],
                                   up=camera_struct_look_at['up'],
                                   eye=camera_struct_look_at['eye'])

    # This function loads a mesh ignoring .mtl
    mesh = visii.mesh.create_from_file(opt.entity, opt.model)

    # creates visii entity using loaded mesh
    obj_entity = visii.entity.create(
        name=opt.entity + "_entity",
        mesh=mesh,
        transform=visii.transform.create(opt.entity + "_entity"),
        material=visii.material.create(opt.entity + "_entity"),
    )

    # obj_entity.get_light().set_intensity(0.05)

    # you can also set the light color manually
    # obj_entity.get_light().set_color((1,0,0))

    # Add texture to the material
    material = visii.material.get(opt.entity + "_entity")
    texture = visii.texture.create_from_file(opt.entity, "./models/Cutie.PNG")
    material.set_base_color_texture(texture)

    # Lets add the cuboid to the object we want to export
    add_cuboid(opt.entity + "_entity", opt.debug)

    # lets keep track of the entities we want to export
    entities_to_export = [opt.entity + "_entity"]

    # Loop where we change and render each frame
    for i in tqdm(frame_ids):
        # load a random negtive onto the dome
        negative = cv2.imread(random.choice(negatives))

        # Skip dark backgrounds (20/255)
        if np.mean(negative) < 20:
            continue

        # Fix lighting of background and make it small within the FOV
        background = make_background(negative)
        cv2.imwrite("test" + str(i) + ".png", background)
        dome = visii.texture.create_from_file("dome", "test" + str(i) + ".png")
        visii.set_dome_light_texture(dome)
        visii.set_dome_light_rotation(
            visii.angleAxis(visii.pi() * .5, visii.vec3(0, 0, 1)))

        stretch_factor = 2
        scale = [
            random.uniform(1, stretch_factor),  # width
            random.uniform(1, stretch_factor),  # length
            random.uniform(1, stretch_factor)  # height 
        ]
        obj_entity.get_transform().set_scale(scale)

        # create random rotation while making usre the entity is facing forward in each frame
        rot = [
            random.uniform(-10, 10),  # Roll
            random.uniform(-15, 15),  # Pitch
            random.uniform(-45, 45)  # Yaw
        ]
        q = Quaternion.from_euler(rot[0], rot[1], rot[2], degrees=True)

        position = [
            random.uniform(0, 4),  # X Depth
            random.uniform(-1, 1),  # Y 
            random.uniform(-1, 1)  # Z
        ]
        # Scale the position based on depth into image to make sure it remains in frame
        position[1] *= position[0]
        position[2] *= position[0]

        obj_entity.get_transform().set_position(tuple(position))

        obj_entity.get_transform().set_rotation((q.x, q.y, q.z, q.w))

        # use random to make 95 % probability the frame data goes into training and
        # 5% chance it goes in test folder
        folder = ''
        if random.randint(0, 100) < opt.test_percent:
            folder = opt.entity + '_test/'
        else:
            folder = opt.entity + '_training/'

        # Render the scene
        visii.render_to_file(width=opt.width,
                             height=opt.height,
                             samples_per_pixel=opt.spp,
                             file_path=opt.out + folder + opt.entity + str(i) +
                             '.png')

        # set up JSON
        export_to_ndds_file(filename=opt.out + folder + opt.entity + str(i) +
                            '.json',
                            obj_names=entities_to_export,
                            width=opt.width,
                            height=opt.height,
                            camera_struct=camera_struct_look_at)

        # remove current negative from the dome
        visii.clear_dome_light_texture()
        visii.texture.remove("dome")

        os.remove("test" + str(i) + ".png")

    visii.deinitialize()
Ejemplo n.º 16
0
def rotateLight(rx=0, ry=0., rz=0):
    areaLight1.get_transform().set_rotation(v.angleAxis(rx, v.vec3(1, 0, 0)))
    areaLight1.get_transform().add_rotation(v.angleAxis(ry, v.vec3(0, 1, 0)))
    areaLight1.get_transform().add_rotation(v.angleAxis(rz, v.vec3(0, 0, 1)))
    mesh=visii.mesh.create_plane("mesh_floor"),
    transform=visii.transform.create("transform_floor"),
    material=visii.material.create("material_floor"))
floor.get_material().set_base_color((0.19, 0.16, 0.19))
floor.get_material().set_metallic(0)
floor.get_material().set_roughness(1)
floor.get_transform().set_scale((5, 5, 1))

# Teapot
teapotahedron = visii.entity.create(
    name="teapotahedron",
    mesh=visii.mesh.create_teapotahedron("teapotahedron", segments=32),
    transform=visii.transform.create("teapotahedron"),
    material=visii.material.create("teapotahedron"))
teapotahedron.get_transform().set_rotation(
    visii.angleAxis(visii.pi() / 4.0, (0, 0, 1)))
teapotahedron.get_transform().set_position((0, 0, 0.41))
teapotahedron.get_transform().set_scale((0.4, 0.4, 0.4))
teapotahedron.get_material().set_base_color((1.0, 1.0, 1.0))
teapotahedron.get_material().set_roughness(0.0)

# Objects can be made to be "alpha transparent", which simulates little holes in the
# mesh that let light through. The smaller the alpha, the more little holes.
teapotahedron.get_material().set_alpha(0.5)

# Make a QT window to demonstrate the difference between alpha transparency and transmission
app = QApplication([])  # Start an application.
window = QWidget()  # Create a window.
layout = QVBoxLayout()  # Create a layout.