【Unity 优化】Skinned-Mesh 能动态合并嘛?

版权声明:本文为博主原创文章,欢迎转载。请保留博主链接:http://blog.csdn.net/andrewfan https://blog.csdn.net/AndrewFan/article/details/78018755

I’v tryed to combine the skinned meshes today.
I can combine all the skinned meshes to one now.And they looks like at the right position and with the right uvs. However , It’s just a static mesh,it can not do any animation.I checked the API of Unity, I found that ,mybe it is not possible to combine all meshes with animation. The reseaon is here:
- Every mesh has huge vertices and boneWeights , one boneWeight per one vertex.The boneWeight contains up to 4 indexes and weights relative to the bindPose list.
- The bindPose list is a array of Matrixes , every Matrix means a trasformation relative to the skinned-mesh’s rootBone.
- The boneWeights are just used as weight-calculation of up to 4 bindPose matrixes , the result is one average matrix relative to the skinned-mesh’s rootBone.
At last , we can think out the calculation process of the vertex’s position.
vertex world transformation <= weight-calculated matrix to the rootBone <= rootBone’s transformation is animated by the animation
This is the relation process. Then, for example, one animation contains 5 bones, and 7 skinned-meshes , the 7 skinned-meshes are relative to diffrent bones, even we’ve combined the meshes ,we just got the static mesh, one mesh can’t rely on 5 rootBones, so it lost the animation feature.
So, I think maybe it is the result: we only can get the static mesh , with no animation.

I’m glad to tell you that the baking does work now.And all problems are resolved.
I think there are 4 key points:
1、The rootBone is not important ,even maybe it is not need.
2、All mesh points all calculated relative to the bones,and when using the Unity’s Combination,it combine all the bones together to a new big bones set.
So, every thing is ok,bones are still work.
3、We juse need to collect all the bones in original skinned-meshes,and give the array of bones to the new created Skinned-Mesh(set the bones).
4、Before do out combination, we need to set all skinned-meshes to standard state (with no scal,tranlate or rotate), and move the animation node to world center, with no scal and rotation, then do the combination,when finished,we can take the animation node back to old state.
That’s it. I think it works now. I will update my plug-in tomorrow.