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.
5 changed files with 120 additions and 122 deletions
Showing only changes of commit d1debd5c4a - Show all commits

View File

@ -3,7 +3,7 @@ from typing import Dict, Set
from . import core # TODO DEBUG WHY THIS DOESN'T WORK
from .naming import get_target_name, get_basename, get_name_with_asset_prefix
from .util import get_storage_of_id
from .transfer_data.transfer_core import transfer_data_add_entry
from .transfer_data.transfer_util import transfer_data_add_entry
from .other_ids import get_other_ids
from .. import constants

View File

@ -3,10 +3,10 @@ from .asset_mapping import AssetTransferMapping
from .transfer_data.transfer_core import (
init_transfer_data,
transfer_data_is_missing,
transfer_data_add_entry,
apply_transfer_data,
transfer_data_clean,
)
from .transfer_data.transfer_util import transfer_data_add_entry
from .naming import (
add_suffix_to_hierarchy,

View File

@ -1,10 +1,14 @@
import bpy
from .. import naming
from . import transfer_functions
from ... import constants
from .transfer_util import (
transfer_data_add_entry,
check_transfer_data_entry,
)
def copy_transfer_data_ownership(
transfer_data_item, target_obj: bpy.types.Object
@ -172,82 +176,3 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
transfer_data_item=transfer_info,
target_obj=target_obj,
)
def check_transfer_data_entry(
transfer_data: bpy.types.CollectionProperty, key: str, td_type: str
) -> set:
"""Verifies if transfer data entry exists
Args:
ownership (bpy.types.CollectionProperty): Transfer Data of an object
key (str): Name of item that is being verified
td_type (str): Type of transfer data
Returns:
set: Returns set of matches where name is found in ownership
"""
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(
transfer_data: bpy.types.CollectionProperty,
name: str,
td_type: str,
task_layer_name: str,
):
"""Add entry to transfer data ownership
Args:
ownership (bpy.types.CollectionProperty): Transfer Data of an object
name (str): Name of new transfer data item
td_type (str): Type of transfer data
task_layer_name (str): Name of current task layer
"""
transfer_info = transfer_data.add()
transfer_info.name = name
transfer_info.owner = task_layer_name.upper()
transfer_info.type = td_type
return transfer_info
def get_transfer_data_as_names(transfer_data, td_type):
return [
transfer_info.name
for transfer_info in transfer_data
if transfer_info.type == td_type
]
def transfer_info_clean(obj, list, td_type):
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, td_type
)
for item in list:
if not naming.get_basename(item.name) in transfer_data_list:
list.remove(item)
def transfer_info_is_missing(transfer_info, type_key, list):
if transfer_info.type == type_key and not list.get(transfer_info["name"]):
return True
def transfer_info_init(scene, obj, list, type_key):
transfer_data = obj.transfer_data_ownership
task_layer_key = scene.asset_pipeline.task_layer_name
for item in list:
# Only add new ownership transfer_info if vertex group doesn't have an owner
matches = check_transfer_data_entry(transfer_data, item.name, type_key)
if len(matches) == 0:
scene.asset_pipeline.add_temp_trasnfer_data(
name=item.name,
owner=task_layer_key,
type=type_key,
obj=obj,
)

View File

