feat(rcf): bring back selected object lock

This commit is contained in:
Swann Martinez 2019-04-18 16:10:55 +02:00
parent 91611f01e2
commit 331b8794da
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
3 changed files with 70 additions and 48 deletions

44
draw.py
View File

@ -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")

View File

@ -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):

View File

@ -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":