Esempio n. 1
0
        //This is because parenting is used at runtime, but cannot be used on prefabs in editor so a copy is required
        public void EditorCreateCopySetPose(Hand hand)
        {
            HandPoseData pose = new HandPoseData();

            if (hand.left && leftPoseSet)
            {
                pose = leftPose;
            }
            else if (!hand.left && rightPoseSet)
            {
                pose = rightPose;
            }

            var  handParent = hand.transform.parent;
            Hand handCopy;

            if (hand.name != "HAND COPY DELETE")
            {
                handCopy = Instantiate(hand, hand.transform.position, hand.transform.rotation);
            }
            else
            {
                handCopy = hand;
            }

            handCopy.name = "HAND COPY DELETE";
            editorHand    = handCopy;

            pose.SetPose(handCopy, transform);
        }
Esempio n. 2
0
        public void EditorSaveGrabPose(Hand hand, bool left)
        {
            var pose = new HandPoseData();

            var posePositionsList = new List <Vector3>();
            var poseRotationsList = new List <Quaternion>();

            var handCopy   = Instantiate(hand, hand.transform.position, hand.transform.rotation);
            var handParent = handCopy.transform.parent;

            handCopy.transform.parent  = transform;
            pose.handOffset            = handCopy.transform.localPosition;
            pose.localQuaternionOffset = handCopy.transform.localRotation;
            DestroyImmediate(handCopy.gameObject);

            foreach (var finger in hand.fingers)
            {
                AssignChildrenPose(finger.transform);
            }

            void AssignChildrenPose(Transform obj)
            {
                AddPoint(obj.localPosition, obj.localRotation);
                for (int j = 0; j < obj.childCount; j++)
                {
                    AssignChildrenPose(obj.GetChild(j));
                }
            }

            void AddPoint(Vector3 pos, Quaternion rot)
            {
                posePositionsList.Add(pos);
                poseRotationsList.Add(rot);
            }

            pose.posePositions = new Vector3[posePositionsList.Count];
            pose.poseRotations = new Quaternion[posePositionsList.Count];
            for (int i = 0; i < posePositionsList.Count; i++)
            {
                pose.posePositions[i] = posePositionsList[i];
                pose.poseRotations[i] = poseRotationsList[i];
            }

            if (left)
            {
                leftPose    = pose;
                leftPoseSet = true;
                Debug.Log("Pose Saved - Left");
            }
            else
            {
                rightPose    = pose;
                rightPoseSet = true;
                Debug.Log("Pose Saved - Right");
            }
        }
Esempio n. 3
0
        public static HandPoseData LerpPose(HandPoseData from, HandPoseData to, float point)
        {
            var lerpPose = new HandPoseData();

            lerpPose.handOffset            = Vector3.Lerp(from.handOffset, to.handOffset, point);
            lerpPose.localQuaternionOffset = Quaternion.Lerp(from.localQuaternionOffset, to.localQuaternionOffset, point);
            lerpPose.posePositions         = new Vector3[from.posePositions.Length];
            lerpPose.poseRotations         = new Quaternion[from.poseRotations.Length];

            for (int i = 0; i < from.posePositions.Length; i++)
            {
                lerpPose.posePositions[i] = Vector3.Lerp(from.posePositions[i], to.posePositions[i], point);
                lerpPose.poseRotations[i] = Quaternion.Lerp(from.poseRotations[i], to.poseRotations[i], point);
            }

            return(lerpPose);
        }