From 148797ece201176b539ecdb4cbd183a8535982c3 Mon Sep 17 00:00:00 2001 From: 989onan Date: Mon, 29 Jul 2024 13:03:31 -0400 Subject: [PATCH] Cleanup some stuff --- core/dictionaries.py | 2 +- core/properties.py | 120 ++++++++++++++++-------------- core/register.py | 19 ----- functions/resonite_functions.py | 3 +- functions/viseme.py | 8 +- resources/translations/en_US.json | 13 ++++ resources/translations/ja_JP.json | 2 +- ui/viseme.py | 8 +- 8 files changed, 91 insertions(+), 84 deletions(-) diff --git a/core/dictionaries.py b/core/dictionaries.py index 64c6125..3d5235d 100644 --- a/core/dictionaries.py +++ b/core/dictionaries.py @@ -78,7 +78,7 @@ bone_names = { "left_ankle": ["leftankle", "anklel", "rankle", "leftfoot", "footl", "lfoot", "leftfoot", "leftfeet", "feetleft", "lfeet", "feetl", "valvebipedbip01lfoot"], "left_toe": ["lefttoe", "toeleft", "toel", "ltoe", "toesl", "ltoes", "valvebipedbip01ltoe0"], - "hips": ["pelvis", "hips", "valvebipedbip01pelvis"], + "hips": ["pelvis", "hips", "hip", "valvebipedbip01pelvis"], "spine": ["torso", "spine", "valvebipedbip01spine"], "chest": ["chest", "valvebipedbip01spine1"], "upper_chest": ["upperchest", "valvebipedbip01spine4"], diff --git a/core/properties.py b/core/properties.py index 8eda6a6..9545d6b 100644 --- a/core/properties.py +++ b/core/properties.py @@ -1,103 +1,115 @@ import bpy from ..functions.translations import t, get_languages_list, update_language from ..core.register import register_property -from bpy.types import Scene, Object, Material, TextureNode, Context, SceneObjects, PropertyGroup -from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty, CollectionProperty, StringProperty, FloatVectorProperty, PointerProperty -from bpy.utils import register_class -from ..core.register import register_wrap +from bpy.types import Scene, Object, Material, Context +from bpy.props import BoolProperty, EnumProperty, IntProperty, CollectionProperty, StringProperty, FloatVectorProperty, PointerProperty from ..core.addon_preferences import get_preference from ..core.common import SceneMatClass, material_list_bool, get_armatures, get_mesh_items def register() -> None: default_language = get_preference("language", 0) - bpy.types.Scene.avatar_toolkit_language = bpy.props.EnumProperty( + register_property((bpy.types.Scene, "avatar_toolkit_language", bpy.props.EnumProperty( name=t("Settings.language.label", "Language"), description=t("Settings.language.desc", "Select the language for the addon"), items=get_languages_list, default=default_language, update=update_language - ) + ))) - bpy.types.Scene.selected_mesh = bpy.props.EnumProperty( + register_property((bpy.types.Scene, "selected_mesh", bpy.props.EnumProperty( items=get_mesh_items, - name="Selected Mesh", - description="The currently selected mesh for viseme operations" - ) + name=t("VisemePanel.selected_mesh.label"), + description=t("VisemePanel.selected_mesh.desc") + ))) - bpy.types.Scene.avatar_toolkit_language_changed = bpy.props.BoolProperty(default=False) + register_property((bpy.types.Scene, "avatar_toolkit_language_changed", bpy.props.BoolProperty(default=False))) - bpy.types.Scene.avatar_toolkit_progress_steps = bpy.props.IntProperty(default=0) - bpy.types.Scene.avatar_toolkit_progress_current = bpy.props.IntProperty(default=0) + register_property((bpy.types.Scene, "avatar_toolkit_progress_steps", bpy.props.IntProperty(default=0))) + register_property((bpy.types.Scene, "avatar_toolkit_progress_current", bpy.props.IntProperty(default=0))) - bpy.types.Scene.mouth_a = bpy.props.StringProperty( + register_property((bpy.types.Scene, "avatar_toolkit_mouth_a", bpy.props.StringProperty( name=t("VisemePanel.mouth_a.label"), description=t("VisemePanel.mouth_a.desc") - ) - bpy.types.Scene.mouth_o = bpy.props.StringProperty( + ))) + register_property((bpy.types.Scene, "avatar_toolkit_mouth_o", bpy.props.StringProperty( name=t("VisemePanel.mouth_o.label"), description=t("VisemePanel.mouth_o.desc") - ) - bpy.types.Scene.mouth_ch = bpy.props.StringProperty( + ))) + register_property((bpy.types.Scene, "avatar_toolkit_mouth_ch", bpy.props.StringProperty( name=t("VisemePanel.mouth_ch.label"), description=t("VisemePanel.mouth_ch.desc") - ) - bpy.types.Scene.shape_intensity = bpy.props.FloatProperty( + ))) + register_property((bpy.types.Scene, "avatar_toolkit_shape_intensity", bpy.props.FloatProperty( name=t("VisemePanel.shape_intensity"), description=t("VisemePanel.shape_intensity_desc"), default=1.0, min=0.0, max=2.0 - ) + ))) - bpy.types.Scene.selected_armature = bpy.props.EnumProperty( + register_property((bpy.types.Scene, "selected_armature", bpy.props.EnumProperty( items=get_armatures, name="Selected Armature", description="The currently selected armature for Avatar Toolkit operations" - ) + ))) #happy with how compressed this get_texture_node_list method is - @989onan def get_texture_node_list(self: Material, context: Context) -> list[set[3]]: + if self.use_nodes: + Object.Enum = [((i.image.name if i.image else i.name+"_image"),(i.image.name if i.image else "node with no image..."),(i.image.name if i.image else i.name),index+1) for index,i in enumerate(self.node_tree.nodes) if i.bl_idname == "ShaderNodeTexImage"] if not len(Object.Enum): - Object.Enum = [("ERROR", "THIS MATERIAL HAS NO IMAGES!", "ERROR", 0)] + Object.Enum = [(t("TextureAtlas.error.label"), t("TextureAtlas.no_images_error.desc") , t("TextureAtlas.error.label"), 0)] else: - Object.Enum = [("ERROR", "THIS MATERIAL DOES NOT USE NODES!", "ERROR", 0)] - Object.Enum.append(("None", "None", "None", 0)) + Object.Enum = [(t("TextureAtlas.error.label"), t("TextureAtlas.no_nodes_error.desc"), t("TextureAtlas.error.label"), 0)] + Object.Enum.append((t("TextureAtlas.none.label"), t("TextureAtlas.none.label"), t("TextureAtlas.none.label"), 0)) return Object.Enum - register_property((Material, "texture_atlas_albedo", EnumProperty(name="Albedo", description="The texture that will be used for the albedo map atlas", default=0, items=get_texture_node_list))) - register_property((Material, "texture_atlas_normal", EnumProperty(name="Normal", description="The texture that will be used for the normal map atlas", default=0, items=get_texture_node_list))) - register_property((Material, "texture_atlas_emission", EnumProperty(name="Emission", description="The texture that will be used for the emission map atlas", default=0, items=get_texture_node_list))) - register_property((Material, "texture_atlas_ambient_occlusion", EnumProperty(name="Ambient Occlusion", description="The texture that will be used for the ambient occlusion map atlas", default=0, items=get_texture_node_list))) - register_property((Material, "texture_atlas_height", EnumProperty(name="Height", description="The texture that will be used for the height map atlas", default=0, items=get_texture_node_list))) - register_property((Material, "texture_atlas_roughness", EnumProperty(name="Roughness", description="The texture that will be used for the roughness map atlas", default=0, items=get_texture_node_list))) + register_property((Material, "texture_atlas_albedo", EnumProperty( + name=t("TextureAtlas.albedo"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.albedo").lower()), + default=0, + items=get_texture_node_list))) + register_property((Material, "texture_atlas_normal", EnumProperty( + name=t("TextureAtlas.normal"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.normal").lower()), + default=0, + items=get_texture_node_list))) + register_property((Material, "texture_atlas_emission", EnumProperty( + name=t("TextureAtlas.emission"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.emission").lower()), + default=0, + items=get_texture_node_list))) + register_property((Material, "texture_atlas_ambient_occlusion", EnumProperty( + name=t("TextureAtlas.ambient_occlusion"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.ambient_occlusion").lower()), + default=0, + items=get_texture_node_list))) + register_property((Material, "texture_atlas_height", EnumProperty( + name=t("TextureAtlas.height"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.height_map").lower()), + default=0, + items=get_texture_node_list))) + register_property((Material, "texture_atlas_roughness", EnumProperty( + name=t("TextureAtlas.roughness"), + description=t("TextureAtlas.texture_use_atlas.desc").format(name=t("TextureAtlas.roughness").lower()), + default=0, + items=get_texture_node_list))) - register_property((Scene, "texture_atlas_material_index", IntProperty(default=-1, get=(lambda self : -1), set=(lambda self,context : None)))) + register_property((Scene, "texture_atlas_material_index", IntProperty( + default=-1, + get=(lambda self : -1), + set=(lambda self,context : None)))) register_property((Scene, "materials", CollectionProperty(type=SceneMatClass))) - register_property((Scene, "texture_atlas_Has_Mat_List_Shown", BoolProperty(default=False, get=material_list_bool.get_bool, set=material_list_bool.set_bool))) + register_property((Scene, "texture_atlas_Has_Mat_List_Shown", BoolProperty( + default=False, + get=material_list_bool.get_bool, + set=material_list_bool.set_bool))) def unregister() -> None: - if hasattr(bpy.types.Scene, "avatar_toolkit_language"): - del bpy.types.Scene.avatar_toolkit_language - - if hasattr(bpy.types.Scene, "avatar_toolkit_language_changed"): - del bpy.types.Scene.avatar_toolkit_language_changed - - if hasattr(bpy.types.Scene, "mouth_a"): - del bpy.types.Scene.mouth_a - - if hasattr(bpy.types.Scene, "mouth_o"): - del bpy.types.Scene.mouth_o - - if hasattr(bpy.types.Scene, "mouth_ch"): - del bpy.types.Scene.mouth_ch - - if hasattr(bpy.types.Scene, "shape_intensity"): - del bpy.types.Scene.shape_intensity - - if hasattr(bpy.types.Scene, "selected_armature"): - del bpy.types.Scene.selected_armature + #if you register properties with register_property then you shouldn't need this function. + pass diff --git a/core/register.py b/core/register.py index ac6211d..1862e99 100644 --- a/core/register.py +++ b/core/register.py @@ -94,22 +94,3 @@ def get_dependency_from_annotation(value): if value[0] in (bpy.props.PointerProperty, bpy.props.CollectionProperty): return value[1]["type"] return None - - -# Find order to register to solve dependencies -################################################# - -def toposort(deps_dict): - sorted_list = [] - sorted_values = set() - while len(deps_dict) > 0: - unsorted = [] - for value, deps in deps_dict.items(): - if len(deps) == 0: - sorted_list.append(value) - sorted_values.add(value) - else: - unsorted.append(value) - deps_dict = {value : deps_dict[value] - sorted_values for value in unsorted} - - return sorted_list diff --git a/functions/resonite_functions.py b/functions/resonite_functions.py index 9d81d70..a8a91b2 100644 --- a/functions/resonite_functions.py +++ b/functions/resonite_functions.py @@ -95,13 +95,14 @@ class ConvertToResonite(Operator): bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='OBJECT') + bone.name = re.compile(re.escape(""), re.IGNORECASE).sub("",bone.name) #remove "NOIK" from bones before translating again, in case an update was done that fixes a translation. for bone in armature.data.bones: if simplify_bonename(bone.name) in reverse_bone_lookup and reverse_bone_lookup[simplify_bonename(bone.name)] in resonite_translations: bone.name = resonite_translations[reverse_bone_lookup[simplify_bonename(bone.name)]] else: untranslated_bones.add(bone.name) - bone.name = re.compile(re.escape(""), re.IGNORECASE).sub("",bone.name)+"" + bone.name = bone.name+"" translate_bone_fails += 1 bpy.ops.object.mode_set(mode='OBJECT') diff --git a/functions/viseme.py b/functions/viseme.py index 8e32146..db18bb9 100644 --- a/functions/viseme.py +++ b/functions/viseme.py @@ -36,9 +36,9 @@ class AutoVisemeButton(bpy.types.Operator): update_progress(self, context, t("VisemePanel.removing_existing_visemes")) self.remove_existing_vrc_shapekeys(mesh) - shape_a = context.scene.mouth_a - shape_o = context.scene.mouth_o - shape_ch = context.scene.mouth_ch + shape_a = context.scene.avatar_toolkit_mouth_a + shape_o = context.scene.avatar_toolkit_mouth_o + shape_ch = context.scene.avatar_toolkit_mouth_ch if shape_a == "Basis" or shape_o == "Basis" or shape_ch == "Basis": raise ValueError(t('AutoVisemeButton.error.selectShapekeys')) @@ -63,7 +63,7 @@ class AutoVisemeButton(bpy.types.Operator): ] for viseme_name, shape_mix in visemes: - self.create_viseme(mesh, viseme_name, shape_mix, context.scene.shape_intensity) + self.create_viseme(mesh, viseme_name, shape_mix, context.scene.avatar_toolkit_shape_intensity) update_progress(self, context, t("VisemePanel.sorting_shapekeys")) common.sort_shape_keys(mesh) diff --git a/resources/translations/en_US.json b/resources/translations/en_US.json index a44cd82..a0ec7b9 100644 --- a/resources/translations/en_US.json +++ b/resources/translations/en_US.json @@ -94,6 +94,17 @@ "TextureAtlas.loaded_list": "Loaded Texture Atlas Material List", "TextureAtlas.material_list_label": "Texture Atlas Material List Material", "TextureAtlas.reload_list": "Reload Texture Atlas Material List", + "TextureAtlas.error.label": "ERROR", + "TextureAtlas.none.label": "None", + "TextureAtlas.no_nodes_error.desc": "THIS MATERIAL DOES NOT USE NODES!", + "TextureAtlas.no_images_error.desc": "THIS MATERIAL HAS NO IMAGES!", + "TextureAtlas.texture_use_atlas.desc": "The texture that will be used for the {name} map atlas", + "TextureAtlas.albedo": "Albedo", + "TextureAtlas.normal": "Normal", + "TextureAtlas.emission": "Emission", + "TextureAtlas.ambient_occlusion": "Ambient Occlusion", + "TextureAtlas.height": "Height", + "TextureAtlas.roughness": "Roughness", "Tools.bones_translated_success": "Successfully translated all bones to humanoid names", "Tools.bones_translated_with_fails": "Failed to translate {translate_bone_fails} bones to humanoid names. Adding \"\" to their names.", "Tools.convert_to_resonite.desc": "Converts bone names on a model to names compatible with Resonite", @@ -139,6 +150,8 @@ "VisemePanel.removing_existing_viseme": "Removing existing viseme: {viseme_name}", "VisemePanel.removing_existing_visemes": "Removing existing visemes...", "VisemePanel.select_mesh": "Select Mesh", + "VisemePanel.selected_mesh.label": "Selected Mesh", + "VisemePanel.selected_mesh.desc": "The currently selected mesh for viseme operations", "VisemePanel.selected_shapes": "Selected shapes: A={shape_a}, O={shape_o}, CH={shape_ch}", "VisemePanel.shape_intensity": "Shape Intensity", "VisemePanel.shape_intensity_desc": "The intensity of the viseme shapekeys", diff --git a/resources/translations/ja_JP.json b/resources/translations/ja_JP.json index f091290..2b525e3 100644 --- a/resources/translations/ja_JP.json +++ b/resources/translations/ja_JP.json @@ -18,7 +18,7 @@ "Importer.export_vrchat.label": "VRChatにエクスポート", "Importer.mmd_anim_importer.desc": "MMDアニメーション(.vmd)をインポート", "Importer.mmd_anim_importer.label": "MMDアニメーション", - "Importing.importer_search_term": "https://search.brave.com/search?q=blender+{extension}+importer+addon&source=web", + "Importing.importer_search_term": "https://search.brave.com/search?q=Blender+{extension}+インポーターアドオン&source=web", "Importing.need_importer": "{extension}タイプに必要なインポーターがありません!インポーター検索用のウェブブラウザを開きます...", "Language.auto": "自動", "Language.en_US": "English", diff --git a/ui/viseme.py b/ui/viseme.py index 7dbf49d..446daff 100644 --- a/ui/viseme.py +++ b/ui/viseme.py @@ -24,11 +24,11 @@ class AvatarToolkitVisemePanel(bpy.types.Panel): mesh = bpy.data.objects.get(context.scene.selected_mesh) if mesh and mesh.type == 'MESH': if mesh.data.shape_keys: - layout.prop_search(context.scene, "mouth_a", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_a.label'), icon='SHAPEKEY_DATA') - layout.prop_search(context.scene, "mouth_o", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_o.label'), icon='SHAPEKEY_DATA') - layout.prop_search(context.scene, "mouth_ch", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_ch.label'), icon='SHAPEKEY_DATA') + layout.prop_search(context.scene, "avatar_toolkit_mouth_a", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_a.label'), icon='SHAPEKEY_DATA') + layout.prop_search(context.scene, "avatar_toolkit_mouth_o", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_o.label'), icon='SHAPEKEY_DATA') + layout.prop_search(context.scene, "avatar_toolkit_mouth_ch", mesh.data.shape_keys, "key_blocks", text=t('VisemePanel.mouth_ch.label'), icon='SHAPEKEY_DATA') - layout.prop(context.scene, 'shape_intensity', text=t('VisemePanel.shape_intensity'), icon='FORCE_LENNARDJONES') + layout.prop(context.scene, 'avatar_toolkit_shape_intensity', text=t('VisemePanel.shape_intensity'), icon='FORCE_LENNARDJONES') row = layout.row() row.scale_y = 1.2