change_ext_pbrt.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # main imports
  2. import sys, os, argparse
  3. import json
  4. def main():
  5. parser = argparse.ArgumentParser(description="Update prefix image output of pbrt scene")
  6. parser.add_argument('--prefix', type=str, help='prefix of filename used', required=True)
  7. parser.add_argument('--pbrt', type=str, help='pbrt scene name (this one to convert)', required=True)
  8. parser.add_argument('--previous', type=str, help='previous extension', default='png', required=True)
  9. parser.add_argument('--ext', type=str, help='new extension to use', default='rawls_20', required=True)
  10. args = parser.parse_args()
  11. p_prefix = args.prefix
  12. p_pbrt = args.pbrt
  13. p_previous = args.previous
  14. p_ext = args.ext
  15. output_content = ""
  16. # read existing pbrt file
  17. pbrt_file = open(p_pbrt, 'r')
  18. pbrt_lines = pbrt_file.readlines()
  19. for line in pbrt_lines:
  20. output_line = line
  21. # 1. Comment Transform and Camera command
  22. if line.find(p_prefix) != -1 and line.find('filename') != -1:
  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()