Showing posts with label MEL. Show all posts
Showing posts with label MEL. 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

Wednesday, April 25, 2012

Hair Script - Progress #5 / What a glitch

I started testing my script on modeled hair instead of polygon planes and I ran into three glitches.

Glitch 1 - Happens if the modeler modeled hair for one half of the body then mirrored it to the other half.   When I create and duplicate my curves, it will duplicate the U spans on one side, but the V spans on the other.  I "think" I can fix this glitch by rebuilding all of my NURB surfaces once they've been created.  I didn't want to do this because it's messy, but I'll just do some "create grouping" and hopefully no one will notice...

Glitch 2 - Happens if the modeler has combined all of the small hair meshes into one super mesh.  The script still works, I think it'll make rigging the original hair a lot harder.

Glitch 3 - Happens when the modeler has groups in groups.  My script works by selecting one hair group instead of marquee selecting all of the hair.  So if you select one top group, my script will end up duplicating the groups IN that group then when a for loop get to that transform node, the entire script will stop working.  Ugh, what a mess.

~Melissa

Monday, April 23, 2012

Hair Script - Progress #4 / Maya Fluid Explosions!

Remember that nuke explosion that I talk about once every 6 months?  I'm STILL working on it lol.  I got a little side tracked with ground explosions.  I'm learning about shaping my fluids with multiple emitters and volume axis fields.  I'm also learning about lighting my fluids and rendering them out in separate passes.  Fun stuff.  I'm still inexperienced when it comes to texturing fluids, so if anyone out there has any good tips/resources they'd like to share, I'm all ears!

Anyway, my hair script!

Progress!  The polygons to nurbs feature works better than I could have hoped for.  I had to completely destroy and rearrange 50% of what I had to get it to work, but it works!  Of course, if you could nest procedures in MEL, I wouldn't have had any problems. (Another reason for me to start working with Python).  My curve duplication is well on it's way to working too.  I'm just trying to figure out the best way to name my curves.  I know I don't HAVE to, but I think it looks bad to have duplicatedCurve40388 in your scene, even if the user will never see it.

The next thing I have to worry about is grouping everything so the user isn't left with a messy scene, but that's not going to be too bad.

I don't know what I want to tackle once I get the curve creation thing to work.  I could create the paint effects hair, or rig the hair.  Rigging will be harder, and it's about 60% of the entire script so I might tackle that first and get it out of the way.

Progress - ????% I don't even know anymore.

~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

Thursday, April 12, 2012

Hair Script - Progress #3 / MEL info

I've been bad about labeling my posts.

Anyway.

I wanted to learn how to put tabs on the side of a window and make it a part of Maya.  I thought there was some hidden way to do this with a tabLayout, come to find out this wasn't a tabLayout, but were several windows with dock controls.  I'd never heard of dock controls until today.

dockControl
Create a dockable control, also known as tool palette or utility window. Dock controls are secondary windows placed in the dock area around the central control in a main window. Dock windows can be moved inside their current area, moved into new areas and floated (e.g. undocked). Dock control consists of a title bar and the content area. The titlebar displays the dock control window title, a float button and a close button. Depending on the state of the dock control, the float and close buttons may be either disabled or not shown at all.


(Pardon my sloppy mouse writing.  My tablet is downstairs and I'm too lazy to get it so...)

I'd wanted to do this with my hair script since day 1 but I just couldn't figure out how.

I found out dockControl was something introduced in Maya 2011 (figures.  I've been using Maya 2010 until a few months ago).  So, I can do this, but if someone wants to use this script in Maya 2010 or an earlier version, it will error out.  I've decided to use dockControl, and build a second UI for users who have Maya 2010 and earlier.

But how will my script know?!

The handy command:

getApplicationVersionAsFloat
Return the application version number as a float value. If you use the "about -version" command you get a string value containing the application version. Strings of course may not be used in comparisons like: if ($version > 3.5) { ... }; This procedure will return a float value containing the major and minor version number. The major version will be separated from the minor version by a decimal. For example, 4.0.3 will return a float value of 4.03.


So I can do:

global proc $ss_hairDo(){
     if (getApplicationVersionAsFloat() >= 2011){
          do my dockable window;
     }else{
          do the safe window;
     }
}


Sad thing is, this command is only available in MEL.  I guess my tool will end up being a blend of Python and MEL, which isn't so bad.  There are a lot of things I'm going to gut out and replace with Python since it does things more efficiently.

Anyway, it shouldn't be too bad creating a second window, just ignore all of the dockControl stuff, and it should be fine.

*famous last words*

~Melissa