Asset Pipeline v2 #145

Closed
Nick Alberelli wants to merge 431 commits from (deleted):feature/asset-pipeline-v2 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
8 changed files with 93 additions and 74 deletions
Showing only changes of commit 0fae738189 - Show all commits

View File

@ -94,7 +94,9 @@ class AssetTransferMapping:
coll_map: Dict[bpy.types.Collection, bpy.types.Collection] = {}
local_tl_names = [
item[1] for item in constants.TASK_LAYER_TYPES if item[0] in self._local_tls
tl_type[1]
for tl_type in constants.TASK_LAYER_TYPES
if tl_type[0] in self._local_tls
]
for local_task_layer_col in self._local_col.children:
@ -126,18 +128,21 @@ class AssetTransferMapping:
transfer_data_map: Dict[bpy.types.Collection, bpy.types.Collection] = {}
for obj in self._external_col.all_objects:
for item in obj.transfer_data_ownership:
if item.owner not in self._local_tls and item.owner != "NONE":
name = item.name + '_' + obj.name
for transfer_info in obj.transfer_data_ownership:
if (
transfer_info.owner not in self._local_tls
and transfer_info.owner != "NONE"
):
name = transfer_info.name + '_' + obj.name
target_obj_name = asset_suffix.get_target_name(obj.name)
target_obj = self._local_col.all_objects.get(target_obj_name)
transfer_data_map[name] = (item, target_obj)
transfer_data_map[name] = (transfer_info, target_obj)
for obj in self._local_col.all_objects:
for item in obj.transfer_data_ownership:
if item.owner in self._local_tls:
name = item.name + '_' + obj.name
for transfer_info in obj.transfer_data_ownership:
if transfer_info.owner in self._local_tls:
name = transfer_info.name + '_' + obj.name
target_obj_name = asset_suffix.get_target_name(obj.name)
target_obj = self._external_col.all_objects.get(target_obj_name)
transfer_data_map[name] = (item, target_obj)
transfer_data_map[name] = (transfer_info, target_obj)
return transfer_data_map

View File

@ -7,8 +7,8 @@ TASK_LAYER_TYPES = [
("SHADE", "Shading", ""),
]
TASK_LAYER_KEYS = [item[0] for item in TASK_LAYER_TYPES]
TASK_LAYER_NAMES = [item[1] for item in TASK_LAYER_TYPES]
TASK_LAYER_KEYS = [task_layer[0] for task_layer in TASK_LAYER_TYPES]
TASK_LAYER_NAMES = [task_layer[1] for task_layer in TASK_LAYER_TYPES]
# KEYS FOR TRANSFER DATA TYPE MATCH NAME OF ICON
TRANSFER_DATA_TYPES = [
@ -21,7 +21,7 @@ TRANSFER_DATA_TYPES = [
("GROUP_UVS", "UV Maps", ""),
]
TRANSFER_DATA_KEYS = [item[0] for item in TRANSFER_DATA_TYPES]
TRANSFER_DATA_KEYS = [transfer_data[0] for transfer_data in TRANSFER_DATA_TYPES]
VERTEX_GROUP_KEY = TRANSFER_DATA_KEYS[1]
VERTEX_COLOR_KEY = TRANSFER_DATA_KEYS[2]
@ -49,7 +49,7 @@ PUBLISH_TYPES = [
"Test the results that will be published in the review area, will not be used as Push/Pull target",
),
]
PUBLISH_KEYS = [item[0] for item in PUBLISH_TYPES]
PUBLISH_KEYS = [pub_type[0] for pub_type in PUBLISH_TYPES]
ACTIVE_PUBLISH_KEY = PUBLISH_KEYS[0]
STAGED_PUBLISH_KEY = PUBLISH_KEYS[1]

View File

