Asset Pipeline v2 #145
@ -3,6 +3,7 @@ from typing import Dict, Set
|
|||||||
|
|
||||||
from . import util
|
from . import util
|
||||||
from . import asset_suffix
|
from . import asset_suffix
|
||||||
|
from . import constants
|
||||||
|
|
||||||
|
|
||||||
class AssetTransferMapping:
|
class AssetTransferMapping:
|
||||||
@ -90,22 +91,30 @@ class AssetTransferMapping:
|
|||||||
coll_map: Dict[bpy.types.Collection, bpy.types.Collection] = {}
|
coll_map: Dict[bpy.types.Collection, bpy.types.Collection] = {}
|
||||||
|
|
||||||
# Link top most parents.
|
# Link top most parents.
|
||||||
coll_map[self._local_col] = self._external_col
|
# coll_map[self._local_col] = self._external_col
|
||||||
|
|
||||||
# Link up all children.
|
# Get user facing names for local task layers
|
||||||
for s_coll in util.traverse_collection_tree(self._local_col):
|
local_tl_names = [
|
||||||
# assert source_obj.name.endswith(self._source_merge_coll.suffix)
|
item[1] for item in constants.TASK_LAYER_ITEMS if item[0] in self._local_tls
|
||||||
|
]
|
||||||
|
|
||||||
# Replace source object suffix with target suffix to get target object.
|
for local_task_layer_col in self._local_col.children:
|
||||||
external_col = asset_suffix.get_target_name(s_coll.name)
|
if (
|
||||||
t_coll = bpy.data.collections.get(external_col)
|
asset_suffix.get_basename(local_task_layer_col.name)
|
||||||
if t_coll:
|
not in local_tl_names
|
||||||
coll_map[s_coll] = t_coll
|
):
|
||||||
else:
|
# Replace source object suffix with target suffix to get target object.
|
||||||
print(
|
external_col_name = asset_suffix.get_target_name(
|
||||||
f"Failed to find match collection {s_coll.name} for {external_col}"
|
local_task_layer_col.name
|
||||||
)
|
)
|
||||||
self._no_match_source_colls.add(s_coll)
|
external_col = bpy.data.collections.get(external_col_name)
|
||||||
|
if external_col:
|
||||||
|
coll_map[local_task_layer_col] = external_col
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
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)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -46,18 +46,17 @@ def merge_task_layer(
|
|||||||
local_col = bpy.data.collections[f"{col_base_name}.{local_suffix}"]
|
local_col = bpy.data.collections[f"{col_base_name}.{local_suffix}"]
|
||||||
external_col = bpy.data.collections[f"{col_base_name}.{external_suffix}"]
|
external_col = bpy.data.collections[f"{col_base_name}.{external_suffix}"]
|
||||||
|
|
||||||
# TODO Make sure we preserve the collection hirearchies instead of having one flat col
|
|
||||||
# TODO Consider re-adding the TARGET collection
|
# TODO Consider re-adding the TARGET collection
|
||||||
map = AssetTransferMapping(local_col, external_col, local_tls)
|
map = AssetTransferMapping(local_col, external_col, local_tls)
|
||||||
|
|
||||||
# Find Transfer Data
|
# Find Transfer Data
|
||||||
transfer_data = []
|
transfer_data = []
|
||||||
for obj in external_col.objects:
|
for obj in external_col.all_objects:
|
||||||
for item in obj.transfer_data_ownership:
|
for item in obj.transfer_data_ownership:
|
||||||
if item.owner not in local_tls:
|
if item.owner not in local_tls:
|
||||||
transfer_data.append(item)
|
transfer_data.append(item)
|
||||||
|
|
||||||
for obj in local_col.objects:
|
for obj in local_col.all_objects:
|
||||||
for item in obj.transfer_data_ownership:
|
for item in obj.transfer_data_ownership:
|
||||||
if item.owner in local_tls:
|
if item.owner in local_tls:
|
||||||
transfer_data.append(item)
|
transfer_data.append(item)
|
||||||
@ -65,18 +64,13 @@ def merge_task_layer(
|
|||||||
target_objs = [map.object_map[obj] for obj in map.object_map]
|
target_objs = [map.object_map[obj] for obj in map.object_map]
|
||||||
transferable_data.apply_transfer_data(context, transfer_data, target_objs)
|
transferable_data.apply_transfer_data(context, transfer_data, target_objs)
|
||||||
|
|
||||||
for old_obj in map.local_obj_to_remove:
|
|
||||||
# TODO Support collection hirearchies
|
|
||||||
local_col.objects.unlink(old_obj)
|
|
||||||
|
|
||||||
for new_obj in map.external_obj_to_add:
|
|
||||||
# TODO Support collection hirearchies
|
|
||||||
local_col.objects.link(new_obj)
|
|
||||||
|
|
||||||
for source_obj in map.object_map:
|
for source_obj in map.object_map:
|
||||||
target_obj = map.object_map[source_obj]
|
target_obj = map.object_map[source_obj]
|
||||||
remap_user(source_obj, target_obj)
|
remap_user(source_obj, target_obj)
|
||||||
|
|
||||||
|
for col in map.collection_map:
|
||||||
|
remap_user(col, map.collection_map[col])
|
||||||
|
|
||||||
bpy.ops.outliner.orphans_purge(
|
bpy.ops.outliner.orphans_purge(
|
||||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user