Created
June 2, 2018 03:19
-
-
Save 1f0/7d841b4e138fc50bbbf1d71994a0d024 to your computer and use it in GitHub Desktop.
merge two obj to one
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
import sys | |
if(len(sys.argv)!=4): | |
print('Usage: ', sys.argv[0], 'input1.obj input2.obj output.obj') | |
sys.exit() | |
import vtk | |
def read(f): | |
reader = vtk.vtkOBJReader() | |
reader.SetFileName(f) | |
reader.Update() | |
return reader.GetOutput() | |
def output(f, obj, offset): | |
for i in range(obj.GetNumberOfPoints()): | |
pt = obj.GetPoint(i) | |
f.write('v %.5f %.5f %.5f\n' % (pt[0], pt[1], pt[2])) | |
for i in range(obj.GetNumberOfCells()): | |
cell = obj.GetCell(i) | |
f.write('f %d %d %d\n'% (cell.GetPointId(0)+1+offset, cell.GetPointId(1)+1+offset, cell.GetPointId(2)+1+offset)) | |
obj1 = read(sys.argv[1]) | |
obj2 = read(sys.argv[2]) | |
with open(sys.argv[3], 'w') as f: | |
output(f, obj1, 0) | |
output(f, obj2, obj1.GetNumberOfPoints()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment