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 42 additions and 19 deletions

View File

@ -68,12 +68,31 @@ class AssetPipeline(bpy.types.PropertyGroup):
description="Depreciated files do not recieve any updates when syncing from a task layer", description="Depreciated files do not recieve any updates when syncing from a task layer",
default=False, 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) or bpy.data.collections.get(
self.asset_collection_name + "." + constants.LOCAL_SUFFIX
)
@asset_collection.setter
def asset_collection(self, coll):
self.asset_collection_name = coll.name
asset_collection_name: bpy.props.StringProperty(
name="Asset", name="Asset",
default="",
description="Top Level Collection of the Asset, all other collections of the asset will be children of this collection", 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) temp_transfer_data: bpy.props.CollectionProperty(type=AssetTransferDataTemp)
def add_temp_transfer_data(self, name, owner, type, obj, surrender): def add_temp_transfer_data(self, name, owner, type, obj, surrender):
@ -102,9 +121,7 @@ class AssetPipeline(bpy.types.PropertyGroup):
) )
name: bpy.props.StringProperty(name="Name", description="Name for new Asset") name: bpy.props.StringProperty(name="Name", description="Name for new Asset")
prefix: bpy.props.StringProperty( prefix: bpy.props.StringProperty(name="Prefix", description="Prefix for new Asset", default="")
name="Prefix", description="Prefix for new Asset", default=""
)
task_layer_config_type: bpy.props.EnumProperty( task_layer_config_type: bpy.props.EnumProperty(
name="Task Layer Preset", name="Task Layer Preset",
@ -132,18 +149,12 @@ class AssetPipeline(bpy.types.PropertyGroup):
# UI BOOLS: used to show/hide Transferable Data elements # UI BOOLS: used to show/hide Transferable Data elements
# The names are also hard coded in constants.py under TRANSFER_DATA_TYPES # 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 # any changes will need to be reflected both here and in that enum
group_vertex_ui_bool: bpy.props.BoolProperty( group_vertex_ui_bool: bpy.props.BoolProperty(name="Show/Hide Vertex Groups", default=False)
name="Show/Hide Vertex Groups", default=False
)
modifier_ui_bool: bpy.props.BoolProperty(name="Show/Hide Modifiers", default=False) modifier_ui_bool: bpy.props.BoolProperty(name="Show/Hide Modifiers", default=False)
constraint_ui_bool: bpy.props.BoolProperty( constraint_ui_bool: bpy.props.BoolProperty(name="Show/Hide Constraints", default=False)
name="Show/Hide Constraints", default=False
)
material_ui_bool: bpy.props.BoolProperty(name="Show/Hide Materials", 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) shapekey_ui_bool: bpy.props.BoolProperty(name="Show/Hide Shape Keys", default=False)
attribute_ui_bool: bpy.props.BoolProperty( attribute_ui_bool: bpy.props.BoolProperty(name="Show/Hide Attributes", default=False)
name="Show/Hide Attributes", default=False
)
file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False) file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False)
def get_asset_catalogs(self, context): def get_asset_catalogs(self, context):
@ -156,6 +167,18 @@ class AssetPipeline(bpy.types.PropertyGroup):
) )
@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 = ( classes = (
AssetTransferData, AssetTransferData,
AssetTransferDataTemp, AssetTransferDataTemp,
@ -167,14 +190,13 @@ classes = (
def register(): def register():
for i in classes: for i in classes:
bpy.utils.register_class(i) bpy.utils.register_class(i)
bpy.types.Object.transfer_data_ownership = bpy.props.CollectionProperty( bpy.types.Object.transfer_data_ownership = bpy.props.CollectionProperty(type=AssetTransferData)
type=AssetTransferData
)
bpy.types.Scene.asset_pipeline = bpy.props.PointerProperty(type=AssetPipeline) 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_owner = bpy.props.StringProperty(name="Owner", default="NONE")
bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty( bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty(
name="Surrender Ownership", default=False name="Surrender Ownership", default=False
) )
bpy.app.handlers.load_post.append(set_asset_collection_name_post_file_load)
def unregister(): def unregister():
@ -183,3 +205,4 @@ def unregister():
del bpy.types.Object.transfer_data_ownership del bpy.types.Object.transfer_data_ownership
del bpy.types.Scene.asset_pipeline del bpy.types.Scene.asset_pipeline
del bpy.types.ID.asset_id_owner del bpy.types.ID.asset_id_owner
bpy.app.handlers.load_post.remove(set_asset_collection_name_post_file_load)

View File

@ -26,7 +26,7 @@ class ASSETPIPE_PT_sync(bpy.types.Panel):
layout.prop(asset_pipe, "prefix") layout.prop(asset_pipe, "prefix")
layout.prop(asset_pipe, "dir") layout.prop(asset_pipe, "dir")
else: else:
layout.prop(asset_pipe, "asset_collection") layout.prop_search(asset_pipe, 'asset_collection_name', bpy.data, 'collections')
layout.operator("assetpipe.create_new_asset") layout.operator("assetpipe.create_new_asset")
return return
@ -55,7 +55,7 @@ class ASSETPIPE_PT_sync(bpy.types.Panel):
for task_layer in asset_pipe.local_task_layers: for task_layer in asset_pipe.local_task_layers:
row.label(text=task_layer.name) 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)) staged = is_staged_publish(Path(bpy.data.filepath))
sync_target_name = "Staged" if staged else "Active" sync_target_name = "Staged" if staged else "Active"