@ -18,15 +18,15 @@ def ownership_transfer_data_cleanup(
obj (bpy.types.Object): Object that contains the transfer data
task_layer_name (str): Name of the current task layer that owns the data
"""
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
to_remove = []
for item in ownership:
if constants.TASK_LAYER_KEYS[item["owner"]] == task_layer_name:
if transfer_core.transfer_data_is_missing(item):
to_remove.append(item.name)
for transfer_info in transfer_data:
if constants.TASK_LAYER_KEYS[transfer_info["owner"]] == task_layer_name:
if transfer_core.transfer_data_is_missing(transfer_info):
to_remove.append(transfer_info.name)
for name in to_remove:
ownership.remove(ownership.keys().index(name))
transfer_data.remove(transfer_data.keys().index(name))
def ownership_get(
@ -75,10 +75,10 @@ def ownership_set(temp_transfer_data: bpy.types.CollectionProperty) -> None:
temp_transfer_data (bpy.types.CollectionProperty): Collection property containing newly found
data and the object that contains this data.
"""
for item in temp_transfer_data:
ownership = item.obj.transfer_data_ownership
for transfer_info in temp_transfer_data:
transfer_data = transfer_info.obj.transfer_data_ownership
transfer_core.transfer_data_add_entry(
ownership, item.name, item.type, item.owner
transfer_data, transfer_info.name, transfer_info.type, transfer_info.owner
)

View File

@ -87,7 +87,7 @@ class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
bl_label = "Sync with Publish"
bl_description = """Push and or Pull data from Published file. Will prompt with a list of new data found before pushing"""
_temp_ownership = None
_temp_transfer_data = None
_invalid_objs = []
save: bpy.props.BoolProperty(
@ -107,8 +107,8 @@ class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
)
def invoke(self, context: bpy.types.Context, event: bpy.types.Event):
self._temp_ownership = context.scene.temp_transfer_data_ownership
self._temp_ownership.clear()
self._temp_transfer_data = context.scene.temp_transfer_data_ownership
self._temp_transfer_data.clear()
self._invalid_objs.clear()
local_col = context.scene.asset_status.asset_collection
@ -123,7 +123,7 @@ class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
self._invalid_objs = core.ownership_get(
local_col,
task_layer_name,
self._temp_ownership,
self._temp_transfer_data,
)
# Default behaviour is to pull before pushing
@ -146,23 +146,27 @@ class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
for obj in self._invalid_objs:
box.label(text=obj.name, icon="OBJECT_DATA")
if len(self._temp_ownership) == 0:
if len(self._temp_transfer_data) == 0:
layout.label(text="No New Transfer Data found")
else:
layout.label(text="New Transfer Data will be Pushed to Publish")
objs = [item.obj for item in self._temp_ownership]
objs = [transfer_info.obj for transfer_info in self._temp_transfer_data]
for obj in set(objs):
obj_ownership = [item for item in self._temp_ownership if item.obj == obj]
obj_ownership = [
transfer_info
for transfer_info in self._temp_transfer_data
if transfer_info.obj == obj
]
box = layout.box()
box.label(text=obj.name, icon="OBJECT_DATA")
transfer_ui.draw_transfer_data(obj_ownership, box)
def execute(self, context: bpy.types.Context):
# Find current task Layer
ownership = context.scene.temp_transfer_data_ownership
core.ownership_set(ownership)
temp_transfer_data = context.scene.temp_transfer_data_ownership
core.ownership_set(temp_transfer_data)
current_file = Path(bpy.data.filepath)
task_layer_name = core.get_task_layer_name_from_file()
if not task_layer_name:
@ -206,7 +210,9 @@ class ASSETPIPE_OT_sync_with_publish(bpy.types.Operator):
continue
local_tls = [
item for item in constants.TASK_LAYER_KEYS if item != task_layer_name
task_layer
for task_layer in constants.TASK_LAYER_KEYS
if task_layer != task_layer_name
]
error_msg = core.merge_task_layer(

View File

@ -13,11 +13,11 @@ def copy_transfer_data_ownership(
transfer_data_item: Item of bpy.types.CollectionProperty from source object
target_obj (bpy.types.Object): Object to add transfer data item to
"""
ownership = target_obj.transfer_data_ownership
transfer_items_names = [item.name for item in ownership]
transfer_data = target_obj.transfer_data_ownership
transfer_items_names = [transfer_info.name for transfer_info in transfer_data]
if transfer_data_item.name not in transfer_items_names:
transfer_data_add_entry(
ownership,
transfer_data,
transfer_data_item.name,
transfer_data_item.type,
transfer_data_item.owner,
@ -110,7 +110,7 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
def check_transfer_data_entry(
ownership: bpy.types.CollectionProperty, key: str, td_type: str
transfer_data: bpy.types.CollectionProperty, key: str, td_type: str
) -> set:
"""Verifies if transfer data entry exists
@ -122,12 +122,16 @@ def check_transfer_data_entry(
Returns:
set: Returns set of matches where name is found in ownership
"""
existing_items = [item.name for item in ownership if item.type == td_type]
existing_items = [
transfer_info.name
for transfer_info in transfer_data
if transfer_info.type == td_type
]
return set([key]).intersection(set(existing_items))
def transfer_data_add_entry(
ownership: bpy.types.CollectionProperty,
transfer_data: bpy.types.CollectionProperty,
name: str,
td_type: str,
task_layer_name: str,
@ -140,7 +144,7 @@ def transfer_data_add_entry(
td_type (str): Type of transfer data
task_layer_name (str): Name of current task layer
"""
item = ownership.add()
item = transfer_data.add()
item.name = name
item.owner = task_layer_name.upper()
item.type = td_type

View File

@ -17,11 +17,11 @@ def vertex_group_is_missing(item):
def get_vertex_groups(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
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
matches = transfer_core.check_transfer_data_entry(
ownership, vertex_group.name, constants.VERTEX_GROUP_KEY
transfer_data, vertex_group.name, constants.VERTEX_GROUP_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()
@ -69,13 +69,13 @@ def vertex_color_is_missing(item):
def get_vertex_colors(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
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
matches = transfer_core.check_transfer_data_entry(
ownership, vertex_color.name, constants.VERTEX_COLOR_KEY
transfer_data, vertex_color.name, constants.VERTEX_COLOR_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()
@ -117,13 +117,13 @@ def uv_layer_is_missing(item):
def get_uv_layers(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
transfer_data = 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
transfer_data, uv_layer.name, constants.UV_LAYERS_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()
@ -163,10 +163,10 @@ def modifiers_is_missing(item):
def get_modifiers(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
for mod in obj.modifiers:
matches = transfer_core.check_transfer_data_entry(
ownership, mod.name, constants.MODIFIER_KEY
transfer_data, mod.name, constants.MODIFIER_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()
@ -241,10 +241,10 @@ def constraints_is_missing(item):
def get_constraints(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
for mod in obj.constraints:
matches = transfer_core.check_transfer_data_entry(
ownership, mod.name, constants.CONSTRAINT_KEY
transfer_data, mod.name, constants.CONSTRAINT_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()
@ -299,10 +299,10 @@ def material_slot_is_missing(item):
def get_material_slots(obj, task_layer_name, new_transfer_data):
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
for slot in obj.material_slots:
matches = transfer_core.check_transfer_data_entry(
ownership, slot.name, constants.MATERIAL_SLOT_KEY
transfer_data, slot.name, constants.MATERIAL_SLOT_KEY
)
if len(matches) == 0:
item = new_transfer_data.add()

View File

@ -3,21 +3,25 @@ import bpy
def draw_transfer_data_type(
layout: bpy.types.UILayout, items: bpy.types.CollectionProperty
layout: bpy.types.UILayout, transfer_data: bpy.types.CollectionProperty
) -> None:
"""Draw UI Element for items of a transfer data type"""
if items == []:
if transfer_data == []:
return
name = core.get_dict_tuple_item(constants.TRANSFER_DATA_TYPES, items[0].type)[1]
name = core.get_dict_tuple_item(
constants.TRANSFER_DATA_TYPES, transfer_data[0].type
)[1]
box = layout.box()
box.label(text=name, icon=items[0].type)
for item in items:
owner = core.get_dict_tuple_item(constants.TASK_LAYER_TYPES, item.owner)[1]
box.label(text=f"{item.name}: '{owner}'")
box.label(text=name, icon=transfer_data[0].type)
for transfer_info in transfer_data:
owner = core.get_dict_tuple_item(
constants.TASK_LAYER_TYPES, transfer_info.owner
)[1]
box.label(text=f"{transfer_info.name}: '{owner}'")
def draw_transfer_data(
ownership: bpy.types.CollectionProperty, layout: bpy.types.UILayout
transfer_data: bpy.types.CollectionProperty, layout: bpy.types.UILayout
) -> None:
"""Draw UI List of Transfer Data"""
vertex_groups = []
@ -27,19 +31,19 @@ def draw_transfer_data(
constraints = []
uv_layers = []
for item in ownership:
if item.type == constants.VERTEX_GROUP_KEY:
vertex_groups.append(item)
if item.type == constants.VERTEX_COLOR_KEY:
vertex_colors.append(item)
if item.type == constants.MATERIAL_SLOT_KEY:
material_slots.append(item)
if item.type == constants.MODIFIER_KEY:
modifiers.append(item)
if item.type == constants.CONSTRAINT_KEY:
constraints.append(item)
if item.type == constants.UV_LAYERS_KEY:
modifiers.append(item)
for transfer_info in transfer_data:
if transfer_info.type == constants.VERTEX_GROUP_KEY:
vertex_groups.append(transfer_info)
if transfer_info.type == constants.VERTEX_COLOR_KEY:
vertex_colors.append(transfer_info)
if transfer_info.type == constants.MATERIAL_SLOT_KEY:
material_slots.append(transfer_info)
if transfer_info.type == constants.MODIFIER_KEY:
modifiers.append(transfer_info)
if transfer_info.type == constants.CONSTRAINT_KEY:
constraints.append(transfer_info)
if transfer_info.type == constants.UV_LAYERS_KEY:
modifiers.append(transfer_info)
draw_transfer_data_type(layout, vertex_groups)
draw_transfer_data_type(layout, vertex_colors)

View File

@ -51,13 +51,13 @@ class ASSETPIPE_ownership_inspector(bpy.types.Panel):
layout.label(text="Set an Active Object to Inspect")
return
obj = context.active_object
ownership = obj.transfer_data_ownership
transfer_data = obj.transfer_data_ownership
layout = layout.box()
owner = core.get_dict_tuple_item(
constants.TASK_LAYER_TYPES, obj.asset_id_owner
)[1]
layout.label(text=f"{obj.name}: '{owner}'", icon="OBJECT_DATA")
transfer_ui.draw_transfer_data(ownership, layout)
transfer_ui.draw_transfer_data(transfer_data, layout)
task_layer_name = core.get_task_layer_name_from_file()
if task_layer_name not in constants.TASK_LAYER_KEYS: