Asset Pipeline v2 #145
@ -1,7 +1,7 @@
|
||||
import bpy
|
||||
from typing import Dict, Set
|
||||
from .naming import (
|
||||
get_target_name,
|
||||
merge_get_target_name,
|
||||
task_layer_prefix_basename_get,
|
||||
)
|
||||
from .util import get_storage_of_id
|
||||
@ -53,7 +53,7 @@ class AssetTransferMapping:
|
||||
self.shared_id_map = self._gen_shared_id_map()
|
||||
|
||||
def _get_external_object(self, local_obj):
|
||||
external_obj_name = get_target_name(
|
||||
external_obj_name = merge_get_target_name(
|
||||
local_obj.name,
|
||||
)
|
||||
external_obj = self._external_col.all_objects.get(external_obj_name)
|
||||
@ -113,7 +113,7 @@ class AssetTransferMapping:
|
||||
# Find new objects to add to local_col
|
||||
for external_obj in self._external_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(merge_get_target_name(external_obj.name))
|
||||
if not obj and external_obj.asset_id_owner not in self._local_tls:
|
||||
self.external_obj_to_add.add(external_obj)
|
||||
return object_map
|
||||
@ -128,7 +128,7 @@ class AssetTransferMapping:
|
||||
for local_task_layer_col in self._local_top_col.children:
|
||||
if local_task_layer_col.asset_id_owner not in self._local_tls:
|
||||
# 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 = merge_get_target_name(local_task_layer_col.name)
|
||||
local_col = bpy.data.collections.get(external_col_name)
|
||||
if local_col:
|
||||
coll_map[local_task_layer_col] = local_col
|
||||
@ -138,18 +138,18 @@ class AssetTransferMapping:
|
||||
)
|
||||
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_name = merge_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_name = merge_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_name = merge_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)
|
||||
@ -183,7 +183,7 @@ class AssetTransferMapping:
|
||||
return name, map_item
|
||||
|
||||
def _check_transfer_data_conflict(self, obj, transfer_data_item):
|
||||
other_obj = bpy.data.objects.get(get_target_name(obj.name))
|
||||
other_obj = bpy.data.objects.get(merge_get_target_name(obj.name))
|
||||
check_transfer_data_item = None
|
||||
if not other_obj:
|
||||
return
|
||||
@ -213,7 +213,7 @@ class AssetTransferMapping:
|
||||
def transfer_data_get_other(self, transfer_data_item):
|
||||
# THIS IS FOR WHEN SURRENDERED DATA HAS BEEN REPLACED
|
||||
obj = transfer_data_item.id_data
|
||||
other_obj = bpy.data.objects.get(get_target_name(obj.name))
|
||||
other_obj = bpy.data.objects.get(merge_get_target_name(obj.name))
|
||||
# Find Related Transfer Data Item on Target/Source Object
|
||||
for other_obj_transfer_data_item in other_obj.transfer_data_ownership:
|
||||
if task_layer_prefix_basename_get(
|
||||
@ -272,7 +272,7 @@ class AssetTransferMapping:
|
||||
def _gen_shared_id_map(self):
|
||||
shared_id_map: Dict[bpy.types.ID, bpy.types.ID] = {}
|
||||
for local_id in get_shared_ids(self._local_top_col):
|
||||
external_id_name = get_target_name(local_id.name)
|
||||
external_id_name = merge_get_target_name(local_id.name)
|
||||
id_storage = get_storage_of_id(local_id)
|
||||
external_id = id_storage.get(external_id_name)
|
||||
if not external_id:
|
||||
|
@ -10,8 +10,8 @@ from .transfer_data.transfer_core import (
|
||||
from .transfer_data.transfer_util import transfer_data_add_entry
|
||||
|
||||
from .naming import (
|
||||
add_suffix_to_hierarchy,
|
||||
remove_suffix_from_hierarchy,
|
||||
merge_add_suffix_to_hierarchy,
|
||||
merge_remove_suffix_from_hierarchy,
|
||||
asset_prefix_name_get,
|
||||
get_id_type_name,
|
||||
)
|
||||
@ -171,10 +171,10 @@ def merge_task_layer(
|
||||
col_base_name = local_col.name
|
||||
local_suffix = constants.LOCAL_SUFFIX
|
||||
external_suffix = constants.EXTERNAL_SUFFIX
|
||||
add_suffix_to_hierarchy(local_col, local_suffix)
|
||||
merge_add_suffix_to_hierarchy(local_col, local_suffix)
|
||||
|
||||
appended_col = import_data_from_lib(external_file, "collections", col_base_name)
|
||||
add_suffix_to_hierarchy(appended_col, external_suffix)
|
||||
merge_add_suffix_to_hierarchy(appended_col, external_suffix)
|
||||
|
||||
local_col = bpy.data.collections[f"{col_base_name}.{local_suffix}"]
|
||||
external_col = bpy.data.collections[f"{col_base_name}.{external_suffix}"]
|
||||
@ -227,7 +227,7 @@ def merge_task_layer(
|
||||
bpy.ops.outliner.orphans_purge(
|
||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||
)
|
||||
remove_suffix_from_hierarchy(local_col)
|
||||
merge_remove_suffix_from_hierarchy(local_col)
|
||||
|
||||
|
||||
def import_data_from_lib(
|
||||
|
@ -26,8 +26,7 @@ from .util import data_type_from_transfer_data_key
|
||||
|
||||
DELIMITER = "."
|
||||
|
||||
|
||||
def get_target_suffix(suffix: str) -> str:
|
||||
def merge_get_target_suffix(suffix: str) -> str:
|
||||
"""Get the corrisponding suffix for a given suffix
|
||||
|
||||
Args:
|
||||
@ -42,7 +41,7 @@ def get_target_suffix(suffix: str) -> str:
|
||||
return constants.EXTERNAL_SUFFIX
|
||||
|
||||
|
||||
def get_target_name(name: str) -> str:
|
||||
def merge_get_target_name(name: str) -> str:
|
||||
"""Get the corrisponding target name for a given datablock's suffix.
|
||||
Suffixes are set by the add_suffix_to_hierarchy() function prior to
|
||||
calling this function.
|
||||
@ -54,12 +53,12 @@ def get_target_name(name: str) -> str:
|
||||
str: Returns datablock name with the opposite suffix
|
||||
"""
|
||||
old = name.split(DELIMITER)[-1]
|
||||
new = get_target_suffix(old)
|
||||
new = merge_get_target_suffix(old)
|
||||
li = name.rsplit(old, 1)
|
||||
return new.join(li)
|
||||
|
||||
|
||||
def get_basename(name: str) -> str:
|
||||
def merge_get_basename(name: str) -> str:
|
||||
"""Returns the name of an asset without it's suffix"""
|
||||
if name.endswith(constants.LOCAL_SUFFIX) or name.endswith(
|
||||
constants.EXTERNAL_SUFFIX
|
||||
@ -84,12 +83,14 @@ def remove_suffix_from_hierarchy(collection: bpy.types.Collection) -> None:
|
||||
# Don't rename linked datablocks.
|
||||
continue
|
||||
try:
|
||||
db.name = get_basename(db.name)
|
||||
db.name = merge_get_basename(db.name)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def add_suffix_to_hierarchy(collection: bpy.types.Collection, suffix_base: str) -> None:
|
||||
def merge_add_suffix_to_hierarchy(
|
||||
collection: bpy.types.Collection, suffix_base: str
|
||||
) -> None:
|
||||
"""Add a suffix to the names of all datablocks referenced by a collection,
|
||||
itself included.
|
||||
|
||||
|
@ -10,7 +10,7 @@ from .transfer_function_util.proximity_core import (
|
||||
transfer_corner_data,
|
||||
)
|
||||
from ..transfer_util import check_transfer_data_entry
|
||||
from ...naming import get_basename
|
||||
from ...naming import merge_get_basename
|
||||
from ...task_layer import get_transfer_data_owner
|
||||
from .... import constants
|
||||
|
||||
@ -36,7 +36,7 @@ def attribute_clean(obj):
|
||||
for attribute in attributes:
|
||||
matches = check_transfer_data_entry(
|
||||
obj.transfer_data_ownership,
|
||||
get_basename(attribute.name),
|
||||
merge_get_basename(attribute.name),
|
||||
constants.ATTRIBUTE_KEY,
|
||||
)
|
||||
if len(matches) == 0:
|
||||
|
@ -1,14 +1,14 @@
|
||||
import bpy
|
||||
from ..transfer_util import check_transfer_data_entry
|
||||
from ...task_layer import get_transfer_data_owner
|
||||
from ...naming import get_basename
|
||||
from ...naming import merge_get_basename
|
||||
from .... import constants
|
||||
|
||||
|
||||
def parent_clean(obj):
|
||||
matches = check_transfer_data_entry(
|
||||
obj.transfer_data_ownership,
|
||||
get_basename(constants.PARENT_TRANSFER_DATA_ITEM_NAME),
|
||||
merge_get_basename(constants.PARENT_TRANSFER_DATA_ITEM_NAME),
|
||||
constants.PARENT_KEY,
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ from ..transfer_util import (
|
||||
transfer_data_item_init,
|
||||
check_transfer_data_entry,
|
||||
)
|
||||
from ...naming import get_basename
|
||||
from ...naming import merge_get_basename
|
||||
from .... import constants
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ def shape_keys_clean(obj):
|
||||
for shape_key in obj.data.shape_keys.key_blocks:
|
||||
matches = check_transfer_data_entry(
|
||||
obj.transfer_data_ownership,
|
||||
get_basename(shape_key.name),
|
||||
merge_get_basename(shape_key.name),
|
||||
constants.SHAPE_KEY_KEY,
|
||||
)
|
||||
if len(matches) == 0:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import bpy
|
||||
from ..naming import get_basename
|
||||
from ..naming import merge_get_basename
|
||||
from ..task_layer import get_transfer_data_owner
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ def transfer_data_clean(
|
||||
for item in data_list:
|
||||
matches = check_transfer_data_entry(
|
||||
obj.transfer_data_ownership,
|
||||
get_basename(item.name),
|
||||
merge_get_basename(item.name),
|
||||
td_type_key,
|
||||
)
|
||||
if len(matches) == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user