|
|
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) |
|
|
|
|
|
print(f'Camera1 location: {bpy.data.objects["Camera1"].location}') |
|
|
print(f'Camera1 rotation: {bpy.data.objects["Camera1"].rotation_euler}') |
|
|
print(f'Camera1 lens: {bpy.data.objects["Camera1"].data.lens}') |
|
|
|
|
|
print(f"Camera2 location: {bpy.data.objects['Camera2'].location}") |
|
|
print(f"Camera2 rotation: {bpy.data.objects['Camera2'].rotation_euler}") |
|
|
print(f"Camera2 lens: {bpy.data.objects['Camera2'].data.lens}") |
|
|
|
|
|
if 'Camera3' in bpy.data.objects: |
|
|
print(f"Camera3 location: {bpy.data.objects['Camera3'].location}") |
|
|
print(f"Camera3 rotation: {bpy.data.objects['Camera3'].rotation_euler}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if save_blend: |
|
|
|
|
|
bpy.context.preferences.filepaths.save_version = 0 |
|
|
|
|
|
bpy.ops.wm.save_as_mainfile(filepath=save_blend) |