Asset Pipeline: Improve Performance #235

Merged
4 changed files with 64 additions and 21 deletions
Showing only changes of commit d9665dadd4 - Show all commits

View File

@ -169,7 +169,7 @@ class AssetTransferMapping:
return coll_map return coll_map
def _transfer_data_get_map_content(self, obj, target_obj, transfer_data_item): def _create_temp_transfer_data_item(self, source_obj, target_obj, transfer_data_item):
temp_transfer_data = bpy.context.scene.asset_pipeline.temp_transfer_data temp_transfer_data = bpy.context.scene.asset_pipeline.temp_transfer_data
temp_transfer_data_item_index = len(temp_transfer_data) temp_transfer_data_item_index = len(temp_transfer_data)
temp_transfer_data_item = transfer_data_add_entry( temp_transfer_data_item = transfer_data_add_entry(
@ -178,17 +178,11 @@ class AssetTransferMapping:
td_type_key=transfer_data_item.type, td_type_key=transfer_data_item.type,
task_layer_name=transfer_data_item.owner, task_layer_name=transfer_data_item.owner,
surrender=transfer_data_item.surrender, surrender=transfer_data_item.surrender,
target_obj=target_obj,
obj=source_obj,
) )
map_item = { return temp_transfer_data_item_index
'transfer_data_item_index': temp_transfer_data_item_index,
'source_obj': obj,
'target_obj': target_obj,
}
# Names of each map item need to be unique
# below name avoids name conflicts between different types
name = transfer_data_item.name + '_' + transfer_data_item.type + obj.name
return name, map_item
def _transfer_data_pair_not_local(self, td_1, td_2): def _transfer_data_pair_not_local(self, td_1, td_2):
# Returns true if neither owners are local to current file # Returns true if neither owners are local to current file
@ -243,11 +237,17 @@ class AssetTransferMapping:
"""Adds item to Transfer Data Map""" """Adds item to Transfer Data Map"""
if self._transfer_data_is_surrendered(transfer_data_item): if self._transfer_data_is_surrendered(transfer_data_item):
return return
td_type_key = transfer_data_item.type
name, map_item = self._transfer_data_get_map_content( temp_td_index = self._create_temp_transfer_data_item(
source_obj, target_obj, transfer_data_item source_obj, target_obj, transfer_data_item
) )
self.transfer_data_map[name] = map_item if not source_obj in self.transfer_data_map:
self.transfer_data_map[source_obj] = {td_type_key: [temp_td_index]}
if not td_type_key in self.transfer_data_map[source_obj]:
self.transfer_data_map[source_obj][td_type_key] = [temp_td_index]
else:
self.transfer_data_map[source_obj][td_type_key].append(temp_td_index)
def _transfer_data_map_item(self, source_obj, target_obj, transfer_data_item): def _transfer_data_map_item(self, source_obj, target_obj, transfer_data_item):
"""Verifies if Transfer Data Item is valid/can be mapped""" """Verifies if Transfer Data Item is valid/can be mapped"""
@ -284,11 +284,17 @@ class AssetTransferMapping:
# Generate a Map of Indexes that need to be set post merge # Generate a Map of Indexes that need to be set post merge
# Stores active_uv & active_color_attribute # Stores active_uv & active_color_attribute
index_map = {} index_map = {}
for _, item in self.transfer_data_map.items(): temp_transfer_data_items = []
temp_transfer_data = bpy.context.scene.asset_pipeline.temp_transfer_data temp_transfer_data = bpy.context.scene.asset_pipeline.temp_transfer_data
temp_transfer_data_item = temp_transfer_data[item.get('transfer_data_item_index')]
source_obj = item.get('source_obj') for source_obj in self.transfer_data_map:
target_obj = item.get('target_obj') for td_type_key, td_indexes in self.transfer_data_map[source_obj].items():
for index in td_indexes:
temp_transfer_data_items.append(temp_transfer_data[index])
for temp_transfer_data_item in temp_transfer_data_items:
source_obj = temp_transfer_data_item.obj
target_obj = temp_transfer_data_item.target_obj
if temp_transfer_data_item.type != constants.MATERIAL_SLOT_KEY: if temp_transfer_data_item.type != constants.MATERIAL_SLOT_KEY:
continue continue

