Asset Pipeline v2 #145
@ -1,45 +1,11 @@
|
||||
import bpy
|
||||
|
||||
from . import transfer_functions, asset_suffix
|
||||
from . import asset_suffix, transferable_data
|
||||
from pathlib import Path
|
||||
|
||||
# TODO refactor merge functions into a class based on AssetBuilder class of Asset Pipeline 1
|
||||
|
||||
|
||||
def update_transfer_data_ownership(transfer_data_item, target_obj: bpy.types.Object):
|
||||
transfer_data_ownership = target_obj.transfer_data_ownership
|
||||
transfer_items_names = [item.name for item in transfer_data_ownership]
|
||||
if transfer_data_item.name not in transfer_items_names:
|
||||
new_item = transfer_data_ownership.add()
|
||||
new_item.name = transfer_data_item.name
|
||||
new_item.owner = transfer_data_item.owner
|
||||
new_item.type = transfer_data_item.type
|
||||
new_item.id = bpy.data.objects[target_obj.name]
|
||||
|
||||
|
||||
def apply_transfer_data(
|
||||
context: bpy.types.Context,
|
||||
transfer_data_list,
|
||||
target_col: bpy.types.Collection,
|
||||
):
|
||||
for item in transfer_data_list:
|
||||
for target_obj in target_col.objects:
|
||||
if asset_suffix.get_asset_basename(
|
||||
target_obj.name
|
||||
) == asset_suffix.get_asset_basename(item.id.name):
|
||||
print(f"{target_obj.name}: READY TO TRANSFER BABY!")
|
||||
transfer_functions.transfer_vertex_group(
|
||||
context=context,
|
||||
vertex_group_name=item.name,
|
||||
target_obj=target_obj,
|
||||
source_obj=item.id,
|
||||
)
|
||||
update_transfer_data_ownership(
|
||||
transfer_data_item=item,
|
||||
target_obj=target_obj,
|
||||
)
|
||||
|
||||
|
||||
def update_task_layer_objects(
|
||||
target_col: bpy.types.Collection,
|
||||
transfer_objs: list[bpy.types.Object],
|
||||
@ -98,7 +64,7 @@ def merge_task_layer(
|
||||
transfer_data.append(item)
|
||||
update_task_layer_objects(target_col, local_objs)
|
||||
|
||||
apply_transfer_data(
|
||||
transferable_data.apply_transfer_data(
|
||||
context,
|
||||
transfer_data,
|
||||
target_col,
|
||||
|
@ -2,7 +2,7 @@ import bpy
|
||||
|
||||
from . import core
|
||||
from pathlib import Path
|
||||
from . import asset_suffix
|
||||
from . import transferable_data
|
||||
|
||||
TASK_LAYER_TYPES = [
|
||||
'RIG',
|
||||
@ -16,16 +16,9 @@ class ASSETPIPE_OT_update_ownership(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
ownership = context.active_object.transfer_data_ownership
|
||||
file_name = bpy.path.basename(bpy.context.blend_data.filepath)
|
||||
task_layer_name = file_name.split(".")[-2]
|
||||
for vertex_group in obj.vertex_groups:
|
||||
if not vertex_group.name in [item.name for item in ownership]:
|
||||
item = ownership.add()
|
||||
item.name = vertex_group.name
|
||||
item.owner = task_layer_name.upper()
|
||||
item.type = "VERTEX_GROUP" # TODO Make procedural
|
||||
item.id = bpy.data.objects[f"{obj.name.split('.')[-1]}"]
|
||||
transferable_data.vertex_groups_update(obj, task_layer_name)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
|
55
scripts-blender/addons/asset_pipeline_2/transferable_data.py
Normal file
55
scripts-blender/addons/asset_pipeline_2/transferable_data.py
Normal file
@ -0,0 +1,55 @@
|
||||
import bpy
|
||||
|
||||
from . import transfer_functions, asset_suffix
|
||||
|
||||
|
||||
def update_transfer_data_ownership(transfer_data_item, target_obj: bpy.types.Object):
|
||||
transfer_data_ownership = target_obj.transfer_data_ownership
|
||||
transfer_items_names = [item.name for item in transfer_data_ownership]
|
||||
if transfer_data_item.name not in transfer_items_names:
|
||||
new_item = transfer_data_ownership.add()
|
||||
new_item.name = transfer_data_item.name
|
||||
new_item.owner = transfer_data_item.owner
|
||||
new_item.type = transfer_data_item.type
|
||||
new_item.id = bpy.data.objects[target_obj.name]
|
||||
|
||||
|
||||
def apply_transfer_data(
|
||||
context: bpy.types.Context,
|
||||
transfer_data_list,
|
||||
target_col: bpy.types.Collection,
|
||||
):
|
||||
for item in transfer_data_list:
|
||||
for target_obj in target_col.objects:
|
||||
if asset_suffix.get_asset_basename(
|
||||
target_obj.name
|
||||
) == asset_suffix.get_asset_basename(item.id.name):
|
||||
print(f"{target_obj.name}: READY TO TRANSFER BABY!")
|
||||
transfer_functions.transfer_vertex_group(
|
||||
context=context,
|
||||
vertex_group_name=item.name,
|
||||
target_obj=target_obj,
|
||||
source_obj=item.id,
|
||||
)
|
||||
update_transfer_data_ownership(
|
||||
transfer_data_item=item,
|
||||
target_obj=target_obj,
|
||||
)
|
||||
|
||||
|
||||
## FUNCTIONS SPECFIC TO TRANSFER DATA TYPES
|
||||
|
||||
|
||||
# VERTEX GROUPS
|
||||
def vertex_groups_update(obj, task_layer_name):
|
||||
ownership = obj.transfer_data_ownership
|
||||
for vertex_group in obj.vertex_groups:
|
||||
# Only add new ownership item if vertex group doesn't have an owner
|
||||
existing_items = [item.name for item in ownership]
|
||||
matches = set([vertex_group.name]).intersection(set(existing_items))
|
||||
if len(matches) == 0:
|
||||
item = ownership.add()
|
||||
item.name = vertex_group.name
|
||||
item.owner = task_layer_name.upper()
|
||||
item.type = "VERTEX_GROUP"
|
||||
item.id = bpy.data.objects[f"{obj.name.split('.')[-1]}"]
|
Loading…
Reference in New Issue
Block a user