fix(rcf): debug

This commit is contained in:
Swann Martinez 2019-04-15 16:21:50 +02:00
parent b43e182094
commit c649f8fe8f
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
4 changed files with 45 additions and 207 deletions

View File

@ -207,7 +207,7 @@ class RCFClientAgent(object):
# value = [self.property_map.get(key) for key in keys]
# value = self.property_map.get(key)
self.pipe.send(umsgpack.packb(value) if value else b'')
self.pipe.send(umsgpack.packb(value) if value else umsgpack.packb(''))
elif command == b"LIST":
self.pipe.send(umsgpack.packb(list(self.property_map)))
@ -338,3 +338,4 @@ def serialization_agent(ctx, pipe):

69
draw.py
View File

@ -79,7 +79,6 @@ class HUD(object):
self.create_batch()
self.register_handlers()
def register_handlers(self):
self.draw3d_handle = bpy.types.SpaceView3D.draw_handler_add(
self.draw3d_callback, (), 'WINDOW', 'POST_VIEW')
@ -107,50 +106,49 @@ class HUD(object):
clients = self.client.get("Client")
for key, values in self.client.property_map.items():
if 'net' in key and values.body is not None and values.id != self.client.id:
if values.mtype == "clientObject":
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)
)
for client in clients:
# if values.mtype == "clientObject":
# 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 values.body['object'] in bpy.data.objects.keys():
ob = bpy.data.objects[values.body['object']]
else:
return
bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box]
# if values.body['object'] in bpy.data.objects.keys():
# ob = bpy.data.objects[values.body['object']]
# else:
# return
# 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 = values.body['color']
batch = batch_for_shader(
shader, 'LINES', {"pos": coords}, indices=indices)
# color = values.body['color']
# batch = batch_for_shader(
# shader, 'LINES', {"pos": coords}, indices=indices)
self.draw_items.append(
(shader, batch, (None, None), color))
# self.draw_items.append(
# (shader, batch, (None, None), color))
# index_object += 1
if values.mtype == "client":
indices = (
(1, 3), (2, 1), (3, 0), (2, 0)
)
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
position = values.body['location']
color = values.body['color']
batch = batch_for_shader(
shader, 'LINES', {"pos": position}, indices=indices)
indices = (
(1, 3), (2, 1), (3, 0), (2, 0)
)
self.draw_items.append(
(shader, batch, (position[1], values.id.decode()), color))
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
position = client[1][b'location']
color = client[1][b'color']
name = client[0].split('/')[1]
batch = batch_for_shader(
shader, 'LINES', {"pos": position}, indices=indices)
index += 1
self.draw_items.append(
(shader, batch, (position[1], name),color))
def draw3d_callback(self):
bgl.glLineWidth(3)
@ -186,6 +184,5 @@ class HUD(object):
def draw(self):
if self.client:
# Draw clients
if len(self.client.property_map) > 1:
self.create_batch()
self.create_batch()

View File

