| import bpy |
| import random |
| import json |
| import os |
| import sys |
| from sys import platform |
|
|
| if __name__ == "__main__": |
|
|
| code_fpath = sys.argv[6] |
| rendering_dir = sys.argv[7] |
| if len(sys.argv) > 8: |
| save_blend = sys.argv[8] |
| else: |
| save_blend = None |
|
|
| |
| bpy.context.scene.render.engine = 'CYCLES' |
| bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA' |
| bpy.context.preferences.addons['cycles'].preferences.get_devices() |
|
|
| |
| for device in bpy.context.preferences.addons['cycles'].preferences.devices: |
| if device.type == 'GPU' and not device.use: |
| device.use = True |
|
|
| |
| bpy.context.scene.cycles.device = 'GPU' |
|
|
| |
| bpy.context.scene.render.resolution_x = 512 |
| bpy.context.scene.render.resolution_y = 512 |
|
|
| |
| bpy.context.scene.cycles.samples = 512 |
|
|
| |
| bpy.context.scene.render.image_settings.color_mode = 'RGB' |
|
|
| |
| with open(code_fpath, "r") as f: |
| code = f.read() |
| try: |
| exec(code) |
| except: |
| raise ValueError |
|
|
| |
| if 'Camera1' in bpy.data.objects: |
| bpy.context.scene.camera = bpy.data.objects['Camera1'] |
| bpy.context.scene.render.image_settings.file_format = 'PNG' |
| bpy.context.scene.render.filepath = os.path.join(rendering_dir, 'render1.png') |
| bpy.ops.render.render(write_still=True) |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| if save_blend: |
| |
| bpy.context.preferences.filepaths.save_version = 0 |
| |
| bpy.ops.wm.save_as_mainfile(filepath=save_blend) |