Unity Programming Unity Animation System (i)

Source: Internet
Author: User
Tags automap

Unity Animation System

The Unity animation system, also known as "Mecanim", provides the following features:

    • A simple workflow that sets all the elements of an animation, including objects, roles, and attributes.
    • Support for importing animated segments created externally and animated segments made with the built-in animation editor.
    • Human-type animation repositioning, motion control of animated characters can be shared by all role models, i.e. the appearance (Skinedmesh) and movement (Animator) of the character are separated, and they are combined to form the final animation.
    • A streamlined workflow for editing the state of an animation, the animation controller.
    • Easily preview animation segments, as well as interpolation transitions between fragments. This allows the animator to work independently of the programmer and can preview the prototype and preview animations without running the game.
    • Manage complex interactions between animations and visual programming tools.
    • Different parts of the body can be controlled using different animation logic.
    • The layering and masking capabilities of animations.

Animation production process
    • Animation segment production: The animation segment is the basis of the Unity animation system, which contains information about how an object changes its position, rotation, or other properties over time. Each fragment can be thought of as a single linear record. Animated segments from outside are made by third-party tools, such as Max or Maya, or from motion capture.
    • Animation controller editing: using animation controller to organize animation segment, animation controller is similar to the flowchart structure of the system (such as), it has a "state machine" to control the current animation segment playback, and when to switch between different fragments, including animation between the interpolation transition and mixing, The contents of the animation controller are saved as a suffix named ". Controller" file.
    • Fragment blending settings: A very simple animation controller may contain only one or two clips, such as animations that control the opening or closing of doors at the right time. A more advanced animation controller may contain dozens of humanoid animation segments to represent all of the protagonist's actions, and can be blended across multiple clips to provide smooth movements as the character moves through the scene.
    • Binding animations and models: Unity's animation system also has special features to handle humanoid animations, allowing you to reposition humanoid animations from any source, such as motion capture, Asset store downloads or other third-party animation libraries, to your own character model, while defining muscle adjustments. These special features are provided by Unity's avatar system, which maps a humanoid character to a common internal format.
    • Referential relationships: All of these-animation segments, animation controllers, and avatar-are all grouped together by animator components on the gameobject. The animator component has a reference to the animation controller and a reference to the avatar of the model, if necessary. The animation controller contains a reference to the animated segment it uses.

Unity's animation system (known as "Mecanim") comes with a number of concepts and terms that can be found in the animation glossary.

Traditional animation system

While Mecanim is recommended in most cases, unity retains the traditional animation system that existed before Unity 4. For information about the traditional animation system, see "Here"
Unity will merge the workflow into Mecanim in the future, phasing out the legacy animation system.

Cartoon paragraph (animationclip)

The animation segment is one of the core elements of the Unity animation system. Unity supports importing animations from external sources, as well as a simple built-in motion editor that lets you create animated segments from scratch, which is currently not supported for human animation editing.

Animations originating from the outside

Animation segments that originate from an external import may include:

    • Motion capture the humanoid animations obtained
    • Animations created in an external 3D application (such as 3DS Max or Maya)
    • An animated set from a third-party library (for example, a resource store from unity)
    • Multiple animated segments obtained after cutting the timeline of an imported single animated segment.

Animations created and edited in Unity

You can also create and edit animation segments from the Unity animated interface, which can change the following:

    • The position, rotation, and proportions of the game object.
    • Component properties, such as the color of the material, the intensity of the light, the volume, and so on.
    • Properties defined in your own script, including Float,int,vector and bool variables
    • A timed call function defined in your own script

Animations originating from the outside

External animations are imported into unity in the form of normal 3D files. These files, whether generic FBX files or native formats such as Maya,cinema 4d,3d Studio Max, can store animation data of the object's motion in a linear record in a file.

Sometimes, the goal of executing a motion (for example, a character) and the motion animation associated with it can exist in the same file. Also sometimes, animations may be stored in separate files, separated from the target model.

Some animations are made separately for special models and cannot be reused on other models. For example, you may have an ultimate boss in your game, a giant octopus with unique limbs and bone distribution, and a set of animations that belong to it.

In most other cases, you might have an animation library for a variety of different models in your scene. For example, some of the different humanoid characters may use the same walking and running animations. In these cases, a simple alternative model is typically placed in the animation file for previewing. Even if they do not have a geometric model at all, they contain only animated data and can also use this animated file.

When importing multiple animation segments, each animation segment can exist as a project file alone. You can also export multiple animation segments to a single FBX file when exporting from the plugins of the motion editor, such as Maya and Max. You might need to do this if your file contains multiple individual animation segments arranged on a single timeline. For example, in an animated timeline with a long capture time, you might have several different animations of jumping motion, and you might want to use some of them as a single fragment and discard the rest of the sections. Unity provides an animated clipping tool to achieve area clipping by allowing you to select a frame range for each fragment and to import all animations on one timeline.

Import an animation file

Before you can use animations in unity, you need to import them into your project first. Unity can import native Maya (. MB or. Ma), 3D Studio Max (. max) and Cinema 4D (. c4d) files, and generic fbx files that can be exported from most animation software (for more information on exporting, see here). To import an animation, simply drag the file to the project's assets folder. When you select a file in the Project panel, you can edit the import settings in the Inspector panel:

For a complete description of the available import options, see the FBX Import page.
View and copy data from an imported animation file.
You can view keyframes and curves for an imported animation segment in the Animation screen. Sometimes, if these imported fragments have many keyframes and multiple bones, the amount of information can seem very complex. For example, the image below is the look of a humanoid run animation in the "Animation" interface. Note that animation can not only create and edit internal animations, but also explore animations originating from external imports, where the animation is read-only and cannot be edited "

