6
$\begingroup$

Animation nodes has a Hair Data node that allows you to get Splines from Particle Hair strands. However, it does not seem to output child hair strands. Is there any way to get the Child hair strands as splines or edges too?

$\endgroup$
  • $\begingroup$ I don't think it is possible. Children particles aren't "real" they follow the existing parent particle based on child settings. I expect they are dynamically calculated as needed so don't have any real data to read from that can be exposed in AN. $\endgroup$ – sambler Feb 18 '18 at 9:03
  • $\begingroup$ @sambler 's point does indeed seem to be true, check: developer.blender.org/T33287 $\endgroup$ – Omar Emara Feb 18 '18 at 15:42
  • $\begingroup$ Children splines can be generated inside Animation Nodes with similar results. Would you be interested in a workflow where one create children splines inside Animation Nodes? $\endgroup$ – Omar Emara Feb 18 '18 at 18:36
  • $\begingroup$ @OmarAhmad yes, that would be great. I'm trying to get similar behavior to particle children in terms of offset and noise from the parent, but I want to turn it all into mesh/curves in the end. $\endgroup$ – Drudge Feb 18 '18 at 21:47
  • $\begingroup$ I will get to answering the question then :). May couple of days. $\endgroup$ – Omar Emara Feb 19 '18 at 20:20
9
+50
$\begingroup$

Problem Definition

Animation Nodes provides a set of nodes that returns some information about particle systems, however, non of which provides any information regarding hair children, and this is a known limitation in blender.

To get around this, we shall replicate the children system in blender's particle system using Animation Nodes.

Inputs

Our input is a list of poly splines that represents the hair returned by the Hair Data Node :

Inputs


Each of the following section will concern with on particular aspect about children, any section can be ignored if it has no need for you. We shall attempt to replicate all children options.

Children Generation

Given a single spline that represents a single hair, the simplest of things we can do to generate some children would be as following. We can make copies of that spline, move them around in random directions and return them. Animation Node have a particular node that does exactly that, the Replicate Spline Node:

Simple Children

Notice that the used transformations acts as offsets to the original spline locations, this is due to the fact that splines are described in global space, something we have defined in the Hair Data Node. So it is sufficient to use the output of the random vector node directly.

Tangent Based Offsets

The previouse simple method imposes certain effect that you might consider faulty, since the hair can move freely in any direction, it might move away from the surface and be considered detached from the mesh. A solution is to restrict the motion to the two axis that are perpendicular to the tangent. There are many ways which we can do this, the simplest of which would be to project the random vectors on the plane with normal equal to the tangent at the start of the splines:

Simple Tangent Children

Notice that the magnitude of the random vector may change based on the angle they make with the normal of the plane, so you might want to renormalize the random vectors accordingly. A more efficient method to do that same thing would be to compute two perpendicular vector that are perpendicular to the tangent, Animation Nodes already gives us one of those vectors, the Normal vector (Though it can still be computed by taking the cross product between the tangent and some arbitrary unit vector), if we take the cross product between the tangent and the normal, we will get a cotangent that is perpendicular to both vectors, if we define the random vectors as a linear combination between the normal and the cotangent, we will get similar results to the projection method:

Simple Normal Cross Children

Remember that a linear combination between two vectors is the sum of the vectors multiplied by some scalar, in this case, random scalars. This works because both vectors are linearly independent from the tangent, this guarantee there won't be an offset along the tangent direction.

Surface Normal Based Offsets

Using the tangent of the first bit of the hair spline may not achieve the result we are looking for, this is due to the fact that if the angle between the tangent and the surface normal at that point is high enough, the offset will still be away from the surface and subsequently it will look detached ! So a possible fix is to use the surface normal at that point instead, to get the surface normal at the tip of the hair, we can use the BVH Find Nearest Surface Point Node:

Simple Surface Normal Children

This, I think, is the method blender uses because it gives very similar if not identical results to the children hairs. It should be noted that this method is more expensive than other methods because it required BVH operations which are costly for large data sets.

Advanced Point To Point Offsets

