Saturday, 14 November 2015

TUTORIAL: Principles of Blender Rigging and Weighting - Part VI

This is a continuation of my series of tutorials on the principles of Blender rigging and weighting for use in the SL/Opensim environment. You'll find links to parts I-V on my list of tutorials page in the "moderate" section.

Today we'll be looking at an extremely basic clothing item and learning how to rig and weight it to the collision ("fitted mesh") armature we explored in Part V, so load up your saved copy of that. While you're at it, you might want to brew a fresh pot of coffee or tea since this is going to be a very long installment.

Note: for this tutorial I'll be assuming that you haven't purchased the Avastar add-on for Blender and need to do it using the base SL-Wiki file instead. Avastar has full instructions and both text and video tutorials to explain how to work with its built-in aides. I still strongly suggest using the method for initial weighting that I describe here since it usually gives better starting weights than the method that Avastar uses (their method pre-dates the latest upgrade in Blender 2.74+).

Remember that if you're directly loading the .blend file from the SL Wiki, you'll want to rotate both avatar and armature by 90 degrees on the z-axis to ensure that it's symmetrical on the x-axis and facing in the negative-y-axis direction (Ruth will be facing you in Blender's front view - numpad1).

To avoid making this any longer than necessary we'll work with a clothing item that's extremely quick and easy to make: a strapless dress that hangs to the mid thigh. When following my instructions for this, don't spend very much time making it look pretty...we're just making something very basic to use as a test object for our work.

Model the Clothing Item

If you prefer to use a somewhat different modeling method to make your dress object, by all means do so. Just ensure that your dress remains symmetrical on the x-axis and that it extends to somewhere around mid-thigh. My very quick step-by-step for making our clothing item:

Skirt step:
  1. Add a mesh cylinder to the scene with a 48-vertex circumference, radius of 0.20, and no end-caps.
  2. Set shading to smooth and give it the name "skirt"
  3. Switch into edit mode and turn on the x-mirror option so we remain symmetrical on the x-axis (which will make things a lot easier for us later).
  4.  Adjust the upper edge to be approximately on the line of Ruth's hip crest and the lower edge to be about mid-thigh.
  5. Scale on the y-axis to compress it closer to the abdomen and butt. If a little bit of Ruth's body pokes through slightly, that's fine for now.
  6. Loop-cut approximately 12 times...I generally start with a little too much geometry and remove the excess later.
  7. Switch back to Object mode
Blouse step:
  1. Add a new mesh cylinder object to the scene with the same settings you used for the skirt
  2. Set shading to smooth and name it "blouse"
  3. Switch into Edit mode and enable x-mirror
  4. Adjust the bottom edge to be slightly below the narrowest part of Ruth's waist
  5. Adjust the upper edge to be at about the top of the hip, leaving gap between it and the top of your skirt model. At the rear it will be roughly where the line of the left and right butt cheeks meet at the spine.
  6. Rotate the upper edge on the x-axis to make it higher at the front and lower at the back
  7. Do a single loop-cut and slide so the cut is just slightly below the line of the bottom of the breast
  8. Loop-cut the resulting lower section by about 6 to make each quad roughly square
  9. Loop-cut the upper section by about 8-10 to give us some extra geometry to work with for the curve of the breast
  10. Switch back into Object mode.
  11. Add a shrinkwrap modifier with
    • target set to "BaseFemale"
    • offset 0.005
    • mode set to "Project"
    • both positive and negative direction enabled
  12. Optional
    • turn off the modifier preview for the shrinkwrap
    • add a lattice to the scene, scaled to enclose your cylinder
    • and a lattice modifier to the blouse, assign the lattice as its object and move it above the shrinkwrap modifier in the stack
    • turn the shrinkwrap modfier's preview back on
    • use the lattice to do further shaping adjustments for the upper portion of the blouse to get a more natural line -- you can only control the vertical positioning/line this way since shrinkwrap will have it hug the body. Don't worry at all about the bottom line.
  13. Again, don't worry if there's a little poke-through of Ruth's body
  14. Apply the modifier(s) and delete the lattice if you did the optional extra shaping
Dress step:
  1. Select the blouse and skirt objects and join them into a single mesh, renaming it to "dress"
  2. Switch into edit mode
  3.  Select the bottom loop of the blouse section and top loop of the skirt section then use Mesh>Edges>Bridge Edge Loops to fill in the gap between the two
  4. Loop-cut that newly-created set of faces to give them roughly square faces
  5. Use any combination of techniques you prefer to smooth the transition between our two portions such as:
    • smooth vertices in Edit mode with gradually expanding selection area
    • manual edits with proportional editing enabled (hotkey o)
    • switching to Sculpt mode (remember to enable x-axis symmetry) and use those tools
    • smooth modifier
    • manipulate using lattice & lattice modifier
  6. While you're doing that, also fix any poke-through areas and if want to you can do some quick additional shaping.
  7. When you're finished and after applying all modifiers, switch into edit mode
  8. Select all and use the menu option "Mesh > Snap to Symmetry" just to be sure that the dress is perfectly symmetrical.
Remember that we're just looking for a quick & dirty dress model to work with for our weighting exercise so you don't need to make it even remotely perfect. The total time I spent to make mine was less than 15 minutes.

