Fill a nurbs cylinder with curves. Hit me with every idea you have!

EDIT: Forgot to say that I’m using Maya.

I’ve been thinking about this for a long time, but have postponed it because I thought I had to learn plugin development for it to be plausible with some high concepts math etc.
But perhaps that is not the case. Maybe I could hack it?

So the idea is for it to be used for grooming hair styles. You’d create and place cylinders on a characters head and bend these cylinders and shape them to your desire. You can scale them and rotate them to your desire and once satisfied you’d generate the curves inside these cylinders.

The result is that you’d get curves that are attached all around the head that would work with simulation. You could have a script select every curves start point and xy shrink wrap it to the head geo.

This is very close to the GMH2 for Maya, apart from that the curves are to be generated inside a volume and not on the surface.

Now, I have seen this sort of thing in this post, but it is procedurally generated at render time.

So the question is: How would I generate the curves inside these nurbs cylinders. What math should I be looking into?

I have some idea of hacks following here:
I could generate planes based on the isoparms and looking into the UV to randomly select a coordinate. store the coordinates for that point in an array, then use the same UV coordinates for the next plane. Regardless whether it is scaled it would be in relation to the same UV space. Then create a nurbs curve based on the coordinates given.
However some obvious questions would be how to create the plane in the first place. And how do you set the boundaries of the random UV to the cylinder?

As said, any idea and inspiration or anything really are more than welcome =)
Thanks for reading

Do you want the output curves to lie on the surface of the cylinder or to be contained in the volume of the cylinder?

Reminds me a lot of HairFarm’s HairMesh primitive. There’s a lot more to it though but i really loved working with it:

The hair mesh can also be used to simulate (which is a lot quicker then per hair).


@Theodox - Precisely. Curves contained inside the volume of the cylinder.

@Thorsten - Yes, hairfarm seems to have some great tools for that task.

This is totally off the top of my head, but here’s what I would try

The tricky bit is getting parametric slices through the cylinders. If the cylinder is not degenerate (it’s closed in one direction) you can do something hacky like this.

  1. Rebuild the cylinder with uniform parameterizations in both directons. You can sample very densely if you want, this is throwaway
  2. Rebuild the closed dimension (the circumference of the cylinder) as a degree 1 surface. I’d be lazy and do it with 6 knots
  3. For every curve you want to create, loop over the open-directions isoparm range:
    A) Duplicate a surface curve in the closed direction, at the appropriate param on the open direction.
    B) make two triangles from it, one using knots [0, 2, 4] and one using knots [1, 3, 5]
    C) get the normal of each triangle. Average them and re-normalize. That’s the tangent along the tube’s axis, more or less
    D) Get the vector from knot [0] to knot [3]. That’s the cross section of the cylinder at that location. re-normalize
    E) get the cross vector of the vectors from C and D
    F) Get the average position of all the knots
    G) Make a 4 x 4 matrix using these vectors like so:
    [D0 D1 D2 0]
    [C0 C1 C2 0]
    [E0 E1 E2 0]
    [F0 F1 F2 1 ]
    That is approximately a coordinate system centered in the tube with its Y axis along the direction of the tube and its X axis aimed away from the seam in the tube
    H) Generate a random position in X and Z. Valid X numbers are +/- half the distance from knot 0 to knot 3, valid Z numbers +/- half the distance from knot 2 to knot 5 (or more accurately from the average of 1 and 2 to the average of 4 and 5)
    If you really want to be good, you may need to clip the XZ values more carefully but I’m betting it will be fine to just use the randoms
    I) Store a 3-d point for [random X, 0, random Z, 1] * the matrix from G
  4. You should now have list of 3-d points for the curve. Make a degree-1 nurbs curve out of that, then rebuid it to a degree 3 curve with an acceptable number of knots.
  5. delete your duplicated dense cylinder

I’d make sure to write it all to make it easy to change the sampling - too much data will be too slow and too little may produce very noise, loopy output. You might want to do something like use the sine of the open isoparm value as a random seed to make sure that the noise is not too discontinuous

Uhm. Actually. I just found out Xgen seem to support this very option inside Maya. I’m curious though if you can extract the curves to regular nurbs ones to be able to use them with yeti.
Tube based grooming.

Perhaps I have already found a solution.

Wow, Thanks Theodox!
I’m sorry I didn’t reply sooner with my find, but thanks alot. I’ll definetly look into it!

There is a node that will create a nurbsCurve from an isoparm on a surface. There is another node (offsetCurve i think) that will offset a curve along a given vector to create a second curve. That vector of offset can be based off the surface normal where your isoparm was sampled. You can randomize the number of curves to make from isoparms, randomize the number of offset curves to create and even randomize the scale of the vector that creates the offset. This should keep it from feeling too mechanical

Thanks for all suggestions. I ended up writing the script a while ago, but posting it first now as I’ve been too lazy to ever record it in action until now.