18. September 2023

Turning Edges into Spline Segments

Turning the edges of a polygon object, parametric or not, into a set of spline segments is both straight forward and complex.

Spline-Primitive-Edges-to-Spline.c4d

Assembling the end points of the edges to a list of paired positions requires the user to mix the two resulting lists, one for start points and one for end points, to be mixed so each matching end point follows its start point. Why? For this we need to look into how the Topology of splines works.

A Spline is defined by the positions of the points and the Topology, which defines in which relationship the points are towards each other. Without going to deep into this, maybe at a later point, it is sufficient to say the Assemble Spline requires the data on Positions, Segments, Tangents and Corners in a specific shape. Corners are a very special case basically only used in fonts so we can ignore it here.

The Segments input accepts an array of integer, where each value defines the number of positions used within a segment. The Positions/Points them self come as an array of vectors Array<Vector>.

Let us assume we have four positions and want to create two segments with two points each. The array for the segments, an Array<Integer>, would then look like this {2,2}. All elements in this array added up need to be equal to the number of positions/points provided, since the first segment will use points 0 and 1, while the second segment will use the points 2 and 3.

The Tangent input is directly related to the Points input and has the same number of elements, though the tangent datatype is a bit more complex than a simple vector. For each points tangent there is a tuple of two vectors so the whole Tangent information is structured like this Array<Tuple<Vector, Vector>>

You might recognize this from the structural information of a Cinema 4D Bezier Spline that basically holds the same information.

One vector represents the incoming tangent, the other the outgoing one.

Creating the tangents for the curved mode of this setup requires a bit of math, the most complex thing you need is the cross product.

Since we create as many segments as we have edges we only have to take one of the tangent vectors of each point into account. From the normal of the point and the difference vector we calculate a vector that is perpendicular to both. Then use this new vector and the normal again to create a second vector that points away from position and is perpendicular to the normal. This will make the transition from the point smooth and provide the rounded look we want. The length is 1/4 of the distance between the two edge points. In general this gives a pleasing result, but it can be varied if wanted.

The same is done for the second point.

The result of this are spline segments that smoothly come together at the points of a geometry

A general note: While we can set the type of spline in the Assemble Spline node, it is also necessary to make sure the correct Spline type is chosen in the Subdivision settings of the Nodes Spline/Spline Primitive object