-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpbaker_list.py
227 lines (170 loc) · 6.53 KB
/
pbaker_list.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import bpy
from bpy.props import BoolProperty, StringProperty
from bpy.types import Operator, PropertyGroup, UIList
from .pbaker_functions import *
# 2.79 - OrderedDict
# TODO throw out with future 2.8+ only verion
if is_2_79:
from collections import OrderedDict
JOBLIST = OrderedDict([
("Color", "_color"),
("Metallic", "_metallic"),
("Roughness", "_roughness"),
("Normal", "_normal"),
#("Bump", "_bump"),
("Displacement", "_disp"),
("Alpha", "_alpha"),
("Emission", "_emission"),
# ('Ambient Occlusion', "_ao"), # not in 2.79
("Subsurface", "_subsurface"),
("Subsurface Radius", "_subsurface_radius"),
("Subsurface Color", "_subsurface_color"),
("Specular", "_specular"),
("Specular Tint", "_specular_tint"),
("Anisotropic", "_anisotropic"),
("Anisotropic Rotation", "_anisotropic_rotation"),
("Sheen", "_sheen"),
("Sheen Tint", "_sheen_tint"),
("Clearcoat", "_clearcoat"),
("Clearcoat Roughness", "_clearcoat_roughness"),
("IOR", "_ior"),
("Transmission", "_transmission"),
("Transmission Roughness", "_transmission_roughness"),
("Clearcoat Normal", "_clearcoat_normal"),
("Tangent", "_tangent")
])
else:
JOBLIST = {
"Color": "_color",
"Metallic": "_metallic",
"Roughness": "_roughness",
"Normal": "_normal",
# "Bump": "_bump",
"Displacement": "_disp",
"Alpha": "_alpha",
"Emission": "_emission",
'Ambient Occlusion': "_ao",
"Subsurface": "_subsurface",
"Subsurface Radius": "_subsurface_radius",
"Subsurface Color": "_subsurface_color",
"Specular": "_specular",
"Specular Tint": "_specular_tint",
"Anisotropic": "_anisotropic",
"Anisotropic Rotation": "_anisotropic_rotation",
"Sheen": "_sheen",
"Sheen Tint": "_sheen_tint",
"Clearcoat": "_clearcoat",
"Clearcoat Roughness": "_clearcoat_roughness",
"IOR": "_ior",
"Transmission": "_transmission",
"Transmission Roughness": "_transmission_roughness",
"Clearcoat Normal": "_clearcoat_normal",
"Tangent": "_tangent",
}
# JOBLIST_SHORT = { # TODO
# "Color": "_color",
# "Metallic": "_metallic",
# "Roughness": "_roughness",
# "Normal": "_normal",
# "Bump": "_bump",
# "Displacement": "_disp",
# "Alpha": "_alpha",
# "Emission": "_emission",
# 'Ambient Occlusion': "_ao",
# }
class PBAKER_ListItem(PropertyGroup):
suffix= StringProperty(name="Suffix")
do_bake= BoolProperty(
name="",
default=False)
class PBAKER_UL_List(UIList):
def draw_item(self, context, layout, data, item, icon, active_data,
active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.prop(item, "do_bake")
layout.label(text=item.name)
layout.prop(item, "suffix", text="")
class PBAKER_BAKELIST_OT_Init(Operator):
bl_idname = "principled_baker_bakelist.init"
bl_label = "Init Bakelist"
def execute(self, context):
bake_list = context.scene.principled_baker_bakelist
for job_name, suffix in JOBLIST.items():
item = bake_list.add()
item.name = job_name
item.suffix = suffix
return{'FINISHED'}
class PBAKER_BAKELIST_OT_Delete(Operator):
bl_idname = "principled_baker_bakelist.delete"
bl_label = "Delete Bakelist"
@classmethod
def poll(cls, context):
return context.scene.principled_baker_bakelist
def execute(self, context):
principled_baker_bakelist = context.scene.principled_baker_bakelist.clear()
return{'FINISHED'}
class PBAKER_BAKELIST_OT_Update(Operator):
"""Detect Bake Types from Selected Objects"""
bl_idname = "principled_baker_bakelist.update"
bl_label = "Update Bakelist"
def execute(self, context):
if not context.scene.principled_baker_bakelist:
bpy.ops.principled_baker_bakelist.init()
bakelist = context.scene.principled_baker_bakelist
temp_joblist = get_joblist_from_objects(context.selected_objects)
for item_name, item in bakelist.items():
if item_name in temp_joblist:
item.do_bake = True
else:
item.do_bake = False
return{'FINISHED'}
class PBAKER_BAKELIST_OT_Reset(Operator):
"""Reset list including suffixes"""
bl_idname = "principled_baker_bakelist.reset"
bl_label = "Update Bakelist"
def execute(self, context):
if context.scene.principled_baker_bakelist:
bpy.ops.principled_baker_bakelist.delete()
bpy.ops.principled_baker_bakelist.init()
return{'FINISHED'}
class PBAKER_BAKELIST_OT_Disable_All(Operator):
"""Disable all"""
bl_idname = "principled_baker_bakelist.disable_all"
bl_label = "Disable All"
def execute(self, context):
bakelist = context.scene.principled_baker_bakelist
for item_name, item in bakelist.items():
item.do_bake = False
return{'FINISHED'}
class PBAKER_BAKELIST_OT_MoveItem_Up(Operator):
bl_idname = "principled_baker_bakelist.move_up"
bl_label = "Up"
@classmethod
def poll(cls, context):
return context.scene.principled_baker_bakelist
def execute(self, context):
principled_baker_bakelist = context.scene.principled_baker_bakelist
index = bpy.context.scene.principled_baker_bakelist_index
prev_index = index - 1
principled_baker_bakelist.move(prev_index, index)
new_index = index - 1
list_len = len(principled_baker_bakelist)
bpy.context.scene.principled_baker_bakelist_index = max(
0, min(new_index, list_len - 1))
return{'FINISHED'}
class PBAKER_BAKELIST_OT_MoveItem_Down(Operator):
bl_idname = "principled_baker_bakelist.move_down"
bl_label = "Down"
@classmethod
def poll(cls, context):
return context.scene.principled_baker_bakelist
def execute(self, context):
principled_baker_bakelist = context.scene.principled_baker_bakelist
index = bpy.context.scene.principled_baker_bakelist_index
next_index = index + 1
principled_baker_bakelist.move(next_index, index)
new_index = index + 1
list_len = len(principled_baker_bakelist)
bpy.context.scene.principled_baker_bakelist_index = max(
0, min(new_index, list_len - 1))
return{'FINISHED'}