change_ext_pbrt.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. output_line = line
  22. # 1. Comment Transform and Camera command
  23. if line.find(p_prefix) != -1 and line.find('filename') != -1:
  24. output_line = line.replace('.' + p_previous, '.' + p_ext)
  25. output_content = output_content + output_line
  26. # close all buffers
  27. pbrt_file.close()
  28. # update content
  29. pbrt_outfile = open(p_pbrt, 'w')
  30. pbrt_outfile.write(output_content)
  31. pbrt_outfile.close()
  32. if __name__== "__main__":
  33. main()