change_ext_pbrt.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # main imports
  2. import sys, os, argparse
  3. import json
  4. # default file
  5. def main():
  6. parser = argparse.ArgumentParser(description="Update prefix image output of pbrt scene")
  7. parser.add_argument('--prefix', type=str, help='prefix of filename used', required=True)
  8. parser.add_argument('--pbrt', type=str, help='pbrt scene name (this one to convert)', required=True)
  9. parser.add_argument('--previous', type=str, help='previous extension', default='png', required=True)
  10. parser.add_argument('--ext', type=str, help='new extension to use', default='rawls_20', required=True)
  11. args = parser.parse_args()
  12. p_prefix = args.prefix
  13. p_pbrt = args.pbrt
  14. p_previous = args.previous
  15. p_ext = args.ext
  16. output_content = ""
  17. # read existing pbrt file
  18. pbrt_file = open(p_pbrt, 'r')
  19. pbrt_lines = pbrt_file.readlines()
  20. for line in pbrt_lines:
  21. # 1. Comment Transform and Camera command
  22. if line.find(p_prefix) and line.find('filename'):
  23. output_line = line.replace('.' + p_previous, '.' + p_ext)
  24. output_content = output_content + output_line
  25. # close all buffers
  26. pbrt_file.close()
  27. # update content
  28. pbrt_outfile = open(p_pbrt, 'w')
  29. pbrt_outfile.write(output_content)
  30. pbrt_outfile.close()
  31. if __name__== "__main__":
  32. main()