Objective
- I want to create a procedural fence with Geometry Nodes, where the fence may have random plank types.
- The planks must be positioned one after another, without overlap, right after the bounding box of the previous plank.
- The idea is to have dynamic/modular fences, shelves, piles, etc.
Desired output
Different random plank types, perfectly placed one after another without overlap:
My solution for Single Plank Type (Successful)
Using a Mesh Line and a Single Plank Type (Object Info), I managed to set the Mesh Line Offset from the plank object Bounding Box.
The result
Node setup
Multi-Plank Types Problem
- When instances come from a collection, there's no way to know the Bounding Box beforehand, because a object type hasn't still picked from the collection, this way, how could I calculate the Mesh Line offset?
- It's not possible to set the Mesh Line offset after instances are added to the mesh points.
- I managed to create a multi-plank fence, by manually setting the Mesh Line offset with the biggest plank dimension, but then, there's a lot of gap between smaller planks.
The failed result
Node setup for multi-plank without dynamic spacing
What have I tried
- I tried getting the bounding box after Instance on Points, but the Instances output already contains all the planks, not the current instance.
- I tried to think of a way to get the previous instance and then I could get its Bounding Box and set the new plank offset with Set Position.
Question
- How to position dynamic, random objects, perfectly aligned one after another?
- How to know the bounding box or attributes of the previous instance?
- For example, with coding it's a matter of calling
instances[curr_index - 1].bounding_box
and then I can dynamically position the current instance based on the previous bounding box.
- For example, with coding it's a matter of calling
- Is Mesh Line still the ideal entry point for this?
UPDATE - Accumulate Field Node
@Chris answer that suggests using Accumulated Field Node works considering the planks are also randomly generated cubes. But my planks are customized, so they have to come from a collection.
Possibilities that don't work
- A) Get the Bounding Box of the current instance and then use Accumulate Field
- I can't find a way to neither of those. In case (A) I don't know how to first pick a random instance from the collection and then feed Instance on Points with the picked instance.
- B) Get the Bounding Box of the Instance on Points geometry so far and then add it to Accumulate Field and set Mesh Line position.
- It appears that there's no way to get the bounding box of the generated geometry with Instance on Points.
- C) Realize instances, get bounding box and add to accumulate.
Instead of randomly generating Y, I'd need to get the random instance Y size here: