So I have made a fence using the array and curve modifiers. I can then use the displacement modifier to add some vertical and depth noise to the mesh to make it look more irregular and not perfectly straight.

But is there a way to add "rotational displacement" to my fence as well? So that in some places the fence is tilting to one direction and in some other place it is tilting to other direction? Tilting randomly along its longitudinal axis for example?


1 Answer 1


Here are two ways in which you can accomplish this:

1) Modify the curve's twist

A bezier curve has the often ignored feature twist that you can set per control point to influence the direction in which the boards are pointing. You can set the twist manually in edit mode by selecting a control point and pressing Ctrl+T, but if you want to create the impression of randomness you will need a lot of control points and manually setting the tilt is going to be tedious.

The following Python script assigns a random tilt to each control point of a bezier curve.

import bpy
import random
from math import pi

curve = bpy.data.objects['Circle']
points = curve.data.splines[0].bezier_points

for point in points:
    point.tilt = random.uniform(-pi/16, pi/16)

Adding the array and curve modifiers to the fence element will allow the fence to distort which is maybe useful for a wire-link fence but may cause ugly deformation of the fence poles.

fence on flat ground

connected fence on hill

For a fence consisting of disconnected planks, instead of a regular object array I use a plane array with duplifaces according to this or this answer, so the fence boards don't get distorted. I.e. add a plane, with modifiers array and curve, activate duplication in the plane's Object tab in the properties panel and parent a single fence board to the plane.

I guess it might be possible to try to mix these two approaches, i.e. use regular array for the mesh and duplifaces for the poles. As I don't have a wire-link mesh model available, I couldn't test it on one of those. Tests with a fence like above with horizontal bars were nonsatisfying.

result of using curve's twist

2) Place the boards with Animation Nodes

Using the addon Animation Nodes allows you to place fence boards automatically at the desired location with the right orientation.

Here I use Animation Node's Evaluate Spline node to sample a number ob points along the bezier curve – and for each point get the coordinates as well as the tangent at that point. I project the tangent to the XY plane so that the standard orientation is “up” and not normal on the surface. This part is optional for a flat ground, but looks better if you place the fence on a hill.

main node tree

I feed the coordinates, and the projected tangents into a loop. For each pair I create a random rotation with the Euler Wiggle node. The amplitudes of the wiggle node affect the amount of randomness for each axis.

rotation loop

There would be room for optimization, e.g. as the wiggle Evolution is linear whereas it might be desirable to match the evolution parameter at the start of the curve to the end of the curve, as it's a closed loop.

I combine the three transformations wiggle, rotation according to the tangent, and translation to the correct coordinate.

Back in the main node tree I place copies of the original board, each board with a transformation from the loop.

I also set a random shape key value for each board to get a random board height – similar to the random particle approach when using Dupligroups.

random shape key

result using animation nodes

  • $\begingroup$ This looks super cool! I'll look at this soon. However this looks like it doesn't merge the pieces? The fence I have is actually a wire fence, like this: jooinn.com/images/barbed-wire-fence-1.jpg I tried something similar earlier with particles and merging was an issue there too. $\endgroup$
    – Life
    Sep 11, 2018 at 14:49
  • $\begingroup$ I tried running the python code but nothing happens. Maybe my curve settings are wrong. I don't know anything about python so I can only assume it is supposed to be the full code. I have my system console open and there are no errors. The animation node doesn't work for because I need the pieces to merge at joints because the fence is continuous mesh, not long object made of separate meshes. Thanks for the suggestion though. $\endgroup$
    – Life
    Sep 11, 2018 at 16:42
  • $\begingroup$ @Life Sorry to hear that. Getting the animation nodes method to play well with a connected fence is more complicated, The twist method however should still work. For a wire-link fence probably best without duplication and with regular array. But apart from the name of the Bezier curve – and even that one should raise an error – I can't think of a reason for the problem. Could you maybe try manually twisting one or two control points to see if this has any effect at all? $\endgroup$
    – binweg
    Sep 11, 2018 at 19:28
  • $\begingroup$ Manually twisting does work. I tried changing some curve parameters but don't see any change. If I put wrong name of the curve I get an error so at least the python code runs but doesn't do anything. Then I tried to apply all the modifiers for the curve (it had shrinkwrap to keep it on ground) and now I get tons of "Invalid clnors in this fan" errors and complaints about non-uniform scale. I resetted the scales (some were not 1). Then applied all modifiers for the mesh and I get this error: "Info: applied modifier only changed CV points, not tessellated/bevel vertices". I have no clue :) $\endgroup$
    – Life
    Sep 12, 2018 at 2:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .