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
Showing only changes of commit a88d77e6d3 - Show all commits

View File

@ -71,7 +71,9 @@ class AssetPipeline(bpy.types.PropertyGroup):
@property @property
def asset_collection(self): 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(
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") ```
self.asset_collection_name + "." + constants.LOCAL_SUFFIX
)
@asset_collection.setter @asset_collection.setter
def asset_collection(self, coll): 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
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)`
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,
@ -182,6 +197,7 @@ def register():
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(AssetPipeline.set_asset_collection_name_post_file_load)
def unregister(): def unregister():
@ -190,3 +206,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(AssetPipeline.set_asset_collection_name_post_file_load)