From 345ba444638dccf4d8cff215583d3e690200e777 Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 31 Mar 2025 22:39:49 +0100 Subject: [PATCH 1/4] 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) From ff5efc9639210b8ff21c5e4f43fe673be1958817 Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 31 Mar 2025 22:51:35 +0100 Subject: [PATCH 2/4] Update blender_manifest.toml --- blender_manifest.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blender_manifest.toml b/blender_manifest.toml index 068cd93..97812f3 100644 --- a/blender_manifest.toml +++ b/blender_manifest.toml @@ -15,6 +15,10 @@ license = [ "SPDX:GPL-3.0-or-later", ] +[permissions] +network = "For the auto updater to work, you need to allow network access." +files = "Import/ Export files, saving atlas images, saving preferences." + wheels = [ "./wheels/lz4-4.4.3-cp311-cp311-macosx_11_0_arm64.whl", "./wheels/lz4-4.3.3-cp311-cp311-macosx_10_9_x86_64.whl", From a407e99ebd9f21317b9d3774adee39babb104b9a Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 31 Mar 2025 23:03:09 +0100 Subject: [PATCH 3/4] Update atlas_materials.py --- functions/atlas_materials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/atlas_materials.py b/functions/atlas_materials.py index b578fcc..8c38f9e 100644 --- a/functions/atlas_materials.py +++ b/functions/atlas_materials.py @@ -218,7 +218,7 @@ class AvatarToolKit_OT_AtlasMaterials(Operator): 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.") + self.report({'WARNING'}, f"Could not save texture to disk, This may be due to a lack of permissions.") setattr(atlased_mat, type_name, canvas) progress.step(f"Created {type_name} atlas") From 0ff2dc1c3826aa3b036ec45c2a7db9d47bf3679e Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 31 Mar 2025 23:22:35 +0100 Subject: [PATCH 4/4] I swear I fixed the issue before we Armautre and Mesh attach, also fixed permission. --- blender_manifest.toml | 8 ++++---- ui/custom_avatar_panel.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/blender_manifest.toml b/blender_manifest.toml index 97812f3..b6e9679 100644 --- a/blender_manifest.toml +++ b/blender_manifest.toml @@ -15,13 +15,13 @@ license = [ "SPDX:GPL-3.0-or-later", ] -[permissions] -network = "For the auto updater to work, you need to allow network access." -files = "Import/ Export files, saving atlas images, saving preferences." - wheels = [ "./wheels/lz4-4.4.3-cp311-cp311-macosx_11_0_arm64.whl", "./wheels/lz4-4.3.3-cp311-cp311-macosx_10_9_x86_64.whl", "./wheels/lz4-4.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/lz4-4.4.3-cp311-cp311-win_amd64.whl" ] + +[permissions] +network = "For the auto updater to work, you need to allow network access" +files = "Import/Export files, saving atlas images, saving preferences" diff --git a/ui/custom_avatar_panel.py b/ui/custom_avatar_panel.py index 4e3ff62..3ebf160 100644 --- a/ui/custom_avatar_panel.py +++ b/ui/custom_avatar_panel.py @@ -2,6 +2,8 @@ import bpy from typing import Set, List, Tuple, Any from bpy.types import Panel, Context, UILayout, Operator, Event, WindowManager from .main_panel import AvatarToolKit_PT_AvatarToolkitPanel, CATEGORY_NAME +from ..functions.custom_tools.mesh_attachment import AvatarToolkit_OT_AttachMesh +from ..functions.custom_tools.armature_merging import AvatarToolkit_OT_MergeArmature from ..core.translations import t from ..core.common import ( get_active_armature,