From 331b8794da004966b3def5f335ff719623ed274b Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Thu, 18 Apr 2019 16:10:55 +0200 Subject: [PATCH] feat(rcf): bring back selected object lock --- draw.py | 44 ++++++++++++++++++++------------------- helpers.py | 15 ++++++------- operators.py | 59 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 70 insertions(+), 48 deletions(-) diff --git a/draw.py b/draw.py index 38e47f3..5ae9e9a 100644 --- a/draw.py +++ b/draw.py @@ -108,34 +108,36 @@ class HUD(object): name = client[0].split('/')[1] local_username = bpy.context.scene.session_settings.username - if name != local_username and client[1]['active_objects']: - for select_ob in client[1]['active_objects']: - indices = ( - (0, 1), (1, 2), (2, 3), (0, 3), - (4, 5), (5, 6), (6, 7), (4, 7), - (0, 4), (1, 5), (2, 6), (3, 7) - ) + if name != local_username: + if client[1]['active_objects']: + for select_ob in client[1]['active_objects']: + indices = ( + (0, 1), (1, 2), (2, 3), (0, 3), + (4, 5), (5, 6), (6, 7), (4, 7), + (0, 4), (1, 5), (2, 6), (3, 7) + ) - if select_ob in bpy.data.objects.keys(): - ob = bpy.data.objects[select_ob] - else: - return + if select_ob in bpy.data.objects.keys(): + ob = bpy.data.objects[select_ob] + else: + return - bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box] + bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box] - coords = [(point.x, point.y, point.z) - for point in bbox_corners] + coords = [(point.x, point.y, point.z) + for point in bbox_corners] - shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') + shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') - color = client[1]['color'] + color = client[1]['color'] - batch = batch_for_shader( - shader, 'LINES', {"pos": coords}, indices=indices) - - self.d3d_items["{}/{}".format(client[0], - select_ob)] = (shader, batch, color) + batch = batch_for_shader( + shader, 'LINES', {"pos": coords}, indices=indices) + self.d3d_items["{}/{}".format(client[0], + select_ob)] = (shader, batch, color) + else: + self.d3d_items.clear() def draw_clients(self): clients = self.client.get("Client") diff --git a/helpers.py b/helpers.py index 3ac50d3..aef6c0e 100644 --- a/helpers.py +++ b/helpers.py @@ -78,14 +78,15 @@ def load_client(client=None, data=None): # localy_selected = get_selected_objects(C.scene) # Draw client + client_data = data # Load selected object - if data['active_objects']: - for obj in C.scene.objects: - if obj.name in data['active_objects']: - D.objects[obj.name].hide_select = True - else: - D.objects[obj.name].hide_select = False - pass + for obj in C.scene.objects: + if client_data['active_objects'] and obj.name in client_data['active_objects']: + D.objects[obj.name].hide_select = True + else: + D.objects[obj.name].hide_select = False + + def load_mesh(target=None, data=None, create=False): diff --git a/operators.py b/operators.py index 2041d6b..cb7e8ca 100644 --- a/operators.py +++ b/operators.py @@ -84,31 +84,48 @@ def update_selected_object(context): global client_instance session = bpy.context.scene.session_settings + username = bpy.context.scene.session_settings.username + client_key = "Client/{}".format(username) + client_data = client_instance.get(client_key) + # Active object bounding box if len(context.selected_objects) > 0: - if session.active_object is not context.selected_objects[0] or session.active_object.is_evaluated: - session.active_object = context.selected_objects[0] - key = "net/objects/{}".format(client_instance.id.decode()) - data = {} - data['color'] = [session.client_instance_color.r, - session.client_instance_color.g, session.client_instance_color.b] - data['object'] = session.active_object.name - client_instance.push_update( - key, 'client_instanceObject', data) + - return True - elif len(context.selected_objects) == 0 and session.active_object: - session.active_object = None - data = {} - data['color'] = [session.client_instance_color.r, - session.client_instance_color.g, session.client_instance_color.b] - data['object'] = None - key = "net/objects/{}".format(client_instance.id.decode()) - client_instance.push_update(key, 'client_instanceObject', data) + for obj in context.selected_objects: + if obj.name not in client_data[0][1]['active_objects']: + client_data[0][1]['active_objects'] = helpers.get_selected_objects(context.scene) - return True + client_instance.set(client_key,client_data[0][1]) + break + elif client_data[0][1]['active_objects']: + client_data[0][1]['active_objects'] = [] + client_instance.set(client_key,client_data[0][1]) + - return False + # if session.active_object is not context.selected_objects[0] or session.active_object.is_evaluated: + # session.active_object = context.selected_objects[0] + # key = "net/objects/{}".format(client_instance.id.decode()) + # data = {} + # data['color'] = [session.client_instance_color.r, + # session.client_instance_color.g, session.client_instance_color.b] + # data['object'] = session.active_object.name + # client_instance.push_update( + # key, 'client_instanceObject', data) + + # return True + # elif len(context.selected_objects) == 0 and session.active_object: + # session.active_object = None + # data = {} + # data['color'] = [session.client_instance_color.r, + # session.client_instance_color.g, session.client_instance_color.b] + # data['object'] = None + # key = "net/objects/{}".format(client_instance.id.decode()) + # client_instance.push_update(key, 'client_instanceObject', data) + + # return True + + # return False def init_datablocks(): @@ -447,6 +464,8 @@ def depsgraph_update(scene): if client_instance and client_instance.agent.is_alive(): updates = bpy.context.depsgraph.updates + update_selected_object(bpy.context) + if is_dirty(updates): for update in ordered(updates): if update[2] == "Master Collection":