Last active
March 2, 2024 23:07
-
-
Save ngunhaSO/494866ac6c19965c760c4ef1b46e7539 to your computer and use it in GitHub Desktop.
Convert obj file to stl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vtk | |
reader = vtk.vtkOBJReader() | |
reader.SetFileName('data/3D_data/demoparts/1_with_wall.obj') | |
reader.Update() | |
triangle = vtk.vtkTriangleFilter() | |
triangle.SetInputConnection(reader.GetOutputPort()) | |
surface = triangle.GetOutputPort() | |
normals = vtk.vtkPolyDataNormals() | |
normals.SetAutoOrientNormals(False) | |
normals.SetFlipNormals(False) | |
normals.SetSplitting(False) | |
normals.SetFeatureAngle(30.0) | |
normals.ConsistencyOn() | |
normals.SetInputConnection(surface) | |
surface = normals.GetOutputPort() | |
fillHoles = vtk.vtkFillHolesFilter() | |
fillHoles.SetHoleSize(1000.0) | |
fillHoles.SetInputConnection(surface) | |
surface = fillHoles.GetOutputPort() | |
print('write') | |
writer = vtk.vtkSTLWriter() | |
writer.SetFileTypeToBinary() | |
writer.SetInputConnection(surface) | |
writer.SetFileName('data/3D_data/demoparts/test.stl') | |
writer.Update() | |
writer.Write() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment