From 345ba444638dccf4d8cff215583d3e690200e777 Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 31 Mar 2025 22:39:49 +0100 Subject: [PATCH] Texture Atlas should require the user to save the blender files before we allow them to atlas --- functions/atlas_materials.py | 14 ++++++++++++-- resources/translations/en_US.json | 4 ++++ resources/translations/ja_JP.json | 4 ++++ resources/translations/ko_KR.json | 4 ++++ ui/atlas_materials_panel.py | 10 ++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/functions/atlas_materials.py b/functions/atlas_materials.py index 74487fa..b578fcc 100644 --- a/functions/atlas_materials.py +++ b/functions/atlas_materials.py @@ -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") diff --git a/resources/translations/en_US.json b/resources/translations/en_US.json index d56bf50..39b1183 100644 --- a/resources/translations/en_US.json +++ b/resources/translations/en_US.json @@ -489,6 +489,10 @@ "TextureAtlas.how_to_use_2": "2. Click 'Load Materials' to begin", "TextureAtlas.load_error": "Error loading materials. Check console for details.", "TextureAtlas.material_not_included": "Material is not included in atlas", + "TextureAtlas.save_file_first": "Please save your Blender file before creating a texture atlas", + "TextureAtlas.save_file_instructions": "Use File > Save As... or click the button below:", + "TextureAtlas.save_file_button": "Save Blender File", + "TextureAtlas.save_file_required": "Save File Required", "Settings.label": "Settings", "Settings.language": "Language", diff --git a/resources/translations/ja_JP.json b/resources/translations/ja_JP.json index 343271b..22282b0 100644 --- a/resources/translations/ja_JP.json +++ b/resources/translations/ja_JP.json @@ -489,6 +489,10 @@ "TextureAtlas.how_to_use_2": "2. 「マテリアルを読み込む」をクリックして開始", "TextureAtlas.load_error": "マテリアルの読み込みエラー。詳細はコンソールを確認してください。", "TextureAtlas.material_not_included": "マテリアルはアトラスに含まれていません", + "TextureAtlas.save_file_first": "テクスチャアトラスを作成する前に、Blenderファイルを保存してください", + "TextureAtlas.save_file_instructions": "ファイル > 名前を付けて保存... を使用するか、下のボタンをクリックしてください:", + "TextureAtlas.save_file_button": "Blenderファイルを保存", + "TextureAtlas.save_file_required": "ファイルの保存が必要です", "Settings.label": "設定", "Settings.language": "言語", diff --git a/resources/translations/ko_KR.json b/resources/translations/ko_KR.json index 6fca745..f80a09d 100644 --- a/resources/translations/ko_KR.json +++ b/resources/translations/ko_KR.json @@ -489,6 +489,10 @@ "TextureAtlas.how_to_use_2": "2. '재질 불러오기'를 클릭하여 시작", "TextureAtlas.load_error": "재질 로딩 오류. 자세한 내용은 콘솔을 확인하세요.", "TextureAtlas.material_not_included": "재질이 아틀라스에 포함되지 않았습니다", + "TextureAtlas.save_file_first": "텍스처 아틀라스를 만들기 전에 Blender 파일을 저장하세요", + "TextureAtlas.save_file_instructions": "파일 > 다른 이름으로 저장... 을 사용하거나 아래 버튼을 클릭하세요:", + "TextureAtlas.save_file_button": "Blender 파일 저장", + "TextureAtlas.save_file_required": "파일 저장 필요", "Settings.label": "설정", "Settings.language": "언어", diff --git a/ui/atlas_materials_panel.py b/ui/atlas_materials_panel.py index f7edfd8..ee940ba 100644 --- a/ui/atlas_materials_panel.py +++ b/ui/atlas_materials_panel.py @@ -229,6 +229,16 @@ class AvatarToolKit_PT_TextureAtlasPanel(Panel): info_col.label(text=t("TextureAtlas.description_1"), icon='INFO') info_col.label(text=t("TextureAtlas.description_2")) + if not bpy.data.filepath: + warning_box = layout.box() + warning_col = warning_box.column() + warning_col.scale_y = 0.9 + warning_col.alert = True + warning_col.label(text=t("TextureAtlas.save_file_first"), icon='ERROR') + warning_col.label(text=t("TextureAtlas.save_file_instructions")) + warning_col.operator("wm.save_as_mainfile", text=t("TextureAtlas.save_file_button"), icon='FILE_TICK') + layout.separator(factor=0.5) + layout.separator(factor=0.5) box = layout.box() row = box.row(align=True)