|
6 | 6 |
|
7 | 7 | import numpy as np
|
8 | 8 |
|
9 |
| -# from ..__about__ import __version__ |
10 |
| -# from .._exceptions import WriteError |
11 | 9 | # from .._files import open_file
|
12 | 10 | # from .._helpers import register_format
|
13 | 11 | # from .._mesh import CellBlock, Mesh
|
|
16 | 14 |
|
17 | 15 |
|
18 | 16 | def read(filename):
|
19 |
| - with open_file(filename, "r") as f: |
| 17 | + with open(filename, "r") as f: |
20 | 18 | mesh = read_buffer(f)
|
21 | 19 | return mesh
|
22 | 20 |
|
@@ -125,48 +123,13 @@ def read_buffer(f):
|
125 | 123 | cells = []
|
126 | 124 | for f, gid in zip(face_groups, face_group_ids):
|
127 | 125 | if f.shape[1] == 3:
|
128 |
| - cells.append(CellBlock("triangle", f - 1)) |
| 126 | + cells.append(meshio.CellBlock("triangle", f - 1)) |
129 | 127 | elif f.shape[1] == 4:
|
130 |
| - cells.append(CellBlock("quad", f - 1)) |
| 128 | + cells.append(meshio.CellBlock("quad", f - 1)) |
131 | 129 | else:
|
132 |
| - cells.append(CellBlock("polygon", f - 1)) |
| 130 | + cells.append(meshio.CellBlock("polygon", f - 1)) |
133 | 131 | cell_data["obj:group_ids"].append(gid)
|
134 | 132 |
|
135 |
| - return Mesh(points, cells, point_data=point_data, cell_data=cell_data, field_data=field_data) |
| 133 | + return meshio.Mesh(points, cells, point_data=point_data, cell_data=cell_data, field_data=field_data) |
136 | 134 |
|
137 |
| - |
138 |
| -def write(filename, mesh): |
139 |
| - for c in mesh.cells: |
140 |
| - if c.type not in ["triangle", "quad", "polygon"]: |
141 |
| - raise WriteError( |
142 |
| - "Wavefront .obj files can only contain triangle or quad cells." |
143 |
| - ) |
144 |
| - |
145 |
| - with open_file(filename, "w") as f: |
146 |
| - f.write( |
147 |
| - "# Created by meshio v{}, {}\n".format( |
148 |
| - __version__, datetime.datetime.now().isoformat() |
149 |
| - ) |
150 |
| - ) |
151 |
| - for p in mesh.points: |
152 |
| - f.write(f"v {p[0]} {p[1]} {p[2]}\n") |
153 |
| - |
154 |
| - if "obj:vn" in mesh.point_data: |
155 |
| - dat = mesh.point_data["obj:vn"] |
156 |
| - fmt = "vn " + " ".join(["{}"] * dat.shape[1]) + "\n" |
157 |
| - for vn in dat: |
158 |
| - f.write(fmt.format(*vn)) |
159 |
| - |
160 |
| - if "obj:vt" in mesh.point_data: |
161 |
| - dat = mesh.point_data["obj:vt"] |
162 |
| - fmt = "vt " + " ".join(["{}"] * dat.shape[1]) + "\n" |
163 |
| - for vt in dat: |
164 |
| - f.write(fmt.format(*vt)) |
165 |
| - |
166 |
| - for cell_block in mesh.cells: |
167 |
| - fmt = "f " + " ".join(["{}"] * cell_block.data.shape[1]) + "\n" |
168 |
| - for c in cell_block.data: |
169 |
| - f.write(fmt.format(*(c + 1))) |
170 |
| - |
171 |
| - |
172 |
| -register_format("obj", [".obj"], read, {"obj": write}) |
| 135 | +meshio.register_format("obj", [".obj"], read, {"obj": None}) |
0 commit comments