通过遮罩功能可以丢弃剪辑中的一些动画数据,从而让剪辑仅动画化对象或角色的某些部分而不是整体。例如,可能有一个标准的行走动画,其中包括手臂和腿部运动,但如果一个角色用双手抱着大型物体,那么不会希望其手臂在行走时向侧面摆动。但是,仍然可以在角色抱着物体时使用标准行走动画,但需要使用遮罩在行走动画的上层仅播放抱着物体动画的上半身部分。
Masking can be applied to animation clips either during import time, or at runtime. Masking during import time is preferable, because it allows the discarded animation data to be omitted from your build, making filesize and memory footprint smaller. It also makes for faster processing speed because there is less animation data to be blended at runtime. In some cases, import masking may not be suitable for your purposes, in which case you can apply a mask at runtime by creating an Avatar Mask asset, and using it in the layer settings of your Animator Controller. This page relates to creating an Avatar Mask asset.
There are two ways to define which parts of your animation should be masked. If your animation uses a Humanoid avatar, you have the option of using the humanoid body selection method which allows you to click on a simplified diagram of a humanoid body to select or deselect certain parts to mask.
The body parts included are: Head, Left Arm, Right Arm, Left Hand, Right Hand, Left Leg, Right Leg and Root (which is denoted by the “shadow” under the feet). In the body mask, you can also toggle inverse kinematics (IK) for hands and feet, which will determine whether or not IK curves will be included in animation blending.
Alternatively, if your animation does not use a Humanoid avatar, or if you want more detailed control over which individual bones are masked off, you can use the Transform method to select or deselect portions of the model’s hierarchy to mask. To do this, you must assign a reference to the avatar whose transform you would like to mask off, then click the “Import Skeleton” button. You will then see the hierarchy of the avatar listed in the inspector. Each bone has a checkbox allowing you to select or deselect parts of the hierarchy to use as your mask.
当指定动画层在运行时应用遮罩,或者在动画文件的导入设置中将遮罩应用于导入动画时,可在 Animator Controller 中使用遮罩资源。
使用遮罩的好处在于有助于减少内存开销,因为非活动身体部位不需要关联的动画曲线。此外,在播放期间不需要计算未使用的曲线,因此还有助于减少动画的 CPU 开销。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.