Needless to say, clothing items don't need to be symmetrical and often aren't. I can promise you, however, that weighting with a symmetrical item is much, much easier -- particularly a dress or skirt where the mesh bridges the space between left and right legs.

I strongly recommend that your first attempts at weighting be done with symmetrical clothing and that you branch out to asymmetrical objects later once you've developed a feel for it. Even then, you'll almost certainly want to take my suggestion from an earlier tutorial and have a fully symmetric weight source blank to work with. It will save you a lot of time and effort.

Rigging the Dress

When you speak to people in-world who work with rigged mesh it can often sound like the "rigging" part of rigging and weighting is some difficult chore. It isn't (unless you're doing extremely advanced work or rigging for non-SL/Opensim projects).

Select your dress and add an armature modifier to it exactly the way we did way back in Part II of this series. The object we assign to it is "armature" (that's the name it has in the SL file) and we will only be binding it to Vertex Groups.

Ta-da! Rigging is done.

If you want to, you could temporarily enable the "Bone Envelopes" binding option of the modifier and play with the armature (in Pose mode) just to get a sense of how poorly it works as a binding for this sort of object. Just remember to disable that again and zero any changes to your armature before proceeding.

Although unnecessary, it's common practice to parent the dress (and body and anything else) to the armature so they appear as hierarchical children of the armature. For purely SL/Opensim purposes it's not necessary although it does help you keep track of what has and hasn't yet been bound to an armature. If you're working with complex scenes for subsequent Blender rendering it can be extremely useful.

Initial Weighting of the Dress

In Part III of this series we used Blender's "Assign Automatic from Bones" capability to generate our initial set of bone weights for a simple cylinder mesh. While that is usually the method to use when working from scratch, that isn't the case here and won't be for any clothing (or jewellery) item you make.

The distinction is our main goal isn't to make the dress move nicely based on bone movements. Instead, it's to make the dress move as nicely as possible with the avatar's movement. To achieve this, we need the weights of our dress's vertices to match, as closely as possible, the weights of the nearest underlying part of the avatar's mesh. The bones move the avatar and we want the dress to mirror that.

Areas where these are different will become problem areas when the avatar moves and will almost always require alpha-masking of the body to hide poke-through. We want (usually) to minimize or even eliminate the need for a custom alpha mask, so of prime importance to us is how the dress weights relate to the nearest avatar weights. We don't have the ability to change any weights in the avatar (unless you use a custom mesh one) so that means the onus is on us getting the weights right on the dress.

In essence, then, our objective is really to "transfer" the weights from our avatar to our dress as best we can, then fix or improve any problem areas.

As you'll undoubtedly know if you've worked with Blender for any length of time, there are frequently multiple different ways to do something and often more than one way to do the same thing. Weight transfer is one of those things.

The particular thing we're doing is a part of Blender that has changed rather dramatically in the last year or two and I don't remember precisely which changes were introduced with which version although, if memory serves, there was a major overhaul with Blender 2.74, some tweaks in 2.75, and even further tweaks with 2.76. Since this is an active area of development, it may continue to change or be refined in future versions.

My pictures/observations/instructions are based on Blender 2.76 (current as of the date this was written) so if you're using any earlier version the options will be a little different.

Blender's weight transfer can be done in two ways:
  • as a "Data Transfer" modifier applied to the target object, or
  • by selecting the source object first, then shift-selecting the target object, then entering Weight Paint mode, then using "transfer weights" (either from the toolshelf or the Weights menu)
It doesn't matter which method you use since the results are the same. If you use the modifier approach you can pre-pose the armature into a non-zeroed pose, then add the modifier and move it above the armature modifier in the stack, select the method and options, then apply it (you must apply before you can do any subsequent tweaking). If you use the Weight Paint mode transfer approach, you must ensure that your armature is zeroed before you use it (there are actually a few exceptions to that rule, but that's a more advanced subject for another time).

Most of the time I personally use the Weight Paint mode transfer method but that's probably as much a result of habit as anything else (and I think when I began working with weighting, weight transfer as a modifier either didn't exist or has drastically changed since then). That's the method we'll use today.

Optional but recommended: select the armature and switch it into Pose mode. Then select all bones. This will allow you to use one of the transfer methods which happens to be the one I prefer since it generally produces the best starting point for this type of work. Leave the armature in pose mode.

Select your BaseFemale mesh (the "source" of our weights) then shift-select your dress (the "target" for the weights) then switch into Weight Paint mode.

If you haven't already done so, once you're in weight paint mode:
  • in the toolshelf's "Tools" tab turn the "auto-normalize" brush option on (SL/Opensim requires this)
  • in the "Options" tab enable X Mirror and ensure that Topology mirror is off
  • in the same tab set "Show Zero Weights" for "Active" (your dress will go black)
  • if you preferred "spray" to be enabled when you were playing with weights in the earlier parts of this tutorial, enable it too...that's purely a matter of personal preference
  • I also like to enable the "restrict" option which prevents you from accidentally brushing weights to any vertex that doesn't already have that bone group assigned to it. When I need to do so, I briefly disable it again, do my brushing (carefully!), then re-enable it so I don't forget.
  • enable face selection masking so I can watch the effect of movement on my topology when I'm tweaking it can always wait until you begin tweaking before you do so
  • in the Properties Pane, select the Data Objects tab (upside down triangle)
Now click the "Transfer Weights" button on the toolshelf's "Tools" tab (Weights section) or use the menu option Weights > Transfer Weights.

In the toolshelf's most recent actions section are all of the options for weight transfer (see below). Remember that when using this method you have to select any options now because as soon as you do anything else the most recent action will cease to be the transfer. With the modifier approach you don't have to worry about that and the modifier has the identical set of options. With this method you can always just re-do the transfer, though.

There are a few things you're allowed to do that won't count as an "action" to prevent you from changing the transfer options. You can toggle face selection masking on and off, and you can select any of the newly-populated bone group names from the vertex group list in the Data Object pane. This lets you easily see the effect of the options on the mesh without making it impossible to change to a different one. Do not select a bone group using the ctrl-select method. It will work but it will also
be considered a new action, preventing you from making any changes.

Weight transfers work by looking at each and every vertex on the target mesh, one by one, then assigning each one a weight (or multiple weights) based on the options you select. Each time you change a transfer option, the transfer is recalculated to reflect that change for each vertex of the target.

UPDATE 2016-08-02: This has changed a little under Blender 2.77. Please see this follow-up post for the settings suitable for 2.77 and later, then return to this post to continue reading.

The weight transfer options and my recommendations are:
  • Freeze Operator: Disabled
    You should never need to enable this since all it does is stop any changes you make to any of the other settings from being recalculated immediately and the only time this will have any significant speed benefit is if your clothing mesh has an insanely high poly count which means it's completely unsuitable to Opensim anyway.
  • Data Type: Vertex Groups
    There are other types of data that can be transferred but the one we want is the vertex (bone) groups. You might want to have a look at the full list just to see what other nifty time-saving options are here for other data types.
  • Create Data: Enabled
    This lets new vertex groups be added if they don't already exist which, in our case, is all of them. For weight transfer (vertex group data) I can't think of any case where you wouldn't enable it.
  • Vertex Mapping: (various)
    The method of vertex mapping you select has a huge impact on how much subsequent tweaking you're likely to need to do and the choice will depend a little on the type of object you're working with. It also affects (slightly) the other options you'll need to choose.

    This deserves its own separate "discussion" which you'll find immediately following this section (see below).
  • Auto Transform: Disabled
    Because both our source and target objects are in their "zero" positions with all transformations applied, this isn't needed. It would only be in rare (and advanced) situations that you might benefit from enabling it.
  • Object Transform: Enabled
    Again, this isn't required because we're working with zeroed objects where all transformations have been applied. By default it is enabled which is fine, too, so you can just leave it at its default.
  • Only Neighbor Geometry / Ray Radius: Disabled / 0.0
    This is a pair of options that go together. If you leave it disabled, as I recommend, the ray radius is ignored. Enabling it limits how far away the transfer will look when it tries to find a source for each target vertex. The distance is determined by the ray radius setting and if there's no part of the source mesh within that radius it doesn't assign any weights to the target vertex. Since SL/Opensim requires that all vertices have at least one weight, disabling this option ensures that (even if we have to go and tweak them later).
  • Source Layers: By Name
    For our purposes always select "By Name" although in most cases either will work equally well. Describing exactly what this means is beyond the scope of this tutorial.
  • Destination Layer Matching: (various)
    Your best choice here depends on the method you select for vertex mapping which we'll talk about in the next section of this tutorial. For our purposes it will usually be either "Selected Pose Bones" (but only if you've selected all bones in the armature while in pose mode as I suggested above) or "All Layers". (see below)
  • Mix Mode / Mix Factor: Replace / 1.0
    This is another pair of related options. The mix mode determines how the source weights are applied to the the vertices of target mesh and the various options only become relevant when you want to combine weights from various sources or only selectively adjust or replace weights. The factor determines what percentage of the weight to apply.

    In our case we don't have any preexisting weights so the default "replace" option and mix factor of 1.0 (100%) is perfect. If you begin doing advanced work there may be occasions where you'll consider using the mix option (and a weight <1.0) or one of the thresholds (the mix factor then becomes the threshold value).
Any time you change an option everything is recalculated which also means that if you're selecting bones from the list of vertex groups you'll need to keep re-selecting them (which is a bit of a nuisance) each time you change something.

As I mentioned above, the vertex mapping method and corresponding destination layer matching choice are the two most important settings in determining how the transfer works and deserve their own separate section in this tutorial.

Vertex Mapping Options

I'll try to give you general guidelines for each mapping option but until you've worked with it for a while you'll find it very difficult to tell which one you'll want just by looking at the weight colours on the mesh. It's something you need to develop an eye for based on experience.

My personal order of preference for the vertex mapping and destination layer matching options:
  • Nearest Face Interpolated : Selected Pose Bones
    This looks at each vertex on the target mesh and determines what the nearest face of the source mesh is (nearest in terms of global space). It then considers the weights of the vertices of that source face and assigns a weight to the target vertex based on that.

    This option has changed with Blender 2.76 (which is brand new at this time so possibly this is a bug?) and to get sensible results now seems to require that you have first put the armature into pose mode and selected all bones; and then when doing the transfer you need to use "Selected Pose Bones" as your destination layer matching. I'm not entirely certain why this has changed or why this matching method is the only one that provides the expected results...I just figured it out through trial and error. If someone happens to know, I'd love to be enlightened.

    EDIT: Versions 2.76-2.76b have a bug for this method which cause it to behave unpredictably in many cases. I'm current using a beta build (nightly Nov 25th) where this has been fixed, works reliably, and no longer requires the full armature to be pre-selected.

    This has been my go-to method since its introduction and has almost always given me the best resulting starting point for weights, provided the distances between the source faces and corresponding target faces aren't too great. This is the method I used this time and show in the accompanying picture.
  • Projected Face Interpolated : All Layers
    This is a very similar method except it limits where the transfer will look for a source by only projecting the search along the target vertex's normal until it intersects the source mesh. This will result in it ignoring source faces that nearby but not in the right direction. You'll usually want to use "All Layers" for your destination layer matching.

    In many cases this won't give you the best starting point weights and will result in a lot of areas you'll need to fix (under the breasts, armpits, or portions of the mesh that might be folded) however it's extremely useful for something like a pair of pants/shorts where you want to ensure that the left leg of the object gets weighted to Ruth's left leg even though her right leg is slightly closer in global space.

    Also beware: unlike all other methods, this method will not assign any weight if it doesn't encounter a source face when it does the search projection. For something like our dress you would find a set of vertices between the legs where that happens and which must be fixed before the mesh can be uploaded. You'll almost always need to fix them anyway, no matter what mapping method you use, so that isn't quite as problematic as it might seem.
  • Nearest Vertex : All Layers
    My third go-to choice is similar to the nearest face option except it simply looks for the nearest vertex (in global space) on the source mesh and uses its exact values.

    This works beautifully if your clothing item was made by taking the source mesh and scaling it slightly along its normals since the nearest vertex will almost always have the exact weight you want your clothing to use (assuming your source was Ruth or something already perfectly weighted to Ruth). If you've scaled it significantly relative to the source it might not be quite as good an option.

    The key thing to remember with this method is it doesn't take into account how the nearest part of Ruth's mesh will move, so if your target vertex is directly above the middle of a source face that deforms a lot, you'll almost always have to do some weight readjustments later.
  • Nearest Edge Interpolated: All Layers
    This does almost the same thing as the nearest face interpolated option except it looks for the nearest edge on the source layer and then considers the vertices at either end of it to determine the weight for the target vertex.

    For mysterious reasons that I still haven't figured out, this appears to work perfectly with the All Layers choice for destination mapping whereas the face version of it requires the selected pose bones. One day I hope to understand why (or find out that it's a bug).

    This choice tends to provide better results than the interpolated face version if the topology of your target is a lot finer than that of your source (ie you have a lot more vertices in your target than you do in your source). Normally this won't be the case for basic clothing items but it could be if you're doing delicately modeled draping (but watch your poly counts!).
  • Everything Else
    There are other options for the vertex mapping and destination layer matching but in my experience they almost never give better starting point results as one of the above four.

    Many of these options are very new (Blender 2.74+) so I must confess to having a certain bias for my tried-and-true ones that have been around in earlier versions and that I'm accustomed to working with. You might find it a worthwhile exercise to experiment with them and you may discover some other combination that works well for you.
For more information on all of the options you can check the latest updates to the Blender Reference Manual.

Now What?

I now disable selection of the Ruth mesh by clicking on its selection control icon in the outliner. This will make it much easier to use the ctrl-select method to select armature bones for subsequent posing. If for some reason you need to select her again later, you can always enabled it again.

For fitted mesh weighting, the next step is to go to your vertex groups list in the Data Object pane and delete all mBone grops from the list by selecting each and clicking the "-" button immediately to the right of the list.

While you're doing that, also delete any of the fitted mesh bone groups that don't have anywhere on the dress that ought to have any weights for it. In this example that's the bones for the arms, lower legs, and head and neck. You may see slight weights for the L_UPPER_ARM and R_UPPER_ARM but most likely they're so minute that they can safely be removed. You'll almost certainly need to keep the two clavicle bones. Unless your dress goes down to the knees, remove the lower leg bones too since the weights will be minimal and their motion shouldn't cause the dress to move.

Most likely you'll be left with only a dozen or so bones in the list (see picture). This is a lot easier to work with than a very lengthy list that's cluttered up with bones that aren't being used. Obviously the bones that are "safe" to remove depends entirely on the object you're weighting. The list for a full length dress with a high collar and sleeves will need to keep almost all of the fitted bones. A necklace or bracelet might only have 2 or 3.

Next, we want to normalize all of the remaining weights. Fitted mesh doesn't demand this (the traditional armature does) but it's a good idea to do so anyway. Click the "Normalize All" button on the toolshelf. Immediately after doing so, in the most recent actions section make sure you select the option to do it for "All Groups" (default) and disable the "Lock Active" option (which is enabled by default).

