feat: selected object highlight is back
This commit is contained in:
@ -23,6 +23,7 @@ class BlUser(BlDatablock):
|
|||||||
def load(self, data, target):
|
def load(self, data, target):
|
||||||
target.name = data['name']
|
target.name = data['name']
|
||||||
target.location = data['location']
|
target.location = data['location']
|
||||||
|
target.selected_objects = data['selected_objects']
|
||||||
utils.dump_anything.load(target, data)
|
utils.dump_anything.load(target, data)
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
@ -36,12 +37,14 @@ class BlUser(BlDatablock):
|
|||||||
#TODO: refactor in order to redraw in cleaner ways
|
#TODO: refactor in order to redraw in cleaner ways
|
||||||
if presence.renderer:
|
if presence.renderer:
|
||||||
presence.renderer.draw_client_camera(self.buffer['name'], self.buffer['location'],self.buffer['color'])
|
presence.renderer.draw_client_camera(self.buffer['name'], self.buffer['location'],self.buffer['color'])
|
||||||
|
presence.renderer.draw_client_selection(self.buffer['name'], self.buffer['color'],self.buffer['selected_objects'])
|
||||||
|
|
||||||
|
|
||||||
def dump(self,pointer=None):
|
def dump(self,pointer=None):
|
||||||
data = utils.dump_anything.dump(pointer)
|
data = utils.dump_anything.dump(pointer)
|
||||||
data['location'] = pointer.location
|
data['location'] = pointer.location
|
||||||
data['color'] = pointer.color
|
data['color'] = pointer.color
|
||||||
|
data['selected_objects'] = pointer.selected_objects
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,3 +101,4 @@ class ClientUpdate(Draw):
|
|||||||
|
|
||||||
if client:
|
if client:
|
||||||
client.pointer.update_location()
|
client.pointer.update_location()
|
||||||
|
client.pointer.update_selected_objects(bpy.context)
|
||||||
|
42
presence.py
42
presence.py
@ -11,7 +11,8 @@ import math
|
|||||||
from bpy_extras import view3d_utils
|
from bpy_extras import view3d_utils
|
||||||
from gpu_extras.batch import batch_for_shader
|
from gpu_extras.batch import batch_for_shader
|
||||||
|
|
||||||
# from .libs import debug
|
from . import utils
|
||||||
|
from .libs import debug
|
||||||
# from .bl_types.bl_user import BlUser
|
# from .bl_types.bl_user import BlUser
|
||||||
# from .delayable import Draw
|
# from .delayable import Draw
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ class User():
|
|||||||
self.name = username
|
self.name = username
|
||||||
self.color = color
|
self.color = color
|
||||||
self.location = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
|
self.location = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
|
||||||
self.active_object = ""
|
self.selected_objects = []
|
||||||
|
|
||||||
def update_location(self):
|
def update_location(self):
|
||||||
current_coords = get_client_cam_points()
|
current_coords = get_client_cam_points()
|
||||||
@ -104,24 +105,8 @@ class User():
|
|||||||
if current_coords:
|
if current_coords:
|
||||||
self.location = list(current_coords)
|
self.location = list(current_coords)
|
||||||
|
|
||||||
def update_client_selected_object(self, context):
|
def update_selected_objects(self, context):
|
||||||
session = bpy.context.window_manager.session
|
self.selected_objects = utils.get_selected_objects(context.scene)
|
||||||
username = bpy.context.window_manager.session.username
|
|
||||||
# client_data = client.get(client_key)
|
|
||||||
|
|
||||||
selected_objects = utils.get_selected_objects(context.scene)
|
|
||||||
if len(selected_objects) > 0 and len(client_data) > 0:
|
|
||||||
|
|
||||||
for obj in selected_objects:
|
|
||||||
# if obj not in client_data[0][1]['active_objects']:
|
|
||||||
client_data[0][1]['active_objects'] = selected_objects
|
|
||||||
|
|
||||||
client.set(client_key, client_data[0][1])
|
|
||||||
break
|
|
||||||
|
|
||||||
elif client_data and client_data[0][1]['active_objects']:
|
|
||||||
client_data[0][1]['active_objects'] = []
|
|
||||||
client.set(client_key, client_data[0][1])
|
|
||||||
|
|
||||||
|
|
||||||
class DrawFactory(object):
|
class DrawFactory(object):
|
||||||
@ -161,22 +146,21 @@ class DrawFactory(object):
|
|||||||
self.d3d_items.clear()
|
self.d3d_items.clear()
|
||||||
self.d2d_items.clear()
|
self.d2d_items.clear()
|
||||||
|
|
||||||
def draw_client_selected_objects(self, client):
|
def draw_client_selection(self, client_uuid, client_color, client_selection):
|
||||||
if client:
|
|
||||||
name = client['id']
|
|
||||||
local_username = bpy.context.window_manager.session.username
|
local_username = bpy.context.window_manager.session.username
|
||||||
|
|
||||||
if name != local_username:
|
|
||||||
key_to_remove = []
|
key_to_remove = []
|
||||||
for k in self.d3d_items.keys():
|
for k in self.d3d_items.keys():
|
||||||
if "{}/".format(client['id']) in k:
|
if "{}_select".format(client_uuid) in k:
|
||||||
key_to_remove.append(k)
|
key_to_remove.append(k)
|
||||||
|
|
||||||
for k in key_to_remove:
|
for k in key_to_remove:
|
||||||
del self.d3d_items[k]
|
del self.d3d_items[k]
|
||||||
|
|
||||||
if client['active_objects']:
|
if client_selection:
|
||||||
for select_ob in client['active_objects']:
|
|
||||||
|
for select_ob in client_selection:
|
||||||
|
drawable_key = "{}_select_{}".format(client_uuid, select_ob)
|
||||||
indices = (
|
indices = (
|
||||||
(0, 1), (1, 2), (2, 3), (0, 3),
|
(0, 1), (1, 2), (2, 3), (0, 3),
|
||||||
(4, 5), (5, 6), (6, 7), (4, 7),
|
(4, 5), (5, 6), (6, 7), (4, 7),
|
||||||
@ -194,10 +178,10 @@ class DrawFactory(object):
|
|||||||
coords = [(point.x, point.y, point.z)
|
coords = [(point.x, point.y, point.z)
|
||||||
for point in bbox_corners]
|
for point in bbox_corners]
|
||||||
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||||
color = client['color']
|
color = client_color
|
||||||
batch = batch_for_shader(
|
batch = batch_for_shader(
|
||||||
shader, 'LINES', {"pos": coords}, indices=indices)
|
shader, 'LINES', {"pos": coords}, indices=indices)
|
||||||
drawable_key = "{}/{}".format(client['id'], select_ob)
|
|
||||||
|
|
||||||
self.d3d_items[drawable_key] = (shader, batch, color)
|
self.d3d_items[drawable_key] = (shader, batch, color)
|
||||||
|
|
||||||
|
7
utils.py
7
utils.py
@ -71,12 +71,7 @@ def get_armature_edition_context(armature):
|
|||||||
|
|
||||||
|
|
||||||
def get_selected_objects(scene):
|
def get_selected_objects(scene):
|
||||||
selected_objects = []
|
return [obj.name for obj in scene.objects if obj.select_get()]
|
||||||
for obj in scene.objects:
|
|
||||||
if obj.select_get():
|
|
||||||
selected_objects.append(obj.name)
|
|
||||||
|
|
||||||
return selected_objects
|
|
||||||
|
|
||||||
def load_dict(src_dict, target):
|
def load_dict(src_dict, target):
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user