Repository navigation
Expand file tree
/
Copy pathproperties.py
More file actions
424 lines (339 loc) · 15.1 KB
/
Copy pathproperties.py
File metadata and controls
424 lines (339 loc) · 15.1 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
import bpy
from bpy.types import AddonPreferences, PropertyGroup
from .update import *
from .image_format_properties import PAK_ImageFormat
from bpy.props import (
IntProperty,
FloatProperty,
BoolProperty,
StringProperty,
PointerProperty,
CollectionProperty,
EnumProperty,
)
def GetExportLocations(scene, context):
items = [
('0', "None", "No export location has been set", 0),
]
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return items
for i,x in enumerate(file_data.locations):
items.append((str(i+1), x.name, x.name, i+1))
return items
def GetImageFormats(scene, context):
items = [
('0', "Original Format", "The image will be saved with the same format and settings as the original image", 0),
]
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return items
for i,x in enumerate(file_data.formats):
items.append((str(i+1), x.name, x.name, i+1))
return items
class PAK_Image(PropertyGroup):
"""
Define an object as a list property, for use when displaying objects
in the user interface.
"""
enable_export: BoolProperty(
name = "Enable Export",
description = "Enable or disable the texture for export",
default = False,
)
export_location: EnumProperty(
name = "Export Location",
description = "Set the file path that the texture will be exported to",
items = GetExportLocations,
)
export_format: EnumProperty(
name = "Export Format",
description = "Set the export format that will be used when exporting a texture. This will NOT change the file format of the image as it is currently stored",
items = GetImageFormats,
)
class PAK_ImageItem(PropertyGroup):
"""
Defines a single texture within a PAK_ImageBundle.
It just wraps an image type in a PropertyGroup as Blender is a bit dumb with collections.
"""
tex: PointerProperty(
type = bpy.types.Image,
name = "Texture",
description = "A pointer for the texture this list item represents",
)
class PAK_ImageBundle(PropertyGroup):
"""
Define an object as a list property, for use when displaying objects in the user interface
"""
pak_items: CollectionProperty(type = PAK_ImageItem)
name: StringProperty(
name = "Texture/Bundle Name",
description = "",
default = "",
update = PAK_Update_TextureListItem_Name
)
enable_export: BoolProperty(
name = "Enable Export",
description = "Enable or disable the texture for export",
default = False,
update = PAK_Update_TextureListItem_EnableExport,
)
export_location: EnumProperty(
name = "Export Location",
description = "Set the file path that the texture will be exported to",
update = PAK_Update_TextureListItem_ExportLocation,
items = GetExportLocations,
)
export_format: EnumProperty(
name = "Export Format",
description = "Set the export format that will be used when exporting a texture. This will NOT change the file format of the image as it is currently stored",
update = PAK_Update_TextureListItem_ExportFormat,
items = GetImageFormats,
)
# Used for multi-select mode.
is_selected: BoolProperty(
default = False,
update = PAK_Update_TextureListItem_IsSelected,
)
class PAK_ExportLocations(PropertyGroup):
# Defines a single export location that can be reused across multiple textures
name: StringProperty(
name = "",
description = "The name of the export location"
)
path: StringProperty(
name = "",
description = "The file path used to export images to",
default = "",
subtype = "FILE_PATH"
)
class PAK_FileData(PropertyGroup):
"""
Everything PakPal needs to preserve as part of the file.
"""
# if true, this object is the empty created for the purposes of storing preset data.
is_file_data: BoolProperty(default = False)
# the available images for export
bundles: CollectionProperty(type = PAK_ImageBundle)
## The index of the currently selected collection from the UI list. Will be -1 if not selected.
bundles_list_index: IntProperty(
name = "Image",
description = "This is an image datablock stored in the currently open .blend file",
default = 0,
update = PAK_Update_TextureList_Preview
)
# the available export locations
locations: CollectionProperty(type = PAK_ExportLocations)
## The index of the currently selected export collection from the UI list. Will be -1 if not selected.
locations_list_index: IntProperty(default = 0)
# the available export formats
formats: CollectionProperty(type = PAK_ImageFormat)
formats_list_index: IntProperty(default = 0)
case_sensitive_matching: BoolProperty(
name = "Case Sensitive Matching",
description = "If enabled, operations that use material slot names such as image packing and material bundling will perform material slot comparisons in a case sensitive manner"
)
# The scene used to store Compositor nodes in.
scene_data: PointerProperty(
type = bpy.types.Scene,
name = "PakPal Scene Data Source",
description = "Defines the scene used to store Compositor nodes used for managing Image Format settings"
)
## HIDDEN PROPERTIES
# (these are activated with operators due to styling issues)
# if true, images can be edited with a psuedo multiselect interface.
enable_multiselect: BoolProperty(
name = "Enable Multiselect",
description = "When enabled, multiple textures can be selected and edited at the same time",
default = False,
)
# if true, images can be edited with a psuedo multiselect interface.
enable_bundles: BoolProperty(
name = "Enable Bundles",
description = "When enabled, textures sharing the same name but using common suffixes (like BaseColor, Height, etc) will be represented as a single entry in the list, and can be edited as a set of images",
default = False,
update = PAK_Update_EnableBundles,
)
## TEXTURE LIST OPTIONS
# These appear in the dropdown
show_file_format: BoolProperty(
name = "Show Format Type",
description = "Shows the format of the image",
default = False,
)
show_material_count: BoolProperty(
name = "Show Material Count",
description = "Shows the number of materials an image uses",
default = False,
)
show_user_count: BoolProperty(
name = "Show User Count",
description = "Shows the number of users an image has, including fake users",
default = False,
)
show_fake_user: BoolProperty(
name = "Show Fake Users",
description = "Shows if an image has a fake user",
default = False,
)
# if true, show hidden images in the list
show_hidden: BoolProperty(
name = "Show Hidden Images",
description = "Enable or disable the ability to see hidden image blocks. These might be used by other addons so be careful!",
default = False,
update = PAK_Update_RefreshList,
)
## TEXTURE PREVIEW
# (these are activated with operators due to styling issues)
preview_tex: PointerProperty(
type = bpy.types.Texture,
name = "Preview Texture",
description = "Used to preview images in the interface"
)
preview_rgb: EnumProperty(
name = "RGB Preview",
options = {'ENUM_FLAG'},
items = (('R', "", "", 'COLOR_RED', 1),
('G', "", "", 'COLOR_GREEN', 2),
('B', "", "", 'COLOR_BLUE', 100), # due to weird behaviour
),
description = "Change how the preview displays different color channels (alpha display is currently unsupported due to inbuilt image preview limitations)",
default = {'R', 'G', 'B'},
update = PAK_Update_TextureList_PreviewColor
)
# ////////////////////////////////////////////////////////////////////
# ////////////////////////////////////////////////////////////////////
## PROXIES
# These are used for multi-select operations and UI enhancements.
# Used during a refresh to prevent unnecessary update function triggers.
is_internal_update: BoolProperty(default = False)
proxy_enable_export: BoolProperty(
name = "Enable Export",
description = "Enable or disable the texture for export",
default = False,
update = PAK_Update_EnableExport,
)
proxy_export_location: EnumProperty(
name = "Export Location",
description = "Set the file path that the texture will be exported to",
items = GetExportLocations,
update = PAK_Update_ExportLocation,
)
proxy_export_format: EnumProperty(
name = "Export Format",
description = "Set the export format that will be used when exporting a texture. This will NOT change the file format of the image as it is currently stored",
items = GetImageFormats,
update = PAK_Update_ExportFormat,
)
# ////////////////////////////////////////////////////////////////////
# ////////////////////////////////////////////////////////////////////
# IMAGE PACKING
# These options are used when performing a channel mix operation
pack_format: PointerProperty(type=PAK_ImageFormat)
pack_r_source: StringProperty(
name = "Red Source Slot Name",
description = "Set the name of the material slot that will be used as a source for the new image's red channel (if it can be found within a bundle). Multiple slot names can be defined but only the first one found in a image bundle will be used",
default = ""
)
pack_g_source: StringProperty(
name = "Green Source Slot Name",
description = "Set the name of the material slot that will be used as a source for the new image's green channel (if it can be found within a bundle). Multiple slot names can be defined but only the first one found in a image bundle will be used",
default = ""
)
pack_b_source: StringProperty(
name = "Blue Source Slot Name",
description = "Set the name of the material slot that will be used as a source for the new image's blue channel (if it can be found within a bundle). Multiple slot names can be defined but only the first one found in a image bundle will be used",
default = ""
)
pack_a_source: StringProperty(
name = "Alpha Source Slot Name",
description = "Set the name of the material slot that will be used as a source for the new image's alpha channel (if it can be found within a bundle). Multiple slot names can be defined but only the first one found in a image bundle will be used",
default = ""
)
pack_r_channel: EnumProperty(
name = " ",
items = (('R', "R", "Use the red channel from the source material slot as the new packed image's red channel"),
('G', "G", "Use the green channel from the source material slot as the new packed image's red channel"),
('B', "B", "Use the blue channel from the source material slot as the new packed image's red channel"),
('A', "A", "Use the alpha channel from the source material slot as the new packed image's red channel")),
description = "",
default = 'R',
)
pack_g_channel: EnumProperty(
name = " ",
items = (('R', "R", "Use the red channel from the source material slot as the new packed image's green channel"),
('G', "G", "Use the green channel from the source material slot as the new packed image's green channel"),
('B', "B", "Use the blue channel from the source material slot as the new packed image's green channel"),
('A', "A", "Use the alpha channel from the source material slot as the new packed image's green channel")),
description = "",
default = 'R',
)
pack_b_channel: EnumProperty(
name = " ",
items = (('R', "R", "Use the red channel from the source material slot as the new packed image's blue channel"),
('G', "G", "Use the green channel from the source material slot as the new packed image's blue channel"),
('B', "B", "Use the blue channel from the source material slot as the new packed image's blue channel"),
('A', "A", "Use the alpha channel from the source material slot as the new packed image's blue channel")),
description = "",
default = 'R',
)
pack_a_channel: EnumProperty(
name = " ",
items = (('R', "R", "Use the red channel from the source material slot as the new packed image's alpha channel"),
('G', "G", "Use the green channel from the source material slot as the new packed image's alpha channel"),
('B', "B", "Use the blue channel from the source material slot as the new packed image's alpha channel"),
('A', "A", "Use the alpha channel from the source material slot as the new packed image's alpha channel")),
description = "",
default = 'R',
)
pack_r_invert: BoolProperty(
name = "Invert R Source",
description = "Invert the source image output",
default = False,
)
pack_g_invert: BoolProperty(
name = "Invert G Source",
description = "Invert the source image output",
default = False,
)
pack_b_invert: BoolProperty(
name = "Invert B Source",
description = "Invert the source image output",
default = False,
)
pack_a_invert: BoolProperty(
name = "Invert A Source",
description = "Invert the source image output",
default = False,
)
packed_image_suffix: StringProperty(
name = "Packed Image Suffix",
description = "Set the suffix the new image will be given. The base name of the new image will be the same as the base name for the Bundle",
default = "",
)
overwrite_image_pack: BoolProperty(
name = "Overwrite Existing Image",
description = "If an image is found with the same name in the Blend file, the new packed image will replace it",
default = True,
)
add_fake_user: BoolProperty(
name = "Add Fake User",
description = "Adds a fake user to any generated packed images to prevent them from disappearing when the blend file is closed",
default = True,
)
temp_bake_path: StringProperty(
name = "Temp Save Location",
description = "A temporary location used to save packed images. Either due to Blender limitations or a skill issue, PakPal needs to save images somewhere before reloading and saving them in the blend file",
default = "//Pak_Cache\\",
subtype = "FILE_PATH"
)
class PAK_MaterialSlot(PropertyGroup):
text: StringProperty(
name = "Bundle Text",
description = "",
default = "",
)