Asset Pipeline v2 #145

Closed
Nick Alberelli wants to merge 431 commits from (deleted):feature/asset-pipeline-v2 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 47 additions and 11 deletions
Showing only changes of commit bde07ba382 - Show all commits

View File

@ -25,10 +25,12 @@ class AssetTransferMapping:
external_coll: bpy.types.Collection, external_coll: bpy.types.Collection,
local_tls: Set[str], local_tls: Set[str],
): ):
self._local_col = local_coll self._local_top_col = local_coll
self._external_col = external_coll self._external_col = external_coll
self._local_tls = local_tls self._local_tls = local_tls
self.external_col_to_remove: Set[bpy.types.Object] = set()
self.external_col_to_add: Set[bpy.types.Object] = set()
self.external_obj_to_add: Set[bpy.types.Object] = set() self.external_obj_to_add: Set[bpy.types.Object] = set()
self._no_match_source_objs: Set[bpy.types.Object] = set() self._no_match_source_objs: Set[bpy.types.Object] = set()
@ -67,7 +69,7 @@ class AssetTransferMapping:
target collection. Uses suffixes to match them up. target collection. Uses suffixes to match them up.
""" """
object_map: Dict[bpy.types.Object, bpy.types.Object] = {} object_map: Dict[bpy.types.Object, bpy.types.Object] = {}
for local_obj in self._local_col.all_objects: for local_obj in self._local_top_col.all_objects:
# Skip items with no owner # Skip items with no owner
if local_obj.asset_id_owner == "NONE": if local_obj.asset_id_owner == "NONE":
continue continue
@ -84,7 +86,7 @@ class AssetTransferMapping:
# Find new objects to add to local_col # Find new objects to add to local_col
for external_obj in self._external_col.all_objects: for external_obj in self._external_col.all_objects:
local_col_objs = self._local_col.all_objects local_col_objs = self._local_top_col.all_objects
obj = local_col_objs.get(get_target_name(external_obj.name)) obj = local_col_objs.get(get_target_name(external_obj.name))
if not obj and external_obj.asset_id_owner not in self._local_tls: if not obj and external_obj.asset_id_owner not in self._local_tls:
self.external_obj_to_add.add(external_obj) self.external_obj_to_add.add(external_obj)
@ -103,19 +105,35 @@ class AssetTransferMapping:
if tl_key in self._local_tls if tl_key in self._local_tls
] ]
for local_task_layer_col in self._local_col.children: for local_task_layer_col in self._local_top_col.children:
if get_basename(local_task_layer_col.name) not in local_tl_names: if local_task_layer_col.asset_id_owner not in self._local_tls:
# Replace source object suffix with target suffix to get target object. # Replace source object suffix with target suffix to get target object.
external_col_name = get_target_name(local_task_layer_col.name) external_col_name = get_target_name(local_task_layer_col.name)
external_col = bpy.data.collections.get(external_col_name) local_col = bpy.data.collections.get(external_col_name)
if external_col: if local_col:
coll_map[local_task_layer_col] = external_col coll_map[local_task_layer_col] = local_col
else: else:
print( print(
f"Failed to find match collection {local_task_layer_col.name} for {external_col_name}" f"Failed to find match collection {local_task_layer_col.name} for {external_col_name}"
) )
self._no_match_source_colls.add(local_task_layer_col) self._no_match_source_colls.add(local_task_layer_col)
external_top_col_name = get_target_name(self._local_top_col.name)
external_top_col = bpy.data.collections.get(external_top_col_name)
# TODO Refactor
for external_col in external_top_col.children:
local_col_name = get_target_name(external_col.name)
local_col = bpy.data.collections.get(local_col_name)
if not local_col and external_col.asset_id_owner not in self._local_tls:
self.external_col_to_add.add(external_col)
for local_col in self._local_top_col.children:
external_col_name = get_target_name(local_col.name)
external_col = bpy.data.collections.get(external_col_name)
if not external_col and local_col.asset_id_owner not in self._local_tls:
self.external_col_to_remove.add(local_col)
all_tgt_colls = set(self._external_col.children_recursive) all_tgt_colls = set(self._external_col.children_recursive)
all_tgt_colls.add(self._external_col) all_tgt_colls.add(self._external_col)
match_target_colls = set([coll for coll in coll_map.values()]) match_target_colls = set([coll for coll in coll_map.values()])
@ -194,7 +212,7 @@ class AssetTransferMapping:
def _gen_shared_id_map(self): def _gen_shared_id_map(self):
shared_id_map: Dict[bpy.types.ID, bpy.types.ID] = {} shared_id_map: Dict[bpy.types.ID, bpy.types.ID] = {}
for local_id in get_shared_ids(self._local_col): for local_id in get_shared_ids(self._local_top_col):
external_id_name = get_target_name(local_id.name) external_id_name = get_target_name(local_id.name)
id_storage = get_storage_of_id(local_id) id_storage = get_storage_of_id(local_id)
external_id = id_storage.get(external_id_name) external_id = id_storage.get(external_id_name)

View File

@ -75,6 +75,9 @@ def ownership_get(
continue continue
ownership_transfer_data_cleanup(obj, task_layer_key) ownership_transfer_data_cleanup(obj, task_layer_key)
init_transfer_data(scene, obj) init_transfer_data(scene, obj)
for col in asset_pipe.asset_collection.children:
if col.asset_id_owner == "NONE":
col.asset_id_owner = task_layer_key
def ownership_set(temp_transfer_data: bpy.types.CollectionProperty) -> None: def ownership_set(temp_transfer_data: bpy.types.CollectionProperty) -> None:
@ -204,6 +207,12 @@ def merge_task_layer(
for col in map.collection_map: for col in map.collection_map:
remap_user(col, map.collection_map[col]) remap_user(col, map.collection_map[col])
for col in map.external_col_to_add:
local_col.children.link(col)
for col in map.external_col_to_remove:
local_col.children.unlink(col)
for id in map.shared_id_map: for id in map.shared_id_map:
remap_user(id, map.shared_id_map[id]) remap_user(id, map.shared_id_map[id])

View File

@ -83,7 +83,9 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
continue continue
col_name = get_task_layer_col_name(task_layer_key) col_name = get_task_layer_col_name(task_layer_key)
bpy.data.collections.new(col_name) bpy.data.collections.new(col_name)
asset_col.children.link(bpy.data.collections.get(col_name)) new_col = bpy.data.collections.get(col_name)
asset_col.children.link(new_col)
new_col.asset_id_owner = task_layer_key
starting_file = "" starting_file = ""
# Create the file for each task layer. # Create the file for each task layer.

View File

@ -55,8 +55,15 @@ class ASSETPIPE_ownership_inspector(bpy.types.Panel):
if not asset_pipe.is_asset_pipeline_file: if not asset_pipe.is_asset_pipeline_file:
layout.label(text="Open valid 'Asset Pipeline' file", icon="ERROR") layout.label(text="Open valid 'Asset Pipeline' file", icon="ERROR")
return return
if context.collection in list(asset_pipe.asset_collection.children):
layout.label(
text=f"{context.collection.name} : '{context.collection.asset_id_owner}' (Active Collection)",
icon="OUTLINER_COLLECTION",
)
if not context.active_object: if not context.active_object:
layout.label(text="Set an Active Object to Inspect") layout.label(text="Set an Active Object to Inspect", icon="OBJECT_DATA")
return return
obj = context.active_object obj = context.active_object
transfer_data = obj.transfer_data_ownership transfer_data = obj.transfer_data_ownership