From a8f96581c5e498caa72c922ef693e8afd23a5fcd Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 30 Jun 2021 15:34:03 +0200 Subject: [PATCH] fix: new mode display --- multi_user/preferences.py | 12 ++++++++++-- multi_user/presence.py | 40 ++++++++++++--------------------------- multi_user/ui.py | 9 +++++++++ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/multi_user/preferences.py b/multi_user/preferences.py index 86e8b8d..de4fba2 100644 --- a/multi_user/preferences.py +++ b/multi_user/preferences.py @@ -273,6 +273,13 @@ class SessionPrefs(bpy.types.AddonPreferences): step=1, subtype='PERCENTAGE', ) + presence_mode_distance: bpy.props.FloatProperty( + name="Distance mode visibilty", + description="Adjust the distance visibilty of user's mode", + min=0.1, + max=1000, + default=100, + ) conf_session_identity_expanded: bpy.props.BoolProperty( name="Identity", description="Identity", @@ -446,10 +453,11 @@ class SessionPrefs(bpy.types.AddonPreferences): col = box.column(align=True) col.prop(self, "presence_hud_scale", expand=True) - col.prop(self, "presence_hud_hpos", expand=True) col.prop(self, "presence_hud_vpos", expand=True) + col.prop(self, "presence_mode_distance", expand=True) + if self.category == 'UPDATE': from . import addon_updater_ops addon_updater_ops.update_settings_ui(self, context) @@ -541,7 +549,7 @@ class SessionProps(bpy.types.PropertyGroup): presence_show_mode: bpy.props.BoolProperty( name="Show users current mode", description='Enable user mode overlay ', - default=True, + default=False, ) presence_show_far_user: bpy.props.BoolProperty( name="Show users on different scenes", diff --git a/multi_user/presence.py b/multi_user/presence.py index 2825f9e..f71c8ce 100644 --- a/multi_user/presence.py +++ b/multi_user/presence.py @@ -417,6 +417,7 @@ class UserModeWidget(Widget): username): self.username = username self.settings = bpy.context.window_manager.session + self.preferences = get_preferences() @property def data(self): @@ -441,48 +442,31 @@ class UserModeWidget(Widget): self.settings.presence_show_mode and \ self.settings.enable_presence - - def draw(self): user_selection = self.data.get('selected_objects') - - B = [1000,0] - A = [1000,0] - C = [1000,0] - + location = self.data.get('view_corners') + positions = [tuple(coord) for coord in location] + viewport_coord = positions[6] for select_obj in user_selection: obj = find_from_attr("uuid", select_obj, bpy.data.objects) if not obj: return - else : - vertex_pos, vertex_indices = bbox_from_obj(obj) mode_current = self.data.get('mode_current') color = self.data.get('color') - origin_coord = project_to_screen(obj.location) - - # A upper left corner - # B lower right corner - for vertex in range(len(vertex_pos)) : - coords = project_to_screen(vertex_pos[vertex]) - if coords[0] < A[0]: - A[0] = coords[0] - if coords[1] > A[1]: - A[1] = coords[1] - if coords[0] > B[0]: - B[0] = coords[0] - if coords[1] < B[1]: - B[1] = coords[1] - - distance = math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2) - - if distance > 950 and coords : + distance_viewport_object = math.sqrt((viewport_coord[0]-obj.location[0])**2+(viewport_coord[1]-obj.location[1])**2+(viewport_coord[2]-obj.location[2])**2) + + if distance_viewport_object > self.preferences.presence_mode_distance : + return + + if origin_coord : blf.position(0, origin_coord[0]+8, origin_coord[1]-15, 0) blf.size(0, 16, 72) blf.color(0, color[0], color[1], color[2], color[3]) - blf.draw(0, mode_current) + blf.draw(0, mode_current) + class SessionStatusWidget(Widget): draw_type = 'POST_PIXEL' diff --git a/multi_user/ui.py b/multi_user/ui.py index 7b22766..919080a 100644 --- a/multi_user/ui.py +++ b/multi_user/ui.py @@ -469,6 +469,10 @@ class SESSION_PT_presence(bpy.types.Panel): row.prop(settings, "presence_show_far_user", text="",icon_only=True, icon='SCENE_DATA') col = layout.column() + if settings.presence_show_mode : + row = col.column() + row.prop(pref, "presence_mode_distance", expand=True) + col.prop(settings, "presence_show_session_status") if settings.presence_show_session_status : row = col.column() @@ -642,6 +646,10 @@ class VIEW3D_PT_overlay_session(bpy.types.Panel): row.prop(settings, "presence_show_far_user", text="",icon_only=True, icon='SCENE_DATA') col = layout.column() + if settings.presence_show_mode : + row = col.column() + row.prop(pref, "presence_mode_distance", expand=True) + col.prop(settings, "presence_show_session_status") if settings.presence_show_session_status : row = col.column() @@ -651,6 +659,7 @@ class VIEW3D_PT_overlay_session(bpy.types.Panel): row.active = settings.presence_show_session_status row.prop(pref, "presence_hud_hpos", expand=True) row.prop(pref, "presence_hud_vpos", expand=True) + classes = ( SESSION_UL_users,