-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for COMSOL (.STL) compatible mesh output file #100
Comments
Hi Max, thanks for reaching out. To make an STL for a polymesh, you could split each 3D polygon facet into triangles. If a facet has 5 vertices, you could form triangles from vertices (0, 1, 2), vertices (0, 2, 3), and vertices (0, 3, 4). The code to write the STL would look something like: with open('mySTL.stl', 'w') as file:
file.write('solid mySTL\n')
for vertices in pmesh.facets:
pt0 = pmesh.points[vertices[0]]
for idx in range(2, len(vertices)):
pt1 = pmesh.points[vertices[idx-1]]
pt2 = pmesh.points[vertices[idx]]
write_tri_in_STL_format(file, pt0, pt1, pt2)
file.write('endsolid mySTL\n') The There's a risk there of generating thin triangles with this method. Instead, you may want to create a center point for each facet and define triangles that emanate from it. This would look something like: with open('mySTL.stl', 'w') as file:
file.write('solid mySTL\n')
for vertices in pmesh.facets:
pts = pmesh.points[vertices]
center = np.mean(pts, axis=2)
n = len(vertices)
for idx_pt1 in range(n):
idx_pt2 = idx_pt1 + 1
if idx_pt2 == n:
idx_pt2 = 0
pt1 = pts[idx_pt1]
pt2 = pts[idx_pt2]
write_tri_in_STL_format(file, center, pt1, pt2)
file.write('endsolid mySTL\n') You could also include an If you'd like to contribute to the project and add an |
Thanks for the quick response, I will look into it further! |
This worked well! Both methods worked and imported into COMSOL! I just attached a rough script to demonstrate it in case anyone else ever needs. Assigning normal direction does not seem to be necessary for COMSOL. Not sure if more complicated geometry will ever cause issues, but this basic example works well. The below image is from COMSOL.
|
I'm wondering if anyone has ideas for how to create a mesh file that is compatible with COMSOL, which accepts .ply, .stl and some others. COMSOL only accepts triangular mesh's for .ply, so the polymesh output to .ply does not work. Trying to convert .vtk from the tri-mesh to .ply or .stl with meshio does not work either.
Ideally I want a polymesh converted to an STL file, not sure if this has been attempted.
The text was updated successfully, but these errors were encountered: