-
Notifications
You must be signed in to change notification settings - Fork 109
/
07_texturing.py
134 lines (108 loc) · 5.71 KB
/
07_texturing.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# blender --background --python 07_texturing.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
# Define paths for the PBR textures used in this scene
texture_paths = {
"Leather05": {
"ambient_occlusion": "",
"color": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Leather05/Leather05_col.jpg"),
"displacement": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Leather05/Leather05_disp.jpg"),
"metallic": "",
"normal": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Leather05/Leather05_nrm.jpg"),
"roughness": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Leather05/Leather05_rgh.jpg"),
},
"Metal07": {
"ambient_occlusion": "",
"color": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Metal07/Metal07_col.jpg"),
"displacement": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Metal07/Metal07_disp.jpg"),
"metallic": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Metal07/Metal07_met.jpg"),
"normal": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Metal07/Metal07_nrm.jpg"),
"roughness": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Metal07/Metal07_rgh.jpg"),
},
"Fabric02": {
"ambient_occlusion": "",
"color": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Fabric02/Fabric02_col.jpg"),
"displacement": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Fabric02/Fabric02_disp.jpg"),
"metallic": "",
"normal": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Fabric02/Fabric02_nrm.jpg"),
"roughness": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Fabric02/Fabric02_rgh.jpg"),
},
"Marble01": {
"ambient_occlusion": "",
"color": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Marble01/Marble01_col.jpg"),
"displacement": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Marble01/Marble01_disp.jpg"),
"metallic": "",
"normal": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Marble01/Marble01_nrm.jpg"),
"roughness": os.path.join(working_dir_path, "assets/cc0textures.com/[2K]Marble01/Marble01_rgh.jpg"),
},
}
def add_named_material(name: str, scale=(1.0, 1.0, 1.0), displacement_scale: float = 1.0) -> bpy.types.Material:
mat = utils.add_material(name, use_nodes=True, make_node_tree_empty=True)
utils.build_pbr_textured_nodes(mat.node_tree,
color_texture_path=texture_paths[name]["color"],
roughness_texture_path=texture_paths[name]["roughness"],
normal_texture_path=texture_paths[name]["normal"],
metallic_texture_path=texture_paths[name]["metallic"],
displacement_texture_path=texture_paths[name]["displacement"],
ambient_occlusion_texture_path=texture_paths[name]["ambient_occlusion"],
scale=scale,
displacement_scale=displacement_scale)
return mat
def set_scene_objects():
add_named_material("Leather05")
add_named_material("Metal07")
add_named_material("Fabric02")
add_named_material("Marble01", displacement_scale=0.02)
left_object, center_object, right_object = utils.create_three_smooth_monkeys()
left_object.data.materials.append(bpy.data.materials["Leather05"])
center_object.data.materials.append(bpy.data.materials["Metal07"])
right_object.data.materials.append(bpy.data.materials["Fabric02"])
current_object = utils.create_plane(size=12.0, name="Floor")
current_object.data.materials.append(bpy.data.materials["Marble01"])
current_object = utils.create_plane(size=12.0,
location=(0.0, 4.0, 0.0),
rotation=(math.pi * 90.0 / 180.0, 0.0, 0.0),
name="Wall")
current_object.data.materials.append(bpy.data.materials["Marble01"])
bpy.ops.object.empty_add(location=(0.0, -0.70, 1.0))
focus_target = bpy.context.object
return focus_target
def set_camera_params(camera, dof_target):
camera.data.sensor_fit = 'HORIZONTAL'
camera.data.sensor_width = 36.0
camera.data.sensor_height = 24.0
camera.data.lens = 72
camera.data.dof_object = dof_target
camera.data.cycles.aperture_type = 'RADIUS'
camera.data.cycles.aperture_size = 0.100
camera.data.cycles.aperture_blades = 6
# 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
focus_target = set_scene_objects()
## Camera
bpy.ops.object.camera_add(location=(0.0, -16.0, 2.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=85, fstop=0.5)
## Lights
utils.build_environment_texture_background(world, hdri_path)
## Composition
utils.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)