Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output curve tilt & radius values for Bezier curves #5167

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/nodes/exchange/bezier_in.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ This node has the following outputs:
* **Curves**. Generated Curve objects.
* **ControlPoints**. Control points of Bezier curves. This output contains a list of 4 points for each segments of each Bezier curve.
* **Matrices**. Transformation matrices of selected objects.
* **Tilt**. Tilt values from Blender's curve object. This output contains one
value for each Bezier's control point in Blender terms (or, in more strict
terms, one value for each point where one Bezier segment ends and new one
starts).
* **Radius**. Radius values from Blender's curve object. Similar to **Tilt** output.

25 changes: 21 additions & 4 deletions nodes/exchange/bezier_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def sv_init(self, context):
self.outputs.new('SvCurveSocket', 'Curves')
self.outputs.new('SvVerticesSocket', 'ControlPoints')
self.outputs.new('SvMatrixSocket', 'Matrices')
self.outputs.new('SvStringsSocket', 'Tilt')
self.outputs.new('SvStringsSocket', 'Radius')

def get_objects_from_scene(self, ops):
"""
Expand Down Expand Up @@ -137,7 +139,6 @@ def get_curve(self, spline, matrix):
if spline.use_cyclic_u:
pairs = list(pairs) + [(spline.bezier_points[-1], spline.bezier_points[0])]
points = []
is_first = True
for p1, p2 in pairs:
c0 = p1.co
c1 = p1.handle_right
Expand All @@ -150,10 +151,18 @@ def get_curve(self, spline, matrix):
points.append([c0, c1, c2, c3])
segment = SvCubicBezierCurve(c0, c1, c2, c3)
segments.append(segment)

tilt_values = []
radius_values = []
if self.concat_segments:
return points, concatenate_curves(segments)
tilt_values = [p.tilt for p in spline.bezier_points]
radius_values = [p.radius for p in spline.bezier_points]
return points, tilt_values, radius_values, concatenate_curves(segments)
else:
return points, segments
for p1, p2 in pairs:
tilt_values.append([p1.tilt, p2.tilt])
radius_values.append([p1.radius, p2.radius])
return points, tilt_values, radius_values, segments

def process(self):

Expand All @@ -163,6 +172,8 @@ def process(self):
curves_out = []
matrices_out = []
controls_out = []
tilt_out = []
radius_out = []
for item in self.object_names:
object_name = item.name
obj = bpy.data.objects.get(object_name)
Expand All @@ -177,14 +188,20 @@ def process(self):
if spline.type != 'BEZIER':
self.warning("%s: not supported spline type: %s", spline, spline.type)
continue
controls, curve = self.get_curve(spline, matrix)
controls, tilt_values, radius_values, curve = self.get_curve(spline, matrix)
curves_out.append(curve)
controls_out.append(controls)
matrices_out.append(matrix)
tilt_out.append(tilt_values)
radius_out.append(radius_values)

self.outputs['Curves'].sv_set(curves_out)
self.outputs['ControlPoints'].sv_set(controls_out)
self.outputs['Matrices'].sv_set(matrices_out)
if 'Tilt' in self.outputs:
self.outputs['Tilt'].sv_set(tilt_out)
if 'Radius' in self.outputs:
self.outputs['Radius'].sv_set(radius_out)


def register():
Expand Down