def moveCamera(x=3, y=3, z=2):
    camera_entity.get_transform().look_at(
        v.vec3(0, 0, 2.0),
        v.vec3(0, 0, 1),
        v.vec3(x, y, z),
    )
    # camera_entity.get_transform().set_position(0, 0.0, x)


interact(moveCamera, x=(-10, 10, .001), y=(-10, 10, .001), z=(-10, 10, .001))

#%%
tex = v.texture.create_from_image("texture",
                                  "../data/abandoned_tank_farm_01_1k.hdr")
v.set_dome_light_texture(tex)

#%%
floor = v.entity.create(name="floor",
                        mesh=v.mesh.create_plane("floor"),
                        transform=v.transform.create("floor"),
                        material=v.material.create("floor"))
#%%
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",
Exemplo n.º 2
0
import time

opt = lambda: None
opt.spp = 1024
opt.width = 1920
opt.height = 1080
opt.out = '18_materials.png'

visii.initialize(headless=False, verbose=True)

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

# This is new, have the dome light use a texture
dome = visii.texture.create_from_file("dome", "content/teatro_massimo_2k.hdr")
visii.set_dome_light_texture(dome, enable_cdf=True)
visii.resize_window(1920, 1080)

# # Make a wall
# wall = visii.entity.create(
#     name = "wall",
#     mesh = visii.mesh.create_plane("mesh_wall"),
#     transform = visii.transform.create("transform_wall"),
#     material = visii.material.create("material_wall")
# )
# wall.get_transform().set_scale((50,50,1))
# wall.get_transform().set_rotation(visii.angleAxis(visii.pi() * .5, (1,0,0)))
# wall.get_transform().set_position((0,-.5,0))

# Make a sphere mesh that we'll make several instances of
# sphere_mesh = visii.mesh.create_teapotahedron("sphere")
Exemplo n.º 3
0
os.add_dll_directory(os.path.join(os.getcwd(), '..', 'install'))
sys.path.append(os.path.join(os.getcwd(), "..", "install"))

import visii

# %%
visii.initialize_interactive()

# %%
camera_entity = visii.entity.create(
    name="my_camera_entity",
    transform=visii.transform.create("my_camera_transform"),
    camera=visii.camera.create_perspective_from_fov(name = "my_camera", field_of_view = 0.785398, aspect = 1., near = .1))
visii.set_camera_entity(camera_entity)
camera_entity.get_transform().set_position(0, 0.0, -5.)
camera_entity.get_camera().use_perspective_from_fov(0.785398, 1.0, .01)
camera_entity.get_camera().set_view(
    visii.lookAt(
        visii.vec3(2,2,2),
        visii.vec3(0,0,.5),
        visii.vec3(0,0,1),
    )
)

# %%
tex = visii.texture.create("texture")

# %%
visii.set_dome_light_texture(tex)

# %%
Exemplo n.º 4
0
    visii.vec3(-2, 0, 2),  # camera_origin    
)
visii.set_camera_entity(camera)

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

visii.set_dome_light_intensity(1)

# load the textures
dome = visii.texture.create_from_image("dome",
                                       "content/kiara_4_mid-morning_4k.hdr")
floor_tex = visii.texture.create_from_image(
    "floor", 'content/photos_2020_5_11_fst_gray-wall-grunge.jpg')

# we can add HDR images to act as dome
visii.set_dome_light_texture(dome)

# 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(5))
mat = visii.material.get("material_floor")

mat.set_roughness(1)

# Lets set the base color of the object to be a texture.
# but the textures could also be used to set other
# material propreties
Exemplo n.º 5
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()