From f9cb6de4bc89068afe7169239089faeec7a58c1f Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Tue, 4 Jun 2024 23:16:16 +0200 Subject: [PATCH] feat(Blenvy): added "levels" tab (likely going to be replacing the "assets" tab) * added basic logic, ui, level selector operator etc * fixed issues with asset dialog * added experimental "always_export" flags for collections & scenes to enable always exporting on save for select blueprints & levels (no logic yet, just UI) * various tweaks & minor experiments --- tools/blenvy/TODO.md | 8 +-- tools/blenvy/__init__.py | 7 +++ tools/blenvy/assets/operators.py | 8 +-- tools/blenvy/assets/ui.py | 4 +- tools/blenvy/blueprints/ui.py | 2 + tools/blenvy/core/blenvy_manager.py | 10 ++++ tools/blenvy/core/operators.py | 2 +- tools/blenvy/core/ui/ui.py | 4 ++ tools/blenvy/levels/__init__.py | 0 tools/blenvy/levels/operators.py | 26 ++++++++++ tools/blenvy/levels/ui.py | 77 +++++++++++++++++++++++++++++ 11 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 tools/blenvy/levels/__init__.py create mode 100644 tools/blenvy/levels/operators.py create mode 100644 tools/blenvy/levels/ui.py diff --git a/tools/blenvy/TODO.md b/tools/blenvy/TODO.md index 606474f..5e39d7c 100644 --- a/tools/blenvy/TODO.md +++ b/tools/blenvy/TODO.md @@ -74,7 +74,7 @@ Components: General things to solve: - [x] save settings - [x] load settings - - [ ] add blueprints data + - [x] add blueprints data - [x] rename all path stuff using the old naming convention : "blueprints_path_full" - [x] generate the full paths directly when setting them in the UI @@ -100,10 +100,12 @@ General issues: - [ ] force overwrite of settings files instead of partial updates ? - [ ] add tests for disabled components -- [x] fix auto export workflow +- [x] fix auto export workflow - [ ] should we write the previous _xxx data only AFTER a sucessfull export only ? - [x] add hashing of modifiers/ geometry nodes in serialize scene - [ ] add ability to FORCE export specific blueprints & levels - [ ] undo after a save removes any saved "serialized scene" data ? DIG into this - [ ] handle scene renames between saves (breaks diffing) -- [ ] change scene selector to work on actual scenes aka to deal with renamed scenes \ No newline at end of file +- [ ] change scene selector to work on actual scenes aka to deal with renamed scenes +- [x] fix asset file selection +- [x] change "assets" tab to "levels"/worlds tab & modify UI accordingly \ No newline at end of file diff --git a/tools/blenvy/__init__.py b/tools/blenvy/__init__.py index 97004d3..214a3b9 100644 --- a/tools/blenvy/__init__.py +++ b/tools/blenvy/__init__.py @@ -38,6 +38,10 @@ from .assets.ui import Blenvy_assets from .assets.assets_registry import Asset, AssetsRegistry from .assets.operators import OT_Add_asset_filebrowser, OT_add_bevy_asset, OT_remove_bevy_asset, OT_test_bevy_assets +# levels management +from .levels.ui import Blenvy_levels +from .levels.operators import OT_select_level + # blueprints management from .blueprints.ui import GLTF_PT_auto_export_blueprints_list from .blueprints.blueprints_registry import BlueprintsRegistry @@ -129,6 +133,9 @@ classes = [ OT_Add_asset_filebrowser, Blenvy_assets, + Blenvy_levels, + OT_select_level, + BlueprintsRegistry, OT_select_blueprint, GLTF_PT_auto_export_blueprints_list, diff --git a/tools/blenvy/assets/operators.py b/tools/blenvy/assets/operators.py index 8307fe6..a813e54 100644 --- a/tools/blenvy/assets/operators.py +++ b/tools/blenvy/assets/operators.py @@ -144,10 +144,10 @@ class OT_Add_asset_filebrowser(Operator, ImportHelper): # Filters files filter_glob: StringProperty(options={'HIDDEN'}, default='*.jpg;*.jpeg;*.png;*.bmp') # type: ignore - def execute(self, context): - current_auto_settings = load_settings(".gltf_auto_export_settings") - project_root_path = current_auto_settings.get("project_root_path", "../") - assets_path = current_auto_settings.get("assets_path", "assets") + def execute(self, context): + blenvy = context.window_manager.blenvy + project_root_path = blenvy.project_root_path + assets_path = blenvy.assets_path # FIXME: not sure print("project_root_path", project_root_path, "assets_path", assets_path) export_assets_path_absolute = absolute_path_from_blend_file(os.path.join(project_root_path, assets_path)) diff --git a/tools/blenvy/assets/ui.py b/tools/blenvy/assets/ui.py index 50c748e..db714d8 100644 --- a/tools/blenvy/assets/ui.py +++ b/tools/blenvy/assets/ui.py @@ -5,7 +5,7 @@ from .asset_helpers import get_user_assets def draw_assets(layout, name, title, asset_registry, target_type, target_name, editable=True, user_assets= [], generated_assets = []): - header, panel = layout.box().panel(f"assets{name}", default_closed=False) + header, panel = layout.panel(f"assets{name}", default_closed=False) header.label(text=title) if panel: if editable: @@ -92,6 +92,8 @@ class Blenvy_assets(bpy.types.Panel): user_assets = get_user_assets(scene) #print("user assets", user_assets, scene) row = panel.row() + row.prop(scene, "always_export") + scene_assets_panel = draw_assets(layout=row, name=scene.name, title=f"{scene.name} Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="SCENE", target_name=scene.name) """if scene.name in blueprints_data.blueprint_instances_per_main_scene: for blueprint_name in blueprints_data.blueprint_instances_per_main_scene[scene.name].keys(): diff --git a/tools/blenvy/blueprints/ui.py b/tools/blenvy/blueprints/ui.py index dbf14a2..1aca00e 100644 --- a/tools/blenvy/blueprints/ui.py +++ b/tools/blenvy/blueprints/ui.py @@ -30,6 +30,8 @@ class GLTF_PT_auto_export_blueprints_list(bpy.types.Panel): row.label(icon="RIGHTARROW") row.label(text=blueprint.name) + row.prop(blueprint.collection, "always_export") + if blueprint.local: select_blueprint = row.operator(operator="blueprint.select", text="", icon="RESTRICT_SELECT_OFF") diff --git a/tools/blenvy/core/blenvy_manager.py b/tools/blenvy/core/blenvy_manager.py index 138ac62..a18f0c6 100644 --- a/tools/blenvy/core/blenvy_manager.py +++ b/tools/blenvy/core/blenvy_manager.py @@ -48,6 +48,7 @@ class BlenvyManager(PropertyGroup): items=( ('COMPONENTS', "Components", ""), ('BLUEPRINTS', "Blueprints", ""), + ('LEVELS', "Levels", ""), ('ASSETS', "Assets", ""), ('SETTINGS', "Settings", ""), ('TOOLS', "Tools", ""), @@ -135,10 +136,19 @@ class BlenvyManager(PropertyGroup): def register(cls): bpy.types.WindowManager.blenvy = PointerProperty(type=BlenvyManager) + # unsure + # you can add components to both objects & collections + #bpy.types.Object.components_meta = PointerProperty(type=ComponentsMeta) + bpy.types.Collection.always_export = BoolProperty(default=False, description="always export this blueprint, regardless of changed status") # FIXME: not sure about this one + bpy.types.Scene.always_export = BoolProperty(default=False, description="always export this blueprint, regardless of changed status") # FIXME: not sure about this one + @classmethod def unregister(cls): del bpy.types.WindowManager.blenvy + del bpy.types.Collection.always_export + del bpy.types.Scene.always_export + def load_settings(self): print("LOAD SETTINGS") settings = load_settings(self.settings_save_path) diff --git a/tools/blenvy/core/operators.py b/tools/blenvy/core/operators.py index 08896a9..0f46750 100644 --- a/tools/blenvy/core/operators.py +++ b/tools/blenvy/core/operators.py @@ -10,11 +10,11 @@ class OT_switch_bevy_tooling(Operator): bl_label = "Switch bevy tooling" #bl_options = {} - tool: EnumProperty( items=( ('COMPONENTS', "Components", "Switch to components"), ('BLUEPRINTS', "Blueprints", ""), + ('LEVELS', "Levels", ""), ('ASSETS', "Assets", ""), ('SETTINGS', "Settings", ""), ('TOOLS', "Tools", ""), diff --git a/tools/blenvy/core/ui/ui.py b/tools/blenvy/core/ui/ui.py index 2482885..fa47041 100644 --- a/tools/blenvy/core/ui/ui.py +++ b/tools/blenvy/core/ui/ui.py @@ -57,6 +57,10 @@ class BLENVY_PT_SidePanel(bpy.types.Panel): tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="PACKAGE") tool_switch_components.tool = "BLUEPRINTS" + target = row.box() if active_mode == 'LEVELS' else row + tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="PACKAGE") + tool_switch_components.tool = "LEVELS" + target = row.box() if active_mode == 'ASSETS' else row tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="ASSET_MANAGER") tool_switch_components.tool = "ASSETS" diff --git a/tools/blenvy/levels/__init__.py b/tools/blenvy/levels/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/blenvy/levels/operators.py b/tools/blenvy/levels/operators.py new file mode 100644 index 0000000..cdc7fe3 --- /dev/null +++ b/tools/blenvy/levels/operators.py @@ -0,0 +1,26 @@ +import os +import bpy +from bpy_types import (Operator) +from bpy.props import (StringProperty) + +class OT_select_level(Operator): + """Select level """ + bl_idname = "level.select" + bl_label = "Select level" + bl_options = {"UNDO"} + + level_name: StringProperty( + name="level name", + description="level to select", + ) # type: ignore + + def execute(self, context): + if self.level_name: + scene = bpy.data.scenes[self.level_name] + if scene: + # bpy.ops.object.select_all(action='DESELECT') + bpy.context.window.scene = scene + + + return {'FINISHED'} + \ No newline at end of file diff --git a/tools/blenvy/levels/ui.py b/tools/blenvy/levels/ui.py new file mode 100644 index 0000000..58549a3 --- /dev/null +++ b/tools/blenvy/levels/ui.py @@ -0,0 +1,77 @@ +from types import SimpleNamespace +import bpy +from ..assets.assets_scan import get_main_scene_assets_tree +from ..assets.asset_helpers import get_user_assets +from ..assets.ui import draw_assets + +class Blenvy_levels(bpy.types.Panel): + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_label = "" + bl_parent_id = "BLENVY_PT_SidePanel" + bl_options = {'DEFAULT_CLOSED','HIDE_HEADER'} + @classmethod + def poll(cls, context): + return context.window_manager.blenvy.mode == 'LEVELS' + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False # No animation. + blenvy = context.window_manager.blenvy + layout.operator(operator="bevyassets.test") + + asset_registry = context.window_manager.assets_registry + blueprints_registry = context.window_manager.blueprints_registry + #blueprints_registry.refresh_blueprints() + blueprints_data = blueprints_registry.blueprints_data + + for scene_selector in blenvy.main_scenes: + scene = bpy.data.scenes[scene_selector.name] + header, panel = layout.box().panel(f"assets{scene.name}", default_closed=False) + if header: + header.label(text=scene.name, icon="HIDE_OFF") + header.prop(scene, "always_export") + select_level = header.operator(operator="level.select", text="", icon="RESTRICT_SELECT_OFF") + select_level.level_name = scene.name + + if panel: + user_assets = get_user_assets(scene) + row = panel.row() + #row.label(text="row") + """col = row.column() + col.label(text=" ") + + col = row.column() + col.label(text="col in row 2") + + column = panel.column() + column.label(text="col")""" + + split = panel.split(factor=0.005) + col = split.column() + col.label(text=" ") + + col = split.column() + #col.label(text="col in row 2") + + scene_assets_panel = draw_assets(layout=col, name=f"{scene.name}_assets", title=f"Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="SCENE", target_name=scene.name) + + + settings = {"blueprints_path": "blueprints", "export_gltf_extension": ".glb"} + settings = SimpleNamespace(**settings) + + """if panel: + for scene_selector in blenvy.main_scenes: + scene = bpy.data.scenes[scene_selector.name] + #get_main_scene_assets_tree(scene, blueprints_data, settings) + user_assets = get_user_assets(scene) + #print("user assets", user_assets, scene) + row = panel.row() + header.prop(scene, "always_export") + + sub_header, sub_panel = row.box().panel(f"assets{name}", default_closed=False) + + + scene_assets_panel = draw_assets(layout=sub_panel, name=scene.name, title=f"{scene.name} Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="SCENE", target_name=scene.name) + """ \ No newline at end of file