Asset Pipeline v2 #145
@ -22,6 +22,7 @@ import bpy
|
||||
from bpy_extras.id_map_utils import get_id_reference_map, get_all_referenced_ids
|
||||
from .util import get_storage_of_id
|
||||
from .. import constants, config
|
||||
from .util import data_type_from_transfer_data_key
|
||||
|
||||
DELIMITER = "."
|
||||
|
||||
@ -166,3 +167,22 @@ def get_id_type_name(id_type: bpy.types) -> str:
|
||||
str: Name of an ID type e.g. bpy.types.Object will return 'Object'
|
||||
"""
|
||||
return str(id_type).split("'bpy_types.")[1].replace("'>", "")
|
||||
|
||||
|
||||
def transfer_data_update_prefix(transfer_data_item):
|
||||
prefix_types = [constants.MODIFIER_KEY, constants.CONSTRAINT_KEY]
|
||||
if transfer_data_item.type not in prefix_types:
|
||||
return
|
||||
|
||||
obj = transfer_data_item.id_data
|
||||
td_data = data_type_from_transfer_data_key(obj, transfer_data_item.type)
|
||||
new_name = get_name_with_task_layer_prefix(
|
||||
transfer_data_item.name, transfer_data_item.owner
|
||||
)
|
||||
|
||||
if new_name == transfer_data_item.name or not td_data.get(transfer_data_item.name):
|
||||
return
|
||||
|
||||
td_data[transfer_data_item.name].name = new_name
|
||||
transfer_data_item.name = new_name
|
||||
return True
|
||||
|
@ -184,21 +184,3 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
|
||||
transfer_data_item=transfer_data_item,
|
||||
target_obj=target_obj,
|
||||
)
|
||||
|
||||
|
||||
def data_type_from_transfer_data_key(obj: bpy.types.Object, td_type: str):
|
||||
"""Returns the data on an object that is referred to by the transfer data type"""
|
||||
if td_type == constants.VERTEX_GROUP_KEY:
|
||||
return obj.vertex_groups
|
||||
if td_type == constants.MODIFIER_KEY:
|
||||
return obj.modifiers
|
||||
if td_type == constants.CONSTRAINT_KEY:
|
||||
return obj.constraints
|
||||
if td_type == constants.MATERIAL_SLOT_KEY:
|
||||
return obj.material_slots
|
||||
if td_type == constants.SHAPE_KEY_KEY:
|
||||
return obj.data.shape_keys.key_blocks
|
||||
if td_type == constants.ATTRIBUTE_KEY:
|
||||
return obj.data.attributes
|
||||
if td_type == constants.PARENT_KEY:
|
||||
return obj.parent
|
||||
|
@ -19,7 +19,7 @@
|
||||
# (c) 2021, Blender Foundation - Paul Golter
|
||||
|
||||
from typing import Dict, Any, Tuple, Generator
|
||||
|
||||
from .. import constants
|
||||
import bpy
|
||||
from bpy import types
|
||||
|
||||
@ -99,3 +99,21 @@ def traverse_collection_tree(
|
||||
yield collection
|
||||
for child in collection.children:
|
||||
yield from traverse_collection_tree(child)
|
||||
|
||||
|
||||
def data_type_from_transfer_data_key(obj: bpy.types.Object, td_type: str):
|
||||
"""Returns the data on an object that is referred to by the transfer data type"""
|
||||
if td_type == constants.VERTEX_GROUP_KEY:
|
||||
return obj.vertex_groups
|
||||
if td_type == constants.MODIFIER_KEY:
|
||||
return obj.modifiers
|
||||
if td_type == constants.CONSTRAINT_KEY:
|
||||
return obj.constraints
|
||||
if td_type == constants.MATERIAL_SLOT_KEY:
|
||||
return obj.material_slots
|
||||
if td_type == constants.SHAPE_KEY_KEY:
|
||||
return obj.data.shape_keys.key_blocks
|
||||
if td_type == constants.ATTRIBUTE_KEY:
|
||||
return obj.data.attributes
|
||||
if td_type == constants.PARENT_KEY:
|
||||
return obj.parent
|
||||
|
@ -2,12 +2,11 @@ import bpy
|
||||
from . import config
|
||||
import os
|
||||
from pathlib import Path
|
||||
from .merge.naming import transfer_data_update_prefix
|
||||
from .merge.task_layer import (
|
||||
set_local_task_layers,
|
||||
draw_task_layer_selection,
|
||||
)
|
||||
from .merge.naming import get_name_with_task_layer_prefix
|
||||
from .merge.transfer_data.transfer_core import data_type_from_transfer_data_key
|
||||
from .merge.publish import get_next_published_file, find_all_published
|
||||
from .images import save_images
|
||||
from . import constants
|
||||
@ -441,39 +440,17 @@ class ASSETPIPE_OT_fix_prefixes(bpy.types.Operator):
|
||||
return False
|
||||
return True
|
||||
|
||||
def transfer_data_update_prefix(self, context, transfer_data_item):
|
||||
obj = transfer_data_item.id_data
|
||||
td_data = data_type_from_transfer_data_key(obj, transfer_data_item.type)
|
||||
new_name = get_name_with_task_layer_prefix(
|
||||
transfer_data_item.name, transfer_data_item.owner
|
||||
)
|
||||
|
||||
if new_name == transfer_data_item.name or not td_data.get(
|
||||
transfer_data_item.name
|
||||
):
|
||||
return
|
||||
|
||||
td_data[transfer_data_item.name].name = new_name
|
||||
transfer_data_item.name = new_name
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Renamed {transfer_data_item.type} on '{obj.name}' to {new_name}",
|
||||
)
|
||||
self._updated_prefix = True
|
||||
|
||||
def transfer_data_using_prefix_get(self, context, obj):
|
||||
types_to_update = [constants.MODIFIER_KEY, constants.CONSTRAINT_KEY]
|
||||
return [td for td in obj.transfer_data_ownership if td.type in types_to_update]
|
||||
|
||||
def transfer_data_update_all_prefixes(self, context, obj):
|
||||
transfer_data_items = self.transfer_data_using_prefix_get(context, obj)
|
||||
for transfer_data_item in transfer_data_items:
|
||||
self.transfer_data_update_prefix(context, transfer_data_item)
|
||||
|
||||
def execute(self, context: bpy.types.Context):
|
||||
objs = context.selected_objects
|
||||
for obj in objs:
|
||||
self.transfer_data_update_all_prefixes(context, obj)
|
||||
transfer_data_items = obj.transfer_data_ownership
|
||||
for transfer_data_item in transfer_data_items:
|
||||
if transfer_data_update_prefix(transfer_data_item):
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Renamed {transfer_data_item.type} on '{obj.name}'",
|
||||
)
|
||||
self._updated_prefix = True
|
||||
|
||||
if not self._updated_prefix:
|
||||
self.report(
|
||||
|
Loading…
Reference in New Issue
Block a user