From 9f59e7b6e895a720187eb83725cc6779320f1c84 Mon Sep 17 00:00:00 2001 From: Swann Date: Tue, 10 Mar 2020 18:00:23 +0100 Subject: [PATCH] fix: curve commit error Releated to #72 --- README.md | 32 +++++++++--------- multi_user/bl_types/bl_curve.py | 58 +++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 567059a..28ba30a 100644 --- a/README.md +++ b/README.md @@ -25,22 +25,22 @@ See the [documentation](https://multi-user.readthedocs.io/en/latest/) for detail Currently, not all data-block are supported for replication over the wire. The following list summarizes the status for each ones. -| Name | Status | Comment | -| ----------- | :----------------: | :------------: | -| action | :exclamation: | Not stable | -| armature | :exclamation: | Not stable | -| camera | :white_check_mark: | | -| collection | :white_check_mark: | | -| curve | :white_check_mark: | Not tested | -| gpencil | :white_check_mark: | | -| image | :exclamation: | Not stable yet | -| mesh | :white_check_mark: | | -| material | :white_check_mark: | | -| metaball | :white_check_mark: | | -| object | :white_check_mark: | | -| scene | :white_check_mark: | | -| world | :white_check_mark: | | -| lightprobes | :white_check_mark: | | +| Name | Status | Comment | +| ----------- | :----------------: | :--------------------------------: | +| action | :exclamation: | Not stable | +| armature | :exclamation: | Not stable | +| camera | :white_check_mark: | | +| collection | :white_check_mark: | | +| curve | :white_check_mark: | Nurbs surface don't load correctly | +| gpencil | :white_check_mark: | | +| image | :exclamation: | Not stable yet | +| mesh | :white_check_mark: | | +| material | :white_check_mark: | | +| metaball | :white_check_mark: | | +| object | :white_check_mark: | | +| scene | :white_check_mark: | | +| world | :white_check_mark: | | +| lightprobes | :white_check_mark: | | ### Performance issues diff --git a/multi_user/bl_types/bl_curve.py b/multi_user/bl_types/bl_curve.py index 66ff445..232377f 100644 --- a/multi_user/bl_types/bl_curve.py +++ b/multi_user/bl_types/bl_curve.py @@ -1,8 +1,11 @@ import bpy +import bpy.types as T import mathutils from .. import utils from .bl_datablock import BlDatablock +from ..libs import dump_anything + class BlCurve(BlDatablock): bl_id = "curves" @@ -13,51 +16,58 @@ class BlCurve(BlDatablock): bl_icon = 'CURVE_DATA' def construct(self, data): - return bpy.data.curves.new(data["name"], 'CURVE') + return bpy.data.curves.new(data["name"], data["type"]) - def load(self, data, target): - utils.dump_anything.load(target, data) + def load_implementation(self, data, target): + dump_anything.load(target, data) target.splines.clear() # load splines for spline in data['splines']: new_spline = target.splines.new(data['splines'][spline]['type']) - utils.dump_anything.load(new_spline, data['splines'][spline]) - + dump_anything.load(new_spline, data['splines'][spline]) + # Load curve geometry data - for bezier_point_index in data['splines'][spline]["bezier_points"]: - if bezier_point_index != 0: - new_spline.bezier_points.add(1) - utils.dump_anything.load( - new_spline.bezier_points[bezier_point_index], data['splines'][spline]["bezier_points"][bezier_point_index]) - - for point_index in data['splines'][spline]["points"]: - new_spline.points.add(1) - utils.dump_anything.load( - new_spline.points[point_index], data['splines'][spline]["points"][point_index]) + 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]) + + # 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]) def dump_implementation(self, data, pointer=None): assert(pointer) - data = utils.dump_datablock(pointer, 1) + dumper = dump_anything.Dumper() + + data = dumper.dump(pointer) data['splines'] = {} dumper = utils.dump_anything.Dumper() dumper.depth = 3 - - for index,spline in enumerate(pointer.splines): - spline_data = {} + + 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) data['splines'][index] = spline_data - if isinstance(pointer,'TextCurve'): - data['type'] = 'TEXT' - if isinstance(pointer,'SurfaceCurve'): + + if isinstance(pointer, T.SurfaceCurve): data['type'] = 'SURFACE' - if isinstance(pointer,'TextCurve'): + elif isinstance(pointer, T.TextCurve): + data['type'] = 'FONT' + elif isinstance(pointer, T.Curve): data['type'] = 'CURVE' return data def is_valid(self): - return bpy.data.curves.get(self.data['name']) + return bpy.data.curves.get(self.data['name']) \ No newline at end of file