资源描述
Unity’s Animation features include Retargetable animations, Full control of animation weights at runtime, Event calling from within the animation playback, Sophisticated State Machine hierarchies and transitions, Blend shapes for facial animations, and more.
Read this section to find out how to import and work with imported animation and how to animate objects, colours, and any other parameters within Unity itself.
Animation System Overview
Unity has a rich and sophisticated animation system (sometimes referred to as ‘Mecanim’). It provides:
Easy workflow and setup of animations for all elements of Unity including objects, characters, and properties.
Support for imported animation clips and animation created within Unity
Humanoid animation retargeting - the ability to apply animations from one character model onto another.
Simplified workflow for aligning animation clips.
Convenient preview of animation clips, transitions and interactions between them. This allows animators to work more independently of programmers, prototype and preview their animations before gameplay code is hooked in.
Management of complex interactions between animations with a visual programming tool.
Animating different body parts with different logic.
Layering and masking features
Animation workflow
Unity’s animation system is based on the concept of Animation Clips, which contain information about how certain objects should change their position, rotation, or other properties over time. Each clip can be thought of as a single linear recording. Animation clips from external sources are created by artists or animators with 3rd party tools such as Max or Maya, or come from motion capture studios or other sources.
Animation Clips are then organised into a structured flowchart-like system called an Animator Controller. The Animator Controller acts as a “State Machine” which keeps track of which clip should currently be playing, and when the animations should change or blend together.
A very simple Animator Controller might only contain one or two clips, for example to control a powerup spinning and bouncing, or to animate a door opening and closing at the correct time. A more advanced Animator Controller might contain dozens of humanoid animations for all the main character’s actions, and might blend between multiple clips at the same time to provide a fluid motion as the player moves around the scene.
Unity’s Animation system also has numerous special features for handling humanoid characters which give you the ability to retargethumanoid animation from any source (Eg. motion capture, the asset store, or some other third-party animation library) to your own character model, as well as adjusting muscle definitions. These special features are enabled by Unity’s Avatar system, where humanoid characters are mapped to a common internal format.
Each of these pieces - the Animation Clips, the Animator Controller, and the Avatar, are brought together on a GameObject via theAnimator Component. This component has a reference to an Animator Controller, and (if required) the Avatar for this model. The Animator Controller, in turn, contains the references to the Animation Clips it uses.
The above diagram shows the following:
Animation clips are imported from an external source or created within Unity. In this example, they are imported motion captured humanoid animations.
The animation clips are placed and arranged in an Animator Controller. This shows a view of an Animator Controller in the Animator window. The States (which may represent animations or nested sub-state machines) appear as nodes connected by lines. This Animator Controller exists as an asset in the Project window.
The rigged character model (in this case, the astronaut “Astrella”) has a specific configuration of bones which are mapped to Unity’s common Avatar format. This mapping is stored as an Avatar asset as part of the imported character model, and also appears in the Project window as shown.
When animating the character model, it has an Animator component attached. In the Inspector view shown above, you can see the Animator Component which has both the Animator Controller and the Avatar assigned. The animator uses these together to animate the model. The Avatar reference is only necessary when animating a humanoid character. For other types of animation, only an Animator Controller is required.
Unity’s animation system (Known as “Mecanim”) comes with a lot of concepts and terminology. If at any point, you need to find out what something means, go to our Animation Glossary.
Legacy animation system
While Mecanim is recommended for use in most situations, Unity has retained its legacy animation system which existed before Unity 4. You may need to use when working with older content created before Unity 4. For information on the Legacy animation system, see this section
Unity intends to phase out the Legacy animation system over time for all cases by merging the workflows into Mecanim.
Animation Clips
Animation Clips are one of the core elements to Unity’s animation system. Unity supports importing animation from external sources, and offers the ability to create animation clips from scratch within the editor using the Animation window.
Animation from External Sources
Animation clips imported from external sources could include:
Humanoid animations captured at a motion capture studio
Animations created from scratch by an artist in an external 3D application (such as 3DS Max or Maya)
Animation sets from 3rd-party libraries (eg, from Unity’s asset store)
Multiple clips cut and sliced from a single imported timeline.
Animation Created and Edited Within Unity
Unity’s Animation Window also allows you to create and edit animation clips. These clips can animate:
The position, rotation and scale of GameObjects
Component properties such as material colour, the intensity of a light, the volume of a sound
Properties within your own scripts including float, int, Vector and boolean variables
The timing of calling functions within your own scripts
Animation from External Sources
Overview of Imported Animation
Animation from external sources is imported into Unity in the same way as regular 3D files. These files, whether they’re generic FBX files or native formats from 3D software such as Maya, Cinema 4D, 3D Studio Max, can contain animation data in the form of a linear recording of the movements of objects within the file.
In some situations the object to be animated (eg, a character) and the animations to go with it can be present in the same file. In other cases, the animations may exist in a separate file to the model to be animated.
It may be that animations are specific to a particular model, and cannot be re-used on other models. For example, a giant octopus end-boss in your game might have a unique arrangement of limbs and bones, and its own set of animations.
In other situations, it may be that you have a library of animations which are to be used on various different models in your scene. For example, a number of different humanoid characters might all use the same walk and run animations. In these situations, it’s common to have a simple placeholder model in your animation files for the purposes of previewing them. Alternatively, it is possible to use animation files even if they have no geometry at all, just the animation data.
When importing multiple animations, the animations can each exist as separate files within your project folder, or you can extract multiple animation clips from a single FBX file if exported as takes from Motion builder or with a plugin / script for Maya, Max or other 3D packages. You might want to do this if your file contains multiple separate animations arranged on a single timeline. For example, a long motion captured timeline might contain the animation for a few different jump motions, and you may want to cut out certain sections of this to use as individual clips and discard the rest. Unity provides animation cutting tools to achieve this when you import all animations in one timeline by allowing you to select the frame range for each clip.
Importing Animation Files
Before any animation can be used in Unity, it must first be imported into your project. Unity can import native Maya (.mb or .ma), 3D Studio Max (.max) and Cinema 4D (.c4d) files, and also generic FBX files which can be exported from most animation packages (see this page for further details on exporting). To import an animation, simply drag the file to the Assets folder of your project. When you select the file in the Project View you can edit the Import Settings in the inspector.
Working with humanoid animations
The Mecanim Animation System is particularly well suited for working with animations for humanoid skeletons. Since humanoid skeletons are used extensively in games, Unity provides a specialized workflow, and an extended tool set for humanoid animations.
Because of the similarity in bone structure, it is possible to map animations from one humanoid skeleton to another, allowingretargeting and inverse kinematics. With rare exceptions, humanoid models can be expected to have the same basic structure, representing the major articulate parts of the body, head and limbs. The Mecanim system makes good use of this idea to simplify the rigging and control of animations. A fundamental step in creating a animation is to set up a mapping between the simplified humanoid bone structure understood by Mecanim and the actual bones present in the skeleton; in Mecanim terminology, this mapping is called an Avatar. The pages in this section explain how to create an Avatar for your model.
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 Model Importer 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.
Avatar added as a sub-asset
Selecting the avatar sub-asset will bring up the inspector. You can then configure the avatar.
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 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. See this section of the manual for further details on legacy animations.
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 the automatic 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:-
Sample Bind-pose (try to get the model closer to the pose with which it was modelled, a sensible initial pose)
Automap (create a bone-mapping from an initial pose)
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 the Hierarchy. 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 - see this page page for further details.
Untiy3D 动画系统
统一的动画功能包括Retargetable动画,在运行时动画完全控制重量,从内部事件调用动画播放,复杂的状态机结构和转换,混合形状的面部动画等等。
阅读本节来找出如何导入和使用进口动画和动画对象,如何团结内部颜色和任何其他参数。
动画系统概述
统一一个丰富而复杂的动画系统(有时称为“Mecanim”)。 它提供了:
简单工作流和设置所有元素的统一,包括对象的动画人物,和属性。
支持导入动画短片
人形动画重定向——从一个角色模型能够应用到另一个角色模型。
简化工作流程调整动画剪辑。
方便预览动画剪辑,转换和它们之间的相互作用。 这让动画师工作更独立于程序员,原型和预览动画游戏代码连接在前。
管理间复杂的交互动画可视化编程工具。
动画不同的身体部位和不同的逻辑。
分层和掩蔽特性
动画工作流程
动画系统是基于统一的概念动画短片包含关于特定对象信息应该改变他们的位置,旋转,或其他属性。 每个片段可以被认为是一个线性记录。 动画剪辑从外部来源是由艺术家和动画师等第三方工具Max或玛雅,或来自动作捕捉工作室或其他来源完成。
动画剪辑然后组织成一个结构化流程图一样的动画叫系统控制器。 动画控制器作为一个“状态机”跟踪剪辑现在应该改变或混合在一起。
一个非常简单的动画控制器可能只包含一个或两个片段,例如控制powerup旋转和跳跃,或有生命的一扇门打开和关闭在正确的时间。 更先进的动画控制器可能包含几十个人形动画的主要人物的行动,和可能之间的混合多个剪辑同时提供流体运动的球员围绕现场。
统一的动画系统也有许多特色处理人形角色给你的能力gdp8 %从任何来源(如人形动画。 动作捕捉,资产存储或其他第三方动画库)自己的角色模型,以及调整肌肉的定义。 这些特点使统一的Avata
展开阅读全文