Created
October 2, 2017 03:00
-
-
Save oiehot/9cbfbc903e199f74ad2d296824a2193e to your computer and use it in GitHub Desktop.
Maya batch render with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import argparse | |
| # command line options | |
| parser = argparse.ArgumentParser(description='N9A Maya Batch render') | |
| parser.add_argument('-prj', '--project', required=True, type=str, help='ex) d:/project/alice/maya') | |
| parser.add_argument('-i', '--include_file', required=True, type=str, help='ex) include.txt') | |
| parser.add_argument('-q', '--quality', required=True, type=str, help='ex) preview, production, default') | |
| cmd_opts = parser.parse_args() | |
| # maya config | |
| project_path = cmd_opts.project | |
| log_path = project_path + '/log' | |
| images_path = project_path + '/images' | |
| asset_path = project_path + '/assets' | |
| housing_path = asset_path + '/Housing' | |
| renderer = 'arnold' | |
| # arnold config | |
| arnold_log_to_file = 'true' | |
| arnold_log_level = 1 | |
| def get_arnold_quality_options(): | |
| quality = cmd_opts.quality | |
| sampling = { | |
| 'preview' : { | |
| 'aa': 1, | |
| 'diffuse': 1, | |
| 'specular': 1, | |
| 'transmission': 1, | |
| 'sss': 1, | |
| 'volume_indirect': 1, | |
| }, | |
| 'production' : { | |
| 'aa': 10, | |
| 'diffuse': 3, | |
| 'specular': 2, | |
| 'transmission': 2, | |
| 'sss': 3, | |
| 'volume_indirect': 3 | |
| }, | |
| 'default': { | |
| 'aa': 3, | |
| 'diffuse': 2, | |
| 'specular': 2, | |
| 'transmission': 2, | |
| 'sss': 2, | |
| 'volume_indirect': 2 | |
| } | |
| } | |
| ray_depth = { | |
| 'preview': { | |
| 'total': 5, | |
| 'diffuse': 1, | |
| 'specular': 1, | |
| 'transmission': 1, | |
| 'volume': 1, | |
| 'transparency_depth': 1 | |
| }, | |
| 'production': { | |
| 'total': 15, | |
| 'diffuse': 3, | |
| 'specular': 1, | |
| 'transmission': 8, | |
| 'volume': 3, | |
| 'transparency_depth': 3 | |
| }, | |
| 'default': { | |
| 'total': 10, | |
| 'diffuse': 1, | |
| 'specular': 1, | |
| 'transmission': 8, | |
| 'volume': 0, | |
| 'transparency_depth': 10 | |
| } | |
| } | |
| opt = '' | |
| opt = '%s -ai:as %d' % (opt, sampling[quality]['aa']) | |
| opt = '%s -ai:hs %d' % (opt, sampling[quality]['diffuse']) | |
| opt = '%s -ai:gs %d' % (opt, sampling[quality]['specular']) | |
| opt = '%s -ai:rs %d' % (opt, sampling[quality]['transmission']) | |
| # opt = '%s -ai:bssrdfs %d ' % (opt, sampling[quality]['sss']) | |
| opt = '%s -ai:td %d' % (opt, ray_depth[quality]['total']) | |
| opt = '%s -ai:dif %d' % (opt, ray_depth[quality]['diffuse']) | |
| opt = '%s -ai:glo %d' % (opt, ray_depth[quality]['specular']) | |
| opt = '%s -ai:rfr %d' % (opt, ray_depth[quality]['transmission']) | |
| opt = '%s -ai:vol %d' % (opt, ray_depth[quality]['volume']) | |
| opt = '%s -ai:atd %d' % (opt, ray_depth[quality]['transparency_depth']) | |
| return opt | |
| def get_render_cmd(filepath): | |
| filename_with_ext = os.path.basename(filepath) # hc_column_corridor.ma | |
| filename_without_ext = os.path.splitext(os.path.basename(filepath))[0] # hc_column_corridor | |
| path_tokens = os.path.dirname(os.path.abspath(filepath)).split('\\') | |
| theme = path_tokens[-1] # HeartCastle | |
| category = path_tokens[-2] # Housing | |
| category_theme = category + '/' + theme + '/' # Housing/HeartCastle/ | |
| # 로그용 폴더가 없는 경우 만들어야 렌더시 튕기지 않는다. | |
| if not os.path.exists(log_path + '/' + category_theme): | |
| os.makedirs(log_path + '/' + category_theme) | |
| maya_log_path = os.path.join(log_path, category_theme + filename_without_ext + '.maya.log' ).replace("\\","/") | |
| arnold_log_path = os.path.join(log_path, category_theme + filename_without_ext + '.arnold.log').replace("\\","/") | |
| maya_options = '-proj "%s" -log "%s" -renderer %s' % (project_path, maya_log_path, renderer) | |
| output_path = images_path + '/' + category_theme | |
| arnold_options = '%s -ai:ltf %s -ai:lfn "%s" -ai:lve %d -rd "%s"' % (get_arnold_quality_options(), arnold_log_to_file, arnold_log_path, arnold_log_level, output_path) | |
| cmd = 'render %s %s "%s"' % (maya_options, arnold_options, filepath) | |
| return cmd | |
| def get_include_list(filepath): | |
| f = open(filepath) | |
| content = f.readlines() | |
| content = [x.strip() for x in content] # 줄 끝에 '\n'를 제거. | |
| result = [] | |
| for path in content: | |
| if path[0] != '#': # 주석 처리된 파일을 생략. | |
| result.append(path) | |
| return result | |
| def render(files): | |
| for file in files: | |
| print(file) | |
| cmd = get_render_cmd(file) | |
| print(cmd) | |
| os.system(cmd) | |
| # main | |
| if __name__ == '__main__': | |
| files = get_include_list(cmd_opts.include_file) | |
| render(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment