fix: nurbs curve
feat: curve material support
This commit is contained in:
parent
3f335c7031
commit
d0bd4193d9
@ -24,9 +24,9 @@ import logging
|
|||||||
from .. import utils
|
from .. import utils
|
||||||
from .bl_datablock import BlDatablock
|
from .bl_datablock import BlDatablock
|
||||||
from .dump_anything import (Dumper, Loader,
|
from .dump_anything import (Dumper, Loader,
|
||||||
np_load_collection,
|
np_load_collection,
|
||||||
np_dump_collection)
|
np_dump_collection)
|
||||||
|
from .bl_datablock import get_datablock_from_uuid
|
||||||
|
|
||||||
SPLINE_BEZIER_POINT = [
|
SPLINE_BEZIER_POINT = [
|
||||||
# "handle_left_type",
|
# "handle_left_type",
|
||||||
@ -68,8 +68,6 @@ CURVE_METADATA = [
|
|||||||
'font_bold',
|
'font_bold',
|
||||||
'font_bold_italic',
|
'font_bold_italic',
|
||||||
'font_italic',
|
'font_italic',
|
||||||
'make_local',
|
|
||||||
'materials',
|
|
||||||
'name',
|
'name',
|
||||||
'offset',
|
'offset',
|
||||||
'offset_x',
|
'offset_x',
|
||||||
@ -79,7 +77,6 @@ CURVE_METADATA = [
|
|||||||
'override_create',
|
'override_create',
|
||||||
'override_library',
|
'override_library',
|
||||||
'path_duration',
|
'path_duration',
|
||||||
'preview',
|
|
||||||
'render_resolution_u',
|
'render_resolution_u',
|
||||||
'render_resolution_v',
|
'render_resolution_v',
|
||||||
'resolution_u',
|
'resolution_u',
|
||||||
@ -113,8 +110,6 @@ CURVE_METADATA = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SPLINE_METADATA = [
|
SPLINE_METADATA = [
|
||||||
'hide',
|
'hide',
|
||||||
'material_index',
|
'material_index',
|
||||||
@ -160,29 +155,37 @@ class BlCurve(BlDatablock):
|
|||||||
# load splines
|
# load splines
|
||||||
for spline in data['splines'].values():
|
for spline in data['splines'].values():
|
||||||
new_spline = target.splines.new(spline['type'])
|
new_spline = target.splines.new(spline['type'])
|
||||||
|
|
||||||
|
|
||||||
# Load curve geometry data
|
# Load curve geometry data
|
||||||
if new_spline.type == 'BEZIER':
|
if new_spline.type == 'BEZIER':
|
||||||
bezier_points = new_spline.bezier_points
|
bezier_points = new_spline.bezier_points
|
||||||
bezier_points.add(spline['bezier_points_count'])
|
bezier_points.add(spline['bezier_points_count'])
|
||||||
np_load_collection(spline['bezier_points'], bezier_points, SPLINE_BEZIER_POINT)
|
np_load_collection(
|
||||||
|
spline['bezier_points'],
|
||||||
if new_spline.type == 'POLY':
|
bezier_points,
|
||||||
points = new_spline.points
|
SPLINE_BEZIER_POINT)
|
||||||
|
|
||||||
|
if new_spline.type in ['POLY', 'NURBS']:
|
||||||
|
points = new_spline.points
|
||||||
points.add(spline['points_count'])
|
points.add(spline['points_count'])
|
||||||
np_load_collection(spline['points'], points, SPLINE_POINT)
|
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)
|
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):
|
def _dump_implementation(self, data, instance=None):
|
||||||
assert(instance)
|
assert(instance)
|
||||||
dumper = Dumper()
|
dumper = Dumper()
|
||||||
@ -210,12 +213,13 @@ class BlCurve(BlDatablock):
|
|||||||
dumper.include_filter = SPLINE_METADATA
|
dumper.include_filter = SPLINE_METADATA
|
||||||
spline_data = dumper.dump(spline)
|
spline_data = dumper.dump(spline)
|
||||||
|
|
||||||
if spline.type == 'POLY':
|
spline_data['points_count'] = len(spline.points)-1
|
||||||
spline_data['points_count'] = len(spline.points)-1
|
spline_data['points'] = np_dump_collection(
|
||||||
spline_data['points'] = np_dump_collection(spline.points, SPLINE_POINT)
|
spline.points, SPLINE_POINT)
|
||||||
|
|
||||||
spline_data['bezier_points_count'] = len(spline.bezier_points)-1
|
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
|
data['splines'][index] = spline_data
|
||||||
|
|
||||||
if isinstance(instance, T.SurfaceCurve):
|
if isinstance(instance, T.SurfaceCurve):
|
||||||
@ -224,6 +228,10 @@ class BlCurve(BlDatablock):
|
|||||||
data['type'] = 'FONT'
|
data['type'] = 'FONT'
|
||||||
elif isinstance(instance, T.Curve):
|
elif isinstance(instance, T.Curve):
|
||||||
data['type'] = 'CURVE'
|
data['type'] = 'CURVE'
|
||||||
|
|
||||||
|
data['material_list'] = [(m.uuid, m.name)
|
||||||
|
for m in instance.materials if m]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _resolve_deps_implementation(self):
|
def _resolve_deps_implementation(self):
|
||||||
@ -237,5 +245,9 @@ class BlCurve(BlDatablock):
|
|||||||
curve.font_bold,
|
curve.font_bold,
|
||||||
curve.font_bold_italic,
|
curve.font_bold_italic,
|
||||||
curve.font_italic])
|
curve.font_italic])
|
||||||
|
|
||||||
return deps
|
for material in self.instance.materials:
|
||||||
|
if material:
|
||||||
|
deps.append(material)
|
||||||
|
|
||||||
|
return deps
|
||||||
|
Loading…
x
Reference in New Issue
Block a user