feat(rcf): added guidlines

This commit is contained in:
Swann 2019-02-25 18:05:46 +01:00
parent afa44878a0
commit 33a19bc142
No known key found for this signature in database
GPG Key ID: B02D0B41F8B6D2EE

View File

@ -23,12 +23,18 @@ VECTOR_TYPES = (
'Vector'
)
def on_scene_evalutation(scene):
# TODO: viewer representation
# TODO: Live update only selected object
# TODO: Scene representation
pass
def randomStringDigits(stringLength=6):
"""Generate a random string of letters and digits """
lettersAndDigits = string.ascii_letters + string.digits
return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
class VectorTypeTranslation(net_components.RCFTranslation):
def set(self, data):
"""
@ -43,6 +49,7 @@ class VectorTypeTranslation(net_components.RCFTranslation):
"""
return mathutils.Vector((data[0], data[1], data[2]))
def match_supported_types(value):
type_factory = None
@ -60,31 +67,6 @@ def match_supported_types(value):
return type_factory
# class RNAFractory(net_components.RCFMsgFactory):
# def __init__(self,data):
# self.load = match_type():
# def load(self,data):
# logger.debug(' casting from bpy')
# value_type = type(data)
# rna_value = None
# if value_type is mathutils.Vector or mathutils.Euler:
# rna_value = [data.x,data.y,data.z]
# elif value_type is bpy.props.collection:
# pass # TODO: Collection replication
# elif value_type in NATIVE_TYPES:
# rna_value = data
# return rna_value
# def unload(self,data):
# rcf_value = None
# if value_type == 'Vector':
# value_casted = mathutils.Vector((data[0],data[1],data[2]))
# return rcf_value
# TODO: Less ugly method
def from_bpy(value):
@ -103,6 +85,7 @@ def from_bpy(value):
return str(value.__class__.__name__), value_casted
def to_bpy(store_item):
"""
Get bpy value from store
@ -112,10 +95,12 @@ def to_bpy(store_item):
store_value = store_item.body
if value_type == 'Vector':
value_casted = mathutils.Vector((store_value[0],store_value[1],store_value[2]))
value_casted = mathutils.Vector(
(store_value[0], store_value[1], store_value[2]))
return value_casted
def resolve_bpy_path(path):
"""
Get bpy property value from path
@ -137,6 +122,7 @@ def resolve_bpy_path(path):
return obj, attribute
def observer():
global client
@ -159,6 +145,7 @@ def refresh_window():
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
def patch_scene(msg):
global client
@ -170,7 +157,8 @@ def patch_scene(msg):
value = to_bpy(msg)
# print(msg.get)
logger.debug("Updating scene:\n object: {} attribute: {} , value: {}".format(obj, attr_name, value))
logger.debug("Updating scene:\n object: {} attribute: {} , value: {}".format(
obj, attr_name, value))
try:
setattr(obj, attr_name, value)
except:
@ -178,9 +166,11 @@ def patch_scene(msg):
else:
logger.debug('no need to update scene on our own')
def vector2array(v):
return [v.x, v.y, v.z]
def array2vector(a):
logger.debug(mathutils.Vector((a[0], a[1], a[2])))
return mathutils.Vector((a[0], a[1], a[2]))
@ -189,6 +179,7 @@ def array2vector(a):
recv_callbacks = [patch_scene]
post_init_callbacks = [refresh_window]
class session_join(bpy.types.Operator):
bl_idname = "session.join"
bl_label = "join"
@ -205,12 +196,13 @@ class session_join(bpy.types.Operator):
net_settings = context.scene.session_settings
if net_settings.username == "DefaultUser":
net_settings.username = "{}_{}".format(net_settings.username,randomStringDigits())
net_settings.username = "{}_{}".format(
net_settings.username, randomStringDigits())
username = str(context.scene.session_settings.username)
client = net_components.Client(id=username,on_recv=recv_callbacks,on_post_init=post_init_callbacks)
client = net_components.Client(
id=username, on_recv=recv_callbacks, on_post_init=post_init_callbacks)
time.sleep(1)
bpy.ops.asyncio.loop()
@ -219,6 +211,7 @@ class session_join(bpy.types.Operator):
net_settings.is_running = True
return {"FINISHED"}
class session_add_property(bpy.types.Operator):
bl_idname = "session.add_prop"
bl_label = "add"
@ -244,6 +237,7 @@ class session_add_property(bpy.types.Operator):
return {"FINISHED"}
class session_remove_property(bpy.types.Operator):
bl_idname = "session.remove_prop"
bl_label = "remove"
@ -266,6 +260,7 @@ class session_remove_property(bpy.types.Operator):
except:
return {"CANCELED"}
class session_create(bpy.types.Operator):
bl_idname = "session.create"
bl_label = "create"
@ -329,7 +324,8 @@ class session_settings(bpy.types.PropertyGroup):
port = bpy.props.IntProperty(name="5555")
buffer = bpy.props.StringProperty(name="None")
is_running = bpy.props.BoolProperty(name="is_running", default=False)
update_frequency = bpy.props.FloatProperty(name="update_frequency", default=0.008)
update_frequency = bpy.props.FloatProperty(
name="update_frequency", default=0.008)
# TODO: Rename to match official blender convention
@ -348,7 +344,11 @@ def register():
for cls in classes:
register_class(cls)
bpy.types.Scene.session_settings = bpy.props.PointerProperty(type=session_settings)
bpy.types.Scene.session_settings = bpy.props.PointerProperty(
type=session_settings)
bpy.app.handlers.depsgraph_update_post.append(on_scene_evalutation)
def unregister():
from bpy.utils import unregister_class
@ -356,6 +356,7 @@ def unregister():
unregister_class(cls)
del bpy.types.Scene.session_settings
bpy.app.handlers.depsgraph_update_post.remove(on_scene_evalutation)
if __name__ == "__main__":