What this does is ensure that for each vertex, the sum of its weights equals 1.0 and by disabling the lock active we ensure that any weights that have to be adjusted are done proportionally to all bones, including whichever one happens to be currently selected. When that option is enabled, no weights for that bone will be changed and normalization is done for all other bones. There are occasions when you may want to do that but this isn't one of them.

One more preliminary step: click the "Clean" button and then in the most recent actions section change the Subset from the default setting to "All Groups" and leave the Keep Single option un-checked.

When the weight transfer is initially made each bone group is assigned to every vertex on the target mesh with a weight of 0.0, then the values are calculated. This will leave each vertex with large numbers of 0.0-weight bone assignments that subsequently makes it a little harder to work with and can lead to some unusual results when you're tweaking the weights. It also defeats the purpose of the "restrict" option because that only prevents new bones weights from being added by accident, but not from weight being given to a bone that is assigned to the vertex but currently has no weight.

If you're working with the traditional armature instead of the fitted one, there's a catch: SL/Opensim requires that all vertices have weights assigned for all bones, so cleaning will make the mesh invalid for upload. If you have the Avastar add-on it will automatically assign them for you at the time of export (with 0 weight for the ones added). If you don't, you'll need to finish by doing another weight transfer when you're finished, with the mix mode set to "mix" and the factor set to 0.0. That will put the "missing" zero-weight bone groups back for each vertex.

This is a very good time to pray, if you believe in that sort of thing.

Identify Problem Areas

If you're very lucky the transferred weights will be perfect and you won't need to do any tweaking at all. That won't be the case for us because even if the majority of the mesh is pretty good, the portion of skirt that bridges the gap between the legs will be a very abrupt, sharp transition.

If you were using a pre-made dress blank as your source (as I mentioned earlier when I linked to another of my tutorials) you'll have already gone through our next chore and the transfer might be close enough to perfect to need almost no further tweaking.

What we want to do now is identify problem areas of our dress mesh weighting. These are areas that either allow Ruth's body to poke through when a bone is moved or where the way the dress moves is "wrong" relative to the way it you want it to move.

Start ctrl-selecting mBones of the armature and rotate them through a range of motion that would be typical for that bone in-world. As you're doing so, be careful not to accidentally paint with your weight brush or it will add that bone back into our vertex group list (though you can immediately remove it again if it happens).

In our SL/Opensim world we have a very low poly (and in my opinion extremely poorly modeled and weighted) avatar and an extremely simplistic armature (again in my opinion, very poorly designed) so there are a lot of limits on what can reasonably be achieved.

In particular, the way the torso bends is going to be a constant source of problems when the motion is at all towards the extremes. You'll also find that armpits, elbows, groin, knees, and ankles will be frequent areas with issues. With dresses where the starting weights are taken from Ruth instead of a dress blank, you'll always have a very sharp, ugly transition between the legs at this point.

Each time you identify a problem spot, you'll need to decide whether to:
  • try editing/sculpting the mesh out away from the body a little so poke-through no longer happens, or
  • try to tweak the weights to improve it, or
  • make an alpha mask for the avatar to wear to make the poke-through invisible there
I'll assume that if you're even thinking about working with rigged mesh clothing you're already familiar with all but the second option so let's look at that.

Mesh poke-through typically results from 2 causes:
  • weighting in that area that doesn't match the underlying mesh's weights accurately enough, or
  • a mismatch of the topology resolution of the clothing mesh when compared to the underlying avatar mesh -- or what I think of as the "truck turning a corner" issue*
* The truck turning a corner issue is where one fixed face rotates and the underlying avatar mesh in that area has a pivot point that's somewhere in the middle of that face. Since the pivot points are different, they'll overlap just like the problem you'd see trying to get a semi-trailer to turn a tight corner on the road. It can't be done.

If it's the former, it's simply a matter of tweaking the weights until they're correct. In the case of the latter there are several possible solutions (often requiring more than one):
  • you can try remodeling that area of the mesh by adding/removing topology to make it far more closely match the topology of the body mesh in that area...ideally the clothing item's vertices and edges will very closely match those of the adjacent part of the Ruth mesh
  • you can move that area of the clothing mesh it a little further away from the body so it doesn't poke through until the rotation becomes more extreme than a body will normally require
  • try tweaking weights in that area to see if you can get it to go away anyway -- something that you might be able to do if the clothing topology is higher resolution than Ruth's

Weight Tweaking

There are a few basic rules when it come to working with rigged mesh for SL/Opensim:
  • every vertex on the mesh must have at least one non-zero bone weight
  • with the traditional armature all weights must be normalized and, in my opinion, it's a good idea of normalize the fitted bone weights as well
  • you're allowed to mix fitted and traditional bone weights in a mesh's weighting but in my opinion it's a bad idea and often leads to confusion while working with it...I highly recommend using one or the other, not both
  • there has been a certain amount of debate about the maximum number of non-zero bone weights a single vertex can actually have...the documentation says 4 but in practice it is possible to upload a mesh that violates that and still appears to move correctly; however I'd still treat 4 as the limit
  • in the base SL avatar, no vertex has more than 2 traditional bone weights
  • in the fitted mesh avatar file, some vertices have 3 bone weights (a small number have 4)
