Asset Pipeline: Use a weak ref for Asset Collection to improve performance #213

Merged
Nick Alberelli merged 3 commits from TinyNick/blender-studio-pipeline:fix/asset-collection-as-string into main 2024-01-25 17:06:04 +01:00
2 changed files with 26 additions and 19 deletions
Showing only changes of commit 8e5067c90a - Show all commits

View File

@ -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)
TinyNick marked this conversation as resolved Outdated

This also needs a tweak to not return None during pull, since we are actually renaming the asset collection before transfer.

from constants import LOCAL_SUFFIX
........
return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get(self.asset_collection_name + ".LOC")
This also needs a tweak to not return None during pull, since we are actually renaming the asset collection before transfer. ```python from constants import LOCAL_SUFFIX ........ return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get(self.asset_collection_name + ".LOC") ```
@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",
)
TinyNick marked this conversation as resolved Outdated
    @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']
```python @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'] ```
# 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():
TinyNick marked this conversation as resolved Outdated

bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load)
...
bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load)

` bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load)` ... ` bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load)`
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(

View File

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