From fcf4604153512a64fa36808e9b35011b484acc2b Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Fri, 24 Jan 2020 17:52:10 +0100 Subject: [PATCH] feat: deps graph update handler --- multi_user/operators.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/multi_user/operators.py b/multi_user/operators.py index f5220db..f5ff741 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -473,6 +473,39 @@ def update_client_frame(scene): 'frame_current': scene.frame_current }) +@persistent +def depsgraph_evaluation(scene): + if client and client.state == STATE_ACTIVE: + context = bpy.context + blender_depsgraph = bpy.context.view_layer.depsgraph + dependency_updates = [u for u in blender_depsgraph.updates] + session_infos = bpy.context.window_manager.session + + # NOTE: maybe we don't need to check each update but only the first + # thanks to our deps graph.... + + for update in reversed(dependency_updates): + # Is the object tracked ? + if update.id.uuid: + # Retrieve local version + node = client.get(update.id.uuid) + + # Check our right on this update: + # - if its ours or ( under common and diff), launch the + # update process + # - if its to someone else, ignore the update (go deeper ?) + if node.owner == session_infos.username: + # Avoid slow geometry update + if 'EDIT' in context.mode: + break + logger.error("UPDATE: MODIFIFY {}".format(type(update.id))) + else: + # Distant update + continue + # else: + # # New items ! + # logger.error("UPDATE: ADD")C.obj + def register(): from bpy.utils import register_class @@ -486,6 +519,8 @@ def register(): bpy.app.handlers.frame_change_pre.append(update_client_frame) + bpy.app.handlers.depsgraph_update_post.append(depsgraph_evaluation) + def unregister(): global client @@ -505,6 +540,8 @@ def unregister(): bpy.app.handlers.frame_change_pre.remove(update_client_frame) + bpy.app.handlers.depsgraph_update_post.remove(depsgraph_evaluation) + if __name__ == "__main__": register()