Unity:骨变换位置不一致

时间:2018-07-19 00:09:01

标签: c# unity3d

我想做的是通过将衣服中每个骨骼的变换设置为与人体模型中的相应骨骼相同的方式,将衣服附加到化身上。 但是,经过实验,我注意到

给出的骨骼位置
bone.transform.position;

与场景中的实际位置不同。

例如,在“ Head”骨骼上运行代码时,上述代码会产生位置(1.6,18,-.04),但是当我进入场景并检查骨骼时,其位置为(-0.7700785,1.117587 e-07,-2.235174e-08)。您可能会想,这会严重破坏该过程。

以下是相关方法:

//copies the bone transforms from the model to the desired article of clothing
private void CopyBones (GameObject art)
{

    //for each bone in the model, modify the corresponding bone in the article
    foreach (string path in bonePaths)
    {

        Transform fromBone = art.transform.Find("Armature/" + path);
        Transform toBone = model.transform.Find("Armature/" + path);

        if (fromBone == null || toBone == null)
            Debug.Log("Could not locate: " + path);

        else
        {

            //doing this doesn't work for some reason
            //fromBone.SetPositionAndRotation(toBone.transform.position, toBone.transform.rotation);

            fromBone.transform.position = toBone.transform.position;
            fromBone.transform.rotation = toBone.transform.rotation;

            //doing this doesn't work either
            //fromBone.SetParent(toBone);
            //fromBone.localPosition = new Vector3(0, 0, 0);
            //fromBone.localRotation = Quaternion.Euler(0, 0, 0);

        }
    }

}

0 个答案:

没有答案
相关问题