View File

@ -9,15 +9,19 @@ from .transfer_functions import (
vertex_groups, vertex_groups,
materials, materials,
) )
from typing import List
from ... import constants, logging from ... import constants, logging
from ...props import AssetTransferDataTemp
from bpy.types import PropertyGroup
from .transfer_util import ( from .transfer_util import (
transfer_data_add_entry, transfer_data_add_entry,
check_transfer_data_entry, check_transfer_data_entry,
) )
def copy_transfer_data_ownership(transfer_data_item, target_obj: bpy.types.Object) -> None:
def copy_transfer_data_ownership(
transfer_data_item: AssetTransferDataTemp, target_obj: bpy.types.Object
) -> None:
"""Copy Transferable Data item to object if non entry exists """Copy Transferable Data item to object if non entry exists
Args: Args:
@ -114,6 +118,12 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
transfer_data_item = temp_transfer_data[transfer_data.get('transfer_data_item_index')] transfer_data_item = temp_transfer_data[transfer_data.get('transfer_data_item_index')]
target_obj = transfer_data.get('target_obj') target_obj = transfer_data.get('target_obj')
source_obj = transfer_data.get('source_obj') source_obj = transfer_data.get('source_obj')
def apply_transfer_data_items(context, td_type_key: str, transfer_data_items: List[PropertyGroup]):
for transfer_data_item in transfer_data_items:
target_obj = transfer_data_item.target_obj
source_obj = transfer_data_item.obj
if target_obj is None: if target_obj is None:
logger.warning(f"Failed to Transfer Data for {transfer_data_item.id_data.name}") logger.warning(f"Failed to Transfer Data for {transfer_data_item.id_data.name}")
continue continue
@ -188,3 +198,23 @@ def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
transfer_data_item=transfer_data_item, transfer_data_item=transfer_data_item,
target_obj=target_obj, target_obj=target_obj,
) )
transfer_data_item.copy_transfer_data_ownership()
def apply_transfer_data(context: bpy.types.Context, transfer_data_map) -> None:
"""Apply all Transferable Data from Transferable Data map onto objects.
Copies any Transferable Data owned by local layer onto objects owned by external layers.
Applies Transferable Data from external layers onto objects owned by local layers
Transfer_data_map is generated by class 'AssetTransferMapping'
Args:
context (bpy.types.Context): context of .blend file
transfer_data_map: Map generated by class AssetTransferMapping
"""
temp_transfer_data = context.scene.asset_pipeline.temp_transfer_data
for source_obj in transfer_data_map:
for td_type_key, td_indexes in transfer_data_map[source_obj].items():
transfer_data_items = [temp_transfer_data[index] for index in td_indexes]
apply_transfer_data_items(context, td_type_key, transfer_data_items)

View File

@ -30,6 +30,8 @@ def transfer_data_add_entry(
td_type_key: str, td_type_key: str,
task_layer_name: str, task_layer_name: str,
surrender: bool, surrender: bool,
target_obj: bpy.types.Object = None,
obj: bpy.types.Object = None,
): ):
"""Add entry to Transferable Data ownership """Add entry to Transferable Data ownership
@ -44,6 +46,10 @@ def transfer_data_add_entry(
transfer_data_item.owner = task_layer_name transfer_data_item.owner = task_layer_name
transfer_data_item.type = td_type_key transfer_data_item.type = td_type_key
transfer_data_item.surrender = surrender transfer_data_item.surrender = surrender
if target_obj:
transfer_data_item.target_obj = target_obj
if obj:
transfer_data_item.obj = obj
return transfer_data_item return transfer_data_item

View File

@ -201,6 +201,7 @@ class AssetPipeline(bpy.types.PropertyGroup):
description="Select Asset Library Catalog for the current Asset, this value will be updated each time you Push to an 'Active' Publish", description="Select Asset Library Catalog for the current Asset, this value will be updated each time you Push to an 'Active' Publish",
) # type: ignore ) # type: ignore
@bpy.app.handlers.persistent @bpy.app.handlers.persistent
def set_asset_collection_name_post_file_load(_): def set_asset_collection_name_post_file_load(_):
# Version the PointerProperty to the StringProperty, and the left-over pointer. # Version the PointerProperty to the StringProperty, and the left-over pointer.