Asset Pipeline v2 #145
@ -34,6 +34,8 @@ UV_LAYERS_KEY = TRANSFER_DATA_KEYS[6]
|
||||
SHAPE_KEY_KEY = TRANSFER_DATA_KEYS[7]
|
||||
ATTRIBUTE_KEY = TRANSFER_DATA_KEYS[8]
|
||||
|
||||
MATERIAL_TRANSFER_INFO_NAME = "All Material Slots"
|
||||
|
||||
PUBLISH_TYPES = [
|
||||
(
|
||||
"publish",
|
||||
|
@ -30,7 +30,7 @@ def transfer_data_clean(obj):
|
||||
# transfer_functions.uv_layer_clean(obj)
|
||||
transfer_functions.modifiers_clean(obj)
|
||||
transfer_functions.constraints_clean(obj)
|
||||
transfer_functions.material_slot_clean(obj)
|
||||
transfer_functions.material_slots_clean(obj)
|
||||
transfer_functions.shape_keys_clean(obj)
|
||||
transfer_functions.attribute_clean(obj)
|
||||
|
||||
@ -47,7 +47,7 @@ def transfer_data_is_missing(transfer_data_item) -> bool:
|
||||
return bool(
|
||||
transfer_functions.vertex_group_is_missing(transfer_data_item)
|
||||
or transfer_functions.modifier_is_missing(transfer_data_item)
|
||||
or transfer_functions.material_slot_is_missing(transfer_data_item)
|
||||
or transfer_functions.material_slots_is_missing(transfer_data_item)
|
||||
or transfer_functions.constraint_is_missing(transfer_data_item)
|
||||
# or transfer_functions.vertex_color_is_missing(transfer_data_item)
|
||||
# or transfer_functions.uv_layer_is_missing(transfer_data_item)
|
||||
@ -130,8 +130,7 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
|
||||
)
|
||||
if transfer_info.type == constants.MATERIAL_SLOT_KEY:
|
||||
print(f"Transfering Data {constants.MATERIAL_SLOT_KEY}: {name}")
|
||||
transfer_functions.transfer_material_slot(
|
||||
material_slot_name=transfer_info.name,
|
||||
transfer_functions.transfer_material_slots(
|
||||
target_obj=target_obj,
|
||||
source_obj=source_obj,
|
||||
)
|
||||
|
@ -284,56 +284,71 @@ def transfer_constraint(constraint_name, target_obj, source_obj):
|
||||
|
||||
|
||||
# MATERIAL SLOT
|
||||
def material_slot_clean(obj):
|
||||
def material_slots_clean(obj):
|
||||
# Material slots cannot use generic transfer_info_clean() function
|
||||
context = bpy.context
|
||||
transfer_data_list = transfer_core.get_transfer_data_as_names(
|
||||
obj.transfer_data_ownership, constants.MATERIAL_SLOT_KEY
|
||||
)
|
||||
|
||||
# Clear Materials if No Transfer Data is Found
|
||||
if transfer_data_list != []:
|
||||
return
|
||||
|
||||
for mat_slot in obj.material_slots:
|
||||
if not asset_suffix.get_basename(mat_slot.name) in transfer_data_list:
|
||||
index = obj.material_slots.keys().index(mat_slot.name)
|
||||
obj.active_material_index = index
|
||||
with context.temp_override(object=obj):
|
||||
bpy.ops.object.material_slot_remove()
|
||||
index = obj.material_slots.keys().index(mat_slot.name)
|
||||
obj.active_material_index = index
|
||||
with context.temp_override(object=obj):
|
||||
bpy.ops.object.material_slot_remove()
|
||||
|
||||
|
||||
def material_slot_is_missing(transfer_info):
|
||||
return transfer_core.transfer_info_is_missing(
|
||||
transfer_info, constants.MATERIAL_SLOT_KEY, transfer_info.id_data.material_slots
|
||||
)
|
||||
def material_slots_is_missing(transfer_info):
|
||||
if (
|
||||
transfer_info.type == constants.MATERIAL_SLOT_KEY
|
||||
and len(transfer_info.id_data.material_slots) == 0
|
||||
):
|
||||
return True
|
||||
|
||||
|
||||
def init_material_slots(scene, obj):
|
||||
transfer_core.transfer_info_init(
|
||||
scene, obj, obj.material_slots, constants.MATERIAL_SLOT_KEY
|
||||
)
|
||||
task_layer_name = scene.asset_pipeline.task_layer_name
|
||||
type_key = constants.MATERIAL_SLOT_KEY
|
||||
name = constants.MATERIAL_TRANSFER_INFO_NAME
|
||||
transfer_data = obj.transfer_data_ownership
|
||||
|
||||
# Only Execute if Material Slots exist on object
|
||||
if len(obj.material_slots) == 0:
|
||||
return
|
||||
matches = transfer_core.check_transfer_data_entry(transfer_data, name, type_key)
|
||||
# Only add new ownership transfer_info if vertex group doesn't have an owner
|
||||
if len(matches) == 0:
|
||||
scene.asset_pipeline.add_temp_trasnfer_data(
|
||||
name=name,
|
||||
owner=task_layer_name,
|
||||
type=type_key,
|
||||
obj=obj,
|
||||
)
|
||||
|
||||
|
||||
def transfer_material_slot(material_slot_name, target_obj, source_obj):
|
||||
def transfer_material_slots(target_obj, source_obj):
|
||||
# Delete existing material slot if exists
|
||||
context = bpy.context
|
||||
for idx in range(len(source_obj.material_slots)):
|
||||
slot = source_obj.material_slots[idx]
|
||||
if asset_suffix.get_basename(slot.material.name) == material_slot_name:
|
||||
target_obj.active_material_index = idx
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.object.material_slot_remove()
|
||||
# Transfer material slot assignments.
|
||||
# Delete all material slots of target object.
|
||||
while len(target_obj.material_slots) > len(source_obj.material_slots):
|
||||
target_obj.active_material_index = len(source_obj.material_slots)
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.object.material_slot_remove()
|
||||
|
||||
# Transfer material slots
|
||||
|
||||
for idx in range(len(source_obj.material_slots)):
|
||||
if idx >= len(target_obj.material_slots):
|
||||
slot = source_obj.material_slots[idx]
|
||||
if asset_suffix.get_basename(slot.material.name) == material_slot_name:
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.object.material_slot_add()
|
||||
target_obj.material_slots[idx].link = source_obj.material_slots[
|
||||
idx
|
||||
].link
|
||||
target_obj.material_slots[idx].material = source_obj.material_slots[
|
||||
idx
|
||||
].material
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.object.material_slot_add()
|
||||
target_obj.material_slots[idx].link = source_obj.material_slots[idx].link
|
||||
target_obj.material_slots[idx].material = source_obj.material_slots[
|
||||
idx
|
||||
].material
|
||||
|
||||
# Transfer active material slot index
|
||||
target_obj.active_material_index = source_obj.active_material_index
|
||||
@ -343,12 +358,6 @@ def transfer_material_slot(material_slot_name, target_obj, source_obj):
|
||||
for spl_to, spl_from in zip(target_obj.data.splines, source_obj.data.splines):
|
||||
spl_to.material_index = spl_from.material_index
|
||||
|
||||
# Rest of the loop applies only to meshes.
|
||||
if target_obj.type == "MESH":
|
||||
# Transfer material slot assignments for mesh
|
||||
for pol_to, pol_from in zip(target_obj.data.polygons, source_obj.data.polygons):
|
||||
pol_to.material_index = pol_from.material_index
|
||||
|
||||
|
||||
# SHAPE KEYS
|
||||
|
||||
@ -506,11 +515,7 @@ def transfer_shape_key(
|
||||
def attributes_get_editable(attributes):
|
||||
# TODO replace 'position' HACK with is_required once https://projects.blender.org/blender/blender/pulls/111468 is merged
|
||||
return [
|
||||
item
|
||||
for item in attributes
|
||||
if not (
|
||||
item.is_internal or item.name == 'position' or item.name == 'material_index'
|
||||
)
|
||||
item for item in attributes if not (item.is_internal or item.name == 'position')
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user