Asset Pipeline v2 #145
@ -2,22 +2,7 @@ import bpy
|
||||
from typing import List, Dict, Union, Any, Set, Optional, Tuple
|
||||
|
||||
from . import util
|
||||
|
||||
|
||||
def get_opposite_suffix(suffix: str):
|
||||
# TODO FIX HACK that is used until I have transfer mapping
|
||||
# TODO Creating a map would be easier that doing this on the fly
|
||||
if suffix.endswith("EXTERNAL"):
|
||||
return "LOCAL"
|
||||
if suffix.endswith("LOCAL"):
|
||||
return "EXTERNAL"
|
||||
|
||||
|
||||
def rreplace(s: str, occurrence=1) -> str:
|
||||
old = s.split(".")[-1]
|
||||
new = get_opposite_suffix(old)
|
||||
li = s.rsplit(old, occurrence)
|
||||
return new.join(li)
|
||||
from . import asset_suffix
|
||||
|
||||
|
||||
class AssetTransferMapping:
|
||||
@ -57,7 +42,7 @@ class AssetTransferMapping:
|
||||
self.collection_map = self._gen_collection_map()
|
||||
|
||||
def _get_external_object(self, local_obj):
|
||||
external_obj_name = rreplace(
|
||||
external_obj_name = asset_suffix.get_target_name(
|
||||
local_obj.name,
|
||||
)
|
||||
external_obj = self._external_col.all_objects.get(external_obj_name)
|
||||
@ -91,7 +76,8 @@ class AssetTransferMapping:
|
||||
|
||||
# Find new objects to add to local_col
|
||||
for external_obj in self._external_col.all_objects:
|
||||
obj = self._local_col.all_objects.get(rreplace(external_obj.name))
|
||||
local_col_objs = self._local_col.all_objects
|
||||
obj = local_col_objs.get(asset_suffix.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
|
||||
@ -111,7 +97,7 @@ class AssetTransferMapping:
|
||||
# assert source_obj.name.endswith(self._source_merge_coll.suffix)
|
||||
|
||||
# Replace source object suffix with target suffix to get target object.
|
||||
external_col = rreplace(s_coll.name)
|
||||
external_col = asset_suffix.get_target_name(s_coll.name)
|
||||
t_coll = bpy.data.collections.get(external_col)
|
||||
if t_coll:
|
||||
coll_map[s_coll] = t_coll
|
||||
|
@ -21,12 +21,26 @@ from typing import List, Dict, Union, Any, Set, Optional, Tuple, Generator
|
||||
|
||||
import bpy
|
||||
from bpy_extras.id_map_utils import get_id_reference_map, get_all_referenced_ids
|
||||
|
||||
from . import constants
|
||||
from .util import get_storage_of_id
|
||||
|
||||
DELIMITER = "."
|
||||
|
||||
|
||||
def get_target_suffix(suffix: str):
|
||||
if suffix.endswith(constants.EXTERNAL_SUFFIX):
|
||||
return constants.LOCAL_SUFFIX
|
||||
if suffix.endswith(constants.LOCAL_SUFFIX):
|
||||
return constants.EXTERNAL_SUFFIX
|
||||
|
||||
|
||||
def get_target_name(name: str, occurrence=1) -> str:
|
||||
old = name.split(DELIMITER)[-1]
|
||||
new = get_target_suffix(old)
|
||||
li = name.rsplit(old, occurrence)
|
||||
return new.join(li)
|
||||
|
||||
|
||||
def get_basename(name):
|
||||
return DELIMITER.join(name.split(DELIMITER)[:-1])
|
||||
|
||||
|
@ -13,3 +13,6 @@ TRANSFER_DATA_TYPES = [
|
||||
("MODIFIER", "Modifier", ""),
|
||||
("MATERIAL_SLOT", "Material Slot", ""),
|
||||
]
|
||||
|
||||
LOCAL_SUFFIX = "LOCAL"
|
||||
EXTERNAL_SUFFIX = "EXTERNAL"
|
||||
|
@ -5,6 +5,7 @@ from pathlib import Path
|
||||
|
||||
from .asset_mapping import AssetTransferMapping
|
||||
|
||||
from . import constants
|
||||
|
||||
# TODO refactor merge functions into a class based on AssetBuilder class of Asset Pipeline 1
|
||||
|
||||
@ -27,8 +28,8 @@ def merge_task_layer(
|
||||
target_file: Path,
|
||||
):
|
||||
local_col = bpy.data.collections[col_base_name]
|
||||
local_suffix = "LOCAL"
|
||||
external_suffix = "EXTERNAL"
|
||||
local_suffix = constants.LOCAL_SUFFIX
|
||||
external_suffix = constants.EXTERNAL_SUFFIX
|
||||
asset_suffix.add_suffix_to_hierarchy(local_col, local_suffix)
|
||||
|
||||
import_data_from_lib(target_file, "collections", col_base_name)
|
||||
|
@ -1,6 +1,8 @@
|
||||
import bpy
|
||||
|
||||
from . import util
|
||||
from . import util, asset_suffix
|
||||
|
||||
# TODO REMOVE UNUSED FUNCTIONS
|
||||
|
||||
|
||||
def get_type_datablocks(datablocks):
|
||||
@ -61,28 +63,14 @@ def remap_user(source_datablock: bpy.data, target_datablock: bpy.data):
|
||||
source_datablock.name += "_Users_Remapped"
|
||||
|
||||
|
||||
def get_opposite_suffix(suffix: str):
|
||||
# TODO FIX HACK that is used until I have transfer mapping
|
||||
# TODO Creating a map would be easier that doing this on the fly
|
||||
if suffix.endswith("EXTERNAL"):
|
||||
return ".LOCAL"
|
||||
if suffix.endswith("LOCAL"):
|
||||
return ".EXTERNAL"
|
||||
|
||||
|
||||
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"""
|
||||
# TODO STANDARDIZE IF ASSET SHOULD HAVE . IN SUFFIX OR NOT,
|
||||
# ADD A CORE FUNCTION FOR APPENDING SUFFIX TO SINGLE ITEM
|
||||
datablocks = remap_get_data_blocks(scene)
|
||||
for datablock in datablocks:
|
||||
# FIND TARGET DATA-BLOCK BY SUFFIX
|
||||
current_suffix = "." + datablock.name.split(".")[-1]
|
||||
target_suffix = get_opposite_suffix(current_suffix)
|
||||
target_name = datablock.name.replace(current_suffix, target_suffix)
|
||||
target_name = asset_suffix.get_target_name(datablock.name)
|
||||
storage = util.get_storage_of_id(datablock)
|
||||
target_datablock = storage.get(target_name)
|
||||
print(f"Will remap {datablock.name} to {target_datablock.name}")
|
||||
if target_datablock:
|
||||
remap_user(datablock, target_datablock)
|
||||
|
Loading…
Reference in New Issue
Block a user