Opens the animation interface, then selects the specified animated Gameobject (node with the animator component or its child nodes), and the animation interface displays the keyframes and curves of the skeletal animation.

When viewing imported animation keyframes, the Animation interface provides a read-only view of the animated data. To edit this data, create a new empty animation segment in unity (see Create a new animated clip), and then select, Copy, and paste the animated data from the imported animated segments to your newly created writable animation segment.

Using humanoid animations

The Mecanim animation system is particularly suitable for animation of human animal skeletons. Because humanoid bones are widely used in games, Unity offers a dedicated workflow and an extended toolset for humanoid animations.

Because of the similarity of skeletal structures, it is called possible to map animations from one human skeleton to another, allowing repositioning and inverse kinematics. In addition to rare exceptions, the class human biological model can have the same basic structure, connecting the body, the head and the limbs representing the main expression part. The Mecanim system makes full use of this idea and simplifies the assembly and control of animations. One of the basic steps in creating an animation is to build a mapping between the simplified human skeleton structure and the actual bones that exist in the skeletal animation that Mecanim can understand, and in Mecanim terminology, this mapping is called Avatar. The pages in this section explain how to create avatar for your model.

Create Avatar

When a model file (FBX, COLLADA, etc) is created and imported, you can specify its import type in the Rig panel.

Humanoid animation

If it is a humanoid structure, select "Humanoid" and then click "Apply". Mecanim will attempt to match the current model bone structure to the avatar bone structure. In most cases, this step is done automatically through the internal analysis of the links between the two skeleton structures.

If the match succeeds, you will see a "√" mark on the side of the "Configure" menu.

In addition, in the case of a successful match, a Avatar child resource will be added to the model resource, and you will be able to see it in Project view.

Select this Avatar sub-resource, there will be a "Configure Avatar" button in the Inspector panel, click this button will enter the Avatar configuration mode. (If the model is imported as a generic type, although it will also produce avatar sub-resources, but in fact it is not configurable, the occurrence of Avatar only indicates that it is a humanoid structure, can be connected to other avatar, as the skin)

If Mecanim failed to create the Avatar successfully, you will see an "X" tag next to the "Configure" button and no Avatar child resources are added. When this happens, you need to manually configure the avatar.

Non-humanoid animations

Unity offers two additional options: Generic (General) and Legacy (Legacy). General animations are imported using the Mecanim system, but cannot take advantage of the advanced features available for humanoid animations. Legacy animations Use the animation system that unity provided prior to Mecanim. In some cases, using legacy animations is still useful (most notable for legacy projects that you don't want to fully update), but new projects rarely need them. For more detailed information about traditional animations, see the "Legacy Animation System" section of the manual.

Configure Avatar

Because "Avatar" is an important aspect of the Mecanim system, you need to configure the appropriate Avatar for your model. Therefore, regardless of whether the automatic creation of Avatar fails or succeeds, you need to go into the Avatar configuration mode to check to make sure that the Avatar is valid and correct. Most importantly, your character's skeletal structure needs to match the Mecanim's predetermined bone structure, and the model is in a "T" pose.

If Mecanim failed to create the Avatar successfully, you will see an "X" tag next to the "Configure" button.

If the match succeeds, you will see a "√" mark on the side of the "Configure" menu.

The successful match here simply means that all the necessary bones have been matched, but for better results you may also need to match the optional bones and convert the model to the appropriate T-pose.

When you enter the configuration (Configure) menu, the editor asks you to save the scene. The reason is that in configuration mode, the scene view is used to display the skeleton, muscle, and animation information of the selected model separately, without showing the rest of the scene.

Once you has saved the scene, you'll see a new Avatar Configuration inspector, with a bone mapping.
When you save the scene, the Inspector inspector will appear with the Avatar Configuration Interface for bone mapping.

The inspector shows which bones are required and which are optional-the optional skeletal movement will be completed by automatic interpolation. In order for Mecanim to build a valid match, your model skeleton needs to contain all the necessary bones. In order to increase the odds of a successful match with "Avatar", Name your bones in a way that reflects the body parts. (such as "Leftarm", "rightforearm" is more appropriate).

If you do not have a valid match for the model, you can manually perform a process similar to the internal process within the Mecanim:

    • Sample bind-pose (samples binding, trying to make the model appear closer to the original posture when it was made into a model, the initial posture is easier to discern)
    • Automap (auto-map, create a bone map from the initial posture)
    • Enforce T-pose (Force T pose, force the model closer to the T-pose, which is the default posture used by the Mecanim animation)

If auto-mapping (mapping-> Automap) fails completely or partially, you can assign it by dragging bones from the scene or hierarchy panel. If Mecanim thinks the bone fits, it will appear green in the Avatar inspector or red.

Finally, if the bones are assigned correctly, but the role poses incorrectly, you will see the "Character Not in T-pose" message. You can try to fix it with "Enforce t-pose", or rotate the incorrect bones, resulting in a T-pose.

Avatar Body Masks Part

It is sometimes useful to limit animations to specific parts of the body. For example, a walking animation might involve swinging a character's arm, but if he picks up the gun, he should put his arm in front of him. You can use "Avatar body Mask" to specify which parts of the role should be restricted for an animation-for more information, see the Avatar Body Mask page.

Unity Programming Unity Animation System (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.