From b8f164adaad4bfaba93b68cfccd49864cfc96ae9 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 15 Jul 2019 22:25:20 +0200 Subject: [PATCH] feat: modifiers support --- __init__.py | 2 +- environment.py | 4 +++- helpers.py | 28 +++++++++++++++++++++------- operators.py | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/__init__.py b/__init__.py index 4bfae02..d6132cd 100644 --- a/__init__.py +++ b/__init__.py @@ -81,7 +81,7 @@ def save_session_config(self,context): config["replicated_types"][bloc.type_name] = bloc.is_replicated # Generate ordered replicate types - environment.genereate_replicated_types(config["replicated_types"]) + environment.genererate_replicated_types() # Save out the configuration file environment.save_config(config) diff --git a/environment.py b/environment.py index 6fef001..5bd51e3 100644 --- a/environment.py +++ b/environment.py @@ -82,9 +82,11 @@ def get_replicated_types(): return tlist -def genereate_replicated_types(replicated_types): +def genererate_replicated_types(): rtypes.clear() + cfg = load_config() + replicated_types = cfg['replicated_types'] for t in ORDERED_TYPES: if replicated_types[t]: rtypes.append(t) diff --git a/helpers.py b/helpers.py index 0698e84..58c6466 100644 --- a/helpers.py +++ b/helpers.py @@ -71,9 +71,6 @@ def get_selected_objects(scene): # LOAD HELPERS -# def load_color(color_dict, target_color_attribute): -# target_color_attribute - def load_dict(src_dict, target): try: for item in src_dict: @@ -96,7 +93,7 @@ def load(key, value): if target_type == 'Object': load_object(target=target, data=value, create=True) - if target_type == 'Image': + elif target_type == 'Image': load_image(target=target, data=value) elif target_type == 'Mesh': load_mesh(target=target, data=value, @@ -328,7 +325,7 @@ def load_object(target=None, data=None, create=False): target = bpy.data.objects.new(data["name"], pointer) - # Load other meshes metadata + # Load other meshes metadata # dump_anything.load(target, data) target.matrix_world = mathutils.Matrix(data["matrix_world"]) @@ -337,6 +334,21 @@ def load_object(target=None, data=None, create=False): client = bpy.context.window_manager.session.username + # Load modifiers + if hasattr(target,'modifiers'): + for local_modifier in target.modifiers: + if local_modifier.name not in data['modifiers']: + target.modifiers.remove(local_modifier) + for modifier in data['modifiers']: + target_modifier = target.modifiers.get(modifier) + + if not target_modifier: + target_modifier = target.modifiers.new(data['modifiers'][modifier]['name'],data['modifiers'][modifier]['type']) + + dump_anything.load(target_modifier, data['modifiers'][modifier]) + + + if target.id == client or target.id == "Common": target.hide_select = False else: @@ -615,8 +627,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] @@ -667,6 +677,10 @@ def dump(key): # "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) + + if hasattr(target,'modifiers'): + dump_datablock_attibutes( + target, ['modifiers'], 3, data) elif target_type == 'Collection': data = dump_datablock(target, 4) elif target_type == 'Scene': diff --git a/operators.py b/operators.py index b40d5bb..60f27e3 100644 --- a/operators.py +++ b/operators.py @@ -90,6 +90,7 @@ def update_client_selected_object(context): def init_datablocks(): + environment.genererate_replicated_types() for datatype in environment.rtypes: if bpy.context.window_manager.session.supported_datablock[datatype].is_replicated: logger.debug("INIT: {}".format(datatype))