Asset Pipeline v2 #145
@ -1,8 +1,7 @@
|
||||
import bpy
|
||||
from typing import Dict, Set
|
||||
|
||||
from . import asset_suffix
|
||||
from . import constants
|
||||
from . import asset_suffix, constants, util
|
||||
from .transfer_data import transfer_core
|
||||
|
||||
|
||||
@ -126,8 +125,9 @@ class AssetTransferMapping:
|
||||
return coll_map
|
||||
|
||||
def _gen_transfer_data_map(self):
|
||||
context = util.get_stored_context()
|
||||
transfer_data_map: Dict[bpy.types.Collection, bpy.types.Collection] = {}
|
||||
temp_transfer_data = bpy.context.scene.asset_pipeline.temp_transfer_data
|
||||
temp_transfer_data = context.scene.asset_pipeline.temp_transfer_data
|
||||
temp_transfer_data.clear()
|
||||
for source_obj in self.object_map:
|
||||
target_obj = self.object_map[source_obj]
|
||||
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||
from typing import Dict
|
||||
from .asset_mapping import AssetTransferMapping
|
||||
|
||||
from . import constants
|
||||
from . import constants, util
|
||||
|
||||
|
||||
def ownership_transfer_data_cleanup(
|
||||
@ -115,6 +115,7 @@ def merge_task_layer(
|
||||
local_tls: (list[str]): list of task layers that are local to the current file
|
||||
external_file (Path): external file to pull data into the current file from
|
||||
"""
|
||||
util.set_stored_context(context=context)
|
||||
local_col = context.scene.asset_pipeline.asset_collection
|
||||
if not local_col:
|
||||
return "Unable to find Asset Collection"
|
||||
@ -299,7 +300,8 @@ def import_data_from_lib(
|
||||
|
||||
def get_task_layer_name_from_file() -> str:
|
||||
"""Returns task layer name found task's file name"""
|
||||
file_name = bpy.path.basename(bpy.context.blend_data.filepath)
|
||||
context = util.get_stored_context()
|
||||
file_name = bpy.path.basename(context.blend_data.filepath)
|
||||
task_layer_name = file_name.split(".")[-2]
|
||||
if task_layer_name in constants.TASK_LAYER_KEYS:
|
||||
return task_layer_name
|
||||
|
@ -1,7 +1,7 @@
|
||||
import bpy
|
||||
from bpy import context
|
||||
from . import transfer_core
|
||||
from .. import asset_suffix, constants
|
||||
from .. import asset_suffix, constants, util
|
||||
import mathutils
|
||||
import bmesh
|
||||
import numpy as np
|
||||
@ -163,7 +163,7 @@ def init_modifiers(scene, obj):
|
||||
|
||||
def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
# remove old and sync existing modifiers
|
||||
context = bpy.context # TODO PASS CONTEXT
|
||||
context = util.get_stored_context()
|
||||
old_mod = target_obj.modifiers.get(modifier_name)
|
||||
if old_mod:
|
||||
target_obj.modifiers.remove(old_mod)
|
||||
@ -233,8 +233,7 @@ def init_constraints(scene, obj):
|
||||
|
||||
|
||||
def transfer_constraint(constraint_name, target_obj, source_obj):
|
||||
context = bpy.context # TODO PASS CONTEXT
|
||||
|
||||
context = util.get_stored_context()
|
||||
# remove old and sync existing modifiers
|
||||
old_mod = target_obj.constraints.get(constraint_name)
|
||||
if old_mod:
|
||||
@ -277,7 +276,7 @@ def transfer_constraint(constraint_name, target_obj, source_obj):
|
||||
# MATERIAL SLOT
|
||||
def material_slot_clean(obj):
|
||||
# Material slots cannot use generic transfer_info_clean() function
|
||||
context = bpy.context # TODO pass context here
|
||||
context = util.get_stored_context()
|
||||
transfer_data_list = transfer_core.get_transfer_data_by_name(
|
||||
obj.transfer_data_ownership, constants.MATERIAL_SLOT_KEY
|
||||
)
|
||||
@ -303,7 +302,7 @@ def init_material_slots(scene, obj):
|
||||
|
||||
def transfer_material_slot(material_slot_name, target_obj, source_obj):
|
||||
# Delete existing material slot if exists
|
||||
context = bpy.context # TODO pass context here
|
||||
context = util.get_stored_context()
|
||||
for idx in range(len(source_obj.material_slots)):
|
||||
slot = source_obj.material_slots[idx]
|
||||
if asset_suffix.get_basename(slot.material.name) == material_slot_name:
|
||||
@ -395,6 +394,7 @@ def shape_key_closest_tri_on_face(tris_dict, face, p):
|
||||
|
||||
|
||||
def shape_keys_clean(obj):
|
||||
context = util.get_stored_context()
|
||||
if obj.type != "MESH" or obj.data.shape_keys is None:
|
||||
return
|
||||
transfer_data_list = transfer_core.get_transfer_data_by_name(
|
||||
@ -403,7 +403,7 @@ def shape_keys_clean(obj):
|
||||
for shape_key in obj.data.shape_keys.key_blocks:
|
||||
# Move Shape Keys relative to themselves to the top (usually basis key)
|
||||
if shape_key.relative_key == shape_key:
|
||||
shape_key_move(bpy.context, obj, shape_key.name)
|
||||
shape_key_move(context, obj, shape_key.name)
|
||||
|
||||
if not asset_suffix.get_basename(shape_key.name) in transfer_data_list:
|
||||
obj.shape_key_remove(shape_key)
|
||||
|
@ -99,3 +99,16 @@ def traverse_collection_tree(
|
||||
yield collection
|
||||
for child in collection.children:
|
||||
yield from traverse_collection_tree(child)
|
||||
|
||||
|
||||
stored_context = None
|
||||
|
||||
|
||||
def set_stored_context(context):
|
||||
global stored_context
|
||||
stored_context = context
|
||||
|
||||
|
||||
def get_stored_context():
|
||||
global stored_context
|
||||
return stored_context
|
||||
|
Loading…
Reference in New Issue
Block a user