# Chain Curve Example

This tutorial will be dedicated to the use of attributes within VEX code inside the example of curves. The goal will be to use attributes in order to create a metal chain effect on the path of a given curve such as in the image below.

##### Getting a Suitable Curve

At the beginning we need a curve. This is the code we will want to use. It is nothing new compared to previous tutorials on curves.

If the curve is visualised with spheres you will notice how the spheres are unevenly spaced. That would be a problem in out implementation of the chains, which is why we will insert a resample node to sample evenly spaced points on the curve. This way we avoid calculating an arc length parametrization. This is the common standard to have parametrization independent curves.

##### Working with Attributes to Establish Chain Twists

Next we want to put one piece of the chain on each each point of the curve. We had already created the single piece of the chain in the previous tutorial on geometry manipulation.

This is a good moment to use the object merge node for the first time. This node allows you to continue with the output of another node without having to connect a line from it in the network view. At the moment we have the chain curve and the chain piece assigned to different geometries in the root level of the network view.

So how to we work with the chain_piece node output inside the chain_curve? Instead of making a copy it is easier to make the object merge node reference our chain_piece node.

To make the curve look like a chain we need to orient each chain piece along its tangen line and rotate each one as such that every follow up piece is roughly 90° twisted to its predecessor along a specific axis. This extra information for each piece can be written inside the points of the curve using attributes.

We need two more point wranglers to do this. The details of what we are doing inside the code require a wide mathematical theory which is outside of the scope of these tutorials.

Note how the compute tangent node introduced the float attribute named pscale by writing f@pscale = . . . ;. Similarly a 3D vector was created using v@, and a 4D vector through p@. All available types can be found here.

The line in the compute parallel frame node shows how to access the attributes from other points using attrib(0,”point”,”tangent”,0); and also how to set attributes by setpointattrib(geoself(),”orient”,nextPoint,cumQ);.

##### Placing the Chain

Finally we can place our chain links using the copy node. Use a transform node to adjust the sizes of the links and the number of points in the resample node to have a pretty chain. The copy node uses the @orient for the orientation of the copies by default as seen on this link.

The result should be a chain traced along the path of the curve as seen below in render view. The parts of the curve with strong curvature require smaller chain links to look good.