feat(blenvy):

* overhauled selection
 * made adding/removing assets specific to collections/scenes (blueprints/levels)
 * ui tweaks & improvements
 * etc
This commit is contained in:
kaosat.dev 2024-05-12 15:10:35 +02:00
parent e42719daf7
commit 53d432fc77
4 changed files with 55 additions and 6 deletions

View File

@ -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'}

View File

@ -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"])
@ -45,3 +53,5 @@ class GLTF_PT_auto_export_assets(bpy.types.Panel):
remove_asset.asset_path = asset["path"]
else:
row.label(text="")
#

View File

@ -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

View File

@ -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)