import os import numpy as np def read_obj_file_ours(obj_fn, sub_one=False): vertices = [] faces = [] with open(obj_fn, "r") as rf: for line in rf: items = line.strip().split(" ") if items[0] == 'v': cur_verts = items[1:] cur_verts = [float(vv) for vv in cur_verts] vertices.append(cur_verts) elif items[0] == 'f': cur_faces = items[1:] # faces cur_face_idxes = [] for cur_f in cur_faces: try: cur_f_idx = int(cur_f.split("/")[0]) except: cur_f_idx = int(cur_f.split("//")[0]) cur_face_idxes.append(cur_f_idx if not sub_one else cur_f_idx - 1) faces.append(cur_face_idxes) rf.close() vertices = np.array(vertices, dtype=np.float) return vertices, faces