def enum_sprite_previews(self, context):
"""EnumProperty callback"""
enum_items = []
if context is None:
return enum_items
if self.coa_type == "MESH":
# Get the preview collection (defined in register func).
coa_pcoll = preview_collections["coa_thumbs"]
#thumb_dir_path = bpy.utils.user_resource("DATAFILES","coa_thumbs")
thumb_dir_path = os.path.join(context.user_preferences.filepaths.temporary_directory,"coa_thumbs")
if os.path.exists(thumb_dir_path):
# Scan the directory for png files
image_paths = []
for fn in os.listdir(thumb_dir_path):
if fn.lower().endswith(".png") and self.name in fn:
image_paths.append(fn)
for i, name in enumerate(image_paths):
if i < self.coa_tiles_x * self.coa_tiles_y:
filepath = os.path.join(thumb_dir_path, name)
if name in coa_pcoll:
thumb = coa_pcoll[name]
else:
thumb = coa_pcoll.load(name, filepath, 'IMAGE')
enum_items.append((str(i), name, "", thumb.icon_id, i))
elif self.coa_type == "SLOT":
for i,slot in enumerate(self.coa_slot):
if slot.mesh != None:
img = slot.mesh.materials[0].texture_slots[0].texture.image
icon = bpy.types.UILayout.icon(img)
enum_items.append((str(i), slot.mesh.name, "", icon, i))
return enum_items
评论列表
文章目录