From 8e5067c90a5e2bd78aa14a523b52c51539ecb244 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 24 Jan 2024 12:32:58 -0500 Subject: [PATCH 1/3] Asset Pipeline: Use a weak ref for Asset Collection to improve performance --- .../addons/asset_pipeline/props.py | 41 +++++++++++-------- scripts-blender/addons/asset_pipeline/ui.py | 4 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index b0bc88a8..eb0225c1 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -68,12 +68,29 @@ class AssetPipeline(bpy.types.PropertyGroup): description="Depreciated files do not recieve any updates when syncing from a task layer", default=False, ) - asset_collection: bpy.props.PointerProperty( - type=bpy.types.Collection, + + @property + def asset_collection(self): + return bpy.data.collections.get(self.asset_collection_name) + + @asset_collection.setter + def asset_collection(self, coll): + self.asset_collection_name = coll.name + + asset_collection_name: bpy.props.StringProperty( name="Asset", + default="", description="Top Level Collection of the Asset, all other collections of the asset will be children of this collection", ) + # Commented out - Let's use a weak ref for now because this causes the collection to evaluate even when hidden, causing performance nightmares + # asset_collection: bpy.props.PointerProperty( + # type=bpy.types.Collection, + # name="Asset", + # description="Top Level Collection of the Asset, all other collections of the + # asset will be children of this collection", + # ) + temp_transfer_data: bpy.props.CollectionProperty(type=AssetTransferDataTemp) def add_temp_transfer_data(self, name, owner, type, obj, surrender): @@ -102,9 +119,7 @@ class AssetPipeline(bpy.types.PropertyGroup): ) name: bpy.props.StringProperty(name="Name", description="Name for new Asset") - prefix: bpy.props.StringProperty( - name="Prefix", description="Prefix for new Asset", default="" - ) + prefix: bpy.props.StringProperty(name="Prefix", description="Prefix for new Asset", default="") task_layer_config_type: bpy.props.EnumProperty( name="Task Layer Preset", @@ -132,18 +147,12 @@ class AssetPipeline(bpy.types.PropertyGroup): # UI BOOLS: used to show/hide Transferable Data elements # The names are also hard coded in constants.py under TRANSFER_DATA_TYPES # any changes will need to be reflected both here and in that enum - group_vertex_ui_bool: bpy.props.BoolProperty( - name="Show/Hide Vertex Groups", default=False - ) + group_vertex_ui_bool: bpy.props.BoolProperty(name="Show/Hide Vertex Groups", default=False) modifier_ui_bool: bpy.props.BoolProperty(name="Show/Hide Modifiers", default=False) - constraint_ui_bool: bpy.props.BoolProperty( - name="Show/Hide Constraints", default=False - ) + constraint_ui_bool: bpy.props.BoolProperty(name="Show/Hide Constraints", default=False) material_ui_bool: bpy.props.BoolProperty(name="Show/Hide Materials", default=False) shapekey_ui_bool: bpy.props.BoolProperty(name="Show/Hide Shape Keys", default=False) - attribute_ui_bool: bpy.props.BoolProperty( - name="Show/Hide Attributes", default=False - ) + attribute_ui_bool: bpy.props.BoolProperty(name="Show/Hide Attributes", default=False) file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False) def get_asset_catalogs(self, context): @@ -167,9 +176,7 @@ classes = ( def register(): for i in classes: bpy.utils.register_class(i) - bpy.types.Object.transfer_data_ownership = bpy.props.CollectionProperty( - type=AssetTransferData - ) + bpy.types.Object.transfer_data_ownership = bpy.props.CollectionProperty(type=AssetTransferData) bpy.types.Scene.asset_pipeline = bpy.props.PointerProperty(type=AssetPipeline) bpy.types.ID.asset_id_owner = bpy.props.StringProperty(name="Owner", default="NONE") bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty( diff --git a/scripts-blender/addons/asset_pipeline/ui.py b/scripts-blender/addons/asset_pipeline/ui.py index e7e75852..ca3f23fe 100644 --- a/scripts-blender/addons/asset_pipeline/ui.py +++ b/scripts-blender/addons/asset_pipeline/ui.py @@ -26,7 +26,7 @@ class ASSETPIPE_PT_sync(bpy.types.Panel): layout.prop(asset_pipe, "prefix") layout.prop(asset_pipe, "dir") else: - layout.prop(asset_pipe, "asset_collection") + layout.prop_search(asset_pipe, 'asset_collection_name', bpy.data, 'collections') layout.operator("assetpipe.create_new_asset") return @@ -55,7 +55,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, "asset_collection") + layout.prop_search(asset_pipe, 'asset_collection_name', bpy.data, 'collections') staged = is_staged_publish(Path(bpy.data.filepath)) sync_target_name = "Staged" if staged else "Active" -- 2.30.2 From a88d77e6d346086cdca9839f664b7c4039a8cef7 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 25 Jan 2024 10:41:54 -0500 Subject: [PATCH 2/3] Asset Pipeline: Add Load Post Handler to version old files Co-authored-by: Demeter Dzadik --- .../addons/asset_pipeline/props.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index eb0225c1..eefd03bd 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -71,7 +71,9 @@ class AssetPipeline(bpy.types.PropertyGroup): @property def asset_collection(self): - return bpy.data.collections.get(self.asset_collection_name) + return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get( + self.asset_collection_name + "." + constants.LOCAL_SUFFIX + ) @asset_collection.setter def asset_collection(self, coll): @@ -165,6 +167,19 @@ class AssetPipeline(bpy.types.PropertyGroup): ) +@staticmethod +@bpy.app.handlers.persistent +def set_asset_collection_name_post_file_load(_): + # Version the PointerProperty to the StringProperty, and the left-over pointer. + for scene in bpy.data.scenes: + if 'asset_collection' not in scene.asset_pipeline: + continue + coll = scene.asset_pipeline['asset_collection'] + if coll: + scene.asset_pipeline.asset_collection_name = coll.name + del scene.asset_pipeline['asset_collection'] + + classes = ( AssetTransferData, AssetTransferDataTemp, @@ -182,6 +197,7 @@ def register(): bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty( name="Surrender Ownership", default=False ) + bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load) def unregister(): @@ -190,3 +206,4 @@ def unregister(): del bpy.types.Object.transfer_data_ownership del bpy.types.Scene.asset_pipeline del bpy.types.ID.asset_id_owner + bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load) -- 2.30.2 From 40473893f998100222422abbf32b11dbe715961b Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 25 Jan 2024 10:59:49 -0500 Subject: [PATCH 3/3] Asset Pipeline: Fix Typo in 'Add Load Post Handler to version old files' Co-authored-by: Demeter Dzadik --- scripts-blender/addons/asset_pipeline/props.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts-blender/addons/asset_pipeline/props.py b/scripts-blender/addons/asset_pipeline/props.py index eefd03bd..0faae947 100644 --- a/scripts-blender/addons/asset_pipeline/props.py +++ b/scripts-blender/addons/asset_pipeline/props.py @@ -167,7 +167,6 @@ class AssetPipeline(bpy.types.PropertyGroup): ) -@staticmethod @bpy.app.handlers.persistent def set_asset_collection_name_post_file_load(_): # Version the PointerProperty to the StringProperty, and the left-over pointer. @@ -197,7 +196,7 @@ def register(): bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty( name="Surrender Ownership", default=False ) - bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load) + bpy.app.handlers.load_post.append(set_asset_collection_name_post_file_load) def unregister(): @@ -206,4 +205,4 @@ def unregister(): del bpy.types.Object.transfer_data_ownership del bpy.types.Scene.asset_pipeline del bpy.types.ID.asset_id_owner - bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load) + bpy.app.handlers.load_post.remove(set_asset_collection_name_post_file_load) -- 2.30.2