Read a surface form a Wavefront .obj file. Parameters ---------- fname : str Name of the .obj file to read. Returns ------- coords : ndarray, shape (n_points, 3) The XYZ coordinates of each vertex. faces : ndarray, shape (n_faces, 3) For each fac
(fname)
| 1041 | |
| 1042 | |
| 1043 | def _read_wavefront_obj(fname): |
| 1044 | """Read a surface form a Wavefront .obj file. |
| 1045 | |
| 1046 | Parameters |
| 1047 | ---------- |
| 1048 | fname : str |
| 1049 | Name of the .obj file to read. |
| 1050 | |
| 1051 | Returns |
| 1052 | ------- |
| 1053 | coords : ndarray, shape (n_points, 3) |
| 1054 | The XYZ coordinates of each vertex. |
| 1055 | faces : ndarray, shape (n_faces, 3) |
| 1056 | For each face of the mesh, the integer indices of the vertices that |
| 1057 | make up the face. |
| 1058 | """ |
| 1059 | coords = [] |
| 1060 | faces = [] |
| 1061 | with open(fname) as f: |
| 1062 | for line in f: |
| 1063 | line = line.strip() |
| 1064 | if len(line) == 0 or line[0] == "#": |
| 1065 | continue |
| 1066 | split = line.split() |
| 1067 | if split[0] == "v": # vertex |
| 1068 | coords.append([float(item) for item in split[1:]]) |
| 1069 | elif split[0] == "f": # face |
| 1070 | dat = [int(item.split("/")[0]) for item in split[1:]] |
| 1071 | if len(dat) != 3: |
| 1072 | raise RuntimeError("Only triangle faces allowed.") |
| 1073 | # In .obj files, indexing starts at 1 |
| 1074 | faces.append([d - 1 for d in dat]) |
| 1075 | return np.array(coords), np.array(faces) |
| 1076 | |
| 1077 | |
| 1078 | def _read_patch(fname): |
no test coverage detected