Unity:附加骨骼

时间:2018-03-14 14:51:11

标签: animation unity3d blender mesh

我试图将程序上的骨骼附加到我拥有的一些自定义网格物体上。但是我有这个网格,当我将骨骼附加到它时表现得很奇怪,网格的一些顶点保持在原位并且在另一个测试网格上移动时不移动。我尽可能地缩小了问题的范围,而我目前的假设是它不是代码问题,但我不知道在网格上寻找什么可能导致这个问题。 代码:

public class BoneTest : MonoBehaviour {

// Use this for initialization
void Start () {
    CreateMeshBones();
}

[SerializeField] SkinnedMeshRenderer skinnedMeshRenderer;
[SerializeField] Transform boneTest;
public void CreateMeshBones()
{ 
    Vector3[] verts = skinnedMeshRenderer.sharedMesh.vertices;
    BoneWeight[] boneWeights = new BoneWeight[verts.Length];

    for (int i = 0; i < boneWeights.Length; i++)
    {
        boneWeights[i] = new BoneWeight();
        boneWeights[i].boneIndex0 = 0;
        boneWeights[i].weight0 = 1;
    }

    Transform[] bones = new Transform[1];
    bones[0] = boneTest;
    Matrix4x4[] bindPoses = new Matrix4x4[1];
    bindPoses[0] = bones[0].worldToLocalMatrix * skinnedMeshRenderer.transform.localToWorldMatrix;

    skinnedMeshRenderer.sharedMesh.boneWeights = boneWeights;
    skinnedMeshRenderer.sharedMesh.bindposes = bindPoses;

    skinnedMeshRenderer.bones = bones;
}

}

问题的礼物:https://media.giphy.com/media/5pYxkuZyVH9bgBbrea/giphy.gif 有问题的网格:https://drive.google.com/file/d/1qQgVcJIiha8-zC-7Zx8lW5_5hcZ_SxQS/view?usp=sharing 复制的统一包:https://drive.google.com/file/d/1Hk4gVuUVAAW3QAYTrJZjsWyn5bvNBB8b/view?usp=sharing 希望有人可以提供帮助

0 个答案:

没有答案