From a46c7584c7332fa1c11177fcaa5963e0de0fb4f0 Mon Sep 17 00:00:00 2001 From: SimonNordon4 Date: Sun, 10 Dec 2023 12:00:38 +1000 Subject: [PATCH] basic update --- auto_load.py | 205 ---------------------------------------------- bakelab_bake.py | 5 ++ bakelab_dev.py | 37 --------- bakelab_loader.py | 27 +++--- bakelab_ui.py | 4 +- bakelab_uv.py | 4 + 6 files changed, 24 insertions(+), 258 deletions(-) delete mode 100644 auto_load.py delete mode 100644 bakelab_dev.py diff --git a/auto_load.py b/auto_load.py deleted file mode 100644 index f6fa59c..0000000 --- a/auto_load.py +++ /dev/null @@ -1,205 +0,0 @@ -import os -import bpy -import sys -import typing -import inspect -import pkgutil -import importlib -from pathlib import Path - - -blender_version = bpy.app.version -modules = None -ordered_classes = None - -def init(): - print("Initializing AutoLoader") - modules = get_all_submodules(Path(__file__).parent) - print("Found modules:", modules) - ordered_classes = get_ordered_classes_to_register(modules) - - -def register(): - global - for cls in ordered_classes: - print("Registering", cls) - bpy.utils.register_class(cls) - for module in modules: - if module.__name__ == __name__: - continue - if hasattr(module, "register"): - module.register() - register_scene_properties() - -def unregister(): - unregister_scene_properties() - if ordered_classes is None: - return - for cls in reversed(ordered_classes): - print("Unregistering", cls) - bpy.utils.unregister_class(cls) - for module in modules: - if module.__name__ == __name__: - continue - if hasattr(module, "unregister"): - module.unregister() - -# Import modules -################################################# -def get_all_submodules(directory): - return list(iter_submodules(directory, directory.name)) - - -def iter_submodules(path, package_name): - for name in sorted(iter_submodule_names(path)): - try: - module = importlib.import_module("." + name, package_name) - print("Imported", module) - except: - print("Failed to import", name) - continue - try: - importlib.reload(module) - print("Reloaded", module) - except: - pass - yield module - - -def iter_submodule_names(path, root=""): - for _, module_name, is_package in pkgutil.iter_modules([str(path)]): - if is_package: - sub_path = path / module_name - sub_root = root + module_name + "." - print("Found submodule", sub_root) - yield from iter_submodule_names(sub_path, sub_root) - else: - yield root + module_name - print("Found module", root + module_name) - - -# Find classes to register -################################################# - -def get_ordered_classes_to_register(modules): - return toposort(get_register_deps_dict(modules)) - - -def get_register_deps_dict(modules): - my_classes = set(iter_my_classes(modules)) - my_classes_by_idname = {cls.bl_idname : cls for cls in my_classes if hasattr(cls, "bl_idname")} - deps_dict = {} - for cls in my_classes: - deps_dict[cls] = set(iter_my_register_deps(cls, my_classes, my_classes_by_idname)) - return deps_dict - - -def iter_my_register_deps(cls, my_classes, my_classes_by_idname): - yield from iter_my_deps_from_annotations(cls, my_classes) - yield from iter_my_deps_from_parent_id(cls, my_classes_by_idname) - - -def iter_my_deps_from_annotations(cls, my_classes): - for value in typing.get_type_hints(cls, {}, {}).values(): - dependency = get_dependency_from_annotation(value) - if dependency is not None: - if dependency in my_classes: - yield dependency - - -def get_dependency_from_annotation(value): - if blender_version >= (2, 93): - if isinstance(value, bpy.props._PropertyDeferred): - return value.keywords.get("type") - else: - if isinstance(value, tuple) and len(value) == 2: - if value[0] in (bpy.props.PointerProperty, bpy.props.CollectionProperty): - return value[1]["type"] - return None - - -def iter_my_deps_from_parent_id(cls, my_classes_by_idname): - if bpy.types.Panel in cls.__bases__: - parent_idname = getattr(cls, "bl_parent_id", None) - if parent_idname is not None: - parent_cls = my_classes_by_idname.get(parent_idname) - if parent_cls is not None: - yield parent_cls - - -def iter_my_classes(modules): - base_types = get_register_base_types() - for cls in get_classes_in_modules(modules): - if any(base in base_types for base in cls.__bases__): - if not getattr(cls, "is_registered", False): - yield cls - else: - #if class is registered, unregister it - bpy.utils.unregister_class(cls) - yield cls - - -def get_classes_in_modules(modules): - classes = set() - for module in modules: - for cls in iter_classes_in_module(module): - classes.add(cls) - return classes - - -def iter_classes_in_module(module): - for value in module.__dict__.values(): - if inspect.isclass(value): - yield value - - -def get_register_base_types(): - return set(getattr(bpy.types, name) for name in [ - "Panel", "Operator", "PropertyGroup", - "AddonPreferences", "Header", "Menu", - "Node", "NodeSocket", "NodeTree", - "UIList", "RenderEngine", - "Gizmo", "GizmoGroup", - ]) - - -# 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 - - -# Scene Properties -# ################################################# -def register_scene_properties(): - from bpy.props import ( - PointerProperty, - CollectionProperty, - IntProperty, - ) - from . import bakelab_properties - from . import bakelab_map - from . import bakelab_baked_data - bpy.types.Scene.BakeLabProps = PointerProperty(type = bakelab_properties.BakeLabProperties) - bpy.types.Scene.BakeLabMaps = CollectionProperty(type = bakelab_map.BakeLabMap) - bpy.types.Scene.BakeLab_Data = CollectionProperty(type = bakelab_baked_data.BakeLab_BakedData) - bpy.types.Scene.BakeLabMapIndex = IntProperty(name = 'BakeLab Map List Index') - - -def unregister_scene_properties(): - del bpy.types.Scene.BakeLabMapIndex - del bpy.types.Scene.BakeLab_Data - del bpy.types.Scene.BakeLabMaps - del bpy.types.Scene.BakeLabProps - diff --git a/bakelab_bake.py b/bakelab_bake.py index 32b5a98..2944136 100644 --- a/bakelab_bake.py +++ b/bakelab_bake.py @@ -20,6 +20,11 @@ from os.path import abspath, join, exists import bakelab_tools +from bakelab_tools import ( + SelectObject, + SelectObjects, + IsValidMesh + ) class Baker(Operator): """Bake""" diff --git a/bakelab_dev.py b/bakelab_dev.py deleted file mode 100644 index f43acc1..0000000 --- a/bakelab_dev.py +++ /dev/null @@ -1,37 +0,0 @@ -import bpy -import bakelab_loader - -from bpy.types import ( - Operator, - Panel) - -class ReloadOperator(bpy.types.Operator): - bl_idname = "bakelab.reload_operator" - bl_label = "Reload Auto-Loader" - - def execute(self, context): - bakelab_loader.unregister() - bakelab_loader.register() - return {'FINISHED'} - -class UninstallOperator(bpy.types.Operator): - bl_idname = "bakelab.uninstall_operator" - bl_label = "Uninstall Addon" - - def execute(self, context): - bakelab_loader.unregister() - return {'FINISHED'} - -class BakeLabDeveloperPanel(Panel): - bl_label = "BakeLabDev" - bl_space_type = 'VIEW_3D' - bl_idname = "BAKELAB_PT_dev_ui" - bl_region_type = 'UI' - bl_context = "objectmode" - bl_category = "BakeLab" - bl_order = 2 - - def draw(self, context): - layout = self.layout - layout.operator("bakelab.reload_operator") - layout.operator("bakelab.uninstall_operator") diff --git a/bakelab_loader.py b/bakelab_loader.py index ca00ab8..ce5a476 100644 --- a/bakelab_loader.py +++ b/bakelab_loader.py @@ -12,8 +12,6 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, script_dir) -is_dev = True - import bakelab_bake import bakelab_baked_data import bakelab_map @@ -32,6 +30,16 @@ importlib.reload(bakelab_tools) importlib.reload(bakelab_ui) importlib.reload(bakelab_uv) + +def reload_modules(): + importlib.reload(bakelab_bake) + importlib.reload(bakelab_baked_data) + importlib.reload(bakelab_map) + importlib.reload(bakelab_post) + importlib.reload(bakelab_properties) + importlib.reload(bakelab_tools) + importlib.reload(bakelab_ui) + importlib.reload(bakelab_uv) classes = ( bakelab_properties.BakeLabProperties, @@ -50,21 +58,10 @@ bakelab_baked_data.BakeMapData, bakelab_baked_data.BakeLab_BakedData, bakelab_map.BakeLabShowPassPresets, - bakelab_ui.BakeLabUI + bakelab_ui.BakeLabUI, + bakelab_ui.ResetUIOperator ) -if is_dev: - import bakelab_dev - if "bakelab_dev" in locals(): - importlib.reload(bakelab_dev) - - classes += ( - bakelab_dev.ReloadOperator, - bakelab_dev.UninstallOperator, - bakelab_dev.BakeLabDeveloperPanel - ) - - def register(): print("Registering..") failed_classes = [] diff --git a/bakelab_ui.py b/bakelab_ui.py index 556cbc8..ffbfbb3 100644 --- a/bakelab_ui.py +++ b/bakelab_ui.py @@ -4,7 +4,7 @@ ) class BakeLabUI(Panel): - bl_label = "BakeLab" + bl_label = "BakeLab1" bl_space_type = 'VIEW_3D' bl_idname = "BAKELAB_PT_ui" bl_region_type = 'UI' @@ -222,6 +222,7 @@ def draw(self, context): else: if props.bake_state == 'BAKING': layout.label(text = 'Baking', icon = 'RENDER_STILL') + if props.bake_mode == 'INDIVIDUAL': row = layout.row() row.label(text = 'Objects:') @@ -257,6 +258,7 @@ def draw(self, context): row.label( text = props.baking_map_type) layout.template_running_jobs() layout.operator("bakelab.reset_ui_operator", icon='CANCEL') + elif props.bake_state == 'BAKED': layout.label(text = 'Baked', icon = 'CHECKMARK') diff --git a/bakelab_uv.py b/bakelab_uv.py index eafed24..3e8346d 100644 --- a/bakelab_uv.py +++ b/bakelab_uv.py @@ -13,6 +13,10 @@ ) import bakelab_tools +from bakelab_tools import ( + SelectObjects, + IsValidMesh + ) def SelectObject(obj): bpy.ops.object.select_all(action = 'DESELECT')