Asset Pipeline v2 #145
@ -242,6 +242,7 @@ def init_modifiers(scene, obj, use_default_owner: bool):
|
||||
def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
# remove old and sync existing modifiers
|
||||
context = bpy.context
|
||||
scene = context.scene
|
||||
old_mod = target_obj.modifiers.get(modifier_name)
|
||||
if old_mod:
|
||||
target_obj.modifiers.remove(old_mod)
|
||||
@ -257,7 +258,7 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
for target_mod_i, target_mod in enumerate(target_obj.modifiers):
|
||||
if target_mod.name == name_prev:
|
||||
idx = target_mod_i + 1
|
||||
with override_obj_visability(obj=target_obj):
|
||||
with override_obj_visability(obj=target_obj, scene=scene):
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.object.modifier_move_to_index(
|
||||
modifier=mod_new.name, index=idx
|
||||
@ -274,7 +275,7 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
if not mod.is_bound:
|
||||
continue
|
||||
for i in range(2):
|
||||
with override_obj_visability(obj=target_obj):
|
||||
with override_obj_visability(obj=target_obj, scene=scene):
|
||||
with context.temp_override(
|
||||
object=target_obj, active_object=target_obj
|
||||
):
|
||||
@ -283,7 +284,7 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
if not mod.is_bound:
|
||||
continue
|
||||
for i in range(2):
|
||||
with override_obj_visability(obj=target_obj):
|
||||
with override_obj_visability(obj=target_obj, scene=scene):
|
||||
with context.temp_override(
|
||||
object=target_obj, active_object=target_obj
|
||||
):
|
||||
@ -292,7 +293,7 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
if not mod.is_bind:
|
||||
continue
|
||||
for i in range(2):
|
||||
with override_obj_visability(obj=target_obj):
|
||||
with override_obj_visability(obj=target_obj, scene=scene):
|
||||
with context.temp_override(
|
||||
object=target_obj, active_object=target_obj
|
||||
):
|
||||
@ -358,7 +359,7 @@ def transfer_constraint(constraint_name, target_obj, source_obj):
|
||||
idx = target_mod_i + 1
|
||||
|
||||
if idx != i:
|
||||
with override_obj_visability(obj=target_obj):
|
||||
with override_obj_visability(obj=target_obj, scene=context.scene):
|
||||
with context.temp_override(object=target_obj):
|
||||
bpy.ops.constraint.move_to_index(
|
||||
constraint=constraint_new.name, index=idx
|
||||
|
@ -12,7 +12,14 @@ def get_visibility_driver(obj) -> Optional[bpy.types.FCurve]:
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def override_obj_visability(obj):
|
||||
def override_obj_visability(obj: bpy.types.Object, scene: bpy.types.Scene):
|
||||
"""Temporarily Change the Visability of an Object so an bpy.ops or other
|
||||
function that requires the object to be visable can be called.
|
||||
|
||||
Args:
|
||||
obj (bpy.types.Object): Object to un-hide
|
||||
scene (bpy.types.Scene): Scene Object is in
|
||||
"""
|
||||
hide = obj.hide_get() # eye icon
|
||||
hide_viewport = obj.hide_viewport # hide viewport
|
||||
select = obj.hide_select # selectable
|
||||
@ -29,9 +36,9 @@ def override_obj_visability(obj):
|
||||
driver.mute = True
|
||||
|
||||
assigned_to_scene_root = False
|
||||
if obj.name not in bpy.context.scene.collection.objects:
|
||||
if obj.name not in scene.collection.objects:
|
||||
assigned_to_scene_root = True
|
||||
bpy.context.scene.collection.objects.link(obj) # TODO Pass Current Scene
|
||||
scene.collection.objects.link(obj)
|
||||
|
||||
yield
|
||||
|
||||
@ -42,5 +49,5 @@ def override_obj_visability(obj):
|
||||
if driver:
|
||||
driver.mute = driver_mute
|
||||
|
||||
if assigned_to_scene_root and obj.name in bpy.context.scene.collection.objects:
|
||||
bpy.context.scene.collection.objects.unlink(obj) # TODO Pass Current Scene
|
||||
if assigned_to_scene_root and obj.name in scene.collection.objects:
|
||||
scene.collection.objects.unlink(obj)
|
||||
|
Loading…
Reference in New Issue
Block a user