public void DetectSymmetry()
 {
     Symmetry = new int[Source.Bones.Length];
     for (int i = 0; i < Source.Bones.Length; i++)
     {
         string name = Source.Bones[i].Name;
         if (name.Contains("Left"))
         {
             BVHData.Bone bone = Source.FindBone("Right" + name.Substring(4));
             if (bone == null)
             {
                 Debug.Log("Could not find mapping for " + name + ".");
             }
             else
             {
                 Symmetry[i] = bone.Index;
             }
         }
         else if (name.Contains("Right"))
         {
             BVHData.Bone bone = Source.FindBone("Left" + name.Substring(5));
             if (bone == null)
             {
                 Debug.Log("Could not find mapping for " + name + ".");
             }
             else
             {
                 Symmetry[i] = bone.Index;
             }
         }
         else if (name.StartsWith("L") && char.IsUpper(name[1]))
         {
             BVHData.Bone bone = Source.FindBone("R" + name.Substring(1));
             if (bone == null)
             {
                 Debug.Log("Could not find mapping for " + name + ".");
             }
             else
             {
                 Symmetry[i] = bone.Index;
             }
         }
         else if (name.StartsWith("R") && char.IsUpper(name[1]))
         {
             BVHData.Bone bone = Source.FindBone("L" + name.Substring(1));
             if (bone == null)
             {
                 Debug.Log("Could not find mapping for " + name + ".");
             }
             else
             {
                 Symmetry[i] = bone.Index;
             }
         }
         else
         {
             Symmetry[i] = i;
         }
     }
 }
 public void DetectHips()
 {
     BVHData.Bone bone = Source.FindBone("Hips");
     if (bone == null)
     {
         Debug.Log("Could not find height map sensor.");
     }
     else
     {
         HeightMapSensor = bone.Index;
     }
 }
 public void DetectHead()
 {
     BVHData.Bone bone = Source.FindBone("Head");
     if (bone == null)
     {
         Debug.Log("Could not find depth map sensor.");
     }
     else
     {
         DepthMapSensor = bone.Index;
     }
 }
Esempio n. 4
0
        public void ComputePosture()
        {
            int channel = 0;

            BVHData.Motion motion = Data.Source.Motions[Index - 1];
            for (int i = 0; i < Data.Source.Bones.Length; i++)
            {
                BVHData.Bone info     = Data.Source.Bones[i];
                Vector3      position = Vector3.zero;
                Quaternion   rotation = Quaternion.identity;
                for (int j = 0; j < info.Channels.Length; j++)
                {
                    if (info.Channels[j] == 1)
                    {
                        position.x = motion.Values[channel]; channel += 1;
                    }
                    if (info.Channels[j] == 2)
                    {
                        position.y = motion.Values[channel]; channel += 1;
                    }
                    if (info.Channels[j] == 3)
                    {
                        position.z = motion.Values[channel]; channel += 1;
                    }
                    if (info.Channels[j] == 4)
                    {
                        rotation *= Quaternion.AngleAxis(motion.Values[channel], Vector3.right); channel += 1;
                    }
                    if (info.Channels[j] == 5)
                    {
                        rotation *= Quaternion.AngleAxis(motion.Values[channel], Vector3.up); channel += 1;
                    }
                    if (info.Channels[j] == 6)
                    {
                        rotation *= Quaternion.AngleAxis(motion.Values[channel], Vector3.forward); channel += 1;
                    }
                }

                position = (position == Vector3.zero ? info.Offset : position) / Data.UnitScale;
                Local[i] = Matrix4x4.TRS(position, rotation, Vector3.one);
                World[i] = info.Parent == "None" ? Local[i] : World[Data.Source.FindBone(info.Parent).Index] * Local[i];
            }
            for (int i = 0; i < Data.Source.Bones.Length; i++)
            {
                Local[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Data.Corrections[i]), Vector3.one);
                World[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Data.Corrections[i]), Vector3.one);
            }
        }