change_dimensions_pbrt.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # main imports
  2. import sys, os, argparse
  3. import json
  4. xresolution_line = "\"integer xresolution\""
  5. yresolution_line = "\"integer yresolution\""
  6. def main():
  7. parser = argparse.ArgumentParser(description="Update image output dimensions of pbrt scene")
  8. parser.add_argument('--xresolution', type=int, help='xresolution to set into image output scene', required=True)
  9. parser.add_argument('--yresolution', type=int, help='yresolution to set into image output scene', required=True)
  10. parser.add_argument('--pbrt', type=str, help='pbrt scene name (this one to convert)', required=True)
  11. args = parser.parse_args()
  12. p_xresolution = args.xresolution
  13. p_yresolution = args.yresolution
  14. p_pbrt = args.pbrt
  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. # Update xresolution into file
  22. if line.find(xresolution_line) != -1:
  23. output_line = "\t" + xresolution_line + " " + str(p_xresolution) + '\n'
  24. # Update yresolution into file
  25. if line.find(yresolution_line) != -1:
  26. output_line = "\t" + yresolution_line + " " + str(p_yresolution) + '\n'
  27. output_content = output_content + output_line
  28. # close all buffers
  29. pbrt_file.close()
  30. # update content
  31. pbrt_outfile = open(p_pbrt, 'w')
  32. pbrt_outfile.write(output_content)
  33. pbrt_outfile.close()
  34. if __name__== "__main__":
  35. main()