Advertisement
JoelSjogren

Untitled

Mar 18th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. a = open('../blendswapdrums2-simplified.obj').read()
  2. b = a.split('\no ')
  3. c = ['o ' + i for i in b[1:]]
  4.  
  5. def normalize(block, offset):
  6. u = block.split('\n')
  7. vertices = [i for i in u if len(i) >= 2 and i[:2] == 'v ']
  8. faces = [i for i in u if len(i) >= 2 and i[:2] == 'f ']
  9.  
  10. def normalize_face(i):
  11. _, p, q, r = i.split(' ')
  12. return f'f {int(p)-offset} {int(q)-offset} {int(r)-offset}'
  13.  
  14. normalized_faces = [normalize_face(i) for i in faces]
  15. normalized_block = '\n'.join(vertices + normalized_faces)
  16. new_offset = offset + len(vertices)
  17.  
  18. return normalized_block, new_offset
  19.  
  20. offset = 0
  21. for i in c:
  22. fnam = i[2:i.index('\n')]
  23. content, offset = normalize(i, offset)
  24. print(offset)
  25. with open(fnam + '.piece', 'w') as f:
  26. f.write(content)
  27.  
  28.  
  29. # % echo *.piece
  30. # '{' + ', '.join(f'"{i}"' for i in t) + '}'
  31. # t=s.split(' ')
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement