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 @classmethod
def poll(cls, context: Context) -> bool: 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 return context.scene.avatar_toolkit.texture_atlas_Has_Mat_List_Shown
def execute(self, context: Context) -> set: def execute(self, context: Context) -> set:
@@ -208,8 +212,14 @@ class AvatarToolKit_OT_AtlasMaterials(Operator):
image_pixels[int(((k*w)+i)*4)+channel] image_pixels[int(((k*w)+i)*4)+channel]
canvas.pixels[:] = canvas_pixels[:] 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) setattr(atlased_mat, type_name, canvas)
progress.step(f"Created {type_name} atlas") progress.step(f"Created {type_name} atlas")
+4
View File
@@ -489,6 +489,10 @@
"TextureAtlas.how_to_use_2": "2. Click 'Load Materials' to begin", "TextureAtlas.how_to_use_2": "2. Click 'Load Materials' to begin",
"TextureAtlas.load_error": "Error loading materials. Check console for details.", "TextureAtlas.load_error": "Error loading materials. Check console for details.",
"TextureAtlas.material_not_included": "Material is not included in atlas", "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.label": "Settings",
"Settings.language": "Language", "Settings.language": "Language",
+4
View File
@@ -489,6 +489,10 @@
"TextureAtlas.how_to_use_2": "2. 「マテリアルを読み込む」をクリックして開始", "TextureAtlas.how_to_use_2": "2. 「マテリアルを読み込む」をクリックして開始",
"TextureAtlas.load_error": "マテリアルの読み込みエラー。詳細はコンソールを確認してください。", "TextureAtlas.load_error": "マテリアルの読み込みエラー。詳細はコンソールを確認してください。",
"TextureAtlas.material_not_included": "マテリアルはアトラスに含まれていません", "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.label": "設定",
"Settings.language": "言語", "Settings.language": "言語",
+4
View File
@@ -489,6 +489,10 @@
"TextureAtlas.how_to_use_2": "2. '재질 불러오기'를 클릭하여 시작", "TextureAtlas.how_to_use_2": "2. '재질 불러오기'를 클릭하여 시작",
"TextureAtlas.load_error": "재질 로딩 오류. 자세한 내용은 콘솔을 확인하세요.", "TextureAtlas.load_error": "재질 로딩 오류. 자세한 내용은 콘솔을 확인하세요.",
"TextureAtlas.material_not_included": "재질이 아틀라스에 포함되지 않았습니다", "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.label": "설정",
"Settings.language": "언어", "Settings.language": "언어",
+10
View File
@@ -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_1"), icon='INFO')
info_col.label(text=t("TextureAtlas.description_2")) 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) layout.separator(factor=0.5)
box = layout.box() box = layout.box()
row = box.row(align=True) row = box.row(align=True)