2024-05-15 21:32:01 +00:00
|
|
|
from types import SimpleNamespace
|
2024-05-12 09:05:11 +00:00
|
|
|
import bpy
|
2024-05-15 21:32:01 +00:00
|
|
|
from .assets_scan import get_main_scene_assets_tree
|
2024-06-05 09:17:49 +00:00
|
|
|
from .asset_helpers import get_user_assets, does_asset_exist
|
2024-05-13 21:36:13 +00:00
|
|
|
|
2024-05-16 12:09:40 +00:00
|
|
|
def draw_assets(layout, name, title, asset_registry, target_type, target_name, editable=True, user_assets= [], generated_assets = []):
|
2024-06-06 18:16:32 +00:00
|
|
|
nesting_indent = 0.05
|
2024-06-05 15:09:03 +00:00
|
|
|
number_of_user_assets = len(user_assets)
|
|
|
|
number_of_generated_assets = len(generated_assets)
|
|
|
|
|
2024-06-05 22:12:17 +00:00
|
|
|
header, panel = layout.panel(f"assets{name}", default_closed=True)
|
2024-06-09 21:14:49 +00:00
|
|
|
header.label(text=title + f"({number_of_user_assets})", icon="ASSET_MANAGER")
|
2024-06-05 09:17:49 +00:00
|
|
|
|
2024-06-05 22:12:17 +00:00
|
|
|
|
|
|
|
blueprint_assets = target_type == 'BLUEPRINT'
|
|
|
|
if blueprint_assets:
|
|
|
|
target = bpy.data.collections[target_name]
|
|
|
|
else:
|
|
|
|
target = bpy.data.scenes[target_name]
|
|
|
|
|
|
|
|
add_possible = does_asset_exist(target, {"path": asset_registry.asset_path_selector}) #"name": asset_registry.asset_name_selector,
|
|
|
|
|
2024-06-08 09:52:13 +00:00
|
|
|
if header and editable:
|
2024-06-05 22:12:17 +00:00
|
|
|
row = header.row()
|
|
|
|
row.alert = add_possible
|
|
|
|
|
|
|
|
row.prop(asset_registry, "asset_name_selector", text="")
|
|
|
|
row.label(text=asset_registry.asset_path_selector)
|
|
|
|
row.operator(operator="asset.open_filebrowser", text="", icon="FILE_FOLDER")
|
|
|
|
|
|
|
|
add_asset_layout = row.column()
|
|
|
|
add_asset_layout.enabled = not add_possible
|
|
|
|
|
|
|
|
add_asset = add_asset_layout.operator(operator="bevyassets.add", text="", icon="ADD")
|
|
|
|
add_asset.target_type = target_type
|
|
|
|
add_asset.target_name = target_name
|
|
|
|
add_asset.asset_name = asset_registry.asset_name_selector
|
|
|
|
add_asset.asset_type = asset_registry.asset_type_selector
|
|
|
|
add_asset.asset_path = asset_registry.asset_path_selector
|
|
|
|
|
2024-05-13 21:36:13 +00:00
|
|
|
if panel:
|
2024-05-15 11:25:30 +00:00
|
|
|
if editable:
|
|
|
|
row = panel.row()
|
2024-06-06 18:16:32 +00:00
|
|
|
#panel.separator()
|
2024-06-09 21:14:49 +00:00
|
|
|
print("here", user_assets)
|
2024-05-16 12:09:40 +00:00
|
|
|
for asset in user_assets:
|
2024-06-09 21:14:49 +00:00
|
|
|
print("asset", asset)
|
2024-05-13 21:36:13 +00:00
|
|
|
row = panel.row()
|
2024-06-06 18:16:32 +00:00
|
|
|
split = row.split(factor=nesting_indent)
|
2024-06-05 22:12:17 +00:00
|
|
|
col = split.column()
|
|
|
|
col.label(text=" ")
|
|
|
|
col = split.column()
|
|
|
|
|
|
|
|
row = col.row()
|
2024-06-06 18:16:32 +00:00
|
|
|
row.label(icon="ASSET_MANAGER")
|
2024-05-16 12:09:40 +00:00
|
|
|
row.prop(asset, "name", text="")
|
|
|
|
row.label(text=asset.path)
|
|
|
|
asset_selector = row.operator(operator="asset.open_filebrowser", text="", icon="FILE_FOLDER")
|
|
|
|
|
|
|
|
remove_asset = row.operator(operator="bevyassets.remove", text="", icon="TRASH")
|
|
|
|
remove_asset.target_type = target_type
|
|
|
|
remove_asset.target_name = target_name
|
|
|
|
remove_asset.asset_path = asset.path
|
2024-05-15 21:32:01 +00:00
|
|
|
return panel
|
|
|
|
|
2024-05-15 11:25:30 +00:00
|
|
|
class Blenvy_assets(bpy.types.Panel):
|
2024-05-12 09:05:11 +00:00
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
bl_region_type = 'UI'
|
2024-05-13 08:28:44 +00:00
|
|
|
bl_label = ""
|
2024-05-12 10:09:11 +00:00
|
|
|
bl_parent_id = "BLENVY_PT_SidePanel"
|
2024-05-13 21:36:13 +00:00
|
|
|
bl_options = {'DEFAULT_CLOSED','HIDE_HEADER'}
|
2024-05-12 10:09:11 +00:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return context.window_manager.blenvy.mode == 'ASSETS'
|
|
|
|
|
2024-05-12 09:05:11 +00:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
layout.use_property_split = True
|
|
|
|
layout.use_property_decorate = False # No animation.
|
2024-05-19 09:22:34 +00:00
|
|
|
blenvy = context.window_manager.blenvy
|
2024-05-12 09:05:11 +00:00
|
|
|
|
2024-05-15 21:32:01 +00:00
|
|
|
layout.operator(operator="bevyassets.test")
|
|
|
|
|
2024-05-12 09:05:11 +00:00
|
|
|
asset_registry = context.window_manager.assets_registry
|
2024-05-15 21:32:01 +00:00
|
|
|
blueprints_registry = context.window_manager.blueprints_registry
|
2024-05-25 08:46:14 +00:00
|
|
|
#blueprints_registry.refresh_blueprints()
|
2024-05-15 21:32:01 +00:00
|
|
|
blueprints_data = blueprints_registry.blueprints_data
|
|
|
|
|
2024-05-13 21:36:13 +00:00
|
|
|
name = "world"
|
|
|
|
header, panel = layout.box().panel(f"assets{name}", default_closed=False)
|
|
|
|
header.label(text="World/Level Assets")
|
2024-05-12 09:05:11 +00:00
|
|
|
|
2024-05-17 12:30:15 +00:00
|
|
|
settings = {"blueprints_path": "blueprints", "export_gltf_extension": ".glb"}
|
2024-05-15 21:32:01 +00:00
|
|
|
settings = SimpleNamespace(**settings)
|
|
|
|
|
2024-05-13 21:36:13 +00:00
|
|
|
if panel:
|
2024-06-07 11:55:00 +00:00
|
|
|
for scene in blenvy.main_scenes:
|
2024-05-19 09:22:34 +00:00
|
|
|
user_assets = get_user_assets(scene)
|
2024-06-05 22:12:17 +00:00
|
|
|
|
2024-05-19 09:22:34 +00:00
|
|
|
row = panel.row()
|
2024-06-04 21:16:16 +00:00
|
|
|
row.prop(scene, "always_export")
|
|
|
|
|
2024-05-19 09:22:34 +00:00
|
|
|
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():
|
|
|
|
blueprint = blueprints_data.blueprints_per_name[blueprint_name]
|
|
|
|
blueprint_assets = get_user_assets(blueprint.collection)
|
|
|
|
if scene_assets_panel:
|
|
|
|
row = scene_assets_panel.row()
|
|
|
|
draw_assets(layout=row, name=blueprint.name, title=f"{blueprint.name} Assets", asset_registry=asset_registry, assets=blueprint_assets, target_type="BLUEPRINT", target_name=blueprint.name)
|
2024-05-16 12:09:40 +00:00
|
|
|
"""
|