Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

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.

~Melissa

Saturday, April 14, 2012

C++

I have a dream.  A dream of being fluent in MEL, Python, Perl, C++ and LINUX/UNIX shell scripting.  I love programming.  I really, really REALLY, REALLY do.  I just wish I were better at it.  I can scrape along, ask the right questions when I'm stuck, but there's so much more for me to learn.

I want to know more.  I want to be better.  I've decided to take a Fundamentals of Unix/Linux class as well as a C++ class this summer, but I started studying early.  I've learned a lot already.  There are still things I struggle with, but I know I'll get the hang of it.  I hope.  MEL, Python now C++.  Let's hope my brain doesn't mix these all up.

~Melissa

Wednesday, August 4, 2010

My First MEL Script - isn't it cute?!

So apparently it's in my best interest to learn MEL and Python.

Thanks for telling me this with 6 months 'til graduation, folks!  I've been cramming for a while and though I'm still intimidated by MEL, I don't hide in a corner and quiver with fear when I come face to face with it.  At least not all the time.

Anyway, I was watching a rigging tutorial and the guy made a Renaming Script.  I thought it was pretty nifty, but I could never remember what order he selected things in and so I'd make a mistake and rename things in the wrong order.  I thought to myself, "Self, why don't you just make a renaming script where all the fields are labeled 'rename ___ to:'?"  Plus, I wanted to see if I could do it on my own, without looking at the tutorial again.

So, after a lot of trial and error (and help from a guy on CGTalk) I did.  Yay!

Behold, my first MEL Script!

-----

//Renaming Script

//Creates a window

string $RenameWindow = `window -widthHeight 450 200 -rtf true -title "Rename Selected Objects"`;

//Makes the window able to scroll

scrollLayout
            -horizontalScrollBarThickness 16
            -verticalScrollBarThickness   16;

//Makes the window a row column layout
rowColumnLayout
        -numberOfColumns 2 -columnAttach 1 "right" 0
        -columnWidth 1 150 -columnWidth 2 250;

//Queries selections

string $sel[] = `ls -sl`;

//For loop - so we can access and apply the command to each selected object individually

for ($each in $sel) {

    //Name Field Label - Acquires and lists the original name of the selected objects
     text -label ("Rename " + $each + " to:");
    //Renaming Field - Allow the selected object to be renamed
    nameField -o $each;
}

//Button on the window for closing the Renaming Window

button -l "RENAME!" -c "deleteUI -window $RenameWindow";

//This shows the Renaming Window
showWindow $RenameWindow;

-----

Have I done something that hasn't already been done 530950394208539 times before?  Nope.  But I did it, and I understand what it does and I can recreate it if I need to.  That's the fun thing ^^;

~Melissa