Texture Atlas should require the user to save the blender files before we allow them to atlas

This commit is contained in:
Yusarina
2025-03-31 22:39:49 +01:00
parent 64a78dbbb2
commit 345ba44463
5 changed files with 34 additions and 2 deletions
+12 -2
View File
@@ -137,6 +137,10 @@ class AvatarToolKit_OT_AtlasMaterials(Operator):
@classmethod
def poll(cls, context: Context) -> bool:
# Only allow operation if the file is saved and materials are selected.
if not bpy.data.filepath:
cls.poll_message_set(t("TextureAtlas.save_file_first"))
return False
return context.scene.avatar_toolkit.texture_atlas_Has_Mat_List_Shown
def execute(self, context: Context) -> set:
@@ -208,8 +212,14 @@ class AvatarToolKit_OT_AtlasMaterials(Operator):
image_pixels[int(((k*w)+i)*4)+channel]
canvas.pixels[:] = canvas_pixels[:]
canvas.save(filepath=os.path.join(os.path.dirname(bpy.data.filepath),
new_image_name+".png"))
try:
save_dir = os.path.dirname(bpy.data.filepath)
canvas.save(filepath=os.path.join(save_dir, new_image_name+".png"))
except Exception as save_error:
logger.error(f"Failed to save atlas texture: {str(save_error)}")
self.report({'WARNING'}, f"Could not save texture to disk. Atlas will work in memory only.")
setattr(atlased_mat, type_name, canvas)
progress.step(f"Created {type_name} atlas")