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

View File

@ -1,6 +1,6 @@
import bpy
from . import asset_suffix, transferable_data
from . import asset_suffix, transferable_data, util
from pathlib import Path
# TODO refactor merge functions into a class based on AssetBuilder class of Asset Pipeline 1
@ -11,7 +11,6 @@ def update_task_layer_objects(
transfer_objs: list[bpy.types.Object],
):
# Link new obj to collection
# TODO implement remap ids
for transfer_obj in transfer_objs:
obj_root_name = transfer_obj.name
transfer_obj.name = f"{obj_root_name}"
@ -69,6 +68,9 @@ def merge_task_layer(
transfer_data,
target_col,
)
remap_users(context)
bpy.ops.outliner.orphans_purge(
do_local_ids=True, do_linked_ids=False, do_recursive=True
)
@ -127,3 +129,50 @@ def import_data_from_lib(
)
return eval(f"bpy.data.{data_category}['{data_name}']")
### REMAPPING IDS
def remap_users(context, suf=".SOURCE"):
"""
When objects inside the asset collection reference datablocks outside of
the asset collection or vice versa, some duplication can occur, as
outside objects end up with a .TASK suffix, and they end up referencing
objects that are no longer linked to the scene.
Objects inside the asset collection correctly lose their suffix, but
also end up referencing outside objects without the suffix, which are
actually the wrong ones.
So this function remaps references such that everything inside and outside
the asset collection reference each other once again, and removes
any leftover .TASK suffixes.
"""
# suf = constants.TASK_SUFFIX
for datablock in bpy.data.user_map():
has_type = hasattr(datablock, 'type')
if (
has_type
and datablock.type == 'OBJECT'
and datablock.name not in context.scene.objects
):
# Objects that aren't in the scene have been replaced by the pull
# process, so we don't want to remap any references to them.
continue
storage = util.get_storage_of_id(datablock)
if not datablock.name.endswith(suf):
continue
without_suffix = datablock.name.replace(suf, ".LOCAL")
other_db = storage.get(without_suffix)
if not other_db:
continue
# print(f'REMAP USERS: "{other_db.name}" -> "{datablock.name}"')
other_db.user_remap(datablock)
# Rename the object to make its name available.
# This datablock should get purged soon, otherwise it's a bug.
other_db.name += "_Users_Remapped"
datablock.name = without_suffix