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 pathlib import Path
from .constants import TASK_LAYER_ITEMS
# 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)
update_task_layer_objects(target_col, local_objs)
transferable_data.apply_transfer_data(
context,
transfer_data,
target_col,
)
transferable_data.apply_transfer_data(context, transfer_data, target_col)
remap_external_datablocks(context)
bpy.ops.outliner.orphans_purge(
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)
@ -138,47 +130,34 @@ def import_data_from_lib(
### 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
def remap_get_data_blocks(context, suffix):
retun_datablocks = []
for datablock in bpy.data.user_map():
has_type = hasattr(datablock, 'type')
if (
# TODO IMPROVE FILTERING?
if not (
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
if datablock.name.endswith(suffix):
retun_datablocks.append(datablock)
return retun_datablocks
def remap_user(datablock, target_name):
storage = util.get_storage_of_id(datablock)
if not datablock.name.endswith(suf):
continue
remap_datablock = storage.get(target_name)
if remap_datablock:
remap_datablock.user_remap(datablock)
remap_datablock.name += "_Users_Remapped"
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
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)