Thursday, July 26, 2012

Hair Script - Progress #6 / What ever happened to that hair script?

Is what I'm sure you're wondering.

I'm still working on it, but I ran into a problem that, for the longest time, I had no idea how to solve.  I asked for help on CGTalk, but no one ever responded.  Here's how far I got on my script before I ran into a titanium wall:

Create a UI (done for testing purposes, but as I add to/delete code, I'll update the UI to reflect these changes)
Duplicate the hair mesh, group it
If the hair is made of polygons, convert them to NURBS, group the NURBS
Get the surface curves
Allow the user to choose which way the hair is growing (if in the U direction, select all U spans and the leading V span.  If in the V direction, choose all V spans and the leading U span.  The leading span [or "root" as I've been calling it] is the span the hair grows from, and then the hair length follows the "growing" spans.)

That all works, and moving the original polygon hair and/or the updated NURBS hair effects the position of the curves perfectly, meaning, once the hair is rigged, you can animate the hair and the dynamic hair curves will follow.  So what's the problem?

If a modeler modeled a characters hair on one side, then mirrored it, the direction of the curves changes.  If they deleted the history then I'm SOL ("sadly" out of luck).

Note the image above.  Both of the highlighted spans are technically the U spans, but because one was mirrored, U now looks like V and V looks like U.  I've been looking for a way to automatically detect if the spans are uniform and heading in the same direction, but I haven't had any luck.  Then I figured I'd just go for a dirty solution.  I hate it, but I really don't have much of a choice.  My solution is to have the user select the pieces of hair where the curves were going in the wrong direction and press a Switch Direction button.  It would use the Reverse Surface Direction command, which is pretty self explanatory.  In essence, it will switch U and V spans and all will be right with the world.

This is what would have to happen in my Switch Direction proc:
Store the name of the curves, groups, etc. that have been created for this piece of hair
Delete EVERYTHING the script has created for this piece of hair so far
Reverse Surface Direction command
Recreate and restore the names to everything in the proper order
Make sure everything goes to the proper group

I looked in the GMH script that a reader recommended to me and got my hands on it.  It's a pretty darn fantastic script and I learned a LOT from it, but it has the same flaw mine currently has.  If the user mirrored some of their hair, the script will fail and there is no way to fix it.  But I THINK with the steps I outlined above, I can fix the problem.  Now that I'm getting a little more comfortable with Python, I think I can use a mix of MEL and Python to do this efficiently.

I think...

I'm open to thoughts and suggestions.


No comments:

Post a Comment