-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbake_gui.py
More file actions
378 lines (327 loc) · 11.3 KB
/
bake_gui.py
File metadata and controls
378 lines (327 loc) · 11.3 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import bpy
from . import bake_operators
from . import addon_updater_ops
class BakeSettings(bpy.types.PropertyGroup):
SimpleMode : bpy.props.BoolProperty(
name="Simple mode",
description="Simple mode",
default=True
)
SaveToFile : bpy.props.BoolProperty(
name="Save to file",
description="Save bake(s) to png files, relative to .blend",
default=False
)
UseCage : bpy.props.BoolProperty(
name="Use cage",
description="Cast rays to active object from cage",
default=False
)
CageObject : bpy.props.PointerProperty(
name="Cage object",
description="Cage object to use instead of calculating the cage from the active object with cage extrusion",
type=bpy.types.Object
)
LowpolyObject : bpy.props.PointerProperty(
name="Lowpoly object",
description="Target object to bake to",
type=bpy.types.Object
)
def TargetMaterialItems(self, context):
items = []
for index, mat in enumerate(context.scene.zodeutils_bake.LowpolyObject.material_slots):
items.append((mat.name, mat.name, ""))
return items
TargetMaterial : bpy.props.EnumProperty(
name="Target material",
description="Target material in lowpoly object to bake to",
items=TargetMaterialItems
)
HighpolyObject : bpy.props.PointerProperty(
name="Highpoly object",
description="Target object to bake from",
type=bpy.types.Object
)
TargetWidth : bpy.props.IntProperty(
name="Width",
description="Bake texture width",
default=1024,
min=1
)
TargetHeight : bpy.props.IntProperty(
name="Height",
description="Bake texture Height",
default=1024,
min=1
)
RayDistance : bpy.props.FloatProperty(
name="Ray distance",
description="Distance to use for the inward ray cast",
default=0.1,
min=0.0,
max=1.0
)
BakeAO : bpy.props.BoolProperty(
name="Bake AO",
description="Enable or Disable ambient occlusion baking",
default=False
)
BakeShadow : bpy.props.BoolProperty(
name="Bake shadow",
description="Enable or Disable shadow baking",
default=False
)
BakeNormal : bpy.props.BoolProperty(
name="Bake normals",
description="Enable or Disable normal baking",
default=True
)
NormalSpace : bpy.props.EnumProperty(
name="Space",
description="Space to bake in",
items=(
("OBJECT", "Object", "Object space"),
("TANGENT", "Tangent", "Tangent space"),
),
default="TANGENT"
)
NormalR : bpy.props.EnumProperty(
name="R",
description="Axis to bake red channel in",
items=(
("POS_X", "+X", ""),
("POS_Y", "+Y", ""),
("POS_Z", "+Z", ""),
("NEG_X", "-X", ""),
("NEG_Y", "-Y", ""),
("NEG_Z", "-Z", ""),
),
default="POS_X"
)
NormalG : bpy.props.EnumProperty(
name="G",
description="Axis to bake green channel in",
items=(
("POS_X", "+X", ""),
("POS_Y", "+Y", ""),
("POS_Z", "+Z", ""),
("NEG_X", "-X", ""),
("NEG_Y", "-Y", ""),
("NEG_Z", "-Z", ""),
),
default="POS_Y"
)
NormalB : bpy.props.EnumProperty(
name="B",
description="Axis to bake blue channel in",
items=(
("POS_X", "+X", ""),
("POS_Y", "+Y", ""),
("POS_Z", "+Z", ""),
("NEG_X", "-X", ""),
("NEG_Y", "-Y", ""),
("NEG_Z", "-Z", ""),
),
default="POS_Z"
)
BakeUV : bpy.props.BoolProperty(
name="Bake UV",
description="Enable or Disable UV baking",
default=False
)
BakeRoughness : bpy.props.BoolProperty(
name="Bake roughness",
description="Enable or Disable roughness baking",
default=False
)
BakeEmit : bpy.props.BoolProperty(
name="Bake emit",
description="Enable or Disable emit baking",
default=False
)
BakeEnvironment : bpy.props.BoolProperty(
name="Bake environment",
description="Enable or Disable environment baking",
default=False
)
BakeDiffuse : bpy.props.BoolProperty(
name="Bake diffuse",
description="Enable or Disable diffuse baking",
default=False
)
DiffuseFlags : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIRECT", "Direct", "Add direct lighting contribution"),
("INDIRECT", "Inirect", "Add indirect lighting contribution"),
("COLOR", "Color", "Color the pass")
),
options = {"ENUM_FLAG"},
default={"DIRECT", "INDIRECT", "COLOR"}
)
BakeGlossy : bpy.props.BoolProperty(
name="Bake glossy",
description="Enable or Disable glossy baking",
default=False
)
GlossyFlags : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIRECT", "Direct", "Add direct lighting contribution"),
("INDIRECT", "Inirect", "Add indirect lighting contribution"),
("COLOR", "Color", "Color the pass")
),
options = {"ENUM_FLAG"},
default={"DIRECT", "INDIRECT", "COLOR"}
)
BakeTransmission : bpy.props.BoolProperty(
name="Bake transmission",
description="Enable or Disable transmission baking",
default=False
)
TransmissionFlags : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIRECT", "Direct", "Add direct lighting contribution"),
("INDIRECT", "Inirect", "Add indirect lighting contribution"),
("COLOR", "Color", "Color the pass")
),
options = {"ENUM_FLAG"},
default={"DIRECT", "INDIRECT", "COLOR"}
)
BakeSubsurface : bpy.props.BoolProperty(
name="Bake subsurface",
description="Enable or Disable subsurface baking",
default=False
)
SubsurfaceFlags : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIRECT", "Direct", "Add direct lighting contribution"),
("INDIRECT", "Inirect", "Add indirect lighting contribution"),
("COLOR", "Color", "Color the pass")
),
options = {"ENUM_FLAG"},
default={"DIRECT", "INDIRECT", "COLOR"}
)
BakeCombined : bpy.props.BoolProperty(
name="Bake combined",
description="Enable or Disable combined baking",
default=False
)
CombinedFlags : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIRECT", "Direct", "Add direct lighting contribution"),
("INDIRECT", "Inirect", "Add indirect lighting contribution")
),
options = {"ENUM_FLAG"},
default={"DIRECT", "INDIRECT"}
)
CombinedFilter : bpy.props.EnumProperty(
name="Influence",
description="Set influences",
items=(
("DIFFUSE", "Diffuse", "Add diffuse contribution"),
("GLOSSY", "Glossy", "Add glossy contribution"),
("TRANSMISSION", "Transmission", "Add transmission contribution"),
("SUBSURFACE", "Subsurface", "Add subsurface contribution"),
("AO", "Ambient Occlusion", "Add ambient occlusion contribution"),
("EMIT", "Emit", "Add emission contribution"),
),
options = {"ENUM_FLAG"},
default={"DIFFUSE", "GLOSSY", "TRANSMISSION", "SUBSURFACE", "AO", "EMIT"}
)
class ZODEUTILS_BAKE(bpy.types.Panel):
bl_label="Zode's bakery"
bl_idname="OBJECT_PT_ZODEUTILS_BAKE"
bl_category="Bake"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
self.layout.prop(context.scene.zodeutils_bake, "SimpleMode")
box = self.layout.box()
box.label(text="Bake settings:")
box.prop(context.scene.zodeutils_bake, "HighpolyObject")
box.prop(context.scene.zodeutils_bake, "LowpolyObject")
box.prop(context.scene.zodeutils_bake, "TargetMaterial")
row = box.row()
row.prop(context.scene.zodeutils_bake, "TargetWidth")
row.prop(context.scene.zodeutils_bake, "TargetHeight")
row = box.row()
row.prop(context.scene.zodeutils_bake, "RayDistance")
row.prop(context.scene.zodeutils_bake, "SaveToFile")
box.prop(context.scene.zodeutils_bake, "UseCage")
if context.scene.zodeutils_bake.UseCage:
box.prop(context.scene.zodeutils_bake, "CageObject")
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeAO", icon=bake_operators.GetIconForBake("AO"))
row.prop(context.scene.zodeutils_bake, "BakeShadow", icon=bake_operators.GetIconForBake("SHADOW"))
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeNormal", icon=bake_operators.GetIconForBake("NORMAL"))
row.prop(context.scene.zodeutils_bake, "BakeUV", icon=bake_operators.GetIconForBake("UV"))
if context.scene.zodeutils_bake.BakeNormal and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Normal bake settings:")
box.prop(context.scene.zodeutils_bake, "NormalSpace")
row = box.row()
row.prop(context.scene.zodeutils_bake, "NormalR")
row.prop(context.scene.zodeutils_bake, "NormalG")
row.prop(context.scene.zodeutils_bake, "NormalB")
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeRoughness", icon=bake_operators.GetIconForBake("ROUGHNESS"))
row.prop(context.scene.zodeutils_bake, "BakeEmit", icon=bake_operators.GetIconForBake("EMIT"))
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeEnvironment", icon=bake_operators.GetIconForBake("ENVIRONMENT"))
row.prop(context.scene.zodeutils_bake, "BakeDiffuse", icon=bake_operators.GetIconForBake("DIFFUSE"))
if context.scene.zodeutils_bake.BakeDiffuse and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Diffuse bake settings:")
box.row().prop(context.scene.zodeutils_bake, "DiffuseFlags", expand=True)
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeGlossy", icon=bake_operators.GetIconForBake("GLOSSY"))
row.prop(context.scene.zodeutils_bake, "BakeTransmission", icon=bake_operators.GetIconForBake("TRANSMISSION"))
if context.scene.zodeutils_bake.BakeGlossy and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Glossy bake settings:")
box.row().prop(context.scene.zodeutils_bake, "GlossyFlags", expand=True)
if context.scene.zodeutils_bake.BakeTransmission and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Transmission bake settings:")
box.row().prop(context.scene.zodeutils_bake, "TransmissionFlags", expand=True)
row = self.layout.row()
row.prop(context.scene.zodeutils_bake, "BakeSubsurface", icon=bake_operators.GetIconForBake("SUBSURFACE"))
row.prop(context.scene.zodeutils_bake, "BakeCombined", icon=bake_operators.GetIconForBake("COMBINED"))
if context.scene.zodeutils_bake.BakeSubsurface and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Subsurface bake settings:")
box.row().prop(context.scene.zodeutils_bake, "SubsurfaceFlags", expand=True)
if context.scene.zodeutils_bake.BakeCombined and not context.scene.zodeutils_bake.SimpleMode:
box = self.layout.box()
box.label(text="Combined bake settings:")
box.row().prop(context.scene.zodeutils_bake, "CombinedFlags", expand=True)
box.prop(context.scene.zodeutils_bake, "CombinedFilter", expand=True)
self.layout.separator()
if context.scene.render.engine != "CYCLES":
self.layout.label(text="Render engine is not set to cycles!", icon="ERROR")
self.layout.operator("zodeutils.bake_fix_engine", icon="MODIFIER")
self.layout.separator()
self.layout.operator("zodeutils.bake", icon="TEXTURE")
addon_updater_ops.check_for_update_background()
if addon_updater_ops.updater.update_ready:
addon_updater_ops.update_notice_box_ui(self, context)
def register():
bpy.utils.register_class(BakeSettings)
bpy.types.Scene.zodeutils_bake = bpy.props.PointerProperty(type=BakeSettings)
bpy.utils.register_class(ZODEUTILS_BAKE)
bake_operators.register()
def unregister():
del bpy.types.Scene.zodeutils_bake
bpy.utils.unregister_class(BakeSettings)
bpy.utils.unregister_class(ZODEUTILS_BAKE)
bake_operators.unregister()