映射和绑定关节和骨骼

时间:2016-01-07 15:21:04

标签: animation unity3d-mecanim

在Unity中使用mecanim-rigged角色时,我可以简单地将我的MoCap设备段绑定到mecanim骨骼上并为角色设置动画,因此我实际上不必查找或查找mecanim骨骼,因为它们已定义且可访问通过HumanBodyBones并使用Animator

(至少,我认为情况就是这样,但如果我错了,请纠正我......)

因此,例如,通过下面的简单过程,我将自己的动画片段映射到mecanim角色,然后使用我的MoCap设备实时制作动画:

    private Dictionary<XsAnimationSegment, HumanBodyBones> mecanimBones;


    public enum XsAnimationSegment
    {
        Pelvis = 0,
        .
        .
        .
        Neck = 21,
        Head = 22
    }


    int[] segmentOrder =
    {
        (int)XsAnimationSegment.Pelvis,
        .
        .
        .
        (int)XsAnimationSegment.Neck,
        (int)XsAnimationSegment.Head
    };



    protected void mapMecanimBones()
    {
        mecanimBones = new Dictionary<XsAnimationSegment, HumanBodyBones>();

        mecanimBones.Add(XsAnimationSegment.Pelvis, HumanBodyBones.Hips);
        .
        .
        .
        mecanimBones.Add(XsAnimationSegment.Neck, HumanBodyBones.Neck);
        mecanimBones.Add(XsAnimationSegment.Head, HumanBodyBones.Head);
    }

所以,我将我的模型联合体Pelvis绑定到Unity的mecanim Hips。不需要寻找臀部等...我甚至可以通过使用:

来获得骨骼的变换
XsAnimationSegment segID = (XsAnimationSegment)segmentOrder[i];             
HumanBodyBones boneID = mecanimBones[(XsAnimationSegment)segmentOrder[i]];
Transform tmpTransf = animator.GetBoneTransform(boneID);

现在,我正在尝试在不同的骨架上进行此映射,并使用我的MoCap设备为其设置动画。显然,我必须找到关节和地图&amp;将它们绑定到我的MoCap段。那么,暂时忘记mecanim,让我们在这个新骨架的关节的开头添加Jt来区分它:

    private Dictionary<XsAnimationSegment, BradBodyBones> bradBones;

    public enum XsAnimationSegment
    {
        Pelvis = 0,
        .
        .
        .                        
        Neck = 21,
        Head = 22
    }


    int[] segmentOrder =
    {
        (int)XsAnimationSegment.Pelvis,
        .
        .
        .
        (int)XsAnimationSegment.Neck,
        (int)XsAnimationSegment.Head
    };


    public enum BradBodyBones
    {
        JtPelvis = 0,
        .
        .
        .
        JtSkullA = 21,
        JtSkullB = 22
    }

现在,映射&amp;我认为,绑定功能应该如下所示:

    protected void mapBradBones()
    {
        bradBones = new Dictionary<XsAnimationSegment, BradBodyBones>();

        GameObject JtPelvis = this.transform.Find("ChrBrad/CharacterRoot/JtRoot/JtPelvis").gameObject;
        bradBones.Add(XsAnimationSegment.Pelvis, BradBodyBones.JtPelvis);
        .
        .
        .
        // Rest of the joints; e.g. Neck, Head, etc...
    }

但这不符合我认为应该做的事情,因为在我的脚本中稍后会抛出以下代码片段中的错误消息:

        for (int i = 0; i < XsSegmentCount; i++)
        {
            XsAnimationSegment segID = (XsAnimationSegment)segmentOrder[i];
            BradBodyBones boneID = bradBones[(XsAnimationSegment)segmentOrder[i]];
            try
            {
                if (boneID == BradBodyBones.JtPelvis)
                {
                    // Do something
                }
                else
                {
                    // Dos omething else
                }
            }
            catch (Exception e)
            {
                Debug.Log("Cannot find " + boneID + " in " + model.name + e);                 
                return false;
            }
        }

我很感激有关如何处理这种情况的任何帮助/建议/提示。

0 个答案:

没有答案