forked from yuki-koyama/blender-cli-rendering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_ibl.py
55 lines (38 loc) · 1.54 KB
/
03_ibl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# blender --background --python 03_ibl.py --render-frame 1 -- </path/to/output/image> <resolution_percentage> <num_samples>
import bpy
import sys
import math
import os
working_dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(working_dir_path)
import utils
def set_scene_objects() -> bpy.types.Object:
num_suzannes = 7
for index in range(num_suzannes):
utils.create_smooth_monkey(location=((index - (num_suzannes - 1) / 2) * 2.8, 0.0, 1.0),
name="Suzanne" + str(index))
utils.create_plane(size=20.0)
return bpy.data.objects["Suzanne" + str(int((num_suzannes - 1) / 2))]
# Args
output_file_path = bpy.path.relpath(str(sys.argv[sys.argv.index('--') + 1]))
resolution_percentage = int(sys.argv[sys.argv.index('--') + 2])
num_samples = int(sys.argv[sys.argv.index('--') + 3])
# Parameters
hdri_path = os.path.join(working_dir_path, "assets/HDRIs/green_point_park_2k.hdr")
# Scene Building
scene = bpy.data.scenes["Scene"]
world = scene.world
## Reset
utils.clean_objects()
## Suzannes
center_suzanne = set_scene_objects()
## Camera
bpy.ops.object.camera_add(location=(5.0, -10.0, 2.0))
camera_object = bpy.context.object
utils.add_track_to_constraint(camera_object, center_suzanne)
utils.set_camera_params(camera_object.data, center_suzanne, lens=50, fstop=0.2)
## Lights
utils.build_environment_texture_background(world, hdri_path)
# Render Setting
utils.set_output_properties(scene, resolution_percentage, output_file_path)
utils.set_cycles_renderer(scene, camera_object, num_samples)