forked from soupday/cc_blender_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.py
345 lines (288 loc) · 18.4 KB
/
preferences.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
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
# Copyright (C) 2021 Victor Soupday
# This file is part of CC/iC Blender Tools <https://github.com/soupday/cc_blender_tools>
#
# CC/iC Blender Tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CC/iC Blender Tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CC/iC Blender Tools. If not, see <https://www.gnu.org/licenses/>.
import bpy
from . import addon_updater_ops, utils, vars
def reset_preferences():
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
prefs.render_target = "EEVEE"
prefs.lighting = "ENABLED"
prefs.physics = "ENABLED"
prefs.quality_lighting = "CC3"
prefs.pipeline_lighting = "CC3"
prefs.morph_lighting = "MATCAP"
prefs.quality_mode = "ADVANCED"
prefs.pipeline_mode = "ADVANCED"
prefs.morph_mode = "ADVANCED"
prefs.log_level = "ERRORS"
prefs.hair_hint = "hair,scalp,beard,mustache,sideburns,ponytail,braid,!bow,!band,!tie,!ribbon,!ring,!butterfly,!flower"
prefs.hair_scalp_hint = "scalp,base,skullcap"
prefs.debug_mode = False
prefs.physics_group = "CC_Physics"
prefs.refractive_eyes = "PARALLAX"
prefs.eye_displacement_group = "CC_Eye_Displacement"
prefs.max_texture_size = 4096
prefs.export_json_changes = True
prefs.export_texture_changes = True
prefs.export_bone_roll_fix = False
prefs.export_bake_nodes = False
prefs.export_bake_bump_to_normal = True
prefs.export_unity_remove_objects = True
prefs.export_texture_size = "2048"
prefs.export_require_key = True
prefs.export_revert_names = True
prefs.cycles_sss_skin_v118 = 0.35
prefs.cycles_sss_hair_v118 = 0.025
prefs.cycles_sss_teeth = 0.1
prefs.cycles_sss_tongue = 0.1
prefs.cycles_sss_eyes = 0.025
prefs.cycles_sss_default = 0.1
prefs.cycles_ssr_iris_brightness = 2.0
prefs.import_auto_convert = True
prefs.import_deduplicate = True
class CC3OperatorPreferences(bpy.types.Operator):
"""CC3 Preferences Functions"""
bl_idname = "cc3.setpreferences"
bl_label = "CC3 Preferences Functions"
bl_options = {"REGISTER", "UNDO", "INTERNAL"}
param: bpy.props.StringProperty(
name = "param",
default = ""
)
def execute(self, context):
if self.param == "RESET_PREFS":
reset_preferences()
return {"FINISHED"}
@classmethod
def description(cls, context, properties):
if properties.param == "RESET_PREFS":
return "Reset preferences to defaults"
return ""
class CC3ToolsAddonPreferences(bpy.types.AddonPreferences):
# this must match the add-on name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__.partition(".")[0]
lighting: bpy.props.EnumProperty(items=[
("DISABLED","Disabled","No automatic lighting and render settings."),
("ENABLED","Enabled","Allows automatic lighting and render settings."),
], default="ENABLED", name = "Automatic Lighting")
physics: bpy.props.EnumProperty(items=[
("DISABLED","Disabled","No physics auto setup."),
("ENABLED","Enabled","Allows automatic physics setup from physX weight maps."),
], default="ENABLED", name = "Generate Physics")
quality_lighting: bpy.props.EnumProperty(items=[
("BLENDER","Blender Default","Blenders default lighting setup"),
("MATCAP","Solid Matcap","Solid shading matcap lighting for sculpting / mesh editing"),
("CC3","CC3 Default","Replica of CC3 default lighting setup"),
("STUDIO","Studio Right","Right facing 3 point lighting with the studio hdri"),
("COURTYARD","Courtyard Left","Left facing soft 3 point lighting with the courtyard hdri"),
], default="CC3", name = "Render / Quality Lighting")
pipeline_lighting: bpy.props.EnumProperty(items=[
("BLENDER","Blender Default","Blenders default lighting setup"),
("MATCAP","Solid Matcap","Solid shading matcap lighting for sculpting / mesh editing"),
("CC3","CC3 Default","Replica of CC3 default lighting setup"),
("STUDIO","Studio Right","Right facing 3 point lighting with the studio hdri"),
("COURTYARD","Courtyard Left","Left facing soft 3 point lighting with the courtyard hdri"),
], default="CC3", name = "(FBX) Accessory Editing Lighting")
morph_lighting: bpy.props.EnumProperty(items=[
("BLENDER","Blender Default","Blenders default lighting setup"),
("MATCAP","Solid Matcap","Solid shading matcap lighting for sculpting / mesh editing"),
("CC3","CC3 Default","Replica of CC3 default lighting setup"),
("STUDIO","Studio Right","Right facing 3 point lighting with the studio hdri"),
("COURTYARD","Courtyard Left","Left facing soft 3 point lighting with the courtyard hdri"),
], default="MATCAP", name = "(OBJ) Morph Edit Lighting")
quality_mode: bpy.props.EnumProperty(items=[
("BASIC","Basic Materials","Build basic PBR materials for quality / rendering"),
("ADVANCED","Advanced Materials","Build advanced materials for quality / rendering"),
], default="ADVANCED", name = "Render / Quality Material Mode")
# = accessory_mode
pipeline_mode: bpy.props.EnumProperty(items=[
("BASIC","Basic Materials","Build basic PBR materials for character morph / accessory editing"),
("ADVANCED","Advanced Materials","Build advanced materials for character morph / accessory editing"),
], default="ADVANCED", name = "Accessory Material Mode")
morph_mode: bpy.props.EnumProperty(items=[
("BASIC","Basic Materials","Build basic PBR materials for character morph / accessory editing"),
("ADVANCED","Advanced Materials","Build advanced materials for character morph / accessory editing"),
], default="ADVANCED", name = "Character Morph Material Mode")
log_level: bpy.props.EnumProperty(items=[
("ALL","All","Log everything to console."),
("WARN","Warnings & Errors","Log warnings and error messages to console."),
("ERRORS","Just Errors","Log only errors to console."),
], default="ERRORS", name = "(Debug) Log Level")
render_target: bpy.props.EnumProperty(items=[
("EEVEE","Eevee","Build shaders for Eevee rendering."),
("CYCLES","Cycles","Build shaders for Cycles rendering."),
], default="EEVEE", name = "Target Renderer")
hair_hint: bpy.props.StringProperty(default="hair,scalp,beard,mustache,sideburns,ponytail,braid,!bow,!band,!tie,!ribbon,!ring,!butterfly,!flower", name="Hair detection keywords")
hair_scalp_hint: bpy.props.StringProperty(default="scalp,base,skullcap", name="Scalp detection keywords")
debug_mode: bpy.props.BoolProperty(default=False)
export_require_key: bpy.props.BoolProperty(default=True, name="Export Require Key", description="Ensure that exports back to CC3 have a valid Fbx/Obj Key file")
export_json_changes: bpy.props.BoolProperty(default=True, name="Material parameters", description="Export all material and shader parameter changes to the character Json data. Setting to False keeps original material and shader parameters.")
export_texture_changes: bpy.props.BoolProperty(default=True, name="Textures", description="Export all texture changes to the character Json data. Setting to False keeps original textures.")
export_bone_roll_fix: bpy.props.BoolProperty(default=False, name="Teeth bone fix", description="(Experimental) Apply zero roll to upper and lower teeth bones to fix teeth alignment problems re-importing to CC3")
export_bake_nodes: bpy.props.BoolProperty(default=True, name="Bake custom nodes", description="(Very Experimental) Bake any custom nodes (non texture image) attached to shader texture map sockets on export.")
export_bake_bump_to_normal: bpy.props.BoolProperty(default=True, name="Combine normals", description="(Very Experimental) When both a bump map and a normal is present, bake the bump map into the normal. (CC3 materials can only have one, normal map or bump map.)")
export_unity_remove_objects: bpy.props.BoolProperty(default=True, name="Unity: Remove non-character objects.", description="Removes all objects not attached to the character, when exporting to Unity.")
export_revert_names: bpy.props.BoolProperty(default=True, name="Revert names", description="Revert object and material names to match their original names from the source Json.")
export_unity_mode: bpy.props.EnumProperty(items=[
("BLEND","Blend File","Save the project as a blend file in a Unity project. All textures and folders will be copied to the new location and made relative to the blend file."),
("FBX","FBX","Export the character as an .Fbx file to the specified location. All textures and folders will be copied."),
], default="BLEND", name = "Unity Export")
export_non_standard_mode: bpy.props.EnumProperty(items=[
("HUMANOID","Humanoid","Export the selected armature and objects as a humanoid .Fbx file, with generated .json data for import into CC4 (Only)"),
("CREATURE","Creature","Export the selected armature and objects as a creature .Fbx file, with generated .json data for import into CC4 (Only)"),
("PROP","Prop","Export the selected objects as a prop .Fbx file, with generated .json data for import into CC4 (Only)"),
], default="HUMANOID", name = "Non-standard Export")
export_texture_size: bpy.props.EnumProperty(items=vars.ENUM_TEX_LIST, default="2048", description="Size of procedurally generated textures to bake")
physics_group: bpy.props.StringProperty(default="CC_Physics", name="Physics Vertex Group Prefix")
refractive_eyes: bpy.props.EnumProperty(items=[
("PARALLAX","Parallax Eye","(Experimental) Approximatated Parallax Refraction in a single cornea material which is not subject to Eevee limitations on Subsurface scattering and receiving shadows."),
("SSR","SSR Eye","Screen Space Refraction with a transmissive & transparent cornea material over an opaque eye (iris) material. SSR Materials do not receive full shadows and cannot have Subsurface scattering in Eevee."),
], default="SSR", name = "Refractive Eyes")
detail_sculpt_target: bpy.props.EnumProperty(items=[
("HEAD","Head","Sculpt on the head only"),
("BODY","Body","Sculpt on the body only"),
("ALL","All","Sculpt the entire body"),
], default="HEAD", name = "Sculpt Target")
detail_sculpt_level: bpy.props.IntProperty(default=4, min = 1, max = 6, name="Level")
body_sculpt_level: bpy.props.IntProperty(default=2, min = 1, max = 6, name="Level")
body_sculpt_apply_base: bpy.props.BoolProperty(default=False, name="Apply Base Shape", description="Apply sculpted shape to base topology on bake.")
detail_normal_bake_size: bpy.props.EnumProperty(items=vars.ENUM_TEX_LIST, default="4096", description="Resolution of detail sculpt normals to bake")
body_normal_bake_size: bpy.props.EnumProperty(items=vars.ENUM_TEX_LIST, default="2048", description="Resolution of full body sculpt normals to bake")
#refractive_eyes: bpy.props.BoolProperty(default=True, name="Refractive Eyes", description="Generate refractive eyes with iris depth and pupil scale parameters")
eye_displacement_group: bpy.props.StringProperty(default="CC_Eye_Displacement", name="Eye Displacement Group", description="Eye Iris displacement vertex group name")
max_texture_size: bpy.props.FloatProperty(default=4096, min=512, max=4096)
import_deduplicate: bpy.props.BoolProperty(default=True, name="De-duplicate Materials", description="Detects and re-uses duplicate textures and consolidates materials with same name, textures and parameters into a single material")
import_auto_convert: bpy.props.BoolProperty(default=True, name="Auto Convert Generic", description="When importing generic characters (GLTF, GLB, VRM or OBJ) automatically convert to Reallusion Non-Standard characters or props."
"Which sets up Reallusion import compatible materials and material parameters.")
cycles_sss_skin_v118: bpy.props.FloatProperty(default=0.35)
cycles_sss_hair_v118: bpy.props.FloatProperty(default=0.025)
cycles_sss_teeth: bpy.props.FloatProperty(default=0.1)
cycles_sss_tongue: bpy.props.FloatProperty(default=0.1)
cycles_sss_eyes: bpy.props.FloatProperty(default=0.025)
cycles_sss_default: bpy.props.FloatProperty(default=0.1)
cycles_ssr_iris_brightness: bpy.props.FloatProperty(default=2.0, min=0, max=4, description="Iris brightness mulitplier when rendering SSR eyes in Cycles")
# old
cycles_sss_skin: bpy.props.FloatProperty(default=0.2)
cycles_sss_hair: bpy.props.FloatProperty(default=0.05)
# hair
hair_export_group_by: bpy.props.EnumProperty(items=[
("CURVE","Curve","Group by curve objects"),
("NAME","Name","Gropu by name"),
("NONE","Single","Don't export separate groups"),
], default="CURVE", name = "Export Hair Grouping",
description="Export hair groups by...")
hair_curve_dir_threshold: bpy.props.FloatProperty(default=0.9, min=0.0, max=1.0, name="Direction Threshold")
hair_curve_dir: bpy.props.EnumProperty(items=[
("UP","UV Direction: Up","Hair cards from bottom to top in UV map"),
("DOWN","UV Direction: Down","Hair cards from top to bottom in UV map"),
("LEFT","UV Direction: Left","Hair cards from right to left in UV map"),
("RIGHT","UV Direction: Right","Hair cards from left to right in UV map"),
], default="DOWN", name = "UV Direction",
description="Export hair groups by...")
# addon updater preferences
auto_check_update: bpy.props.BoolProperty(
name="Auto-check for Update",
description="If enabled, auto-check for updates using an interval",
default=False,
)
updater_intrval_months: bpy.props.IntProperty(
name='Months',
description="Number of months between checking for updates",
default=0,
min=0
)
updater_intrval_days: bpy.props.IntProperty(
name='Days',
description="Number of days between checking for updates",
default=7,
min=0,
max=31
)
updater_intrval_hours: bpy.props.IntProperty(
name='Hours',
description="Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_intrval_minutes: bpy.props.IntProperty(
name='Minutes',
description="Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.label(text="Import:")
layout.prop(self, "import_deduplicate")
layout.prop(self, "import_auto_convert")
layout.label(text="Rendering:")
layout.prop(self, "render_target")
layout.label(text="Material settings:")
layout.prop(self, "quality_mode")
layout.prop(self, "pipeline_mode")
layout.prop(self, "morph_mode")
layout.label(text="Lighting:")
layout.prop(self, "lighting")
if self.lighting == "ENABLED":
layout.prop(self, "quality_lighting")
layout.prop(self, "pipeline_lighting")
layout.prop(self, "morph_lighting")
layout.label(text="Detection:")
layout.prop(self, "hair_hint")
layout.prop(self, "hair_scalp_hint")
layout.label(text="Eyes:")
layout.prop(self, "refractive_eyes")
layout.prop(self, "eye_displacement_group")
layout.label(text="Cycles Adjustments:")
layout.prop(self, "cycles_sss_skin_v118")
layout.prop(self, "cycles_sss_hair_v118")
layout.prop(self, "cycles_sss_teeth")
layout.prop(self, "cycles_sss_tongue")
layout.prop(self, "cycles_sss_eyes")
layout.prop(self, "cycles_sss_default")
layout.prop(self, "cycles_ssr_iris_brightness")
layout.label(text="Physics:")
layout.prop(self, "physics")
layout.prop(self, "physics_group")
layout.label(text="Export:")
layout.prop(self, "export_json_changes")
layout.prop(self, "export_texture_changes")
layout.prop(self, "export_bone_roll_fix")
layout.prop(self, "export_bake_nodes")
layout.prop(self, "export_bake_bump_to_normal")
layout.prop(self, "export_unity_remove_objects")
layout.prop(self, "export_texture_size")
layout.prop(self, "export_require_key")
layout.label(text="Debug Settings:")
layout.prop(self, "log_level")
op = layout.operator("cc3.setpreferences", icon="FILE_REFRESH", text="Reset to Defaults")
op.param = "RESET_PREFS"
addon_updater_ops.update_settings_ui(self,context)
class MATERIAL_UL_weightedmatslots(bpy.types.UIList):
def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
slot = item
ma = slot.material
if self.layout_type in {'DEFAULT', 'COMPACT'}:
if ma:
layout.prop(ma, "name", text="", emboss=False, icon_value=icon)
else:
layout.label(text="", icon_value=icon)
elif self.layout_type == 'GRID':
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)