I make a point of talking about the number of bone weights a vertex can have because your approach to weight tweaking will depend on how many weights you're working with in a given region.

The easy way to check is to tab into edit mode (TAB always toggles back and forth between edit mode and whatever mode you were in prior to that) and select a single vertex. On the 3D View pane's properties panel (hotkey N toggles visibility) is a section called "vertex weights" where you will see a list of all vertex groups assigned to it.

If we hadn't done the tidying up of bone groups and then "cleaned" the mesh earlier, you'd see a list of 60+ bones for every vertex, most of them with values of 0.0. Because we did, you'll now only see the ones that actually have some weight. You might need to drag the panel a little wider to see it in decimal detail.

By selecting a few vertices in that area, one by one, you can see how many bones are commonly being used in that vicinity. Of course you can also check this, visually, by looking at the mesh in weight paint mode and selecting the bones one by one. Both methods are useful.

While we're here, though, it's worth pointing out a few things about weights in edit mode since they can be very handy.
  • If you edit the topology by moving vertices around, their weights will remain unchanged (that's also true when you're in sculpt mode)
  • If you add a new loop-cut, or subdivide an edge, the newly-created topology is automatically assigned weights "intelligently" based on where each new vertex is added relative to the weights of the preexisting vertices nearby. That's a huge time-saver!
  • You can manually change the weight of a bone for a single vertex by selecting it and changing that displayed value.
  • As long as X-Mirror option is enabled for the mesh in edit mode, it will mirror that change on the mirrored vertex and will be aware of the left-right bone mirroring (so changing LEFT_PEC on one vertex will make the identical change to RIGHT_PEC for its mirror). It won't do that if X-Mirror isn't enabled, even if it's enabled in weight paint mode. They're two distinct modes so you have to remember to enable both.
  • Your auto-normalize setting in Weight Paint is ignored in Edit mode so you will need to click the "Normalize" button to do so after making a change.
  • If you select multiple vertices, the value shown here is the weights of the currently active vertex, not the average of them all
  • With multiple vertices selected, you can click the little "copy" symbol to the right of the weight to have that value applied to all of the selected vertices
  • With multiple vertices selected, you can click the "Copy" button at the bottom (beside the Normalize button) to copy all the bone weight values of the active selected vertex to all of the other selected vertices.
  • When using the above two copy methods, if a vertex doesn't already have that bone group assigned to it as a weight the new bone group is NOT created or normalized. You have to add it first. It's easy to forget that...
  • Clicking the "X" button to the right of a weight removes that weight group assignment for the selected vertex (but only for that vertex if you have multiple vertices selected).
  • Any selection you make in edit mode is preserved as a selection when you return to Weight Paint mode. If you have either face selection masking or vertex selection masking enabled in weight paint mode you can only paint changes for vertices that are selected (otherwise you can paint anywhere). This is a great way to avoid accidents
  • Anything you hide while in edit mode will also remain hidden in weight paint mode
  • The assorted hide/unhide hotkeys (H, shift-H, Alt-H) and the global area selection hotkeys (A, C, B, ctrl-I) also work in weight paint mode when either of the masking modes is enabled
  • There are probably a few other nifty things that I do instinctively but am forgetting at the moment
When tweaking weights you should always only rotate one bone at a time, and you should always use the mBones for posing. Once you've tweaked the weights all of those, one by one, you can then come back and check the response to movement of the fitted mesh bones. Normally it's only the bones involved in avatar physics that are likely to cause problems (the pecs, butt, and belly).

Getting every single one of them perfect is (in my opinion) an exercise in frustration so you'll have to decide just how long you're willing to minutely tweak things rather than just alpha-masking or pulling that part of the mesh a little futher away from the body.

The best workflow that I've developed for this process is to always start at the extremities (which will have only 1 or two bones weighted to them) and/or to work outwards from the root (pelvis) bone, leaving the "trouble" areas until last.

With each bone, move it to a natural extreme for x-axis rotation and tweak the weights until that looks right. Then move it to the opposite natural extreme for that rotation and tweak for that. Repeat that with y-axis rotation for each extreme, then repeat for z-axis rotations. If you're able to get all three axes to look good at both extremes, you've got the right weights and it should look perfect no matter what mixture of the 3 you use.

If it's impossible to get both extremes of the same axis' rotation to look good, you're suffering from the "truck turning a corner" issue and will need to adjust the mesh by editing its topology or clearance.

I'll give you some more practical guidelines to tweaking in a moment, but first let's deal with the major issue of the horrid crease of weights on the dress between the legs.

Why Dresses and Skirts Are a PITA

In this case, PITA isn't a middle-eastern type of bread. It's my acronym for "pain in the posterior" except substituting a more vulgar word for posterior.

