From 53d432fc77fe853680af47c40a276401210c139d Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Sun, 12 May 2024 15:10:35 +0200 Subject: [PATCH] feat(blenvy): * overhauled selection * made adding/removing assets specific to collections/scenes (blueprints/levels) * ui tweaks & improvements * etc --- tools/gltf_auto_export/assets/operators.py | 39 ++++++++++++++++++- tools/gltf_auto_export/assets/ui.py | 16 ++++++-- tools/gltf_auto_export/blenvy/ui.py | 5 ++- .../helpers/helpers_blueprints.py | 1 + 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/tools/gltf_auto_export/assets/operators.py b/tools/gltf_auto_export/assets/operators.py index 930d0d4..1dc2f66 100644 --- a/tools/gltf_auto_export/assets/operators.py +++ b/tools/gltf_auto_export/assets/operators.py @@ -1,4 +1,5 @@ import os +import json import bpy from bpy_types import (Operator) from bpy.props import (StringProperty, EnumProperty) @@ -29,7 +30,26 @@ class OT_add_bevy_asset(Operator): ) # type: ignore def execute(self, context): - context.window_manager.assets_registry.add_asset(self.asset_name, self.asset_type, self.asset_path, False) + assets_list = [] + blueprint_assets = False + if context.collection is not None and context.collection.name == 'Scene Collection': + assets_list = json.loads(context.scene.get('assets')) + blueprint_assets = False + else: + if 'assets' in context.collection: + assets_list = json.loads(context.collection.get('assets')) + blueprint_assets = True + + in_list = [asset for asset in assets_list if (asset["path"] == self.asset_path)] + in_list = len(in_list) > 0 + if not in_list: + assets_list.append({"name": self.asset_name, "type": self.asset_type, "path": self.asset_path, "internal": False}) + + if blueprint_assets: + context.collection["assets"] = json.dumps(assets_list) + else: + context.scene["assets"] = json.dumps(assets_list) + #context.window_manager.assets_registry.add_asset(self.asset_name, self.asset_type, self.asset_path, False) return {'FINISHED'} @@ -46,5 +66,20 @@ class OT_remove_bevy_asset(Operator): ) # type: ignore def execute(self, context): - context.window_manager.assets_registry.remove_asset(self.asset_path) + assets_list = [] + blueprint_assets = False + if context.collection is not None and context.collection.name == 'Scene Collection': + assets_list = json.loads(context.scene.get('assets')) + blueprint_assets = False + else: + if 'assets' in context.collection: + assets_list = json.loads(context.collection.get('assets')) + blueprint_assets = True + + assets_list = [asset for asset in assets_list if (asset["path"] != self.asset_path)] + if blueprint_assets: + context.collection["assets"] = json.dumps(assets_list) + else: + context.scene["assets"] = json.dumps(assets_list) + #context.window_manager.assets_registry.remove_asset(self.asset_path) return {'FINISHED'} \ No newline at end of file diff --git a/tools/gltf_auto_export/assets/ui.py b/tools/gltf_auto_export/assets/ui.py index 5864eea..382e1cd 100644 --- a/tools/gltf_auto_export/assets/ui.py +++ b/tools/gltf_auto_export/assets/ui.py @@ -1,4 +1,5 @@ import bpy +import json class GLTF_PT_auto_export_assets(bpy.types.Panel): bl_space_type = 'VIEW_3D' @@ -34,8 +35,15 @@ class GLTF_PT_auto_export_assets(bpy.types.Panel): row.label(text="Type") row.label(text="Path") row.label(text="Remove") - - for asset in asset_registry.assets_list: + #print("FOO", json.dumps([{"name":"foo", "type":"MODEL", "path":"bla", "internal":True}])) + # [{"name": "trigger_sound", "type": "AUDIO", "path": "assets/audio/trigger.mp3", "internal": true}] + assets_list = [] + if context.collection is not None and context.collection.name == 'Scene Collection': + assets_list = json.loads(context.scene.get('assets')) #asset_registry.assets_list + else: + if 'assets' in context.collection: + assets_list = json.loads(context.collection.get('assets')) + for asset in assets_list: row = layout.row() row.label(text=asset["name"]) row.label(text=asset["type"]) @@ -44,4 +52,6 @@ class GLTF_PT_auto_export_assets(bpy.types.Panel): remove_asset = row.operator(operator="bevyassets.remove", text="remove") remove_asset.asset_path = asset["path"] else: - row.label(text="") \ No newline at end of file + row.label(text="") + + # \ No newline at end of file diff --git a/tools/gltf_auto_export/blenvy/ui.py b/tools/gltf_auto_export/blenvy/ui.py index cf21292..cebeab3 100644 --- a/tools/gltf_auto_export/blenvy/ui.py +++ b/tools/gltf_auto_export/blenvy/ui.py @@ -25,19 +25,22 @@ class BLENVY_PT_SidePanel(bpy.types.Panel): active_mode = blenvy.mode world_scene_active = False library_scene_active = False + active_collection = context.collection current_auto_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else None current_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings"] if ".gltf_auto_export_gltf_settings" in bpy.data.texts else None if current_auto_settings is not None: current_auto_settings = json.loads(current_auto_settings.as_string()) - print("current_auto_settings", current_auto_settings) + #print("current_auto_settings", current_auto_settings) main_scene_names = current_auto_settings["main_scene_names"] library_scene_names = current_auto_settings["library_scene_names"] world_scene_active = context.scene.name in main_scene_names library_scene_active = context.scene.name in library_scene_names + layout.label(text="Active Blueprint: "+ active_collection.name.upper()) + # Now to actual drawing of the UI target = row.box() if active_mode == 'COMPONENTS' else row diff --git a/tools/gltf_auto_export/helpers/helpers_blueprints.py b/tools/gltf_auto_export/helpers/helpers_blueprints.py index 01ab9b3..9d0f4a4 100644 --- a/tools/gltf_auto_export/helpers/helpers_blueprints.py +++ b/tools/gltf_auto_export/helpers/helpers_blueprints.py @@ -360,6 +360,7 @@ def inject_blueprints_list_into_main_scene(scene, blueprints_data, addon_prefs): assets_list_name = f"assets_{scene.name}" assets_list_data = {"blueprints": json.dumps(blueprint_assets_list), "sounds":[], "images":[]} + scene["assets"] = json.dumps(blueprint_assets_list) print("blueprint assets", blueprint_assets_list) add_scene_property(scene, assets_list_name, assets_list_data)