Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis on the use of Model Animation in Unity3D

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the analysis of the use of model animation in Unity3D. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

How do I import a model and how does the imported model appear in the project panel of unity3d? What does it contain? How do I load it into the scene? How to control it? What is the relationship between model and animation?

[model Import]:

Unity can read files in fbx,dae,3ds,dxf,obj and other formats, and you can find the FBX exporter here

Http://usa.autodesk.com/fbx/

The model in each imported project contains the following:

Meshes mesh, each model is composed of countless triangles.

Related options:

Scale Factor scaling factor adjusts the scale of the model

Use File Units uses this file unit only for 3dsMax files, 1Max=1Unity when enabled, otherwise 1 cm Max=1Unity

Mesh Compression grid compression is within the range of differences allowed. Try to increase this value.

Mesh Optimization mesh optimization determines the order of triangles in the mesh

Does Generate Colliders generate mesh Collider or not?

Swap UVs swap UV enable this option when the UV channel of an object with a light map is incorrect

Generate Lightmap UVs generates Lightmap UV creates a second UV channel for Lightmap

Normals & Tangents normals and tangents, which are mainly used to describe the orientation of triangles, can be applied to trimming (showing only the front, not the back) lighting

Related options:

Normals normals import normals by default, optional Calculate calculates normals based on smoothness, or disables

Tangents tangents tangents work only when normals are enabled. The default is automatic calculation, and you can choose to import and disable them.

Smoothing Angle smooth Corner sets the smoothness of the corners, which is used to split normal map tangents?

Split Tangents detach tangents turn on this option if the seams on your mesh break the normal map lighting. This usually applies only to roles.

Materials material, mainly describes the color, the display under various lighting effects, as well as the above map!

Related options:

If Import Materials imported materials is off, all materials are diffuse

Material Naming material naming map name, material name, model-material name, etc.

Material Search material search determines how to find existing materials based on material names.

Animations animation, if this file is accompanied by animation, you can see it here

Related options:

Generation generation controls the import of animation and where the animation is stored (Root or Node)

Bake Animations baked animation is used for animations using IK

Animation Wrap mode Animation Loop Mode

Split Animations split animation

The method of compressing Anim.Compression Animation

Anim.Compression.Errors sets error control when compressing keyframes

What you need to pay attention to is! The model we imported does not contain maps. To import a model, you need to import the maps used in the model materials at the same time! The rule for U3D to search for maps is the Textures folder under the path of the model, and then gradually search the Textures folder in the parent directory, and then search globally if you can't find it (slow, and may make a mistake when two textures have the same name)

For each imported material, Unity uses the following rules:

1. If the Import material option is disabled, all materials default to diffuse materials

two。 According to the material name set to Unity, the material name

3. Look for a material with the same name among the existing materials

4. If you find the material, you will assign it directly to the object, otherwise a new material will be generated

Unity provides two types of colliders, a Mesh Colliders Grid Collider, which can accurately detect collisions, while the Primitive Colliders primitive Collider, although not as accurate as the former, is much more efficient, so it should be used as much as possible.

If you have a character with normal mapping generated from a high-precision polygon version, you should import the game quality version of this character at a smoothing angle of 180 degrees (Smoothing angel). This will prevent strange seams in the light due to tangent cutting. If seams still exist after applying these settings, turn on the split tangents at UV seams option (Split tangents across UV seams).

[animation Import]

Maya .mb, .ma files, Cinema 4D c4d files and fbx files all support the export of animations, and when we import these models, we can import animations incidentally

1. Segmented animation uses animation segmentation to import animation, and all the actions are put in the same model, which is the most resource-saving. when importing the model, the segmented animation is automatically imported, and all animation clips can be seen in the split animation table.

2.@ Animation creates a separate model file and names it according to the format "Model name" @ "Animation name" .fbx. When importing the model file, Unity automatically imports the animation file related to the model. When you export such a file, you export the model separately, and then export clips of all actions.

3. Reverse dynamic settings for baking IK and simulation box?

[animation script]

The related interface http://game.ceeger.com/Script/Animation/Animation.html of animation script

If you want to play a simple animation, use Animation.Play

If you want to cross-fade between animations, you can use Animation.CrossFade

If you want to change the animation mode (loop, once, ping-pong), you can change the WrapMode of the animation frame in the animation import settings, or change the value of AnimationState.wrapMode at run time

AnimationState can be used to change the layers of the animation, modify the playback speed, and directly control blending and blending.

Animation overlay, blending, layering, etc.-- refer to hello world--angrybots of U3D

Animation is a component that can be added to GameObject. When we mount a script to a GameObject, we can access the animation mounted on it through the animation member variable. There are these animation methods.

Animation

AddClip add clip

AnimateOnlyIfVisible visible time animation

Whether animatePhysics is physical animation

Blend mixing

Clip clip

CrossFadeQueued fade in and out queue

CrossFade fade in and out

CullingType blanking type

GetClipCount gets the number of clips

Is IsPlaying playing?

Is isPlaying playing?

LocalBounds local bounding box

PlayAutomatically auto playback

PlayQueued playback queue

Play playback

RemoveClip remove clip

Rewind rewind

Sample sampling

Stop stop

SyncLayer synchronization layer

This [string name] operation name

WrapMode cycle mode

Animation blend:

To ensure that the character's animation is smooth, when we want to transition from one animation to another in the game, we don't want a sudden jump between the two actions, but want a smooth transition.

We use CrossFade ("animate name") to smoothly switch to another animation (probably a motion tween in the middle)

Animation layer:

Layers allow crowd animation and priority, the transition between animations, you can use CrossFade or specify manual fusion weights to automatically handle the weights of animations. When the weights of both animations are 100%, unity will normalize the final animation weights, which means that both of them account for 50% of the weights, but in the case of priority, you need to set which animation has a higher weight, and make sure that the sum of the weights is 100%. It's much easier to use layers.

The easiest way to do this is to simply keep walking and idle animation while shooting, and then we need to make sure that shooting animation is at a higher level than idle and walking animation. This means that the shooting animation will first receive fusion weights. Walking and idle animations receive weights only when the shooting animation does not use a blend weight of 100%. Therefore, when you cross-fade in and out of the shooting animation, the weight will change to 100% in a short time from 0, and the walking and free layers will still receive fusion weights at the beginning, but when the shooting animation is fully cut in, they will no longer receive weights. that's exactly what we need!

Function Start () {/ / Set all animations to loop animation.wrapMode = WrapMode.Loop; / / except shooting animation ["shoot"]. WrapMode = WrapMode.Once; / / Put idle and walk into lower layers (The default layer is always 0) / / This will do two things / /-Since shoot and idle/walk are in different layers they will not affect / / each other's playback when calling CrossFade. / /-Since shoot is in a higher layer, the animation will replace idle/walk / / animations when faded in. Animation ["shoot"]. Layer = 1; / / Stop animations that are already playing / / (In case user forgot to disable play automatically) animation.Stop ();} function Update () {/ / Based on the key that is pressed, / / play the walk animation or the idle animation if (Mathf.Abs (Input.GetAxis ("Vertical")) > 0.1) animation.CrossFade ("walk"); else animation.CrossFade ("idle") / Shoot if (Input.GetButtonDown ("Fire1")) animation.CrossFade ("shoot") } Animation Playback and Sampling animation playback and sampling: the word sampling may not be easy to understand. Sampling in Unity is a term related to rendering, that is, pixel sampling is a comprehensive operation. Our animation is constantly moving, extracting the current motion state of the animation and rendering it to the screen. This is my understanding of sampling. We edit an animation in a model editing tool such as 3ds Max or Maya, and we create the animation at a certain frame rate (FPS). When the animation is imported into U3D, the frame rate is also imported, so it is consistent with the rate of the editor. However, the frame rate of our game is not stable, there may be hardware reasons or the object to be rendered, the logical complexity of processing is different, and the frame rate is unstable. If we play according to the frame rate set by it, the animation will be stuck one card at a time. Unity samples the animation at a variable frame rate, not at the frame rate at the time of production. 3D computer graphics animation is not made up of scattered animations, but continuous curves. These curves allow us to sample at any point in time, rather than just corresponding to the point in time of an original frame. In this way, when our computer is faster, the animation will be more smooth and smooth. For most practical applications, the fact that Unity samples variable frame rates is not a concern, however, if your game logic depends on animation transformations or attribute animation in a very special configuration, you must know this. For example, if you have an animation that rotates an object from 0 to 180 degrees in 30 frames, you want to know from the code that when it is halfway through, you can't write a conditional statement to check whether the current rotation value is 90 degrees. Because Unity samples the animation according to the rate of change in the game, it may sample when the rotation is as fast as 90 degrees, or just past 90 degrees. When you specify a point to arrive in an animation, you need to be notified and AnimationEvent should be used instead. Also note that the result of varying frame rate sampling is that a sample of an animation played in WrapMode.Once mode is not necessarily the exact last frame. It is likely to be a frame just before the end of the game, and the time of the next frame may exceed the length of the animation, so it is disabled and no longer sampled. If you need accurate sampling of the last frame of the animation, you can use WrapMode.ClampForever. As in this case, the animation in this case, the animation will remain infinitely sampled the last frame until you stop the animation.

[animation view]

Press Ctrl+6 to pop up the animation editing view, select any object on the Hierarchy panel, and edit their animation.

After reading the above, do you have any further understanding of the analysis of the use of model animation in Unity3D? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report