Asset Pipeline v2 #145
@ -15,6 +15,7 @@ TRANSFER_DATA_TYPES = [
|
||||
("NONE", "None", ""),
|
||||
("GROUP_VERTEX", "Vertex Group", ""),
|
||||
("MODIFIER", "Modifier", ""),
|
||||
("CONSTRAINT", "Constraint", ""),
|
||||
("MATERIAL", "Material Slot", ""),
|
||||
]
|
||||
|
||||
@ -22,7 +23,9 @@ TRANSFER_DATA_KEYS = [item[0] for item in TRANSFER_DATA_TYPES]
|
||||
|
||||
VERTEX_GROUP_KEY = TRANSFER_DATA_KEYS[1]
|
||||
MODIFIER_KEY = TRANSFER_DATA_KEYS[2]
|
||||
MATERIAL_SLOT_KEY = TRANSFER_DATA_KEYS[3]
|
||||
CONSTRAINT_KEY = TRANSFER_DATA_KEYS[3]
|
||||
MATERIAL_SLOT_KEY = TRANSFER_DATA_KEYS[4]
|
||||
|
||||
|
||||
PUBLISH_TYPES = [
|
||||
(
|
||||
|
@ -12,6 +12,7 @@ from . import constants
|
||||
def ownership_transfer_data_cleanup(
|
||||
obj: bpy.types.Object, task_layer_name: str
|
||||
) -> None:
|
||||
# TODO MOVE TRANSFER DATA SPECIFIC STUFF TO TRANSFER CORE
|
||||
"""Remove Transfer Data ownership items if the corrisponding data is missing
|
||||
|
||||
Args:
|
||||
@ -26,6 +27,7 @@ def ownership_transfer_data_cleanup(
|
||||
transfer_functions.vertex_group_is_missing(item)
|
||||
or transfer_functions.modifiers_is_missing(item)
|
||||
or transfer_functions.material_slot_is_missing(item)
|
||||
or transfer_functions.constraints_is_missing(item)
|
||||
):
|
||||
to_remove.append(item.name)
|
||||
|
||||
@ -38,6 +40,7 @@ def ownership_get(
|
||||
task_layer_name: str,
|
||||
temp_transfer_data: bpy.types.CollectionProperty,
|
||||
) -> list[bpy.types.Object]:
|
||||
# TODO MOVE TRANSFER DATA SPECIFIC STUFF TO TRANSFER CORE
|
||||
"""Find new transfer data owned by the local task layer.
|
||||
Marks items as owned by the local task layer if they are in the
|
||||
corrisponding task layer collection and have no owner.
|
||||
@ -69,6 +72,7 @@ def ownership_get(
|
||||
transfer_functions.get_vertex_groups(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_material_slots(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_modifiers(obj, task_layer_name, temp_transfer_data)
|
||||
transfer_functions.get_constraints(obj, task_layer_name, temp_transfer_data)
|
||||
|
||||
return invalid_objs
|
||||
|
||||
|
@ -53,6 +53,8 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
|
||||
if item.type == constants.MODIFIER_KEY:
|
||||
print(f"Transfering Data {constants.MODIFIER_KEY}: {name}")
|
||||
transfer_functions.transfer_modifier(item, target_obj)
|
||||
if item.type == constants.CONSTRAINT_KEY:
|
||||
transfer_functions.transfer_constraint(item, target_obj)
|
||||
if item.type == constants.MATERIAL_SLOT_KEY:
|
||||
print(f"Transfering Data {constants.MATERIAL_SLOT_KEY}: {name}")
|
||||
transfer_functions.transfer_material_slot(item, target_obj)
|
||||
|
@ -137,6 +137,62 @@ def transfer_modifier(item, obj_target):
|
||||
)
|
||||
|
||||
|
||||
# CONSTRAINTS
|
||||
def constraints_is_missing(item):
|
||||
obj = item.id_data
|
||||
if item.type == constants.CONSTRAINT_KEY and not obj.constraints.get(item["name"]):
|
||||
return True
|
||||
|
||||
|
||||
def get_constraints(obj, task_layer_name, new_transfer_data):
|
||||
ownership = obj.transfer_data_ownership
|
||||
for mod in obj.constraints:
|
||||
matches = transfer_core.check_transfer_data_entry(
|
||||
ownership, 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
|
||||
|
||||
|
||||
def transfer_constraint(item, obj_target):
|
||||
# remove old and sync existing modifiers
|
||||
obj_source = item.id_data
|
||||
if obj_source == obj_target:
|
||||
return
|
||||
old_mod = obj_target.constraints.get(item.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:
|
||||
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)
|
||||
idx = 0
|
||||
if i > 0:
|
||||
name_prev = obj_source.constraints[i - 1].name
|
||||
for target_mod_i, target_constraint in enumerate(
|
||||
obj_target.constraints
|
||||
):
|
||||
if target_constraint.name == name_prev:
|
||||
idx = target_mod_i + 1
|
||||
bpy.ops.constraint.move_to_index(
|
||||
{'object': obj_target}, constraint=constraint_new.name, index=idx
|
||||
)
|
||||
constraint_target = obj_target.constraints.get(constraint.name)
|
||||
props = [
|
||||
p.identifier for p in constraint.bl_rna.properties if not p.is_readonly
|
||||
]
|
||||
for prop in props:
|
||||
value = getattr(constraint, prop)
|
||||
setattr(constraint_target, prop, value)
|
||||
|
||||
|
||||
# MATERIAL SLOT
|
||||
def material_slot_is_missing(item):
|
||||
obj = item.id_data
|
||||
|
@ -23,6 +23,7 @@ def draw_transfer_data(
|
||||
vertex_groups = []
|
||||
material_slots = []
|
||||
modifiers = []
|
||||
constraints = []
|
||||
|
||||
for item in ownership:
|
||||
if item.type == constants.VERTEX_GROUP_KEY:
|
||||
@ -31,7 +32,10 @@ def draw_transfer_data(
|
||||
material_slots.append(item)
|
||||
if item.type == constants.MODIFIER_KEY:
|
||||
modifiers.append(item)
|
||||
if item.type == constants.CONSTRAINT_KEY:
|
||||
constraints.append(item)
|
||||
|
||||
draw_transfer_data_type(layout, vertex_groups)
|
||||
draw_transfer_data_type(layout, modifiers)
|
||||
draw_transfer_data_type(layout, material_slots)
|
||||
draw_transfer_data_type(layout, constraints)
|
||||
|
Loading…
Reference in New Issue
Block a user