fix(rcf): debug
This commit is contained in:
@ -207,7 +207,7 @@ class RCFClientAgent(object):
|
|||||||
|
|
||||||
# value = [self.property_map.get(key) for key in keys]
|
# value = [self.property_map.get(key) for key in keys]
|
||||||
# value = self.property_map.get(key)
|
# 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":
|
elif command == b"LIST":
|
||||||
self.pipe.send(umsgpack.packb(list(self.property_map)))
|
self.pipe.send(umsgpack.packb(list(self.property_map)))
|
||||||
@ -338,3 +338,4 @@ def serialization_agent(ctx, pipe):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
55
draw.py
55
draw.py
@ -79,7 +79,6 @@ class HUD(object):
|
|||||||
self.create_batch()
|
self.create_batch()
|
||||||
self.register_handlers()
|
self.register_handlers()
|
||||||
|
|
||||||
|
|
||||||
def register_handlers(self):
|
def register_handlers(self):
|
||||||
self.draw3d_handle = bpy.types.SpaceView3D.draw_handler_add(
|
self.draw3d_handle = bpy.types.SpaceView3D.draw_handler_add(
|
||||||
self.draw3d_callback, (), 'WINDOW', 'POST_VIEW')
|
self.draw3d_callback, (), 'WINDOW', 'POST_VIEW')
|
||||||
@ -107,50 +106,49 @@ class HUD(object):
|
|||||||
|
|
||||||
clients = self.client.get("Client")
|
clients = self.client.get("Client")
|
||||||
|
|
||||||
for key, values in self.client.property_map.items():
|
for client in clients:
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
if values.body['object'] in bpy.data.objects.keys():
|
# if values.mtype == "clientObject":
|
||||||
ob = bpy.data.objects[values.body['object']]
|
# indices = (
|
||||||
else:
|
# (0, 1), (1, 2), (2, 3), (0, 3),
|
||||||
return
|
# (4, 5), (5, 6), (6, 7), (4, 7),
|
||||||
bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box]
|
# (0, 4), (1, 5), (2, 6), (3, 7)
|
||||||
|
# )
|
||||||
|
|
||||||
coords = [(point.x, point.y, point.z)
|
# if values.body['object'] in bpy.data.objects.keys():
|
||||||
for point in bbox_corners]
|
# ob = bpy.data.objects[values.body['object']]
|
||||||
|
# else:
|
||||||
|
# return
|
||||||
|
# bbox_corners = [ob.matrix_world @ mathutils.Vector(corner) for corner in ob.bound_box]
|
||||||
|
|
||||||
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
# coords = [(point.x, point.y, point.z)
|
||||||
|
# for point in bbox_corners]
|
||||||
|
|
||||||
color = values.body['color']
|
# shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||||
batch = batch_for_shader(
|
|
||||||
shader, 'LINES', {"pos": coords}, indices=indices)
|
|
||||||
|
|
||||||
self.draw_items.append(
|
# color = values.body['color']
|
||||||
(shader, batch, (None, None), color))
|
# batch = batch_for_shader(
|
||||||
|
# shader, 'LINES', {"pos": coords}, indices=indices)
|
||||||
|
|
||||||
|
# self.draw_items.append(
|
||||||
|
# (shader, batch, (None, None), color))
|
||||||
|
|
||||||
# index_object += 1
|
# index_object += 1
|
||||||
|
|
||||||
if values.mtype == "client":
|
|
||||||
indices = (
|
indices = (
|
||||||
(1, 3), (2, 1), (3, 0), (2, 0)
|
(1, 3), (2, 1), (3, 0), (2, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||||
position = values.body['location']
|
position = client[1][b'location']
|
||||||
color = values.body['color']
|
color = client[1][b'color']
|
||||||
|
name = client[0].split('/')[1]
|
||||||
batch = batch_for_shader(
|
batch = batch_for_shader(
|
||||||
shader, 'LINES', {"pos": position}, indices=indices)
|
shader, 'LINES', {"pos": position}, indices=indices)
|
||||||
|
|
||||||
self.draw_items.append(
|
self.draw_items.append(
|
||||||
(shader, batch, (position[1], values.id.decode()), color))
|
(shader, batch, (position[1], name),color))
|
||||||
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
def draw3d_callback(self):
|
def draw3d_callback(self):
|
||||||
bgl.glLineWidth(3)
|
bgl.glLineWidth(3)
|
||||||
@ -186,6 +184,5 @@ class HUD(object):
|
|||||||
def draw(self):
|
def draw(self):
|
||||||
if self.client:
|
if self.client:
|
||||||
# Draw clients
|
# Draw clients
|
||||||
if len(self.client.property_map) > 1:
|
|
||||||
self.create_batch()
|
self.create_batch()
|
||||||
|
|
||||||
|
179
operators.py
179
operators.py
@ -82,6 +82,7 @@ def refresh_window():
|
|||||||
import bpy
|
import bpy
|
||||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
|
|
||||||
|
|
||||||
def upload_client_instance_position():
|
def upload_client_instance_position():
|
||||||
global client_instance
|
global client_instance
|
||||||
|
|
||||||
@ -111,6 +112,7 @@ def upload_client_instance_position():
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_selected_object(context):
|
def update_selected_object(context):
|
||||||
global client_instance
|
global client_instance
|
||||||
session = bpy.context.scene.session_settings
|
session = bpy.context.scene.session_settings
|
||||||
@ -151,142 +153,6 @@ def init_datablocks():
|
|||||||
print(key)
|
print(key)
|
||||||
client_instance.set(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():
|
def default_tick():
|
||||||
|
|
||||||
@ -312,47 +178,21 @@ def default_tick():
|
|||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# print("pull error: {}".format(e))
|
# print("pull error: {}".format(e))
|
||||||
|
|
||||||
# bpy.ops.session.refresh()
|
bpy.ops.session.refresh()
|
||||||
# global client_instance
|
# global client_instance
|
||||||
|
|
||||||
# if not client_instance.queue.empty():
|
# if not client_instance.queue.empty():
|
||||||
# update = client_instance.queue.get()
|
# update = client_instance.queue.get()
|
||||||
# helpers.load(update[0],update[1])
|
# helpers.load(update[0],update[1])
|
||||||
|
|
||||||
return 0.001
|
return 0.5
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def draw_tick():
|
def draw_tick():
|
||||||
# drawing
|
# drawing
|
||||||
# global drawer
|
global drawer
|
||||||
|
|
||||||
# drawer.draw()
|
drawer.draw()
|
||||||
|
|
||||||
# Upload
|
# Upload
|
||||||
upload_client_instance_position()
|
upload_client_instance_position()
|
||||||
@ -369,8 +209,8 @@ def register_ticks():
|
|||||||
|
|
||||||
def unregister_ticks():
|
def unregister_ticks():
|
||||||
# REGISTER Updaters
|
# REGISTER Updaters
|
||||||
# global drawer
|
global drawer
|
||||||
# drawer.unregister_handlers()
|
drawer.unregister_handlers()
|
||||||
bpy.app.timers.unregister(draw_tick)
|
bpy.app.timers.unregister(draw_tick)
|
||||||
# bpy.app.timers.unregister(mesh_tick)
|
# bpy.app.timers.unregister(mesh_tick)
|
||||||
# bpy.app.timers.unregister(object_tick)
|
# bpy.app.timers.unregister(object_tick)
|
||||||
@ -409,8 +249,7 @@ class session_join(bpy.types.Operator):
|
|||||||
|
|
||||||
|
|
||||||
# net_settings.is_running = True
|
# net_settings.is_running = True
|
||||||
|
drawer = draw.HUD(client_instance=client_instance)
|
||||||
# drawer = net_draw.HUD(client_instance_instance=client_instance)
|
|
||||||
|
|
||||||
register_ticks()
|
register_ticks()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
@ -73,6 +73,7 @@ class RCFServerAgent():
|
|||||||
|
|
||||||
client_dict = {}
|
client_dict = {}
|
||||||
client_dict['location'] = [0,0,0]
|
client_dict['location'] = [0,0,0]
|
||||||
|
client_dict['color'] = [0,0,0]
|
||||||
client_dict['active_object'] = ''
|
client_dict['active_object'] = ''
|
||||||
client_store = message.RCFMessage(key=client_key, id=identity,body=client_dict)
|
client_store = message.RCFMessage(key=client_key, id=identity,body=client_dict)
|
||||||
logger.info(client_store)
|
logger.info(client_store)
|
||||||
|
Reference in New Issue
Block a user