44983_Featured

Attaching objects to a deforming model in Maya

‌‌
Whether you're new to creature rigging or an expert, you probably have had to, or no doubt will have to, attach accessories to a deforming model. These accessories can range from hard surface models like buttons or badges to items with a little more flexibility, like belts and straps. Simply skinning these objects to deform with the rest of your model can lead to a ton of interpenetration as they never actually follow your geometry in a way that creates the illusion of them actually being pinned. Thankfully, there are quite a few solutions out there that can help us overcome this issue, i.e., the Point On Poly Constraint and the Rivet Tool.  Another option that works very well involves the use of hair follicles, which is what I'd like to focus on for the remainder of this article. If you were to constrain a hair system to either a polygonal mesh or NURBS surface, Maya also generates a follicle node per hair strand. These hair follicles drive the root of each strand and are ‘glued’ to your model so the hair system can naturally follow. Just in case you decide to animate the model at some point. What's also great about these follicle nodes is that they work independently from the actual hair system. What this means is that after the hair is created you can basically trash all other nodes that are generated when hair is applied, leaving only the follicle and its group, and the follicle will work correctly. The only thing to consider here is that follicles require polygonal models to have UVs to figure out where they should be placed when the node is generated. What if your model doesn't have UVs? Well, then this article is NOT for you. That was a joke. Here's a fast and accurate technique that you can use to get around this hurdle: 1) Duplicate the model 2) Select the face, or faces where you'd like your follicles to be attached 3) Invert your selection (Edit> Invert Selection) and hit Delete on your keyboard, so that now only the faces you need remain 4) Apply an Automatic Map on the remaining faces, which will place then in the correct UV space.  They might look a bit scrambled, but that's nothing to worry about. Unless, of course, you're trying to render these faces. (That was another joke.) You'll eventually hide this dissected mesh after your follicles have been set up. 44983_01 5) Either Wrap Deform the decimated model to the original or use Maya's Copy Skin Weights tool. This’ll assure the decimated version of the model will follow the very faces it was created from. 44983_02 Here's a simple MEL script that can be used to generate a follicle node on a selected face or surface patch. This tool also allows the user to create a unique name for each follicle, to help keep each system organized:
/*Instructions: select a face or surface patch and run the code... Remember, your poly model should first have UVs for this to work, so if you find that it gives you an error, simply create an Automatic UV map and rerun the tool.   The first task in this script is to make sure that any existing hair nodes are renamed in order to prevent name clashes. Each existing node will have a prefix of "orig_" (for "original") after this script is run... */ if (`objExists "nucleus1"`){ rename "nucleus1" "orig_nucleus"; } if (`objExists "hairSystem1OutputCurves"`){ rename "hairSystem1OutputCurves" "orig_hairSystem1OutputCurves"; } if (`objExists "hairSystem1"`){ rename "hairSystem1" "orig_hairSystem1"; } if (`objExists "curve1"`){ rename "curve1" "orig_curve1"; } /* Next, the hair system is applied.  The "createHair" line of the code can be generated in the Script Editors History by first enabling "Echo All Commands", under the History menu,  before you create a hair system... */ createHair 8 8 2 0 0 0 0 5 0 2 1 2; //After this, the script will then trash every hair node that gets created from the "createHair" command, leaving only the follicle and its group... select -r nucleus1 ; select -add hairSystem1OutputCurves ;select -add hairSystem1 ;    doDelete; //Next, we rename the follicle node and its group in order to stay organized... string $rnm_flc_grp = `rename "hairSystem1Follicles" "flc_grp"`;    _ __ _select -r "flc_grp"; pickWalk -d down;   string $flc[] = `ls -sl`;    string $rnm_flc = `rename $flc[0] "flc"`;    _ __ _//At this point, there's still an empty node named "curve1" that should be removed to optimize our follicle system..._ _select -r |flc_grp|flc|curve1; doDelete; //Lastly, in order to help prevent name clashes, this script will ask that you create a unique prefix for the follicle system... select -r "flc_grp";    PrefixHierarchyNames;
Editor’s note: Sometimes web formatting doesn’t always play well with scripts. If you’re copying this code and are having issues, please download the above script in this text file. Again, this is a fast way to set up follicles. This will place a follicle node at the center of a selected face. If you’re using this tool on a NURBS surface, you can use the "parameter U" and "parameter V" channels, found on the follicle's shape node, to adjust its position so that it’s placed exactly where you'd like it to end up. By the way, this begins to open up a world of interesting techniques where NURBS surfaces are used to simulate very smooth results across a polygonal mesh. Essentially, you can set up a modular component that you'd attached to your rig. For instance, a custom muscle, using a NURBS object as the muscle so you can produce smooth deformations. Then follicles can be attached to your NURBS muscle, which would then allow those follicles to serve as parent objects to joints that you would place under their hierarchies. Now these muscle joints can be added as influence objects so your creature appears to have a form of musculature as it deforms, enhancing its realism while not sacrificing performance and speed in the rig. 44983_03 Then, to take it a step further, you can set up a jiggle system on the muscle with either the Jiggle Deformed or Soft Bodies to produce more natural results from your muscles. Doing so will likely begin to affect your rig's performance; however this step can always be done in post after the animation is approved. To conclude, whenever the need arises to attach an item to a deforming model, remember there are several ways this can be accomplished in Maya. We've only touched on a few solutions, but trust me, there are many more! 44983_04 Whether you decide to use either the Point On Poly Constraint, follicles, or a custom tool that you or another artist has built, make sure the solution is the best option for you. Stress test the system and make sure it can withstand the pressure of a model that will probably deform in rather extreme ways. If you system manages to pass this test, then pat yourself on the back (or ask a colleague to) and keep moving forward!