Asset Pipeline v2 #145
@ -8,6 +8,13 @@ from .asset_mapping import AssetTransferMapping
|
||||
from . import constants
|
||||
|
||||
|
||||
def remap_user(source_datablock: bpy.data, target_datablock: bpy.data):
|
||||
"""Remap datablock and append name to datablock that has been remapped"""
|
||||
print(f"REMAPPING {source_datablock.name} to {target_datablock.name}")
|
||||
source_datablock.user_remap(target_datablock)
|
||||
source_datablock.name += "_Users_Remapped"
|
||||
|
||||
|
||||
def update_task_layer_objects(
|
||||
target_col: bpy.types.Collection,
|
||||
transfer_objs: list[bpy.types.Object],
|
||||
@ -67,7 +74,7 @@ def merge_task_layer(
|
||||
|
||||
for source_obj in map.object_map:
|
||||
target_obj = map.object_map[source_obj]
|
||||
datablocks.remap_user(source_obj, target_obj)
|
||||
remap_user(source_obj, target_obj)
|
||||
|
||||
bpy.ops.outliner.orphans_purge(
|
||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||
|
@ -1,76 +0,0 @@
|
||||
import bpy
|
||||
|
||||
from . import util, asset_suffix
|
||||
|
||||
# TODO REMOVE UNUSED FUNCTIONS
|
||||
|
||||
|
||||
def get_type_datablocks(datablocks):
|
||||
"""Filters for items in a list of datablocks that have a 'type'"""
|
||||
return [datablock for datablock in datablocks if hasattr(datablock, 'type')]
|
||||
|
||||
|
||||
def get_users_of_id(datablock):
|
||||
"""Returns datablocks that are using/referencing a give datablock"""
|
||||
return bpy.data.user_map()[datablock]
|
||||
|
||||
|
||||
def recursively_find_parent_objs(datablock):
|
||||
"""Recursively loop through ID parents and return a parent obj
|
||||
of a given datablock"""
|
||||
datablocks = bpy.data.user_map()[datablock]
|
||||
if datablock not in list(bpy.data.objects):
|
||||
for datablock in datablocks:
|
||||
recursively_find_parent_objs(datablock)
|
||||
else:
|
||||
return datablocks
|
||||
|
||||
|
||||
def referenced_in_scene(scene: bpy.types.Scene, datablock):
|
||||
"""Returns datablocks that are being references by data within
|
||||
the scene"""
|
||||
users = get_users_of_id(datablock)
|
||||
for user in users:
|
||||
if user in list(scene.objects):
|
||||
return True
|
||||
|
||||
# FOR DATABLOCKS THAT ARE NOT OBJ BUT ARE REFERENCES BY OBJS IN SCENE
|
||||
parent_users = recursively_find_parent_objs(datablock)
|
||||
if parent_users is None:
|
||||
return
|
||||
for parent_user in parent_users:
|
||||
if parent_user in list(scene.objects):
|
||||
return True
|
||||
|
||||
|
||||
def remap_get_data_blocks(scene: bpy.types.Scene):
|
||||
"""Returns list of datablocks that aren't in the scene
|
||||
but are referenced by data within the scene"""
|
||||
retun_datablocks = []
|
||||
datablocks = [db for db in bpy.data.user_map() if hasattr(db, 'type')]
|
||||
for datablock in datablocks:
|
||||
if referenced_in_scene(scene, datablock) and datablock not in list(
|
||||
scene.objects
|
||||
):
|
||||
retun_datablocks.append(datablock)
|
||||
return retun_datablocks
|
||||
|
||||
|
||||
def remap_user(source_datablock: bpy.data, target_datablock: bpy.data):
|
||||
"""Remap datablock and append name to datablock that has been remapped"""
|
||||
print(f"REMAPPING {source_datablock.name} to {target_datablock.name}")
|
||||
source_datablock.user_remap(target_datablock)
|
||||
source_datablock.name += "_Users_Remapped"
|
||||
|
||||
|
||||
def remap_datablocks_outside_scene(scene: bpy.types.Scene):
|
||||
"""Remap Datablocks that are used in the scene but will be purged
|
||||
because they are not references by the items within the scene"""
|
||||
datablocks = remap_get_data_blocks(scene)
|
||||
for datablock in datablocks:
|
||||
# FIND TARGET DATA-BLOCK BY SUFFIX
|
||||
target_name = asset_suffix.get_target_name(datablock.name)
|
||||
storage = util.get_storage_of_id(datablock)
|
||||
target_datablock = storage.get(target_name)
|
||||
if target_datablock:
|
||||
remap_user(datablock, target_datablock)
|
Loading…
Reference in New Issue
Block a user