@ -82,6 +82,7 @@ def refresh_window():
import bpy
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
def upload_client_instance_position():
global client_instance
@ -111,6 +112,7 @@ def upload_client_instance_position():
except:
pass
def update_selected_object(context):
global client_instance
session = bpy.context.scene.session_settings
@ -151,142 +153,6 @@ def init_datablocks():
print(key)
client_instance.set(key)
def update_scene(msg):
global client_instance
net_vars = bpy.context.scene.session_settings
pull_tasks.put(msg.key)
# if net_vars.active_object:
# if net_vars.active_object.name in msg.key:
# raise ValueError()
# if 'net' not in msg.key:
# target = resolve_bpy_path(msg.key)
# if target:
# target.is_updating = True
# if msg.mtype == 'Object':
# load_object(target=target, data=msg.body,
# create=net_vars.load_data)
# global drawer
# drawer.draw()
# elif msg.mtype == 'Mesh':
# load_mesh(target=target, data=msg.body,
# create=net_vars.load_data)
# elif msg.mtype == 'Collection':
# load_collection(target=target, data=msg.body,
# create=net_vars.load_data)
# elif msg.mtype == 'Material':
# load_material(target=target, data=msg.body,
# create=net_vars.load_data)
# elif msg.mtype == 'Grease Pencil':
# load_gpencil(target=target, data=msg.body,
# create=net_vars.load_data)
# elif msg.mtype == 'Scene':
# load_scene(target=target, data=msg.body,
# create=net_vars.load_data)
# elif 'Light' in msg.mtype:
# load_light(target=target, data=msg.body,
# create=net_vars.load_data)
# else:
# load_default(target=target, data=msg.body,
# create=net_vars.load_data, type=msg.mtype)
# else:
# if msg.mtype == 'client_instance':
# refresh_window()
# elif msg.mtype == 'client_instanceObject':
# selected_objects = []
# for k, v in client_instance.property_map.items():
# if v.mtype == 'client_instanceObject':
# if client_instance.id != v.id:
# selected_objects.append(v.body['object'])
# for obj in bpy.data.objects:
# if obj.name in selected_objects:
# obj.hide_select = True
# else:
# obj.hide_select = False
# refresh_window()
def push(data_type,id):
if data_type == 'Material':
upload_material(bpy.data.materials[id])
if data_type == 'Grease Pencil':
upload_gpencil(bpy.data.grease_pencils[id])
if data_type == 'Camera':
dump_datablock(bpy.data.cameras[id], 1)
if data_type == 'Light':
dump_datablock(bpy.data.lights[id], 1)
if data_type == 'Mesh':
upload_mesh(bpy.data.meshes[id])
if data_type == 'Object':
dump_datablock(bpy.data.objects[id], 1)
if data_type == 'Collection':
dump_datablock(bpy.data.collections[id], 4)
if data_type == 'Scene':
dump_datablock(bpy.data.scenes[id], 4)
def pull(keystore):
global client_instance
net_vars = bpy.context.scene.session_settings
body = client_instance.property_map[keystore].body
data_type = client_instance.property_map[keystore].mtype
target = resolve_bpy_path(keystore)
if target:
target.is_updating = True
if data_type == 'Object':
load_object(target=target, data=body,
create=net_vars.load_data)
global drawer
drawer.draw()
elif data_type == 'Mesh':
load_mesh(target=target, data=body,
create=net_vars.load_data)
elif data_type == 'Collection':
load_collection(target=target, data=body,
create=net_vars.load_data)
elif data_type == 'Material':
load_material(target=target, data=body,
create=net_vars.load_data)
elif data_type == 'Grease Pencil':
load_gpencil(target=target, data=body,
create=net_vars.load_data)
elif data_type == 'Scene':
load_scene(target=target, data=body,
create=net_vars.load_data)
elif 'Light' in data_type:
load_light(target=target, data=body,
create=net_vars.load_data)
elif data_type == 'Camera':
load_default(target=target, data=body,
create=net_vars.load_data, type=mtype)
elif data_type == 'client_instance':
refresh_window()
elif data_type == 'client_instanceObject':
selected_objects = []
for k, v in client_instance.property_map.items():
if v.mtype == 'client_instanceObject':
if client_instance.id != v.id:
selected_objects.append(v.body['object'])
for obj in bpy.data.objects:
if obj.name in selected_objects:
obj.hide_select = True
else:
obj.hide_select = False
refresh_window()
recv_callbacks = [update_scene]
post_init_callbacks = [refresh_window]
def default_tick():
@ -312,47 +178,21 @@ def default_tick():
# except Exception as e:
# print("pull error: {}".format(e))
# bpy.ops.session.refresh()
bpy.ops.session.refresh()
# global client_instance
# if not client_instance.queue.empty():
# update = client_instance.queue.get()
# helpers.load(update[0],update[1])
return 0.001
def mesh_tick():
mesh = get_update("Mesh")
if mesh:
upload_mesh(bpy.data.meshes[mesh])
return 2
def object_tick():
obj_name = get_update("Object")
global client_instance
if obj_name:
if "Object/{}".format(obj_name) in client_instance.property_map.keys():
dump_datablock_attibute(bpy.data.objects[obj_name], ['matrix_world'])
else:
dump_datablock(bpy.data.objects[obj_name], 1)
return 0.1
def material_tick():
return 2
return 0.5
def draw_tick():
# drawing
# global drawer
global drawer
# drawer.draw()
drawer.draw()
# Upload
upload_client_instance_position()
@ -369,8 +209,8 @@ def register_ticks():
def unregister_ticks():
# REGISTER Updaters
# global drawer
# drawer.unregister_handlers()
global drawer
drawer.unregister_handlers()
bpy.app.timers.unregister(draw_tick)
# bpy.app.timers.unregister(mesh_tick)
# bpy.app.timers.unregister(object_tick)
@ -409,8 +249,7 @@ class session_join(bpy.types.Operator):
# net_settings.is_running = True
# drawer = net_draw.HUD(client_instance_instance=client_instance)
drawer = draw.HUD(client_instance=client_instance)
register_ticks()
return {"FINISHED"}

View File

@ -73,6 +73,7 @@ class RCFServerAgent():
client_dict = {}
client_dict['location'] = [0,0,0]
client_dict['color'] = [0,0,0]
client_dict['active_object'] = ''
client_store = message.RCFMessage(key=client_key, id=identity,body=client_dict)
logger.info(client_store)