Esempio n. 1
0
        public static SkeletonV1 CreateOverrideSkeleton(Animator animator, string name)
        {
            var total = (int)HumanBodyBones.LastBone;
            var sk    = new SkeletonV1();

            sk.variation   = SkeletonV1.Variation.skeletonv1posture;
            sk.name        = name;
            sk.hasSkeleton = true;

            var list = new List <SkeletonV1.Joint>();

            Transform lShoulder    = animator.GetBoneTransform(HumanBodyBones.LeftShoulder);
            Transform rShoulder    = animator.GetBoneTransform(HumanBodyBones.RightShoulder);
            var       distShoulder = lShoulder.position - rShoulder.position;

            for (int i = 0; i < total; i++)
            {
                var joint = animator.GetBoneTransform((HumanBodyBones)i);
                if (joint)
                {
                    var jt = new SkeletonV1.Joint();
                    jt.type = i;
                    jt.pos  = joint.localPosition;
                    jt.rot  = joint.rotation;
                    //package.joints[i] = jt;
                    list.Add(jt);
                }
                else
                {
                    Debug.LogWarningFormat("This avatar doesn't have {0}", (HumanBodyBones)i);
                }
            }

            var root = new SkeletonV1.Joint();

            root.type = -1;
            root.pos  = animator.transform.localPosition;
            root.rot  = animator.transform.rotation;
            list.Add(root);

            sk.upperConf        = 1f;
            sk.lowerConf        = 1f;
            sk.overallConf      = 1f;
            sk.distanceShoulder = distShoulder;
            sk.joints           = list.ToArray();

            return(sk);
        }
Esempio n. 2
0
        public static SkeletonV1 CreateRelativedSkeleton(Animator animator, SkeletonV1 tpose, string name)
        {
            var sk = new SkeletonV1();
            var upperConf = 0f; var upperNum = 0;
            var lowerConf = 0f; var lowerNum = 0;
            var overallConf = 0f;

            sk.variation   = Chiron.Skeleton.SkeletonV1.Variation.skeletonv1default;
            sk.name        = name;
            sk.hasSkeleton = true;
            sk.joints      = new SkeletonV1.Joint[tpose.joints.Length];

            Transform lShoulder    = animator.GetBoneTransform(HumanBodyBones.LeftShoulder);
            Transform rShoulder    = animator.GetBoneTransform(HumanBodyBones.RightShoulder);
            var       distShoulder = lShoulder.position - rShoulder.position;

            Transform hip = animator.GetBoneTransform(HumanBodyBones.Hips);

            var index = 0;

            /*
             * Length of VNect joint
             * Because VNect bone not always existing in Avatar
             * Meaning you can't get correct length on VNectModel, length of 28 is incorrect
             * So we need to count it base on Avatar, then cross reference with VNectModel
             */
            var vcount = 0;

            foreach (var i in tpose.joints)
            {
                if (i.type == -1)
                {
                    continue;
                }

                var joint = animator.GetBoneTransform((HumanBodyBones)i.type);
                if (joint)
                {
                    var jt = new SkeletonV1.Joint();
                    jt.type = i.type;
                    jt.pos  = joint.localPosition - tpose.GetJoint(i.type).pos;
                    jt.rot  = joint.rotation * Quaternion.Inverse(tpose.GetJoint(i.type).rot);

                    sk.joints[index] = jt;

                    if (IsUpperBody(i.type))
                    {
                        upperConf += 1f;
                        upperNum++;
                    }
                    else if (IsLowerBody(i.type))
                    {
                        lowerConf += 1f;
                        lowerNum++;
                    }
                    overallConf += 1f;

                    vcount++;
                }
                index++;
            }

            var root = new SkeletonV1.Joint();

            root.type = -1;
            root.pos  = animator.transform.localPosition;
            root.rot  = animator.transform.rotation;
            sk.joints[sk.joints.Length - 1] = root;

            sk.upperConf        = upperConf / (float)upperNum;
            sk.lowerConf        = lowerConf / (float)lowerNum;
            sk.overallConf      = overallConf / (float)vcount;
            sk.distanceShoulder = distShoulder;
            return(sk);
        }