diff --git a/helpers.py b/helpers.py index b77d91a..a7e33ef 100644 --- a/helpers.py +++ b/helpers.py @@ -9,8 +9,8 @@ import mathutils from . import draw from .libs import dump_anything -CORRESPONDANCE = {'GreasePencil':'grease_pencils','Curve': 'curves', 'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials', - 'Texture': 'textures', 'Scene': 'scenes', 'Light': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'} +CORRESPONDANCE = {'GreasePencil': 'grease_pencils', 'Curve': 'curves', 'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials', + 'Texture': 'textures', 'Scene': 'scenes', 'Light': 'lights', 'SunLight': 'lights', 'SpotLight': 'lights', 'AreaLight': 'lights', 'PointLight': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'} SUPPORTED_TYPES = ['Curve', 'Material', 'Texture', 'Light', 'Camera', 'Mesh', 'Armature', 'Grease Pencil', 'Object', 'Action', 'Collection', 'Scene'] @@ -303,14 +303,16 @@ def load_curve(target=None, data=None, create=False): new_spline = target.splines.new(data['splines'][spline]['type']) dump_anything.load(new_spline, data['splines'][spline]) - #Load curve geometry data + # Load curve geometry data for bezier_point_index in data['splines'][spline]["bezier_points"]: new_spline.bezier_points.add(1) - dump_anything.load(new_spline.bezier_points[bezier_point_index], data['splines'][spline]["bezier_points"][bezier_point_index]) - + dump_anything.load( + new_spline.bezier_points[bezier_point_index], data['splines'][spline]["bezier_points"][bezier_point_index]) + for point_index in data['splines'][spline]["points"]: new_spline.points.add(1) - dump_anything.load(new_spline.points[point_index], data['splines'][spline]["points"][point_index]) + dump_anything.load( + new_spline.points[point_index], data['splines'][spline]["points"][point_index]) target.id = data['id'] except Exception as e: logger.error("curve loading error: {}".format(e)) @@ -341,7 +343,6 @@ def load_collection(target=None, data=None, create=False): target.id = data['id'] - client = bpy.context.window_manager.session_settings.username if target.id == client: @@ -384,7 +385,6 @@ def load_scene(target=None, data=None, create=False): target.collection.children.unlink( bpy.data.collections[collection]) - target.id = data['id'] # Load annotation # if data["grease_pencil"]: @@ -404,13 +404,12 @@ def load_material(target=None, data=None, create=False): if data['is_grease_pencil']: if not target.is_grease_pencil: bpy.data.materials.create_gpencil_data(target) - + dump_anything.load(target.grease_pencil, data['grease_pencil']) # Load other meshes metadata dump_anything.load(target, data) - # load nodes if data["use_nodes"]: for node in data["node_tree"]["nodes"]: @@ -442,9 +441,9 @@ def load_material(target=None, data=None, create=False): for link in data["node_tree"]["links"]: current_link = data["node_tree"]["links"][link] input_socket = target.node_tree.nodes[current_link['to_node'] - ['name']].inputs[current_link['to_socket']['name']] + ['name']].inputs[current_link['to_socket']['name']] output_socket = target.node_tree.nodes[current_link['from_node'] - ['name']].outputs[current_link['from_socket']['name']] + ['name']].outputs[current_link['from_socket']['name']] target.node_tree.links.new(input_socket, output_socket) @@ -535,8 +534,6 @@ def load_default(target=None, data=None, create=False, type=None): logger.error("default loading error {}".format(e)) # DUMP HELPERS - - def dump(key): target = resolve_bpy_path(key) target_type = key.split('/')[0] @@ -548,11 +545,10 @@ def dump(key): elif target_type == 'Grease Pencil': data = dump_datablock(target, 2) dump_datablock_attibute( - target, ['layers'], 9,data) - + target, ['layers'], 9, data) elif target_type == 'Camera': data = dump_datablock(target, 1) - elif 'Light' in target_type : + elif 'Light' in target_type: data = dump_datablock(target, 1) elif target_type == 'Mesh': data = dump_datablock(target, 2) @@ -568,11 +564,9 @@ def dump(key): data = dump_datablock(target, 1) dump_datablock_attibute( target, ['splines'], 5, data) - # for index, spline in enumerate(target.splines): # data["splines"][index] = dump_datablock_attibute(target.splines[index],"Curve/{}".format(index), ["bezier_points", "material_index", "points", "order_u", "order_v", "point_count_u", "point_count_v", # "radius_interpolation", "resolution_v", "use_bezier_u", "use_bezier_v", "use_cyclic_u", "use_cyclic_v", "use_endpoint_u", "use_endpoint_v"], 3) - elif target_type == 'Object': data = dump_datablock(target, 1) elif target_type == 'Collection': @@ -582,13 +576,12 @@ def dump(key): target, ['name', 'collection', 'id', 'camera', 'grease_pencil'], 2) dump_datablock_attibute( target, ['collection'], 4, data) - + # elif target_type == 'Armature': # data = dump_datablock(target, 4) return data - def dump_datablock(datablock, depth): if datablock: dumper = dump_anything.Dumper() @@ -601,15 +594,13 @@ def dump_datablock(datablock, depth): return data - def dump_datablock_attibute(datablock=None, attributes=[], depth=1, dickt=None): if datablock: dumper = dump_anything.Dumper() dumper.type_subset = dumper.match_subset_all dumper.depth = depth - - datablock_type = datablock.bl_rna.name + datablock_type = datablock.bl_rna.name key = "{}/{}".format(datablock_type, datablock.name) data = {} diff --git a/operators.py b/operators.py index 8ca03ae..547e222 100644 --- a/operators.py +++ b/operators.py @@ -526,12 +526,17 @@ def is_replicated(update): # dickt = dict(client_keys) global client_instance - + object_type = update.id.bl_rna.name + object_name = update.id.name + #Master collection special cae if update.id.name == 'Master Collection': - key = "Scene/{}".format(bpy.context.scene.name) - else: - key = "{}/{}".format(update.id.bl_rna.name, update.id.name) + object_type = 'Scene' + object_name = bpy.context.scene.name + if 'Light' in update.id.bl_rna.name: + object_type = 'Light' + + key = "{}/{}".format(object_type, object_name) if client_instance.exist(key): return True @@ -572,8 +577,7 @@ def depsgraph_update(scene): ctx = bpy.context if client_state == 3: - - + if ctx.mode in ['OBJECT','PAINT_GPENCIL']: updates = ctx.depsgraph.updates username = ctx.window_manager.session_settings.username @@ -595,7 +599,12 @@ def depsgraph_update(scene): if parent_id == username or parent_id == 'Common': item.id = username - key = "{}/{}".format(item.__class__.__name__, item.name) + item_type = item.__class__.__name__ + + if 'Light'in item.__class__.__name__: + item_type = 'Light' + + key = "{}/{}".format(item_type , item.name) client_instance.set(key) logger.info("APPEND {}".format(key)) else: diff --git a/ui.py b/ui.py index 9e4363a..aee53eb 100644 --- a/ui.py +++ b/ui.py @@ -5,7 +5,7 @@ from . import client, operators ICONS = {'Curve':'CURVE_DATA', 'Client':'SOLO_ON','Collection': 'FILE_FOLDER', 'Mesh': 'MESH_DATA', 'Object': 'OBJECT_DATA', 'Material': 'MATERIAL_DATA', - 'Texture': 'TEXTURE_DATA', 'Scene': 'SCENE_DATA', 'Light': 'LIGHT_DATA', 'Camera': 'CAMERA_DATA', 'Action': 'ACTION_DATA', 'Armature': 'ARMATURE_DATA', 'Grease Pencil': 'GREASEPENCIL'} + 'Texture': 'TEXTURE_DATA', 'Scene': 'SCENE_DATA', 'Light': 'LIGHT_DATA', 'SpotLight': 'LIGHT_DATA', 'SunLight': 'LIGHT_DATA', 'PointLight': 'LIGHT_DATA', 'Camera': 'CAMERA_DATA', 'Action': 'ACTION_DATA', 'Armature': 'ARMATURE_DATA', 'Grease Pencil': 'GREASEPENCIL'} class SessionSettingsPanel(bpy.types.Panel):