def get_add(obj1, obj2, pos1, pos2, quat1, quat2): obj1.get_transform().set_position(visii.vec3(pos1[0],pos1[1],pos1[2])) obj1.get_transform().set_rotation(visii.quat(quat1[0],quat1[1],quat1[2],quat1[3])) obj2.get_transform().set_position(visii.vec3(pos2[0],pos2[1],pos2[2])) obj2.get_transform().set_rotation(visii.quat(quat2[0],quat2[1],quat2[2],quat2[3])) dist = [] vertices = obj1.get_mesh().get_vertices() for i in range(len(vertices)): v = visii.vec4(vertices[i][0],vertices[i][1],vertices[i][2],1) p0 = obj1.get_transform().get_local_to_world_matrix() * v p1 = obj2.get_transform().get_local_to_world_matrix() * v dist.append(visii.distance(p0, p1)) dist = np.mean(dist) return dist
visii.render_to_file(width=int(opt.width), height=int(opt.height), samples_per_pixel=int(opt.spp), file_path=f"20_frame1.png") obj1.get_transform().set_position(obj1.get_transform().get_position(), previous=True) obj1.get_transform().add_position(visii.vec3(0, 0.5, 0)) obj2.get_transform().set_position(obj2.get_transform().get_position(), previous=True) obj2.get_transform().add_position(visii.vec3(0, 0, 0.5)) obj3.get_transform().set_rotation(obj3.get_transform().get_rotation(), previous=True) obj3.get_transform().add_rotation(visii.quat(0, -1, 0, 0)) motion_vectors_array = visii.render_data(width=int(opt.width), height=int(opt.height), start_frame=0, frame_count=1, bounce=int(0), options="diffuse_motion_vectors") motion_vectors_array = np.array(motion_vectors_array).reshape( opt.height, opt.width, 4) * -1 motion_vectors_array = np.flipud(motion_vectors_array) image = generate_image_from_motion_vector(motion_vectors_array) cv2.imwrite("20_motion_from_1_to_2.png", image * 255) # frame now has to be set at 1 to have the current image, e.g., the transformed one
obj3 = visii.entity.create(name="obj3", mesh=mesh, transform=visii.transform.create("obj3"), material=visii.material.create("obj3")) obj4 = visii.entity.create(name="obj4", mesh=mesh, transform=visii.transform.create("obj4"), material=visii.material.create("obj4")) # place those objects into the scene # lets set the obj_entity up obj1.get_transform().set_position(visii.vec3(-1.5, 0, 0)) obj1.get_transform().set_rotation(visii.quat(0.7071, 0.7071, 0, 0)) obj1.get_material().set_base_color(visii.vec3(1, 0, 0)) obj1.get_material().set_roughness(0.7) obj1.get_material().set_specular(1) obj1.get_material().set_sheen(1) obj2.get_transform().set_position(visii.vec3(-.5, 0, 0)) obj2.get_transform().set_rotation(visii.quat(0.7071, 0.7071, 0, 0)) obj2.get_material().set_base_color(visii.vec3(0, 1, 0)) obj2.get_material().set_roughness(0.7) obj2.get_material().set_specular(1) obj2.get_material().set_sheen(1) obj3.get_transform().set_position(visii.vec3(.5, 0, 0)) obj3.get_transform().set_rotation(visii.quat(0.7071, 0.7071, 0, 0)) obj3.get_material().set_base_color(visii.vec3(0, 0, 1))
visii.set_camera_entity(camera) visii.set_dome_light_intensity(1) # # # # # # # # # # # # # # # # # # # # # # # # # # This function loads the obj meshes, it will ignore # other content like materials mesh = visii.mesh.create_from_obj("obj", opt.path_obj) obj_entity = visii.entity.create( name="obj_entity", mesh=mesh, transform=visii.transform.create("obj_entity"), material=visii.material.create("obj_entity")) # lets set the obj_entity up obj_entity.get_transform().set_rotation(visii.quat(0.7071, 0.7071, 0, 0)) obj_entity.get_material().set_base_color(visii.vec3(0.9, 0.12, 0.08)) obj_entity.get_material().set_roughness(0.7) obj_entity.get_material().set_specular(1) obj_entity.get_material().set_sheen(1) # # # # # # # # # # # # # # # # # # # # # # # # # 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.cleanup()
img_name=img_name, output_folder=f"{opt.outf}/{folder_substructure}", 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']
transform=visii.transform.create("light"), ) obj_entity.set_light(visii.light.create('light')) obj_entity.get_light().set_intensity(1000) # lets set the color texture as the color of the light obj_entity.get_light().set_color_texture(tex) obj_entity.get_transform().set_scale(visii.vec3(0.6, 0.6, 0.2)) obj_entity.get_transform().set_position(visii.vec3(0.5, -0.4, 0.7)) obj_entity.get_transform().look_at( visii.vec3(0, 0, 0), visii.vec3(0, 0, 1), ) obj_entity.get_transform().add_rotation(visii.quat(0, 0, 1, 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(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))
def add_random_obj(name="name"): # this function adds a random object from the pre loaded meshes # it will give it a random pose and an random material obj = visii.entity.create(name=name, transform=visii.transform.create(name), material=visii.material.create(name)) obj_id = random.randint(0, 15) # set the mesh, the meshes can be shared mesh = visii.mesh.get(f'mesh_{obj_id}') obj.set_mesh(mesh) obj.get_transform().set_position( visii.vec3(random.uniform(-5, 5), random.uniform(-5, 5), random.uniform(-10, 3))) obj.get_transform().set_rotation( visii.quat(random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1))) obj.get_transform().set_scale( visii.vec3(random.uniform(0.15, 0.2), random.uniform(0.15, 0.2), random.uniform(0.15, 0.2))) rgb = colorsys.hsv_to_rgb(random.uniform(0, 1), random.uniform(0.7, 1), random.uniform(0.7, 1)) obj.get_material().set_base_color(visii.vec3( rgb[0], rgb[1], rgb[2], )) obj_mat = obj.get_material() r = random.randint(0, 2) # This is a simple logic for more natural random materials, e.g., # mirror or glass like objects if r == 0: # Plastic / mat obj_mat.set_metallic(0) # should 0 or 1 obj_mat.set_transmission(0) # should 0 or 1 obj_mat.set_roughness(random.uniform(0, 1)) # default is 1 if r == 1: # metallic obj_mat.set_metallic(random.uniform(0.9, 1)) # should 0 or 1 obj_mat.set_transmission(0) # should 0 or 1 if r == 2: # glass obj_mat.set_metallic(0) # should 0 or 1 obj_mat.set_transmission(random.uniform(0.9, 1)) # should 0 or 1 if r > 0: # for metallic and glass r2 = random.randint(0, 1) if r2 == 1: obj_mat.set_roughness(random.uniform(0, .1)) # default is 1 else: obj_mat.set_roughness(random.uniform(0.9, 1)) # default is 1 obj_mat.set_sheen(random.uniform(0, 1)) # degault is 0 obj_mat.set_clearcoat(random.uniform(0, 1)) # degault is 0 obj_mat.set_specular(random.uniform(0, 1)) # degault is 0 r = random.randint(0, 1) if r == 0: obj_mat.set_anisotropic(random.uniform(0, 0.1)) # degault is 0 else: obj_mat.set_anisotropic(random.uniform(0.9, 1)) # degault is 0
ids_pybullet_and_visii_names = [] for i in range(opt.nb_objects): name = f"mesh_{i}" obj = visii.entity.create(name=name, transform=visii.transform.create(name), material=visii.material.create(name)) obj.set_mesh(mesh) # transforms pos = visii.vec3(random.uniform(-4, 4), random.uniform(-4, 4), random.uniform(2, 5)) rot = visii.quat( random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1), ) scale = visii.vec3(random.uniform(0.2, 0.5), ) obj.get_transform().set_position(pos) obj.get_transform().set_rotation(rot) obj.get_transform().set_scale(scale) # pybullet setup pos = [pos[0], pos[1], pos[2]] rot = [rot[0], rot[1], rot[2], rot[3]] scale = [scale[0], scale[1], scale[2]] obj_col_id = p.createCollisionShape( p.GEOM_MESH,
ids_pybullet_and_visii_names = [] for i in range(opt.nb_objects): name = f"mesh_{i}" obj = visii.entity.create(name=name, transform=visii.transform.create(name), material=visii.material.create(name)) obj.set_mesh(mesh) # transforms pos = visii.vec3(random.uniform(-4, 4), random.uniform(-4, 4), random.uniform(2, 5)) rot = visii.normalize( visii.quat( random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1), )) s = random.uniform(0.2, 0.5) scale = (s, s, s) obj.get_transform().set_position(pos) obj.get_transform().set_rotation(rot) obj.get_transform().set_scale(scale) # pybullet setup pos = [pos[0], pos[1], pos[2]] rot = [rot[0], rot[1], rot[2], rot[3]] scale = [scale[0], scale[1], scale[2]] obj_col_id = p.createCollisionShape(