Unity3d 交换Mecaim骨骼的动画
我已经编写了一个函数来交换应用于mecanim骨骼的旋转;e、 g.左手和右手:Unity3d 交换Mecaim骨骼的动画,unity3d,unity3d-mecanim,Unity3d,Unity3d Mecanim,我已经编写了一个函数来交换应用于mecanim骨骼的旋转;e、 g.左手和右手: private void swapLimbsRots(Quaternion[] rotationsArray) { Quaternion bone1Rot = rotationsArray [(int)XsAnimationSegment.LeftHand]; // 16 Quaternion bone2Rot = rotationsArray [(int)XsAnimationSegment
private void swapLimbsRots(Quaternion[] rotationsArray)
{
Quaternion bone1Rot = rotationsArray [(int)XsAnimationSegment.LeftHand]; // 16
Quaternion bone2Rot = rotationsArray [(int)XsAnimationSegment.RightHand]; // 20
Quaternion temp = bone1Rot;
bone1Rot = bone2Rot;
bone2Rot = temp;
Debug.Log("I am called");
}
我只交换旋转,因为我认为这样就足够了。是这样,还是我也应该交换头寸
下面是我的更新方法,我相信它会交换左手和右手的旋转,然后使用新的旋转数组来更新我的统一角色:
void Update()
{
Vector3[] latestPositions;
Quaternion[] latestOrientations;
if (mvnActors.getLatestPose(actorID, out latestPositions, out latestOrientations))
{
if (swapLimbs)
{
swapLimbsRots(latestOrientations);
}
updateMvnActor(currentPose, latestPositions, latestOrientations);
updateModel(currentPose, targetModel);
}
当然,我的类变量包含必要的声明,如下所示。这就是函数中提到16
和20
的原因:
public bool swapLimbs = false;
private Dictionary<XsAnimationSegment, HumanBodyBones> mecanimBones;
/// The 23 segments numbers for the animation. The first part of the dictionary pairs.
public enum XsAnimationSegment
{
Pelvis = 0, // Hips
RightUpperLeg = 1,
RightLowerLeg = 2,
RightFoot = 3,
RightToe = 4,
LeftUpperLeg = 5,
LeftLowerLeg = 6,
LeftFoot = 7,
LeftToe = 8,
L5 = 9, // not used
L3 = 10, // Spine
T12 = 11, // not used
T8 = 12, // Chest
LeftShoulder = 13,
LeftUpperArm = 14,
LeftLowerArm = 15,
LeftHand = 16,
RightShoulder = 17,
RightUpperArm = 18,
RightLowerArm = 19,
RightHand = 20,
Neck = 21,
Head = 22
}
/// The segments order.
int[] segmentOrder =
{
(int)XsAnimationSegment.Pelvis,
(int)XsAnimationSegment.RightUpperLeg,
(int)XsAnimationSegment.RightLowerLeg,
(int)XsAnimationSegment.RightFoot,
(int)XsAnimationSegment.RightToe,
(int)XsAnimationSegment.LeftUpperLeg,
(int)XsAnimationSegment.LeftLowerLeg,
(int)XsAnimationSegment.LeftFoot,
(int)XsAnimationSegment.LeftToe,
(int)XsAnimationSegment.L5,
(int)XsAnimationSegment.L3,
(int)XsAnimationSegment.T12,
(int)XsAnimationSegment.T8,
(int)XsAnimationSegment.LeftShoulder,
(int)XsAnimationSegment.LeftUpperArm,
(int)XsAnimationSegment.LeftLowerArm,
(int)XsAnimationSegment.LeftHand,
(int)XsAnimationSegment.RightShoulder,
(int)XsAnimationSegment.RightUpperArm,
(int)XsAnimationSegment.RightLowerArm,
(int)XsAnimationSegment.RightHand,
(int)XsAnimationSegment.Neck,
(int)XsAnimationSegment.Head
};
/// Map the mecanim bones to xsens segments. 23 bones/segments
protected void mapMecanimBones()
{
mecanimBones = new Dictionary<XsAnimationSegment, HumanBodyBones>();
mecanimBones.Add(XsAnimationSegment.Pelvis, HumanBodyBones.Hips);
mecanimBones.Add(XsAnimationSegment.LeftUpperLeg, HumanBodyBones.LeftUpperLeg);
mecanimBones.Add(XsAnimationSegment.LeftLowerLeg, HumanBodyBones.LeftLowerLeg);
mecanimBones.Add(XsAnimationSegment.LeftFoot, HumanBodyBones.LeftFoot);
mecanimBones.Add(XsAnimationSegment.LeftToe, HumanBodyBones.LeftToes);
mecanimBones.Add(XsAnimationSegment.RightUpperLeg, HumanBodyBones.RightUpperLeg);
mecanimBones.Add(XsAnimationSegment.RightLowerLeg, HumanBodyBones.RightLowerLeg);
mecanimBones.Add(XsAnimationSegment.RightFoot, HumanBodyBones.RightFoot);
mecanimBones.Add(XsAnimationSegment.RightToe, HumanBodyBones.RightToes);
mecanimBones.Add(XsAnimationSegment.L5, HumanBodyBones.LastBone);
mecanimBones.Add(XsAnimationSegment.L3, HumanBodyBones.Spine);
mecanimBones.Add(XsAnimationSegment.T12, HumanBodyBones.LastBone);
mecanimBones.Add(XsAnimationSegment.T8, HumanBodyBones.Chest);
mecanimBones.Add(XsAnimationSegment.LeftShoulder, HumanBodyBones.LeftShoulder);
mecanimBones.Add(XsAnimationSegment.LeftUpperArm, HumanBodyBones.LeftUpperArm);
mecanimBones.Add(XsAnimationSegment.LeftLowerArm, HumanBodyBones.LeftLowerArm);
mecanimBones.Add(XsAnimationSegment.LeftHand, HumanBodyBones.LeftHand);
mecanimBones.Add(XsAnimationSegment.RightShoulder, HumanBodyBones.RightShoulder);
mecanimBones.Add(XsAnimationSegment.RightUpperArm, HumanBodyBones.RightUpperArm);
mecanimBones.Add(XsAnimationSegment.RightLowerArm, HumanBodyBones.RightLowerArm);
mecanimBones.Add(XsAnimationSegment.RightHand, HumanBodyBones.RightHand);
mecanimBones.Add(XsAnimationSegment.Neck, HumanBodyBones.Neck);
mecanimBones.Add(XsAnimationSegment.Head, HumanBodyBones.Head);
}
public bool swapLimbs=false;
私人字典;
///动画的23个分段编号。字典的第一部分是成对的。
公共枚举XsAnimationSegment
{
骨盆=0,//髋
右上肢=1,
RightLowerLeg=2,
右脚=3,
右脚趾=4,
左大腿=5,
LeftLowerLeg=6,
左脚=7,
LeftToe=8,
L5=9,//未使用
L3=10,//脊椎
T12=11,//未使用
T8=12,//胸部
左肩=13,
左上臂=14,
LeftLowerArm=15,
左手=16,
右肩=17,
右上臂=18,
RightLowerArm=19,
右手=20,
颈部=21,
水头=22
}
///分段顺序。
int[]段顺序=
{
(int)XsAnimationSegment.Pelvis,
(int)XsAnimationSegment.RightUpperLeg,
(int)XsAnimationSegment.RightLowerLeg,
(int)XsAnimationSegment.RightFoot,
(int)XsAnimationSegment.RightToe,
(int)XsAnimationSegment.LeftUpperLeg,
(int)XsAnimationSegment.LeftLowerLeg,
(int)XsAnimationSegment.LeftFoot,
(int)XsAnimationSegment.LeftToe,
(int)XsAnimationSegment.L5,
(int)XsAnimationSegment.L3,
(int)XsAnimationSegment.T12,
(int)XsAnimationSegment.T8,
(int)XsAnimationSegment.LeftShoulder,
(int)XsAnimationSegment.LeftUpperArm,
(int)XsAnimationSegment.LeftLowerArm,
(int)XsAnimationSegment.LeftHand,
(int)XsAnimationSegment.rightloard,
(int)XsAnimationSegment.RightUpperArm,
(int)XsAnimationSegment.RightLowerArm,
(int)XsAnimationSegment.RightHand,
(int)XsAnimationSegment.Neck,
(int)XsAnimationSegment.Head
};
///将mecanim骨骼映射到xsens线段。23骨骼/节段
受保护的void mapMecanimBones()
{
mecanimBones=新字典();
添加(XsAnimationSegment.Pelvis,HumanBodyBones.Hips);
添加(XsAnimationSegment.LeftUpperLeg,HumanBodyBones.LeftUpperLeg);
添加(XsAnimationSegment.LeftLowerLeg,HumanBodyBones.LeftLowerLeg);
添加(XsAnimationSegment.LeftFoot,HumanBodyBones.LeftFoot);
添加(XsAnimationSegment.LeftToe,HumanBodyBones.LeftToes);
添加(XsAnimationSegment.righupperleg,HumanBodyBones.righupperleg);
添加(XsAnimationSegment.RightLowerLeg,HumanBodyBones.RightLowerLeg);
添加(XsAnimationSegment.RightFoot,HumanBodyBones.RightFoot);
添加(XsAnimationSegment.rightoe,HumanBodyBones.rightoes);
添加(XsAnimationSegment.L5,HumanBodyBones.LastBone);
添加(XsAnimationSegment.L3,HumanBodyBones.Spine);
添加(XsAnimationSegment.T12,HumanBodyBones.LastBone);
添加(XsAnimationSegment.T8,HumanBodyBones.cost);
添加(XsAnimationSegment.lefthealth,HumanBodyBones.lefthealth);
添加(XsAnimationSegment.LeftUpperArm,HumanBodyBones.LeftUpperArm);
添加(XsAnimationSegment.LeftLowerArm,HumanBodyBones.LeftLowerArm);
添加(XsAnimationSegment.LeftHand,HumanBodyBones.LeftHand);
添加(XsAnimationSegment.rightweal,HumanBodyBones.rightweal);
添加(XsAnimationSegment.righupperarm,HumanBodyBones.righupperarm);
添加(XsAnimationSegment.RightLowerArm,HumanBodyBones.RightLowerArm);
添加(XsAnimationSegment.rightmand,HumanBodyBones.rightmand);
添加(XsAnimationSegment.Neck,HumanBodyBones.Neck);
添加(XsAnimationSegment.Head,HumanBodyBones.Head);
}
但是,左手和右手的动画方式显然不会发生交换。我遗漏了什么或做错了什么?动画是在更新中完成的,如果你想更改它的任何内容,你应该在
LateUpdate()中完成。
只需将您的
Update()
更改为LateUpdate()
即可解决此问题 动画制作是在更新中完成的,如果您想更改它的任何内容,您应该在LateUpdate()中完成它。
只需将您的
Update()
更改为LateUpdate()
即可解决此问题 多谢各位。您是对的,但是在LateUpdate()
中,我将不具有latestororientations
,它是我的swapLimbsRots
方法的唯一参数。。。你是不是建议我调用mvnActors.getLatestPose(actorID)