Asset Pipeline v2 #145
@ -135,7 +135,7 @@ def get_name_with_asset_prefix(name: str) -> str:
|
|||||||
return prefix + name
|
return prefix + name
|
||||||
|
|
||||||
|
|
||||||
def get_name_with_task_layer_prefix(name: str, task_layer_owner: str) -> str:
|
def task_layer_prefix_name_get(name: str, task_layer_owner: str) -> str:
|
||||||
"""Returns a string with the prefix if it is not already set.
|
"""Returns a string with the prefix if it is not already set.
|
||||||
Users can specify a prefix to live on all objects during the
|
Users can specify a prefix to live on all objects during the
|
||||||
asset creation process. This prefix is stored in the scene.
|
asset creation process. This prefix is stored in the scene.
|
||||||
@ -148,13 +148,39 @@ def get_name_with_task_layer_prefix(name: str, task_layer_owner: str) -> str:
|
|||||||
"""
|
"""
|
||||||
if name.startswith(config.TASK_LAYER_TYPES[task_layer_owner] + "."):
|
if name.startswith(config.TASK_LAYER_TYPES[task_layer_owner] + "."):
|
||||||
return name
|
return name
|
||||||
for task_layer_key in config.TASK_LAYER_TYPES:
|
|
||||||
if name.startswith(config.TASK_LAYER_TYPES[task_layer_key] + "."):
|
base_name = task_layer_prefix_basename_get(name)
|
||||||
name = name.replace(name.split(".")[0], "")[1:]
|
if name == base_name:
|
||||||
break
|
return
|
||||||
|
|
||||||
prefix = config.TASK_LAYER_TYPES[task_layer_owner]
|
prefix = config.TASK_LAYER_TYPES[task_layer_owner]
|
||||||
return prefix + "." + name
|
return prefix + "." + base_name
|
||||||
|
|
||||||
|
|
||||||
|
def task_layer_prefix_basename_get(name: str) -> str:
|
||||||
|
for task_layer_key in config.TASK_LAYER_TYPES:
|
||||||
|
if name.startswith(config.TASK_LAYER_TYPES[task_layer_key] + "."):
|
||||||
|
return name.replace(name.split(".")[0], "")[1:]
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
def task_layer_prefix_update_name(transfer_data_item):
|
||||||
|
prefix_types = [constants.MODIFIER_KEY, constants.CONSTRAINT_KEY]
|
||||||
|
if transfer_data_item.type not in prefix_types:
|
||||||
|
return
|
||||||
|
|
||||||
|
obj = transfer_data_item.id_data
|
||||||
|
td_data = data_type_from_transfer_data_key(obj, transfer_data_item.type)
|
||||||
|
new_name = task_layer_prefix_name_get(
|
||||||
|
transfer_data_item.name, transfer_data_item.owner
|
||||||
|
)
|
||||||
|
|
||||||
|
if new_name == transfer_data_item.name or not td_data.get(transfer_data_item.name):
|
||||||
|
return
|
||||||
|
|
||||||
|
td_data[transfer_data_item.name].name = new_name
|
||||||
|
transfer_data_item.name = new_name
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_id_type_name(id_type: bpy.types) -> str:
|
def get_id_type_name(id_type: bpy.types) -> str:
|
||||||
@ -167,22 +193,3 @@ def get_id_type_name(id_type: bpy.types) -> str:
|
|||||||
str: Name of an ID type e.g. bpy.types.Object will return 'Object'
|
str: Name of an ID type e.g. bpy.types.Object will return 'Object'
|
||||||
"""
|
"""
|
||||||
return str(id_type).split("'bpy_types.")[1].replace("'>", "")
|
return str(id_type).split("'bpy_types.")[1].replace("'>", "")
|
||||||
|
|
||||||
|
|
||||||
def transfer_data_update_prefix(transfer_data_item):
|
|
||||||
prefix_types = [constants.MODIFIER_KEY, constants.CONSTRAINT_KEY]
|
|
||||||
if transfer_data_item.type not in prefix_types:
|
|
||||||
return
|
|
||||||
|
|
||||||
obj = transfer_data_item.id_data
|
|
||||||
td_data = data_type_from_transfer_data_key(obj, transfer_data_item.type)
|
|
||||||
new_name = get_name_with_task_layer_prefix(
|
|
||||||
transfer_data_item.name, transfer_data_item.owner
|
|
||||||
)
|
|
||||||
|
|
||||||
if new_name == transfer_data_item.name or not td_data.get(transfer_data_item.name):
|
|
||||||
return
|
|
||||||
|
|
||||||
td_data[transfer_data_item.name].name = new_name
|
|
||||||
transfer_data_item.name = new_name
|
|
||||||
return True
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from bpy import context
|
from bpy import context
|
||||||
from ..naming import get_basename, get_name_with_task_layer_prefix
|
from ..naming import get_basename, task_layer_prefix_name_get
|
||||||
from ..drivers import find_drivers, copy_driver
|
from ..drivers import find_drivers, copy_driver
|
||||||
from ..visibility import override_obj_visability
|
from ..visibility import override_obj_visability
|
||||||
from .transfer_util import (
|
from .transfer_util import (
|
||||||
@ -105,7 +105,7 @@ def init_modifiers(scene, obj, use_default_owner: bool):
|
|||||||
transfer_data = obj.transfer_data_ownership
|
transfer_data = obj.transfer_data_ownership
|
||||||
task_layer_owner = get_transfer_data_owner(td_type_key, use_default_owner)
|
task_layer_owner = get_transfer_data_owner(td_type_key, use_default_owner)
|
||||||
for mod in obj.modifiers:
|
for mod in obj.modifiers:
|
||||||
mod.name = get_name_with_task_layer_prefix(mod.name, task_layer_owner)
|
mod.name = task_layer_prefix_name_get(mod.name, task_layer_owner)
|
||||||
# Only add new ownership transfer_data_item if vertex group doesn't have an owner
|
# Only add new ownership transfer_data_item if vertex group doesn't have an owner
|
||||||
matches = check_transfer_data_entry(transfer_data, mod.name, td_type_key)
|
matches = check_transfer_data_entry(transfer_data, mod.name, td_type_key)
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
@ -202,7 +202,7 @@ def init_constraints(scene, obj, use_default_owner: bool):
|
|||||||
transfer_data = obj.transfer_data_ownership
|
transfer_data = obj.transfer_data_ownership
|
||||||
task_layer_owner = get_transfer_data_owner(td_type_key, use_default_owner)
|
task_layer_owner = get_transfer_data_owner(td_type_key, use_default_owner)
|
||||||
for const in obj.constraints:
|
for const in obj.constraints:
|
||||||
const.name = get_name_with_task_layer_prefix(const.name, task_layer_owner)
|
const.name = task_layer_prefix_name_get(const.name, task_layer_owner)
|
||||||
# Only add new ownership transfer_data_item if vertex group doesn't have an owner
|
# Only add new ownership transfer_data_item if vertex group doesn't have an owner
|
||||||
matches = check_transfer_data_entry(transfer_data, const.name, td_type_key)
|
matches = check_transfer_data_entry(transfer_data, const.name, td_type_key)
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
|
@ -2,7 +2,7 @@ import bpy
|
|||||||
from . import config
|
from . import config
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from .merge.naming import transfer_data_update_prefix
|
from .merge.naming import task_layer_prefix_update_name
|
||||||
from .merge.task_layer import (
|
from .merge.task_layer import (
|
||||||
set_local_task_layers,
|
set_local_task_layers,
|
||||||
draw_task_layer_selection,
|
draw_task_layer_selection,
|
||||||
@ -445,7 +445,7 @@ class ASSETPIPE_OT_fix_prefixes(bpy.types.Operator):
|
|||||||
for obj in objs:
|
for obj in objs:
|
||||||
transfer_data_items = obj.transfer_data_ownership
|
transfer_data_items = obj.transfer_data_ownership
|
||||||
for transfer_data_item in transfer_data_items:
|
for transfer_data_item in transfer_data_items:
|
||||||
if transfer_data_update_prefix(transfer_data_item):
|
if task_layer_prefix_update_name(transfer_data_item):
|
||||||
self.report(
|
self.report(
|
||||||
{'INFO'},
|
{'INFO'},
|
||||||
f"Renamed {transfer_data_item.type} on '{obj.name}'",
|
f"Renamed {transfer_data_item.type} on '{obj.name}'",
|
||||||
|
Loading…
Reference in New Issue
Block a user