Whenever you transfer weights from Ruth's legs to something that crosses between them, you'll see a very distinct demarcation line between the vertices that are given weights for the right upper leg and the ones that are given weight for the left upper leg (or mHipLeft and mHipRight if you're using the traditional armature).

This happens in all of the transfer methods and is why I advocate making a dress blank to use in future as your weight source. In many cases, a row of vertices that is precisely in the center between the two will be given no weight at all.

There's a trick to dealing with this area. I'll describe the one for fitted mesh but the same technique works for the classic armature too.
  • If your armature has any translations, zero them
  • Make sure the "Auto-normalize" brush option is enabled
  • Disable the "Restrict" weighting option if it's enabled
  • Make sure the "X Mirror" weighting option is enabled
  • If you ignored my suggestion earlier and your dress mesh isn't modeled symmetrically, enable topology mirror weighting option, pray a lot, and promise yourself to make a dress blank weight source later that is symmetrical...prepare to curse...a lot...(if it is symmetrical, congratulate yourself for having saved yourself a lot of frustration and don't enable topology mirror)
  • Look at the front of the dress and check to see if any vertices have weights for the BUTT bone. If they do, switch to the subtract brush and remove them completely, then click the "Clean" button on the toolshelf (options: All Groups and "Keep Simple" disabled)
  • Select the blur brush and set the strength to 0.001 (keep weight at 1.0)
  • Select the L-UPPER_LEG bone from the vertex groups list in the Data Objects pane
  • Paint this very soft blur to include the vertices on the right side of the dress to about 1/4 to 1/3 of the way across the width of the right leg and all vertices in between (see picture)
  • When you do this, don't be surprised when a sudden row of green appears right up the middle of the dress since that will always happen
  • Select the R_UPPER_LEG bone and make sure that what you just did with the left leg was correctly mirrored (it should have been)
  • If any areas were missed, brush them softly with the blur again
  • Repeat this for the rear of the dress 
