Asset Pipeline v2 #145
@ -18,6 +18,7 @@ TRANSFER_DATA_TYPES = [
|
||||
("MODIFIER", "Modifier", ""),
|
||||
("CONSTRAINT", "Constraint", ""),
|
||||
("MATERIAL", "Material Slot", ""),
|
||||
("GROUP_UVS", "UV Maps", ""),
|
||||
]
|
||||
|
||||
TRANSFER_DATA_KEYS = [item[0] for item in TRANSFER_DATA_TYPES]
|
||||
@ -27,6 +28,7 @@ VERTEX_COLOR_KEY = TRANSFER_DATA_KEYS[2]
|
||||
MODIFIER_KEY = TRANSFER_DATA_KEYS[3]
|
||||
CONSTRAINT_KEY = TRANSFER_DATA_KEYS[4]
|
||||
MATERIAL_SLOT_KEY = TRANSFER_DATA_KEYS[5]
|
||||
UV_LAYERS_KEY = TRANSFER_DATA_KEYS[6]
|
||||
|
||||
|
||||
PUBLISH_TYPES = [
|
||||
|
@ -38,6 +38,7 @@ def transfer_data_is_missing(transfer_data_item) -> bool:
|
||||
or transfer_functions.modifiers_is_missing(transfer_data_item)
|
||||
or transfer_functions.material_slot_is_missing(transfer_data_item)
|
||||
or transfer_functions.constraints_is_missing(transfer_data_item)
|
||||
or transfer_functions.uv_layer_is_missing(transfer_data_item)
|
||||
)
|
||||
|
||||
|
||||
@ -54,6 +55,7 @@ def get_transfer_data(obj: bpy.types.Object, task_layer_name: str, temp_transfer
|
||||
transfer_functions.get_modifiers(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_constraints(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_vertex_colors(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_uv_layers(obj, task_layer_name, temp_transfer_data)
|
||||
|
||||
|
||||
def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
|
||||
@ -96,6 +98,11 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
|
||||
if item.type == constants.MATERIAL_SLOT_KEY:
|
||||
print(f"Transfering Data {constants.MATERIAL_SLOT_KEY}: {name}")
|
||||
transfer_functions.transfer_material_slot(item, target_obj)
|
||||
if item.type == constants.UV_LAYERS_KEY:
|
||||
transfer_functions.transfer_uv_layer(
|
||||
obj_target=target_obj, obj_source=item.id_data, uv_name=item.name
|
||||
)
|
||||
|
||||
copy_transfer_data_ownership(
|
||||
transfer_data_item=item,
|
||||
target_obj=target_obj,
|
||||
|
@ -59,6 +59,7 @@ 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(
|
||||
@ -106,6 +107,54 @@ def transfer_vertex_colors(
|
||||
# transfer_corner_data(obj_source, obj_target, vcol_from.data, vcol_to.data, data_suffix = '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"]
|
||||
):
|
||||
return True
|
||||
|
||||
|
||||
def get_uv_layers(obj, task_layer_name, new_transfer_data):
|
||||
ownership = obj.transfer_data_ownership
|
||||
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
|
||||
matches = transfer_core.check_transfer_data_entry(
|
||||
ownership, 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
|
||||
|
||||
|
||||
def transfer_uv_layer(obj_source, obj_target, uv_name):
|
||||
old_uv_layer = obj_target.data.uv_layers.get(uv_name)
|
||||
if old_uv_layer:
|
||||
obj_target.data.uv_layers.remove(old_uv_layer)
|
||||
|
||||
transfer_uv = obj_source.data.uv_layers.get(uv_name)
|
||||
new_uv = obj_target.data.uv_layers.new(name=uv_name, do_init=False)
|
||||
for loop in obj_target.data.loops:
|
||||
new_uv.data[loop.index].uv = transfer_uv.data[loop.index].uv
|
||||
# BELOW CODE IS FOR NON MATCHING TOPOLOGY
|
||||
# else:
|
||||
# for uv_from in obj_source.data.uv_layers:
|
||||
# uv_to = obj_target.data.uv_layers.new(name=uv_from.name, do_init=False)
|
||||
# transfer_corner_data(obj_source, obj_target, uv_from.data, uv_to.data, data_suffix = 'uv')
|
||||
|
||||
# Make sure correct layer is set to active
|
||||
for uv_l in obj_source.data.uv_layers:
|
||||
if uv_l.active_render:
|
||||
obj_target.data.uv_layers[uv_l.name].active_render = True
|
||||
break
|
||||
|
||||
|
||||
# MODIFIERS
|
||||
def modifiers_is_missing(item):
|
||||
obj = item.id_data
|
||||
|
@ -25,6 +25,7 @@ def draw_transfer_data(
|
||||
material_slots = []
|
||||
modifiers = []
|
||||
constraints = []
|
||||
uv_layers = []
|
||||
|
||||
for item in ownership:
|
||||
if item.type == constants.VERTEX_GROUP_KEY:
|
||||
@ -37,9 +38,12 @@ def draw_transfer_data(
|
||||
modifiers.append(item)
|
||||
if item.type == constants.CONSTRAINT_KEY:
|
||||
constraints.append(item)
|
||||
if item.type == constants.UV_LAYERS_KEY:
|
||||
modifiers.append(item)
|
||||
|
||||
draw_transfer_data_type(layout, vertex_groups)
|
||||
draw_transfer_data_type(layout, vertex_colors)
|
||||
draw_transfer_data_type(layout, modifiers)
|
||||
draw_transfer_data_type(layout, material_slots)
|
||||
draw_transfer_data_type(layout, constraints)
|
||||
draw_transfer_data_type(layout, uv_layers)
|
||||
|
Loading…
Reference in New Issue
Block a user