def stop(self): """Disconnect from Unity and cleanup synced objects""" if not self.is_running(): return log('DCC teardown') self.lib.Disconnect() self.lib.Clear() # Clear local tracking self.objects = set() self.has_metaballs = False # Turning off `running` will also destroy the `on_tick` timer. self.running = False if self.on_depsgraph_update in depsgraph_update_post: depsgraph_update_post.remove(self.on_depsgraph_update) if self.on_load_pre in load_pre: load_pre.remove(self.on_load_pre) if self.image_editor_handle: bpy.types.SpaceImageEditor.draw_handler_remove( self.image_editor_handle, 'WINDOW') self.image_editor_handle = None self.tag_redraw_viewports()
def unregister(): """! Unload the Python classes and functions from Blender. """ log.debug(f"Unregistering handlers") load_post.remove(_load_post) save_pre.remove(_save_pre) depsgraph_update_post.remove(_depsgraph_update_post)
def RemoveHandler(): #Scene upate handler if handler_key in driver_namespace: if driver_namespace[handler_key] in frame_change_post: frame_change_post.remove(driver_namespace[handler_key]) #print("Handler Removed") if driver_namespace[handler_key] in depsgraph_update_post: depsgraph_update_post.remove(driver_namespace[handler_key]) #print("Handler Removed") del driver_namespace[handler_key]
def stop(self): """Disconnect from Unity and cleanup sycned objects""" log('DCC teardown') self.lib.Disconnect() self.lib.Clear() # Turning off `running` will also destroy the `on_tick` timer. self.running = False if self.on_depsgraph_update in depsgraph_update_post: depsgraph_update_post.remove(self.on_depsgraph_update) # Untrack everything in the scene - we'll have to re-track it all on start() again. self.object_ids = set()
def scene_load_post(_): def convert(id, *prop_groups): prop_map = { "export_path": "path", "engine_path": "studiomdl_custom_path", "export_format": "format" } for p_g in prop_groups: for prop in [ prop for prop in p_g.__dict__.keys() if prop[0] != '_' ]: val = id.get("smd_" + (prop_map[prop] if prop in prop_map else prop)) if val != None: id.vs[prop] = val for prop in id.keys(): if prop.startswith("smd_"): del id[prop] for s in bpy.data.scenes: if hasattr(s, "vs"): convert(s, ValveSource_SceneProps) game_path_changed(s, bpy.context) engine_path_changed(s, bpy.context) for ob in bpy.data.objects: convert(ob, ValveSource_ObjectProps, ExportableProps) for a in bpy.data.armatures: convert(a, ValveSource_ArmatureProps) for g in bpy.data.collections: convert(g, ValveSource_CollectionProps, ExportableProps) for c in bpy.data.curves: convert(c, ValveSource_CurveProps, ShapeTypeProps) for m in bpy.data.meshes: convert(m, ValveSource_MeshProps, ShapeTypeProps) for vert_map in m.vertex_colors: if vert_map.name == "ValveSource_VertexPaintTintColor": vert_map.name = "valvesource_vertex_paint" elif vert_map.name == "ValveSource_VertexPaintBlendParams": vert_map.name = "valvesource_vertex_blend" elif vert_map.name == "ValveSource_VertexPaintBlendParams.001": vert_map.name = "valvesource_vertex_blend1" if scene_load_post in depsgraph_update_post: depsgraph_update_post.remove(scene_load_post)
def unhook_scene_update(): if scene_update in depsgraph_update_post: depsgraph_update_post.remove(scene_update)
for file_path in [ os.path.join("modules","datamodel.py"), os.path.join("addons","io_smd_tools.py") ]: try: os.remove(os.path.abspath(os.path.join(script_path,file_path))) except: pass # Python doesn't reload package sub-modules at the same time as __init__.py! import imp, sys for filename in [ f for f in os.listdir(os.path.dirname(os.path.realpath(__file__))) if f.endswith(".py") ]: if filename == os.path.basename(__file__): continue mod = sys.modules.get("{}.{}".format(__name__,filename[:-3])) if mod: imp.reload(mod) # clear out any scene update funcs hanging around, e.g. after a script reload from bpy.app.handlers import depsgraph_update_pre, depsgraph_update_post for func in depsgraph_update_post: if func.__module__.startswith(__name__): depsgraph_update_post.remove(func) from . import datamodel, import_smd, export_smd, flex, GUI, update from .utils import * class ValveSource_Exportable(bpy.types.PropertyGroup): ob_type : StringProperty() icon : StringProperty() item_name : StringProperty() def get_id(self): try: if self.ob_type == 'COLLECTION': return bpy.data.collections[self.item_name] if self.ob_type in ['ACTION', 'OBJECT']: return bpy.data.objects[self.item_name]
def unregister(): depsgraph_update_pre.remove(pre.depsgraph) depsgraph_update_post.remove(post.depsgraph) load_pre.remove(pre.load) load_post.remove(post.load) save_pre.remove(pre.save)
def stop(cls): # stop monitor changes if cls.on_depsgraph_update in depsgraph_update_post: depsgraph_update_post.remove(cls.on_depsgraph_update)