Skip to content

Commit ada1a62

Browse files
committed
Default normals now work with .obj and .vtk
1 parent 78d78d0 commit ada1a62

File tree

3 files changed

+9
-44
lines changed

3 files changed

+9
-44
lines changed

additional_file_formats/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import bgeo
2-
from . import mzd
2+
from . import mzd
3+
from . import obj

additional_file_formats/obj.py

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import numpy as np
88

9-
# from ..__about__ import __version__
10-
# from .._exceptions import WriteError
119
# from .._files import open_file
1210
# from .._helpers import register_format
1311
# from .._mesh import CellBlock, Mesh
@@ -16,7 +14,7 @@
1614

1715

1816
def read(filename):
19-
with open_file(filename, "r") as f:
17+
with open(filename, "r") as f:
2018
mesh = read_buffer(f)
2119
return mesh
2220

@@ -125,48 +123,13 @@ def read_buffer(f):
125123
cells = []
126124
for f, gid in zip(face_groups, face_group_ids):
127125
if f.shape[1] == 3:
128-
cells.append(CellBlock("triangle", f - 1))
126+
cells.append(meshio.CellBlock("triangle", f - 1))
129127
elif f.shape[1] == 4:
130-
cells.append(CellBlock("quad", f - 1))
128+
cells.append(meshio.CellBlock("quad", f - 1))
131129
else:
132-
cells.append(CellBlock("polygon", f - 1))
130+
cells.append(meshio.CellBlock("polygon", f - 1))
133131
cell_data["obj:group_ids"].append(gid)
134132

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)
136134

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})

bseq/importer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def update_mesh(meshio_mesh, mesh):
198198
# set split normal per loop per vertex
199199
if mesh.BSEQ.split_norm_att_name and mesh.BSEQ.split_norm_att_name == k:
200200
# Currently hard-coded for .obj files
201+
mesh.use_auto_smooth = True
201202
indices = [item for sublist in meshio_mesh.cell_data["obj:vn_face_idx"][0] for item in sublist]
202203
mesh.normals_split_custom_set([meshio_mesh.field_data["obj:vn"][i - 1] for i in indices])
203204

0 commit comments

Comments
 (0)