Tuesday, 26 August 2014

Humanoid Avatars

Creating the Avatar

After a model file (FBX, COLLADA, etc.) is imported, you can specify what kind of rig it is in the Rig tab of the ModelImporter options.

Humanoid animations

For a Humanoid rig, select Humanoid and click Apply. Mecanim will attempt to match up your existing bone structure to the Avatar bone structure. In many cases, it can do this automatically by analysing the connections between bones in the rig.
If the match has succeeded, you will see a check mark next to the Configure menu
Also, in the case of a successful match, an Avatar sub-asset is added to the model asset, which you will be able to see in the project view hierarchy.
Models with and without an Avatar sub-asset
Models with and without an Avatar sub-asset
The inspector for an Avatar asset
The inspector for an Avatar asset
If Mecanim was unable to create the Avatar, you will see a cross next to the Configure button, and no Avatar sub-asset will be added. When this happens, you need to configure the avatar manually.

Non-humanoid animations

Two options for non-humanoid animation are provided: Generic and Legacy. Generic animations are imported using the Mecanim system but don’t take advantage of the extra features available for humanoid animations. Legacy animations use the the animation system that was provided by Unity before Mecanim. There are some cases where it is still useful to work with legacy animations (most notably with legacy projects that you don’t want to update fully) but they are seldom needed for new projects. 

Configuring the Avatar

Since the Avatar is such an important aspect of the Mecanim system, it is important that it is configured properly for your model. So, whether theautomatic Avatar creation fails or succeeds, you need to go into the Configure Avatar mode to ensure your Avatar is valid and properly set up. It is important that your character’s bone structure matches Mecanim’s predefined bone structure and that the model is in T-pose.
If the automatic Avatar creation fails, you will see a cross next to the Configure button.
If it succeeds, you will see a check/tick mark:
Here, success simply means all of the required bones have been matched but for better results, you might want to match the optional bones as well and get the model into a proper T-pose.
When you go to the Configure … menu, the editor will ask you to save your scene. The reason for this is that in Configure mode, the Scene View is used to display bone, muscle and animation information for the selected model alone, without displaying the rest of the scene.
Once you have saved the scene, you will see a new Avatar Configuration inspector, with a bone mapping.
The inspector shows which of the bones are required and which are optional - the optional ones can have their movements interpolated automatically. For Mecanim to produce a valid match, your skeleton needs to have at least the required bones in place. In order to improve your chances for finding a match to the Avatar, name your bones in a way that reflects the body parts they represent (names like “LeftArm”, “RightForearm” are suitable here).
If the model does NOT yield a valid match, you can manually follow a similar process to the one used internally by Mecanim:-
  1. Sample Bind-pose (try to get the model closer to the pose with which it was modelled, a sensible initial pose)
  2. Automap (create a bone-mapping from an initial pose)
  3. Enforce T-pose (force the model closer to T-pose, which is the default pose used by Mecanim animations)
If the auto-mapping (Mapping->Automap) fails completely or partially, you can assign bones by either draging them from the Scene or from theHierarchy. If Mecanim thinks a bone fits, it will show up as green in the Avatar Inspector, otherwise it shows up in red.
Finally, if the bone assignment is correct, but the character is not in the correct pose, you will see the message “Character not in T-Pose”. You can try to fix that with Enforce T-Pose or rotate the remaining bones into T-pose.

Avatar Body Masks

Sometimes it is useful to restrict an animation to specific body parts. For example, an walking animation might involve the character swaying his arms but if he picks up a gun, he should hold it in front of him. You can use an Avatar Body Mask to specify which parts of a character an animation should be restricted to.

Muscle setup

Mecanim allows you to control the range of motion of different bones using Muscles.
Once the Avatar has been properly configured, Mecanim will “understand” the bone structure and allow you to start working in the Muscles tab of the Avatar Inspector. Here, it is very easy to tweak the character’s range of motion and ensure the character deforms in a convincing way, free from visual artifacts or self-overlaps.
You can either adjust individual bones in the body (lower part of the view) or manipulate the character using predefined deformations which operate on several bones at once (upper part of the view).

Muscle Clips

In the Animation tab, you can set up Muscle Clips, which are animations for specific muscles and muscle groups.
You can also define which body parts these muscle clips apply to.

Retargeting of Humanoid animations

One of the most powerful features of Mecanim is retargeting of humanoid animations. This means that with relative ease, you can apply the same set of animations to various character models. Retargeting is only possible for humanoid models, where an Avatar has been configured, because this gives us a correspondence between the models’ bone structure.

Recommended Hierarchy structure

When working with Mecanim animations, you can expect your scene to contain the following elements:-
  • The Imported character model, which has an Avatar on it.
  • The Animator Component, referencing an Animator Controller asset.
  • A set of animation clips, referenced from the Animator Controller.
  • Scripts for the character.
  • Character-related components, such as the Character Controller.
Your project should also contain another character model with a valid Avatar.
The recommended setup is to:
  • Create a GameObject in the Hierarchy that contains Character-related components
  • Put the model as a child of the GameObject, together with the Animator component
  • Make sure scripts referencing the Animator are looking for the animator in the children instead of the root; use GetComponentInChildren<Animator>() instead of GetComponent<Animator>().
Then in order to reuse the same animations on another model, you need to:
  • Disable the original model
  • Drop in the desired model as another child of GameObject
  • Make sure the Animator Controller property for the new model is referencing the same controller asset
  • Tweak the character controller, the transform, and other properties on the top-level GameObject, to make sure that the animations work smoothly with the new model.
  • You’re done!
Previous
Muscle setup

No comments:

Post a Comment