def load_obj_verts(mesh_path, rand_rotmat, rndrotate=True, scale=1., n_sample_verts=10000): np.random.seed(100) obj_mesh = Mesh(filename=mesh_path, vscale=scale) obj_mesh.reset_normals() obj_mesh.vc = obj_mesh.colors_like('green') ## center and scale the object max_length = np.linalg.norm(obj_mesh.v, axis=1).max() if max_length > .3: re_scale = max_length / .08 print(f'The object is very large, down-scaling by {re_scale} factor') obj_mesh.v = obj_mesh.v / re_scale object_fullpts = obj_mesh.v maximum = object_fullpts.max(0, keepdims=True) minimum = object_fullpts.min(0, keepdims=True) offset = (maximum + minimum) / 2 verts_obj = object_fullpts - offset obj_mesh.v = verts_obj if rndrotate: obj_mesh.rotate_vertices(rand_rotmat) else: rand_rotmat = np.eye(3) while (obj_mesh.v.shape[0] < n_sample_verts): mesh = M(vertices=obj_mesh.v, faces=obj_mesh.f) mesh = mesh.subdivide() obj_mesh = Mesh(v=mesh.vertices, f=mesh.faces, vc=name_to_rgb['green']) verts_obj = obj_mesh.v verts_sample_id = np.random.choice(verts_obj.shape[0], n_sample_verts, replace=False) verts_sampled = verts_obj[verts_sample_id] return verts_sampled, obj_mesh, rand_rotmat
def load_obj_verts(ho, rand_rotmat, rndrotate=True, scale=1., n_sample_verts=10000): np.random.seed(100) obj_mesh = Mesh(v=ho.obj_verts, f=ho.obj_faces, vscale=scale) # obj_mesh = Mesh(filename=mesh_path, vscale=scale) obj_mesh.reset_normals() obj_mesh.vc = obj_mesh.colors_like('green') ## center and scale the object # max_length = np.linalg.norm(obj_mesh.v, axis=1).max() # if max_length > .3: # re_scale = max_length/.08 # print(f'The object is very large, down-scaling by {re_scale} factor') # obj_mesh.v = obj_mesh.v/re_scale # object_fullpts = obj_mesh.v # maximum = object_fullpts.max(0, keepdims=True) # minimum = object_fullpts.min(0, keepdims=True) # # offset = ( maximum + minimum) / 2 verts_obj = object_fullpts # - offset # obj_mesh.v = verts_obj # if rndrotate: # obj_mesh.rotate_vertices(rand_rotmat) # verts_obj = obj_mesh.v if verts_obj.shape[0] > n_sample_verts: verts_sample_id = np.random.choice(verts_obj.shape[0], n_sample_verts, replace=False) else: verts_sample_id = np.arange(verts_obj.shape[0]) verts_sampled = verts_obj[verts_sample_id] return verts_sampled, obj_mesh, rand_rotmat