-
Notifications
You must be signed in to change notification settings - Fork 109
/
13_matcap.py
92 lines (63 loc) · 3.08 KB
/
13_matcap.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# blender --background --python 13_matcap.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():
image_path = os.path.join(working_dir_path, "assets/matcaps/blue.png")
mat = utils.add_material("MatCap", use_nodes=True, make_node_tree_empty=True)
utils.build_matcap_nodes(mat.node_tree, image_path)
current_object = utils.create_smooth_monkey(location=(1.2, 0.0, 0.0))
current_object.data.materials.append(mat)
current_object = utils.create_smooth_sphere(location=(-1.2, 0.0, 0.0), subdivision_level=2)
current_object.data.materials.append(mat)
bpy.ops.object.empty_add(location=(0.0, 0.0, 0.0))
focus_target = bpy.context.object
return focus_target
# 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])
# Scene Building
scene = bpy.data.scenes["Scene"]
world = scene.world
## Reset
utils.clean_objects()
## Object
focus_target = set_scene_objects()
## Camera
bpy.ops.object.camera_add(location=(0.0, -12.0, 0.0))
camera_object = bpy.context.object
utils.add_track_to_constraint(camera_object, focus_target)
utils.set_camera_params(camera_object.data, focus_target, lens=72, fstop=128.0)
## Background
utils.build_rgb_background(world, rgb=(0.89, 0.93, 1.00, 1.00))
## Composition
def build_scene_composition(scene):
scene.use_nodes = True
utils.clean_nodes(scene.node_tree.nodes)
render_layer_node = scene.node_tree.nodes.new(type="CompositorNodeRLayers")
filter_node = scene.node_tree.nodes.new(type="CompositorNodeFilter")
filter_node.filter_type = "SHARPEN"
filter_node.inputs["Fac"].default_value = 0.1
color_correction_node = scene.node_tree.nodes.new(type="CompositorNodeColorCorrection")
color_correction_node.master_saturation = 1.10
color_correction_node.master_gain = 1.20
color_correction_node.midtones_gain = 1.20
color_correction_node.shadows_gain = 1.50
split_tone_node = utils.create_split_tone_node(scene.node_tree)
split_tone_node.inputs["ShadowsHue"].default_value = 0.6
split_tone_node.inputs["ShadowsSaturation"].default_value = 0.1
composite_node = scene.node_tree.nodes.new(type="CompositorNodeComposite")
scene.node_tree.links.new(render_layer_node.outputs['Image'], filter_node.inputs['Image'])
scene.node_tree.links.new(filter_node.outputs['Image'], color_correction_node.inputs['Image'])
scene.node_tree.links.new(color_correction_node.outputs['Image'], split_tone_node.inputs['Image'])
scene.node_tree.links.new(split_tone_node.outputs['Image'], composite_node.inputs['Image'])
utils.arrange_nodes(scene.node_tree)
build_scene_composition(scene)
# Render Setting
utils.set_output_properties(scene, resolution_percentage, output_file_path)
utils.set_cycles_renderer(scene, camera_object, num_samples, use_denoising=False)