In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use spin in unity. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.
skeletal animation
First let's look at exactly what skeleton animation is:
On earlier machines, rendering itself already consumed a lot of CPU resources, so for rendering, a space-for-time strategy was often adopted to avoid continuing to burden the CPU in the rendering of models. Frame animation models emerge under these conditions. The most famous frame animation format is MD2, which is used by Quake2. To this day, frame animation still exists, but frame animation is more about describing small and relatively less moving objects.
After the GPU appeared, CPU problems were no longer as prominent as before, and some new methods and technologies could be applied. Bone animation is more flexible than frame animation, but at the same time, bone animation requires more calculation, so bone animation is often applied to models that need to focus on details of actions.
Skeleton animation technology came after frame animation technology. Initially, skeletal animation was used only in non-real-time rendering modeling applications, such as 3DMax, to facilitate artist modeling. Later, after the CPU was freed from rendering, skeleton animation was used in real-time rendered games.
Skeleton Animation Principles
The idea for skeletal animation comes from human bones. For example, all muscles and skin of the upper limbs are affected by the bones of the upper limbs, while the ankles are affected by the bones of the lower legs and feet respectively. According to this we can understand skeletal animation as two concepts: Skeleton: An abstract concept used to control skin, such as human skeleton control skin. Skin: Factors that are controlled by bones and displayed externally, such as the skin of the human body being influenced by bones.
SKINMESH
In the final rendering result, the skin will be fully visible, essentially the elements whose vertices, normals, and texture coordinates will be rendered. The most important of these is, of course, the vertices, which will be pulled directly by the bones, thus making the entire model appear as determined by the bones.
SKELETON
A skeleton is an abstract concept that is invisible in the final rendered result. A skeleton is a tree-like collection of bones, each of which is associated with a number of skin vertices. When a bone moves, all skin vertices associated with it also move under the influence of the bone.
The association of bones to skin vertices needs to take into account the influence of each bone on the skin vertices. Although in most cases a vertex will be influenced by only one bone, vertices at joints are often influenced by multiple bones, such as the ankle joint, which may be influenced by 50% of the leg bone and 50% of the foot bone, respectively. This influence is called weight. In this case, we call these vertices of the ankle joint 50% weighted by the leg bone and 50% weighted by the foot bone.
Unity Skeleton Animation Plug-ins
In Unity3D, there are many bone animation plug-ins, such as Uni2D,SmoothMovoe, Puppet2D, etc., but in order to facilitate the editing of our project, we use spine.
Spine Introduction
Spine is easy to use, and it provides mesh, usually a texture has only 4 vertices, bottom left, bottom right, top left, top right, but with mesh, we can grab this image, and set a large number of vertices to it, and then we can complete the stretching deformation of the image by setting the vertices, such as the milk shake function.
Spine 30 frames for 1s, the latest version also provides IK, you can fix bones, do actions
Import bone animation in Unity
1: Prepare the runtimes needed for unity to use Spine at github.com/EsotericSoftware/spine-runtimes/tree/master/spine-unity
Use git to download, or download master.zip file directly.
2: Prepare Spine exported animation files, just recently occasionally play a game, which uses Spine made skeleton animation, I will directly use it to do a good job of recording the steps, only for notes to use.
The animation file resources I have here are as follows:
Here you need to do a preparatory work in advance, rename the enemy_hunter.atlas file in the above picture as enemy_hunter.atlas.txt, because unity cannot recognize the.atlas file, and the resource import cannot be carried out later.
3: Now that we are ready to work, we can create a unity project.
a: Copy the spine-runtimes-master\spine-unity\Assets\spine-unity folder in the master.zip file to the Assets folder of the project
b: Copy everything in the spine-runtimes-master\spine-csharp\src folder in the master.zip file to the Assets\spine-csharp folder of the project
4: Import Resources
a: Here I right-click in the resource panel to create a new folder, used to store imported resources, the recommended import order is ".png" ".json" ".atlas.txt", so that in the final import ".atlas.txt" file, will automatically generate enemy_hunter_Material.mat file and enemy_hunter_Atlas.asset file.
b: Right click to create a new "spine skettonData" type file, named "enemy_hunter_SkeletonData.asset", here combined with online information, feeling the previous version, should be automatically generated, do not know why you need to manually create this file, the previous version has not been used, pure speculation. After the file is created, you need to configure Skeleton JSON properties, specify the file "enemy_hunter.json", and then click the "Attempt Reimport" button. After completion, as shown in the figure:
So far, the import of bone animation is complete.
5. Now let's add this skeleton animation to the scene and see how it works.
Create a Spine SkeletonAnimation object with Skeleton Data Asset properties specified as "enemy_hunter_SkeletonData.asset" file. Then select an action in the Animation property of Advanced, check the Loop property, you can loop.
As shown in the figure:
6: The effect can now be played in the Game panel. The Spine skeleton animation import unity is now complete!
Using Bone Animation in Unity
Spine can be used to animate bones for unity. Spine provides unity runtime packages. The version of the runtime package must be consistent with the spin version, otherwise an error will be reported.
Import spine animation:
There are three animation files exported by spine: xx.atlas, xx.json, xx.png. Importing these three files directly into unity will report an error. Change xx.atlas to xx.atlas.txt, and xx_Atlas.asset,xx_Material.mat will be automatically generated. Then create spine SkeletonData in unity, specifying xx_Atlas.asset and xx.json. You can use SkeletonData to generate animation.
Control animation playback:
SkeletonAnimation skeletonAnimation; //component of gameobject. Spine.AnimationState spineAnimationState = skeletonAnimation.state;Spine.Skeleton skeleton;spineAnimationState.SetAnimation(0, animationName, true);
Switch animation bugs:
Smooth transition for animation because spine compensates automatically when switching animations. However, it will cause bugs such as afterimages. In this case, you need to call before SetAnimation.
skeletonAnimation.skeleton.SetToSetupPose ();spineAnimationState.ClearTracks ();
to eliminate the effects of the previous animation.
Add Event:
skeletonAnimation.state.Start: Start playback SkeletonAnimation.state.End: animation cleared or interrupted SkeletonAnimation.state.Interrupt: animation interrupted SkeletonAnimation.state.Complete: end playback SkeletonAnimation.state.Event: user-defined event
Event settings take lambda expressions:
skeletonAnimation.state.Complete += (state, trackIndex,loopCount) => { Debug.log(""); };
Get slot coordinates dynamically:
Vector3 pos = SkeletonAnimation.skeleton.FindSlot("hat_1").Bone.GetWorldPosition(transform); About "unity in how to use" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.