To really get fine control over the output spline, we will take it a step deeper and edit the individual points of of the spline. We will first evaluate some points on the spline, get their locations, normals and cotangents, to get the cotangent, we use the cross product as we learned before. Then we create a loop that has two iterators which are some random values that we will use as scalars in the linear combination just as before, inside the loop, we perform the linear combination and create a poly spline from the result and return them:

Advanced Point To Point Offsets

Now that we have a good base children hair, we can go ahead and add some effects to it.

Clump Effect

A clump effect is making the hair closer to each other at the tip or the root of the hair, since we are actually offsetting the children's points, all we have to do is to scale down the offset factor based on the location along the hair, for instance, if we were to clump the hair at its root, will will multiply the scalars of the linear combination by some small value for points near the root and leave the scalars of the points at the tip as this, in other words, we will multiply all the scalars by values ranging from zero to one where zero is at the root and one is at the tip:

Simple Clump

The added nodes are highlighted in blue. If I want the clumping to happen at the tip, I simply have to invert the values of the interval:

Inverse Simple Clump

Let us take it a step further and control the clump factor using an interpolation curve, all we have to do is to evaluate the interpolation at the values we used before:

Interpolation Clump

Which gives the effect:

Interpolation Clump Result

Randomize Hair Points

Adding noise to the hair is as easy as adding the random vectors on the hair points, so I will leave this one to you.

Hair Trimming

We can trim hair using the Trim Spline Node:

Trim Hair

We can also input random values from the trim node:

Random Hair Trim

Which results:

Random Hair Trim Results

Hair Noise

We can use Animation Node's noise functions to offset hair points and making it look a bit noisy:

Hair Noise

Noise can be evaluated three times to construct a vector noise which can be add on the final point locations instead of the offset factor.

Curl Kink

Curl king is shaping the hair as a helix. This can be done by adding a vector defined by the parametric equation of the circle ($x = cos(t), y = \sin(t)$) where the parameter $t$ is a scalar multiple of the index of the point along each hair, this is exactly the equation of the helix except we are using the normal and contangent as the fundamental vectors of the space where is the normal helix equation is defined in terms of the $x$ and $y$ fundamental vectors:

Curl

Which results:

Curl Result

Notice that we can optimize the node tree by putting the interpolation and kink computations outside the loop since it is constant for all hair strands:

Optimized Interpolation And Curl

Radial Kink

Radial kink is making the hair oscillate as a sine wave radially around the base hair, so it is as simple as adding a sine wave by the factor we generated from the interpolation:

Radial Kink


I have shown most of the effects achievable through hair children system in blender, there are millions of other ways to control the children, I think I have showed the workflow and you will be able to do whatever you want yourself. Finally, here is a sample blend file for a combination of effects to play with and explore:

$\endgroup$
  • $\begingroup$ Another amazing answer! I'm trying out your file, but the 4 Vector Math Scale nodes in the bottom loop are all giving me a 'lists have different length' error and the script doesn't seem to be generating anything. Do you know why this is? I have not changed any settings. $\endgroup$ – Drudge Feb 23 '18 at 9:00
  • $\begingroup$ @Drudge Can you measure the length of each list that is going in those node and report back? using the Get List Length Node. $\endgroup$ – Omar Emara Feb 23 '18 at 16:30
  • $\begingroup$ Upon looking closer, it looks like a lot of nodes in the whole setup are no longer connected together. This is also happening in other files. In the Skin Modifier filed you shared, NONE of the nodes are connected at all. This seems like a problem with versions or something. Can you tell me what version of Animation Nodes, and what version of blender you are using? I have 2.79 release and AN 2.0.4 $\endgroup$ – Drudge Feb 23 '18 at 21:16
  • $\begingroup$ @Drudge I see, I am sorry, I didn't know that this would be a problem. I am using v2.1 which isn't released yet. Will you be able to compile 2.1 yourself? If not, I will try to downgrade my version and build the node tree again. $\endgroup$ – Omar Emara Feb 24 '18 at 14:09
  • $\begingroup$ @Drudge Found out what is wrong. Spline normals output was added in version 2.1 so the node tree will not work in your version. Let me know if you can compile it, what OS are you using? $\endgroup$ – Omar Emara Feb 24 '18 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.