Skip to main content
6 of 7
Add explanations.
StefLAncien
  • 6.7k
  • 5
  • 20

(Using Blender 3.6.8)

(NB: documentation to be continued)

The approach implemented in the following GN graph is:

  • To trim the curve to make its length proportional to the user-defined spacing (dark red part).
  • To spawn on points instances picked in a collection, as many times as required (dark green part).
  • To spawn on the last point a specific instance (dark blue part).

GN Graph

Setup

1. A BezierCurve is added in Object Mode. In Edit Mode, its control points are "hooked" to three empties, used as manipulating handles. The middle one is animated up and down.
2. In Object Mode, one Cube is added at the world origin, then duplicated. This copy is rotated by 45 degrees around its Z axis, remaining centred at the world origin. Both cubes are gathered in a Collection. These are picked in alphabetical order. So their name is edited to control which one is instanced on odd indices (the first one), and which one is instanced on even indices (the second one).
3. In Object Mode, one Sphere is added at the world origin. (NB: Transformations must be "applied" to these objects, cubes and sphere, to spawn).
4. In Object Mode, one Single Vert is added at the world origin. The GeometryNodes modifier is attached to this object. Its Input are:
4.1. Curve: the curve on which to spawn other objects.
4.2. Last: the object to spawn at the last index.
4.3. Collection: the collection containing the objects duplicated along the curve.
4.4. Count: the number of objects to spawn, excluding the last one (labelled $n$).
4.5. Length: the distance between two successive spawned objects (labelled $\lambda$).

Trimming the curve

1. The Geometry of the input curve is recovered through an Object Info node.
2. Let $L$ be its Length, evaluated with a Curve Length node. It is assumed that $L \ge \lambda$. Let $N$ be an integer such that $N+1$ is the maximum number of points along the curve separated exactly by the length $\lambda$. Let $l$ be a length such that $l \lt \lambda$. $N$ and $l$ are defined by the relation $L = N \lambda + l$.
3. Consequently $N$ is computed as the truncated part of $\frac{L}{\lambda}$.
4. The input curve length is reduced to $N \lambda$ using a Trim Curve node.
5. Eventually, $N+1$ points are interpolated along the trimmed curve with a Curve to Points node set in Count mode. It is returning a Rotation vector per point, which aligns the Z axis of an object with the local tangent to the curve.
6. For subsequent operations, the number of duplicated objects is limited to the Minimum between the user-defined value $n$ and the computed value $N$ to not exceed the length $N\lambda$.

Spawning duplicated objects from collection

1. Duplicated objects are spawned by an Instance on Points node.
2. The Selection of the points sampled along the curve to use is based on a Less Than node comparing these points Index with $n$ (or $N$ if $n \gt N$). As Index value starts at 0, it yields that exactly $n$ points with an Index value in the range $[0,n-1]$ are selected.
3. Individual objects to spawn are picked from a user-defined collection. This behaviour is controlled by the Pick Instance check-box and by the Instance Index socket. As it is left unconnected, the point Index is used to choose which object to spawn. Because there are only two objects in the collection, the first one is used for even indices (starting at 0) while the second one is used for odd indices (starting at 1).
4. Instances are recovered from the collection using a Collection Info node. The Separate Children socket is controlling that only one object at a time is picked, not the whole collection.
5. The Rotation vector output by the Curve to Points node is directly connected to the Rotation input socket to align the Z axis of the spawned objects with the local tangent to the curve.

Spawning the last object

Resources

StefLAncien
  • 6.7k
  • 5
  • 20