It's possible that during the initial weight transfer there will be a vertex on the left side of the dress that received no weights at all or received a weight for the right leg instead of the left. When you do the soft blur it will put an unexpected red dot on the wrong side of the mesh, creating a "problem pair" (see picture). To fix that, tab into edit mode, select one of the two vertices and manually reverse their weight values. As long as you've enabled x-mirror that will also fix the other vertex. Then tab back out.
  • While still looking at the rear of the dress, select the BUTT bone and using the same soft blur brush extend its area of influence down to fill any empty vertices in that center seam
  • Repeat that with the PELVIS bone
  • Look back at the front of the dress and repeat yet again with the PELVIS bone
  • Tab into edit mode
  • For the front of the dress: select the vertex at the very bottom of the central line.
  • Then shift-select the vertex immediate to the right of it
  • If the vertex to the right has any weight for the PELVIS bone, click the little "copy" icon immediately to the right of the weight which will copy that weight back to the center vertex, If it doesn't have a weight, move on to the next. DO NOT CLICK THE NORMALIZE BUTTON.
  • Repeat this, working your way up the seam until you reach the place where the pelvis weight is already about the same in the center as it is at the edge.
  • Repeat this exact same method for the rear of the dress except for each time, copy both the PELVIS and the BUTT bone values
  • Once both front and back are done, tab back to weight paint mode
  • Select the PELVIS bone in the vertex group list (if it isn't already) and click the Normalize All button but this time enable the "Lock Active" option for it in the most recent actions
 At this point if you look at the weights for the butt and the pelvis, they should seem fairly smoothly graduated down the leg (the butt only in the rear, the pelvis in both front and rear). The left and right upper legs should be green up the center lines, front and back, slowly fading as the pelvis (and butt in the rear) gain influence.
  • Re-enable the Restrict option
  • Ctrl-select the mHipLeft bone of the traditional armature and rotate it outwards by about 30 degrees (R Y -30)
  • From the bone group list in the Data Object pane, select the R_UPPER_LEG bone (not the left, the right!)
  • Switch to the add brush and set the strength to about 0.001 or 0.002 (depending on whether you're using spray or not)
  • Start adding weight to the blue portion of the left leg area to even out the spacing of the'll notice as you do that a corresponding change occurs on the opposite side. DO NOT change the weights on the line of green vertices that denote the center of the dress, even though they've been dragged to the left by the leg's motion.
  • Once you have it somewhat smooth, zero the y-axis rotation of the mHipLeft bone and move it through about a 45-degree x-axis rotation. You'll likely need to tweak a little to fix poke-through of a thigh. When tweaking, always add thigh weight, don't subtract it (even if this means switching to the opposite UPPER_LEG bone)
  • Repeat all of this on the rear (or the front if you started with the rear)
  • Because everything is being mirrored, anything you do with the left will be identical to anything that would affect right leg movement.
Once you have both front and back done you should have something that looks a bit like the picture above.
  • In the Outliner Pane, select the armature (or switch back into Object mode and select the armature in the 3D View pane.
  • Select the mHipLeft bone, then shift-select the mHipRight bone (unfortunately you can't do this while still in weight paint mode)
  • Zero their rotations (ALT-R)
  • Now rotate both of them forwards by about 45 degrees
  • Keep them both selected and then switch back to your dress in the Outliner Pane (or select the dress and switch it back into weight paint mode)...the two mHip bones will still be selected so you can continue to manipulate their rotations without needing to do that again until you select a different bone
  • Now that our two UPPER_LEG bone weights are correct relative to one another, we need to balance them against the PELVIS bone in the front, and against both PELVIS and BUTT bones in the rear. The front is much easier so let's start there.
  • select the PELVIS bone from the bone groups list then using gentle values of add and subtract and blur brush strokes (~0.001 strength) tweak its weights until the bend in the front looks fairly natural (it's the nature of the this type of system that it will never be completely perfect)
  • Then switch to the BUTT bone and bend both legs backwards by about 30 degrees (as long as they're still selected you can easily do this with hotkeys)
  • Blur the BUTT weights and if necessary add a very small amount but we'll do most of our fixing using the PELVIS bone because it tends to have more influence over thighs
  • Switch to the PELVIS bone and smooth again, and then begin adding weight to push down what will probably be an ugly bulge pushing up from our upper leg weights
  • Again, it will never be perfect but get it to look reasonably natural if you can
  • Do all of your work by adding and subtracting PELVIS weight (and perhaps a little BUTT near the very top of the leg). Avoid adjusting with UPPER_LEG weights...just left them adjust themselves naturally as they're auto-normalized.
  • You'll find that you probably want to add quite a lot of PEVLIS weight as you move lower on the skirt at the rear, but less so at the front. Legs rarely bend backwards more than about 40 degrees but when sitting they'll commonly be rotated forwards by 90 degrees or even more.
Don't be surprised if this takes a while. There's a real art to weight painting and no matter how well I try to describe it, there's no substitute for the feel you get for it through hours and hours of hands-on work. In time, balancing the weights of two bones will become simplistic, for three bones it will be relatively easy, and any day now I'm sure I'll be feeling better about weighting four bones simultaneously (but without a doubt it's tricky).

The unfortunate thing is this part of a dress/skirt moves completely differently on real life where a lot of the movement comes from gravity and cloth physics. Being bound directly to bones prevents any really natural movement from occurring (for instance, when you cross your leg is slips under the fabric without dragging it along for the ride). One day, in our dreams, we'll have real-time cloth draping physics in-world.

When you finish all of this, move each bone individually through its range of motion as well as checking both forward and backward motion of both legs (particularly for sitting) and make any further tweaks necessary. You will always have a little poke-through of the upper thigh whenever you have cross-over weighting like this, but that's a small price to pay in exchange for an overall more natural movement appearance. If it really bothers you, alpha-mask the avatar's upper thighs.

Don't be surprised if this takes you a couple of hours the first time you do it and still doesn't look all that great. Save often, take periodic breaks, brew another pot of something, take the dog for a walk...whatever works for you. It's never fun and always takes time. This is why having a very, very good weight blank or two is worth it. You expend all this time and work once or twice, then you have a weight source to use for all future projects that will drastically reduce how much tweaking is needed (from several hours to as little as 5-10 minutes).

You'll also get a lot better at it the more you work with it. It will become more like second nature and you'll find that you know intuitively which areas will need weight added or subtracted and which bones are best to work with for that zone.

Practical Guidelines for General Tweaking

While this has already become an insanely long tutorial installment, I'll leave you with a few tips that ought to help when tweaking weights in general.

I find that weight-painting is almost as much an art as it is a science. It takes a while to learn and even longer to become proficient. If you're like me, you'll find yourself having a "eureka!" moment where it will also suddenly "click" in your head and make sense, becoming far more predictable and much less scary and time-consuming.

It's really important to be aware at all times how many different bones are affecting the weights of the vertices you're working with. Failing to do so can cause you to waste huge amounts of time.

If an area has only two bones affecting it, it's "easy" in the sense that it doesn't matter if you add or subtract weight from either bone since the net effect is identical.

For areas that have three weights, two of them are usually complementary and overlapping. Never work with the "middle" one unless you absolutely have to. Instead, move and weight based on one of the outer ones, then move and weight based on the other. The net effect of those combined changes in that region will make the middle bone balance itself.

Because working on an area with three or four bones weights is much harder, Linden Lab generally avoided too many zones on the avatar that have that. Those that do usually transfer quite well and will need only minor weight blurring (the dress/skirt being the HUGE exception to that observation).

I've already mentioned working with all bone zeroed and then only changing one bone at a time on the armature, rotating it through x, y and z axis rotations one at a time and through both extremes. If you get each of these balanced, it almost always results in the whole thing being balanced just thanks to auto-normalize.

Even when you've finished working with a bone, go back and check it again if you make any nearby changes that might impact it when you're working on a different bone. It will save uploading something more than once.

If you need to solidify something (like the bottom of a dress so it isn't invisible when you look at the inside of it) DO NOT solidify until AFTER you have completely finished weighting it. Weights are automatically transferred and preserved by the solidify modifier so there's no sense having to waste time trying to match inside and outside weights (which is extremely hard to do). I will almost always leave my solidify modifier in the stack and never apply it until just before I am ready to export.

After you've been working with weighting for a little while, come back and read through this tutorial series again since there are undoubtedly parts of it that won't make a lot of sense when you begin but might become more clear when revisited with a little practice under your belt.

Some weighting issues are simply impossible to resolve due to the nature of the system. It's not uncommon for a quick bit of editing/lattice modifier/sculpting to accomplish a far faster and easier fix. If all else fails, alpha mask...

Finally, I apologize for the extremely long post. I usually try to break things up into smaller, easier -to-digest chunks but there just wasn't a good place to do that with this installment. I hope you find it helpful in spite of its length.