From c20777f86055737c00903f69759a56d2256110c0 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 30 Mar 2020 17:15:38 +0200 Subject: [PATCH 01/13] feat: update submodule --- multi_user/libs/replication | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multi_user/libs/replication b/multi_user/libs/replication index 70b2d24..83caa04 160000 --- a/multi_user/libs/replication +++ b/multi_user/libs/replication @@ -1 +1 @@ -Subproject commit 70b2d24d15690540c0e0bee43bd82bf338f986c9 +Subproject commit 83caa04e71ca7ded8ba44fb12cf8042e61308d7a From acbf897f5d4d33ad733524a20b34b760c19960d2 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 30 Mar 2020 17:21:28 +0200 Subject: [PATCH 02/13] refactor: rename def --- multi_user/bl_types/bl_armature.py | 4 ++-- multi_user/bl_types/bl_camera.py | 4 ++-- multi_user/bl_types/bl_collection.py | 6 +++--- multi_user/bl_types/bl_curve.py | 4 ++-- multi_user/bl_types/bl_datablock.py | 12 ++++++------ multi_user/bl_types/bl_gpencil.py | 6 +++--- multi_user/bl_types/bl_lattice.py | 4 ++-- multi_user/bl_types/bl_light.py | 4 ++-- multi_user/bl_types/bl_lightprobe.py | 4 ++-- multi_user/bl_types/bl_material.py | 6 +++--- multi_user/bl_types/bl_mesh.py | 6 +++--- multi_user/bl_types/bl_metaball.py | 2 +- multi_user/bl_types/bl_object.py | 6 +++--- multi_user/bl_types/bl_scene.py | 6 +++--- multi_user/bl_types/bl_speaker.py | 4 ++-- multi_user/bl_types/bl_world.py | 6 +++--- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/multi_user/bl_types/bl_armature.py b/multi_user/bl_types/bl_armature.py index 81d464f..dcf85e3 100644 --- a/multi_user/bl_types/bl_armature.py +++ b/multi_user/bl_types/bl_armature.py @@ -35,7 +35,7 @@ class BlArmature(BlDatablock): def _construct(self, data): return bpy.data.armatures.new(data["name"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): # Load parent object parent_object = utils.find_from_attr( 'uuid', @@ -107,7 +107,7 @@ class BlArmature(BlDatablock): if 'EDIT' in current_mode: bpy.ops.object.mode_set(mode='EDIT') - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() diff --git a/multi_user/bl_types/bl_camera.py b/multi_user/bl_types/bl_camera.py index 4876010..aa4005e 100644 --- a/multi_user/bl_types/bl_camera.py +++ b/multi_user/bl_types/bl_camera.py @@ -35,7 +35,7 @@ class BlCamera(BlDatablock): return bpy.data.cameras.new(data["name"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) dof_settings = data.get('dof') @@ -44,7 +44,7 @@ class BlCamera(BlDatablock): if dof_settings: utils.dump_anything.load(target.dof, dof_settings) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) # TODO: background image support diff --git a/multi_user/bl_types/bl_collection.py b/multi_user/bl_types/bl_collection.py index 3d3f9f7..87ecc08 100644 --- a/multi_user/bl_types/bl_collection.py +++ b/multi_user/bl_types/bl_collection.py @@ -46,7 +46,7 @@ class BlCollection(BlDatablock): instance.uuid = self.uuid return instance - def load_implementation(self, data, target): + def _load_implementation(self, data, target): # Load other meshes metadata # dump_anything.load(target, data) target.name = data["name"] @@ -72,7 +72,7 @@ class BlCollection(BlDatablock): if collection.uuid not in data["children"]: target.children.unlink(collection) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) data = {} data['name'] = pointer.name @@ -95,7 +95,7 @@ class BlCollection(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] for child in self.pointer.children: diff --git a/multi_user/bl_types/bl_curve.py b/multi_user/bl_types/bl_curve.py index ac6fbdc..74a7fbe 100644 --- a/multi_user/bl_types/bl_curve.py +++ b/multi_user/bl_types/bl_curve.py @@ -36,7 +36,7 @@ class BlCurve(BlDatablock): def _construct(self, data): return bpy.data.curves.new(data["name"], data["type"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): dump_anything.load(target, data) target.splines.clear() @@ -61,7 +61,7 @@ class BlCurve(BlDatablock): dump_anything.load( new_spline.points[point_index], data['splines'][spline]["points"][point_index]) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = dump_anything.Dumper() diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 1aeb8be..8ddb6eb 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -145,11 +145,11 @@ class BlDatablock(ReplicatedDatablock): if self.is_library: data.update(dump_anything.dump(pointer)) else: - data.update(self.dump_implementation(data, pointer=pointer)) + data.update(self._dump_implementation(data, pointer=pointer)) return data - def dump_implementation(self, data, target): + def _dump_implementation(self, data, target): raise NotImplementedError def _load(self, data, target): @@ -171,9 +171,9 @@ class BlDatablock(ReplicatedDatablock): if self.is_library: return else: - self.load_implementation(data, target) + self._load_implementation(data, target) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): raise NotImplementedError def resolve_deps(self): @@ -183,11 +183,11 @@ class BlDatablock(ReplicatedDatablock): dependencies.append(self.pointer.animation_data.action) if not self.is_library: - dependencies.extend(self.resolve_deps_implementation()) + dependencies.extend(self._resolve_deps_implementation()) return dependencies - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): return [] def is_valid(self): diff --git a/multi_user/bl_types/bl_gpencil.py b/multi_user/bl_types/bl_gpencil.py index bb02332..7e26bfa 100644 --- a/multi_user/bl_types/bl_gpencil.py +++ b/multi_user/bl_types/bl_gpencil.py @@ -221,7 +221,7 @@ class BlGpencil(BlDatablock): def _construct(self, data): return bpy.data.grease_pencils.new(data["name"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): target.materials.clear() if "materials" in data.keys(): for mat in data['materials']: @@ -248,7 +248,7 @@ class BlGpencil(BlDatablock): - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = Dumper() dumper.depth = 2 @@ -261,7 +261,7 @@ class BlGpencil(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] for material in self.pointer.materials: diff --git a/multi_user/bl_types/bl_lattice.py b/multi_user/bl_types/bl_lattice.py index ca6de99..a19c4ce 100644 --- a/multi_user/bl_types/bl_lattice.py +++ b/multi_user/bl_types/bl_lattice.py @@ -31,7 +31,7 @@ class BlLattice(BlDatablock): bl_automatic_push = True bl_icon = 'LATTICE_DATA' - def load_implementation(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) for point in data['points']: @@ -39,7 +39,7 @@ class BlLattice(BlDatablock): def _construct(self, data): return bpy.data.lattices.new(data["name"]) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() diff --git a/multi_user/bl_types/bl_light.py b/multi_user/bl_types/bl_light.py index 67f8af9..05b7dbb 100644 --- a/multi_user/bl_types/bl_light.py +++ b/multi_user/bl_types/bl_light.py @@ -34,10 +34,10 @@ class BlLight(BlDatablock): def _construct(self, data): return bpy.data.lights.new(data["name"], data["type"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() dumper.depth = 3 diff --git a/multi_user/bl_types/bl_lightprobe.py b/multi_user/bl_types/bl_lightprobe.py index abd20e9..3941e19 100644 --- a/multi_user/bl_types/bl_lightprobe.py +++ b/multi_user/bl_types/bl_lightprobe.py @@ -41,10 +41,10 @@ class BlLightprobe(BlDatablock): else: logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396") - def load_implementation(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) if bpy.app.version[1] < 83: logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396") diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index a3ecdb0..1c9cb4e 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -93,7 +93,7 @@ class BlMaterial(BlDatablock): def _construct(self, data): return bpy.data.materials.new(data["name"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): target.name = data['name'] if data['is_grease_pencil']: if not target.is_grease_pencil: @@ -120,7 +120,7 @@ class BlMaterial(BlDatablock): load_links(data["node_tree"]["links"], target.node_tree) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) mat_dumper = dump_anything.Dumper() mat_dumper.depth = 2 @@ -235,7 +235,7 @@ class BlMaterial(BlDatablock): data['grease_pencil'] = gp_mat_dumper.dump(pointer.grease_pencil) return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): # TODO: resolve node group deps deps = [] diff --git a/multi_user/bl_types/bl_mesh.py b/multi_user/bl_types/bl_mesh.py index 83a9358..5738e58 100644 --- a/multi_user/bl_types/bl_mesh.py +++ b/multi_user/bl_types/bl_mesh.py @@ -42,7 +42,7 @@ class BlMesh(BlDatablock): instance.uuid = self.uuid return instance - def load_implementation(self, data, target): + def _load_implementation(self, data, target): if not target or not target.is_editmode: loader = Loader() loader.load(target, data) @@ -97,7 +97,7 @@ class BlMesh(BlDatablock): target.validate() target.update() - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) mesh = pointer @@ -162,7 +162,7 @@ class BlMesh(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] for material in self.pointer.materials: diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index 36c998f..b0807e6 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -42,7 +42,7 @@ class BlMetaball(BlDatablock): new_element = target.elements.new(type=data["elements"][element]['type']) utils.dump_anything.load(new_element, data["elements"][element]) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() dumper.depth = 3 diff --git a/multi_user/bl_types/bl_object.py b/multi_user/bl_types/bl_object.py index 2abb6ad..962a46a 100644 --- a/multi_user/bl_types/bl_object.py +++ b/multi_user/bl_types/bl_object.py @@ -87,7 +87,7 @@ class BlObject(BlDatablock): return instance - def load_implementation(self, data, target): + def _load_implementation(self, data, target): # Load transformation data utils.dump_anything.load(target, data) @@ -151,7 +151,7 @@ class BlObject(BlDatablock): target.data.shape_keys.key_blocks[key_block].relative_key = target.data.shape_keys.key_blocks[reference] - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() dumper.depth = 1 @@ -290,7 +290,7 @@ class BlObject(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] # Avoid Empty case diff --git a/multi_user/bl_types/bl_scene.py b/multi_user/bl_types/bl_scene.py index 5b7b9e5..739f027 100644 --- a/multi_user/bl_types/bl_scene.py +++ b/multi_user/bl_types/bl_scene.py @@ -35,7 +35,7 @@ class BlScene(BlDatablock): instance.uuid = self.uuid return instance - def load_implementation(self, data, target): + def _load_implementation(self, data, target): target = self.pointer # Load other meshes metadata utils.dump_anything.load(target, data) @@ -67,7 +67,7 @@ class BlScene(BlDatablock): if 'grease_pencil' in data.keys(): target.grease_pencil = bpy.data.grease_pencils[data['grease_pencil']] - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) data = {} @@ -89,7 +89,7 @@ class BlScene(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] # child collections diff --git a/multi_user/bl_types/bl_speaker.py b/multi_user/bl_types/bl_speaker.py index 9d2f87c..5e90780 100644 --- a/multi_user/bl_types/bl_speaker.py +++ b/multi_user/bl_types/bl_speaker.py @@ -31,13 +31,13 @@ class BlSpeaker(BlDatablock): bl_automatic_push = True bl_icon = 'SPEAKER' - def load_implementation(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) def _construct(self, data): return bpy.data.speakers.new(data["name"]) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index 8f79dc1..2650013 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -35,7 +35,7 @@ class BlWorld(BlDatablock): def _construct(self, data): return bpy.data.worlds.new(data["name"]) - def load_implementation(self, data, target): + def _load_implementation(self, data, target): if data["use_nodes"]: if target.node_tree is None: target.use_nodes = True @@ -51,7 +51,7 @@ class BlWorld(BlDatablock): load_links(data["node_tree"]["links"], target.node_tree) - def dump_implementation(self, data, pointer=None): + def _dump_implementation(self, data, pointer=None): assert(pointer) world_dumper = utils.dump_anything.Dumper() @@ -109,7 +109,7 @@ class BlWorld(BlDatablock): return data - def resolve_deps_implementation(self): + def _resolve_deps_implementation(self): deps = [] if self.pointer.use_nodes: From 820c6dad7ed3a569bbfad5413ca7b7cad9282e23 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 30 Mar 2020 18:05:33 +0200 Subject: [PATCH 03/13] refactor: feat dump node --- multi_user/bl_types/bl_material.py | 132 ++++++++++++++++------------- multi_user/bl_types/bl_world.py | 36 +------- 2 files changed, 77 insertions(+), 91 deletions(-) diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index 1c9cb4e..c742ecc 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -47,6 +47,7 @@ def load_node(node_data, node_tree): except: logger.error("{} not supported, skipping".format(input)) + def load_links(links_data, node_tree): """ Load node_tree links from a list @@ -62,6 +63,7 @@ def load_links(links_data, node_tree): node_tree.links.new(input_socket, output_socket) + def dump_links(links): """ Dump node_tree links collection to a list @@ -82,6 +84,77 @@ def dump_links(links): return links_data + +def dump_node(node): + """ Dump a single node to a dict + + :arg node: target node + :type node: bpy.types.Node + :retrun: dict + """ + + node_dumper = dump_anything.Dumper() + node_dumper.depth = 1 + node_dumper.exclude_filter = [ + "dimensions", + "show_expanded", + "name_full", + "select", + "bl_height_min", + "bl_height_max", + "bl_height_default", + "bl_width_min", + "bl_width_max", + "type", + "bl_icon", + "bl_width_default", + "bl_static_type", + "show_tetxure", + "is_active_output", + "hide", + "show_options", + "show_preview", + "show_texture", + "outputs", + "width_hidden" + ] + + dumped_node = node_dumper.dump(node) + + if hasattr(node, 'inputs'): + dumped_node['inputs'] = {} + + for i in node.inputs: + input_dumper = dump_anything.Dumper() + input_dumper.depth = 2 + input_dumper.include_filter = ["default_value"] + + if hasattr(i, 'default_value'): + dumped_node['inputs'][i.name] = input_dumper.dump( + i) + if hasattr(node, 'color_ramp'): + ramp_dumper = dump_anything.Dumper() + ramp_dumper.depth = 4 + ramp_dumper.include_filter = [ + 'elements', + 'alpha', + 'color', + 'position' + ] + dumped_node['color_ramp'] = ramp_dumper.dump(node.color_ramp) + if hasattr(node, 'mapping'): + curve_dumper = dump_anything.Dumper() + curve_dumper.depth = 5 + curve_dumper.include_filter = [ + 'curves', + 'points', + 'location' + ] + dumped_node['mapping'] = curve_dumper.dump(node.mapping) + + return dumped_node + + class BlMaterial(BlDatablock): bl_id = "materials" bl_class = bpy.types.Material @@ -144,68 +217,11 @@ class BlMaterial(BlDatablock): if pointer.use_nodes: nodes = {} - node_dumper = dump_anything.Dumper() - node_dumper.depth = 1 - node_dumper.exclude_filter = [ - "dimensions", - "show_expanded", - "name_full", - "select", - "bl_height_min", - "bl_height_max", - "bl_width_min", - "bl_width_max", - "type", - "bl_icon", - "bl_width_default", - "bl_static_type", - "show_tetxure", - "hide", - "show_options", - "show_preview", - "outputs", - "width_hidden" - ] for node in pointer.node_tree.nodes: - - nodes[node.name] = node_dumper.dump(node) - - if hasattr(node, 'inputs'): - nodes[node.name]['inputs'] = {} - - for i in node.inputs: - input_dumper = dump_anything.Dumper() - input_dumper.depth = 2 - input_dumper.include_filter = ["default_value"] - - if hasattr(i, 'default_value'): - nodes[node.name]['inputs'][i.name] = input_dumper.dump( - i) - if hasattr(node, 'color_ramp'): - ramp_dumper = dump_anything.Dumper() - ramp_dumper.depth = 4 - ramp_dumper.include_filter = [ - 'elements', - 'alpha', - 'color', - 'position' - ] - nodes[node.name]['color_ramp'] = ramp_dumper.dump(node.color_ramp) - if hasattr(node, 'mapping'): - curve_dumper = dump_anything.Dumper() - curve_dumper.depth = 5 - curve_dumper.include_filter = [ - 'curves', - 'points', - 'location' - ] - nodes[node.name]['mapping'] = curve_dumper.dump(node.mapping) - + nodes[node.name] = dump_node(node) data["node_tree"]['nodes'] = nodes - data["node_tree"]["links"] = dump_links(pointer.node_tree.links) - elif pointer.is_grease_pencil: gp_mat_dumper = dump_anything.Dumper() gp_mat_dumper.depth = 3 diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index 2650013..de25218 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -21,7 +21,7 @@ import mathutils from .. import utils from .bl_datablock import BlDatablock -from .bl_material import load_links, load_node, dump_links +from .bl_material import load_links, load_node,dump_node, dump_links class BlWorld(BlDatablock): @@ -69,40 +69,10 @@ class BlWorld(BlDatablock): data = world_dumper.dump(pointer) if pointer.use_nodes: nodes = {} - dumper = utils.dump_anything.Dumper() - dumper.depth = 2 - dumper.exclude_filter = [ - "dimensions", - "select", - "bl_height_min", - "bl_height_max", - "bl_width_min", - "bl_width_max", - "bl_width_default", - "hide", - "show_options", - "show_tetxures", - "show_preview", - "outputs", - "preview", - "original", - "width_hidden", - - ] - + for node in pointer.node_tree.nodes: - nodes[node.name] = dumper.dump(node) + nodes[node.name] = dump_node(node) - if hasattr(node, 'inputs'): - nodes[node.name]['inputs'] = {} - - for i in node.inputs: - input_dumper = utils.dump_anything.Dumper() - input_dumper.depth = 2 - input_dumper.include_filter = ["default_value"] - if hasattr(i, 'default_value'): - nodes[node.name]['inputs'][i.name] = input_dumper.dump( - i) data["node_tree"]['nodes'] = nodes data["node_tree"]['links'] = dump_links(pointer.node_tree.links) From d46ea3a117921fe656d4a4ca8072ec1c6a122350 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 30 Mar 2020 18:12:43 +0200 Subject: [PATCH 04/13] refactor: change default materials refrash rate to 1s --- multi_user/bl_types/bl_material.py | 4 ++-- multi_user/bl_types/bl_world.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index c742ecc..beee34c 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -158,8 +158,8 @@ def dump_node(node): class BlMaterial(BlDatablock): bl_id = "materials" bl_class = bpy.types.Material - bl_delay_refresh = 10 - bl_delay_apply = 10 + bl_delay_refresh = 1 + bl_delay_apply = 1 bl_automatic_push = True bl_icon = 'MATERIAL_DATA' diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index de25218..e78ca2a 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -27,8 +27,8 @@ from .bl_material import load_links, load_node,dump_node, dump_links class BlWorld(BlDatablock): bl_id = "worlds" bl_class = bpy.types.World - bl_delay_refresh = 4 - bl_delay_apply = 4 + bl_delay_refresh = 1 + bl_delay_apply = 1 bl_automatic_push = True bl_icon = 'WORLD_DATA' @@ -69,7 +69,7 @@ class BlWorld(BlDatablock): data = world_dumper.dump(pointer) if pointer.use_nodes: nodes = {} - + for node in pointer.node_tree.nodes: nodes[node.name] = dump_node(node) From 9c9d7a31bfafd7e8d99a720ba03bebf02819d39d Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 30 Mar 2020 18:50:54 +0200 Subject: [PATCH 05/13] feat: cleanup metaballs --- multi_user/bl_types/bl_metaball.py | 76 ++++++++++++++++++++++++++---- multi_user/libs/dump_anything.py | 27 +++++++++++ 2 files changed, 94 insertions(+), 9 deletions(-) diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index b0807e6..4bfdac9 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -20,8 +20,57 @@ import bpy import mathutils from .. import utils +from ..libs.dump_anything import ( + Dumper, Loader, dump_collection_attr, load_collection_attr, dump_collection_attr_to_dict, load_collection_attr_from_dict) + from .bl_datablock import BlDatablock +ENUM_METABALL_TYPE = [ + 'BALL', + 'CAPSULE', + 'PLANE', + 'ELLIPSOID', + 'CUBE' +] + + +ELEMENTS_FAST_ATTR = [ + 'co', + 'hide', + 'radius', + 'rotation', + 'size_x', + 'size_y', + 'size_z', + 'stiffness'] + + +def dump_metaball_elements(elements): + """ Dump a metaball element + + :arg element: metaball element + :type bpy.types.MetaElement + :return: dict + """ + + dumped_elements = {} + + dump_collection_attr_to_dict(dumped_elements, elements, ELEMENTS_FAST_ATTR) + + dumped_elements['type'] = [ENUM_METABALL_TYPE.index(e.type) for e in elements] + + return dumped_elements + + +def load_metaball_elements(elements_data, elements): + """ Dump a metaball element + + :arg element: metaball element + :type bpy.types.MetaElement + :return: dict + """ + load_collection_attr_from_dict(elements_data, elements, ELEMENTS_FAST_ATTR) + class BlMetaball(BlDatablock): bl_id = "metaballs" @@ -34,22 +83,31 @@ class BlMetaball(BlDatablock): def _construct(self, data): return bpy.data.metaballs.new(data["name"]) - def load(self, data, target): + def _load_implementation(self, data, target): utils.dump_anything.load(target, data) - + target.elements.clear() - for element in data["elements"]: - new_element = target.elements.new(type=data["elements"][element]['type']) - utils.dump_anything.load(new_element, data["elements"][element]) + + for element_type in data["elements"]['type']: + new_element = target.elements.new( + type=ENUM_METABALL_TYPE[element_type]) + + load_metaball_elements(data['elements'], target.elements) def _dump_implementation(self, data, pointer=None): assert(pointer) dumper = utils.dump_anything.Dumper() - dumper.depth = 3 - dumper.exclude_filter = ["is_editmode"] + dumper.depth = 1 + dumper.exclude_filter = [ + "is_editmode", + "is_evaluated", + "is_embedded_data", + "is_library_indirect", + "name_full" + ] data = dumper.dump(pointer) + data['elements'] = dump_metaball_elements(pointer.elements) + return data - - diff --git a/multi_user/libs/dump_anything.py b/multi_user/libs/dump_anything.py index ba12f8e..62c1f4b 100644 --- a/multi_user/libs/dump_anything.py +++ b/multi_user/libs/dump_anything.py @@ -30,6 +30,33 @@ BPY_TO_NUMPY_TYPES = { 'BOOL': np.bool } +def load_collection_attr_from_dict(dikt, collection, attributes): + """ Dump a list of attributes from the sane collection + to the target dikt + + :arg dikt: target dict + :type dikt: dict + :arg collection: source collection + :type collection: bpy.types.CollectionProperty + :arg attributes: list of attributes name + :type attributes: list + """ + for attr in attributes: + load_collection_attr(collection, attr, dikt[attr]) + +def dump_collection_attr_to_dict(dikt, collection, attributes): + """ Dump a list of attributes from the sane collection + to the target dikt + + :arg dikt: target dict + :type dikt: dict + :arg collection: source collection + :type collection: bpy.types.CollectionProperty + :arg attributes: list of attributes name + :type attributes: list + """ + for attr in attributes: + dikt[attr] = dump_collection_attr(collection, attr) def dump_collection_attr(collection, attribute): """ Dump a collection attribute as a sequence From 928eccfa2390fba3c5ed2ca5e11cb00d3c628c21 Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 31 Mar 2020 10:13:49 +0200 Subject: [PATCH 06/13] feat: vertex_color support --- multi_user/bl_types/bl_mesh.py | 57 ++++++++++++++++-------------- multi_user/bl_types/bl_metaball.py | 27 +++++++------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/multi_user/bl_types/bl_mesh.py b/multi_user/bl_types/bl_mesh.py index 5738e58..cfc2bc5 100644 --- a/multi_user/bl_types/bl_mesh.py +++ b/multi_user/bl_types/bl_mesh.py @@ -66,33 +66,37 @@ class BlMesh(BlDatablock): load_collection_attr(target.vertices, 'co', data["verts_co"]) load_collection_attr(target.edges, "vertices", data["egdes_vert"]) if data['use_customdata_edge_crease']: - load_collection_attr( - target.edges, "crease", data["edges_crease"]) + load_collection_attr(target.edges, "crease", data["edges_crease"]) if data['use_customdata_edge_bevel']: - load_collection_attr( - target.edges, "bevel_weight", data["edges_bevel"]) + load_collection_attr(target.edges, "bevel_weight", data["edges_bevel"]) - load_collection_attr( - target.loops, 'vertex_index', data["loop_vertex_index"]) + load_collection_attr(target.loops, 'vertex_index', data["loop_vertex_index"]) load_collection_attr(target.loops, 'normal', data["loop_normal"]) - load_collection_attr( - target.polygons, 'loop_total', data["poly_loop_total"]) - load_collection_attr( - target.polygons, 'loop_start', data["poly_loop_start"]) - load_collection_attr( - target.polygons, 'use_smooth', data["poly_smooth"]) - load_collection_attr( - target.polygons, 'material_index', data["poly_mat"]) + load_collection_attr(target.polygons, 'loop_total', data["poly_loop_total"]) + load_collection_attr(target.polygons, 'loop_start', data["poly_loop_start"]) + load_collection_attr(target.polygons, 'use_smooth', data["poly_smooth"]) + load_collection_attr(target.polygons, 'material_index', data["poly_mat"]) # UV Layers for layer in data['uv_layers']: if layer not in target.uv_layers: target.uv_layers.new(name=layer) - uv_buffer = np.frombuffer(data["uv_layers"][layer]['data']) + load_collection_attr( + target.uv_layers[layer].data, + 'uv', + data["uv_layers"][layer]['data']) + + # Vertex color + for color_layer in data['vertex_colors']: + if color_layer not in target.vertex_colors: + target.vertex_colors.new(name=color_layer) - target.uv_layers[layer].data.foreach_set('uv', uv_buffer) + load_collection_attr( + target.vertex_colors[color_layer].data, + 'color', + data["vertex_colors"][color_layer]['data']) target.validate() target.update() @@ -131,26 +135,27 @@ class BlMesh(BlDatablock): # POLYGONS data["poly_count"] = len(mesh.polygons) - data["poly_mat"] = dump_collection_attr( - mesh.polygons, 'material_index') - data["poly_loop_start"] = dump_collection_attr( - mesh.polygons, 'loop_start') - data["poly_loop_total"] = dump_collection_attr( - mesh.polygons, 'loop_total') + data["poly_mat"] = dump_collection_attr(mesh.polygons, 'material_index') + data["poly_loop_start"] = dump_collection_attr(mesh.polygons, 'loop_start') + data["poly_loop_total"] = dump_collection_attr(mesh.polygons, 'loop_total') data["poly_smooth"] = dump_collection_attr(mesh.polygons, 'use_smooth') # LOOPS data["loop_count"] = len(mesh.loops) data["loop_normal"] = dump_collection_attr(mesh.loops, 'normal') - data["loop_vertex_index"] = dump_collection_attr( - mesh.loops, 'vertex_index') + data["loop_vertex_index"] = dump_collection_attr(mesh.loops, 'vertex_index') # UV Layers data['uv_layers'] = {} for layer in mesh.uv_layers: data['uv_layers'][layer.name] = {} - data['uv_layers'][layer.name]['data'] = dump_collection_attr( - layer.data, 'uv') + data['uv_layers'][layer.name]['data'] = dump_collection_attr(layer.data, 'uv') + + # Vertex color + data['vertex_colors'] = {} + for color_map in mesh.vertex_colors: + data['vertex_colors'][color_map.name] = {} + data['vertex_colors'][color_map.name]['data'] = dump_collection_attr(color_map.data, 'color') # Fix material index m_list = [] diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index 4bfdac9..be510a7 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -21,7 +21,8 @@ import mathutils from .. import utils from ..libs.dump_anything import ( - Dumper, Loader, dump_collection_attr, load_collection_attr, dump_collection_attr_to_dict, load_collection_attr_from_dict) + Dumper, Loader, dump_collection_attr, load_collection_attr, + dump_collection_attr_to_dict, load_collection_attr_from_dict) from .bl_datablock import BlDatablock @@ -35,14 +36,15 @@ ENUM_METABALL_TYPE = [ ELEMENTS_FAST_ATTR = [ - 'co', - 'hide', - 'radius', - 'rotation', - 'size_x', - 'size_y', - 'size_z', - 'stiffness'] + 'co', + 'hide', + 'radius', + 'rotation', + 'size_x', + 'size_y', + 'size_z', + 'stiffness' +] def dump_metaball_elements(elements): @@ -52,11 +54,11 @@ def dump_metaball_elements(elements): :type bpy.types.MetaElement :return: dict """ - + dumped_elements = {} dump_collection_attr_to_dict(dumped_elements, elements, ELEMENTS_FAST_ATTR) - + dumped_elements['type'] = [ENUM_METABALL_TYPE.index(e.type) for e in elements] return dumped_elements @@ -91,7 +93,7 @@ class BlMetaball(BlDatablock): for element_type in data["elements"]['type']: new_element = target.elements.new( type=ENUM_METABALL_TYPE[element_type]) - + load_metaball_elements(data['elements'], target.elements) def _dump_implementation(self, data, pointer=None): @@ -110,4 +112,3 @@ class BlMetaball(BlDatablock): data['elements'] = dump_metaball_elements(pointer.elements) return data - From 379e7cdf7150ad61cd1018888d56b37f806a5c85 Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 31 Mar 2020 17:28:32 +0200 Subject: [PATCH 07/13] refactor: cleanup implementation feat: np_load_collection for collection attr load/unload --- multi_user/bl_types/bl_action.py | 86 +++++---------------------- multi_user/bl_types/bl_curve.py | 69 ++++++++++++++-------- multi_user/bl_types/bl_gpencil.py | 31 +++++----- multi_user/bl_types/bl_mesh.py | 65 ++++++++++----------- multi_user/bl_types/bl_metaball.py | 31 ++++------ multi_user/libs/dump_anything.py | 93 +++++++++++++++++++++++++----- 6 files changed, 197 insertions(+), 178 deletions(-) diff --git a/multi_user/bl_types/bl_action.py b/multi_user/bl_types/bl_action.py index 9e736be..40fc124 100644 --- a/multi_user/bl_types/bl_action.py +++ b/multi_user/bl_types/bl_action.py @@ -24,53 +24,27 @@ from enum import Enum from .. import utils from ..libs.dump_anything import ( - Dumper, Loader, dump_collection_attr, load_collection_attr) + Dumper, Loader, np_dump_collection, np_load_collection) from .bl_datablock import BlDatablock -ENUM_EASING_TYPE = [ - 'AUTO', - 'EAS_IN', - 'EASE_OUT', - 'EASE_IN_OUT'] - - -ENUM_HANDLE_TYPE = [ - 'FREE', - 'ALIGNED', - 'VECTOR', - 'AUTO', - 'AUTO_CLAMPED'] - - -ENUM_INTERPOLATION_TYPE = [ - 'CONSTANT', - 'LINEAR', - 'BEZIER', - 'SINE', - 'QUAD', - 'CUBIC', - 'QUART', - 'QUINT', - 'EXPO', - 'CIRC', - 'BACK', - 'BOUNCE', - 'ELASTIC'] - - -ENUM_KEY_TYPE = [ - 'KEYFRAME', - 'BREAKDOWN', - 'MOVING_HOLD', - 'EXTREME', - 'JITTER'] - +KEYFRAME = [ + 'amplitude', + 'co', + 'back', + 'handle_left', + 'handle_right', + 'easing', + 'handle_left_type', + 'handle_right_type', + 'type', + 'interpolation', +] # TODO: Automatic enum and numpy dump and loading -def dump_fcurve(fcurve, use_numpy=True): +def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy:bool =True) -> dict: """ Dump a sigle curve to a dict :arg fcurve: fcurve to dump @@ -88,23 +62,7 @@ def dump_fcurve(fcurve, use_numpy=True): if use_numpy: points = fcurve.keyframe_points fcurve_data['keyframes_count'] = len(fcurve.keyframe_points) - - fcurve_data['amplitude'] = dump_collection_attr(points, 'amplitude') - fcurve_data['co'] = dump_collection_attr(points, 'co') - fcurve_data['back'] = dump_collection_attr(points, 'back') - fcurve_data['handle_left'] = dump_collection_attr(points, 'handle_left') - fcurve_data['handle_right'] = dump_collection_attr(points, 'handle_right') - - fcurve_data['easing'] = [ENUM_EASING_TYPE.index( - p.easing) for p in fcurve.keyframe_points] - fcurve_data['handle_left_type'] = [ENUM_HANDLE_TYPE.index( - p.handle_left_type) for p in fcurve.keyframe_points] - fcurve_data['handle_right_type'] = [ENUM_HANDLE_TYPE.index( - p.handle_right_type) for p in fcurve.keyframe_points] - fcurve_data['type'] = [ENUM_KEY_TYPE.index( - p.type) for p in fcurve.keyframe_points] - fcurve_data['interpolation'] = [ENUM_INTERPOLATION_TYPE.index( - p.interpolation) for p in fcurve.keyframe_points] + fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME) else: # Legacy method dumper = utils.dump_anything.Dumper() @@ -136,19 +94,7 @@ def load_fcurve(fcurve_data, fcurve): if use_numpy: keyframe_points.add(fcurve_data['keyframes_count']) - - load_collection_attr(keyframe_points, 'co', fcurve_data['co']) - load_collection_attr(keyframe_points, 'back', fcurve_data['back']) - load_collection_attr(keyframe_points, 'amplitude', fcurve_data['amplitude']) - load_collection_attr(keyframe_points, 'handle_left', fcurve_data['handle_left']) - load_collection_attr(keyframe_points, 'handle_right', fcurve_data['handle_right']) - - for index, point in enumerate(keyframe_points): - point.type = ENUM_KEY_TYPE[fcurve_data['type'][index]] - point.easing = ENUM_EASING_TYPE[fcurve_data['easing'][index]] - point.handle_left_type = ENUM_HANDLE_TYPE[fcurve_data['handle_left_type'][index]] - point.handle_right_type = ENUM_HANDLE_TYPE[fcurve_data['handle_right_type'][index]] - point.interpolation = ENUM_INTERPOLATION_TYPE[fcurve_data['interpolation'][index]] + np_load_collection(fcurve_data["keyframe_points"], keyframe_points, KEYFRAME) else: # paste dumped keyframes diff --git a/multi_user/bl_types/bl_curve.py b/multi_user/bl_types/bl_curve.py index 74a7fbe..c662829 100644 --- a/multi_user/bl_types/bl_curve.py +++ b/multi_user/bl_types/bl_curve.py @@ -19,11 +19,33 @@ import bpy import bpy.types as T import mathutils +import logging from .. import utils from .bl_datablock import BlDatablock -from ..libs import dump_anything +from ..libs.dump_anything import (Dumper, Loader, + np_load_collection, + np_dump_collection) +logger = logging.getLogger(__name__) + +SPLINE_BEZIER_POINT = [ + # "handle_left_type", + # "handle_right_type", + "handle_left", + "co", + "handle_right", + "tilt", + "weight_softbody", + "radius", +] + +SPLINE_POINT = [ + "co", + "tilt", + "weight_softbody", + "radius", +] class BlCurve(BlDatablock): bl_id = "curves" @@ -37,48 +59,46 @@ class BlCurve(BlDatablock): return bpy.data.curves.new(data["name"], data["type"]) def _load_implementation(self, data, target): - dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) target.splines.clear() # load splines - for spline in data['splines']: - new_spline = target.splines.new(data['splines'][spline]['type']) - dump_anything.load(new_spline, data['splines'][spline]) + for spline in data['splines'].values(): + new_spline = target.splines.new(spline['type']) + # Load curve geometry data if new_spline.type == 'BEZIER': - for bezier_point_index in data['splines'][spline]["bezier_points"]: - if bezier_point_index != 0: - new_spline.bezier_points.add(1) - dump_anything.load( - new_spline.bezier_points[bezier_point_index], data['splines'][spline]["bezier_points"][bezier_point_index]) - + bezier_points = new_spline.bezier_points + bezier_points.add(spline['bezier_points_count']) + np_load_collection(spline['bezier_points'], bezier_points, SPLINE_BEZIER_POINT) + # Not really working for now... # See https://blender.stackexchange.com/questions/7020/create-nurbs-surface-with-python if new_spline.type == 'NURBS': - new_spline.points.add(len(data['splines'][spline]["points"])-1) - for point_index in data['splines'][spline]["points"]: - dump_anything.load( - new_spline.points[point_index], data['splines'][spline]["points"][point_index]) + logger.error("NURBS not supported.") + # new_spline.points.add(len(data['splines'][spline]["points"])-1) + # for point_index in data['splines'][spline]["points"]: + # loader.load( + # new_spline.points[point_index], data['splines'][spline]["points"][point_index]) + loader.load(new_spline, spline) def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = dump_anything.Dumper() + dumper = Dumper() data = dumper.dump(pointer) data['splines'] = {} - dumper = utils.dump_anything.Dumper() - dumper.depth = 3 - for index, spline in enumerate(pointer.splines): - spline_data = dump_anything.dump(spline) - spline_data['points'] = dumper.dump(spline.points) - spline_data['bezier_points'] = dumper.dump(spline.bezier_points) - spline_data['type'] = dumper.dump(spline.type) + dumper.depth = 2 + spline_data = dumper.dump(spline) + # spline_data['points'] = np_dump_collection(spline.points, SPLINE_POINT) + spline_data['bezier_points_count'] = len(spline.bezier_points)-1 + spline_data['bezier_points'] = np_dump_collection(spline.bezier_points, SPLINE_BEZIER_POINT) data['splines'][index] = spline_data - if isinstance(pointer, T.SurfaceCurve): data['type'] = 'SURFACE' elif isinstance(pointer, T.TextCurve): @@ -86,4 +106,3 @@ class BlCurve(BlDatablock): elif isinstance(pointer, T.Curve): data['type'] = 'CURVE' return data - diff --git a/multi_user/bl_types/bl_gpencil.py b/multi_user/bl_types/bl_gpencil.py index 7e26bfa..81acd16 100644 --- a/multi_user/bl_types/bl_gpencil.py +++ b/multi_user/bl_types/bl_gpencil.py @@ -22,13 +22,25 @@ import numpy as np from ..libs.dump_anything import (Dumper, Loader, - dump_collection_attr, - load_collection_attr) + np_dump_collection, + np_load_collection) from .bl_datablock import BlDatablock # GPencil data api is structured as it follow: # GP-Object --> GP-Layers --> GP-Frames --> GP-Strokes --> GP-Stroke-Points +STROKE_POINT = [ + 'co', + 'pressure', + 'strength', + 'uv_factor', + 'uv_rotation' + +] + +if bpy.app.version[1] >= 83: + STROKE_POINT.append('vertex_color') + def dump_stroke(stroke): """ Dump a grease pencil stroke to a dict @@ -59,12 +71,7 @@ def dump_stroke(stroke): # Stoke points p_count = len(stroke.points) dumped_stroke['p_count'] = p_count - dumped_stroke['p_co'] = dump_collection_attr(stroke.points,'co') - dumped_stroke['p_pressure'] = dump_collection_attr(stroke.points,'pressure') - dumped_stroke['p_strength'] = dump_collection_attr(stroke.points,'strength') - - if bpy.app.version[1] >= 83: # new in blender 2.83 - dumped_stroke['p_vertex_color'] = dump_collection_attr(stroke.points,'vertex_color') + dumped_stroke['points'] = np_dump_collection(stroke.points, STROKE_POINT) # TODO: uv_factor, uv_rotation @@ -86,13 +93,7 @@ def load_stroke(stroke_data, stroke): stroke.points.add(stroke_data["p_count"]) - load_collection_attr(stroke.points, 'co',stroke_data["p_co"]) - load_collection_attr(stroke.points, 'pressure',stroke_data["p_pressure"]) - load_collection_attr(stroke.points, 'strength',stroke_data["p_strength"]) - - if "p_vertex_color" in stroke_data: - load_collection_attr(stroke.points, 'vertex_color',stroke_data["p_vertex_color"]) - + np_load_collection(stroke_data['points'], stroke.points, STROKE_POINT) def dump_frame(frame): """ Dump a grease pencil frame to a dict diff --git a/multi_user/bl_types/bl_mesh.py b/multi_user/bl_types/bl_mesh.py index cfc2bc5..137cec8 100644 --- a/multi_user/bl_types/bl_mesh.py +++ b/multi_user/bl_types/bl_mesh.py @@ -22,12 +22,30 @@ import mathutils import logging import numpy as np -from ..libs.dump_anything import Dumper, Loader, load_collection_attr, dump_collection_attr +from ..libs.dump_anything import Dumper, Loader, np_load_collection_primitives, np_dump_collection_primitive, np_load_collection, np_dump_collection from ..libs.replication.replication.constants import DIFF_BINARY from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) +VERTICE = ['co'] + +EDGE = [ + 'vertices', + 'crease', + 'bevel_weight', +] +LOOP = [ + 'vertex_index', + 'normal', +] + +POLYGON = [ + 'loop_total', + 'loop_start', + 'use_smooth', + 'material_index', +] class BlMesh(BlDatablock): bl_id = "meshes" @@ -63,27 +81,17 @@ class BlMesh(BlDatablock): target.polygons.add(data["poly_count"]) # LOADING - load_collection_attr(target.vertices, 'co', data["verts_co"]) - load_collection_attr(target.edges, "vertices", data["egdes_vert"]) - if data['use_customdata_edge_crease']: - load_collection_attr(target.edges, "crease", data["edges_crease"]) - - if data['use_customdata_edge_bevel']: - load_collection_attr(target.edges, "bevel_weight", data["edges_bevel"]) - - load_collection_attr(target.loops, 'vertex_index', data["loop_vertex_index"]) - load_collection_attr(target.loops, 'normal', data["loop_normal"]) - load_collection_attr(target.polygons, 'loop_total', data["poly_loop_total"]) - load_collection_attr(target.polygons, 'loop_start', data["poly_loop_start"]) - load_collection_attr(target.polygons, 'use_smooth', data["poly_smooth"]) - load_collection_attr(target.polygons, 'material_index', data["poly_mat"]) + np_load_collection(data['vertices'], target.vertices, VERTICE) + np_load_collection(data['edges'], target.edges, EDGE) + np_load_collection(data['loops'], target.loops, LOOP) + np_load_collection(data["polygons"],target.polygons, POLYGON) # UV Layers for layer in data['uv_layers']: if layer not in target.uv_layers: target.uv_layers.new(name=layer) - load_collection_attr( + np_load_collection_primitives( target.uv_layers[layer].data, 'uv', data["uv_layers"][layer]['data']) @@ -93,7 +101,7 @@ class BlMesh(BlDatablock): if color_layer not in target.vertex_colors: target.vertex_colors.new(name=color_layer) - load_collection_attr( + np_load_collection_primitives( target.vertex_colors[color_layer].data, 'color', data["vertex_colors"][color_layer]['data']) @@ -120,42 +128,31 @@ class BlMesh(BlDatablock): # VERTICES data["vertex_count"] = len(mesh.vertices) - data["verts_co"] = dump_collection_attr(mesh.vertices, 'co') + data["vertices"] = np_dump_collection(mesh.vertices, VERTICE) # EDGES data["egdes_count"] = len(mesh.edges) - data["egdes_vert"] = dump_collection_attr(mesh.edges, 'vertices') - - if mesh.use_customdata_edge_crease: - data["edges_crease"] = dump_collection_attr(mesh.edges, 'crease') - - if mesh.use_customdata_edge_bevel: - data["edges_bevel"] = dump_collection_attr( - mesh.edges, 'edges_bevel') + data["edges"] = np_dump_collection(mesh.edges, EDGE) # POLYGONS data["poly_count"] = len(mesh.polygons) - data["poly_mat"] = dump_collection_attr(mesh.polygons, 'material_index') - data["poly_loop_start"] = dump_collection_attr(mesh.polygons, 'loop_start') - data["poly_loop_total"] = dump_collection_attr(mesh.polygons, 'loop_total') - data["poly_smooth"] = dump_collection_attr(mesh.polygons, 'use_smooth') + data["polygons"] = np_dump_collection(mesh.polygons, POLYGON) # LOOPS data["loop_count"] = len(mesh.loops) - data["loop_normal"] = dump_collection_attr(mesh.loops, 'normal') - data["loop_vertex_index"] = dump_collection_attr(mesh.loops, 'vertex_index') + data["loops"] = np_dump_collection(mesh.loops, LOOP) # UV Layers data['uv_layers'] = {} for layer in mesh.uv_layers: data['uv_layers'][layer.name] = {} - data['uv_layers'][layer.name]['data'] = dump_collection_attr(layer.data, 'uv') + data['uv_layers'][layer.name]['data'] = np_dump_collection_primitive(layer.data, 'uv') # Vertex color data['vertex_colors'] = {} for color_map in mesh.vertex_colors: data['vertex_colors'][color_map.name] = {} - data['vertex_colors'][color_map.name]['data'] = dump_collection_attr(color_map.data, 'color') + data['vertex_colors'][color_map.name]['data'] = np_dump_collection_primitive(color_map.data, 'color') # Fix material index m_list = [] diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index be510a7..fd17b0d 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -21,21 +21,13 @@ import mathutils from .. import utils from ..libs.dump_anything import ( - Dumper, Loader, dump_collection_attr, load_collection_attr, - dump_collection_attr_to_dict, load_collection_attr_from_dict) + Dumper, Loader, np_dump_collection_primitive, np_load_collection_primitives, + np_dump_collection, np_load_collection) from .bl_datablock import BlDatablock -ENUM_METABALL_TYPE = [ - 'BALL', - 'CAPSULE', - 'PLANE', - 'ELLIPSOID', - 'CUBE' -] - -ELEMENTS_FAST_ATTR = [ +ELEMENT = [ 'co', 'hide', 'radius', @@ -43,7 +35,8 @@ ELEMENTS_FAST_ATTR = [ 'size_x', 'size_y', 'size_z', - 'stiffness' + 'stiffness', + 'type' ] @@ -55,11 +48,7 @@ def dump_metaball_elements(elements): :return: dict """ - dumped_elements = {} - - dump_collection_attr_to_dict(dumped_elements, elements, ELEMENTS_FAST_ATTR) - - dumped_elements['type'] = [ENUM_METABALL_TYPE.index(e.type) for e in elements] + dumped_elements = np_dump_collection(elements, ELEMENT) return dumped_elements @@ -71,7 +60,7 @@ def load_metaball_elements(elements_data, elements): :type bpy.types.MetaElement :return: dict """ - load_collection_attr_from_dict(elements_data, elements, ELEMENTS_FAST_ATTR) + np_load_collection(elements_data, elements, ELEMENT) class BlMetaball(BlDatablock): @@ -90,9 +79,9 @@ class BlMetaball(BlDatablock): target.elements.clear() - for element_type in data["elements"]['type']: - new_element = target.elements.new( - type=ENUM_METABALL_TYPE[element_type]) + for mtype in data["elements"]['type']: + print(mtype) + new_element = target.elements.new() load_metaball_elements(data['elements'], target.elements) diff --git a/multi_user/libs/dump_anything.py b/multi_user/libs/dump_anything.py index 62c1f4b..19b4a1d 100644 --- a/multi_user/libs/dump_anything.py +++ b/multi_user/libs/dump_anything.py @@ -30,9 +30,15 @@ BPY_TO_NUMPY_TYPES = { 'BOOL': np.bool } -def load_collection_attr_from_dict(dikt, collection, attributes): +PRIMITIVE_TYPES = ['FLOAT', 'INT', 'BOOLEAN'] + +NP_COMPATIBLE_TYPES = ['FLOAT', 'INT', 'BOOLEAN', 'ENUM'] + +def np_load_collection(dikt: dict, collection: bpy.types.CollectionProperty, attributes: list = None): """ Dump a list of attributes from the sane collection - to the target dikt + to the target dikt. + + Without attribute given, it try to load all entry from dikt. :arg dikt: target dict :type dikt: dict @@ -41,24 +47,59 @@ def load_collection_attr_from_dict(dikt, collection, attributes): :arg attributes: list of attributes name :type attributes: list """ - for attr in attributes: - load_collection_attr(collection, attr, dikt[attr]) + if attributes is None: + attributes = dikt.keys() -def dump_collection_attr_to_dict(dikt, collection, attributes): + for attr in attributes: + attr_type = collection[0].bl_rna.properties.get(attr).type + + if attr_type in PRIMITIVE_TYPES: + np_load_collection_primitives(collection, attr, dikt[attr]) + elif attr_type == 'ENUM': + np_load_collection_enum(collection, attr, dikt[attr]) + else: + logger.error(f"{attr} of type {attr_type} not supported.") + + +def np_dump_collection(collection, attributes=None): """ Dump a list of attributes from the sane collection to the target dikt - :arg dikt: target dict - :type dikt: dict + Without attributes given, it try to dump all properties + that matches NP_COMPATIBLE_TYPES. + :arg collection: source collection :type collection: bpy.types.CollectionProperty :arg attributes: list of attributes name :type attributes: list + :retrun: dict """ - for attr in attributes: - dikt[attr] = dump_collection_attr(collection, attr) + dumped_collection = {} -def dump_collection_attr(collection, attribute): + if len(collection) == 0: + return dumped_collection + + # TODO: find a way without getting the first item + properties = collection[0].bl_rna.properties + + if attributes is None: + attributes = [p.identifier for p in properties if p.type in NP_COMPATIBLE_TYPES and not p.is_readonly] + + logger.error(attributes) + + for attr in attributes: + attr_type = properties[attr].type + + if attr_type in PRIMITIVE_TYPES: + dumped_collection[attr] = np_dump_collection_primitive(collection, attr) + elif attr_type == 'ENUM': + dumped_collection[attr] = np_dump_collection_enum(collection, attr) + else: + logger.error(f"{attr} of type {attr_type} not supported. Only {PRIMITIVE_TYPES} and ENUM supported. Skipping it.") + + return dumped_collection + +def np_dump_collection_primitive(collection, attribute): """ Dump a collection attribute as a sequence !!! warning @@ -85,8 +126,35 @@ def dump_collection_attr(collection, attribute): return dumped_sequence.tobytes() +def np_dump_collection_enum(collection, attribute): + """ Dump a collection enum attribute to an index list -def load_collection_attr(collection, attribute, sequence): + :arg collection: target collection + :type collection: bpy.types.CollectionProperty + :arg attribute: target attribute + :type attribute: bpy.types.EnumProperty + :return: list of int + """ + attr_infos = collection[0].bl_rna.properties.get(attribute) + + assert(attr_infos.type == 'ENUM') + + enum_items = attr_infos.enum_items + return [enum_items[getattr(i, attribute)].value for i in collection] + + +def np_load_collection_enum(collection, attribute, sequence): + attr_infos = collection[0].bl_rna.properties.get(attribute) + + assert(attr_infos.type == 'ENUM') + + enum_items = attr_infos.enum_items + enum_idx = [i.value for i in enum_items] + for index, item in enumerate(sequence): + setattr(collection[index], attribute, enum_items[enum_idx.index(item)].identifier) + + +def np_load_collection_primitives(collection, attribute, sequence): """ Load a collection attribute from a bytes sequence !!! warning @@ -103,9 +171,8 @@ def load_collection_attr(collection, attribute, sequence): assert(attr_infos.type in ['FLOAT', 'INT', 'BOOLEAN']) - # TODO: check types match collection.foreach_set( - attribute, + attribute, np.frombuffer(sequence, dtype=BPY_TO_NUMPY_TYPES.get(attr_infos.type))) From e041b2cb91bfbb3e583f6352f94ca42f83157c2f Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 31 Mar 2020 17:42:14 +0200 Subject: [PATCH 08/13] feat: cleanup --- multi_user/libs/dump_anything.py | 103 +++++++++++++++++++------------ 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/multi_user/libs/dump_anything.py b/multi_user/libs/dump_anything.py index 19b4a1d..0129c4a 100644 --- a/multi_user/libs/dump_anything.py +++ b/multi_user/libs/dump_anything.py @@ -34,10 +34,11 @@ PRIMITIVE_TYPES = ['FLOAT', 'INT', 'BOOLEAN'] NP_COMPATIBLE_TYPES = ['FLOAT', 'INT', 'BOOLEAN', 'ENUM'] + def np_load_collection(dikt: dict, collection: bpy.types.CollectionProperty, attributes: list = None): """ Dump a list of attributes from the sane collection to the target dikt. - + Without attribute given, it try to load all entry from dikt. :arg dikt: target dict @@ -59,9 +60,9 @@ def np_load_collection(dikt: dict, collection: bpy.types.CollectionProperty, att np_load_collection_enum(collection, attr, dikt[attr]) else: logger.error(f"{attr} of type {attr_type} not supported.") - -def np_dump_collection(collection, attributes=None): + +def np_dump_collection(collection: bpy.types.CollectionProperty, attributes: list = None) -> dict: """ Dump a list of attributes from the sane collection to the target dikt @@ -78,28 +79,30 @@ def np_dump_collection(collection, attributes=None): if len(collection) == 0: return dumped_collection - + # TODO: find a way without getting the first item properties = collection[0].bl_rna.properties if attributes is None: - attributes = [p.identifier for p in properties if p.type in NP_COMPATIBLE_TYPES and not p.is_readonly] - - logger.error(attributes) + attributes = [ + p.identifier for p in properties if p.type in NP_COMPATIBLE_TYPES and not p.is_readonly] for attr in attributes: attr_type = properties[attr].type if attr_type in PRIMITIVE_TYPES: - dumped_collection[attr] = np_dump_collection_primitive(collection, attr) + dumped_collection[attr] = np_dump_collection_primitive( + collection, attr) elif attr_type == 'ENUM': dumped_collection[attr] = np_dump_collection_enum(collection, attr) else: - logger.error(f"{attr} of type {attr_type} not supported. Only {PRIMITIVE_TYPES} and ENUM supported. Skipping it.") - + logger.error( + f"{attr} of type {attr_type} not supported. Only {PRIMITIVE_TYPES} and ENUM supported. Skipping it.") + return dumped_collection -def np_dump_collection_primitive(collection, attribute): + +def np_dump_collection_primitive(collection: bpy.types.CollectionProperty, attribute: str) -> str: """ Dump a collection attribute as a sequence !!! warning @@ -126,7 +129,8 @@ def np_dump_collection_primitive(collection, attribute): return dumped_sequence.tobytes() -def np_dump_collection_enum(collection, attribute): + +def np_dump_collection_enum(collection: bpy.types.CollectionProperty, attribute: str) -> list: """ Dump a collection enum attribute to an index list :arg collection: target collection @@ -136,26 +140,42 @@ def np_dump_collection_enum(collection, attribute): :return: list of int """ attr_infos = collection[0].bl_rna.properties.get(attribute) - + assert(attr_infos.type == 'ENUM') enum_items = attr_infos.enum_items return [enum_items[getattr(i, attribute)].value for i in collection] -def np_load_collection_enum(collection, attribute, sequence): +def np_load_collection_enum(collection: bpy.types.CollectionProperty, attribute: str, sequence: list): + """ Load a collection enum attribute from a list sequence + + !!! warning + Only work with Enum + + :arg collection: target collection + :type collection: bpy.types.CollectionProperty + :arg attribute: target attribute + :type attribute: str + :arg sequence: enum data buffer + :type sequence: list + :return: numpy byte buffer + """ + attr_infos = collection[0].bl_rna.properties.get(attribute) assert(attr_infos.type == 'ENUM') enum_items = attr_infos.enum_items enum_idx = [i.value for i in enum_items] - for index, item in enumerate(sequence): - setattr(collection[index], attribute, enum_items[enum_idx.index(item)].identifier) - -def np_load_collection_primitives(collection, attribute, sequence): - """ Load a collection attribute from a bytes sequence + for index, item in enumerate(sequence): + setattr(collection[index], attribute, + enum_items[enum_idx.index(item)].identifier) + + +def np_load_collection_primitives(collection: bpy.types.CollectionProperty, attribute: str, sequence: str): + """ Load a collection attribute from a str bytes sequence !!! warning Only work with int, float and bool attributes @@ -164,6 +184,8 @@ def np_load_collection_primitives(collection, attribute, sequence): :type collection: bpy.types.CollectionProperty :arg attribute: target attribute :type attribute: str + :arg sequence: data buffer + :type sequence: str :return: numpy byte buffer """ @@ -174,7 +196,7 @@ def np_load_collection_primitives(collection, attribute, sequence): collection.foreach_set( attribute, np.frombuffer(sequence, dtype=BPY_TO_NUMPY_TYPES.get(attr_infos.type))) - + def remove_items_from_dict(d, keys, recursive=False): copy = dict(d) @@ -185,7 +207,7 @@ def remove_items_from_dict(d, keys, recursive=False): copy[k] = remove_items_from_dict(copy[k], keys, recursive) return copy - + def _is_dictionnary(v): return hasattr(v, "items") and callable(v.items) @@ -246,7 +268,7 @@ def _load_filter_default(default): class Dumper: - # TODO: support occlude readonly + # TODO: support occlude readonly # TODO: use foreach_set/get on collection compatible properties def __init__(self): self.verbose = True @@ -414,8 +436,8 @@ class BlenderAPIElement: def write(self, value): # take precaution if property is read-only if self.sub_element_name and \ - not self.api_element.is_property_readonly(self.sub_element_name): - + not self.api_element.is_property_readonly(self.sub_element_name): + setattr(self.api_element, self.sub_element_name, value) else: self.api_element = value @@ -473,7 +495,7 @@ class Loader: DESTRUCTOR_REMOVE = "remove" DESTRUCTOR_CLEAR = "clear" - + constructors = { T.ColorRampElement: (CONSTRUCTOR_NEW, ["position"]), T.ParticleSettingsTextureSlot: (CONSTRUCTOR_ADD, []), @@ -482,20 +504,20 @@ class Loader: } destructors = { - T.ColorRampElement:DESTRUCTOR_REMOVE, + T.ColorRampElement: DESTRUCTOR_REMOVE, T.Modifier: DESTRUCTOR_CLEAR, T.Constraint: CONSTRUCTOR_NEW, } element_type = element.bl_rna_property.fixed_type - + constructor = constructors.get(type(element_type)) if constructor is None: # collection type not supported return - destructor = destructors.get(type(element_type)) + destructor = destructors.get(type(element_type)) - # Try to clear existing + # Try to clear existing if destructor: if destructor == DESTRUCTOR_REMOVE: collection = element.read() @@ -503,18 +525,18 @@ class Loader: collection.remove(collection[0]) else: getattr(element.read(), DESTRUCTOR_CLEAR)() - + for dump_idx, dumped_element in enumerate(dump.values()): - if dump_idx == 0 and len(element.read())>0: - new_element = element.read()[0] + if dump_idx == 0 and len(element.read()) > 0: + new_element = element.read()[0] else: try: constructor_parameters = [dumped_element[name] - for name in constructor[1]] + for name in constructor[1]] except KeyError: logger.debug("Collection load error, missing parameters.") continue # TODO handle error - + new_element = getattr(element.read(), constructor[0])( *constructor_parameters) self._load_any( @@ -535,11 +557,12 @@ class Loader: for curve_index, curve in dump['curves'].items(): for point_idx, point in curve['points'].items(): pos = point['location'] - + if len(mapping.curves[curve_index].points) == 1: - mapping.curves[curve_index].points[int(point_idx)].location = pos + mapping.curves[curve_index].points[int( + point_idx)].location = pos else: - mapping.curves[curve_index].points.new(pos[0],pos[1]) + mapping.curves[curve_index].points.new(pos[0], pos[1]) def _load_pointer(self, pointer, dump): rna_property_type = pointer.bl_rna_property.fixed_type @@ -603,9 +626,11 @@ class Loader: (_load_filter_type(mathutils.Matrix, use_bl_rna=False), self._load_matrix), # before float because bl_rna type of vector if FloatProperty (_load_filter_type(mathutils.Vector, use_bl_rna=False), self._load_vector), - (_load_filter_type(mathutils.Quaternion, use_bl_rna=False), self._load_quaternion), + (_load_filter_type(mathutils.Quaternion, + use_bl_rna=False), self._load_quaternion), (_load_filter_type(mathutils.Euler, use_bl_rna=False), self._load_euler), - (_load_filter_type(T.CurveMapping, use_bl_rna=False), self._load_curve_mapping), + (_load_filter_type(T.CurveMapping, use_bl_rna=False), + self._load_curve_mapping), (_load_filter_type(T.FloatProperty), self._load_identity), (_load_filter_type(T.StringProperty), self._load_identity), (_load_filter_type(T.EnumProperty), self._load_identity), From 31feb2439d470cb062b0810c2a7f910e861b0d5d Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 31 Mar 2020 17:52:52 +0200 Subject: [PATCH 09/13] refactor: cleanup --- multi_user/bl_types/bl_metaball.py | 1 - multi_user/libs/dump_anything.py | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index fd17b0d..5663510 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -80,7 +80,6 @@ class BlMetaball(BlDatablock): target.elements.clear() for mtype in data["elements"]['type']: - print(mtype) new_element = target.elements.new() load_metaball_elements(data['elements'], target.elements) diff --git a/multi_user/libs/dump_anything.py b/multi_user/libs/dump_anything.py index 0129c4a..d47e84e 100644 --- a/multi_user/libs/dump_anything.py +++ b/multi_user/libs/dump_anything.py @@ -27,8 +27,7 @@ logger = logging.getLogger(__name__) BPY_TO_NUMPY_TYPES = { 'FLOAT': np.float, 'INT': np.int, - 'BOOL': np.bool -} + 'BOOL': np.bool} PRIMITIVE_TYPES = ['FLOAT', 'INT', 'BOOLEAN'] @@ -84,8 +83,7 @@ def np_dump_collection(collection: bpy.types.CollectionProperty, attributes: lis properties = collection[0].bl_rna.properties if attributes is None: - attributes = [ - p.identifier for p in properties if p.type in NP_COMPATIBLE_TYPES and not p.is_readonly] + attributes = [p.identifier for p in properties if p.type in NP_COMPATIBLE_TYPES and not p.is_readonly] for attr in attributes: attr_type = properties[attr].type @@ -96,8 +94,7 @@ def np_dump_collection(collection: bpy.types.CollectionProperty, attributes: lis elif attr_type == 'ENUM': dumped_collection[attr] = np_dump_collection_enum(collection, attr) else: - logger.error( - f"{attr} of type {attr_type} not supported. Only {PRIMITIVE_TYPES} and ENUM supported. Skipping it.") + logger.error(f"{attr} of type {attr_type} not supported. Only {PRIMITIVE_TYPES} and ENUM supported. Skipping it.") return dumped_collection From fef088e39bc923d0af1947ac68994dedbd1e9635 Mon Sep 17 00:00:00 2001 From: Swann Date: Wed, 1 Apr 2020 10:23:28 +0200 Subject: [PATCH 10/13] refactor: cleanup lattice --- multi_user/bl_types/bl_lattice.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/multi_user/bl_types/bl_lattice.py b/multi_user/bl_types/bl_lattice.py index a19c4ce..1c5443f 100644 --- a/multi_user/bl_types/bl_lattice.py +++ b/multi_user/bl_types/bl_lattice.py @@ -19,9 +19,11 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Dumper, Loader, np_dump_collection, np_load_collection from .bl_datablock import BlDatablock +POINT = ['co', 'weight_softbody', 'co_deform'] + class BlLattice(BlDatablock): bl_id = "lattices" @@ -32,18 +34,19 @@ class BlLattice(BlDatablock): bl_icon = 'LATTICE_DATA' def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) + + np_load_collection(data['points'], target.points, POINT) - for point in data['points']: - utils.dump_anything.load(target.points[point], data["points"][point]) def _construct(self, data): return bpy.data.lattices.new(data["name"]) def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() - dumper.depth = 3 + dumper = Dumper() + dumper.depth = 1 dumper.include_filter = [ "name", 'type', @@ -53,17 +56,10 @@ class BlLattice(BlDatablock): 'interpolation_type_u', 'interpolation_type_v', 'interpolation_type_w', - 'use_outside', - 'points', - 'co', - 'weight_softbody', - 'co_deform' + 'use_outside' ] data = dumper.dump(pointer) + data['points'] = np_dump_collection(pointer.points, POINT) return data - - - - From 776664149e95f03e0cf1c3eec335b97b9dc256c0 Mon Sep 17 00:00:00 2001 From: Swann Date: Wed, 1 Apr 2020 11:34:24 +0200 Subject: [PATCH 11/13] refactor: imports --- multi_user/bl_types/bl_action.py | 13 ++++++------- multi_user/bl_types/bl_armature.py | 10 ++++++---- multi_user/bl_types/bl_camera.py | 9 +++++---- multi_user/bl_types/bl_collection.py | 1 - multi_user/bl_types/bl_datablock.py | 17 +++++++++-------- multi_user/bl_types/bl_image.py | 3 ++- multi_user/bl_types/bl_library.py | 5 +++-- multi_user/bl_types/bl_light.py | 7 ++++--- multi_user/bl_types/bl_lightprobe.py | 7 ++++--- multi_user/bl_types/bl_material.py | 22 ++++++++++++---------- multi_user/bl_types/bl_metaball.py | 6 +++--- multi_user/bl_types/bl_object.py | 19 ++++++++++--------- multi_user/bl_types/bl_scene.py | 7 ++++--- multi_user/bl_types/bl_speaker.py | 7 ++++--- multi_user/bl_types/bl_world.py | 6 +++--- multi_user/presence.py | 6 ++---- multi_user/utils.py | 1 - 17 files changed, 77 insertions(+), 69 deletions(-) diff --git a/multi_user/bl_types/bl_action.py b/multi_user/bl_types/bl_action.py index 40fc124..d1d2823 100644 --- a/multi_user/bl_types/bl_action.py +++ b/multi_user/bl_types/bl_action.py @@ -24,7 +24,7 @@ from enum import Enum from .. import utils from ..libs.dump_anything import ( - Dumper, Loader, np_dump_collection, np_load_collection) + Dumper, Loader, np_dump_collection, np_load_collection, remove_items_from_dict) from .bl_datablock import BlDatablock @@ -41,8 +41,6 @@ KEYFRAME = [ 'interpolation', ] -# TODO: Automatic enum and numpy dump and loading - def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy:bool =True) -> dict: """ Dump a sigle curve to a dict @@ -65,7 +63,7 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy:bool =True) -> dict: fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME) else: # Legacy method - dumper = utils.dump_anything.Dumper() + dumper = Dumper() fcurve_data["keyframe_points"] = [] for k in fcurve.keyframe_points: @@ -109,12 +107,13 @@ def load_fcurve(fcurve_data, fcurve): ) keycache = copy.copy(dumped_keyframe_point) - keycache = utils.dump_anything.remove_items_from_dict( + keycache = remove_items_from_dict( keycache, ["co", "handle_left", "handle_right", 'type'] ) - utils.dump_anything.load(new_kf, keycache) + loader = Loader() + loader.load(new_kf, keycache) new_kf.type = dumped_keyframe_point['type'] new_kf.handle_left = [ @@ -157,7 +156,7 @@ class BlAction(BlDatablock): def _dump(self, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.exclude_filter = [ 'name_full', 'original', diff --git a/multi_user/bl_types/bl_armature.py b/multi_user/bl_types/bl_armature.py index dcf85e3..b35271a 100644 --- a/multi_user/bl_types/bl_armature.py +++ b/multi_user/bl_types/bl_armature.py @@ -19,8 +19,9 @@ import bpy import mathutils -from .. import utils -from .. import presence, operators + +from ..libs.dump_anything import Loader, Dumper +from .. import presence, operators, utils from .bl_datablock import BlDatablock @@ -97,7 +98,8 @@ class BlArmature(BlDatablock): [bone]['parent']] new_bone.use_connect = bone_data['use_connect'] - utils.dump_anything.load(new_bone, bone_data) + loader = Loader() + loader.load(new_bone, bone_data) if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') @@ -110,7 +112,7 @@ class BlArmature(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 4 dumper.include_filter = [ 'bones', diff --git a/multi_user/bl_types/bl_camera.py b/multi_user/bl_types/bl_camera.py index aa4005e..b33b43b 100644 --- a/multi_user/bl_types/bl_camera.py +++ b/multi_user/bl_types/bl_camera.py @@ -19,7 +19,7 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock @@ -36,20 +36,21 @@ class BlCamera(BlDatablock): def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) dof_settings = data.get('dof') # DOF settings if dof_settings: - utils.dump_anything.load(target.dof, dof_settings) + loader.load(target.dof, dof_settings) def _dump_implementation(self, data, pointer=None): assert(pointer) # TODO: background image support - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 2 dumper.include_filter = [ "name", diff --git a/multi_user/bl_types/bl_collection.py b/multi_user/bl_types/bl_collection.py index 87ecc08..4a4d382 100644 --- a/multi_user/bl_types/bl_collection.py +++ b/multi_user/bl_types/bl_collection.py @@ -48,7 +48,6 @@ class BlCollection(BlDatablock): def _load_implementation(self, data, target): # Load other meshes metadata - # dump_anything.load(target, data) target.name = data["name"] # link objects diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 8ddb6eb..802252b 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -20,9 +20,9 @@ import bpy import mathutils from .. import utils +from ..libs.dump_anything import Loader, Dumper from ..libs.replication.replication.data import ReplicatedDatablock from ..libs.replication.replication.constants import (UP, DIFF_BINARY) -from ..libs import dump_anything def has_action(target): @@ -42,7 +42,7 @@ def has_driver(target): def dump_driver(driver): - dumper = dump_anything.Dumper() + dumper = Dumper() dumper.depth = 6 data = dumper.dump(driver) @@ -50,6 +50,7 @@ def dump_driver(driver): def load_driver(target_datablock, src_driver): + loader = Loader() drivers = target_datablock.animation_data.drivers src_driver_data = src_driver['driver'] new_driver = drivers.new(src_driver['data_path']) @@ -57,7 +58,7 @@ def load_driver(target_datablock, src_driver): # Settings new_driver.driver.type = src_driver_data['type'] new_driver.driver.expression = src_driver_data['expression'] - dump_anything.load(new_driver, src_driver) + loader.load(new_driver, src_driver) # Variables for src_variable in src_driver_data['variables']: @@ -70,7 +71,7 @@ def load_driver(target_datablock, src_driver): src_target_data = src_var_data['targets'][src_target] new_var.targets[src_target].id = utils.resolve_from_id( src_target_data['id'], src_target_data['id_type']) - dump_anything.load( + loader.load( new_var.targets[src_target], src_target_data) # Fcurve @@ -82,8 +83,7 @@ def load_driver(target_datablock, src_driver): for index, src_point in enumerate(src_driver['keyframe_points']): new_point = new_fcurve[index] - dump_anything.load( - new_point, src_driver['keyframe_points'][src_point]) + loader.load(new_point, src_driver['keyframe_points'][src_point]) class BlDatablock(ReplicatedDatablock): @@ -127,10 +127,11 @@ class BlDatablock(ReplicatedDatablock): self.pointer = datablock_ref def _dump(self, pointer=None): + dumper = Dumper() data = {} # Dump animation data if has_action(pointer): - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.include_filter = ['action'] data['animation_data'] = dumper.dump(pointer.animation_data) @@ -143,7 +144,7 @@ class BlDatablock(ReplicatedDatablock): data.update(dumped_drivers) if self.is_library: - data.update(dump_anything.dump(pointer)) + data.update(dumper.dump(pointer)) else: data.update(self._dump_implementation(data, pointer=pointer)) diff --git a/multi_user/bl_types/bl_image.py b/multi_user/bl_types/bl_image.py index 8497725..d4aba73 100644 --- a/multi_user/bl_types/bl_image.py +++ b/multi_user/bl_types/bl_image.py @@ -21,6 +21,7 @@ import mathutils import os from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock def dump_image(image): @@ -83,7 +84,7 @@ class BlImage(BlDatablock): assert(pointer) data = {} data['pixels'] = dump_image(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 2 dumper.include_filter = [ "name", diff --git a/multi_user/bl_types/bl_library.py b/multi_user/bl_types/bl_library.py index f53e6de..fb3b0e8 100644 --- a/multi_user/bl_types/bl_library.py +++ b/multi_user/bl_types/bl_library.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs import dump_anything +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock @@ -40,6 +40,7 @@ class BlLibrary(BlDatablock): def dump(self, pointer=None): assert(pointer) - return dump_anything.dump(pointer, 1) + dumper = Dumper() + return dumper.dump(pointer, 1) diff --git a/multi_user/bl_types/bl_light.py b/multi_user/bl_types/bl_light.py index 05b7dbb..6518c1f 100644 --- a/multi_user/bl_types/bl_light.py +++ b/multi_user/bl_types/bl_light.py @@ -19,7 +19,7 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock @@ -35,11 +35,12 @@ class BlLight(BlDatablock): return bpy.data.lights.new(data["name"], data["type"]) def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 3 dumper.include_filter = [ "name", diff --git a/multi_user/bl_types/bl_lightprobe.py b/multi_user/bl_types/bl_lightprobe.py index 3941e19..9f869a5 100644 --- a/multi_user/bl_types/bl_lightprobe.py +++ b/multi_user/bl_types/bl_lightprobe.py @@ -20,7 +20,7 @@ import bpy import mathutils import logging -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) @@ -42,14 +42,15 @@ class BlLightprobe(BlDatablock): logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396") def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) def _dump_implementation(self, data, pointer=None): assert(pointer) if bpy.app.version[1] < 83: logger.warning("Lightprobe replication only supported since 2.83. See https://developer.blender.org/D6396") - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 1 dumper.include_filter = [ "name", diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index beee34c..7db3192 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -21,7 +21,7 @@ import mathutils import logging from .. import utils -from ..libs import dump_anything +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) @@ -34,9 +34,10 @@ def load_node(node_data, node_tree): :arg node_tree: target node_tree :type node_tree: bpy.types.NodeTree """ + loader = Loader() target_node = node_tree.nodes.new(type=node_data["bl_idname"]) - dump_anything.load(target_node, node_data) + loader.load(target_node, node_data) @@ -93,7 +94,7 @@ def dump_node(node): :retrun: dict """ - node_dumper = dump_anything.Dumper() + node_dumper = Dumper() node_dumper.depth = 1 node_dumper.exclude_filter = [ "dimensions", @@ -125,7 +126,7 @@ def dump_node(node): dumped_node['inputs'] = {} for i in node.inputs: - input_dumper = dump_anything.Dumper() + input_dumper = Dumper() input_dumper.depth = 2 input_dumper.include_filter = ["default_value"] @@ -133,7 +134,7 @@ def dump_node(node): dumped_node['inputs'][i.name] = input_dumper.dump( i) if hasattr(node, 'color_ramp'): - ramp_dumper = dump_anything.Dumper() + ramp_dumper = Dumper() ramp_dumper.depth = 4 ramp_dumper.include_filter = [ 'elements', @@ -143,7 +144,7 @@ def dump_node(node): ] dumped_node['color_ramp'] = ramp_dumper.dump(node.color_ramp) if hasattr(node, 'mapping'): - curve_dumper = dump_anything.Dumper() + curve_dumper = Dumper() curve_dumper.depth = 5 curve_dumper.include_filter = [ 'curves', @@ -167,12 +168,13 @@ class BlMaterial(BlDatablock): return bpy.data.materials.new(data["name"]) def _load_implementation(self, data, target): + loader = Loader() target.name = data['name'] if data['is_grease_pencil']: if not target.is_grease_pencil: bpy.data.materials.create_gpencil_data(target) - dump_anything.load( + loader.load( target.grease_pencil, data['grease_pencil']) @@ -182,7 +184,7 @@ class BlMaterial(BlDatablock): target.node_tree.nodes.clear() - dump_anything.load(target,data) + loader.load(target,data) # Load nodes for node in data["node_tree"]["nodes"]: @@ -195,7 +197,7 @@ class BlMaterial(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - mat_dumper = dump_anything.Dumper() + mat_dumper = Dumper() mat_dumper.depth = 2 mat_dumper.exclude_filter = [ "is_embed_data", @@ -223,7 +225,7 @@ class BlMaterial(BlDatablock): data["node_tree"]["links"] = dump_links(pointer.node_tree.links) elif pointer.is_grease_pencil: - gp_mat_dumper = dump_anything.Dumper() + gp_mat_dumper = Dumper() gp_mat_dumper.depth = 3 gp_mat_dumper.include_filter = [ diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index 5663510..865b846 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -19,7 +19,6 @@ import bpy import mathutils -from .. import utils from ..libs.dump_anything import ( Dumper, Loader, np_dump_collection_primitive, np_load_collection_primitives, np_dump_collection, np_load_collection) @@ -75,7 +74,8 @@ class BlMetaball(BlDatablock): return bpy.data.metaballs.new(data["name"]) def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) target.elements.clear() @@ -86,7 +86,7 @@ class BlMetaball(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 1 dumper.exclude_filter = [ "is_editmode", diff --git a/multi_user/bl_types/bl_object.py b/multi_user/bl_types/bl_object.py index 962a46a..a02ee33 100644 --- a/multi_user/bl_types/bl_object.py +++ b/multi_user/bl_types/bl_object.py @@ -20,7 +20,7 @@ import bpy import mathutils import logging -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) @@ -28,8 +28,8 @@ logger = logging.getLogger(__name__) def load_pose(target_bone, data): target_bone.rotation_mode = data['rotation_mode'] - - utils.dump_anything.load(target_bone, data) + loader = Loader() + loader.load(target_bone, data) class BlObject(BlDatablock): @@ -89,7 +89,8 @@ class BlObject(BlDatablock): def _load_implementation(self, data, target): # Load transformation data - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) # Pose if 'pose' in data: @@ -103,7 +104,7 @@ class BlObject(BlDatablock): if not bg_target: bg_target = target.pose.bone_groups.new(name=bg_name) - utils.dump_anything.load(bg_target, bg_data) + loader.load(bg_target, bg_data) # target.pose.bone_groups.get # Bones @@ -112,7 +113,7 @@ class BlObject(BlDatablock): bone_data = data['pose']['bones'].get(bone) if 'constraints' in bone_data.keys(): - utils.dump_anything.load(target_bone, bone_data['constraints']) + loader.load(target_bone, bone_data['constraints']) load_pose(target_bone, bone_data) @@ -140,7 +141,7 @@ class BlObject(BlDatablock): key_data = data['shape_keys']['key_blocks'][key_block] target.shape_key_add(name=key_block) - utils.dump_anything.load( + loader.load( target.data.shape_keys.key_blocks[key_block], key_data) for vert in key_data['data']: target.data.shape_keys.key_blocks[key_block].data[vert].co = key_data['data'][vert]['co'] @@ -153,7 +154,7 @@ class BlObject(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 1 dumper.include_filter = [ "name", @@ -263,7 +264,7 @@ class BlObject(BlDatablock): # SHAPE KEYS object_data = pointer.data if hasattr(object_data, 'shape_keys') and object_data.shape_keys: - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 2 dumper.include_filter = [ 'reference_key', diff --git a/multi_user/bl_types/bl_scene.py b/multi_user/bl_types/bl_scene.py index 739f027..9f58d4f 100644 --- a/multi_user/bl_types/bl_scene.py +++ b/multi_user/bl_types/bl_scene.py @@ -19,7 +19,7 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock class BlScene(BlDatablock): @@ -38,7 +38,8 @@ class BlScene(BlDatablock): def _load_implementation(self, data, target): target = self.pointer # Load other meshes metadata - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) # Load master collection for object in data["collection"]["objects"]: @@ -71,7 +72,7 @@ class BlScene(BlDatablock): assert(pointer) data = {} - scene_dumper = utils.dump_anything.Dumper() + scene_dumper = Dumper() scene_dumper.depth = 1 scene_dumper.include_filter = [ 'name', diff --git a/multi_user/bl_types/bl_speaker.py b/multi_user/bl_types/bl_speaker.py index 5e90780..0928ee2 100644 --- a/multi_user/bl_types/bl_speaker.py +++ b/multi_user/bl_types/bl_speaker.py @@ -19,7 +19,7 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock @@ -32,7 +32,8 @@ class BlSpeaker(BlDatablock): bl_icon = 'SPEAKER' def _load_implementation(self, data, target): - utils.dump_anything.load(target, data) + loader = Loader() + loader.load(target, data) def _construct(self, data): return bpy.data.speakers.new(data["name"]) @@ -40,7 +41,7 @@ class BlSpeaker(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - dumper = utils.dump_anything.Dumper() + dumper = Dumper() dumper.depth = 1 dumper.include_filter = [ "muted", diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index e78ca2a..75ca181 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -19,9 +19,9 @@ import bpy import mathutils -from .. import utils +from ..libs.dump_anything import Loader, Dumper from .bl_datablock import BlDatablock -from .bl_material import load_links, load_node,dump_node, dump_links +from .bl_material import load_links, load_node, dump_node, dump_links class BlWorld(BlDatablock): @@ -54,7 +54,7 @@ class BlWorld(BlDatablock): def _dump_implementation(self, data, pointer=None): assert(pointer) - world_dumper = utils.dump_anything.Dumper() + world_dumper = Dumper() world_dumper.depth = 2 world_dumper.exclude_filter = [ "preview", diff --git a/multi_user/presence.py b/multi_user/presence.py index 975193d..4a3ee19 100644 --- a/multi_user/presence.py +++ b/multi_user/presence.py @@ -135,10 +135,8 @@ def get_bb_coords_from_obj(object, parent=None): def get_view_matrix(): area, region, rv3d = view3d_find() - if area and region and rv3d: - matrix_dumper = utils.dump_anything.Dumper() - - return matrix_dumper.dump(rv3d.view_matrix) + if area and region and rv3d: + return [list(v) for v in rv3d.view_matrix] def update_presence(self, context): global renderer diff --git a/multi_user/utils.py b/multi_user/utils.py index 270766d..d221dff 100644 --- a/multi_user/utils.py +++ b/multi_user/utils.py @@ -28,7 +28,6 @@ import bpy import mathutils from . import environment, presence -from .libs import dump_anything logger = logging.getLogger(__name__) logger.setLevel(logging.WARNING) From 39766739d2a268bc762ac25ad561d8847822cc5f Mon Sep 17 00:00:00 2001 From: Swann Date: Wed, 1 Apr 2020 11:37:05 +0200 Subject: [PATCH 12/13] refactor: move dump_anything to the dump modules --- multi_user/bl_types/bl_action.py | 2 +- multi_user/bl_types/bl_armature.py | 2 +- multi_user/bl_types/bl_camera.py | 2 +- multi_user/bl_types/bl_curve.py | 2 +- multi_user/bl_types/bl_datablock.py | 2 +- multi_user/bl_types/bl_gpencil.py | 2 +- multi_user/bl_types/bl_image.py | 2 +- multi_user/bl_types/bl_lattice.py | 2 +- multi_user/bl_types/bl_library.py | 2 +- multi_user/bl_types/bl_light.py | 2 +- multi_user/bl_types/bl_lightprobe.py | 2 +- multi_user/bl_types/bl_material.py | 2 +- multi_user/bl_types/bl_mesh.py | 2 +- multi_user/bl_types/bl_metaball.py | 2 +- multi_user/bl_types/bl_object.py | 2 +- multi_user/bl_types/bl_scene.py | 2 +- multi_user/bl_types/bl_speaker.py | 2 +- multi_user/bl_types/bl_world.py | 2 +- multi_user/{libs => bl_types}/dump_anything.py | 0 19 files changed, 18 insertions(+), 18 deletions(-) rename multi_user/{libs => bl_types}/dump_anything.py (100%) diff --git a/multi_user/bl_types/bl_action.py b/multi_user/bl_types/bl_action.py index d1d2823..1fc8138 100644 --- a/multi_user/bl_types/bl_action.py +++ b/multi_user/bl_types/bl_action.py @@ -23,7 +23,7 @@ import numpy as np from enum import Enum from .. import utils -from ..libs.dump_anything import ( +from .dump_anything import ( Dumper, Loader, np_dump_collection, np_load_collection, remove_items_from_dict) from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_armature.py b/multi_user/bl_types/bl_armature.py index b35271a..98bef98 100644 --- a/multi_user/bl_types/bl_armature.py +++ b/multi_user/bl_types/bl_armature.py @@ -20,7 +20,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .. import presence, operators, utils from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_camera.py b/multi_user/bl_types/bl_camera.py index b33b43b..178d578 100644 --- a/multi_user/bl_types/bl_camera.py +++ b/multi_user/bl_types/bl_camera.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_curve.py b/multi_user/bl_types/bl_curve.py index c662829..b2ec720 100644 --- a/multi_user/bl_types/bl_curve.py +++ b/multi_user/bl_types/bl_curve.py @@ -23,7 +23,7 @@ import logging from .. import utils from .bl_datablock import BlDatablock -from ..libs.dump_anything import (Dumper, Loader, +from .dump_anything import (Dumper, Loader, np_load_collection, np_dump_collection) diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 802252b..ed58f27 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -20,7 +20,7 @@ import bpy import mathutils from .. import utils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from ..libs.replication.replication.data import ReplicatedDatablock from ..libs.replication.replication.constants import (UP, DIFF_BINARY) diff --git a/multi_user/bl_types/bl_gpencil.py b/multi_user/bl_types/bl_gpencil.py index 81acd16..346d1b5 100644 --- a/multi_user/bl_types/bl_gpencil.py +++ b/multi_user/bl_types/bl_gpencil.py @@ -20,7 +20,7 @@ import bpy import mathutils import numpy as np -from ..libs.dump_anything import (Dumper, +from .dump_anything import (Dumper, Loader, np_dump_collection, np_load_collection) diff --git a/multi_user/bl_types/bl_image.py b/multi_user/bl_types/bl_image.py index d4aba73..4a9ce9c 100644 --- a/multi_user/bl_types/bl_image.py +++ b/multi_user/bl_types/bl_image.py @@ -21,7 +21,7 @@ import mathutils import os from .. import utils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock def dump_image(image): diff --git a/multi_user/bl_types/bl_lattice.py b/multi_user/bl_types/bl_lattice.py index 1c5443f..d816a2c 100644 --- a/multi_user/bl_types/bl_lattice.py +++ b/multi_user/bl_types/bl_lattice.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Dumper, Loader, np_dump_collection, np_load_collection +from .dump_anything import Dumper, Loader, np_dump_collection, np_load_collection from .bl_datablock import BlDatablock POINT = ['co', 'weight_softbody', 'co_deform'] diff --git a/multi_user/bl_types/bl_library.py b/multi_user/bl_types/bl_library.py index fb3b0e8..1057026 100644 --- a/multi_user/bl_types/bl_library.py +++ b/multi_user/bl_types/bl_library.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_light.py b/multi_user/bl_types/bl_light.py index 6518c1f..3bccfe4 100644 --- a/multi_user/bl_types/bl_light.py +++ b/multi_user/bl_types/bl_light.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_lightprobe.py b/multi_user/bl_types/bl_lightprobe.py index 9f869a5..7da2b7e 100644 --- a/multi_user/bl_types/bl_lightprobe.py +++ b/multi_user/bl_types/bl_lightprobe.py @@ -20,7 +20,7 @@ import bpy import mathutils import logging -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index 7db3192..4699711 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -21,7 +21,7 @@ import mathutils import logging from .. import utils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) diff --git a/multi_user/bl_types/bl_mesh.py b/multi_user/bl_types/bl_mesh.py index 137cec8..bd8d618 100644 --- a/multi_user/bl_types/bl_mesh.py +++ b/multi_user/bl_types/bl_mesh.py @@ -22,7 +22,7 @@ import mathutils import logging import numpy as np -from ..libs.dump_anything import Dumper, Loader, np_load_collection_primitives, np_dump_collection_primitive, np_load_collection, np_dump_collection +from .dump_anything import Dumper, Loader, np_load_collection_primitives, np_dump_collection_primitive, np_load_collection, np_dump_collection from ..libs.replication.replication.constants import DIFF_BINARY from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_metaball.py b/multi_user/bl_types/bl_metaball.py index 865b846..22eeea5 100644 --- a/multi_user/bl_types/bl_metaball.py +++ b/multi_user/bl_types/bl_metaball.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import ( +from .dump_anything import ( Dumper, Loader, np_dump_collection_primitive, np_load_collection_primitives, np_dump_collection, np_load_collection) diff --git a/multi_user/bl_types/bl_object.py b/multi_user/bl_types/bl_object.py index a02ee33..9e45ed7 100644 --- a/multi_user/bl_types/bl_object.py +++ b/multi_user/bl_types/bl_object.py @@ -20,7 +20,7 @@ import bpy import mathutils import logging -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock logger = logging.getLogger(__name__) diff --git a/multi_user/bl_types/bl_scene.py b/multi_user/bl_types/bl_scene.py index 9f58d4f..39cbeb4 100644 --- a/multi_user/bl_types/bl_scene.py +++ b/multi_user/bl_types/bl_scene.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock class BlScene(BlDatablock): diff --git a/multi_user/bl_types/bl_speaker.py b/multi_user/bl_types/bl_speaker.py index 0928ee2..3d419f9 100644 --- a/multi_user/bl_types/bl_speaker.py +++ b/multi_user/bl_types/bl_speaker.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock diff --git a/multi_user/bl_types/bl_world.py b/multi_user/bl_types/bl_world.py index 75ca181..7fffb53 100644 --- a/multi_user/bl_types/bl_world.py +++ b/multi_user/bl_types/bl_world.py @@ -19,7 +19,7 @@ import bpy import mathutils -from ..libs.dump_anything import Loader, Dumper +from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock from .bl_material import load_links, load_node, dump_node, dump_links diff --git a/multi_user/libs/dump_anything.py b/multi_user/bl_types/dump_anything.py similarity index 100% rename from multi_user/libs/dump_anything.py rename to multi_user/bl_types/dump_anything.py From bfbf2727ea47f3aa127122ad16bab6dba678029f Mon Sep 17 00:00:00 2001 From: Swann Date: Thu, 2 Apr 2020 12:14:12 +0200 Subject: [PATCH 13/13] fix: material error --- multi_user/bl_types/bl_gpencil.py | 14 ++++++++++++-- multi_user/bl_types/bl_library.py | 2 +- multi_user/bl_types/bl_material.py | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/multi_user/bl_types/bl_gpencil.py b/multi_user/bl_types/bl_gpencil.py index 346d1b5..e3156ed 100644 --- a/multi_user/bl_types/bl_gpencil.py +++ b/multi_user/bl_types/bl_gpencil.py @@ -228,6 +228,9 @@ class BlGpencil(BlDatablock): for mat in data['materials']: target.materials.append(bpy.data.materials[mat]) + loader = Loader() + loader.load(target, data) + # TODO: reuse existing layer for layer in target.layers: target.layers.remove(layer) @@ -244,8 +247,7 @@ class BlGpencil(BlDatablock): load_layer(layer_data, target_layer) - loader = Loader() - loader.load(target, data) + @@ -253,6 +255,14 @@ class BlGpencil(BlDatablock): assert(pointer) dumper = Dumper() dumper.depth = 2 + dumper.include_filter = [ + 'materials', + 'name', + 'zdepth_offset', + 'stroke_thickness_space', + 'pixel_factor', + 'stroke_depth_order' + ] data = dumper.dump(pointer) data['layers'] = {} diff --git a/multi_user/bl_types/bl_library.py b/multi_user/bl_types/bl_library.py index 1057026..f5b1753 100644 --- a/multi_user/bl_types/bl_library.py +++ b/multi_user/bl_types/bl_library.py @@ -41,6 +41,6 @@ class BlLibrary(BlDatablock): def dump(self, pointer=None): assert(pointer) dumper = Dumper() - return dumper.dump(pointer, 1) + return dumper.dump(pointer) diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index 4699711..f230ef1 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -178,7 +178,7 @@ class BlMaterial(BlDatablock): target.grease_pencil, data['grease_pencil']) - elif data["use_nodes"]: + if data["use_nodes"]: if target.node_tree is None: target.use_nodes = True @@ -224,7 +224,8 @@ class BlMaterial(BlDatablock): data["node_tree"]['nodes'] = nodes data["node_tree"]["links"] = dump_links(pointer.node_tree.links) - elif pointer.is_grease_pencil: + + if pointer.is_grease_pencil: gp_mat_dumper = Dumper() gp_mat_dumper.depth = 3