feat(halpers): started to add basic armature support
This commit is contained in:
@ -82,7 +82,7 @@ class RCFClient(object):
|
|||||||
serial_agent.start()
|
serial_agent.start()
|
||||||
self.serial_agents.append(serial_agent)
|
self.serial_agents.append(serial_agent)
|
||||||
|
|
||||||
# Database and connexion agent
|
# Sync Watchdog
|
||||||
self.watchdog_agent = threading.Thread(
|
self.watchdog_agent = threading.Thread(
|
||||||
target=watchdog_worker, args=(self.serial_feed, 2, self.stop_event), name="watchdog-agent")
|
target=watchdog_worker, args=(self.serial_feed, 2, self.stop_event), name="watchdog-agent")
|
||||||
self.watchdog_agent.daemon = True
|
self.watchdog_agent.daemon = True
|
||||||
@ -507,7 +507,7 @@ def watchdog_worker(feed,interval, stop_event):
|
|||||||
for datatype in helpers.SUPPORTED_TYPES:
|
for datatype in helpers.SUPPORTED_TYPES:
|
||||||
for item in getattr(bpy.data, helpers.CORRESPONDANCE[datatype]):
|
for item in getattr(bpy.data, helpers.CORRESPONDANCE[datatype]):
|
||||||
key = "{}/{}".format(datatype, item.name)
|
key = "{}/{}".format(datatype, item.name)
|
||||||
|
try:
|
||||||
if item.id == 'None':
|
if item.id == 'None':
|
||||||
item.id = bpy.context.scene.session_settings.username
|
item.id = bpy.context.scene.session_settings.username
|
||||||
feed.put(('DUMP',key,None))
|
feed.put(('DUMP',key,None))
|
||||||
@ -515,6 +515,8 @@ def watchdog_worker(feed,interval, stop_event):
|
|||||||
logger.info("{} needs update".format(item.name))
|
logger.info("{} needs update".format(item.name))
|
||||||
feed.put(('DUMP',key,None))
|
feed.put(('DUMP',key,None))
|
||||||
item.is_dirty = False
|
item.is_dirty = False
|
||||||
|
except:
|
||||||
|
pass
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
logger.info("watchdog thread stopped")
|
logger.info("watchdog thread stopped")
|
||||||
|
68
helpers.py
68
helpers.py
@ -11,11 +11,11 @@ from .libs import dump_anything
|
|||||||
CORRESPONDANCE = {'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials',
|
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'}
|
'Texture': 'textures', 'Scene': 'scenes', 'Light': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'}
|
||||||
|
|
||||||
SUPPORTED_TYPES = ['Material',
|
SUPPORTED_TYPES = [ 'Armature', 'Material',
|
||||||
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Armature', 'Collection', 'Scene']
|
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Collection', 'Scene']
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
# UTILITY FUNCTIONS
|
# UTILITY FUNCTIONS
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +23,35 @@ 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 get_armature_edition_context(armature):
|
||||||
|
override = bpy.context.copy()
|
||||||
|
|
||||||
|
# Set correct area
|
||||||
|
for area in bpy.data.window_managers[0].windows[0].screen.areas :
|
||||||
|
if area.type == 'VIEW_3D':
|
||||||
|
override['area'] = area
|
||||||
|
break
|
||||||
|
|
||||||
|
# Set correct armature settings
|
||||||
|
override['mode'] = 'EDIT_ARMATURE'
|
||||||
|
override['active_object'] = armature
|
||||||
|
override['selected_objects'] = [armature]
|
||||||
|
|
||||||
|
edit_object_ref = None
|
||||||
|
|
||||||
|
for o in bpy.data.objects:
|
||||||
|
if o.data == armature:
|
||||||
|
edit_object_ref = o
|
||||||
|
break
|
||||||
|
|
||||||
|
if edit_object_ref is None:
|
||||||
|
edit_object_ref = bpy.data.objects.new(armature.name, armature)
|
||||||
|
|
||||||
|
|
||||||
|
override['edit_object'] = edit_object_ref
|
||||||
|
|
||||||
|
|
||||||
|
return override
|
||||||
|
|
||||||
def get_selected_objects(scene):
|
def get_selected_objects(scene):
|
||||||
selected_objects = []
|
selected_objects = []
|
||||||
@ -76,6 +105,9 @@ def load(key, value):
|
|||||||
elif target_type == 'Camera':
|
elif target_type == 'Camera':
|
||||||
load_default(target=target, data=value,
|
load_default(target=target, data=value,
|
||||||
create=True, type=target_type)
|
create=True, type=target_type)
|
||||||
|
elif target_type == 'Armature':
|
||||||
|
load_armature(target=target, data=value,
|
||||||
|
create=True)
|
||||||
elif target_type == 'Client':
|
elif target_type == 'Client':
|
||||||
load_client(key.split('/')[1], value)
|
load_client(key.split('/')[1], value)
|
||||||
|
|
||||||
@ -106,6 +138,29 @@ def load_client(client=None, data=None):
|
|||||||
draw.renderer.draw_client(data)
|
draw.renderer.draw_client(data)
|
||||||
draw.renderer.draw_client_selected_objects(data)
|
draw.renderer.draw_client_selected_objects(data)
|
||||||
|
|
||||||
|
def load_armature(target=None, data=None, create=False):
|
||||||
|
if not target or not target.is_editmode:
|
||||||
|
target = bpy.data.armatures.new(data['name'])
|
||||||
|
|
||||||
|
# Construct a correct execution context
|
||||||
|
# context = get_armature_edition_context(target)
|
||||||
|
|
||||||
|
dump_anything.load(target, data)
|
||||||
|
|
||||||
|
# for eb in data['edit_bones']:
|
||||||
|
# if eb in target.edit_bones.keys():
|
||||||
|
# # Update the bone
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# # Add new edit bone and load it
|
||||||
|
# bpy.ops.armature.bone_primitive_add(context)
|
||||||
|
|
||||||
|
# target_new_eb = target.edit_bones[eb]
|
||||||
|
# dump_anything.load(target_new_eb, data['edit_bones'][eb])
|
||||||
|
|
||||||
|
# logger.info(eb)
|
||||||
|
target.id = data['id']
|
||||||
|
|
||||||
|
|
||||||
def load_mesh(target=None, data=None, create=False):
|
def load_mesh(target=None, data=None, create=False):
|
||||||
import bmesh
|
import bmesh
|
||||||
@ -160,6 +215,8 @@ def load_object(target=None, data=None, create=False):
|
|||||||
pointer = bpy.data.cameras[data["data"]]
|
pointer = bpy.data.cameras[data["data"]]
|
||||||
elif data["data"] in bpy.data.curves.keys():
|
elif data["data"] in bpy.data.curves.keys():
|
||||||
pointer = bpy.data.curves[data["data"]]
|
pointer = bpy.data.curves[data["data"]]
|
||||||
|
elif data["data"] in bpy.data.armatures.keys():
|
||||||
|
pointer = bpy.data.armatures[data["data"]]
|
||||||
elif data["data"] in bpy.data.grease_pencils.keys():
|
elif data["data"] in bpy.data.grease_pencils.keys():
|
||||||
pointer = bpy.data.grease_pencils[data["data"]]
|
pointer = bpy.data.grease_pencils[data["data"]]
|
||||||
|
|
||||||
@ -365,8 +422,6 @@ def load_default(target=None, data=None, create=False, type=None):
|
|||||||
logger.error("default loading error {}".format(e))
|
logger.error("default loading error {}".format(e))
|
||||||
|
|
||||||
# DUMP HELPERS
|
# DUMP HELPERS
|
||||||
|
|
||||||
|
|
||||||
def dump(key):
|
def dump(key):
|
||||||
target = resolve_bpy_path(key)
|
target = resolve_bpy_path(key)
|
||||||
target_type = key.split('/')[0]
|
target_type = key.split('/')[0]
|
||||||
@ -391,6 +446,9 @@ def dump(key):
|
|||||||
elif target_type == 'Scene':
|
elif target_type == 'Scene':
|
||||||
data = dump_datablock_attibute(
|
data = dump_datablock_attibute(
|
||||||
target, ['name', 'collection', 'id', 'camera', 'grease_pencil'], 4)
|
target, ['name', 'collection', 'id', 'camera', 'grease_pencil'], 4)
|
||||||
|
elif target_type == 'Armature':
|
||||||
|
data = dump_datablock(target, 4)
|
||||||
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ server = None
|
|||||||
context = None
|
context = None
|
||||||
update_list = {}
|
update_list = {}
|
||||||
|
|
||||||
SUPPORTED_DATABLOCKS = ['collections', 'meshes', 'objects',
|
SUPPORTED_DATABLOCKS = ['collections','armatures', 'meshes', 'objects',
|
||||||
'materials', 'textures', 'lights', 'cameras', 'actions', 'armatures', 'grease_pencils']
|
'materials', 'textures', 'lights', 'cameras', 'actions', 'grease_pencils']
|
||||||
SUPPORTED_TYPES = ['Material',
|
SUPPORTED_TYPES = [ 'Armature', 'Material',
|
||||||
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Armature', 'Collection', 'Scene']
|
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Collection', 'Scene']
|
||||||
|
|
||||||
# UTILITY FUNCTIONS
|
# UTILITY FUNCTIONS
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ logger = logging.getLogger("Server")
|
|||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
SUPPORTED_TYPES = [ 'Client', 'Material',
|
SUPPORTED_TYPES = [ 'Client', 'Material',
|
||||||
'Texture', 'Light', 'Camera','Mesh', 'Grease Pencil', 'Object', 'Action', 'Armature','Collection', 'Scene']
|
'Texture', 'Light', 'Camera','Mesh', 'Grease Pencil','Armature', 'Object', 'Action', 'Collection', 'Scene']
|
||||||
|
|
||||||
class RCFServerAgent():
|
class RCFServerAgent():
|
||||||
def __init__(self, context=zmq.Context.instance(), id="admin"):
|
def __init__(self, context=zmq.Context.instance(), id="admin"):
|
||||||
|
Reference in New Issue
Block a user