-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_2_msh.py
More file actions
36 lines (32 loc) · 952 Bytes
/
convert_2_msh.py
File metadata and controls
36 lines (32 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import meshio as mio
import glob
import igl
for ext in [".obj", ".ply", ".stl", ".off"]:
for file in glob.glob(f"./**/*{ext}", recursive=True):
if ext == ".obj":
v, f = igl.read_triangle_mesh(file)
m = mio.Mesh(v, [("triangle", f)])
else:
m = mio.read(file)
m.write(
file.replace(ext, ".msh"),
file_format="gmsh",
binary=True
)
for ext in [".mesh"]:
for file in glob.glob(f"./**/*{ext}", recursive=True):
m = mio.read(file)
T = []
for c in m.cells:
if c.type == "tetra":
T = c.data
break
if len(T) == 0:
print(f"{file} doesnt contain any tets, skipping")
continue
m = mio.Mesh(m.points, [("tetra", T)])
m.write(
file.replace(ext, "_3d.msh"),
file_format="gmsh",
binary=True
)