public void ReparentHand(HandBoneReferences hand)
 {
     ReparentFinger(hand.index, hand.wrist);
     ReparentFinger(hand.middle, hand.wrist);
     ReparentFinger(hand.ring, hand.wrist);
     ReparentFinger(hand.pinky, hand.wrist);
     ReparentFinger(hand.thumb, hand.wrist);
 }
        public void ParentHandSkeletonToAnotherHandSkeleton(HandBoneReferences parent, HandBoneReferences child)
        {
            InsertBoneParent(child.wrist.bone, parent.wrist.bone);

            ParentFingerToFinger(parent.index, child.index);
            ParentFingerToFinger(parent.middle, child.middle);
            ParentFingerToFinger(parent.ring, child.ring);
            ParentFingerToFinger(parent.pinky, child.pinky);
            ParentFingerToFinger(parent.thumb, child.thumb);
        }
        private void DrawHand(HandBoneReferences hand)
        {
            DrawBone(hand.wrist, size);

            DrawFinger(hand.index, hand);
            DrawFinger(hand.middle, hand);
            DrawFinger(hand.ring, hand);
            DrawFinger(hand.pinky, hand);
            DrawFinger(hand.thumb, hand);
        }
Beispiel #4
0
        private Vector3 GetHandForward(HandBoneReferences hand)
        {
            Vector3 handForward = (hand.middle.proximal.bone.position - hand.wrist.bone.position).normalized;

            if (debug)
            {
                Vector3 palmPosition = (hand.wrist.bone.position + hand.index.proximal.bone.position + hand.pinky.proximal.bone.position) / 3f;
                Debug.DrawRay(palmPosition, handForward, Color.red);
            }

            return(handForward);
        }
        private void DrawFinger(Finger finger, HandBoneReferences hand)
        {
            // Draw Skeleton
            ConnectBones(hand.wrist, finger.proximal);
            ConnectBones(finger.proximal, finger.middle);
            ConnectBones(finger.middle, finger.distal);
            ConnectBones(finger.distal, finger.tip);

            // Draw Bones
            DrawBone(finger.proximal, size / 3f);
            DrawBone(finger.middle, size / 3f);
            DrawBone(finger.distal, size / 3f);
            DrawBone(finger.tip, size / 3f);
        }
Beispiel #6
0
        private Vector3 CalculatePalmNormal(HandBoneReferences hand, bool left)
        {
            Vector3 palmNormal = Vector3.Cross(hand.index.proximal.bone.position - hand.wrist.bone.position, hand.pinky.proximal.bone.position - hand.wrist.bone.position).normalized *(left ? 1f : -1f);

            //palmNormal = Vector3.Cross(hand.index.proximal.bone.position - palmNormal * fingerOffset / 2f - hand.wrist.bone.position, hand.pinky.proximal.bone.position - palmNormal * fingerOffset / 2f - hand.wrist.bone.position).normalized * (left ? 1f : -1f);

            if (debug)
            {
                Vector3 palmPosition = (hand.wrist.bone.position + hand.index.proximal.bone.position + hand.pinky.proximal.bone.position) / 3f;
                Debug.DrawRay(palmPosition, palmNormal, Color.blue);
            }

            return(palmNormal);
        }
        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);
            }
        }
        private HandBoneReferences CopyHandSkeleton(HandBoneReferences hand, Transform parent)
        {
            var     newHand = new HandBoneReferences();
            Vector3 handUp  = Vector3.up;

            newHand.wrist = new Bone(CreateDirectionBone("wrist", hand.wrist.bone.position, hand.middle.proximal.bone.position - hand.wrist.bone.position, handUp, parent));

            newHand.index.AssignBones(
                CreateDirectionBone("index_prox", hand.index.proximal.bone.position, hand.index.middle.bone.position - hand.index.proximal.bone.position, handUp, parent),
                CreateDirectionBone("index_mid", hand.index.middle.bone.position, hand.index.distal.bone.position - hand.index.middle.bone.position, handUp, parent),
                CreateDirectionBone("index_dis", hand.index.distal.bone.position, hand.index.tip.bone.position - hand.index.distal.bone.position, handUp, parent),
                CreateDirectionBone("index_tip", hand.index.tip.bone.position, hand.index.tip.bone.position - hand.index.distal.bone.position, handUp, parent));

            newHand.middle.AssignBones(
                CreateDirectionBone("middle_prox", hand.middle.proximal.bone.position, hand.middle.middle.bone.position - hand.middle.proximal.bone.position, handUp, parent),
                CreateDirectionBone("middle_mid", hand.middle.middle.bone.position, hand.middle.distal.bone.position - hand.middle.middle.bone.position, handUp, parent),
                CreateDirectionBone("middle_dis", hand.middle.distal.bone.position, hand.middle.tip.bone.position - hand.middle.distal.bone.position, handUp, parent),
                CreateDirectionBone("middle_tip", hand.middle.tip.bone.position, hand.middle.tip.bone.position - hand.middle.distal.bone.position, handUp, parent));

            newHand.ring.AssignBones(
                CreateDirectionBone("ring_prox", hand.ring.proximal.bone.position, hand.ring.middle.bone.position - hand.ring.proximal.bone.position, handUp, parent),
                CreateDirectionBone("ring_mid", hand.ring.middle.bone.position, hand.ring.distal.bone.position - hand.ring.middle.bone.position, handUp, parent),
                CreateDirectionBone("ring_dis", hand.ring.distal.bone.position, hand.ring.tip.bone.position - hand.ring.distal.bone.position, handUp, parent),
                CreateDirectionBone("ring_tip", hand.ring.tip.bone.position, hand.ring.tip.bone.position - hand.ring.distal.bone.position, handUp, parent));

            newHand.pinky.AssignBones(
                CreateDirectionBone("pinky_prox", hand.pinky.proximal.bone.position, hand.pinky.middle.bone.position - hand.pinky.proximal.bone.position, handUp, parent),
                CreateDirectionBone("pinky_mid", hand.pinky.middle.bone.position, hand.pinky.distal.bone.position - hand.pinky.middle.bone.position, handUp, parent),
                CreateDirectionBone("pinky_dis", hand.pinky.distal.bone.position, hand.pinky.tip.bone.position - hand.pinky.distal.bone.position, handUp, parent),
                CreateDirectionBone("pinky_tip", hand.pinky.tip.bone.position, hand.pinky.tip.bone.position - hand.pinky.distal.bone.position, handUp, parent));

            newHand.thumb.AssignBones(
                CreateDirectionBone("thumb_prox", hand.thumb.proximal.bone.position, hand.thumb.middle.bone.position - hand.thumb.proximal.bone.position, handUp, parent),
                CreateDirectionBone("thumb_mid", hand.thumb.middle.bone.position, hand.thumb.distal.bone.position - hand.thumb.middle.bone.position, handUp, parent),
                CreateDirectionBone("thumb_dis", hand.thumb.distal.bone.position, hand.thumb.tip.bone.position - hand.thumb.distal.bone.position, handUp, parent),
                CreateDirectionBone("thumb_tip", hand.thumb.tip.bone.position, hand.thumb.tip.bone.position - hand.thumb.distal.bone.position, handUp, parent));

            return(newHand);
        }