Asset Pipeline v2 #145
@ -134,7 +134,12 @@ def merge_task_layer(
|
||||
|
||||
for source_obj in map.object_map:
|
||||
target_obj = map.object_map[source_obj]
|
||||
if target_obj.asset_id_owner not in local_tls:
|
||||
transfer_core.copy_transfer_data(
|
||||
target_obj.transfer_data_ownership, source_obj.transfer_data_ownership
|
||||
)
|
||||
remap_user(source_obj, target_obj)
|
||||
transfer_core.transfer_data_clean(target_obj)
|
||||
|
||||
for col in map.collection_map:
|
||||
remap_user(col, map.collection_map[col])
|
||||
|
@ -24,6 +24,15 @@ def copy_transfer_data_ownership(
|
||||
)
|
||||
|
||||
|
||||
def transfer_data_clean(obj):
|
||||
# TODO add each type of transfer data here
|
||||
transfer_functions.vertex_groups_clean(obj)
|
||||
transfer_functions.vertex_colors_clean(obj)
|
||||
transfer_functions.uv_layer_clean(obj)
|
||||
transfer_functions.modifiers_clean(obj)
|
||||
transfer_functions.constraints_clean(obj)
|
||||
|
||||
|
||||
def transfer_data_is_missing(transfer_data_item) -> bool:
|
||||
"""Check if Transfer Data item is missing
|
||||
|
||||
@ -148,3 +157,14 @@ def transfer_data_add_entry(
|
||||
item.name = name
|
||||
item.owner = task_layer_name.upper()
|
||||
item.type = td_type
|
||||
|
||||
|
||||
def copy_transfer_data(source_data, target_data):
|
||||
source_data.clear()
|
||||
for transfer_info in target_data:
|
||||
transfer_data_add_entry(
|
||||
transfer_data=source_data,
|
||||
name=transfer_info.name,
|
||||
task_layer_name=transfer_info.owner,
|
||||
td_type=transfer_info.type,
|
||||
)
|
||||
|
@ -7,11 +7,18 @@ from .. import asset_suffix, constants
|
||||
## FUNCTIONS SPECFIC TO TRANSFER DATA TYPES
|
||||
|
||||
|
||||
def vertex_groups_clean(obj):
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for vertex_group in obj.vertex_groups:
|
||||
if not transfer_data.get(vertex_group.name):
|
||||
obj.vertex_groups.remove(vertex_group)
|
||||
|
||||
|
||||
# VERTEX GROUPS
|
||||
def vertex_group_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.VERTEX_GROUP_KEY and not obj.vertex_groups.get(
|
||||
item["name"]
|
||||
def vertex_group_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if transfer_info.type == constants.VERTEX_GROUP_KEY and not obj.vertex_groups.get(
|
||||
transfer_info["name"]
|
||||
):
|
||||
return True
|
||||
|
||||
@ -19,16 +26,16 @@ def vertex_group_is_missing(item):
|
||||
def get_vertex_groups(obj, task_layer_name, new_transfer_data):
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for vertex_group in obj.vertex_groups:
|
||||
# Only add new ownership item if vertex group doesn't have an owner
|
||||
# Only add new ownership transfer_info if vertex group doesn't have an owner
|
||||
matches = transfer_core.check_transfer_data_entry(
|
||||
transfer_data, vertex_group.name, constants.VERTEX_GROUP_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = vertex_group.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.VERTEX_GROUP_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = vertex_group.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.VERTEX_GROUP_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_vertex_group(
|
||||
@ -60,10 +67,20 @@ def transfer_vertex_group(
|
||||
|
||||
|
||||
# VERTEX COLORS
|
||||
def vertex_color_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.VERTEX_COLOR_KEY and not obj.data.vertex_colors.get(
|
||||
item["name"]
|
||||
def vertex_colors_clean(obj):
|
||||
if not obj.type == "MESH":
|
||||
return
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for vertex_color in obj.data.vertex_colors:
|
||||
if not transfer_data.get(vertex_color.name):
|
||||
obj.vertex_colors.data.remove(vertex_color)
|
||||
|
||||
|
||||
def vertex_color_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if (
|
||||
transfer_info.type == constants.VERTEX_COLOR_KEY
|
||||
and not obj.data.vertex_colors.get(transfer_info["name"])
|
||||
):
|
||||
return True
|
||||
|
||||
@ -73,16 +90,16 @@ def get_vertex_colors(obj, task_layer_name, new_transfer_data):
|
||||
if not obj.type == "MESH":
|
||||
return
|
||||
for vertex_color in obj.data.vertex_colors:
|
||||
# Only add new ownership item if vertex color doesn't have an owner
|
||||
# Only add new ownership transfer_info if vertex color doesn't have an owner
|
||||
matches = transfer_core.check_transfer_data_entry(
|
||||
transfer_data, vertex_color.name, constants.VERTEX_COLOR_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = vertex_color.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.VERTEX_COLOR_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = vertex_color.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.VERTEX_COLOR_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_vertex_color(
|
||||
@ -108,10 +125,19 @@ def transfer_vertex_color(
|
||||
|
||||
|
||||
# UV LAYERS
|
||||
def uv_layer_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.UV_LAYERS_KEY and not obj.data.uv_layers.get(
|
||||
item["name"]
|
||||
def uv_layer_clean(obj):
|
||||
if not obj.type == "MESH":
|
||||
return
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for uv_layer in obj.data.uv_layers:
|
||||
if not transfer_data.get(uv_layer.name):
|
||||
obj.data.uv_layers.remove(uv_layer)
|
||||
|
||||
|
||||
def uv_layer_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if transfer_info.type == constants.UV_LAYERS_KEY and not obj.data.uv_layers.get(
|
||||
transfer_info["name"]
|
||||
):
|
||||
return True
|
||||
|
||||
@ -121,16 +147,16 @@ def get_uv_layers(obj, task_layer_name, new_transfer_data):
|
||||
if not obj.type == "MESH":
|
||||
return
|
||||
for uv_layer in obj.data.uv_layers:
|
||||
# Only add new ownership item if vertex color doesn't have an owner
|
||||
# Only add new ownership transfer_info if vertex color doesn't have an owner
|
||||
matches = transfer_core.check_transfer_data_entry(
|
||||
transfer_data, uv_layer.name, constants.UV_LAYERS_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = uv_layer.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.UV_LAYERS_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = uv_layer.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.UV_LAYERS_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_uv_layer(obj_source, obj_target, uv_name):
|
||||
@ -156,9 +182,18 @@ def transfer_uv_layer(obj_source, obj_target, uv_name):
|
||||
|
||||
|
||||
# MODIFIERS
|
||||
def modifier_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.MODIFIER_KEY and not obj.modifiers.get(item["name"]):
|
||||
def modifiers_clean(obj):
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for modifiers in obj.modifiers:
|
||||
if not transfer_data.get(modifiers.name):
|
||||
obj.modifiers.remove(modifiers)
|
||||
|
||||
|
||||
def modifier_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if transfer_info.type == constants.MODIFIER_KEY and not obj.modifiers.get(
|
||||
transfer_info["name"]
|
||||
):
|
||||
return True
|
||||
|
||||
|
||||
@ -169,25 +204,25 @@ def get_modifiers(obj, task_layer_name, new_transfer_data):
|
||||
transfer_data, mod.name, constants.MODIFIER_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = mod.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.MODIFIER_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = mod.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.MODIFIER_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_modifier(item, obj_target):
|
||||
def transfer_modifier(transfer_info, obj_target):
|
||||
# remove old and sync existing modifiers
|
||||
obj_source = item.id_data
|
||||
obj_source = transfer_info.id_data
|
||||
if obj_source == obj_target:
|
||||
return
|
||||
old_mod = obj_target.modifiers.get(item.name)
|
||||
old_mod = obj_target.modifiers.get(transfer_info.name)
|
||||
if old_mod:
|
||||
obj_target.modifiers.remove(old_mod)
|
||||
|
||||
# transfer new modifiers
|
||||
for i, mod in enumerate(obj_source.modifiers):
|
||||
if mod.name == item.name:
|
||||
if mod.name == transfer_info.name:
|
||||
mod_new = obj_target.modifiers.new(mod.name, mod.type)
|
||||
# sort new modifier at correct index (default to beginning of the stack)
|
||||
idx = 0
|
||||
@ -234,9 +269,18 @@ def transfer_modifier(item, obj_target):
|
||||
|
||||
|
||||
# CONSTRAINTS
|
||||
def constraint_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.CONSTRAINT_KEY and not obj.constraints.get(item["name"]):
|
||||
def constraints_clean(obj):
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for constraint in obj.constraints:
|
||||
if not transfer_data.get(constraint.name):
|
||||
obj.constraints.remove(constraint)
|
||||
|
||||
|
||||
def constraint_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if transfer_info.type == constants.CONSTRAINT_KEY and not obj.constraints.get(
|
||||
transfer_info["name"]
|
||||
):
|
||||
return True
|
||||
|
||||
|
||||
@ -247,25 +291,25 @@ def get_constraints(obj, task_layer_name, new_transfer_data):
|
||||
transfer_data, mod.name, constants.CONSTRAINT_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = mod.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.CONSTRAINT_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = mod.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.CONSTRAINT_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_constraint(item, obj_target):
|
||||
def transfer_constraint(transfer_info, obj_target):
|
||||
# remove old and sync existing modifiers
|
||||
obj_source = item.id_data
|
||||
obj_source = transfer_info.id_data
|
||||
if obj_source == obj_target:
|
||||
return
|
||||
old_mod = obj_target.constraints.get(item.name)
|
||||
old_mod = obj_target.constraints.get(transfer_info.name)
|
||||
if old_mod:
|
||||
obj_target.constraints.remove(old_mod)
|
||||
|
||||
# transfer new modifiers
|
||||
for i, constraint in enumerate(obj_source.constraints):
|
||||
if constraint.name == item.name:
|
||||
if constraint.name == transfer_info.name:
|
||||
constraint_new = obj_target.constraints.new(constraint.type)
|
||||
constraint_new.name = constraint.name
|
||||
# sort new modifier at correct index (default to beginning of the stack)
|
||||
@ -290,10 +334,18 @@ def transfer_constraint(item, obj_target):
|
||||
|
||||
|
||||
# MATERIAL SLOT
|
||||
def material_slot_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.MATERIAL_SLOT_KEY and not obj.material_slots.get(
|
||||
item["name"]
|
||||
def material_slot_clean(obj):
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
for mat_slot in obj.material_slots:
|
||||
if not transfer_data.get(mat_slot.name):
|
||||
obj.material_slots.remove(mat_slot)
|
||||
|
||||
|
||||
def material_slot_is_missing(transfer_info):
|
||||
obj = transfer_info.id_data
|
||||
if (
|
||||
transfer_info.type == constants.MATERIAL_SLOT_KEY
|
||||
and not obj.material_slots.get(transfer_info["name"])
|
||||
):
|
||||
return True
|
||||
|
||||
@ -305,21 +357,21 @@ def get_material_slots(obj, task_layer_name, new_transfer_data):
|
||||
transfer_data, slot.name, constants.MATERIAL_SLOT_KEY
|
||||
)
|
||||
if len(matches) == 0:
|
||||
item = new_transfer_data.add()
|
||||
item.name = slot.name
|
||||
item.owner = task_layer_name
|
||||
item.type = constants.MATERIAL_SLOT_KEY
|
||||
item.obj = obj
|
||||
transfer_info = new_transfer_data.add()
|
||||
transfer_info.name = slot.name
|
||||
transfer_info.owner = task_layer_name
|
||||
transfer_info.type = constants.MATERIAL_SLOT_KEY
|
||||
transfer_info.obj = obj
|
||||
|
||||
|
||||
def transfer_material_slot(item, obj_target):
|
||||
obj_source = item.id_data
|
||||
def transfer_material_slot(transfer_info, obj_target):
|
||||
obj_source = transfer_info.id_data
|
||||
if obj_source == obj_target:
|
||||
return
|
||||
# Delete existing material slot if exists
|
||||
for idx in range(len(obj_source.material_slots)):
|
||||
slot = obj_source.material_slots[idx]
|
||||
if asset_suffix.get_basename(slot.material.name) == item.name:
|
||||
if asset_suffix.get_basename(slot.material.name) == transfer_info.name:
|
||||
obj_target.active_material_index = idx
|
||||
bpy.ops.object.material_slot_remove({"object": obj_target})
|
||||
|
||||
@ -328,7 +380,7 @@ def transfer_material_slot(item, obj_target):
|
||||
for idx in range(len(obj_source.material_slots)):
|
||||
if idx >= len(obj_target.material_slots):
|
||||
slot = obj_source.material_slots[idx]
|
||||
if asset_suffix.get_basename(slot.material.name) == item.name:
|
||||
if asset_suffix.get_basename(slot.material.name) == transfer_info.name:
|
||||
bpy.ops.object.material_slot_add({"object": obj_target})
|
||||
obj_target.material_slots[idx].link = obj_source.material_slots[
|
||||
idx
|
||||
|
Loading…
Reference in New Issue
Block a user