Exemplo n.º 1
0
        private void RotateHandToNewPalmNormal(HandSkeleton hand, bool isLeft, Vector3 newPalmNormal)
        {
            Vector3 rotationPlane = Vector3.Cross(GetHandForward(hand.handBoneReferences), CalculatePalmNormal(hand.handBoneReferences, isLeft));

            Vector3 newHandForward  = Vector3.Cross(CalculatePalmNormal(hand.handBoneReferences, isLeft), rotationPlane);
            bool    inverseRotation = Vector3.Dot(newHandForward, Vector3.ProjectOnPlane(newPalmNormal, rotationPlane)) > 0f;

            float angleToRotate = Vector3.Angle(CalculatePalmNormal(hand.handBoneReferences, isLeft), Vector3.ProjectOnPlane(newPalmNormal, rotationPlane));

            //angleToRotate += fingerAngleOffset / 2f;
            angleToRotate *= inverseRotation ? -1f : 1f;
            angleToRotate += fingerAngleOffset;

            hand.transform.GetChild(0).rotation *= Quaternion.AngleAxis(angleToRotate, hand.transform.GetChild(0).InverseTransformDirection(rotationPlane));
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            HandSkeleton script = target as HandSkeleton;

            if (GUILayout.Button("Populate Bones"))
            {
                script.PopulateBoneReferences();
            }

            if (GUILayout.Button("Clear Bone References"))
            {
                script.ClearBoneReferences();
            }
        }
        void OnSceneGUI()
        {
            // TODO: add undo/redo functionality
            HandSkeleton skeleton = target as HandSkeleton;

            if (skeleton == null || !skeleton.handBoneReferences.IsValid)
            {
                return;
            }

            HandBoneReferences bones = skeleton.handBoneReferences;

            if (bones.IsValid)
            {
                DrawHand(bones);
            }
        }
Exemplo n.º 4
0
        private void AlignHands(HandSkeleton leftHand, HandSkeleton rightHand)
        {
            Vector3 rightHandNormal = CalculatePalmNormal(rightHand.handBoneReferences, false);
            Vector3 leftHandNormal  = CalculatePalmNormal(leftHand.handBoneReferences, true);
            Vector3 averageNormal   = (rightHandNormal * -1f + leftHandNormal) / 2f;

            if (debug)
            {
                Vector3 palmPosition = (leftHand.handBoneReferences.wrist.bone.position + leftHand.handBoneReferences.index.proximal.bone.position + leftHand.handBoneReferences.pinky.proximal.bone.position) / 3f;
                Debug.DrawRay(palmPosition, averageNormal, Color.magenta, 1f);

                palmPosition = (rightHand.handBoneReferences.wrist.bone.position + rightHand.handBoneReferences.index.proximal.bone.position + rightHand.handBoneReferences.pinky.proximal.bone.position) / 3f;
                Debug.DrawRay(palmPosition, averageNormal * -1f, Color.magenta, 1f);
            }

            RotateHandToNewPalmNormal(leftHand, true, averageNormal);
            RotateHandToNewPalmNormal(rightHand, false, averageNormal * -1f);
        }