@ -2,7 +2,13 @@ import bpy
from bpy import context
from ..naming import get_basename
from ..drivers import find_drivers, copy_driver
from . import transfer_core # TODO FIX
from .transfer_util import (
transfer_info_clean,
transfer_info_is_missing,
transfer_info_init,
get_transfer_data_as_names, # TODO Replce with check entry
check_transfer_data_entry,
)
from ... import constants
import mathutils
import bmesh
@ -14,21 +20,17 @@ import numpy as np
# VERTEX GROUPS
def vertex_groups_clean(obj):
transfer_core.transfer_info_clean(
obj, obj.vertex_groups, constants.VERTEX_GROUP_KEY
)
transfer_info_clean(obj, obj.vertex_groups, constants.VERTEX_GROUP_KEY)
def vertex_group_is_missing(transfer_info):
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info, constants.VERTEX_GROUP_KEY, transfer_info.id_data.vertex_groups
)
def init_vertex_groups(scene, obj):
transfer_core.transfer_info_init(
scene, obj, obj.vertex_groups, constants.VERTEX_GROUP_KEY
)
transfer_info_init(scene, obj, obj.vertex_groups, constants.VERTEX_GROUP_KEY)
def transfer_vertex_group(
@ -75,13 +77,11 @@ def transfer_vertex_group(
def vertex_colors_clean(obj):
if not obj.type == "MESH":
return
transfer_core.transfer_info_clean(
obj, obj.data.vertex_colors, constants.VERTEX_COLOR_KEY
)
transfer_info_clean(obj, obj.data.vertex_colors, constants.VERTEX_COLOR_KEY)
def vertex_color_is_missing(transfer_info):
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info, constants.VERTEX_COLOR_KEY, transfer_info.id_data.vertex_colors
)
@ -89,9 +89,7 @@ def vertex_color_is_missing(transfer_info):
def init_vertex_colors(scene, obj):
if not obj.type == "MESH":
return
transfer_core.transfer_info_init(
scene, obj, obj.data.vertex_colors, constants.VERTEX_COLOR_KEY
)
transfer_info_init(scene, obj, obj.data.vertex_colors, constants.VERTEX_COLOR_KEY)
def transfer_vertex_color(
@ -120,11 +118,11 @@ def transfer_vertex_color(
def uv_layer_clean(obj):
if not obj.type == "MESH":
return
transfer_core.transfer_info_clean(obj, obj.data.uv_layers, constants.UV_LAYERS_KEY)
transfer_info_clean(obj, obj.data.uv_layers, constants.UV_LAYERS_KEY)
def uv_layer_is_missing(transfer_info):
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info, constants.UV_LAYERS_KEY, transfer_info.id_data.data.uv_layers
)
@ -132,9 +130,7 @@ def uv_layer_is_missing(transfer_info):
def init_uv_layers(scene, obj):
if not obj.type == "MESH":
return
transfer_core.transfer_info_init(
scene, obj, obj.data.uv_layers, constants.UV_LAYERS_KEY
)
transfer_info_init(scene, obj, obj.data.uv_layers, constants.UV_LAYERS_KEY)
def transfer_uv_layer(source_obj, target_obj, uv_name):
@ -161,17 +157,17 @@ def transfer_uv_layer(source_obj, target_obj, uv_name):
# MODIFIERS
def modifiers_clean(obj):
transfer_core.transfer_info_clean(obj, obj.modifiers, constants.MODIFIER_KEY)
transfer_info_clean(obj, obj.modifiers, constants.MODIFIER_KEY)
def modifier_is_missing(transfer_info):
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info, constants.MODIFIER_KEY, transfer_info.id_data.modifiers
)
def init_modifiers(scene, obj):
transfer_core.transfer_info_init(scene, obj, obj.modifiers, constants.MODIFIER_KEY)
transfer_info_init(scene, obj, obj.modifiers, constants.MODIFIER_KEY)
def transfer_modifier(modifier_name, target_obj, source_obj):
@ -237,19 +233,17 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
# CONSTRAINTS
def constraints_clean(obj):
transfer_core.transfer_info_clean(obj, obj.constraints, constants.CONSTRAINT_KEY)
transfer_info_clean(obj, obj.constraints, constants.CONSTRAINT_KEY)
def constraint_is_missing(transfer_info):
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info, constants.CONSTRAINT_KEY, transfer_info.id_data.constraints
)
def init_constraints(scene, obj):
transfer_core.transfer_info_init(
scene, obj, obj.constraints, constants.CONSTRAINT_KEY
)
transfer_info_init(scene, obj, obj.constraints, constants.CONSTRAINT_KEY)
def transfer_constraint(constraint_name, target_obj, source_obj):
@ -304,9 +298,9 @@ def transfer_constraint(constraint_name, target_obj, source_obj):
# MATERIAL SLOT
def material_slots_clean(obj):
# Material slots cannot use generic transfer_core.transfer_info_clean() function
# Material slots cannot use generic transfer_info_clean() function
context = bpy.context
transfer_data_list = transfer_core.get_transfer_data_as_names(
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, constants.MATERIAL_SLOT_KEY
)
@ -335,7 +329,7 @@ def init_material_slots(scene, obj):
# 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)
matches = 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(
@ -416,7 +410,7 @@ def shape_keys_clean(obj):
context = bpy.context
if obj.type != "MESH" or obj.data.shape_keys is None:
return
transfer_data_list = transfer_core.get_transfer_data_as_names(
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, constants.SHAPE_KEY_KEY
)
for shape_key in obj.data.shape_keys.key_blocks:
@ -432,7 +426,7 @@ def shape_key_is_missing(transfer_info):
return
if not obj.data.shape_keys:
return True
return transfer_core.transfer_info_is_missing(
return transfer_info_is_missing(
transfer_info,
constants.SHAPE_KEY_KEY,
obj.data.shape_keys.key_blocks,
@ -453,7 +447,7 @@ def init_shape_keys(scene, obj):
f'Shape Key "{kb.name}" must be ordered after its base shape "{kb.relative_key.name}" on object "{obj.name}".'
)
transfer_core.transfer_info_init(
transfer_info_init(
scene, obj, obj.data.shape_keys.key_blocks, constants.SHAPE_KEY_KEY
)
@ -552,7 +546,7 @@ def attribute_clean(obj):
if obj.type != "MESH":
return
attributes = attributes_get_editable(obj.data.attributes)
transfer_data_list = transfer_core.get_transfer_data_as_names(
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, constants.ATTRIBUTE_KEY
)
for item in attributes:
@ -582,9 +576,7 @@ def init_attributes(scene, obj):
type_key = constants.ATTRIBUTE_KEY
for atttribute in attributes_get_editable(obj.data.attributes):
# Only add new ownership transfer_info if vertex group doesn't have an owner
matches = transfer_core.check_transfer_data_entry(
transfer_data, atttribute.name, type_key
)
matches = check_transfer_data_entry(transfer_data, atttribute.name, type_key)
if len(matches) == 0:
scene.asset_pipeline.add_temp_trasnfer_data(
name=atttribute.name,
@ -625,7 +617,7 @@ def transfer_attribute(
def parent_clean(obj):
transfer_data_list = transfer_core.get_transfer_data_as_names(
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, constants.PARENT_KEY
)
@ -653,7 +645,7 @@ def init_parent(scene, obj):
# Only Execute if Material Slots exist on object
if obj.parent == None:
return
matches = transfer_core.check_transfer_data_entry(transfer_data, name, type_key)
matches = 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(

View File

@ -0,0 +1,81 @@
import bpy
from ..naming import get_basename
def check_transfer_data_entry(
transfer_data: bpy.types.CollectionProperty, key: str, td_type: str
) -> set:
"""Verifies if transfer data entry exists
Args:
ownership (bpy.types.CollectionProperty): Transfer Data of an object
key (str): Name of item that is being verified
td_type (str): Type of transfer data
Returns:
set: Returns set of matches where name is found in ownership
"""
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(
transfer_data: bpy.types.CollectionProperty,
name: str,
td_type: str,
task_layer_name: str,
):
"""Add entry to transfer data ownership
Args:
ownership (bpy.types.CollectionProperty): Transfer Data of an object
name (str): Name of new transfer data item
td_type (str): Type of transfer data
task_layer_name (str): Name of current task layer
"""
transfer_info = transfer_data.add()
transfer_info.name = name
transfer_info.owner = task_layer_name.upper()
transfer_info.type = td_type
return transfer_info
def get_transfer_data_as_names(transfer_data, td_type):
return [
transfer_info.name
for transfer_info in transfer_data
if transfer_info.type == td_type
]
def transfer_info_clean(obj, list, td_type):
transfer_data_list = get_transfer_data_as_names(
obj.transfer_data_ownership, td_type
)
for item in list:
if not get_basename(item.name) in transfer_data_list:
list.remove(item)
def transfer_info_is_missing(transfer_info, type_key, list):
if transfer_info.type == type_key and not list.get(transfer_info["name"]):
return True
def transfer_info_init(scene, obj, list, type_key):
transfer_data = obj.transfer_data_ownership
task_layer_key = scene.asset_pipeline.task_layer_name
for item in list:
# Only add new ownership transfer_info if vertex group doesn't have an owner
matches = check_transfer_data_entry(transfer_data, item.name, type_key)
if len(matches) == 0:
scene.asset_pipeline.add_temp_trasnfer_data(
name=item.name,
owner=task_layer_key,
type=type_key,
obj=obj,
)