From d0bd4193d925dfea8bc351c81b07a2cbe65d735f Mon Sep 17 00:00:00 2001 From: Swann Date: Fri, 5 Feb 2021 11:22:11 +0100 Subject: [PATCH] fix: nurbs curve feat: curve material support --- multi_user/bl_types/bl_curve.py | 70 +++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/multi_user/bl_types/bl_curve.py b/multi_user/bl_types/bl_curve.py index 00fd0c8..7121b3a 100644 --- a/multi_user/bl_types/bl_curve.py +++ b/multi_user/bl_types/bl_curve.py @@ -24,9 +24,9 @@ import logging from .. import utils from .bl_datablock import BlDatablock from .dump_anything import (Dumper, Loader, - np_load_collection, - np_dump_collection) - + np_load_collection, + np_dump_collection) +from .bl_datablock import get_datablock_from_uuid SPLINE_BEZIER_POINT = [ # "handle_left_type", @@ -68,8 +68,6 @@ CURVE_METADATA = [ 'font_bold', 'font_bold_italic', 'font_italic', - 'make_local', - 'materials', 'name', 'offset', 'offset_x', @@ -79,7 +77,6 @@ CURVE_METADATA = [ 'override_create', 'override_library', 'path_duration', - 'preview', 'render_resolution_u', 'render_resolution_v', 'resolution_u', @@ -113,8 +110,6 @@ CURVE_METADATA = [ ] - - SPLINE_METADATA = [ 'hide', 'material_index', @@ -160,29 +155,37 @@ class BlCurve(BlDatablock): # load splines for spline in data['splines'].values(): new_spline = target.splines.new(spline['type']) - # Load curve geometry data if new_spline.type == 'BEZIER': - bezier_points = new_spline.bezier_points + bezier_points = new_spline.bezier_points bezier_points.add(spline['bezier_points_count']) - np_load_collection(spline['bezier_points'], bezier_points, SPLINE_BEZIER_POINT) - - if new_spline.type == 'POLY': - points = new_spline.points + np_load_collection( + spline['bezier_points'], + bezier_points, + SPLINE_BEZIER_POINT) + + if new_spline.type in ['POLY', 'NURBS']: + points = new_spline.points points.add(spline['points_count']) np_load_collection(spline['points'], points, SPLINE_POINT) - # Not working for now... - # See https://blender.stackexchange.com/questions/7020/create-nurbs-surface-with-python - if new_spline.type == 'NURBS': - logging.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) - + + # MATERIAL SLOTS + target.materials.clear() + for mat_uuid, mat_name in data["material_list"]: + mat_ref = None + if mat_uuid is not None: + mat_ref = get_datablock_from_uuid(mat_uuid, None) + else: + mat_ref = bpy.data.materials.get(mat_name, None) + + if mat_ref is None: + raise Exception("Material doesn't exist") + + target.materials.append(mat_ref) + def _dump_implementation(self, data, instance=None): assert(instance) dumper = Dumper() @@ -210,12 +213,13 @@ class BlCurve(BlDatablock): dumper.include_filter = SPLINE_METADATA spline_data = dumper.dump(spline) - if spline.type == 'POLY': - spline_data['points_count'] = len(spline.points)-1 - spline_data['points'] = np_dump_collection(spline.points, SPLINE_POINT) + spline_data['points_count'] = len(spline.points)-1 + 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) + spline_data['bezier_points'] = np_dump_collection( + spline.bezier_points, SPLINE_BEZIER_POINT) data['splines'][index] = spline_data if isinstance(instance, T.SurfaceCurve): @@ -224,6 +228,10 @@ class BlCurve(BlDatablock): data['type'] = 'FONT' elif isinstance(instance, T.Curve): data['type'] = 'CURVE' + + data['material_list'] = [(m.uuid, m.name) + for m in instance.materials if m] + return data def _resolve_deps_implementation(self): @@ -237,5 +245,9 @@ class BlCurve(BlDatablock): curve.font_bold, curve.font_bold_italic, curve.font_italic]) - - return deps \ No newline at end of file + + for material in self.instance.materials: + if material: + deps.append(material) + + return deps