Created
September 29, 2018 06:00
-
-
Save 1f0/f3d37e198e606a91475eadd1d6dced77 to your computer and use it in GitHub Desktop.
change vtk to obj
This file contains 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
from __future__ import print_function | |
import sys | |
if(len(sys.argv)!=3): | |
print('Usage: ', sys.argv[0], 'input.vtk output.obj') | |
sys.exit() | |
import vtk | |
reader = vtk.vtkUnstructuredGridReader() | |
reader.SetFileName(sys.argv[1]) | |
reader.Update() | |
output = reader.GetOutput() | |
out_obj_file = sys.argv[2] | |
with open(out_obj_file, 'w') as f: | |
for i in range(output.GetNumberOfPoints()): | |
pt = output.GetPoint(i) | |
f.write('v %.5f %.5f %.5f\n' % (pt[0], pt[1], pt[2])) | |
for i in range(output.GetNumberOfCells()): | |
cell = output.GetCell(i) | |
f.write('f %d %d %d\n'% (cell.GetPointId(0)+1, cell.GetPointId(1)+1, cell.GetPointId(2)+1) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment