feat(client): append init datablocks functions tu test blender lock
This commit is contained in:
parent
5e7ac95228
commit
0caf529a59
46
client.py
46
client.py
@ -81,6 +81,12 @@ class RCFClient(object):
|
||||
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
||||
id, str) else id), (address.encode() if isinstance(
|
||||
address, str) else address), b'%d' % port])
|
||||
def init(self):
|
||||
"""Set new value in distributed hash table
|
||||
Sends [SET][key][value] to the agent
|
||||
"""
|
||||
self.pipe.send_multipart(
|
||||
[b"INIT"])
|
||||
|
||||
def set(self, key, value=None, override=False):
|
||||
"""Set new value in distributed hash table
|
||||
@ -183,6 +189,20 @@ class RCFClientAgent(object):
|
||||
# target=serialization_agent, args=(self.ctx, peer), name="serial-agent")
|
||||
# self.serial_agent.daemon = True
|
||||
# self.serial_agent.start()
|
||||
def _add(self,key, value='None'):
|
||||
if value == 'None':
|
||||
# try to dump from bpy
|
||||
# logging.info(key)
|
||||
value = helpers.dump(key)
|
||||
value['id'] = self.id.decode()
|
||||
if value:
|
||||
rcfmsg = message.RCFMessage(
|
||||
key=key, id=self.id, body=value)
|
||||
|
||||
rcfmsg.store(self.property_map)
|
||||
rcfmsg.send(self.publisher)
|
||||
else:
|
||||
logger.error("Fail to dump ")
|
||||
|
||||
def control_message(self):
|
||||
msg = self.pipe.recv_multipart()
|
||||
@ -232,6 +252,10 @@ class RCFClientAgent(object):
|
||||
else:
|
||||
helpers.load(key,self.property_map[key].body)
|
||||
|
||||
elif command == b"INIT":
|
||||
d = helpers.get_all_datablocks()
|
||||
for i in d:
|
||||
self._add(i)
|
||||
|
||||
elif command == b"ADD":
|
||||
key = umsgpack.unpackb(msg[0])
|
||||
@ -367,19 +391,19 @@ def rcf_client_agent(ctx, pipe, queue):
|
||||
logger.debug("{} nothing to do".format(agent.id))
|
||||
|
||||
# LOCAL SYNC
|
||||
if not update_queue.empty():
|
||||
key = update_queue.get()
|
||||
# if not update_queue.empty():
|
||||
# key = update_queue.get()
|
||||
|
||||
value = helpers.dump(key)
|
||||
value['id'] = agent.id.decode()
|
||||
if value:
|
||||
rcfmsg = message.RCFMessage(
|
||||
key=key, id=agent.id, body=value)
|
||||
# value = helpers.dump(key)
|
||||
# value['id'] = agent.id.decode()
|
||||
# if value:
|
||||
# rcfmsg = message.RCFMessage(
|
||||
# key=key, id=agent.id, body=value)
|
||||
|
||||
rcfmsg.store(agent.property_map)
|
||||
rcfmsg.send(agent.publisher)
|
||||
else:
|
||||
logger.error("Fail to dump ")
|
||||
# rcfmsg.store(agent.property_map)
|
||||
# rcfmsg.send(agent.publisher)
|
||||
# else:
|
||||
# logger.error("Fail to dump ")
|
||||
|
||||
|
||||
|
||||
|
13
helpers.py
13
helpers.py
@ -7,6 +7,9 @@ import logging
|
||||
CORRESPONDANCE = {'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials',
|
||||
'Texture': 'textures', 'Scene': 'scenes', 'Light': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'}
|
||||
|
||||
SUPPORTED_TYPES = ['Material',
|
||||
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Armature', 'Collection', 'Scene']
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# UTILITY FUNCTIONS
|
||||
@ -23,7 +26,15 @@ def get_selected_objects(scene):
|
||||
|
||||
return selected_objects
|
||||
|
||||
|
||||
def get_all_datablocks():
|
||||
datas = []
|
||||
for datatype in SUPPORTED_TYPES:
|
||||
for item in getattr(bpy.data, CORRESPONDANCE[datatype]):
|
||||
item.id= bpy.context.scene.session_settings.username
|
||||
datas.append("{}/{}".format(datatype, item.name))
|
||||
|
||||
return datas
|
||||
|
||||
# LOAD HELPERS
|
||||
def load(key, value):
|
||||
target = resolve_bpy_path(key)
|
||||
|
13
operators.py
13
operators.py
@ -170,14 +170,14 @@ def init_datablocks():
|
||||
|
||||
|
||||
def default_tick():
|
||||
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.5
|
||||
return 10
|
||||
|
||||
|
||||
def draw_tick():
|
||||
@ -210,7 +210,7 @@ def sync():
|
||||
|
||||
def register_ticks():
|
||||
# REGISTER Updaters
|
||||
bpy.app.timers.register(draw_tick)
|
||||
# bpy.app.timers.register(draw_tick)
|
||||
bpy.app.timers.register(sync)
|
||||
bpy.app.timers.register(default_tick)
|
||||
|
||||
@ -260,7 +260,7 @@ class session_join(bpy.types.Operator):
|
||||
|
||||
# net_settings.is_running = True
|
||||
drawer = draw.HUD(client_instance=client_instance)
|
||||
|
||||
# bpy.ops.session.refresh()
|
||||
register_ticks()
|
||||
return {"FINISHED"}
|
||||
|
||||
@ -367,9 +367,10 @@ class session_create(bpy.types.Operator):
|
||||
|
||||
bpy.ops.session.join()
|
||||
|
||||
if net_settings.init_scene:
|
||||
init_datablocks()
|
||||
# if net_settings.init_scene:
|
||||
# init_datablocks()
|
||||
|
||||
client_instance.init()
|
||||
net_settings.is_admin = True
|
||||
|
||||
return {"FINISHED"}
|
||||
|
Loading…
Reference in New Issue
Block a user