Asset Pipeline v2 #145
@ -72,3 +72,6 @@ STAGED_PUBLISH_KEY = PUBLISH_KEYS[1]
|
|||||||
|
|
||||||
LOCAL_SUFFIX = "LOCAL"
|
LOCAL_SUFFIX = "LOCAL"
|
||||||
EXTERNAL_SUFFIX = "EXTERNAL"
|
EXTERNAL_SUFFIX = "EXTERNAL"
|
||||||
|
|
||||||
|
|
||||||
|
MATERIAL_ATTRIBUTE_NAME = "material_index"
|
||||||
|
@ -47,6 +47,7 @@ def transfer_vertex_group(
|
|||||||
|
|
||||||
source_obj.vertex_groups.active = source_obj.vertex_groups.get(vertex_group_name)
|
source_obj.vertex_groups.active = source_obj.vertex_groups.get(vertex_group_name)
|
||||||
# TODO Debug crashing / use context.temp_override(object=obj) style
|
# TODO Debug crashing / use context.temp_override(object=obj) style
|
||||||
|
# https://projects.blender.org/blender/blender/issues/112299
|
||||||
context = bpy.context
|
context = bpy.context
|
||||||
override = context.copy()
|
override = context.copy()
|
||||||
override["selected_editable_objects"] = [target_obj, source_obj]
|
override["selected_editable_objects"] = [target_obj, source_obj]
|
||||||
@ -295,11 +296,7 @@ def material_slots_clean(obj):
|
|||||||
if transfer_data_list != []:
|
if transfer_data_list != []:
|
||||||
return
|
return
|
||||||
|
|
||||||
for mat_slot in obj.material_slots:
|
obj.data.materials.clear()
|
||||||
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_slots_is_missing(transfer_info):
|
def material_slots_is_missing(transfer_info):
|
||||||
@ -330,25 +327,14 @@ def init_material_slots(scene, obj):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def transfer_material_slots(target_obj, source_obj):
|
def transfer_material_slots(target_obj: bpy.types.Object, source_obj):
|
||||||
# Delete existing material slot if exists
|
|
||||||
context = bpy.context
|
|
||||||
# Transfer material slot assignments.
|
|
||||||
# Delete all material slots of target object.
|
# Delete all material slots of target object.
|
||||||
while len(target_obj.material_slots) > len(source_obj.material_slots):
|
target_obj.data.materials.clear()
|
||||||
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
|
# Transfer material slots
|
||||||
for idx in range(len(source_obj.material_slots)):
|
for idx in range(len(source_obj.material_slots)):
|
||||||
if idx >= len(target_obj.material_slots):
|
target_obj.data.materials.append(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].link = source_obj.material_slots[idx].link
|
||||||
target_obj.material_slots[idx].material = source_obj.material_slots[
|
|
||||||
idx
|
|
||||||
].material
|
|
||||||
|
|
||||||
# Transfer active material slot index
|
# Transfer active material slot index
|
||||||
target_obj.active_material_index = source_obj.active_material_index
|
target_obj.active_material_index = source_obj.active_material_index
|
||||||
@ -358,6 +344,9 @@ def transfer_material_slots(target_obj, source_obj):
|
|||||||
for spl_to, spl_from in zip(target_obj.data.splines, source_obj.data.splines):
|
for spl_to, spl_from in zip(target_obj.data.splines, source_obj.data.splines):
|
||||||
spl_to.material_index = spl_from.material_index
|
spl_to.material_index = spl_from.material_index
|
||||||
|
|
||||||
|
if source_obj.data.attributes.get(constants.MATERIAL_ATTRIBUTE_NAME):
|
||||||
|
transfer_attribute(constants.MATERIAL_ATTRIBUTE_NAME, target_obj, source_obj)
|
||||||
|
|
||||||
|
|
||||||
# SHAPE KEYS
|
# SHAPE KEYS
|
||||||
|
|
||||||
@ -515,7 +504,11 @@ def transfer_shape_key(
|
|||||||
def attributes_get_editable(attributes):
|
def attributes_get_editable(attributes):
|
||||||
# TODO replace 'position' HACK with is_required once https://projects.blender.org/blender/blender/pulls/111468 is merged
|
# TODO replace 'position' HACK with is_required once https://projects.blender.org/blender/blender/pulls/111468 is merged
|
||||||
return [
|
return [
|
||||||
item for item in attributes if not (item.is_internal or item.name == 'position')
|
item
|
||||||
|
for item in attributes
|
||||||
|
if not (
|
||||||
|
item.is_internal or item.name == 'position' or item.name == 'material_index'
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user