From f74113a89966abd10be076ab73ab10cecbf9678c Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 20 Dec 2023 16:34:34 -0500 Subject: [PATCH 1/7] Asset Pipeline: Add Enum for Asset Catalog --- .../addons/asset_pipeline/merge/publish.py | 17 ++++++++++ .../addons/asset_pipeline/props.py | 32 +++++++++++++++++++ scripts-blender/addons/asset_pipeline/ui.py | 1 + 3 files changed, 50 insertions(+) diff --git a/scripts-blender/addons/asset_pipeline/merge/publish.py b/scripts-blender/addons/asset_pipeline/merge/publish.py index c74d34c1..30f4b0e6 100644 --- a/scripts-blender/addons/asset_pipeline/merge/publish.py +++ b/scripts-blender/addons/asset_pipeline/merge/publish.py @@ -49,6 +49,22 @@ def get_next_published_file( ) +def get_asset_catalogues(): + folder = Path(bpy.data.filepath).parent + target_catalog = "Catalog" + + with (folder / "blender_assets.cats.txt").open() as f: + for line in f.readlines(): + if line.startswith(("#", "VERSION", "\n")): + continue + # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') + name = line.split(":")[2].split("\n")[0] + if name == target_catalog: + uuid = line.split(":")[0] + obj = bpy.data.objects["Suzanne"] # Object name, case-sensitive ! + asset_data = obj.asset_data + asset_data.catalog_id = uuid + def create_next_published_file( current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY ) -> None: @@ -58,6 +74,7 @@ def create_next_published_file( current_file (Path): Current file, which must be a task file at root of asset directory publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'. """ + # TODO Set Catalogue here new_file_path = get_next_published_file(current_file, publish_type) if publish_type == constants.ACTIVE_PUBLISH_KEY: bpy.context.scene.asset_pipeline.asset_collection.asset_mark() diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index 1a5a1ffa..7284a2a7 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -1,4 +1,5 @@ import bpy +import os from typing import List from . import constants from .config import get_task_layer_presets_path @@ -10,6 +11,19 @@ avaliable task layers from the task_layer.json file that needs to be created. """ +# TODO find better place for this function +def find_asset_cat_file(directory): + asset_file = os.path.join(directory, "blender_assets.cats.txt") + if os.path.exists(asset_file): + return asset_file + + parent_dir = os.path.dirname(directory) + if parent_dir == directory: + raise FileNotFoundError("blender_assets.cats.txt not found") + + return find_asset_cat_file(parent_dir) + + def get_task_layer_presets(self, context): prefs = get_addon_prefs() user_tls = Path(prefs.custom_task_layers_dir) @@ -144,6 +158,24 @@ class AssetPipeline(bpy.types.PropertyGroup): ) file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False) + def get_asset_catalogs(self, context): + items = [] + asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__()) + with (Path(asset_cat_file)).open() as file: + for line in file.readlines(): + if line.startswith(("#", "VERSION", "\n")): + continue + # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') + name = line.split(":")[2].split("\n")[0] + uuid = line.split(":")[0] + + items.append((uuid, name, '')) + return items + + aval_asset_catalogs: bpy.props.EnumProperty( + name="Catalog", items=get_asset_catalogs + ) + classes = ( AssetTransferData, diff --git a/scripts-blender/addons/asset_pipeline/ui.py b/scripts-blender/addons/asset_pipeline/ui.py index 46e6a02f..217a2326 100644 --- a/scripts-blender/addons/asset_pipeline/ui.py +++ b/scripts-blender/addons/asset_pipeline/ui.py @@ -54,6 +54,7 @@ class ASSETPIPE_PT_sync(bpy.types.Panel): for task_layer in asset_pipe.local_task_layers: row.label(text=task_layer.name) + layout.prop(asset_pipe, 'aval_asset_catalogs') layout.prop(asset_pipe, "asset_collection") staged = is_staged_publish(Path(bpy.data.filepath)) -- 2.30.2 From 3cd22dc307a0fc86bccd56774758241cd8e68e10 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 11:15:22 -0500 Subject: [PATCH 2/7] Asset Pipeline: Cache Asset Catalog Data --- .../addons/asset_pipeline/asset_catalog.py | 42 +++++++++++++++++++ .../addons/asset_pipeline/props.py | 31 ++------------ 2 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 scripts-blender/addons/asset_pipeline/asset_catalog.py diff --git a/scripts-blender/addons/asset_pipeline/asset_catalog.py b/scripts-blender/addons/asset_pipeline/asset_catalog.py new file mode 100644 index 00000000..54a2b884 --- /dev/null +++ b/scripts-blender/addons/asset_pipeline/asset_catalog.py @@ -0,0 +1,42 @@ +import os +from pathlib import Path +import bpy + +asset_file_cache = None +cat_data_cache = None + + +# TODO add refresh operator + + +def find_asset_cat_file(directory): + global asset_file_cache + if asset_file_cache is not None: + return asset_file_cache + asset_file = os.path.join(directory, "blender_assets.cats.txt") + if os.path.exists(asset_file): + return asset_file + + parent_dir = os.path.dirname(directory) + if parent_dir == directory: + raise FileNotFoundError("blender_assets.cats.txt not found") + + return find_asset_cat_file(parent_dir) + + +def get_asset_cat_enum_items(): + global cat_data_cache + if cat_data_cache is not None: + return cat_data_cache + items = [] + asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__()) + with (Path(asset_cat_file)).open() as file: + for line in file.readlines(): + if line.startswith(("#", "VERSION", "\n")): + continue + # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') + name = line.split(':', 1)[1].strip('\n') + uuid = line.split(':', 1)[0] + + items.append((uuid, name, uuid)) + return items diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index 7284a2a7..d46c6b14 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -5,25 +5,13 @@ from . import constants from .config import get_task_layer_presets_path from pathlib import Path from .prefs import get_addon_prefs +from .asset_catalog import get_asset_cat_enum_items """ NOTE Items in these properties groups should be generated by a function that finds the avaliable task layers from the task_layer.json file that needs to be created. """ -# TODO find better place for this function -def find_asset_cat_file(directory): - asset_file = os.path.join(directory, "blender_assets.cats.txt") - if os.path.exists(asset_file): - return asset_file - - parent_dir = os.path.dirname(directory) - if parent_dir == directory: - raise FileNotFoundError("blender_assets.cats.txt not found") - - return find_asset_cat_file(parent_dir) - - def get_task_layer_presets(self, context): prefs = get_addon_prefs() user_tls = Path(prefs.custom_task_layers_dir) @@ -159,22 +147,9 @@ class AssetPipeline(bpy.types.PropertyGroup): file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False) def get_asset_catalogs(self, context): - items = [] - asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__()) - with (Path(asset_cat_file)).open() as file: - for line in file.readlines(): - if line.startswith(("#", "VERSION", "\n")): - continue - # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') - name = line.split(":")[2].split("\n")[0] - uuid = line.split(":")[0] + return get_asset_cat_enum_items() - items.append((uuid, name, '')) - return items - - aval_asset_catalogs: bpy.props.EnumProperty( - name="Catalog", items=get_asset_catalogs - ) + asset_catalog_id: bpy.props.EnumProperty(name="Catalog", items=get_asset_catalogs) classes = ( -- 2.30.2 From ef7dede93bcdc946f152edc5f88e34ba5c289995 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 11:16:31 -0500 Subject: [PATCH 3/7] Asset Pipeline: Set Asset Catalog during new Publishs --- .../addons/asset_pipeline/merge/publish.py | 11 ++++++++--- scripts-blender/addons/asset_pipeline/ops.py | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts-blender/addons/asset_pipeline/merge/publish.py b/scripts-blender/addons/asset_pipeline/merge/publish.py index 30f4b0e6..b78043e4 100644 --- a/scripts-blender/addons/asset_pipeline/merge/publish.py +++ b/scripts-blender/addons/asset_pipeline/merge/publish.py @@ -65,8 +65,9 @@ def get_asset_catalogues(): asset_data = obj.asset_data asset_data.catalog_id = uuid + def create_next_published_file( - current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY + current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY, catalog_id: str = '' ) -> None: """Creates new Published version of a given Publish Type @@ -75,11 +76,15 @@ def create_next_published_file( publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'. """ # TODO Set Catalogue here + new_file_path = get_next_published_file(current_file, publish_type) + asset_col = bpy.context.scene.asset_pipeline.asset_collection if publish_type == constants.ACTIVE_PUBLISH_KEY: - bpy.context.scene.asset_pipeline.asset_collection.asset_mark() + asset_col.asset_mark() + if catalog_id != '': + asset_col.asset_data.catalog_id = catalog_id bpy.ops.wm.save_as_mainfile(filepath=new_file_path.__str__(), copy=True) - bpy.context.scene.asset_pipeline.asset_collection.asset_clear() + asset_col.asset_clear() def find_all_published(current_file: Path, publish_type: str) -> list[Path]: diff --git a/scripts-blender/addons/asset_pipeline/ops.py b/scripts-blender/addons/asset_pipeline/ops.py index 2d436a7e..91f6c55d 100644 --- a/scripts-blender/addons/asset_pipeline/ops.py +++ b/scripts-blender/addons/asset_pipeline/ops.py @@ -425,8 +425,12 @@ class ASSETPIPE_OT_publish_new_version(bpy.types.Operator): f"Only '{constants.REVIEW_PUBLISH_KEY}' Publish is supported when a version is staged", ) return {'CANCELLED'} - - create_next_published_file(Path(bpy.data.filepath), self.publish_types) + catalog_id = context.scene.asset_pipeline.asset_catalog_id + create_next_published_file( + current_file=Path(bpy.data.filepath), + publish_type=self.publish_types, + catalog_id=catalog_id, + ) return {'FINISHED'} @@ -465,7 +469,8 @@ class ASSETPIPE_OT_publish_staged_as_active(bpy.types.Operator): ) # Delete Staged File staged_file.unlink() - create_next_published_file(current_file) + catalog_id = context.scene.asset_pipeline.asset_catalog_id + create_next_published_file(current_file=current_file, catalog_id=catalog_id) return {'FINISHED'} @@ -861,7 +866,6 @@ class ASSETPIPE_OT_batch_ownership_change(bpy.types.Operator): layout.row(align=True).prop(self, "data_source", expand=True) layout.prop(self, "data_type", expand=True) - filter_owner_row = layout.row() filter_owner_row.enabled = grey_out if advanced_mode: -- 2.30.2 From d04db2db956499aebde6a518bc5ca02413624c5a Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 11:16:45 -0500 Subject: [PATCH 4/7] Asset Pipeline: Set Asset Catalog during Push --- scripts-blender/addons/asset_pipeline/sync.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts-blender/addons/asset_pipeline/sync.py b/scripts-blender/addons/asset_pipeline/sync.py index 37fafe2e..a383b3ce 100644 --- a/scripts-blender/addons/asset_pipeline/sync.py +++ b/scripts-blender/addons/asset_pipeline/sync.py @@ -151,8 +151,11 @@ def sync_execute_pull(self, context): def sync_execute_push(self, context): + _catalog_id = None temp_file_path = create_temp_file_backup(self, context) + _catalog_id = context.scene.asset_pipeline.asset_catalog_id + file_path = self._sync_target.__str__() bpy.ops.wm.open_mainfile(filepath=file_path) @@ -174,5 +177,10 @@ def sync_execute_push(self, context): self.report({'ERROR'}, error_msg) return {'CANCELLED'} + asset_pipe = context.scene.asset_pipeline + asset_col = asset_pipe.asset_collection + if _catalog_id != '': + asset_col.asset_data.catalog_id = _catalog_id + bpy.ops.wm.save_as_mainfile(filepath=file_path) bpy.ops.wm.open_mainfile(filepath=self._current_file.__str__()) -- 2.30.2 From 942b24ca0e48ffcfd9595874e07c32e20ba71e4a Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 12:00:47 -0500 Subject: [PATCH 5/7] Asset Pipeline: Add Operator to Refresh Asset Catalog & Add Default None Value --- .../addons/asset_pipeline/asset_catalog.py | 9 +++++---- .../addons/asset_pipeline/merge/publish.py | 2 +- scripts-blender/addons/asset_pipeline/ops.py | 16 ++++++++++++++++ scripts-blender/addons/asset_pipeline/sync.py | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts-blender/addons/asset_pipeline/asset_catalog.py b/scripts-blender/addons/asset_pipeline/asset_catalog.py index 54a2b884..a0ec4c95 100644 --- a/scripts-blender/addons/asset_pipeline/asset_catalog.py +++ b/scripts-blender/addons/asset_pipeline/asset_catalog.py @@ -24,19 +24,20 @@ def find_asset_cat_file(directory): return find_asset_cat_file(parent_dir) -def get_asset_cat_enum_items(): +def get_asset_cat_enum_items(reload: bool = False): global cat_data_cache - if cat_data_cache is not None: + if cat_data_cache is not None and not reload: return cat_data_cache items = [] + items.append(('NONE', 'None', '')) asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__()) with (Path(asset_cat_file)).open() as file: for line in file.readlines(): if line.startswith(("#", "VERSION", "\n")): continue # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') - name = line.split(':', 1)[1].strip('\n') + name = line.split(':', 1)[1].split(":")[-1].strip("\n") uuid = line.split(':', 1)[0] - items.append((uuid, name, uuid)) + items.append((uuid, name, '')) return items diff --git a/scripts-blender/addons/asset_pipeline/merge/publish.py b/scripts-blender/addons/asset_pipeline/merge/publish.py index b78043e4..2a4d6932 100644 --- a/scripts-blender/addons/asset_pipeline/merge/publish.py +++ b/scripts-blender/addons/asset_pipeline/merge/publish.py @@ -81,7 +81,7 @@ def create_next_published_file( asset_col = bpy.context.scene.asset_pipeline.asset_collection if publish_type == constants.ACTIVE_PUBLISH_KEY: asset_col.asset_mark() - if catalog_id != '': + if catalog_id != '' or catalog_id != 'NONE': asset_col.asset_data.catalog_id = catalog_id bpy.ops.wm.save_as_mainfile(filepath=new_file_path.__str__(), copy=True) asset_col.asset_clear() diff --git a/scripts-blender/addons/asset_pipeline/ops.py b/scripts-blender/addons/asset_pipeline/ops.py index 91f6c55d..3dd3ea28 100644 --- a/scripts-blender/addons/asset_pipeline/ops.py +++ b/scripts-blender/addons/asset_pipeline/ops.py @@ -1,6 +1,8 @@ +from typing import Set import bpy import os from pathlib import Path + from . import constants from . import config from .prefs import get_addon_prefs @@ -25,6 +27,8 @@ from .sync import ( sync_execute_push, ) +from .asset_catalog import get_asset_cat_enum_items + class ASSETPIPE_OT_create_new_asset(bpy.types.Operator): bl_idname = "assetpipe.create_new_asset" @@ -944,6 +948,17 @@ class ASSETPIPE_OT_batch_ownership_change(bpy.types.Operator): return {'FINISHED'} +class ASSETPIPE_OT_refresh_asset_cat(bpy.types.Operator): + bl_idname = "assetpipe.refresh_asset_cat" + bl_label = "Refresh Asset Catalogs" + bl_description = """Refresh Asset Catalogs""" + + def execute(self, context: bpy.types.Context): + get_asset_cat_enum_items() + self.report({'INFO'}, "Asset Catalogs Refreshed!") + return {'FINISHED'} + + classes = ( ASSETPIPE_OT_update_ownership, ASSETPIPE_OT_sync_push, @@ -958,6 +973,7 @@ classes = ( ASSETPIPE_OT_update_surrendered_object, ASSETPIPE_OT_update_surrendered_transfer_data, ASSETPIPE_OT_batch_ownership_change, + ASSETPIPE_OT_refresh_asset_cat, ) diff --git a/scripts-blender/addons/asset_pipeline/sync.py b/scripts-blender/addons/asset_pipeline/sync.py index a383b3ce..507d7b2a 100644 --- a/scripts-blender/addons/asset_pipeline/sync.py +++ b/scripts-blender/addons/asset_pipeline/sync.py @@ -179,7 +179,7 @@ def sync_execute_push(self, context): asset_pipe = context.scene.asset_pipeline asset_col = asset_pipe.asset_collection - if _catalog_id != '': + if _catalog_id != '' or _catalog_id != 'NONE': asset_col.asset_data.catalog_id = _catalog_id bpy.ops.wm.save_as_mainfile(filepath=file_path) -- 2.30.2 From 6eb71079182902775c1fb23e4f0c0a1e6270a9bc Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 12:01:06 -0500 Subject: [PATCH 6/7] Asset Pipeline Add Description for Asset Catalog Dropdown --- scripts-blender/addons/asset_pipeline/props.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index d46c6b14..b0bc88a8 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -149,7 +149,11 @@ class AssetPipeline(bpy.types.PropertyGroup): def get_asset_catalogs(self, context): return get_asset_cat_enum_items() - asset_catalog_id: bpy.props.EnumProperty(name="Catalog", items=get_asset_catalogs) + asset_catalog_id: bpy.props.EnumProperty( + name="Catalog", + items=get_asset_catalogs, + description="Select Asset Library Catalog for the current Asset, this value will be updated each time you Push to an 'Active' Publish", + ) classes = ( -- 2.30.2 From 4e6c6814910ece6b21956c63bd7d4af53b0edc61 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 21 Dec 2023 12:01:43 -0500 Subject: [PATCH 7/7] Asset Pipeline: Move Catalog Dropdown to Tools Menu --- scripts-blender/addons/asset_pipeline/ui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/asset_pipeline/ui.py b/scripts-blender/addons/asset_pipeline/ui.py index 217a2326..9b549698 100644 --- a/scripts-blender/addons/asset_pipeline/ui.py +++ b/scripts-blender/addons/asset_pipeline/ui.py @@ -54,7 +54,6 @@ class ASSETPIPE_PT_sync(bpy.types.Panel): for task_layer in asset_pipe.local_task_layers: row.label(text=task_layer.name) - layout.prop(asset_pipe, 'aval_asset_catalogs') layout.prop(asset_pipe, "asset_collection") staged = is_staged_publish(Path(bpy.data.filepath)) @@ -90,6 +89,9 @@ class ASSETPIPE_PT_sync_tools(bpy.types.Panel): def draw(self, context: bpy.types.Context) -> None: layout = self.layout + cat_row = layout.row(align=True) + cat_row.prop(context.scene.asset_pipeline, 'asset_catalog_id') + cat_row.operator("assetpipe.refresh_asset_cat", icon='FILE_REFRESH', text="") layout.operator("assetpipe.batch_ownership_change") layout.operator("assetpipe.revert_file", icon="FILE_TICK") -- 2.30.2