diff --git a/net_operators.py b/net_operators.py index 2d4c5f6..06a852d 100644 --- a/net_operators.py +++ b/net_operators.py @@ -449,7 +449,7 @@ class session_draw_clients(bpy.types.Operator): self.draw2d_callback, (), 'WINDOW', 'POST_PIXEL') self.draw_event = context.window_manager.event_timer_add( - 0.1, window=context.window) + 0.01, window=context.window) def unregister_handlers(self, context): if self.draw_event and self.draw3d_handle and self.draw2d_handle: @@ -464,13 +464,37 @@ class session_draw_clients(bpy.types.Operator): self.draw2d_handle = None self.draw_event = None + # TODO: refactor this ugly things def create_batch(self): global client index = 0 + index_object = 0 for key, values in client.property_map.items(): + if values.mtype == "object": + if values.id != client.id: + 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) + ) + + ob = bpy.data.objects[values.body] + + 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] + + shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') + batch = batch_for_shader( + shader, 'LINES', {"pos": coords}, indices=indices) + + self.draw_items.append( + (shader, batch, (None,None), COLOR_TABLE[index_object])) + + index_object+=1 + if values.mtype == "client": if values.id != client.id: - indices = ( (1, 3), (2, 1), (3, 0), (2, 0) ) @@ -481,21 +505,8 @@ class session_draw_clients(bpy.types.Operator): self.draw_items.append( (shader, batch, (values.body[1], values.id.decode()), COLOR_TABLE[index])) - - index += 1 - if values.mtype == "object": - 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) - ) - - shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') - batch = batch_for_shader( - shader, 'LINES', {"pos": values.body}, indices=indices) - - self.draw_items.append( - (shader, batch, (None,None), COLOR_TABLE[index])) + index+=1 + def draw3d_callback(self): @@ -530,6 +541,7 @@ class session_draw_clients(bpy.types.Operator): session = context.scene.session_settings if client: + # Local view update current_coords = get_client_view_rect() if current_coords != self.coords: @@ -540,18 +552,25 @@ class session_draw_clients(bpy.types.Operator): # 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_modified: + for object in context.scene.objects: + # TODO: fix + try: + #TODO: function to find occurence + for k,v in client.property_map.items(): + if v.mtype == 'object': + if client.id.decode() not in k: + if object.name in v.body: + object.hide_select = True + break + + object.hide_select = False + except: + pass + + if session.active_object is not context.selected_objects[0] or session.active_object.is_evaluated : session.active_object = context.selected_objects[0] - - ob = session.active_object - - 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] - - key = "net/objects/{}".format(client.id.decode()) - client.push_update(key, 'object', coords) + client.push_update(key, 'object', session.active_object.name) # Draw clients if len(client.property_map) > 0: