From 33f2809682e41cf620358360de25d52a56736036 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Fri, 9 Aug 2024 12:22:49 +0200 Subject: [PATCH] refactor(Blender): changed all imports to be relative, to be up to spec with Blender 4.2 extensions --- TODO.md | 1 + tools/blenvy/add_ons/auto_export/__init__.py | 2 +- .../auto_export/blueprints/get_blueprints_to_export.py | 3 +-- tools/blenvy/add_ons/auto_export/common/auto_export.py | 3 +-- .../add_ons/auto_export/common/duplicate_object.py | 4 ++-- tools/blenvy/add_ons/auto_export/common/export_gltf.py | 2 +- .../common/generate_temporary_scene_and_export.py | 4 ++-- .../add_ons/auto_export/common/prepare_and_export.py | 2 +- tools/blenvy/add_ons/auto_export/common/project_diff.py | 2 +- tools/blenvy/add_ons/auto_export/common/settings_diff.py | 4 +--- .../add_ons/auto_export/levels/get_levels_to_export.py | 2 +- .../add_ons/auto_export/materials/export_materials.py | 5 ++--- .../auto_export/materials/get_materials_to_export.py | 2 +- tools/blenvy/add_ons/auto_export/settings.py | 2 +- tools/blenvy/add_ons/auto_export/utils.py | 4 ++-- tools/blenvy/add_ons/bevy_components/components/lists.py | 2 +- tools/blenvy/add_ons/bevy_components/components/maps.py | 2 +- .../blenvy/add_ons/bevy_components/registry/operators.py | 3 +-- tools/blenvy/add_ons/bevy_components/settings.py | 3 ++- tools/blenvy/add_ons/bevy_components/utils.py | 7 +++---- tools/blenvy/blueprints/operators.py | 2 +- tools/blenvy/core/blenvy_manager.py | 9 ++++----- tools/blenvy/core/ui/ui.py | 5 +++-- 23 files changed, 35 insertions(+), 40 deletions(-) diff --git a/TODO.md b/TODO.md index 7b5ae7c..adc4316 100644 --- a/TODO.md +++ b/TODO.md @@ -273,6 +273,7 @@ Blender side: - [ ] auto reload registry if absent/possible - cannot be done from UI possibly polling with increasing timeout - bpy.ops.blenvy.components_registry_reload() + - double check bpy.context.components_registry - [x] filter out MaterialInfos from list of "fixable components" diff --git a/tools/blenvy/add_ons/auto_export/__init__.py b/tools/blenvy/add_ons/auto_export/__init__.py index 6cf2318..6aa4507 100644 --- a/tools/blenvy/add_ons/auto_export/__init__.py +++ b/tools/blenvy/add_ons/auto_export/__init__.py @@ -2,7 +2,7 @@ import os import json import pathlib import bpy -from blenvy.settings import generate_complete_settings_dict +from ...settings import generate_complete_settings_dict from io_scene_gltf2 import ExportGLTF2_Base diff --git a/tools/blenvy/add_ons/auto_export/blueprints/get_blueprints_to_export.py b/tools/blenvy/add_ons/auto_export/blueprints/get_blueprints_to_export.py index 5489e4f..5757f15 100644 --- a/tools/blenvy/add_ons/auto_export/blueprints/get_blueprints_to_export.py +++ b/tools/blenvy/add_ons/auto_export/blueprints/get_blueprints_to_export.py @@ -1,6 +1,5 @@ -from blenvy.blueprints.blueprint_helpers import find_blueprints_not_on_disk - +from ....blueprints.blueprint_helpers import find_blueprints_not_on_disk def is_blueprint_always_export(blueprint): return blueprint.collection['always_export'] if 'always_export' in blueprint.collection else False diff --git a/tools/blenvy/add_ons/auto_export/common/auto_export.py b/tools/blenvy/add_ons/auto_export/common/auto_export.py index 05e6bea..cf86871 100644 --- a/tools/blenvy/add_ons/auto_export/common/auto_export.py +++ b/tools/blenvy/add_ons/auto_export/common/auto_export.py @@ -3,8 +3,7 @@ import os import bpy import traceback -from blenvy.blueprints.blueprints_scan import blueprints_scan -from blenvy.blueprints.blueprint_helpers import inject_export_path_into_internal_blueprints +from ....blueprints.blueprint_helpers import inject_export_path_into_internal_blueprints from ..blueprints.get_blueprints_to_export import get_blueprints_to_export from ..levels.get_levels_to_export import get_levels_to_export diff --git a/tools/blenvy/add_ons/auto_export/common/duplicate_object.py b/tools/blenvy/add_ons/auto_export/common/duplicate_object.py index 26ee995..c0aade4 100644 --- a/tools/blenvy/add_ons/auto_export/common/duplicate_object.py +++ b/tools/blenvy/add_ons/auto_export/common/duplicate_object.py @@ -1,7 +1,7 @@ import json import bpy -from blenvy.core.object_makers import (make_empty) -from blenvy.add_ons.bevy_components.utils import is_component_valid_and_enabled +from ....core.object_makers import make_empty +from ...bevy_components.utils import is_component_valid_and_enabled from ..constants import custom_properties_to_filter_out from ..utils import remove_unwanted_custom_properties diff --git a/tools/blenvy/add_ons/auto_export/common/export_gltf.py b/tools/blenvy/add_ons/auto_export/common/export_gltf.py index 10d6ae5..df69cf7 100644 --- a/tools/blenvy/add_ons/auto_export/common/export_gltf.py +++ b/tools/blenvy/add_ons/auto_export/common/export_gltf.py @@ -2,7 +2,7 @@ import json import os import bpy -from blenvy.settings import load_settings +from ....settings import load_settings def get_standard_exporter_settings(): standard_gltf_exporter_settings = load_settings(".blenvy_gltf_settings") diff --git a/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py b/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py index 4ba36a0..5856a97 100644 --- a/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py +++ b/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py @@ -1,6 +1,6 @@ import bpy -from blenvy.core.helpers_collections import (set_active_collection) -from blenvy.core.object_makers import (make_empty) +from ....core.helpers_collections import set_active_collection +from ....core.object_makers import make_empty from .duplicate_object import duplicate_object from .export_gltf import export_gltf from ..constants import custom_properties_to_filter_out diff --git a/tools/blenvy/add_ons/auto_export/common/prepare_and_export.py b/tools/blenvy/add_ons/auto_export/common/prepare_and_export.py index 27d73d3..0175a4e 100644 --- a/tools/blenvy/add_ons/auto_export/common/prepare_and_export.py +++ b/tools/blenvy/add_ons/auto_export/common/prepare_and_export.py @@ -3,7 +3,7 @@ import bpy from .project_diff import get_changes_per_scene from .auto_export import auto_export from .settings_diff import get_setting_changes -from blenvy.settings import load_settings, upsert_settings +from ....settings import upsert_settings # prepare export by gather the changes to the scenes & settings def prepare_and_export(): diff --git a/tools/blenvy/add_ons/auto_export/common/project_diff.py b/tools/blenvy/add_ons/auto_export/common/project_diff.py index 484af37..59afbca 100644 --- a/tools/blenvy/add_ons/auto_export/common/project_diff.py +++ b/tools/blenvy/add_ons/auto_export/common/project_diff.py @@ -2,7 +2,7 @@ import json import traceback import bpy from .serialize_project import serialize_project -from blenvy.settings import load_settings, upsert_settings +from ....settings import load_settings def bubble_up_changes(object, changes_per_scene): if object is not None and object.parent: diff --git a/tools/blenvy/add_ons/auto_export/common/settings_diff.py b/tools/blenvy/add_ons/auto_export/common/settings_diff.py index 0f0f2e3..55a2ffb 100644 --- a/tools/blenvy/add_ons/auto_export/common/settings_diff.py +++ b/tools/blenvy/add_ons/auto_export/common/settings_diff.py @@ -1,6 +1,4 @@ -import bpy - -from blenvy.settings import are_settings_identical, load_settings, changed_settings +from ....settings import are_settings_identical, load_settings, changed_settings # which common settings changes should trigger a re-export parameter_names_whitelist_common = [ diff --git a/tools/blenvy/add_ons/auto_export/levels/get_levels_to_export.py b/tools/blenvy/add_ons/auto_export/levels/get_levels_to_export.py index bf5584f..f6c9b6b 100644 --- a/tools/blenvy/add_ons/auto_export/levels/get_levels_to_export.py +++ b/tools/blenvy/add_ons/auto_export/levels/get_levels_to_export.py @@ -1,5 +1,5 @@ import bpy -from blenvy.blueprints.blueprint_helpers import check_if_blueprint_on_disk +from ....blueprints.blueprint_helpers import check_if_blueprint_on_disk # IF collection_instances_combine_mode is not 'split' check for each scene if any object in changes_per_scene has an instance in the scene def changed_object_in_scene(scene_name, changes_per_scene, blueprints_data, collection_instances_combine_mode): diff --git a/tools/blenvy/add_ons/auto_export/materials/export_materials.py b/tools/blenvy/add_ons/auto_export/materials/export_materials.py index 08c299f..de9b0dc 100644 --- a/tools/blenvy/add_ons/auto_export/materials/export_materials.py +++ b/tools/blenvy/add_ons/auto_export/materials/export_materials.py @@ -1,8 +1,7 @@ import os import bpy - -from blenvy.core.helpers_collections import (traverse_tree) -from blenvy.core.object_makers import make_cube +from ....core.helpers_collections import traverse_tree +from ....core.object_makers import make_cube from ..common.generate_temporary_scene_and_export import generate_temporary_scene_and_export from ..common.export_gltf import (generate_gltf_export_settings) diff --git a/tools/blenvy/add_ons/auto_export/materials/get_materials_to_export.py b/tools/blenvy/add_ons/auto_export/materials/get_materials_to_export.py index e3f96a2..11ab92b 100644 --- a/tools/blenvy/add_ons/auto_export/materials/get_materials_to_export.py +++ b/tools/blenvy/add_ons/auto_export/materials/get_materials_to_export.py @@ -1,6 +1,6 @@ import bpy -from blenvy.materials.materials_helpers import find_materials_not_on_disk +from ....materials.materials_helpers import find_materials_not_on_disk def get_materials_to_export(changes_per_material, changed_export_parameters, blueprints_data, settings): export_gltf_extension = getattr(settings, "export_gltf_extension", ".glb") diff --git a/tools/blenvy/add_ons/auto_export/settings.py b/tools/blenvy/add_ons/auto_export/settings.py index a08e9fe..726e5ba 100644 --- a/tools/blenvy/add_ons/auto_export/settings.py +++ b/tools/blenvy/add_ons/auto_export/settings.py @@ -1,7 +1,7 @@ import bpy from bpy_types import (PropertyGroup) from bpy.props import (EnumProperty, PointerProperty, StringProperty, BoolProperty, CollectionProperty, IntProperty) -from blenvy.settings import load_settings, upsert_settings, generate_complete_settings_dict +from ...settings import load_settings, upsert_settings, generate_complete_settings_dict # list of settings we do NOT want to save settings_black_list = ['settings_save_enabled', 'dry_run'] diff --git a/tools/blenvy/add_ons/auto_export/utils.py b/tools/blenvy/add_ons/auto_export/utils.py index b2bc3cc..8e879fd 100644 --- a/tools/blenvy/add_ons/auto_export/utils.py +++ b/tools/blenvy/add_ons/auto_export/utils.py @@ -1,8 +1,8 @@ import posixpath import bpy from pathlib import Path -from blenvy.assets.assets_scan import get_blueprint_asset_tree, get_level_scene_assets_tree2 -from blenvy.add_ons.bevy_components.utils import is_component_valid_and_enabled +from ...assets.assets_scan import get_blueprint_asset_tree, get_level_scene_assets_tree2 +from ..bevy_components.utils import is_component_valid_and_enabled from .constants import custom_properties_to_filter_out from ...assets.assets_scan import get_level_scene_assets_tree2 diff --git a/tools/blenvy/add_ons/bevy_components/components/lists.py b/tools/blenvy/add_ons/bevy_components/components/lists.py index d809021..4b10201 100644 --- a/tools/blenvy/add_ons/bevy_components/components/lists.py +++ b/tools/blenvy/add_ons/bevy_components/components/lists.py @@ -1,7 +1,7 @@ import json from bpy_types import Operator from bpy.props import (StringProperty, EnumProperty, IntProperty) -from blenvy.add_ons.bevy_components.utils import get_item_by_type +from ..utils import get_item_by_type class BLENVY_OT_component_list_actions(Operator): """Move items up and down, add and remove""" diff --git a/tools/blenvy/add_ons/bevy_components/components/maps.py b/tools/blenvy/add_ons/bevy_components/components/maps.py index 77d152f..5633dbf 100644 --- a/tools/blenvy/add_ons/bevy_components/components/maps.py +++ b/tools/blenvy/add_ons/bevy_components/components/maps.py @@ -3,7 +3,7 @@ from bpy_types import Operator, UIList from bpy.props import (StringProperty, EnumProperty, PointerProperty, FloatVectorProperty, IntProperty) from ..propGroups.conversions_from_prop_group import property_group_value_to_custom_property_value -from blenvy.add_ons.bevy_components.utils import get_item_by_type +from ..utils import get_item_by_type class BLENVY_OT_component_map_actions(Operator): """Move items up and down, add and remove""" diff --git a/tools/blenvy/add_ons/bevy_components/registry/operators.py b/tools/blenvy/add_ons/bevy_components/registry/operators.py index dc71961..aec46fc 100644 --- a/tools/blenvy/add_ons/bevy_components/registry/operators.py +++ b/tools/blenvy/add_ons/bevy_components/registry/operators.py @@ -3,8 +3,7 @@ import bpy from bpy_types import (Operator) from bpy.props import (StringProperty) from bpy_extras.io_utils import ImportHelper - -from blenvy.settings import upsert_settings +from ....settings import upsert_settings from ..components.metadata import ensure_metadata_for_all_items from ..propGroups.prop_groups import generate_propertyGroups_for_components diff --git a/tools/blenvy/add_ons/bevy_components/settings.py b/tools/blenvy/add_ons/bevy_components/settings.py index 6671faa..c698425 100644 --- a/tools/blenvy/add_ons/bevy_components/settings.py +++ b/tools/blenvy/add_ons/bevy_components/settings.py @@ -2,7 +2,8 @@ import os import bpy from bpy_types import (PropertyGroup) from bpy.props import (EnumProperty, PointerProperty, StringProperty, BoolProperty, CollectionProperty, FloatProperty) -from blenvy.settings import load_settings, upsert_settings, generate_complete_settings_dict +from ...settings import load_settings, upsert_settings, generate_complete_settings_dict + from .propGroups.prop_groups import generate_propertyGroups_for_components from .components.metadata import ensure_metadata_for_all_items from .utils import add_component_to_ui_list diff --git a/tools/blenvy/add_ons/bevy_components/utils.py b/tools/blenvy/add_ons/bevy_components/utils.py index 411b5bc..d3e626a 100644 --- a/tools/blenvy/add_ons/bevy_components/utils.py +++ b/tools/blenvy/add_ons/bevy_components/utils.py @@ -1,10 +1,9 @@ +import json import bpy -from .constants import HIDDEN_COMPONENTS from bpy.props import StringProperty, EnumProperty from bpy_types import Operator -from blenvy.core.helpers_collections import (set_active_collection) - -import json +from ...core.helpers_collections import set_active_collection +from .constants import HIDDEN_COMPONENTS def select_area(context, area_name): for area in context.screen.areas: diff --git a/tools/blenvy/blueprints/operators.py b/tools/blenvy/blueprints/operators.py index 92ec234..3fbd0e8 100644 --- a/tools/blenvy/blueprints/operators.py +++ b/tools/blenvy/blueprints/operators.py @@ -2,7 +2,7 @@ import os import bpy from bpy_types import (Operator) from bpy.props import (StringProperty) -from blenvy.core.helpers_collections import set_active_collection +from ..core.helpers_collections import set_active_collection class BLENVY_OT_blueprint_select(Operator): """Select blueprint """ diff --git a/tools/blenvy/core/blenvy_manager.py b/tools/blenvy/core/blenvy_manager.py index f0a5506..0e50f4a 100644 --- a/tools/blenvy/core/blenvy_manager.py +++ b/tools/blenvy/core/blenvy_manager.py @@ -3,9 +3,8 @@ import bpy from bpy_types import (PropertyGroup) from bpy.props import (BoolProperty, EnumProperty, PointerProperty, StringProperty, CollectionProperty, IntProperty) from ..settings import upsert_settings, load_settings, generate_complete_settings_dict -import blenvy.add_ons.auto_export.settings as auto_export_settings -import blenvy.add_ons.bevy_components.settings as component_settings - +from ..add_ons.auto_export.settings import AutoExportSettings +from ..add_ons.bevy_components.settings import ComponentsSettings # list of settings we do NOT want to save settings_black_list = ['settings_save_enabled', 'level_scene_selector', 'library_scene_selector'] @@ -127,8 +126,8 @@ class BlenvyManager(PropertyGroup): ) # type: ignore # sub ones - auto_export: PointerProperty(type=auto_export_settings.AutoExportSettings) # type: ignore - components: PointerProperty(type=component_settings.ComponentsSettings) # type: ignore + auto_export: PointerProperty(type=AutoExportSettings) # type: ignore + components: PointerProperty(type=ComponentsSettings) # type: ignore level_scene_selector: PointerProperty(type=bpy.types.Scene, name="level scene", description="level scene picker", poll=is_scene_already_in_use, update=save_settings)# type: ignore library_scene_selector: PointerProperty(type=bpy.types.Scene, name="library scene", description="library scene picker", poll=is_scene_already_in_use, update=save_settings)# type: ignore diff --git a/tools/blenvy/core/ui/ui.py b/tools/blenvy/core/ui/ui.py index 8212463..35e11ad 100644 --- a/tools/blenvy/core/ui/ui.py +++ b/tools/blenvy/core/ui/ui.py @@ -1,7 +1,8 @@ import bpy -import blenvy.add_ons.bevy_components.ui as components_ui -import blenvy.add_ons.auto_export.ui as auto_export_ui # from ...bevy_components.components import ui# as components_ui +from ...add_ons.bevy_components import ui as components_ui +from ...add_ons.auto_export import ui as auto_export_ui + ###################################################### ## ui logic & co