Skip to content

Instantly share code, notes, and snippets.

@ngunhaSO
Last active March 2, 2024 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngunhaSO/494866ac6c19965c760c4ef1b46e7539 to your computer and use it in GitHub Desktop.
Save ngunhaSO/494866ac6c19965c760c4ef1b46e7539 to your computer and use it in GitHub Desktop.
Convert obj file to stl
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