Asset Pipeline v2 #145
46
scripts-blender/addons/asset_pipeline_2/visability.py
Normal file
46
scripts-blender/addons/asset_pipeline_2/visability.py
Normal file
@ -0,0 +1,46 @@
|
||||
import bpy
|
||||
import contextlib
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def get_visibility_driver(obj) -> Optional[bpy.types.FCurve]:
|
||||
obj = bpy.data.objects.get(obj.name)
|
||||
assert obj, "Object was renamed while its visibility was being ensured?"
|
||||
if hasattr(obj, "animation_data") and obj.animation_data:
|
||||
return obj.animation_data.drivers.find("hide_viewport")
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def override_obj_visability(obj):
|
||||
hide = obj.hide_get() # eye icon
|
||||
hide_viewport = obj.hide_viewport # hide viewport
|
||||
select = obj.hide_select # selectable
|
||||
|
||||
driver = get_visibility_driver(obj)
|
||||
if driver:
|
||||
driver_mute = driver.mute
|
||||
|
||||
try:
|
||||
obj.hide_set(False)
|
||||
obj.hide_viewport = False
|
||||
obj.hide_select = False
|
||||
if driver:
|
||||
driver.mute = True
|
||||
|
||||
assigned_to_scene_root = False
|
||||
if obj.name not in bpy.context.scene.collection.objects:
|
||||
assigned_to_scene_root = True
|
||||
bpy.context.scene.collection.objects.link(obj) # TODO Pass Current Scene
|
||||
|
||||
yield
|
||||
|
||||
finally:
|
||||
obj.hide_set(hide)
|
||||
obj.hide_viewport = hide_viewport
|
||||
obj.hide_select = select
|
||||
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
|
Loading…
Reference in New Issue
Block a user