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 b78c48811a - Show all commits

View File

@ -2,6 +2,7 @@ import bpy
from . import asset_suffix, transferable_data, util from . import asset_suffix, transferable_data, util
from pathlib import Path from pathlib import Path
from .constants import TASK_LAYER_ITEMS
# TODO refactor merge functions into a class based on AssetBuilder class of Asset Pipeline 1 # TODO refactor merge functions into a class based on AssetBuilder class of Asset Pipeline 1
@ -64,22 +65,13 @@ def merge_task_layer(
transfer_data.append(item) transfer_data.append(item)
update_task_layer_objects(target_col, local_objs) update_task_layer_objects(target_col, local_objs)
transferable_data.apply_transfer_data( transferable_data.apply_transfer_data(context, transfer_data, target_col)
context,
transfer_data, remap_external_datablocks(context)
target_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
) )
# TODO DEBUG WHY REMAP USERS SOMETIMES REPLACES LOCAL OBJ WITH SOURCE OBJ
# ADDING A PURGE BEFORE THIS FIXES IT FOR SOME REASON?
remap_users(context)
# bpy.ops.outliner.orphans_purge(
# do_local_ids=True, do_linked_ids=False, do_recursive=True
# )
asset_suffix.remove_suffix_from_hierarchy(target_col) asset_suffix.remove_suffix_from_hierarchy(target_col)
@ -138,47 +130,34 @@ def import_data_from_lib(
### REMAPPING IDS ### REMAPPING IDS
def remap_get_data_blocks(context, suffix):
retun_datablocks = []
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(): for datablock in bpy.data.user_map():
has_type = hasattr(datablock, 'type') has_type = hasattr(datablock, 'type')
if ( # TODO IMPROVE FILTERING?
if not (
has_type has_type
and datablock.type == 'OBJECT' and datablock.type == 'OBJECT'
and datablock.name not in context.scene.objects and datablock.name not in context.scene.objects
): ):
# Objects that aren't in the scene have been replaced by the pull if datablock.name.endswith(suffix):
# process, so we don't want to remap any references to them. retun_datablocks.append(datablock)
continue return retun_datablocks
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}"') def remap_user(datablock, target_name):
other_db.user_remap(datablock) storage = util.get_storage_of_id(datablock)
# Rename the object to make its name available. remap_datablock = storage.get(target_name)
# This datablock should get purged soon, otherwise it's a bug. if remap_datablock:
other_db.name += "_Users_Remapped" remap_datablock.user_remap(datablock)
datablock.name = without_suffix remap_datablock.name += "_Users_Remapped"
def remap_external_datablocks(context):
source_suffix = ".SOURCE"
target_suffix = ".LOCAL"
datablocks = remap_get_data_blocks(context, source_suffix)
for datablock in datablocks:
target_name = datablock.name.replace(source_suffix, target_suffix)
remap_user(datablock, target_name)