This is difficult to solve as each segment's position is calculated individually. The usual way we deal with this situation is to make a "panel" of pickets about the right size to fit between the posts.
And then use that in the default input with the Generator's mode set to Scale. If you make the panel with RailClone you can easily adjust the size to be sure it fits into fences with different evely distances.
I've also had a go at creating this using a single style and an expression, but be warned this is a bit experimental
To do this I wanted to get the position on the Z axis of the beginning of a spline section (a section is defined as the space between corners, evenly, start or end segments). The theory is that this can then be reused for the other segments in that section to keep them level. Unfortunately, as mentioned, each segments position is returned and calculated individually, but I did find a workaround - here's how it works.
1 - Add a transform Operator to the Picket segment and export Z Fixed Transform
2 - Wire an Arithmetic operator to the exported Z Transform input
3 - Add the Expression -XSplineCoords.z+Input1
. This moves the pickets down the same distance the spline had moved them up. Essentially resetting them so that are level with the spline's first vertex. We haven't created a value for Input1 yet, but this will be the distance required to move the pickets back to the correct location.
4 - Wire a Random parameter node to Input1 and export Min and Max (Scene Units). You can use this as a kind of variable that only updates on each section by changing the Generate On
property to X Spline Section
. In this mode all the segments in each spline section will take the same value.
5 - Wire an arithmetic operator to the exported Min and Max inputs of the randomise node. Set Operation
and enter XSplineCoords.z
By doing this the random operator will sample the Z position only once at the beginning of the section. This can then be re-used for all the segments in that section to move them up from their reset position.
Something to keep in mind is that the RailClone objects local axis position must also be level with vertex 1 for this to work correctly. The easiest way to move it is to click Realign
from the Base Objects rollout.
Attached is a sample file with both techniques. I hope that helps, let me know if you have any further question.