-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
preferences.py
253 lines (216 loc) · 9.08 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
import bpy
from bpy.props import *
from bpy.types import AddonPreferences
from bpy.app.handlers import persistent
from . import image_ops
from .common import *
from .lib import *
from .UDIM import *
def update_icons(self, context):
unload_custom_icons()
load_custom_icons()
class YPaintPreferences(AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __package__
default_new_image_size : IntProperty(
name = 'Custom Default Image Size',
description = 'Default new image size',
default=1024, min=64, max=16384
)
image_atlas_size : IntProperty(
name = 'Image Atlas Size',
description = 'Image Atlas Size',
default=8192, min=2048, max=16384
)
hdr_image_atlas_size : IntProperty(
name = 'HDR Image Atlas Size',
description = 'HDR Image Atlas Size',
default=4096, min=1024, max=8192
)
unique_image_atlas_per_yp : BoolProperty(
name = 'Use unique Image Atlas per ' + get_addon_title() + ' tree',
description = 'Try to use different image atlas per ' + get_addon_title() + ' tree',
default = True
)
developer_mode : BoolProperty(
name = 'Developer Mode',
description = 'Developer mode will shows several menu intented for developer only',
default = False
)
show_experimental : BoolProperty(
name = 'Show Experimental Features',
description = 'Show unfinished experimental features',
default = False
)
use_image_preview : BoolProperty(
name = 'Use Image Preview/Thumbnail',
description = 'Use image preview or thumbnail on the layers list',
default = False
)
skip_property_popups : BoolProperty(
name = 'Skip Property Popups (Hold Shift to Show)',
description = 'Don\'t show property popups unless Shift key is pressed. Will use last invokation properties if skipped',
default = False
)
icons : EnumProperty(
name = 'Icons',
description = 'Icon set',
items = (
('DEFAULT', 'Default', 'Icon set from the current Blender version'),
('LEGACY', 'Legacy', 'Icon set from the old Blender version')
),
default = 'DEFAULT',
update = update_icons
)
make_preview_mode_srgb : BoolProperty(
name = 'Make Preview Mode use sRGB',
description = 'Make sure preview mode use sRGB color',
default = True
)
parallax_without_baked : BoolProperty(
name = 'Parallax Without Use Baked',
description = 'Make it possible to use parallax without using baked textures (currently VERY SLOW)',
default = False
)
default_bake_device : EnumProperty(
name = 'Bake Device',
description = 'Default bake device',
items = (
('DEFAULT', 'Default', 'Use last selected bake device'),
('CPU', 'CPU', 'Use CPU by default'),
('GPU', 'GPU Compute', 'Use GPU by default')
),
default = 'DEFAULT'
)
enable_baked_outside_by_default : BoolProperty(
name = 'Enable Baked Outside by default',
description = "Enable baked outside by default when creating new " + get_addon_title() + " node.\n(Useful for creating game assets)",
default = False
)
enable_uniform_uv_scale_by_default : BoolProperty(
name = 'Enable Uniform UV Scale by default',
description = "Enable uniform UV scale by default in Layer and Mask UVs. This will make all scale axes have the same value",
default = False
)
enable_auto_udim_detection : BoolProperty(
name = 'Enable Auto UDIM Detection',
description = "Enable automatic UDIM detection. This will automatically check 'Use UDIM Tiles' checkboxes when UDIM is detected",
default = True
)
# Addon updater preferences.
auto_check_update : BoolProperty(
name = 'Auto-check for Update',
description = 'If enabled, auto-check for updates using an interval',
default = True
)
updater_interval_months : IntProperty(
name = 'Months',
description = 'Number of months between checking for updates',
default=0, min=0
)
updater_interval_days : IntProperty(
name = 'Days',
description = 'Number of days between checking for updates',
default=1, min=0, max=31
)
updater_interval_hours : IntProperty(
name = 'Hours',
description = 'Number of hours between checking for updates',
default=0, min=0, max=23
)
updater_interval_minutes : IntProperty(
name = 'Minutes',
description = 'Number of minutes between checking for updates',
default=1, min=0, max=59
)
default_image_resolution : EnumProperty(
name = 'Default Image Size',
items = (
('DEFAULT', "Default", 'Use the last selected image size'),
('512', "512", 'Always use a 512x512 image by default'),
('1024', "1024", 'Always use a 1024x1024 image by default'),
('2048', "2048", 'Always use a 2048x2048 image by default'),
('4096', "4096", 'Always use a 4096x4096 image by default'),
('CUSTOM', "Custom Resolution", 'Use a custom resolution by default')
),
default = 'DEFAULT'
)
def draw(self, context):
if is_bl_newer_than(2, 80):
self.layout.prop(self, 'default_bake_device')
self.layout.prop(self, 'icons')
self.layout.prop(self, 'default_image_resolution')
if self.default_image_resolution == 'CUSTOM':
self.layout.prop(self, 'default_new_image_size')
self.layout.prop(self, 'image_atlas_size')
self.layout.prop(self, 'hdr_image_atlas_size')
self.layout.prop(self, 'unique_image_atlas_per_yp')
self.layout.prop(self, 'make_preview_mode_srgb')
self.layout.prop(self, 'use_image_preview')
self.layout.prop(self, 'skip_property_popups')
self.layout.prop(self, 'enable_baked_outside_by_default')
if is_bl_newer_than(2, 81):
self.layout.prop(self, 'enable_uniform_uv_scale_by_default')
if is_udim_supported():
self.layout.prop(self, 'enable_auto_udim_detection')
self.layout.prop(self, 'show_experimental')
self.layout.prop(self, 'developer_mode')
#self.layout.prop(self, 'parallax_without_baked')
if self.developer_mode:
box = self.layout.box()
box.prop(self, "auto_check_update")
sub_col = box.column()
if not self.auto_check_update:
sub_col.enabled = False
sub_row = sub_col.row()
sub_row.label(text="Interval between checks")
sub_row = sub_col.row(align=True)
check_col = sub_row.column(align=True)
check_col.prop(self, "updater_interval_days")
check_col = sub_row.column(align=True)
check_col.prop(self, "updater_interval_hours")
check_col = sub_row.column(align=True)
check_col.prop(self, "updater_interval_minutes")
check_col = sub_row.column(align=True)
@persistent
def auto_save_images(scene):
ypup = get_user_preferences()
for tree in bpy.data.node_groups:
if not hasattr(tree, 'yp'): continue
if tree.yp.is_ypaint_node:
image_ops.save_pack_all(tree.yp)
# NOTE: Version update only happen when loading the blend file or updating the node tree
# Update version
#try: tree.yp.version = get_current_version_str()
#except: print('EXCEPTIION: Cannot save yp version!')
#try: tree.yp.blender_version = get_current_blender_version_str()
#except: print('EXCEPTIION: Cannot save blender version!')
#try: tree.yp.is_unstable = get_alpha_suffix() != ''
#except: print('EXCEPTIION: Cannot save unstable version flag!')
# HACK: For some reason active float image will glitch after auto save
# This hack will fix that
@persistent
def refresh_float_image_hack(scene):
ypui = bpy.context.window_manager.ypui
if ypui.refresh_image_hack:
node = get_active_ypaint_node()
if node:
yp = node.node_tree.yp
if len(yp.layers) > 0:
layer = yp.layers[yp.active_layer_index]
source = get_layer_source(layer)
if source.type == 'TEX_IMAGE' and source.image:
# Just reload image to fix glitched float image
print("INFO: Just ignore error below if there's any, this is fine..")
source.image.reload()
print('INFO: ..fine error ended')
ypui.refresh_image_hack = False
def register():
bpy.utils.register_class(YPaintPreferences)
bpy.app.handlers.save_pre.append(auto_save_images)
bpy.app.handlers.save_post.append(refresh_float_image_hack)
def unregister():
bpy.utils.unregister_class(YPaintPreferences)
bpy.app.handlers.save_pre.remove(auto_save_images)
bpy.app.handlers.save_post.remove(refresh_float_image_hack)